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

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: 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
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 #include "bindings/core/v8/ScriptValue.h" 93 #include "bindings/core/v8/ScriptValue.h"
94 #include "bindings/core/v8/V8Binding.h" 94 #include "bindings/core/v8/V8Binding.h"
95 #include "bindings/core/v8/V8GCController.h" 95 #include "bindings/core/v8/V8GCController.h"
96 #include "bindings/core/v8/V8PerIsolateData.h" 96 #include "bindings/core/v8/V8PerIsolateData.h"
97 #include "core/HTMLNames.h" 97 #include "core/HTMLNames.h"
98 #include "core/dom/Document.h" 98 #include "core/dom/Document.h"
99 #include "core/dom/IconURL.h" 99 #include "core/dom/IconURL.h"
100 #include "core/dom/MessagePort.h" 100 #include "core/dom/MessagePort.h"
101 #include "core/dom/Node.h" 101 #include "core/dom/Node.h"
102 #include "core/dom/NodeTraversal.h" 102 #include "core/dom/NodeTraversal.h"
103 #include "core/dom/SuspendableScriptRunner.h"
103 #include "core/dom/shadow/ShadowRoot.h" 104 #include "core/dom/shadow/ShadowRoot.h"
104 #include "core/editing/Editor.h" 105 #include "core/editing/Editor.h"
105 #include "core/editing/FrameSelection.h" 106 #include "core/editing/FrameSelection.h"
106 #include "core/editing/InputMethodController.h" 107 #include "core/editing/InputMethodController.h"
107 #include "core/editing/PlainTextRange.h" 108 #include "core/editing/PlainTextRange.h"
108 #include "core/editing/SpellChecker.h" 109 #include "core/editing/SpellChecker.h"
109 #include "core/editing/TextAffinity.h" 110 #include "core/editing/TextAffinity.h"
110 #include "core/editing/TextIterator.h" 111 #include "core/editing/TextIterator.h"
111 #include "core/editing/htmlediting.h" 112 #include "core/editing/htmlediting.h"
112 #include "core/editing/markup.h" 113 #include "core/editing/markup.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 } 290 }
290 291
291 WebPluginContainerImpl* WebLocalFrameImpl::pluginContainerFromNode(LocalFrame* f rame, const WebNode& node) 292 WebPluginContainerImpl* WebLocalFrameImpl::pluginContainerFromNode(LocalFrame* f rame, const WebNode& node)
292 { 293 {
293 WebPluginContainerImpl* pluginContainer = pluginContainerFromFrame(frame); 294 WebPluginContainerImpl* pluginContainer = pluginContainerFromFrame(frame);
294 if (pluginContainer) 295 if (pluginContainer)
295 return pluginContainer; 296 return pluginContainer;
296 return toWebPluginContainerImpl(node.pluginContainer()); 297 return toWebPluginContainerImpl(node.pluginContainer());
297 } 298 }
298 299
300 Vector<ScriptSourceCode> WebLocalFrameImpl::createSourcesVector(const WebScriptS ource* sourcesIn, unsigned numSources)
301 {
302 Vector<ScriptSourceCode> sources;
303 for (unsigned i = 0; i < numSources; ++i) {
304 TextPosition position(OrdinalNumber::fromOneBasedInt(sourcesIn[i].startL ine), OrdinalNumber::first());
305 sources.append(ScriptSourceCode(sourcesIn[i].code, sourcesIn[i].url, pos ition));
306 }
307 return sources;
308 }
309
299 // Simple class to override some of PrintContext behavior. Some of the methods 310 // Simple class to override some of PrintContext behavior. Some of the methods
300 // made virtual so that they can be overridden by ChromePluginPrintContext. 311 // made virtual so that they can be overridden by ChromePluginPrintContext.
301 class ChromePrintContext : public PrintContext { 312 class ChromePrintContext : public PrintContext {
302 WTF_MAKE_NONCOPYABLE(ChromePrintContext); 313 WTF_MAKE_NONCOPYABLE(ChromePrintContext);
303 public: 314 public:
304 ChromePrintContext(LocalFrame* frame) 315 ChromePrintContext(LocalFrame* frame)
305 : PrintContext(frame) 316 : PrintContext(frame)
306 , m_printedPageWidth(0) 317 , m_printedPageWidth(0)
307 { 318 {
308 } 319 }
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 v8::HandleScope handleScope(toIsolate(frame())); 710 v8::HandleScope handleScope(toIsolate(frame()));
700 frame()->script().executeScriptInMainWorld(ScriptSourceCode(source.code, sou rce.url, position)); 711 frame()->script().executeScriptInMainWorld(ScriptSourceCode(source.code, sou rce.url, position));
701 } 712 }
702 713
703 void WebLocalFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScrip tSource* sourcesIn, unsigned numSources, int extensionGroup) 714 void WebLocalFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScrip tSource* sourcesIn, unsigned numSources, int extensionGroup)
704 { 715 {
705 ASSERT(frame()); 716 ASSERT(frame());
706 RELEASE_ASSERT(worldID > 0); 717 RELEASE_ASSERT(worldID > 0);
707 RELEASE_ASSERT(worldID < EmbedderWorldIdLimit); 718 RELEASE_ASSERT(worldID < EmbedderWorldIdLimit);
708 719
709 Vector<ScriptSourceCode> sources; 720 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())); 721 v8::HandleScope handleScope(toIsolate(frame()));
716 frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensionGr oup, 0); 722 frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensionGr oup, 0);
717 } 723 }
718 724
719 void WebLocalFrameImpl::setIsolatedWorldSecurityOrigin(int worldID, const WebSec urityOrigin& securityOrigin) 725 void WebLocalFrameImpl::setIsolatedWorldSecurityOrigin(int worldID, const WebSec urityOrigin& securityOrigin)
720 { 726 {
721 ASSERT(frame()); 727 ASSERT(frame());
722 DOMWrapperWorld::setIsolatedWorldSecurityOrigin(worldID, securityOrigin.get( )); 728 DOMWrapperWorld::setIsolatedWorldSecurityOrigin(worldID, securityOrigin.get( ));
723 } 729 }
724 730
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 } 782 }
777 783
778 v8::Handle<v8::Value> WebLocalFrameImpl::executeScriptAndReturnValue(const WebSc riptSource& source) 784 v8::Handle<v8::Value> WebLocalFrameImpl::executeScriptAndReturnValue(const WebSc riptSource& source)
779 { 785 {
780 ASSERT(frame()); 786 ASSERT(frame());
781 787
782 TextPosition position(OrdinalNumber::fromOneBasedInt(source.startLine), Ordi nalNumber::first()); 788 TextPosition position(OrdinalNumber::fromOneBasedInt(source.startLine), Ordi nalNumber::first());
783 return frame()->script().executeScriptInMainWorldAndReturnValue(ScriptSource Code(source.code, source.url, position)); 789 return frame()->script().executeScriptInMainWorldAndReturnValue(ScriptSource Code(source.code, source.url, position));
784 } 790 }
785 791
792 void WebLocalFrameImpl::asyncExecuteScriptAndReturnValue(const WebScriptSource& sourceIn, WebScriptCallback* callback)
793 {
794 ASSERT(frame());
795
796 Vector<ScriptSourceCode> sources = createSourcesVector(&sourceIn, 1);
797 SuspendableScriptRunner* runner = new SuspendableScriptRunner(frame(), 0, so urces, 0, callback);
798 runner->run();
799 }
800
786 void WebLocalFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScrip tSource* sourcesIn, unsigned numSources, int extensionGroup, WebVector<v8::Local <v8::Value> >* results) 801 void WebLocalFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScrip tSource* sourcesIn, unsigned numSources, int extensionGroup, WebVector<v8::Local <v8::Value> >* results)
787 { 802 {
788 ASSERT(frame()); 803 ASSERT(frame());
789 RELEASE_ASSERT(worldID > 0); 804 RELEASE_ASSERT(worldID > 0);
790 RELEASE_ASSERT(worldID < EmbedderWorldIdLimit); 805 RELEASE_ASSERT(worldID < EmbedderWorldIdLimit);
791 806
792 Vector<ScriptSourceCode> sources; 807 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 808
799 if (results) { 809 if (results) {
800 Vector<v8::Local<v8::Value> > scriptResults; 810 Vector<v8::Local<v8::Value> > scriptResults;
801 frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensi onGroup, &scriptResults); 811 frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensi onGroup, &scriptResults);
802 WebVector<v8::Local<v8::Value> > v8Results(scriptResults.size()); 812 WebVector<v8::Local<v8::Value> > v8Results(scriptResults.size());
803 for (unsigned i = 0; i < scriptResults.size(); i++) 813 for (unsigned i = 0; i < scriptResults.size(); i++)
804 v8Results[i] = v8::Local<v8::Value>::New(toIsolate(frame()), scriptR esults[i]); 814 v8Results[i] = v8::Local<v8::Value>::New(toIsolate(frame()), scriptR esults[i]);
805 results->swap(v8Results); 815 results->swap(v8Results);
806 } else { 816 } else {
807 v8::HandleScope handleScope(toIsolate(frame())); 817 v8::HandleScope handleScope(toIsolate(frame()));
808 frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensi onGroup, 0); 818 frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensi onGroup, 0);
809 } 819 }
810 } 820 }
811 821
822 void WebLocalFrameImpl::asyncExecuteScriptInIsolatedWorld(int worldID, const Web ScriptSource* sourcesIn, unsigned numSources, int extensionGroup, WebScriptCallb ack* callback)
823 {
824 ASSERT(frame());
825 RELEASE_ASSERT(worldID > 0);
826 RELEASE_ASSERT(worldID < EmbedderWorldIdLimit);
827
828 Vector<ScriptSourceCode> sources = createSourcesVector(sourcesIn, numSources );
829 SuspendableScriptRunner* runner = new SuspendableScriptRunner(frame(), world ID, sources, extensionGroup, callback);
830 runner->run();
831 }
832
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[]) 833 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 { 834 {
814 ASSERT(frame()); 835 ASSERT(frame());
815 return frame()->script().callFunction(function, receiver, argc, argv); 836 return frame()->script().callFunction(function, receiver, argc, argv);
816 } 837 }
817 838
818 v8::Local<v8::Context> WebLocalFrameImpl::mainWorldScriptContext() const 839 v8::Local<v8::Context> WebLocalFrameImpl::mainWorldScriptContext() const
819 { 840 {
820 return toV8Context(frame(), DOMWrapperWorld::mainWorld()); 841 return toV8Context(frame(), DOMWrapperWorld::mainWorld());
821 } 842 }
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 1950
1930 void WebLocalFrameImpl::invalidateAll() const 1951 void WebLocalFrameImpl::invalidateAll() const
1931 { 1952 {
1932 ASSERT(frame() && frame()->view()); 1953 ASSERT(frame() && frame()->view());
1933 FrameView* view = frame()->view(); 1954 FrameView* view = frame()->view();
1934 view->invalidateRect(view->frameRect()); 1955 view->invalidateRect(view->frameRect());
1935 invalidateScrollbar(); 1956 invalidateScrollbar();
1936 } 1957 }
1937 1958
1938 } // namespace blink 1959 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698