| OLD | NEW | 
|     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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|    81 // |    81 // | 
|    82 // The client is expected to be set whenever the WebLocalFrameImpl is attached t
      o |    82 // The client is expected to be set whenever the WebLocalFrameImpl is attached t
      o | 
|    83 // the DOM. |    83 // the DOM. | 
|    84  |    84  | 
|    85 #include "config.h" |    85 #include "config.h" | 
|    86 #include "web/WebLocalFrameImpl.h" |    86 #include "web/WebLocalFrameImpl.h" | 
|    87  |    87  | 
|    88 #include "bindings/core/v8/DOMWrapperWorld.h" |    88 #include "bindings/core/v8/DOMWrapperWorld.h" | 
|    89 #include "bindings/core/v8/ExceptionState.h" |    89 #include "bindings/core/v8/ExceptionState.h" | 
|    90 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |    90 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 
 |    91 #include "bindings/core/v8/ScheduledActionWithCallback.h" | 
|    91 #include "bindings/core/v8/ScriptController.h" |    92 #include "bindings/core/v8/ScriptController.h" | 
|    92 #include "bindings/core/v8/ScriptSourceCode.h" |    93 #include "bindings/core/v8/ScriptSourceCode.h" | 
|    93 #include "bindings/core/v8/ScriptValue.h" |    94 #include "bindings/core/v8/ScriptValue.h" | 
|    94 #include "bindings/core/v8/V8Binding.h" |    95 #include "bindings/core/v8/V8Binding.h" | 
|    95 #include "bindings/core/v8/V8GCController.h" |    96 #include "bindings/core/v8/V8GCController.h" | 
|    96 #include "bindings/core/v8/V8PerIsolateData.h" |    97 #include "bindings/core/v8/V8PerIsolateData.h" | 
|    97 #include "core/HTMLNames.h" |    98 #include "core/HTMLNames.h" | 
|    98 #include "core/dom/Document.h" |    99 #include "core/dom/Document.h" | 
|    99 #include "core/dom/IconURL.h" |   100 #include "core/dom/IconURL.h" | 
|   100 #include "core/dom/MessagePort.h" |   101 #include "core/dom/MessagePort.h" | 
|   101 #include "core/dom/Node.h" |   102 #include "core/dom/Node.h" | 
|   102 #include "core/dom/NodeTraversal.h" |   103 #include "core/dom/NodeTraversal.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" | 
|   113 #include "core/fetch/ResourceFetcher.h" |   114 #include "core/fetch/ResourceFetcher.h" | 
|   114 #include "core/frame/Console.h" |   115 #include "core/frame/Console.h" | 
 |   116 #include "core/frame/DOMWindowTimers.h" | 
|   115 #include "core/frame/LocalDOMWindow.h" |   117 #include "core/frame/LocalDOMWindow.h" | 
|   116 #include "core/frame/FrameHost.h" |   118 #include "core/frame/FrameHost.h" | 
|   117 #include "core/frame/FrameView.h" |   119 #include "core/frame/FrameView.h" | 
|   118 #include "core/frame/Settings.h" |   120 #include "core/frame/Settings.h" | 
|   119 #include "core/html/HTMLAnchorElement.h" |   121 #include "core/html/HTMLAnchorElement.h" | 
|   120 #include "core/html/HTMLCollection.h" |   122 #include "core/html/HTMLCollection.h" | 
|   121 #include "core/html/HTMLFormElement.h" |   123 #include "core/html/HTMLFormElement.h" | 
|   122 #include "core/html/HTMLFrameElementBase.h" |   124 #include "core/html/HTMLFrameElementBase.h" | 
|   123 #include "core/html/HTMLFrameOwnerElement.h" |   125 #include "core/html/HTMLFrameOwnerElement.h" | 
|   124 #include "core/html/HTMLHeadElement.h" |   126 #include "core/html/HTMLHeadElement.h" | 
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   698     v8::HandleScope handleScope(toIsolate(frame())); |   700     v8::HandleScope handleScope(toIsolate(frame())); | 
|   699     frame()->script().executeScriptInMainWorld(ScriptSourceCode(source.code, sou
      rce.url, position)); |   701     frame()->script().executeScriptInMainWorld(ScriptSourceCode(source.code, sou
      rce.url, position)); | 
