Chromium Code Reviews| 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 |
| 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 } | |
| 59 if (m_streamer) { | |
| 60 m_streamer->cancel(); | |
| 61 m_streamer->removeClient(client); | |
| 62 } else if (resource()) { | |
|
haraken
2014/09/10 05:57:52
How is it possible that resource() returns 0 here?
marja
2014/09/11 09:15:37
This code was originally in HTMLScriptRunner like
| |
| 52 resource()->removeClient(client); | 63 resource()->removeClient(client); |
| 53 m_watchingForLoad = false; | |
| 54 } | 64 } |
| 65 m_watchingForLoad = false; | |
| 55 } | 66 } |
| 56 | 67 |
| 57 PassRefPtrWillBeRawPtr<Element> PendingScript::releaseElementAndClear() | 68 PassRefPtrWillBeRawPtr<Element> PendingScript::releaseElementAndClear() |
| 58 { | 69 { |
| 59 setScriptResource(0); | 70 setScriptResource(0); |
| 60 m_watchingForLoad = false; | 71 m_watchingForLoad = false; |
| 61 m_startingPosition = TextPosition::belowRangePosition(); | 72 m_startingPosition = TextPosition::belowRangePosition(); |
| 62 return m_element.release(); | 73 return m_element.release(); |
| 63 } | 74 } |
| 64 | 75 |
| 65 void PendingScript::setScriptResource(ScriptResource* resource) | 76 void PendingScript::setScriptResource(ScriptResource* resource) |
| 66 { | 77 { |
| 67 setResource(resource); | 78 setResource(resource); |
| 79 // This function is only called 1) during construction (we're not yet | |
| 80 // streaming) 2) after loading has completed (and streaming too, if we were | |
| 81 // streaming). | |
| 82 ASSERT(!m_streamer || !m_streamer->streamingInProgress()); | |
|
haraken
2014/09/10 05:57:52
ASSERT(!isStreaming());
haraken
2014/09/10 05:57:52
Add ASSERT(!m_watchingForLoad);
marja
2014/09/11 09:15:37
Done.
marja
2014/09/11 09:15:37
Done.
marja
2014/09/16 11:20:38
Actually, this is not true in the current code (in
| |
| 83 m_streamer.release(); | |
| 68 } | 84 } |
| 69 | 85 |
| 70 void PendingScript::notifyFinished(Resource*) | 86 void PendingScript::notifyFinished(Resource*) |
| 71 { | 87 { |
| 88 if (m_streamer) { | |
| 89 m_streamer->notifyFinished(); | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 void PendingScript::notifyAppendData(ScriptResource*) | |
| 94 { | |
| 95 if (m_streamer) { | |
| 96 m_streamer->notifyAppendData(); | |
| 97 } | |
| 72 } | 98 } |
| 73 | 99 |
| 74 void PendingScript::trace(Visitor* visitor) | 100 void PendingScript::trace(Visitor* visitor) |
| 75 { | 101 { |
| 76 visitor->trace(m_element); | 102 visitor->trace(m_element); |
| 77 } | 103 } |
| 78 | 104 |
| 79 ScriptSourceCode PendingScript::getSource(const KURL& documentURL, bool& errorOc curred) const | 105 ScriptSourceCode PendingScript::getSource(const KURL& documentURL, bool& errorOc curred) const |
| 80 { | 106 { |
| 81 if (resource()) { | 107 if (resource()) { |
| 82 errorOccurred = resource()->errorOccurred(); | 108 errorOccurred = resource()->errorOccurred(); |
| 83 ASSERT(resource()->isLoaded()); | 109 ASSERT(resource()->isLoaded()); |
| 110 if (m_streamer && !m_streamer->streamingSuppressed()) { | |
|
haraken
2014/09/10 05:57:51
Help me understand: Why do we need this branch? Ca
marja
2014/09/11 09:15:37
We need to somehow take the results of streaming i
| |
| 111 return ScriptSourceCode(m_streamer, resource()); | |
| 112 } | |
| 84 return ScriptSourceCode(resource()); | 113 return ScriptSourceCode(resource()); |
| 85 } | 114 } |
| 86 errorOccurred = false; | 115 errorOccurred = false; |
| 87 return ScriptSourceCode(m_element->textContent(), documentURL, startingPosit ion()); | 116 return ScriptSourceCode(m_element->textContent(), documentURL, startingPosit ion()); |
| 88 } | 117 } |
| 89 | 118 |
| 119 bool PendingScript::isStreaming() const | |
| 120 { | |
| 121 return m_streamer && m_streamer->streamingInProgress(); | |
| 90 } | 122 } |
| 123 | |
| 124 } | |
| OLD | NEW |