1 /* 2 * Copyright (C) 2000 Peter Kelly (pmk (at) post.com) 3 * Copyright (C) 2005, 2006 Apple Computer, Inc. 4 * Copyright (C) 2007 Samuel Weinig (sam (at) webkit.org) 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public License 17 * along with this library; see the file COPYING.LIB. If not, write to 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef Tokenizer_h 24 #define Tokenizer_h 25 26 namespace WebCore { 27 28 class SegmentedString; 29 class XSSAuditor; 30 31 class Tokenizer : public Noncopyable { 32 public: 33 virtual ~Tokenizer() { } 34 35 // Script output must be prepended, while new data 36 // received during executing a script must be appended, hence the 37 // extra bool to be able to distinguish between both cases. 38 // document.write() always uses false, while the loader uses true. 39 virtual void write(const SegmentedString&, bool appendData) = 0; 40 virtual void finish() = 0; 41 virtual bool isWaitingForScripts() const = 0; 42 virtual void stopParsing() { m_parserStopped = true; } 43 virtual bool processingData() const { return false; } 44 virtual int executingScript() const { return 0; } 45 46 virtual bool wantsRawData() const { return false; } 47 virtual bool writeRawData(const char* /*data*/, int /*length*/) { return false; } 48 49 bool inViewSourceMode() const { return m_inViewSourceMode; } 50 void setInViewSourceMode(bool mode) { m_inViewSourceMode = mode; } 51 52 virtual bool wellFormed() const { return true; } 53 54 virtual int lineNumber() const { return -1; } 55 virtual int columnNumber() const { return -1; } 56 57 virtual void executeScriptsWaitingForStylesheets() {} 58 59 virtual bool isHTMLTokenizer() const { return false; } 60 61 XSSAuditor* xssAuditor() const { return m_XSSAuditor; } 62 void setXSSAuditor(XSSAuditor* auditor) { m_XSSAuditor = auditor; } 63 64 protected: 65 Tokenizer(bool viewSourceMode = false) 66 : m_parserStopped(false) 67 , m_inViewSourceMode(viewSourceMode) 68 , m_XSSAuditor(0) 69 { 70 } 71 72 // The tokenizer has buffers, so parsing may continue even after 73 // it stops receiving data. We use m_parserStopped to stop the tokenizer 74 // even when it has buffered data. 75 bool m_parserStopped; 76 bool m_inViewSourceMode; 77 78 // The XSSAuditor associated with this tokenizer. 79 XSSAuditor* m_XSSAuditor; 80 }; 81 82 } // namespace WebCore 83 84 #endif // Tokenizer_h 85