Index: third_party/WebKit/Source/core/dom/ClassicPendingScript.cpp |
diff --git a/third_party/WebKit/Source/core/dom/PendingScript.cpp b/third_party/WebKit/Source/core/dom/ClassicPendingScript.cpp |
similarity index 53% |
copy from third_party/WebKit/Source/core/dom/PendingScript.cpp |
copy to third_party/WebKit/Source/core/dom/ClassicPendingScript.cpp |
index e9cd5ab012ca4d19f1cfbdbfd6a9001076ccb32c..d6a9c82697185f2d3640e684b78009c847547ec5 100644 |
--- a/third_party/WebKit/Source/core/dom/PendingScript.cpp |
+++ b/third_party/WebKit/Source/core/dom/ClassicPendingScript.cpp |
@@ -1,141 +1,70 @@ |
-/* |
- * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
- * |
- * Redistribution and use in source and binary forms, with or without |
- * modification, are permitted provided that the following conditions |
- * are met: |
- * 1. Redistributions of source code must retain the above copyright |
- * notice, this list of conditions and the following disclaimer. |
- * 2. Redistributions in binary form must reproduce the above copyright |
- * notice, this list of conditions and the following disclaimer in the |
- * documentation and/or other materials provided with the distribution. |
- * |
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
- */ |
- |
-#include "core/dom/PendingScript.h" |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "core/dom/ClassicPendingScript.h" |
#include "bindings/core/v8/ScriptSourceCode.h" |
#include "bindings/core/v8/ScriptState.h" |
#include "bindings/core/v8/V8Binding.h" |
-#include "core/dom/ClassicScript.h" |
#include "core/dom/Document.h" |
-#include "core/dom/ScriptElementBase.h" |
#include "core/dom/TaskRunnerHelper.h" |
#include "core/frame/LocalFrame.h" |
#include "core/frame/SubresourceIntegrity.h" |
-#include "platform/SharedBuffer.h" |
-#include "wtf/CurrentTime.h" |
namespace blink { |
-PendingScript* PendingScript::create(ScriptElementBase* element, |
- ScriptResource* resource) { |
- return new PendingScript(element, resource, TextPosition()); |
+ClassicPendingScript* ClassicPendingScript::create(ScriptElementBase* element, |
+ ScriptResource* resource) { |
+ return new ClassicPendingScript(element, resource, TextPosition()); |
} |
-PendingScript* PendingScript::create(ScriptElementBase* element, |
- const TextPosition& startingPosition) { |
- return new PendingScript(element, nullptr, startingPosition); |
+ClassicPendingScript* ClassicPendingScript::create( |
+ ScriptElementBase* element, |
+ const TextPosition& startingPosition) { |
+ return new ClassicPendingScript(element, nullptr, startingPosition); |
} |
-PendingScript* PendingScript::createForTesting(ScriptResource* resource) { |
- return new PendingScript(nullptr, resource, TextPosition(), true); |
+ClassicPendingScript* ClassicPendingScript::createForTesting( |
+ ScriptResource* resource) { |
+ return new ClassicPendingScript(nullptr, resource, TextPosition(), true); |
} |
-PendingScript::PendingScript(ScriptElementBase* element, |
- ScriptResource* resource, |
- const TextPosition& startingPosition, |
- bool isForTesting) |
- : m_watchingForLoad(false), |
- m_element(element), |
- m_startingPosition(startingPosition), |
+ClassicPendingScript::ClassicPendingScript(ScriptElementBase* element, |
+ ScriptResource* resource, |
+ const TextPosition& startingPosition, |
+ bool isForTesting) |
+ : PendingScript(element, startingPosition), |
m_integrityFailure(false), |
- m_parserBlockingLoadStartTime(0), |
- m_client(nullptr), |
m_isForTesting(isForTesting) { |
checkState(); |
setResource(resource); |
MemoryCoordinator::instance().registerClient(this); |
} |
-PendingScript::~PendingScript() {} |
+ClassicPendingScript::~ClassicPendingScript() {} |
-NOINLINE void PendingScript::checkState() const { |
+NOINLINE void ClassicPendingScript::checkState() const { |
// TODO(hiroshige): Turn these CHECK()s into DCHECK() before going to beta. |
- CHECK(m_isForTesting || m_element); |
+ CHECK(m_isForTesting || element()); |
CHECK(resource() || !m_streamer); |
CHECK(!m_streamer || m_streamer->resource() == resource()); |
} |
-void PendingScript::dispose() { |
- stopWatchingForLoad(); |
- DCHECK(!m_client); |
- DCHECK(!m_watchingForLoad); |
- |
+void ClassicPendingScript::disposeInternal() { |
MemoryCoordinator::instance().unregisterClient(this); |
setResource(nullptr); |
- m_startingPosition = TextPosition::belowRangePosition(); |
m_integrityFailure = false; |
- m_parserBlockingLoadStartTime = 0; |
if (m_streamer) |
m_streamer->cancel(); |
m_streamer = nullptr; |
- m_element = nullptr; |
-} |
- |
-void PendingScript::watchForLoad(PendingScriptClient* client) { |
- checkState(); |
- |
- DCHECK(!m_watchingForLoad); |
- // addClient() will call streamingFinished() if the load is complete. Callers |
- // who do not expect to be re-entered from this call should not call |
- // watchForLoad for a PendingScript which isReady. We also need to set |
- // m_watchingForLoad early, since addClient() can result in calling |
- // notifyFinished and further stopWatchingForLoad(). |
- m_watchingForLoad = true; |
- m_client = client; |
- if (isReady()) |
- m_client->pendingScriptFinished(this); |
} |
-void PendingScript::stopWatchingForLoad() { |
- if (!m_watchingForLoad) |
- return; |
+void ClassicPendingScript::streamingFinished() { |
checkState(); |
DCHECK(resource()); |
- m_client = nullptr; |
- m_watchingForLoad = false; |
-} |
- |
-ScriptElementBase* PendingScript::element() const { |
- // As mentioned in the comment at |m_element| declaration, |
- // |m_element| must point to the corresponding ScriptLoader's |
- // client. |
- CHECK(m_element); |
- return m_element.get(); |
-} |
- |
-void PendingScript::streamingFinished() { |
- checkState(); |
- DCHECK(resource()); |
- if (m_client) |
- m_client->pendingScriptFinished(this); |
-} |
- |
-void PendingScript::markParserBlockingLoadStartTime() { |
- DCHECK_EQ(m_parserBlockingLoadStartTime, 0.0); |
- m_parserBlockingLoadStartTime = monotonicallyIncreasingTime(); |
+ if (client()) |
+ client()->pendingScriptFinished(this); |
} |
// Returns true if SRI check passed. |
@@ -182,7 +111,7 @@ static bool checkScriptResourceIntegrity(Resource* resource, |
return true; |
} |
-void PendingScript::notifyFinished(Resource* resource) { |
+void ClassicPendingScript::notifyFinished(Resource* resource) { |
// The following SRI checks need to be here because, unfortunately, fetches |
// are not done purely according to the Fetch spec. In particular, |
// different requests for the same resource do not have different |
@@ -206,33 +135,32 @@ void PendingScript::notifyFinished(Resource* resource) { |
// |
// See https://crbug.com/500701 for more information. |
checkState(); |
- if (m_element) { |
- m_integrityFailure = !checkScriptResourceIntegrity(resource, m_element); |
+ if (!m_isForTesting && element()) { |
+ m_integrityFailure = !checkScriptResourceIntegrity(resource, element()); |
} |
// If script streaming is in use, the client will be notified in |
// streamingFinished. |
if (m_streamer) |
m_streamer->notifyFinished(resource); |
- else if (m_client) |
- m_client->pendingScriptFinished(this); |
+ else if (client()) |
+ client()->pendingScriptFinished(this); |
} |
-void PendingScript::notifyAppendData(ScriptResource* resource) { |
+void ClassicPendingScript::notifyAppendData(ScriptResource* resource) { |
if (m_streamer) |
m_streamer->notifyAppendData(resource); |
} |
-DEFINE_TRACE(PendingScript) { |
- visitor->trace(m_element); |
+DEFINE_TRACE(ClassicPendingScript) { |
visitor->trace(m_streamer); |
- visitor->trace(m_client); |
ResourceOwner<ScriptResource>::trace(visitor); |
MemoryCoordinatorClient::trace(visitor); |
+ PendingScript::trace(visitor); |
} |
-ClassicScript* PendingScript::getSource(const KURL& documentURL, |
- bool& errorOccurred) const { |
+ClassicScript* ClassicPendingScript::getSource(const KURL& documentURL, |
+ bool& errorOccurred) const { |
checkState(); |
errorOccurred = this->errorOccurred(); |
@@ -244,17 +172,17 @@ ClassicScript* PendingScript::getSource(const KURL& documentURL, |
} |
return ClassicScript::create(ScriptSourceCode( |
- m_element->textContent(), documentURL, startingPosition())); |
+ element()->textContent(), documentURL, startingPosition())); |
} |
-void PendingScript::setStreamer(ScriptStreamer* streamer) { |
+void ClassicPendingScript::setStreamer(ScriptStreamer* streamer) { |
DCHECK(!m_streamer); |
- DCHECK(!m_watchingForLoad); |
+ DCHECK(!isWatchingForLoad()); |
m_streamer = streamer; |
checkState(); |
} |
-bool PendingScript::isReady() const { |
+bool ClassicPendingScript::isReady() const { |
checkState(); |
if (resource()) { |
return resource()->isLoaded() && (!m_streamer || m_streamer->isFinished()); |
@@ -263,7 +191,7 @@ bool PendingScript::isReady() const { |
return true; |
} |
-bool PendingScript::errorOccurred() const { |
+bool ClassicPendingScript::errorOccurred() const { |
checkState(); |
if (resource()) |
return resource()->errorOccurred() || m_integrityFailure; |
@@ -271,7 +199,7 @@ bool PendingScript::errorOccurred() const { |
return false; |
} |
-void PendingScript::onPurgeMemory() { |
+void ClassicPendingScript::onPurgeMemory() { |
checkState(); |
if (!m_streamer) |
return; |
@@ -279,7 +207,7 @@ void PendingScript::onPurgeMemory() { |
m_streamer = nullptr; |
} |
-void PendingScript::startStreamingIfPossible( |
+void ClassicPendingScript::startStreamingIfPossible( |
Document* document, |
ScriptStreamer::Type streamerType) { |
if (!document->frame()) |
@@ -294,4 +222,12 @@ void PendingScript::startStreamingIfPossible( |
TaskRunnerHelper::get(TaskType::Networking, document)); |
} |
+bool ClassicPendingScript::wasCanceled() const { |
+ return resource()->wasCanceled(); |
+} |
+ |
+KURL ClassicPendingScript::url() const { |
+ return resource()->url(); |
+} |
+ |
} // namespace blink |