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

Side by Side 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: Added deprecated label for not suspendable execute methods 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
« no previous file with comments | « Source/web/WebLocalFrameImpl.h ('k') | Source/web/WebScriptSource.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 #include "public/web/WebSerializedScriptValue.h" 194 #include "public/web/WebSerializedScriptValue.h"
195 #include "web/AssociatedURLLoader.h" 195 #include "web/AssociatedURLLoader.h"
196 #include "web/CompositionUnderlineVectorBuilder.h" 196 #include "web/CompositionUnderlineVectorBuilder.h"
197 #include "web/FindInPageCoordinates.h" 197 #include "web/FindInPageCoordinates.h"
198 #include "web/GeolocationClientProxy.h" 198 #include "web/GeolocationClientProxy.h"
199 #include "web/LocalFileSystemClient.h" 199 #include "web/LocalFileSystemClient.h"
200 #include "web/MIDIClientProxy.h" 200 #include "web/MIDIClientProxy.h"
201 #include "web/NotificationPermissionClientImpl.h" 201 #include "web/NotificationPermissionClientImpl.h"
202 #include "web/PageOverlay.h" 202 #include "web/PageOverlay.h"
203 #include "web/SharedWorkerRepositoryClientImpl.h" 203 #include "web/SharedWorkerRepositoryClientImpl.h"
204 #include "web/SuspendableScriptExecutor.h"
204 #include "web/TextFinder.h" 205 #include "web/TextFinder.h"
205 #include "web/WebDataSourceImpl.h" 206 #include "web/WebDataSourceImpl.h"
206 #include "web/WebDevToolsAgentPrivate.h" 207 #include "web/WebDevToolsAgentPrivate.h"
207 #include "web/WebPluginContainerImpl.h" 208 #include "web/WebPluginContainerImpl.h"
208 #include "web/WebRemoteFrameImpl.h" 209 #include "web/WebRemoteFrameImpl.h"
209 #include "web/WebViewImpl.h" 210 #include "web/WebViewImpl.h"
210 #include "wtf/CurrentTime.h" 211 #include "wtf/CurrentTime.h"
211 #include "wtf/HashMap.h" 212 #include "wtf/HashMap.h"
212 #include <algorithm> 213 #include <algorithm>
213 214
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 if (output.length() >= maxChars - frameSeparatorLength) 272 if (output.length() >= maxChars - frameSeparatorLength)
272 return; 273 return;
273 274
274 output.append(frameSeparator, frameSeparatorLength); 275 output.append(frameSeparator, frameSeparatorLength);
275 frameContentAsPlainText(maxChars, curLocalChild, output); 276 frameContentAsPlainText(maxChars, curLocalChild, output);
276 if (output.length() >= maxChars) 277 if (output.length() >= maxChars)
277 return; // Filled up the buffer. 278 return; // Filled up the buffer.
278 } 279 }
279 } 280 }
280 281
282 static Vector<ScriptSourceCode> createSourcesVector(const WebScriptSource* sourc esIn, unsigned numSources)
283 {
284 Vector<ScriptSourceCode> sources;
285 sources.append(sourcesIn, numSources);
286 return sources;
287 }
288
281 WebPluginContainerImpl* WebLocalFrameImpl::pluginContainerFromFrame(LocalFrame* frame) 289 WebPluginContainerImpl* WebLocalFrameImpl::pluginContainerFromFrame(LocalFrame* frame)
282 { 290 {
283 if (!frame) 291 if (!frame)
284 return 0; 292 return 0;
285 if (!frame->document() || !frame->document()->isPluginDocument()) 293 if (!frame->document() || !frame->document()->isPluginDocument())
286 return 0; 294 return 0;
287 PluginDocument* pluginDocument = toPluginDocument(frame->document()); 295 PluginDocument* pluginDocument = toPluginDocument(frame->document());
288 return toWebPluginContainerImpl(pluginDocument->pluginWidget()); 296 return toWebPluginContainerImpl(pluginDocument->pluginWidget());
289 } 297 }
290 298
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 v8::HandleScope handleScope(toIsolate(frame())); 707 v8::HandleScope handleScope(toIsolate(frame()));
700 frame()->script().executeScriptInMainWorld(ScriptSourceCode(source.code, sou rce.url, position)); 708 frame()->script().executeScriptInMainWorld(ScriptSourceCode(source.code, sou rce.url, position));
701 } 709 }
702 710
703 void WebLocalFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScrip tSource* sourcesIn, unsigned numSources, int extensionGroup) 711 void WebLocalFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScrip tSource* sourcesIn, unsigned numSources, int extensionGroup)
704 { 712 {
705 ASSERT(frame()); 713 ASSERT(frame());
706 RELEASE_ASSERT(worldID > 0); 714 RELEASE_ASSERT(worldID > 0);
707 RELEASE_ASSERT(worldID < EmbedderWorldIdLimit); 715 RELEASE_ASSERT(worldID < EmbedderWorldIdLimit);
708 716
709 Vector<ScriptSourceCode> sources; 717 Vector<ScriptSourceCode> sources = createSourcesVector(sourcesIn, numSources );
710 for (unsigned i = 0; i < numSources; ++i) {
711 TextPosition position(OrdinalNumber::fromOneBasedInt(sourcesIn[i].startL ine), OrdinalNumber::first());
712 sources.append(ScriptSourceCode(sourcesIn[i].code, sourcesIn[i].url, pos ition));
713 }
714
715 v8::HandleScope handleScope(toIsolate(frame())); 718 v8::HandleScope handleScope(toIsolate(frame()));
716 frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensionGr oup, 0); 719 frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensionGr oup, 0);
717 } 720 }
718 721
719 void WebLocalFrameImpl::setIsolatedWorldSecurityOrigin(int worldID, const WebSec urityOrigin& securityOrigin) 722 void WebLocalFrameImpl::setIsolatedWorldSecurityOrigin(int worldID, const WebSec urityOrigin& securityOrigin)
720 { 723 {
721 ASSERT(frame()); 724 ASSERT(frame());
722 DOMWrapperWorld::setIsolatedWorldSecurityOrigin(worldID, securityOrigin.get( )); 725 DOMWrapperWorld::setIsolatedWorldSecurityOrigin(worldID, securityOrigin.get( ));
723 } 726 }
724 727
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 } 779 }
777 780
778 v8::Handle<v8::Value> WebLocalFrameImpl::executeScriptAndReturnValue(const WebSc riptSource& source) 781 v8::Handle<v8::Value> WebLocalFrameImpl::executeScriptAndReturnValue(const WebSc riptSource& source)
779 { 782 {
780 ASSERT(frame()); 783 ASSERT(frame());
781 784
782 TextPosition position(OrdinalNumber::fromOneBasedInt(source.startLine), Ordi nalNumber::first()); 785 TextPosition position(OrdinalNumber::fromOneBasedInt(source.startLine), Ordi nalNumber::first());
783 return frame()->script().executeScriptInMainWorldAndReturnValue(ScriptSource Code(source.code, source.url, position)); 786 return frame()->script().executeScriptInMainWorldAndReturnValue(ScriptSource Code(source.code, source.url, position));
784 } 787 }
785 788
789 void WebLocalFrameImpl::requestExecuteScriptAndReturnValue(const WebScriptSource & source, bool userGesture, WebScriptExecutionCallback* callback)
790 {
791 ASSERT(frame());
792
793 Vector<ScriptSourceCode> sources = createSourcesVector(&source, 1);
794 SuspendableScriptExecutor* executor = new SuspendableScriptExecutor(frame(), 0, sources, 0, userGesture, callback);
aandrey 2014/10/23 18:02:58 Should anyone create a OwnPtr<SuspendableScriptExe
795 executor->run();
796 }
797
786 void WebLocalFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScrip tSource* sourcesIn, unsigned numSources, int extensionGroup, WebVector<v8::Local <v8::Value> >* results) 798 void WebLocalFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScrip tSource* sourcesIn, unsigned numSources, int extensionGroup, WebVector<v8::Local <v8::Value> >* results)
787 { 799 {
788 ASSERT(frame()); 800 ASSERT(frame());
789 RELEASE_ASSERT(worldID > 0); 801 RELEASE_ASSERT(worldID > 0);
790 RELEASE_ASSERT(worldID < EmbedderWorldIdLimit); 802 RELEASE_ASSERT(worldID < EmbedderWorldIdLimit);
791 803
792 Vector<ScriptSourceCode> sources; 804 Vector<ScriptSourceCode> sources = createSourcesVector(sourcesIn, numSources );
793
794 for (unsigned i = 0; i < numSources; ++i) {
795 TextPosition position(OrdinalNumber::fromOneBasedInt(sourcesIn[i].startL ine), OrdinalNumber::first());
796 sources.append(ScriptSourceCode(sourcesIn[i].code, sourcesIn[i].url, pos ition));
797 }
798 805
799 if (results) { 806 if (results) {
800 Vector<v8::Local<v8::Value> > scriptResults; 807 Vector<v8::Local<v8::Value> > scriptResults;
801 frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensi onGroup, &scriptResults); 808 frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensi onGroup, &scriptResults);
802 WebVector<v8::Local<v8::Value> > v8Results(scriptResults.size()); 809 WebVector<v8::Local<v8::Value> > v8Results(scriptResults.size());
803 for (unsigned i = 0; i < scriptResults.size(); i++) 810 for (unsigned i = 0; i < scriptResults.size(); i++)
804 v8Results[i] = v8::Local<v8::Value>::New(toIsolate(frame()), scriptR esults[i]); 811 v8Results[i] = v8::Local<v8::Value>::New(toIsolate(frame()), scriptR esults[i]);
805 results->swap(v8Results); 812 results->swap(v8Results);
806 } else { 813 } else {
807 v8::HandleScope handleScope(toIsolate(frame())); 814 v8::HandleScope handleScope(toIsolate(frame()));
808 frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensi onGroup, 0); 815 frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensi onGroup, 0);
809 } 816 }
810 } 817 }
811 818
819 void WebLocalFrameImpl::requestExecuteScriptInIsolatedWorld(int worldID, const W ebScriptSource* sourcesIn, unsigned numSources, int extensionGroup, bool userGes ture, WebScriptExecutionCallback* callback)
820 {
821 ASSERT(frame());
822 RELEASE_ASSERT(worldID > 0);
823 RELEASE_ASSERT(worldID < EmbedderWorldIdLimit);
824
825 Vector<ScriptSourceCode> sources = createSourcesVector(sourcesIn, numSources );
826 SuspendableScriptExecutor* executor = new SuspendableScriptExecutor(frame(), worldID, sources, extensionGroup, userGesture, callback);
827 executor->run();
828 }
829
812 v8::Handle<v8::Value> WebLocalFrameImpl::callFunctionEvenIfScriptDisabled(v8::Ha ndle<v8::Function> function, v8::Handle<v8::Value> receiver, int argc, v8::Handl e<v8::Value> argv[]) 830 v8::Handle<v8::Value> WebLocalFrameImpl::callFunctionEvenIfScriptDisabled(v8::Ha ndle<v8::Function> function, v8::Handle<v8::Value> receiver, int argc, v8::Handl e<v8::Value> argv[])
813 { 831 {
814 ASSERT(frame()); 832 ASSERT(frame());
815 return frame()->script().callFunction(function, receiver, argc, argv); 833 return frame()->script().callFunction(function, receiver, argc, argv);
816 } 834 }
817 835
818 v8::Local<v8::Context> WebLocalFrameImpl::mainWorldScriptContext() const 836 v8::Local<v8::Context> WebLocalFrameImpl::mainWorldScriptContext() const
819 { 837 {
820 return toV8Context(frame(), DOMWrapperWorld::mainWorld()); 838 return toV8Context(frame(), DOMWrapperWorld::mainWorld());
821 } 839 }
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 1963
1946 void WebLocalFrameImpl::invalidateAll() const 1964 void WebLocalFrameImpl::invalidateAll() const
1947 { 1965 {
1948 ASSERT(frame() && frame()->view()); 1966 ASSERT(frame() && frame()->view());
1949 FrameView* view = frame()->view(); 1967 FrameView* view = frame()->view();
1950 view->invalidateRect(view->frameRect()); 1968 view->invalidateRect(view->frameRect());
1951 invalidateScrollbar(); 1969 invalidateScrollbar();
1952 } 1970 }
1953 1971
1954 } // namespace blink 1972 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/WebLocalFrameImpl.h ('k') | Source/web/WebScriptSource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698