Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / html / parser / BackgroundHTMLParser.h
blob6922c310f9bd1f8fe0f96648f79ad7e3cbc0b370
1 /*
2 * Copyright (C) 2013 Google, Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef BackgroundHTMLParser_h
27 #define BackgroundHTMLParser_h
29 #include "core/dom/DocumentEncodingData.h"
30 #include "core/html/parser/BackgroundHTMLInputStream.h"
31 #include "core/html/parser/CompactHTMLToken.h"
32 #include "core/html/parser/HTMLParserOptions.h"
33 #include "core/html/parser/HTMLPreloadScanner.h"
34 #include "core/html/parser/HTMLSourceTracker.h"
35 #include "core/html/parser/HTMLTreeBuilderSimulator.h"
36 #include "core/html/parser/TextResourceDecoder.h"
37 #include "core/html/parser/XSSAuditorDelegate.h"
38 #include "wtf/PassOwnPtr.h"
39 #include "wtf/WeakPtr.h"
41 namespace blink {
43 class HTMLDocumentParser;
44 class XSSAuditor;
45 class WebScheduler;
47 class BackgroundHTMLParser {
48 WTF_MAKE_FAST_ALLOCATED(BackgroundHTMLParser);
49 WTF_MAKE_NONCOPYABLE(BackgroundHTMLParser);
50 public:
51 struct Configuration {
52 WTF_MAKE_FAST_ALLOCATED(Configuration);
53 public:
54 Configuration();
55 HTMLParserOptions options;
56 WeakPtr<HTMLDocumentParser> parser;
57 OwnPtr<XSSAuditor> xssAuditor;
58 OwnPtr<TokenPreloadScanner> preloadScanner;
59 OwnPtr<TextResourceDecoder> decoder;
60 // outstandingTokenLimit must be greater than or equal to
61 // pendingTokenLimit
62 size_t outstandingTokenLimit;
63 size_t pendingTokenLimit;
66 static void start(PassRefPtr<WeakReference<BackgroundHTMLParser>>, PassOwnPtr<Configuration>, WebScheduler*);
68 struct Checkpoint {
69 WTF_MAKE_FAST_ALLOCATED(CheckPoint);
70 public:
71 WeakPtr<HTMLDocumentParser> parser;
72 OwnPtr<HTMLToken> token;
73 OwnPtr<HTMLTokenizer> tokenizer;
74 HTMLTreeBuilderSimulator::State treeBuilderState;
75 HTMLInputCheckpoint inputCheckpoint;
76 TokenPreloadScannerCheckpoint preloadScannerCheckpoint;
77 String unparsedInput;
80 void appendRawBytesFromParserThread(const char* data, int dataLength);
82 void appendRawBytesFromMainThread(PassOwnPtr<Vector<char>>);
83 void setDecoder(PassOwnPtr<TextResourceDecoder>);
84 void flush();
85 void resumeFrom(PassOwnPtr<Checkpoint>);
86 void startedChunkWithCheckpoint(HTMLInputCheckpoint);
87 void finish();
88 void stop();
90 void forcePlaintextForTextDocument();
92 private:
93 BackgroundHTMLParser(PassRefPtr<WeakReference<BackgroundHTMLParser>>, PassOwnPtr<Configuration>, WebScheduler*);
94 ~BackgroundHTMLParser();
96 void appendDecodedBytes(const String&);
97 void markEndOfFile();
98 void pumpTokenizer();
99 void sendTokensToMainThread();
100 void updateDocument(const String& decodedData);
102 WeakPtrFactory<BackgroundHTMLParser> m_weakFactory;
103 BackgroundHTMLInputStream m_input;
104 HTMLSourceTracker m_sourceTracker;
105 OwnPtr<HTMLToken> m_token;
106 OwnPtr<HTMLTokenizer> m_tokenizer;
107 HTMLTreeBuilderSimulator m_treeBuilderSimulator;
108 HTMLParserOptions m_options;
109 const size_t m_outstandingTokenLimit;
110 WeakPtr<HTMLDocumentParser> m_parser;
112 OwnPtr<CompactHTMLTokenStream> m_pendingTokens;
113 const size_t m_pendingTokenLimit;
114 PreloadRequestStream m_pendingPreloads;
115 XSSInfoStream m_pendingXSSInfos;
117 OwnPtr<XSSAuditor> m_xssAuditor;
118 OwnPtr<TokenPreloadScanner> m_preloadScanner;
119 OwnPtr<TextResourceDecoder> m_decoder;
120 DocumentEncodingData m_lastSeenEncodingData;
121 WebScheduler* m_scheduler; // NOT OWNED, scheduler will outlive BackgroundHTMLParser
123 bool m_startingScript;
128 #endif