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 18 matching lines...) Expand all Loading... |
29 #include "core/dom/DocumentEncodingData.h" | 29 #include "core/dom/DocumentEncodingData.h" |
30 #include "core/html/parser/BackgroundHTMLInputStream.h" | 30 #include "core/html/parser/BackgroundHTMLInputStream.h" |
31 #include "core/html/parser/CompactHTMLToken.h" | 31 #include "core/html/parser/CompactHTMLToken.h" |
32 #include "core/html/parser/HTMLParserOptions.h" | 32 #include "core/html/parser/HTMLParserOptions.h" |
33 #include "core/html/parser/HTMLPreloadScanner.h" | 33 #include "core/html/parser/HTMLPreloadScanner.h" |
34 #include "core/html/parser/HTMLSourceTracker.h" | 34 #include "core/html/parser/HTMLSourceTracker.h" |
35 #include "core/html/parser/HTMLTreeBuilderSimulator.h" | 35 #include "core/html/parser/HTMLTreeBuilderSimulator.h" |
36 #include "core/html/parser/ParsedChunkQueue.h" | 36 #include "core/html/parser/ParsedChunkQueue.h" |
37 #include "core/html/parser/TextResourceDecoder.h" | 37 #include "core/html/parser/TextResourceDecoder.h" |
38 #include "core/html/parser/XSSAuditorDelegate.h" | 38 #include "core/html/parser/XSSAuditorDelegate.h" |
| 39 #include "wtf/PassOwnPtr.h" |
39 #include "wtf/WeakPtr.h" | 40 #include "wtf/WeakPtr.h" |
40 #include <memory> | |
41 | 41 |
42 namespace blink { | 42 namespace blink { |
43 | 43 |
44 class HTMLDocumentParser; | 44 class HTMLDocumentParser; |
45 class XSSAuditor; | 45 class XSSAuditor; |
46 class WebTaskRunner; | 46 class WebTaskRunner; |
47 | 47 |
48 class BackgroundHTMLParser { | 48 class BackgroundHTMLParser { |
49 USING_FAST_MALLOC(BackgroundHTMLParser); | 49 USING_FAST_MALLOC(BackgroundHTMLParser); |
50 WTF_MAKE_NONCOPYABLE(BackgroundHTMLParser); | 50 WTF_MAKE_NONCOPYABLE(BackgroundHTMLParser); |
51 public: | 51 public: |
52 struct Configuration { | 52 struct Configuration { |
53 USING_FAST_MALLOC(Configuration); | 53 USING_FAST_MALLOC(Configuration); |
54 public: | 54 public: |
55 Configuration(); | 55 Configuration(); |
56 HTMLParserOptions options; | 56 HTMLParserOptions options; |
57 WeakPtr<HTMLDocumentParser> parser; | 57 WeakPtr<HTMLDocumentParser> parser; |
58 std::unique_ptr<XSSAuditor> xssAuditor; | 58 OwnPtr<XSSAuditor> xssAuditor; |
59 std::unique_ptr<TextResourceDecoder> decoder; | 59 OwnPtr<TextResourceDecoder> decoder; |
60 RefPtr<ParsedChunkQueue> parsedChunkQueue; | 60 RefPtr<ParsedChunkQueue> parsedChunkQueue; |
61 // outstandingTokenLimit must be greater than or equal to | 61 // outstandingTokenLimit must be greater than or equal to |
62 // pendingTokenLimit | 62 // pendingTokenLimit |
63 size_t outstandingTokenLimit; | 63 size_t outstandingTokenLimit; |
64 size_t pendingTokenLimit; | 64 size_t pendingTokenLimit; |
65 }; | 65 }; |
66 | 66 |
67 static void start(PassRefPtr<WeakReference<BackgroundHTMLParser>>, std::uniq
ue_ptr<Configuration>, const KURL& documentURL, std::unique_ptr<CachedDocumentPa
rameters>, const MediaValuesCached::MediaValuesCachedData&, std::unique_ptr<WebT
askRunner>); | 67 static void start(PassRefPtr<WeakReference<BackgroundHTMLParser>>, PassOwnPt
r<Configuration>, const KURL& documentURL, PassOwnPtr<CachedDocumentParameters>,
const MediaValuesCached::MediaValuesCachedData&, PassOwnPtr<WebTaskRunner>); |
68 | 68 |
69 struct Checkpoint { | 69 struct Checkpoint { |
70 USING_FAST_MALLOC(Checkpoint); | 70 USING_FAST_MALLOC(Checkpoint); |
71 public: | 71 public: |
72 WeakPtr<HTMLDocumentParser> parser; | 72 WeakPtr<HTMLDocumentParser> parser; |
73 std::unique_ptr<HTMLToken> token; | 73 OwnPtr<HTMLToken> token; |
74 std::unique_ptr<HTMLTokenizer> tokenizer; | 74 OwnPtr<HTMLTokenizer> tokenizer; |
75 HTMLTreeBuilderSimulator::State treeBuilderState; | 75 HTMLTreeBuilderSimulator::State treeBuilderState; |
76 HTMLInputCheckpoint inputCheckpoint; | 76 HTMLInputCheckpoint inputCheckpoint; |
77 TokenPreloadScannerCheckpoint preloadScannerCheckpoint; | 77 TokenPreloadScannerCheckpoint preloadScannerCheckpoint; |
78 String unparsedInput; | 78 String unparsedInput; |
79 }; | 79 }; |
80 | 80 |
81 void appendRawBytesFromParserThread(const char* data, int dataLength); | 81 void appendRawBytesFromParserThread(const char* data, int dataLength); |
82 | 82 |
83 void appendRawBytesFromMainThread(std::unique_ptr<Vector<char>>); | 83 void appendRawBytesFromMainThread(PassOwnPtr<Vector<char>>); |
84 void setDecoder(std::unique_ptr<TextResourceDecoder>); | 84 void setDecoder(PassOwnPtr<TextResourceDecoder>); |
85 void flush(); | 85 void flush(); |
86 void resumeFrom(std::unique_ptr<Checkpoint>); | 86 void resumeFrom(PassOwnPtr<Checkpoint>); |
87 void startedChunkWithCheckpoint(HTMLInputCheckpoint); | 87 void startedChunkWithCheckpoint(HTMLInputCheckpoint); |
88 void finish(); | 88 void finish(); |
89 void stop(); | 89 void stop(); |
90 | 90 |
91 void forcePlaintextForTextDocument(); | 91 void forcePlaintextForTextDocument(); |
92 | 92 |
93 private: | 93 private: |
94 BackgroundHTMLParser(PassRefPtr<WeakReference<BackgroundHTMLParser>>, std::u
nique_ptr<Configuration>, const KURL& documentURL, std::unique_ptr<CachedDocumen
tParameters>, const MediaValuesCached::MediaValuesCachedData&, std::unique_ptr<W
ebTaskRunner>); | 94 BackgroundHTMLParser(PassRefPtr<WeakReference<BackgroundHTMLParser>>, PassOw
nPtr<Configuration>, const KURL& documentURL, PassOwnPtr<CachedDocumentParameter
s>, const MediaValuesCached::MediaValuesCachedData&, PassOwnPtr<WebTaskRunner>); |
95 ~BackgroundHTMLParser(); | 95 ~BackgroundHTMLParser(); |
96 | 96 |
97 void appendDecodedBytes(const String&); | 97 void appendDecodedBytes(const String&); |
98 void markEndOfFile(); | 98 void markEndOfFile(); |
99 void pumpTokenizer(); | 99 void pumpTokenizer(); |
100 void sendTokensToMainThread(); | 100 void sendTokensToMainThread(); |
101 void updateDocument(const String& decodedData); | 101 void updateDocument(const String& decodedData); |
102 | 102 |
103 WeakPtrFactory<BackgroundHTMLParser> m_weakFactory; | 103 WeakPtrFactory<BackgroundHTMLParser> m_weakFactory; |
104 BackgroundHTMLInputStream m_input; | 104 BackgroundHTMLInputStream m_input; |
105 HTMLSourceTracker m_sourceTracker; | 105 HTMLSourceTracker m_sourceTracker; |
106 std::unique_ptr<HTMLToken> m_token; | 106 OwnPtr<HTMLToken> m_token; |
107 std::unique_ptr<HTMLTokenizer> m_tokenizer; | 107 OwnPtr<HTMLTokenizer> m_tokenizer; |
108 HTMLTreeBuilderSimulator m_treeBuilderSimulator; | 108 HTMLTreeBuilderSimulator m_treeBuilderSimulator; |
109 HTMLParserOptions m_options; | 109 HTMLParserOptions m_options; |
110 const size_t m_outstandingTokenLimit; | 110 const size_t m_outstandingTokenLimit; |
111 WeakPtr<HTMLDocumentParser> m_parser; | 111 WeakPtr<HTMLDocumentParser> m_parser; |
112 | 112 |
113 std::unique_ptr<CompactHTMLTokenStream> m_pendingTokens; | 113 OwnPtr<CompactHTMLTokenStream> m_pendingTokens; |
114 const size_t m_pendingTokenLimit; | 114 const size_t m_pendingTokenLimit; |
115 PreloadRequestStream m_pendingPreloads; | 115 PreloadRequestStream m_pendingPreloads; |
116 // Indices into |m_pendingTokens|. | 116 // Indices into |m_pendingTokens|. |
117 Vector<int> m_likelyDocumentWriteScriptIndices; | 117 Vector<int> m_likelyDocumentWriteScriptIndices; |
118 ViewportDescriptionWrapper m_viewportDescription; | 118 ViewportDescriptionWrapper m_viewportDescription; |
119 XSSInfoStream m_pendingXSSInfos; | 119 XSSInfoStream m_pendingXSSInfos; |
120 | 120 |
121 std::unique_ptr<XSSAuditor> m_xssAuditor; | 121 OwnPtr<XSSAuditor> m_xssAuditor; |
122 std::unique_ptr<TokenPreloadScanner> m_preloadScanner; | 122 OwnPtr<TokenPreloadScanner> m_preloadScanner; |
123 std::unique_ptr<TextResourceDecoder> m_decoder; | 123 OwnPtr<TextResourceDecoder> m_decoder; |
124 DocumentEncodingData m_lastSeenEncodingData; | 124 DocumentEncodingData m_lastSeenEncodingData; |
125 std::unique_ptr<WebTaskRunner> m_loadingTaskRunner; | 125 OwnPtr<WebTaskRunner> m_loadingTaskRunner; |
126 RefPtr<ParsedChunkQueue> m_parsedChunkQueue; | 126 RefPtr<ParsedChunkQueue> m_parsedChunkQueue; |
127 | 127 |
128 bool m_startingScript; | 128 bool m_startingScript; |
129 }; | 129 }; |
130 | 130 |
131 } // namespace blink | 131 } // namespace blink |
132 | 132 |
133 #endif | 133 #endif |
OLD | NEW |