Chromium Code Reviews| Index: Source/core/dom/SuspendableScriptExecutor.cpp |
| diff --git a/Source/core/dom/SuspendableScriptExecutor.cpp b/Source/core/dom/SuspendableScriptExecutor.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..de1f86fd652df71985a1b2dff3dd1f805e19ba18 |
| --- /dev/null |
| +++ b/Source/core/dom/SuspendableScriptExecutor.cpp |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2014 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 "config.h" |
| +#include "core/dom/SuspendableScriptExecutor.h" |
| + |
| +#include "bindings/core/v8/ScriptController.h" |
| +#include "core/dom/Document.h" |
| +#include "core/dom/ScriptExecutionCallback.h" |
| +#include "core/frame/LocalFrame.h" |
| +#include "platform/UserGestureIndicator.h" |
| +#include "public/platform/WebVector.h" |
| + |
| +namespace blink { |
| + |
| +SuspendableScriptExecutor::SuspendableScriptExecutor(LocalFrame* frame, int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, bool userGesture, PassOwnPtr<ScriptExecutionCallback> callback) |
| + : ActiveDOMObject(frame->document()) |
| + , m_frame(frame) |
| + , m_worldID(worldID) |
| + , m_sources(sources) |
| + , m_extensionGroup(extensionGroup) |
| + , m_userGesture(userGesture) |
| + , m_callback(callback) |
| +{ |
| +} |
| + |
| +SuspendableScriptExecutor::~SuspendableScriptExecutor() |
| +{ |
| +} |
| + |
| +void SuspendableScriptExecutor::run() |
| +{ |
| + suspendIfNeeded(); |
| + ExecutionContext* context = executionContext(); |
| + ASSERT(context); |
| + if (context && !context->activeDOMObjectsAreSuspended()) |
| + executeAndDestroySelf(); |
| +} |
| + |
| +void SuspendableScriptExecutor::resume() |
| +{ |
| + executeAndDestroySelf(); |
| +} |
| + |
| +void SuspendableScriptExecutor::contextDestroyed() |
| +{ |
| + ActiveDOMObject::contextDestroyed(); |
| + m_callback->completed(Vector<v8::Local<v8::Value> >()); |
| + delete this; |
| +} |
| + |
| +void SuspendableScriptExecutor::executeAndDestroySelf() |
| +{ |
| + OwnPtr<UserGestureIndicator> indicator; |
| + if (m_userGesture) |
| + indicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessingNewUserGesture)); |
| + |
| + v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| + Vector<v8::Local<v8::Value> > results; |
| + if (m_worldID) { |
| + m_frame->script().executeScriptInIsolatedWorld(m_worldID, m_sources, m_extensionGroup, &results); |
| + } else { |
| + v8::Local<v8::Value> scriptValue = m_frame->script().executeScriptInMainWorldAndReturnValue(m_sources.first()); |
| + results.append(scriptValue); |
| + } |
| + m_callback->completed(results); |
| + delete this; |
|
pfeldman
2014/10/22 15:38:17
You are at risk of deleting it twice.
pfeldman
2014/10/22 15:42:55
Lets comment on this.
kozyatinskiy1
2014/10/22 16:46:57
Done.
|
| +} |
| + |
| + |
| +} // namespace blink |