Chromium Code Reviews| Index: Source/core/dom/SuspendableScriptRunner.cpp |
| diff --git a/Source/core/dom/SuspendableScriptRunner.cpp b/Source/core/dom/SuspendableScriptRunner.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..743290f0dbcf7e0670fbe18635eaf4e2a7983166 |
| --- /dev/null |
| +++ b/Source/core/dom/SuspendableScriptRunner.cpp |
| @@ -0,0 +1,66 @@ |
| +// 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/SuspendableScriptRunner.h" |
| + |
| +#include "bindings/core/v8/ScriptController.h" |
| +#include "core/dom/Document.h" |
| +#include "core/frame/LocalFrame.h" |
| +#include "public/platform/WebVector.h" |
| +#include "public/web/WebScriptCallback.h" |
| + |
| +namespace blink { |
| + |
| +SuspendableScriptRunner::SuspendableScriptRunner(LocalFrame* frame, int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, WebScriptCallback* callback) |
| + : ActiveDOMObject(frame->document()) |
| + , m_frame(frame) |
| + , m_worldID(worldID) |
| + , m_sources(sources) |
| + , m_extensionGroup(extensionGroup) |
| + , m_callback(callback) |
| +{ |
| +} |
| + |
| +SuspendableScriptRunner::~SuspendableScriptRunner() |
| +{ |
| +} |
| + |
| +void SuspendableScriptRunner::run() |
| +{ |
| + suspendIfNeeded(); |
| + ExecutionContext* context = executionContext(); |
| + ASSERT(context); |
| + if (context && !context->activeDOMObjectsAreSuspended()) |
| + execute(); // delete this |
|
vsevik
2014/10/20 16:50:37
executeAndDestroySelf() ?
kozyatinskiy1
2014/10/21 12:46:47
Done.
|
| +} |
| + |
| +void SuspendableScriptRunner::resume() |
| +{ |
| + execute(); // delete this |
| +} |
| + |
| +void SuspendableScriptRunner::contextDestroyed() |
| +{ |
| + ActiveDOMObject::contextDestroyed(); |
| + m_callback->finished(Vector<v8::Local<v8::Value> >()); |
| + delete this; |
| +} |
| + |
| +void SuspendableScriptRunner::execute() |
| +{ |
| + 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->finished(results); |
| + delete this; |
| +} |
| + |
| + |
| +} // namespace blink |