|   700 } |   702 } | 
|   701  |   703  | 
|   702 void WebLocalFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScrip
      tSource* sourcesIn, unsigned numSources, int extensionGroup) |   704 void WebLocalFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScrip
      tSource* sourcesIn, unsigned numSources, int extensionGroup) | 
|   703 { |   705 { | 
|   704     ASSERT(frame()); |   706     ASSERT(frame()); | 
|   705     RELEASE_ASSERT(worldID > 0); |   707     RELEASE_ASSERT(worldID > 0); | 
|   706     RELEASE_ASSERT(worldID < EmbedderWorldIdLimit); |   708     RELEASE_ASSERT(worldID < EmbedderWorldIdLimit); | 
|   707  |   709  | 
|   708     Vector<ScriptSourceCode> sources; |   710     Vector<ScriptSourceCode> sources = createSourcesVector(sourcesIn, numSources
      ); | 
|   709     for (unsigned i = 0; i < numSources; ++i) { |  | 
|   710         TextPosition position(OrdinalNumber::fromOneBasedInt(sourcesIn[i].startL
      ine), OrdinalNumber::first()); |  | 
|   711         sources.append(ScriptSourceCode(sourcesIn[i].code, sourcesIn[i].url, pos
      ition)); |  | 
|   712     } |  | 
|   713  |  | 
|   714     v8::HandleScope handleScope(toIsolate(frame())); |   711     v8::HandleScope handleScope(toIsolate(frame())); | 
|   715     frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensionGr
      oup, 0); |   712     frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensionGr
      oup, 0); | 
|   716 } |   713 } | 
|   717  |   714  | 
|   718 void WebLocalFrameImpl::setIsolatedWorldSecurityOrigin(int worldID, const WebSec
      urityOrigin& securityOrigin) |   715 void WebLocalFrameImpl::setIsolatedWorldSecurityOrigin(int worldID, const WebSec
      urityOrigin& securityOrigin) | 
|   719 { |   716 { | 
|   720     ASSERT(frame()); |   717     ASSERT(frame()); | 
|   721     DOMWrapperWorld::setIsolatedWorldSecurityOrigin(worldID, securityOrigin.get(
      )); |   718     DOMWrapperWorld::setIsolatedWorldSecurityOrigin(worldID, securityOrigin.get(
      )); | 
|   722 } |   719 } | 
|   723  |   720  | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   775 } |   772 } | 
|   776  |   773  | 
|   777 v8::Handle<v8::Value> WebLocalFrameImpl::executeScriptAndReturnValue(const WebSc
      riptSource& source) |   774 v8::Handle<v8::Value> WebLocalFrameImpl::executeScriptAndReturnValue(const WebSc
      riptSource& source) | 
|   778 { |   775 { | 
|   779     ASSERT(frame()); |   776     ASSERT(frame()); | 
|   780  |   777  | 
|   781     TextPosition position(OrdinalNumber::fromOneBasedInt(source.startLine), Ordi
      nalNumber::first()); |   778     TextPosition position(OrdinalNumber::fromOneBasedInt(source.startLine), Ordi
      nalNumber::first()); | 
|   782     return frame()->script().executeScriptInMainWorldAndReturnValue(ScriptSource
      Code(source.code, source.url, position)); |   779     return frame()->script().executeScriptInMainWorldAndReturnValue(ScriptSource
      Code(source.code, source.url, position)); | 
|   783 } |   780 } | 
|   784  |   781  | 
 |   782 void WebLocalFrameImpl::executeScriptAndReturnValue(const WebScriptSource& scrip
      tSource, WebScriptCallback* callback) | 
 |   783 { | 
 |   784     ASSERT(frame()); | 
 |   785  | 
 |   786     Vector<ScriptSourceCode> sources = createSourcesVector(&scriptSource, 1); | 
 |   787     OwnPtr<ScheduledActionBase> action = adoptPtr(new ScheduledActionWithCallbac
      k(0, sources, 0, callback)); | 
 |   788     DOMWindowTimers::setTimeout(*frame()->domWindow(), action.release(), 0); | 
 |   789 } | 
 |   790  | 
