Chromium Code Reviews| Index: Source/web/WebLocalFrameImpl.cpp |
| diff --git a/Source/web/WebLocalFrameImpl.cpp b/Source/web/WebLocalFrameImpl.cpp |
| index a4cb06f33aadbbafbb21fbbbf09ce342cc0a2aa1..da4a06ea42f455ca02c78d91b2694e2bc4fa3eec 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/SuspendableScriptExecutor.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) |
|
pfeldman
2014/10/22 15:38:17
Should we have operator ScriptSourceCode() in orde
kozyatinskiy1
2014/10/22 16:46:58
Done.
|
| +{ |
| + 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::requestExecuteScriptAndReturnValue(const WebScriptSource& source, bool userGesture, WebScriptExecutionCallback* callback) |
| +{ |
| + ASSERT(frame()); |
| + |
| + Vector<ScriptSourceCode> sources = createSourcesVector(&source, 1); |
| + SuspendableScriptExecutor* executor = new SuspendableScriptExecutor(frame(), 0, sources, 0, userGesture, adoptPtr(new ScriptExecutionCallbackImpl(callback))); |
| + executor->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::requestExecuteScriptInIsolatedWorld(int worldID, const WebScriptSource* sourcesIn, unsigned numSources, int extensionGroup, bool userGesture, WebScriptExecutionCallback* callback) |
| +{ |
| + ASSERT(frame()); |
| + RELEASE_ASSERT(worldID > 0); |
| + RELEASE_ASSERT(worldID < EmbedderWorldIdLimit); |
| + |
| + Vector<ScriptSourceCode> sources = createSourcesVector(sourcesIn, numSources); |
| + SuspendableScriptExecutor* executor = new SuspendableScriptExecutor(frame(), worldID, sources, extensionGroup, userGesture, adoptPtr(new ScriptExecutionCallbackImpl(callback))); |
| + executor->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()); |