OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2013 Google, Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 13 matching lines...) Expand all Loading... |
24 */ | 24 */ |
25 | 25 |
26 #ifndef BackgroundHTMLParser_h | 26 #ifndef BackgroundHTMLParser_h |
27 #define BackgroundHTMLParser_h | 27 #define BackgroundHTMLParser_h |
28 | 28 |
29 #include "core/html/parser/BackgroundHTMLInputStream.h" | 29 #include "core/html/parser/BackgroundHTMLInputStream.h" |
30 #include "core/html/parser/CompactHTMLToken.h" | 30 #include "core/html/parser/CompactHTMLToken.h" |
31 #include "core/html/parser/HTMLParserOptions.h" | 31 #include "core/html/parser/HTMLParserOptions.h" |
32 #include "core/html/parser/HTMLPreloadScanner.h" | 32 #include "core/html/parser/HTMLPreloadScanner.h" |
33 #include "core/html/parser/HTMLSourceTracker.h" | 33 #include "core/html/parser/HTMLSourceTracker.h" |
| 34 #include "core/html/parser/HTMLToken.h" |
| 35 #include "core/html/parser/HTMLTokenizer.h" |
34 #include "core/html/parser/HTMLTreeBuilderSimulator.h" | 36 #include "core/html/parser/HTMLTreeBuilderSimulator.h" |
35 #include "core/html/parser/XSSAuditorDelegate.h" | 37 #include "core/html/parser/XSSAuditorDelegate.h" |
36 #include "wtf/PassOwnPtr.h" | 38 #include "wtf/PassOwnPtr.h" |
37 #include "wtf/WeakPtr.h" | 39 #include "wtf/WeakPtr.h" |
38 | 40 |
39 namespace WebCore { | 41 namespace WebCore { |
40 | 42 |
41 class HTMLDocumentParser; | 43 class HTMLDocumentParser; |
42 class SharedBuffer; | |
43 class XSSAuditor; | 44 class XSSAuditor; |
44 | 45 |
45 class BackgroundHTMLParser { | 46 class BackgroundHTMLParser { |
46 WTF_MAKE_FAST_ALLOCATED; | 47 WTF_MAKE_FAST_ALLOCATED; |
47 public: | 48 public: |
48 struct Configuration { | 49 struct Configuration { |
49 HTMLParserOptions options; | 50 HTMLParserOptions options; |
50 WeakPtr<HTMLDocumentParser> parser; | 51 WeakPtr<HTMLDocumentParser> parser; |
51 OwnPtr<XSSAuditor> xssAuditor; | 52 OwnPtr<XSSAuditor> xssAuditor; |
52 OwnPtr<TokenPreloadScanner> preloadScanner; | 53 OwnPtr<TokenPreloadScanner> preloadScanner; |
53 OwnPtr<TextResourceDecoder> decoder; | |
54 }; | 54 }; |
55 | 55 |
56 static void start(PassRefPtr<WeakReference<BackgroundHTMLParser> >, PassOwnP
tr<Configuration>); | 56 static void create(PassRefPtr<WeakReference<BackgroundHTMLParser> > referenc
e, PassOwnPtr<Configuration> config) |
| 57 { |
| 58 new BackgroundHTMLParser(reference, config); |
| 59 // Caller must free by calling stop(). |
| 60 } |
57 | 61 |
58 struct Checkpoint { | 62 struct Checkpoint { |
59 WeakPtr<HTMLDocumentParser> parser; | 63 WeakPtr<HTMLDocumentParser> parser; |
60 OwnPtr<HTMLToken> token; | 64 OwnPtr<HTMLToken> token; |
61 OwnPtr<HTMLTokenizer> tokenizer; | 65 OwnPtr<HTMLTokenizer> tokenizer; |
62 HTMLTreeBuilderSimulator::State treeBuilderState; | 66 HTMLTreeBuilderSimulator::State treeBuilderState; |
63 HTMLInputCheckpoint inputCheckpoint; | 67 HTMLInputCheckpoint inputCheckpoint; |
64 TokenPreloadScannerCheckpoint preloadScannerCheckpoint; | 68 TokenPreloadScannerCheckpoint preloadScannerCheckpoint; |
65 String unparsedInput; | 69 String unparsedInput; |
66 }; | 70 }; |
67 | 71 |
68 void appendBytes(PassOwnPtr<Vector<char> >); | 72 void append(const String&); |
69 void setDecoder(PassOwnPtr<TextResourceDecoder>); | |
70 void flush(); | |
71 void resumeFrom(PassOwnPtr<Checkpoint>); | 73 void resumeFrom(PassOwnPtr<Checkpoint>); |
72 void startedChunkWithCheckpoint(HTMLInputCheckpoint); | 74 void startedChunkWithCheckpoint(HTMLInputCheckpoint); |
73 void finish(); | 75 void finish(); |
74 void stop(); | 76 void stop(); |
75 | 77 |
76 void forcePlaintextForTextDocument(); | 78 void forcePlaintextForTextDocument(); |
77 | 79 |
78 private: | 80 private: |
79 BackgroundHTMLParser(PassRefPtr<WeakReference<BackgroundHTMLParser> >, PassO
wnPtr<Configuration>); | 81 BackgroundHTMLParser(PassRefPtr<WeakReference<BackgroundHTMLParser> >, PassO
wnPtr<Configuration>); |
80 ~BackgroundHTMLParser(); | |
81 | 82 |
82 void append(const String&); | |
83 void markEndOfFile(); | 83 void markEndOfFile(); |
84 void pumpTokenizer(); | 84 void pumpTokenizer(); |
85 void sendTokensToMainThread(); | 85 void sendTokensToMainThread(); |
86 void updateDocument(const String& decodedData); | |
87 | 86 |
88 WeakPtrFactory<BackgroundHTMLParser> m_weakFactory; | 87 WeakPtrFactory<BackgroundHTMLParser> m_weakFactory; |
89 BackgroundHTMLInputStream m_input; | 88 BackgroundHTMLInputStream m_input; |
90 HTMLSourceTracker m_sourceTracker; | 89 HTMLSourceTracker m_sourceTracker; |
91 OwnPtr<HTMLToken> m_token; | 90 OwnPtr<HTMLToken> m_token; |
92 OwnPtr<HTMLTokenizer> m_tokenizer; | 91 OwnPtr<HTMLTokenizer> m_tokenizer; |
93 HTMLTreeBuilderSimulator m_treeBuilderSimulator; | 92 HTMLTreeBuilderSimulator m_treeBuilderSimulator; |
94 HTMLParserOptions m_options; | 93 HTMLParserOptions m_options; |
95 WeakPtr<HTMLDocumentParser> m_parser; | 94 WeakPtr<HTMLDocumentParser> m_parser; |
96 | 95 |
97 OwnPtr<CompactHTMLTokenStream> m_pendingTokens; | 96 OwnPtr<CompactHTMLTokenStream> m_pendingTokens; |
98 PreloadRequestStream m_pendingPreloads; | 97 PreloadRequestStream m_pendingPreloads; |
99 XSSInfoStream m_pendingXSSInfos; | 98 XSSInfoStream m_pendingXSSInfos; |
100 | 99 |
101 OwnPtr<XSSAuditor> m_xssAuditor; | 100 OwnPtr<XSSAuditor> m_xssAuditor; |
102 OwnPtr<TokenPreloadScanner> m_preloadScanner; | 101 OwnPtr<TokenPreloadScanner> m_preloadScanner; |
103 OwnPtr<TextResourceDecoder> m_decoder; | |
104 DocumentEncodingData m_lastSeenEncodingData; | |
105 }; | 102 }; |
106 | 103 |
107 } | 104 } |
108 | 105 |
109 #endif | 106 #endif |
OLD | NEW |