Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLDocumentParser.cpp

Issue 2826213003: Don't lower priority for scripts inserted by doc.write (Closed)
Patch Set: Fixed duplicate URLs in Layout test Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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);
726 preload_scanner_->AppendToEnd(input_.Current()); 727 preload_scanner_->AppendToEnd(input_.Current());
727 } 728 }
728 ScanAndPreload(preload_scanner_.get()); 729 ScanAndPreload(preload_scanner_.get());
729 } 730 }
730 } 731 }
731 } 732 }
732 733
733 void HTMLDocumentParser::ConstructTreeFromHTMLToken() { 734 void HTMLDocumentParser::ConstructTreeFromHTMLToken() {
734 AtomicHTMLToken atomic_token(Token()); 735 AtomicHTMLToken atomic_token(Token());
735 736
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 } 791 }
791 792
792 SegmentedString excluded_line_number_source(source); 793 SegmentedString excluded_line_number_source(source);
793 excluded_line_number_source.SetExcludeLineNumbers(); 794 excluded_line_number_source.SetExcludeLineNumbers();
794 input_.InsertAtCurrentInsertionPoint(excluded_line_number_source); 795 input_.InsertAtCurrentInsertionPoint(excluded_line_number_source);
795 PumpTokenizerIfPossible(); 796 PumpTokenizerIfPossible();
796 797
797 if (IsPaused()) { 798 if (IsPaused()) {
798 // Check the document.write() output with a separate preload scanner as 799 // Check the document.write() output with a separate preload scanner as
799 // the main scanner can't deal with insertions. 800 // the main scanner can't deal with insertions.
800 if (!insertion_preload_scanner_) 801 if (!insertion_preload_scanner_) {
801 insertion_preload_scanner_ = CreatePreloadScanner(); 802 insertion_preload_scanner_ =
803 CreatePreloadScanner(TokenPreloadScanner::ScannerType::kInsertion);
804 }
802 insertion_preload_scanner_->AppendToEnd(source); 805 insertion_preload_scanner_->AppendToEnd(source);
803 ScanAndPreload(insertion_preload_scanner_.get()); 806 ScanAndPreload(insertion_preload_scanner_.get());
804 } 807 }
805 808
806 EndIfDelayed(); 809 EndIfDelayed();
807 } 810 }
808 811
809 void HTMLDocumentParser::StartBackgroundParser() { 812 void HTMLDocumentParser::StartBackgroundParser() {
810 DCHECK(!IsStopped()); 813 DCHECK(!IsStopped());
811 DCHECK(ShouldUseThreading()); 814 DCHECK(ShouldUseThreading());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 895
893 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.debug"), 896 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.debug"),
894 "HTMLDocumentParser::append", "size", input_source.length()); 897 "HTMLDocumentParser::append", "size", input_source.length());
895 const SegmentedString source(input_source); 898 const SegmentedString source(input_source);
896 899
897 if (GetDocument()->IsPrefetchOnly()) { 900 if (GetDocument()->IsPrefetchOnly()) {
898 // Do not prefetch if there is an appcache. 901 // Do not prefetch if there is an appcache.
899 if (GetDocument()->Loader()->GetResponse().AppCacheID() != 0) 902 if (GetDocument()->Loader()->GetResponse().AppCacheID() != 0)
900 return; 903 return;
901 904
902 if (!preload_scanner_) 905 if (!preload_scanner_) {
903 preload_scanner_ = CreatePreloadScanner(); 906 preload_scanner_ =
907 CreatePreloadScanner(TokenPreloadScanner::ScannerType::kMainDocument);
908 }
904 909
905 preload_scanner_->AppendToEnd(source); 910 preload_scanner_->AppendToEnd(source);
906 ScanAndPreload(preload_scanner_.get()); 911 ScanAndPreload(preload_scanner_.get());
907 912
908 // Return after the preload scanner, do not actually parse the document. 913 // Return after the preload scanner, do not actually parse the document.
909 return; 914 return;
910 } 915 }
911 916
912 if (preload_scanner_) { 917 if (preload_scanner_) {
913 if (input_.Current().IsEmpty() && !IsPaused()) { 918 if (input_.Current().IsEmpty() && !IsPaused()) {
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 WTF::Passed(TakeDecoder()))); 1254 WTF::Passed(TakeDecoder())));
1250 } 1255 }
1251 } 1256 }
1252 1257
1253 void HTMLDocumentParser::DocumentElementAvailable() { 1258 void HTMLDocumentParser::DocumentElementAvailable() {
1254 TRACE_EVENT0("blink,loader", "HTMLDocumentParser::documentElementAvailable"); 1259 TRACE_EVENT0("blink,loader", "HTMLDocumentParser::documentElementAvailable");
1255 DCHECK(GetDocument()->documentElement()); 1260 DCHECK(GetDocument()->documentElement());
1256 FetchQueuedPreloads(); 1261 FetchQueuedPreloads();
1257 } 1262 }
1258 1263
1259 std::unique_ptr<HTMLPreloadScanner> HTMLDocumentParser::CreatePreloadScanner() { 1264 std::unique_ptr<HTMLPreloadScanner> HTMLDocumentParser::CreatePreloadScanner(
1265 TokenPreloadScanner::ScannerType scanner_type) {
1260 return HTMLPreloadScanner::Create( 1266 return HTMLPreloadScanner::Create(
1261 options_, GetDocument()->Url(), 1267 options_, GetDocument()->Url(),
1262 CachedDocumentParameters::Create(GetDocument()), 1268 CachedDocumentParameters::Create(GetDocument()),
1263 MediaValuesCached::MediaValuesCachedData(*GetDocument())); 1269 MediaValuesCached::MediaValuesCachedData(*GetDocument()), scanner_type);
1264 } 1270 }
1265 1271
1266 void HTMLDocumentParser::ScanAndPreload(HTMLPreloadScanner* scanner) { 1272 void HTMLDocumentParser::ScanAndPreload(HTMLPreloadScanner* scanner) {
1267 PreloadRequestStream requests = 1273 PreloadRequestStream requests =
1268 scanner->Scan(GetDocument()->ValidBaseElementURL(), nullptr); 1274 scanner->Scan(GetDocument()->ValidBaseElementURL(), nullptr);
1269 preloader_->TakeAndPreload(requests); 1275 preloader_->TakeAndPreload(requests);
1270 } 1276 }
1271 1277
1272 void HTMLDocumentParser::FetchQueuedPreloads() { 1278 void HTMLDocumentParser::FetchQueuedPreloads() {
1273 if (pending_csp_meta_token_ || !GetDocument()->documentElement()) 1279 if (pending_csp_meta_token_ || !GetDocument()->documentElement())
(...skipping 25 matching lines...) Expand all
1299 double initialization_duration = 1305 double initialization_duration =
1300 MonotonicallyIncreasingTimeMS() - initialize_start_time; 1306 MonotonicallyIncreasingTimeMS() - initialize_start_time;
1301 1307
1302 double start_time = MonotonicallyIncreasingTimeMS(); 1308 double start_time = MonotonicallyIncreasingTimeMS();
1303 String written_source = evaluator_->EvaluateAndEmitWrittenSource(source); 1309 String written_source = evaluator_->EvaluateAndEmitWrittenSource(source);
1304 double duration = MonotonicallyIncreasingTimeMS() - start_time; 1310 double duration = MonotonicallyIncreasingTimeMS() - start_time;
1305 1311
1306 int current_preload_count = 1312 int current_preload_count =
1307 GetDocument()->Loader()->Fetcher()->CountPreloads(); 1313 GetDocument()->Loader()->Fetcher()->CountPreloads();
1308 1314
1309 std::unique_ptr<HTMLPreloadScanner> scanner = CreatePreloadScanner(); 1315 std::unique_ptr<HTMLPreloadScanner> scanner =
1316 CreatePreloadScanner(TokenPreloadScanner::ScannerType::kInsertion);
1310 scanner->AppendToEnd(SegmentedString(written_source)); 1317 scanner->AppendToEnd(SegmentedString(written_source));
1311 ScanAndPreload(scanner.get()); 1318 ScanAndPreload(scanner.get());
1312 1319
1313 int num_preloads = GetDocument()->Loader()->Fetcher()->CountPreloads() - 1320 int num_preloads = GetDocument()->Loader()->Fetcher()->CountPreloads() -
1314 current_preload_count; 1321 current_preload_count;
1315 1322
1316 TRACE_EVENT_INSTANT2( 1323 TRACE_EVENT_INSTANT2(
1317 "blink", 1324 "blink",
1318 "HTMLDocumentParser::evaluateAndPreloadScriptForDocumentWrite.data", 1325 "HTMLDocumentParser::evaluateAndPreloadScriptForDocumentWrite.data",
1319 TRACE_EVENT_SCOPE_THREAD, "numPreloads", num_preloads, "scriptLength", 1326 TRACE_EVENT_SCOPE_THREAD, "numPreloads", num_preloads, "scriptLength",
(...skipping 13 matching lines...) Expand all
1333 success_histogram.Count(duration); 1340 success_histogram.Count(duration);
1334 } else { 1341 } else {
1335 DEFINE_STATIC_LOCAL( 1342 DEFINE_STATIC_LOCAL(
1336 CustomCountHistogram, failure_histogram, 1343 CustomCountHistogram, failure_histogram,
1337 ("PreloadScanner.DocumentWrite.ExecutionTime.Failure", 1, 10000, 50)); 1344 ("PreloadScanner.DocumentWrite.ExecutionTime.Failure", 1, 10000, 50));
1338 failure_histogram.Count(duration); 1345 failure_histogram.Count(duration);
1339 } 1346 }
1340 } 1347 }
1341 1348
1342 } // namespace blink 1349 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698