Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(876)

Side by Side Diff: Source/core/dom/SuspendableScriptRunner.cpp

Issue 660863002: [DevTools] Added public method for async execution of scripts (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/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 SuspendableScriptRunner::SuspendableScriptRunner(LocalFrame* frame, int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, bool userGesture, PassOwnPtr<ScriptExecutionCallback> client)
vsevik 2014/10/22 13:29:00 PassOwnPtr<ScriptExecutionCallback> callback
kozyatinskiy1 2014/10/22 13:53:02 Done.
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_client(client)
25 {
26 }
27
28 SuspendableScriptRunner::~SuspendableScriptRunner()
29 {
30 }
31
32 void SuspendableScriptRunner::run()
33 {
34 suspendIfNeeded();
35 ExecutionContext* context = executionContext();
36 ASSERT(context);
37 if (context && !context->activeDOMObjectsAreSuspended())
38 executeAndDestroySelf();
39 }
40
41 void SuspendableScriptRunner::resume()
42 {
43 executeAndDestroySelf();
44 }
45
46 void SuspendableScriptRunner::contextDestroyed()
47 {
48 ActiveDOMObject::contextDestroyed();
49 m_client->completed(Vector<v8::Local<v8::Value> >());
50 delete this;
51 }
52
53 void SuspendableScriptRunner::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_client->completed(results);
68 delete this;
69 }
70
71
72 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698