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

Side by Side Diff: Source/core/dom/PendingScript.cpp

Issue 368283002: Stream scripts to V8 as they load - Blink side. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: removed untrue assert Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/PendingScript.h ('k') | Source/core/dom/ScriptLoader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "config.h" 26 #include "config.h"
27 #include "core/dom/PendingScript.h" 27 #include "core/dom/PendingScript.h"
28 28
29 #include "bindings/core/v8/ScriptStreamer.h"
29 #include "core/dom/Element.h" 30 #include "core/dom/Element.h"
30 #include "core/fetch/ScriptResource.h" 31 #include "core/fetch/ScriptResource.h"
31 32
32 namespace blink { 33 namespace blink {
33 34
34 PendingScript::~PendingScript() 35 PendingScript::~PendingScript()
35 { 36 {
36 } 37 }
37 38
38 void PendingScript::watchForLoad(ResourceClient* client) 39 void PendingScript::watchForLoad(ScriptResourceClient* client)
39 { 40 {
40 ASSERT(!m_watchingForLoad); 41 ASSERT(!m_watchingForLoad);
41 ASSERT(!resource()->isLoaded()); 42 ASSERT(!resource()->isLoaded());
42 // addClient() will call notifyFinished() if the load is complete. Callers 43 if (m_streamer) {
43 // do not expect to be re-entered from this call, so they should not become 44 m_streamer->addClient(client);
44 // a client of an already-loaded Resource. 45 } else {
45 resource()->addClient(client); 46 // addClient() will call notifyFinished() if the load is
47 // complete. Callers do not expect to be re-entered from this call, so
48 // they should not become a client of an already-loaded Resource.
49 resource()->addClient(client);
50 }
46 m_watchingForLoad = true; 51 m_watchingForLoad = true;
47 } 52 }
48 53
49 void PendingScript::stopWatchingForLoad(ResourceClient* client) 54 void PendingScript::stopWatchingForLoad(ScriptResourceClient* client)
50 { 55 {
51 if (resource() && m_watchingForLoad) { 56 if (!m_watchingForLoad)
57 return;
58 ASSERT(resource());
59 if (m_streamer) {
60 m_streamer->cancel();
61 m_streamer->removeClient(client);
62 m_streamer.clear();
63 } else {
52 resource()->removeClient(client); 64 resource()->removeClient(client);
53 m_watchingForLoad = false;
54 } 65 }
66 m_watchingForLoad = false;
55 } 67 }
56 68
57 PassRefPtrWillBeRawPtr<Element> PendingScript::releaseElementAndClear() 69 PassRefPtrWillBeRawPtr<Element> PendingScript::releaseElementAndClear()
58 { 70 {
59 setScriptResource(0); 71 setScriptResource(0);
60 m_watchingForLoad = false; 72 m_watchingForLoad = false;
61 m_startingPosition = TextPosition::belowRangePosition(); 73 m_startingPosition = TextPosition::belowRangePosition();
62 return m_element.release(); 74 return m_element.release();
63 } 75 }
64 76
65 void PendingScript::setScriptResource(ScriptResource* resource) 77 void PendingScript::setScriptResource(ScriptResource* resource)
66 { 78 {
67 setResource(resource); 79 setResource(resource);
80 // This function is only called 1) during construction (we're not yet
81 // streaming) 2) after loading has completed (and streaming too, if we were
82 // streaming).
83 ASSERT(!isStreaming());
84 m_streamer.release();
68 } 85 }
69 86
70 void PendingScript::notifyFinished(Resource*) 87 void PendingScript::notifyFinished(Resource* resource)
71 { 88 {
89 if (m_streamer)
90 m_streamer->notifyFinished(resource);
91 }
92
93 void PendingScript::notifyAppendData(ScriptResource* resource)
94 {
95 if (m_streamer)
96 m_streamer->notifyAppendData(resource);
72 } 97 }
73 98
74 void PendingScript::trace(Visitor* visitor) 99 void PendingScript::trace(Visitor* visitor)
75 { 100 {
76 visitor->trace(m_element); 101 visitor->trace(m_element);
77 } 102 }
78 103
79 ScriptSourceCode PendingScript::getSource(const KURL& documentURL, bool& errorOc curred) const 104 ScriptSourceCode PendingScript::getSource(const KURL& documentURL, bool& errorOc curred) const
80 { 105 {
81 if (resource()) { 106 if (resource()) {
82 errorOccurred = resource()->errorOccurred(); 107 errorOccurred = resource()->errorOccurred();
83 ASSERT(resource()->isLoaded()); 108 ASSERT(resource()->isLoaded());
109 if (m_streamer && !m_streamer->streamingSuppressed())
110 return ScriptSourceCode(m_streamer, resource());
84 return ScriptSourceCode(resource()); 111 return ScriptSourceCode(resource());
85 } 112 }
86 errorOccurred = false; 113 errorOccurred = false;
87 return ScriptSourceCode(m_element->textContent(), documentURL, startingPosit ion()); 114 return ScriptSourceCode(m_element->textContent(), documentURL, startingPosit ion());
88 } 115 }
89 116
117 bool PendingScript::isStreaming() const
118 {
119 return m_streamer && m_streamer->streamingInProgress();
90 } 120 }
121
122 }
OLDNEW
« no previous file with comments | « Source/core/dom/PendingScript.h ('k') | Source/core/dom/ScriptLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698