| 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 "web/SuspendableScriptExecutor.h" |
| 7 |
| 8 #include "bindings/core/v8/ScriptController.h" |
| 9 #include "core/dom/Document.h" |
| 10 #include "core/frame/LocalFrame.h" |
| 11 #include "platform/UserGestureIndicator.h" |
| 12 #include "public/platform/WebVector.h" |
| 13 #include "public/web/WebScriptExecutionCallback.h" |
| 14 |
| 15 namespace blink { |
| 16 |
| 17 SuspendableScriptExecutor::SuspendableScriptExecutor(LocalFrame* frame, int worl
dID, const Vector<ScriptSourceCode>& sources, int extensionGroup, bool userGestu
re, WebScriptExecutionCallback* callback) |
| 18 : ActiveDOMObject(frame->document()) |
| 19 , m_frame(frame) |
| 20 , m_worldID(worldID) |
| 21 , m_sources(sources) |
| 22 , m_extensionGroup(extensionGroup) |
| 23 , m_userGesture(userGesture) |
| 24 , m_callback(callback) |
| 25 { |
| 26 } |
| 27 |
| 28 SuspendableScriptExecutor::~SuspendableScriptExecutor() |
| 29 { |
| 30 } |
| 31 |
| 32 void SuspendableScriptExecutor::run() |
| 33 { |
| 34 suspendIfNeeded(); |
| 35 ExecutionContext* context = executionContext(); |
| 36 ASSERT(context); |
| 37 if (context && !context->activeDOMObjectsAreSuspended()) |
| 38 executeAndDestroySelf(); |
| 39 } |
| 40 |
| 41 void SuspendableScriptExecutor::resume() |
| 42 { |
| 43 executeAndDestroySelf(); |
| 44 } |
| 45 |
| 46 void SuspendableScriptExecutor::contextDestroyed() |
| 47 { |
| 48 // this method can only be called if the script was not called in run() |
| 49 // and context remained suspend (method resume has never called) |
| 50 ActiveDOMObject::contextDestroyed(); |
| 51 m_callback->completed(Vector<v8::Local<v8::Value> >()); |
| 52 delete this; |
| 53 } |
| 54 |
| 55 void SuspendableScriptExecutor::executeAndDestroySelf() |
| 56 { |
| 57 // after calling the destructor of object - object will be unsubscribed from |
| 58 // resumed and contextDestroyed LifecycleObserver methods |
| 59 OwnPtr<UserGestureIndicator> indicator; |
| 60 if (m_userGesture) |
| 61 indicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessingNewUse
rGesture)); |
| 62 |
| 63 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 64 Vector<v8::Local<v8::Value> > results; |
| 65 if (m_worldID) { |
| 66 m_frame->script().executeScriptInIsolatedWorld(m_worldID, m_sources, m_e
xtensionGroup, &results); |
| 67 } else { |
| 68 v8::Local<v8::Value> scriptValue = m_frame->script().executeScriptInMain
WorldAndReturnValue(m_sources.first()); |
| 69 results.append(scriptValue); |
| 70 } |
| 71 m_callback->completed(results); |
| 72 delete this; |
| 73 } |
| 74 |
| 75 |
| 76 } // namespace blink |
| OLD | NEW |