Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "core/dom/SuspendableScriptRunner.h" | |
| 7 | |
| 8 #include "bindings/core/v8/ScriptController.h" | |
| 9 #include "core/dom/Document.h" | |
| 10 #include "core/frame/LocalFrame.h" | |
| 11 #include "public/platform/WebVector.h" | |
| 12 #include "public/web/WebScriptCallback.h" | |
| 13 | |
| 14 namespace blink { | |
| 15 | |
| 16 SuspendableScriptRunner::SuspendableScriptRunner(LocalFrame* frame, int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, WebScriptCallback* callback) | |
| 17 : ActiveDOMObject(frame->document()) | |
| 18 , m_frame(frame) | |
| 19 , m_worldID(worldID) | |
| 20 , m_sources(sources) | |
| 21 , m_extensionGroup(extensionGroup) | |
| 22 , m_callback(callback) | |
| 23 { | |
| 24 } | |
| 25 | |
| 26 SuspendableScriptRunner::~SuspendableScriptRunner() | |
| 27 { | |
| 28 } | |
| 29 | |
| 30 void SuspendableScriptRunner::run() | |
| 31 { | |
| 32 suspendIfNeeded(); | |
| 33 ExecutionContext* context = executionContext(); | |
| 34 ASSERT(context); | |
| 35 if (context && !context->activeDOMObjectsAreSuspended()) | |
| 36 execute(); // delete this | |
|
vsevik
2014/10/20 16:50:37
executeAndDestroySelf() ?
kozyatinskiy1
2014/10/21 12:46:47
Done.
| |
| 37 } | |
| 38 | |
| 39 void SuspendableScriptRunner::resume() | |
| 40 { | |
| 41 execute(); // delete this | |
| 42 } | |
| 43 | |
| 44 void SuspendableScriptRunner::contextDestroyed() | |
| 45 { | |
| 46 ActiveDOMObject::contextDestroyed(); | |
| 47 m_callback->finished(Vector<v8::Local<v8::Value> >()); | |
| 48 delete this; | |
| 49 } | |
| 50 | |
| 51 void SuspendableScriptRunner::execute() | |
| 52 { | |
| 53 v8::HandleScope scope(v8::Isolate::GetCurrent()); | |
| 54 Vector<v8::Local<v8::Value> > results; | |
| 55 if (m_worldID) { | |
| 56 m_frame->script().executeScriptInIsolatedWorld(m_worldID, m_sources, m_e xtensionGroup, &results); | |
| 57 } else { | |
| 58 v8::Local<v8::Value> scriptValue = m_frame->script().executeScriptInMain WorldAndReturnValue(m_sources.first()); | |
| 59 results.append(scriptValue); | |
| 60 } | |
| 61 m_callback->finished(results); | |
| 62 delete this; | |
| 63 } | |
| 64 | |
| 65 | |
| 66 } // namespace blink | |
| OLD | NEW |