| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 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 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 | 715 |
| 716 if (IsPaused()) { | 716 if (IsPaused()) { |
| 717 DCHECK_EQ(tokenizer_->GetState(), HTMLTokenizer::kDataState); | 717 DCHECK_EQ(tokenizer_->GetState(), HTMLTokenizer::kDataState); |
| 718 | 718 |
| 719 DCHECK(preloader_); | 719 DCHECK(preloader_); |
| 720 // TODO(kouhei): m_preloader should be always available for synchronous | 720 // TODO(kouhei): m_preloader should be always available for synchronous |
| 721 // parsing case, adding paranoia if for speculative crash fix for | 721 // parsing case, adding paranoia if for speculative crash fix for |
| 722 // crbug.com/465478 | 722 // crbug.com/465478 |
| 723 if (preloader_) { | 723 if (preloader_) { |
| 724 if (!preload_scanner_) { | 724 if (!preload_scanner_) { |
| 725 preload_scanner_ = CreatePreloadScanner( | 725 preload_scanner_ = CreatePreloadScanner(); |
| 726 TokenPreloadScanner::ScannerType::kMainDocument); | |
| 727 preload_scanner_->AppendToEnd(input_.Current()); | 726 preload_scanner_->AppendToEnd(input_.Current()); |
| 728 } | 727 } |
| 729 ScanAndPreload(preload_scanner_.get()); | 728 ScanAndPreload(preload_scanner_.get()); |
| 730 } | 729 } |
| 731 } | 730 } |
| 732 } | 731 } |
| 733 | 732 |
| 734 void HTMLDocumentParser::ConstructTreeFromHTMLToken() { | 733 void HTMLDocumentParser::ConstructTreeFromHTMLToken() { |
| 735 AtomicHTMLToken atomic_token(Token()); | 734 AtomicHTMLToken atomic_token(Token()); |
| 736 | 735 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 } | 790 } |
| 792 | 791 |
| 793 SegmentedString excluded_line_number_source(source); | 792 SegmentedString excluded_line_number_source(source); |
| 794 excluded_line_number_source.SetExcludeLineNumbers(); | 793 excluded_line_number_source.SetExcludeLineNumbers(); |
| 795 input_.InsertAtCurrentInsertionPoint(excluded_line_number_source); | 794 input_.InsertAtCurrentInsertionPoint(excluded_line_number_source); |
| 796 PumpTokenizerIfPossible(); | 795 PumpTokenizerIfPossible(); |
| 797 | 796 |
| 798 if (IsPaused()) { | 797 if (IsPaused()) { |
| 799 // Check the document.write() output with a separate preload scanner as | 798 // Check the document.write() output with a separate preload scanner as |
| 800 // the main scanner can't deal with insertions. | 799 // the main scanner can't deal with insertions. |
| 801 if (!insertion_preload_scanner_) { | 800 if (!insertion_preload_scanner_) |
| 802 insertion_preload_scanner_ = | 801 insertion_preload_scanner_ = CreatePreloadScanner(); |
| 803 CreatePreloadScanner(TokenPreloadScanner::ScannerType::kInsertion); | |
| 804 } | |
| 805 insertion_preload_scanner_->AppendToEnd(source); | 802 insertion_preload_scanner_->AppendToEnd(source); |
| 806 ScanAndPreload(insertion_preload_scanner_.get()); | 803 ScanAndPreload(insertion_preload_scanner_.get()); |
| 807 } | 804 } |
| 808 | 805 |
| 809 EndIfDelayed(); | 806 EndIfDelayed(); |
| 810 } | 807 } |
| 811 | 808 |
| 812 void HTMLDocumentParser::StartBackgroundParser() { | 809 void HTMLDocumentParser::StartBackgroundParser() { |
| 813 DCHECK(!IsStopped()); | 810 DCHECK(!IsStopped()); |
| 814 DCHECK(ShouldUseThreading()); | 811 DCHECK(ShouldUseThreading()); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 | 892 |
| 896 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.debug"), | 893 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.debug"), |
| 897 "HTMLDocumentParser::append", "size", input_source.length()); | 894 "HTMLDocumentParser::append", "size", input_source.length()); |
| 898 const SegmentedString source(input_source); | 895 const SegmentedString source(input_source); |
| 899 | 896 |
| 900 if (GetDocument()->IsPrefetchOnly()) { | 897 if (GetDocument()->IsPrefetchOnly()) { |
| 901 // Do not prefetch if there is an appcache. | 898 // Do not prefetch if there is an appcache. |
| 902 if (GetDocument()->Loader()->GetResponse().AppCacheID() != 0) | 899 if (GetDocument()->Loader()->GetResponse().AppCacheID() != 0) |
| 903 return; | 900 return; |
| 904 | 901 |
| 905 if (!preload_scanner_) { | 902 if (!preload_scanner_) |
| 906 preload_scanner_ = | 903 preload_scanner_ = CreatePreloadScanner(); |
| 907 CreatePreloadScanner(TokenPreloadScanner::ScannerType::kMainDocument); | |
| 908 } | |
| 909 | 904 |
| 910 preload_scanner_->AppendToEnd(source); | 905 preload_scanner_->AppendToEnd(source); |
| 911 ScanAndPreload(preload_scanner_.get()); | 906 ScanAndPreload(preload_scanner_.get()); |
| 912 | 907 |
| 913 // Return after the preload scanner, do not actually parse the document. | 908 // Return after the preload scanner, do not actually parse the document. |
| 914 return; | 909 return; |
| 915 } | 910 } |
| 916 | 911 |
| 917 if (preload_scanner_) { | 912 if (preload_scanner_) { |
| 918 if (input_.Current().IsEmpty() && !IsPaused()) { | 913 if (input_.Current().IsEmpty() && !IsPaused()) { |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1254 WTF::Passed(TakeDecoder()))); | 1249 WTF::Passed(TakeDecoder()))); |
| 1255 } | 1250 } |
| 1256 } | 1251 } |
| 1257 | 1252 |
| 1258 void HTMLDocumentParser::DocumentElementAvailable() { | 1253 void HTMLDocumentParser::DocumentElementAvailable() { |
| 1259 TRACE_EVENT0("blink,loader", "HTMLDocumentParser::documentElementAvailable"); | 1254 TRACE_EVENT0("blink,loader", "HTMLDocumentParser::documentElementAvailable"); |
| 1260 DCHECK(GetDocument()->documentElement()); | 1255 DCHECK(GetDocument()->documentElement()); |
| 1261 FetchQueuedPreloads(); | 1256 FetchQueuedPreloads(); |
| 1262 } | 1257 } |
| 1263 | 1258 |
| 1264 std::unique_ptr<HTMLPreloadScanner> HTMLDocumentParser::CreatePreloadScanner( | 1259 std::unique_ptr<HTMLPreloadScanner> HTMLDocumentParser::CreatePreloadScanner() { |
| 1265 TokenPreloadScanner::ScannerType scanner_type) { | |
| 1266 return HTMLPreloadScanner::Create( | 1260 return HTMLPreloadScanner::Create( |
| 1267 options_, GetDocument()->Url(), | 1261 options_, GetDocument()->Url(), |
| 1268 CachedDocumentParameters::Create(GetDocument()), | 1262 CachedDocumentParameters::Create(GetDocument()), |
| 1269 MediaValuesCached::MediaValuesCachedData(*GetDocument()), scanner_type); | 1263 MediaValuesCached::MediaValuesCachedData(*GetDocument())); |
| 1270 } | 1264 } |
| 1271 | 1265 |
| 1272 void HTMLDocumentParser::ScanAndPreload(HTMLPreloadScanner* scanner) { | 1266 void HTMLDocumentParser::ScanAndPreload(HTMLPreloadScanner* scanner) { |
| 1273 PreloadRequestStream requests = | 1267 PreloadRequestStream requests = |
| 1274 scanner->Scan(GetDocument()->ValidBaseElementURL(), nullptr); | 1268 scanner->Scan(GetDocument()->ValidBaseElementURL(), nullptr); |
| 1275 preloader_->TakeAndPreload(requests); | 1269 preloader_->TakeAndPreload(requests); |
| 1276 } | 1270 } |
| 1277 | 1271 |
| 1278 void HTMLDocumentParser::FetchQueuedPreloads() { | 1272 void HTMLDocumentParser::FetchQueuedPreloads() { |
| 1279 if (pending_csp_meta_token_ || !GetDocument()->documentElement()) | 1273 if (pending_csp_meta_token_ || !GetDocument()->documentElement()) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1305 double initialization_duration = | 1299 double initialization_duration = |
| 1306 MonotonicallyIncreasingTimeMS() - initialize_start_time; | 1300 MonotonicallyIncreasingTimeMS() - initialize_start_time; |
| 1307 | 1301 |
| 1308 double start_time = MonotonicallyIncreasingTimeMS(); | 1302 double start_time = MonotonicallyIncreasingTimeMS(); |
| 1309 String written_source = evaluator_->EvaluateAndEmitWrittenSource(source); | 1303 String written_source = evaluator_->EvaluateAndEmitWrittenSource(source); |
| 1310 double duration = MonotonicallyIncreasingTimeMS() - start_time; | 1304 double duration = MonotonicallyIncreasingTimeMS() - start_time; |
| 1311 | 1305 |
| 1312 int current_preload_count = | 1306 int current_preload_count = |
| 1313 GetDocument()->Loader()->Fetcher()->CountPreloads(); | 1307 GetDocument()->Loader()->Fetcher()->CountPreloads(); |
| 1314 | 1308 |
| 1315 std::unique_ptr<HTMLPreloadScanner> scanner = | 1309 std::unique_ptr<HTMLPreloadScanner> scanner = CreatePreloadScanner(); |
| 1316 CreatePreloadScanner(TokenPreloadScanner::ScannerType::kInsertion); | |
| 1317 scanner->AppendToEnd(SegmentedString(written_source)); | 1310 scanner->AppendToEnd(SegmentedString(written_source)); |
| 1318 ScanAndPreload(scanner.get()); | 1311 ScanAndPreload(scanner.get()); |
| 1319 | 1312 |
| 1320 int num_preloads = GetDocument()->Loader()->Fetcher()->CountPreloads() - | 1313 int num_preloads = GetDocument()->Loader()->Fetcher()->CountPreloads() - |
| 1321 current_preload_count; | 1314 current_preload_count; |
| 1322 | 1315 |
| 1323 TRACE_EVENT_INSTANT2( | 1316 TRACE_EVENT_INSTANT2( |
| 1324 "blink", | 1317 "blink", |
| 1325 "HTMLDocumentParser::evaluateAndPreloadScriptForDocumentWrite.data", | 1318 "HTMLDocumentParser::evaluateAndPreloadScriptForDocumentWrite.data", |
| 1326 TRACE_EVENT_SCOPE_THREAD, "numPreloads", num_preloads, "scriptLength", | 1319 TRACE_EVENT_SCOPE_THREAD, "numPreloads", num_preloads, "scriptLength", |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1340 success_histogram.Count(duration); | 1333 success_histogram.Count(duration); |
| 1341 } else { | 1334 } else { |
| 1342 DEFINE_STATIC_LOCAL( | 1335 DEFINE_STATIC_LOCAL( |
| 1343 CustomCountHistogram, failure_histogram, | 1336 CustomCountHistogram, failure_histogram, |
| 1344 ("PreloadScanner.DocumentWrite.ExecutionTime.Failure", 1, 10000, 50)); | 1337 ("PreloadScanner.DocumentWrite.ExecutionTime.Failure", 1, 10000, 50)); |
| 1345 failure_histogram.Count(duration); | 1338 failure_histogram.Count(duration); |
| 1346 } | 1339 } |
| 1347 } | 1340 } |
| 1348 | 1341 |
| 1349 } // namespace blink | 1342 } // namespace blink |
| OLD | NEW |