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/SuspendableScriptExecutor.h" | |
| 7 | |
| 8 #include "bindings/core/v8/ScriptController.h" | |
| 9 #include "core/dom/Document.h" | |
| 10 #include "core/dom/ScriptExecutionCallback.h" | |
| 11 #include "core/frame/LocalFrame.h" | |
| 12 #include "platform/UserGestureIndicator.h" | |
| 13 #include "public/platform/WebVector.h" | |
| 14 | |
| 15 namespace blink { | |
| 16 | |
| 17 SuspendableScriptExecutor::SuspendableScriptExecutor(LocalFrame* frame, int worl dID, const Vector<ScriptSourceCode>& sources, int extensionGroup, bool userGestu re, PassOwnPtr<ScriptExecutionCallback> 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 ActiveDOMObject::contextDestroyed(); | |
| 49 m_callback->completed(Vector<v8::Local<v8::Value> >()); | |
| 50 delete this; | |
| 51 } | |
| 52 | |
| 53 void SuspendableScriptExecutor::executeAndDestroySelf() | |
| 54 { | |
| 55 OwnPtr<UserGestureIndicator> indicator; | |
| 56 if (m_userGesture) | |
| 57 indicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessingNewUse rGesture)); | |
| 58 | |
| 59 v8::HandleScope scope(v8::Isolate::GetCurrent()); | |
| 60 Vector<v8::Local<v8::Value> > results; | |
| 61 if (m_worldID) { | |
| 62 m_frame->script().executeScriptInIsolatedWorld(m_worldID, m_sources, m_e xtensionGroup, &results); | |
| 63 } else { | |
| 64 v8::Local<v8::Value> scriptValue = m_frame->script().executeScriptInMain WorldAndReturnValue(m_sources.first()); | |
| 65 results.append(scriptValue); | |
| 66 } | |
| 67 m_callback->completed(results); | |
| 68 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.
| |
| 69 } | |
| 70 | |
| 71 | |
| 72 } // namespace blink | |
| OLD | NEW |