Web Inspector: use regular eval instead of injectScript for front-end extension API
authoryurys@chromium.org <yurys@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Mar 2013 14:07:36 +0000 (14:07 +0000)
committeryurys@chromium.org <yurys@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Mar 2013 14:07:36 +0000 (14:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=111529

Reviewed by Pavel Feldman.

Removed InjectedScriptManager::injectScript and replaced all of it calls
except the actual script injection with ScriptController::executeScript.

* inspector/InjectedScriptManager.cpp:
(WebCore::InjectedScriptManager::injectedScriptFor):
* inspector/InjectedScriptManager.h:
(InjectedScriptManager):
* inspector/InspectorAgent.cpp:
(WebCore::InspectorAgent::didClearWindowObjectInWorld):
* inspector/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::didClearWindowObjectInWorld):
* inspector/front-end/DOMAgent.js:
(WebInspector.DOMAgent.prototype._emulateTouchEventsChanged.get if):
* inspector/front-end/ExtensionAPI.js:
(buildExtensionAPIInjectedScript):
* inspector/front-end/ExtensionServer.js:
(WebInspector.ExtensionServer.prototype._onReload):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@144916 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/InjectedScriptManager.cpp
Source/WebCore/inspector/InjectedScriptManager.h
Source/WebCore/inspector/InspectorAgent.cpp
Source/WebCore/inspector/InspectorPageAgent.cpp
Source/WebCore/inspector/front-end/DOMAgent.js
Source/WebCore/inspector/front-end/ExtensionAPI.js
Source/WebCore/inspector/front-end/ExtensionServer.js

index 3d4f3e3..39a7cba 100644 (file)
@@ -1,3 +1,28 @@
+2013-03-06  Yury Semikhatsky  <yurys@chromium.org>
+
+        Web Inspector: use regular eval instead of injectScript for front-end extension API
+        https://bugs.webkit.org/show_bug.cgi?id=111529
+
+        Reviewed by Pavel Feldman.
+
+        Removed InjectedScriptManager::injectScript and replaced all of it calls
+        except the actual script injection with ScriptController::executeScript.
+
+        * inspector/InjectedScriptManager.cpp:
+        (WebCore::InjectedScriptManager::injectedScriptFor):
+        * inspector/InjectedScriptManager.h:
+        (InjectedScriptManager):
+        * inspector/InspectorAgent.cpp:
+        (WebCore::InspectorAgent::didClearWindowObjectInWorld):
+        * inspector/InspectorPageAgent.cpp:
+        (WebCore::InspectorPageAgent::didClearWindowObjectInWorld):
+        * inspector/front-end/DOMAgent.js:
+        (WebInspector.DOMAgent.prototype._emulateTouchEventsChanged.get if):
+        * inspector/front-end/ExtensionAPI.js:
+        (buildExtensionAPIInjectedScript):
+        * inspector/front-end/ExtensionServer.js:
+        (WebInspector.ExtensionServer.prototype._onReload):
+
 2013-03-06  Allan Sandfeld Jensen  <allan.jensen@digia.com>
 
         [Qt] Do not disable C++0x
index 1d5e317..9756edf 100644 (file)
@@ -40,9 +40,6 @@
 #include "InspectorValues.h"
 #include "ScriptObject.h"
 #include <wtf/PassOwnPtr.h>
-#include <wtf/StdLibExtras.h>
-
-using namespace std;
 
 namespace WebCore {
 
@@ -163,12 +160,6 @@ String InjectedScriptManager::injectedScriptSource()
     return String(reinterpret_cast<const char*>(InjectedScriptSource_js), sizeof(InjectedScriptSource_js));
 }
 