|   785 void WebLocalFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScrip
      tSource* sourcesIn, unsigned numSources, int extensionGroup, WebVector<v8::Local
      <v8::Value> >* results) |   791 void WebLocalFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScrip
      tSource* sourcesIn, unsigned numSources, int extensionGroup, WebVector<v8::Local
      <v8::Value> >* results) | 
|   786 { |   792 { | 
|   787     ASSERT(frame()); |   793     ASSERT(frame()); | 
|   788     RELEASE_ASSERT(worldID > 0); |   794     RELEASE_ASSERT(worldID > 0); | 
|   789     RELEASE_ASSERT(worldID < EmbedderWorldIdLimit); |   795     RELEASE_ASSERT(worldID < EmbedderWorldIdLimit); | 
|   790  |   796  | 
|   791     Vector<ScriptSourceCode> sources; |   797     Vector<ScriptSourceCode> sources = createSourcesVector(sourcesIn, numSources
      ); | 
|   792  |  | 
|   793     for (unsigned i = 0; i < numSources; ++i) { |  | 
|   794         TextPosition position(OrdinalNumber::fromOneBasedInt(sourcesIn[i].startL
      ine), OrdinalNumber::first()); |  | 
|   795         sources.append(ScriptSourceCode(sourcesIn[i].code, sourcesIn[i].url, pos
      ition)); |  | 
|   796     } |  | 
|   797  |  | 
|   798     if (results) { |   798     if (results) { | 
|   799         Vector<v8::Local<v8::Value> > scriptResults; |   799         Vector<v8::Local<v8::Value> > scriptResults; | 
|   800         frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensi
      onGroup, &scriptResults); |   800         frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensi
      onGroup, &scriptResults); | 
|   801         WebVector<v8::Local<v8::Value> > v8Results(scriptResults.size()); |   801         WebVector<v8::Local<v8::Value> > v8Results(scriptResults.size()); | 
|   802         for (unsigned i = 0; i < scriptResults.size(); i++) |   802         for (unsigned i = 0; i < scriptResults.size(); i++) | 
|   803             v8Results[i] = v8::Local<v8::Value>::New(toIsolate(frame()), scriptR
      esults[i]); |   803             v8Results[i] = v8::Local<v8::Value>::New(toIsolate(frame()), scriptR
      esults[i]); | 
|   804         results->swap(v8Results); |   804         results->swap(v8Results); | 
|   805     } else { |   805     } else { | 
|   806         v8::HandleScope handleScope(toIsolate(frame())); |   806         v8::HandleScope handleScope(toIsolate(frame())); | 
|   807         frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensi
      onGroup, 0); |   807         frame()->script().executeScriptInIsolatedWorld(worldID, sources, extensi
      onGroup, 0); | 
|   808     } |   808     } | 
|   809 } |   809 } | 
|   810  |   810  | 
 |   811 void WebLocalFrameImpl::executeScriptInIsolatedWorld(int worldID, const WebScrip
      tSource* sourcesIn, unsigned numSources, int extensionGroup, WebScriptCallback* 
      callback) | 
 |   812 { | 
 |   813     ASSERT(frame()); | 
 |   814     RELEASE_ASSERT(worldID > 0); | 
 |   815     RELEASE_ASSERT(worldID < EmbedderWorldIdLimit); | 
 |   816  | 
 |   817     Vector<ScriptSourceCode> sources = createSourcesVector(sourcesIn, numSources
      ); | 
 |   818     OwnPtr<ScheduledActionBase> action = adoptPtr(new ScheduledActionWithCallbac
      k(worldID, sources, extensionGroup, callback)); | 
 |   819     DOMWindowTimers::setTimeout(*frame()->domWindow(), action.release(), 0); | 
 |   820 } | 
 |   821  | 
