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

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

Issue 2796653003: Move ScriptState::forWorld/ScriptState::forMainWorld (Part 2) (Closed)
Patch Set: Rebase 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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "core/html/parser/HTMLParserScriptRunner.h" 26 #include "core/html/parser/HTMLParserScriptRunner.h"
27 27
28 #include <inttypes.h>
29 #include <memory>
28 #include "bindings/core/v8/Microtask.h" 30 #include "bindings/core/v8/Microtask.h"
29 #include "bindings/core/v8/ScriptSourceCode.h" 31 #include "bindings/core/v8/ScriptSourceCode.h"
32 #include "bindings/core/v8/V8Binding.h"
30 #include "bindings/core/v8/V8PerIsolateData.h" 33 #include "bindings/core/v8/V8PerIsolateData.h"
31 #include "core/dom/DocumentParserTiming.h" 34 #include "core/dom/DocumentParserTiming.h"
32 #include "core/dom/Element.h" 35 #include "core/dom/Element.h"
33 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" 36 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h"
34 #include "core/dom/ScriptLoader.h" 37 #include "core/dom/ScriptLoader.h"
35 #include "core/dom/TaskRunnerHelper.h" 38 #include "core/dom/TaskRunnerHelper.h"
36 #include "core/events/Event.h" 39 #include "core/events/Event.h"
37 #include "core/frame/LocalFrame.h" 40 #include "core/frame/LocalFrame.h"
38 #include "core/html/parser/HTMLInputStream.h" 41 #include "core/html/parser/HTMLInputStream.h"
39 #include "core/html/parser/HTMLParserScriptRunnerHost.h" 42 #include "core/html/parser/HTMLParserScriptRunnerHost.h"
40 #include "core/html/parser/NestingLevelIncrementer.h" 43 #include "core/html/parser/NestingLevelIncrementer.h"
41 #include "core/inspector/ConsoleMessage.h" 44 #include "core/inspector/ConsoleMessage.h"
42 #include "core/loader/resource/ScriptResource.h" 45 #include "core/loader/resource/ScriptResource.h"
43 #include "platform/Histogram.h" 46 #include "platform/Histogram.h"
44 #include "platform/WebFrameScheduler.h" 47 #include "platform/WebFrameScheduler.h"
45 #include "platform/instrumentation/tracing/TraceEvent.h" 48 #include "platform/instrumentation/tracing/TraceEvent.h"
46 #include "platform/instrumentation/tracing/TracedValue.h" 49 #include "platform/instrumentation/tracing/TracedValue.h"
47 #include "platform/loader/fetch/MemoryCache.h" 50 #include "platform/loader/fetch/MemoryCache.h"
48 #include "public/platform/Platform.h" 51 #include "public/platform/Platform.h"
49 #include <inttypes.h>
50 #include <memory>
51 52
52 namespace blink { 53 namespace blink {
53 54
54 namespace { 55 namespace {
55 56
56 // TODO(bmcquade): move this to a shared location if we find ourselves wanting 57 // TODO(bmcquade): move this to a shared location if we find ourselves wanting
57 // to trace similar data elsewhere in the codebase. 58 // to trace similar data elsewhere in the codebase.
58 std::unique_ptr<TracedValue> getTraceArgsForScriptElement( 59 std::unique_ptr<TracedValue> getTraceArgsForScriptElement(
59 ScriptElementBase* element, 60 ScriptElementBase* element,
60 const TextPosition& textPosition) { 61 const TextPosition& textPosition) {
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 if (!parserBlockingScript()) 548 if (!parserBlockingScript())
548 return; 549 return;
549 550
550 DCHECK(parserBlockingScript()->resource()); 551 DCHECK(parserBlockingScript()->resource());
551 552
552 // We only care about a load callback if resource is not already in the cache. 553 // We only care about a load callback if resource is not already in the cache.
553 // Callers will attempt to run the m_parserBlockingScript if possible before 554 // Callers will attempt to run the m_parserBlockingScript if possible before
554 // returning control to the parser. 555 // returning control to the parser.
555 if (!parserBlockingScript()->isReady()) { 556 if (!parserBlockingScript()->isReady()) {
556 if (m_document->frame()) { 557 if (m_document->frame()) {
557 ScriptState* scriptState = ScriptState::forMainWorld(m_document->frame()); 558 ScriptState* scriptState = toScriptStateForMainWorld(m_document->frame());
558 if (scriptState) { 559 if (scriptState) {
559 ScriptStreamer::startStreaming( 560 ScriptStreamer::startStreaming(
560 m_parserBlockingScript, ScriptStreamer::ParsingBlocking, 561 m_parserBlockingScript, ScriptStreamer::ParsingBlocking,
561 m_document->frame()->settings(), scriptState, 562 m_document->frame()->settings(), scriptState,
562 TaskRunnerHelper::get(TaskType::Networking, m_document)); 563 TaskRunnerHelper::get(TaskType::Networking, m_document));
563 } 564 }
564 } 565 }
565 566
566 m_parserBlockingScript->watchForLoad(this); 567 m_parserBlockingScript->watchForLoad(this);
567 } 568 }
568 } 569 }
569 570
570 // 1st Clause, Step 23 of https://html.spec.whatwg.org/#prepare-a-script 571 // 1st Clause, Step 23 of https://html.spec.whatwg.org/#prepare-a-script
571 void HTMLParserScriptRunner::requestDeferredScript(Element* element) { 572 void HTMLParserScriptRunner::requestDeferredScript(Element* element) {
572 PendingScript* pendingScript = requestPendingScript(element); 573 PendingScript* pendingScript = requestPendingScript(element);
573 if (!pendingScript) 574 if (!pendingScript)
574 return; 575 return;
575 576
576 if (m_document->frame() && !pendingScript->isReady()) { 577 if (m_document->frame() && !pendingScript->isReady()) {
577 ScriptState* scriptState = ScriptState::forMainWorld(m_document->frame()); 578 ScriptState* scriptState = toScriptStateForMainWorld(m_document->frame());
578 if (scriptState) { 579 if (scriptState) {
579 ScriptStreamer::startStreaming( 580 ScriptStreamer::startStreaming(
580 pendingScript, ScriptStreamer::Deferred, 581 pendingScript, ScriptStreamer::Deferred,
581 m_document->frame()->settings(), scriptState, 582 m_document->frame()->settings(), scriptState,
582 TaskRunnerHelper::get(TaskType::Networking, m_document)); 583 TaskRunnerHelper::get(TaskType::Networking, m_document));
583 } 584 }
584 } 585 }
585 586
586 DCHECK(pendingScript->resource()); 587 DCHECK(pendingScript->resource());
587 588
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 691
691 DEFINE_TRACE(HTMLParserScriptRunner) { 692 DEFINE_TRACE(HTMLParserScriptRunner) {
692 visitor->trace(m_document); 693 visitor->trace(m_document);
693 visitor->trace(m_host); 694 visitor->trace(m_host);
694 visitor->trace(m_parserBlockingScript); 695 visitor->trace(m_parserBlockingScript);
695 visitor->trace(m_scriptsToExecuteAfterParsing); 696 visitor->trace(m_scriptsToExecuteAfterParsing);
696 PendingScriptClient::trace(visitor); 697 PendingScriptClient::trace(visitor);
697 } 698 }
698 699
699 } // namespace blink 700 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698