-pair<int, ScriptObject> InjectedScriptManager::injectScript(const String& source, ScriptState* scriptState)
-{
-    int id = injectedScriptIdFor(scriptState);
-    return std::make_pair(id, createInjectedScript(source, scriptState, id));
-}
-
 InjectedScript InjectedScriptManager::injectedScriptFor(ScriptState* inspectedScriptState)
 {
     ScriptStateToId::iterator it = m_scriptStateToId.find(inspectedScriptState);
@@ -181,9 +172,10 @@ InjectedScript InjectedScriptManager::injectedScriptFor(ScriptState* inspectedSc
     if (!m_inspectedStateAccessCheck(inspectedScriptState))
         return InjectedScript();
 
-    pair<int, ScriptObject> injectedScript = injectScript(injectedScriptSource(), inspectedScriptState);
-    InjectedScript result(injectedScript.second, m_inspectedStateAccessCheck);
-    m_idToInjectedScript.set(injectedScript.first, result);
+    int id = injectedScriptIdFor(inspectedScriptState);
+    ScriptObject injectedScriptObject = createInjectedScript(injectedScriptSource(), inspectedScriptState, id);
+    InjectedScript result(injectedScriptObject, m_inspectedStateAccessCheck);
+    m_idToInjectedScript.set(id, result);
     return result;
 }
 
index 111e2b2..17f8f75 100644 (file)
@@ -54,7 +54,6 @@ public:
 
     InjectedScriptHost* injectedScriptHost();
 
-    pair<int, ScriptObject> injectScript(const String& source, ScriptState*);
     InjectedScript injectedScriptFor(ScriptState*);
     InjectedScript injectedScriptForId(int);
     int injectedScriptIdFor(ScriptState*);
index ea7e7f3..2149334 100644 (file)
@@ -88,8 +88,15 @@ void InspectorAgent::didClearWindowObjectInWorld(Frame* frame, DOMWrapperWorld*
 
     String origin = frame->document()->securityOrigin()->toRawString();
     String script = m_injectedScriptForOrigin.get(origin);
-    if (!script.isEmpty())
-        m_injectedScriptManager->injectScript(script, mainWorldScriptState(frame));
+    if (script.isEmpty())
+        return;
+    int injectedScriptId = m_injectedScriptManager->injectedScriptIdFor(mainWorldScriptState(frame));
+    StringBuilder scriptSource;
+    scriptSource.append(script);
+    scriptSource.append("(");
+    scriptSource.appendNumber(injectedScriptId);
+    scriptSource.append(")");
+    frame->script()->executeScript(scriptSource.toString());
 }
 
 void InspectorAgent::setFrontend(InspectorFrontend* inspectorFrontend)
index abb7991..6c147d5 100644 (file)
@@ -852,11 +852,11 @@ void InspectorPageAgent::didClearWindowObjectInWorld(Frame* frame, DOMWrapperWor
         for (InspectorObject::const_iterator it = scripts->begin(); it != end; ++it) {
             String scriptText;
             if (it->value->asString(&scriptText))
-                m_injectedScriptManager->injectScript(scriptText, mainWorldScriptState(frame));
+                frame->script()->executeScript(scriptText);
         }
     }
     if (!m_scriptToEvaluateOnLoadOnce.isEmpty())
-        m_injectedScriptManager->injectScript(m_scriptToEvaluateOnLoadOnce, mainWorldScriptState(frame));
+        frame->script()->executeScript(m_scriptToEvaluateOnLoadOnce);
 }
 
 void InspectorPageAgent::domContentEventFired()
index 507f680..9221dcd 100644 (file)
@@ -1322,7 +1322,7 @@ WebInspector.DOMAgent.prototype = {
         var emulationEnabled = WebInspector.settings.emulateTouchEvents.get();
         if (emulationEnabled && !this._addTouchEventsScriptInjecting) {
             this._addTouchEventsScriptInjecting = true;
-            PageAgent.addScriptToEvaluateOnLoad("(" + injectedFunction.toString() + ")", scriptAddedCallback.bind(this));
+            PageAgent.addScriptToEvaluateOnLoad("(" + injectedFunction.toString() + ")()", scriptAddedCallback.bind(this));
         } else {
             if (typeof this._addTouchEventsScriptId !== "undefined") {
                 PageAgent.removeScriptToEvaluateOnLoad(this._addTouchEventsScriptId);
index 3c321d1..2f02e57 100644 (file)
@@ -885,7 +885,7 @@ function buildPlatformExtensionAPI(extensionInfo)
 
 function buildExtensionAPIInjectedScript(extensionInfo)
 {
-    return "(function(injectedScriptHost, inspectedWindow, injectedScriptId){ " +
+    return "(function(injectedScriptId){ " +
         "var extensionServer;" +
         defineCommonExtensionSymbols.toString() + ";" +
         injectedExtensionAPI.toString() + ";" +
index fd307fa..1c29214 100644 (file)
@@ -310,11 +310,8 @@ WebInspector.ExtensionServer.prototype = {
         var options = /** @type ExtensionReloadOptions */ (message.options || {});
         NetworkAgent.setUserAgentOverride(typeof options.userAgent === "string" ? options.userAgent : "");
         var injectedScript;
-        if (options.injectedScript) {
-            // Wrap client script into anonymous function, return another anonymous function that
-            // returns empty object for compatibility with InjectedScriptManager on the backend.
-            injectedScript = "((function(){" + options.injectedScript + "})(),function(){return {}})";
-        }
+        if (options.injectedScript)
+            injectedScript = "(function(){" + options.injectedScript + "})()";
         PageAgent.reload(!!options.ignoreCache, injectedScript);
         return this._status.OK();
     },