|   811 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[]) |   822 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[]) | 
|   812 { |   823 { | 
|   813     ASSERT(frame()); |   824     ASSERT(frame()); | 
|   814     return frame()->script().callFunction(function, receiver, argc, argv); |   825     return frame()->script().callFunction(function, receiver, argc, argv); | 
|   815 } |   826 } | 
|   816  |   827  | 
|   817 v8::Local<v8::Context> WebLocalFrameImpl::mainWorldScriptContext() const |   828 v8::Local<v8::Context> WebLocalFrameImpl::mainWorldScriptContext() const | 
|   818 { |   829 { | 
|   819     return toV8Context(frame(), DOMWrapperWorld::mainWorld()); |   830     return toV8Context(frame(), DOMWrapperWorld::mainWorld()); | 
|   820 } |   831 } | 
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1231 } |  1242 } | 
|  1232  |  1243  | 
|  1233 WebPlugin* WebLocalFrameImpl::focusedPluginIfInputMethodSupported() |  1244 WebPlugin* WebLocalFrameImpl::focusedPluginIfInputMethodSupported() | 
|  1234 { |  1245 { | 
|  1235     WebPluginContainerImpl* container = WebLocalFrameImpl::pluginContainerFromNo
      de(frame(), WebNode(frame()->document()->focusedElement())); |  1246     WebPluginContainerImpl* container = WebLocalFrameImpl::pluginContainerFromNo
      de(frame(), WebNode(frame()->document()->focusedElement())); | 
|  1236     if (container && container->supportsInputMethod()) |  1247     if (container && container->supportsInputMethod()) | 
|  1237         return container->plugin(); |  1248         return container->plugin(); | 
|  1238     return 0; |  1249     return 0; | 
|  1239 } |  1250 } | 
|  1240  |  1251  | 
 |  1252 Vector<ScriptSourceCode> WebLocalFrameImpl::createSourcesVector(const WebScriptS
      ource* sourcesIn, unsigned numSources) | 
 |  1253 { | 
 |  1254     Vector<ScriptSourceCode> sources; | 
 |  1255     for (unsigned i = 0; i < numSources; ++i) { | 
 |  1256         TextPosition position(OrdinalNumber::fromOneBasedInt(sourcesIn[i].startL
      ine), OrdinalNumber::first()); | 
 |  1257         sources.append(ScriptSourceCode(sourcesIn[i].code, sourcesIn[i].url, pos
      ition)); | 
 |  1258     } | 
 |  1259     return sources; | 
 |  1260 } | 
 |  1261  | 
|  1241 int WebLocalFrameImpl::printBegin(const WebPrintParams& printParams, const WebNo
      de& constrainToNode) |  1262 int WebLocalFrameImpl::printBegin(const WebPrintParams& printParams, const WebNo
      de& constrainToNode) | 
|  1242 { |  1263 { | 
|  1243     ASSERT(!frame()->document()->isFrameSet()); |  1264     ASSERT(!frame()->document()->isFrameSet()); | 
|  1244     WebPluginContainerImpl* pluginContainer = 0; |  1265     WebPluginContainerImpl* pluginContainer = 0; | 
|  1245     if (constrainToNode.isNull()) { |  1266     if (constrainToNode.isNull()) { | 
|  1246         // If this is a plugin document, check if the plugin supports its own |  1267         // If this is a plugin document, check if the plugin supports its own | 
|  1247         // printing. If it does, we will delegate all printing to that. |  1268         // printing. If it does, we will delegate all printing to that. | 
|  1248         pluginContainer = pluginContainerFromFrame(frame()); |  1269         pluginContainer = pluginContainerFromFrame(frame()); | 
|  1249     } else { |  1270     } else { | 
|  1250         // We only support printing plugin nodes for now. |  1271         // We only support printing plugin nodes for now. | 
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1914  |  1935  | 
|  1915 void WebLocalFrameImpl::invalidateAll() const |  1936 void WebLocalFrameImpl::invalidateAll() const | 
|  1916 { |  1937 { | 
|  1917     ASSERT(frame() && frame()->view()); |  1938     ASSERT(frame() && frame()->view()); | 
|  1918     FrameView* view = frame()->view(); |  1939     FrameView* view = frame()->view(); | 
|  1919     view->invalidateRect(view->frameRect()); |  1940     view->invalidateRect(view->frameRect()); | 
|  1920     invalidateScrollbar(); |  1941     invalidateScrollbar(); | 
|  1921 } |  1942 } | 
|  1922  |  1943  | 
|  1923 } // namespace blink |  1944 } // namespace blink | 
| OLD | NEW |