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 ASSERT(resource()); | |
| 60 if (m_streamer) { | |
| 61 m_streamer->cancel(); | |
| 62 m_streamer->removeClient(client); | |
|
haraken
2014/09/11 16:12:30
Shall we clear m_streamer ?
marja
2014/09/15 17:45:27
Yeah, we cancel() it here anyway, so why not. Done
| |
| 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 ASSERT(!m_watchingForLoad); | |
| 85 m_streamer.release(); | |
| 68 } | 86 } |
| 69 | 87 |
| 70 void PendingScript::notifyFinished(Resource*) | 88 void PendingScript::notifyFinished(Resource* resource) |
| 71 { | 89 { |
| 90 if (m_streamer) { | |
| 91 m_streamer->notifyFinished(resource); | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 void PendingScript::notifyAppendData(ScriptResource* resource) | |
| 96 { | |
| 97 if (m_streamer) { | |
| 98 m_streamer->notifyAppendData(resource); | |
| 99 } | |
| 72 } | 100 } |
| 73 | 101 |
| 74 void PendingScript::trace(Visitor* visitor) | 102 void PendingScript::trace(Visitor* visitor) |
| 75 { | 103 { |
| 76 visitor->trace(m_element); | 104 visitor->trace(m_element); |
| 77 } | 105 } |
| 78 | 106 |
| 79 ScriptSourceCode PendingScript::getSource(const KURL& documentURL, bool& errorOc curred) const | 107 ScriptSourceCode PendingScript::getSource(const KURL& documentURL, bool& errorOc curred) const |
| 80 { | 108 { |
| 81 if (resource()) { | 109 if (resource()) { |
| 82 errorOccurred = resource()->errorOccurred(); | 110 errorOccurred = resource()->errorOccurred(); |
| 83 ASSERT(resource()->isLoaded()); | 111 ASSERT(resource()->isLoaded()); |
| 112 if (m_streamer && !m_streamer->streamingSuppressed()) { | |
|
haraken
2014/09/11 16:12:30
Just to confirm: Is it possible that the streaming
marja
2014/09/15 17:45:27
You're correct, the answer is no. The streaming ca
| |
| 113 return ScriptSourceCode(m_streamer, resource()); | |
| 114 } | |
| 84 return ScriptSourceCode(resource()); | 115 return ScriptSourceCode(resource()); |
| 85 } | 116 } |
| 86 errorOccurred = false; | 117 errorOccurred = false; |
| 87 return ScriptSourceCode(m_element->textContent(), documentURL, startingPosit ion()); | 118 return ScriptSourceCode(m_element->textContent(), documentURL, startingPosit ion()); |
| 88 } | 119 } |
| 89 | 120 |
| 121 bool PendingScript::isStreaming() const | |
| 122 { | |
| 123 return m_streamer && m_streamer->streamingInProgress(); | |
| 90 } | 124 } |
| 125 | |
| 126 } | |
| OLD | NEW |