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

Unified Diff: Source/web/WebLocalFrameImpl.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 side-by-side diff with in-line comments
Download patch
Index: Source/web/WebLocalFrameImpl.cpp
diff --git a/Source/web/WebLocalFrameImpl.cpp b/Source/web/WebLocalFrameImpl.cpp
index a4b6bf98c91f95aff7373f6899df13992026a770..d6ab0be4f27df04b5beb3d5d9f924990f71b842c 100644
--- a/Source/web/WebLocalFrameImpl.cpp
+++ b/Source/web/WebLocalFrameImpl.cpp
@@ -100,6 +100,7 @@
#include "core/dom/MessagePort.h"
#include "core/dom/Node.h"
#include "core/dom/NodeTraversal.h"
+#include "core/dom/SuspendableScriptRunner.h"
#include "core/dom/shadow/ShadowRoot.h"
#include "core/editing/Editor.h"
#include "core/editing/FrameSelection.h"
@@ -200,6 +201,7 @@
#include "web/MIDIClientProxy.h"
#include "web/NotificationPermissionClientImpl.h"
#include "web/PageOverlay.h"
+#include "web/ScriptExecutionCallbackImpl.h"
#include "web/SharedWorkerRepositoryClientImpl.h"
#include "web/TextFinder.h"
#include "web/WebDataSourceImpl.h"
@@ -278,6 +280,16 @@ static void frameContentAsPlainText(size_t maxChars, LocalFrame* frame, StringBu
}
}
+static Vector<ScriptSourceCode> createSourcesVector(const WebScriptSource* sourcesIn, unsigned numSources)
+{
+ Vector<ScriptSourceCode> sources;
+ for (unsigned i = 0; i < numSources; ++i) {
+ TextPosition position(OrdinalNumber::fromOneBasedInt(sourcesIn[i].startLine), OrdinalNumber::first());
+ sources.append(ScriptSourceCode(sourcesIn[i].code, sourcesIn[i].url, position));
+ }
+ return sources;
+}
+
WebPluginContainerImpl* WebLocalFrameImpl::pluginContainerFromFrame(LocalFrame* frame)
{
if (!frame)
@@ -706,12 +718,7 @@ void WebLocalFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScrip
RELEASE_ASSERT(worldID > 0);
RELEASE_ASSERT(worldID < EmbedderWorldIdLimit);
- Vector<ScriptSourceCode> sources;
- for (unsigned i = 0; i < numSources; ++i) {
- TextPosition position(OrdinalNumber::fromOneBasedInt(sourcesIn[i].startLine), OrdinalNumber::first());
- sources.append(ScriptSourceCode(sourcesIn[i].code, sourcesIn[i].url, position));
- }
-
+ Vector<ScriptSourceCode> sources = createSourcesVector(sourcesIn, numSources);
v8::HandleScope handleScope(toIsolate(frame()));
frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensionGroup, 0);
}
@@ -783,18 +790,22 @@ v8::Handle<v8::Value> WebLocalFrameImpl::executeScriptAndReturnValue(const WebSc
return frame()->script().executeScriptInMainWorldAndReturnValue(ScriptSourceCode(source.code, source.url, position));
}
+void WebLocalFrameImpl::asyncExecuteScriptAndReturnValue(const WebScriptSource& sourceIn, bool userGesture, WebScriptExecutionCallback* callback)
vsevik 2014/10/22 13:29:00 requestScriptExecutionAndReturnValue
vsevik 2014/10/22 13:29:00 /sourceIn/source/
kozyatinskiy1 2014/10/22 13:53:03 Done.
kozyatinskiy1 2014/10/22 13:53:03 Done.
+{
+ ASSERT(frame());
+
+ Vector<ScriptSourceCode> sources = createSourcesVector(&sourceIn, 1);
+ SuspendableScriptRunner* runner = new SuspendableScriptRunner(frame(), 0, sources, 0, userGesture, adoptPtr(new ScriptExecutionCallbackImpl(callback)));
+ runner->run();
+}
+
void WebLocalFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScriptSource* sourcesIn, unsigned numSources, int extensionGroup, WebVector<v8::Local<v8::Value> >* results)
{
ASSERT(frame());
RELEASE_ASSERT(worldID > 0);
RELEASE_ASSERT(worldID < EmbedderWorldIdLimit);
- Vector<ScriptSourceCode> sources;
-
- for (unsigned i = 0; i < numSources; ++i) {
- TextPosition position(OrdinalNumber::fromOneBasedInt(sourcesIn[i].startLine), OrdinalNumber::first());
- sources.append(ScriptSourceCode(sourcesIn[i].code, sourcesIn[i].url, position));
- }
+ Vector<ScriptSourceCode> sources = createSourcesVector(sourcesIn, numSources);
if (results) {
Vector<v8::Local<v8::Value> > scriptResults;
@@ -809,6 +820,17 @@ void WebLocalFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScrip
}
}
+void WebLocalFrameImpl::asyncExecuteScriptInIsolatedWorld(int worldID, const WebScriptSource* sourcesIn, unsigned numSources, int extensionGroup, bool userGesture, WebScriptExecutionCallback* callback)
vsevik 2014/10/22 13:29:00 ditto
kozyatinskiy1 2014/10/22 13:53:03 async -> request - done. sourcesIn -> source - not
+{
+ ASSERT(frame());
+ RELEASE_ASSERT(worldID > 0);
+ RELEASE_ASSERT(worldID < EmbedderWorldIdLimit);
+
+ Vector<ScriptSourceCode> sources = createSourcesVector(sourcesIn, numSources);
+ SuspendableScriptRunner* runner = new SuspendableScriptRunner(frame(), worldID, sources, extensionGroup, userGesture, adoptPtr(new ScriptExecutionCallbackImpl(callback)));
+ runner->run();
+}
+
v8::Handle<v8::Value> WebLocalFrameImpl::callFunctionEvenIfScriptDisabled(v8::Handle<v8::Function> function, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> argv[])
{
ASSERT(frame());

Powered by Google App Engine
This is Rietveld 408576698