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

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

Issue 2862303002: Don't lower priority for scripts inserted by doc.write (Closed)
Patch Set: Created 3 years, 7 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 891
889 // We should never reach this point if we're using a parser thread, as 892 // We should never reach this point if we're using a parser thread, as
890 // appendBytes() will directly ship the data to the thread. 893 // appendBytes() will directly ship the data to the thread.
891 DCHECK(!ShouldUseThreading()); 894 DCHECK(!ShouldUseThreading());
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 if (!preload_scanner_) 901 if (!preload_scanner_) {
899 preload_scanner_ = CreatePreloadScanner(); 902 preload_scanner_ =
903 CreatePreloadScanner(TokenPreloadScanner::ScannerType::kMainDocument);
904 }
900 905
901 preload_scanner_->AppendToEnd(source); 906 preload_scanner_->AppendToEnd(source);
902 ScanAndPreload(preload_scanner_.get()); 907 ScanAndPreload(preload_scanner_.get());
903 908
904 // Return after the preload scanner, do not actually parse the document. 909 // Return after the preload scanner, do not actually parse the document.
905 return; 910 return;
906 } 911 }
907 912
908 if (preload_scanner_) { 913 if (preload_scanner_) {
909 if (input_.Current().IsEmpty() && !IsPaused()) { 914 if (input_.Current().IsEmpty() && !IsPaused()) {
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 WTF::Passed(TakeDecoder()))); 1250 WTF::Passed(TakeDecoder())));
1246 } 1251 }
1247 } 1252 }
1248 1253
1249 void HTMLDocumentParser::DocumentElementAvailable() { 1254 void HTMLDocumentParser::DocumentElementAvailable() {
1250 TRACE_EVENT0("blink,loader", "HTMLDocumentParser::documentElementAvailable"); 1255 TRACE_EVENT0("blink,loader", "HTMLDocumentParser::documentElementAvailable");
1251 DCHECK(GetDocument()->documentElement()); 1256 DCHECK(GetDocument()->documentElement());
1252 FetchQueuedPreloads(); 1257 FetchQueuedPreloads();
1253 } 1258 }
1254 1259
1255 std::unique_ptr<HTMLPreloadScanner> HTMLDocumentParser::CreatePreloadScanner() { 1260 std::unique_ptr<HTMLPreloadScanner> HTMLDocumentParser::CreatePreloadScanner(
1261 TokenPreloadScanner::ScannerType scanner_type) {
1256 return HTMLPreloadScanner::Create( 1262 return HTMLPreloadScanner::Create(
1257 options_, GetDocument()->Url(), 1263 options_, GetDocument()->Url(),
1258 CachedDocumentParameters::Create(GetDocument()), 1264 CachedDocumentParameters::Create(GetDocument()),
1259 MediaValuesCached::MediaValuesCachedData(*GetDocument())); 1265 MediaValuesCached::MediaValuesCachedData(*GetDocument()), scanner_type);
1260 } 1266 }
1261 1267
1262 void HTMLDocumentParser::ScanAndPreload(HTMLPreloadScanner* scanner) { 1268 void HTMLDocumentParser::ScanAndPreload(HTMLPreloadScanner* scanner) {
1263 PreloadRequestStream requests = 1269 PreloadRequestStream requests =
1264 scanner->Scan(GetDocument()->ValidBaseElementURL(), nullptr); 1270 scanner->Scan(GetDocument()->ValidBaseElementURL(), nullptr);
1265 preloader_->TakeAndPreload(requests); 1271 preloader_->TakeAndPreload(requests);
1266 } 1272 }
1267 1273
1268 void HTMLDocumentParser::FetchQueuedPreloads() { 1274 void HTMLDocumentParser::FetchQueuedPreloads() {
1269 if (pending_csp_meta_token_ || !GetDocument()->documentElement()) 1275 if (pending_csp_meta_token_ || !GetDocument()->documentElement())
(...skipping 25 matching lines...) Expand all
1295 double initialization_duration = 1301 double initialization_duration =
1296 MonotonicallyIncreasingTimeMS() - initialize_start_time; 1302 MonotonicallyIncreasingTimeMS() - initialize_start_time;
1297 1303
1298 double start_time = MonotonicallyIncreasingTimeMS(); 1304 double start_time = MonotonicallyIncreasingTimeMS();
1299 String written_source = evaluator_->EvaluateAndEmitWrittenSource(source); 1305 String written_source = evaluator_->EvaluateAndEmitWrittenSource(source);
1300 double duration = MonotonicallyIncreasingTimeMS() - start_time; 1306 double duration = MonotonicallyIncreasingTimeMS() - start_time;
1301 1307
1302 int current_preload_count = 1308 int current_preload_count =
1303 GetDocument()->Loader()->Fetcher()->CountPreloads(); 1309 GetDocument()->Loader()->Fetcher()->CountPreloads();
1304 1310
1305 std::unique_ptr<HTMLPreloadScanner> scanner = CreatePreloadScanner(); 1311 std::unique_ptr<HTMLPreloadScanner> scanner =
1312 CreatePreloadScanner(TokenPreloadScanner::ScannerType::kInsertion);
1306 scanner->AppendToEnd(SegmentedString(written_source)); 1313 scanner->AppendToEnd(SegmentedString(written_source));
1307 ScanAndPreload(scanner.get()); 1314 ScanAndPreload(scanner.get());
1308 1315
1309 int num_preloads = GetDocument()->Loader()->Fetcher()->CountPreloads() - 1316 int num_preloads = GetDocument()->Loader()->Fetcher()->CountPreloads() -
1310 current_preload_count; 1317 current_preload_count;
1311 1318
1312 TRACE_EVENT_INSTANT2( 1319 TRACE_EVENT_INSTANT2(
1313 "blink", 1320 "blink",
1314 "HTMLDocumentParser::evaluateAndPreloadScriptForDocumentWrite.data", 1321 "HTMLDocumentParser::evaluateAndPreloadScriptForDocumentWrite.data",
1315 TRACE_EVENT_SCOPE_THREAD, "numPreloads", num_preloads, "scriptLength", 1322 TRACE_EVENT_SCOPE_THREAD, "numPreloads", num_preloads, "scriptLength",
(...skipping 13 matching lines...) Expand all
1329 success_histogram.Count(duration); 1336 success_histogram.Count(duration);
1330 } else { 1337 } else {
1331 DEFINE_STATIC_LOCAL( 1338 DEFINE_STATIC_LOCAL(
1332 CustomCountHistogram, failure_histogram, 1339 CustomCountHistogram, failure_histogram,
1333 ("PreloadScanner.DocumentWrite.ExecutionTime.Failure", 1, 10000, 50)); 1340 ("PreloadScanner.DocumentWrite.ExecutionTime.Failure", 1, 10000, 50));
1334 failure_histogram.Count(duration); 1341 failure_histogram.Count(duration);
1335 } 1342 }
1336 } 1343 }
1337 1344
1338 } // namespace blink 1345 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698