Title: [115323] trunk
Revision
115323
Author
apav...@chromium.org
Date
2012-04-26 09:44:46 -0700 (Thu, 26 Apr 2012)

Log Message

Web Inspector: Implement the "Disable _javascript_" option in the settings dialog
https://bugs.webkit.org/show_bug.cgi?id=84946

Source/WebCore:

Based on user actions in the Inspector frontend, InspectorPageAgent invokes Settings::setScriptEnabled()
for the associated page to switch the script execution therein.

Reviewed by Yury Semikhatsky.

Test: inspector/debugger/disable-script.html

* inspector/Inspector.json:
* inspector/InspectorPageAgent.cpp:
(PageAgentState):
(WebCore::InspectorPageAgent::enable):
(WebCore::InspectorPageAgent::disable):
(WebCore::InspectorPageAgent::getScriptExecutionStatus):
(WebCore):
(WebCore::InspectorPageAgent::setScriptExecutionDisabled):
* inspector/InspectorPageAgent.h:
* inspector/front-end/Settings.js:
* inspector/front-end/SettingsScreen.js:
(WebInspector.SettingsScreen):
(WebInspector.SettingsScreen.prototype.get _updateScriptDisabledCheckbox):
(WebInspector.SettingsScreen.prototype._javaScriptDisabledChanged):
* inspector/front-end/inspector.js:

LayoutTests:

Reviewed by Yury Semikhatsky.

* inspector/debugger/disable-script-expected.txt: Added.
* inspector/debugger/disable-script.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (115322 => 115323)


--- trunk/LayoutTests/ChangeLog	2012-04-26 16:19:41 UTC (rev 115322)
+++ trunk/LayoutTests/ChangeLog	2012-04-26 16:44:46 UTC (rev 115323)
@@ -1,3 +1,13 @@
+2012-04-26  Alexander Pavlov  <apav...@chromium.org>
+
+        Web Inspector: Implement the "Disable _javascript_" option in the settings dialog
+        https://bugs.webkit.org/show_bug.cgi?id=84946
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/debugger/disable-script-expected.txt: Added.
+        * inspector/debugger/disable-script.html: Added.
+
 2012-04-26  Dominik Röttsches  <dominik.rottsc...@linux.intel.com>
 
         [cairo] CairoGraphicsContext fillRect (with Color) overrides composite operator

Added: trunk/LayoutTests/inspector/debugger/disable-script-expected.txt (0 => 115323)


--- trunk/LayoutTests/inspector/debugger/disable-script-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/debugger/disable-script-expected.txt	2012-04-26 16:44:46 UTC (rev 115323)
@@ -0,0 +1,21 @@
+Tests that inspector effectively disables script execution in the inspected page.
+
+Execution count: 2
+
+Running: init
+Script execution status: allowed
+
+Running: tryWithEnabled
+Attempting execution...
+Script execution status: allowed
+
+Running: tryWithDisabled
+Attempting execution...
+Script execution status: disabled
+
+Running: tryWithRestored
+Attempting execution...
+Script execution status: allowed
+
+Running: finalize
+
Property changes on: trunk/LayoutTests/inspector/debugger/disable-script-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/inspector/debugger/disable-script.html (0 => 115323)


--- trunk/LayoutTests/inspector/debugger/disable-script.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/debugger/disable-script.html	2012-04-26 16:44:46 UTC (rev 115323)
@@ -0,0 +1,85 @@
+<html>
+<head>
+<script src=""
+<script>
+var count = 0;
+
+function updateCount()
+{
+    setTimeout(function() {
+        count++;
+    }, 0);
+}
+
+function recordExecutions()
+{
+    document.getElementById("main").textContent = "Execution count: " + count;
+}
+
+function test()
+{
+    function dumpState(next)
+    {
+        PageAgent.scriptExecutionStatus(statusCallback);
+        function statusCallback(error, status)
+        {
+            if (error) {
+                InspectorTest.addResult("Error: " + JSON.stringify(error));
+                return;
+            }
+
+            InspectorTest.addResult("Script execution status: " + status);
+            next();
+        }
+   }
+
+    function updateCount(next)
+    {
+        InspectorTest.addResult("Attempting execution...");
+        InspectorTest.evaluateInPage("updateCount()", next);
+    }
+
+    function setJSDisabled(disabled, next)
+    {
+        PageAgent.setScriptExecutionDisabled(disabled, next);
+    }
+
+    InspectorTest.runTestSuite([
+        function init(next)
+        {
+            PageAgent.enable();
+            dumpState(next);
+        },
+
+        function tryWithEnabled(next)
+        {
+            updateCount(dumpState.bind(null, next));
+        },
+
+        function tryWithDisabled(next)
+        {
+            setJSDisabled(true, updateCount.bind(null, dumpState.bind(null, next)));
+        },
+
+        function tryWithRestored(next)
+        {
+            setJSDisabled(false, updateCount.bind(null, dumpState.bind(null, next)));
+        },
+
+        function finalize(next)
+        {
+            InspectorTest.evaluateInPage("recordExecutions()", next);
+        }
+    ]);
+}
+</script>
+</head>
+
+<body _onload_="runTest()">
+<p>
+Tests that inspector effectively disables script execution in the inspected page.
+</p>
+
+<div id="main">Original text.</div>
+</body>
+</html>
Property changes on: trunk/LayoutTests/inspector/debugger/disable-script.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/ChangeLog (115322 => 115323)


--- trunk/Source/WebCore/ChangeLog	2012-04-26 16:19:41 UTC (rev 115322)
+++ trunk/Source/WebCore/ChangeLog	2012-04-26 16:44:46 UTC (rev 115323)
@@ -1,3 +1,31 @@
+2012-04-26  Alexander Pavlov  <apav...@chromium.org>
+
+        Web Inspector: Implement the "Disable _javascript_" option in the settings dialog
+        https://bugs.webkit.org/show_bug.cgi?id=84946
+
+        Based on user actions in the Inspector frontend, InspectorPageAgent invokes Settings::setScriptEnabled()
+        for the associated page to switch the script execution therein.
+
+        Reviewed by Yury Semikhatsky.
+
+        Test: inspector/debugger/disable-script.html
+
+        * inspector/Inspector.json:
+        * inspector/InspectorPageAgent.cpp:
+        (PageAgentState):
+        (WebCore::InspectorPageAgent::enable):
+        (WebCore::InspectorPageAgent::disable):
+        (WebCore::InspectorPageAgent::getScriptExecutionStatus):
+        (WebCore):
+        (WebCore::InspectorPageAgent::setScriptExecutionDisabled):
+        * inspector/InspectorPageAgent.h:
+        * inspector/front-end/Settings.js:
+        * inspector/front-end/SettingsScreen.js:
+        (WebInspector.SettingsScreen):
+        (WebInspector.SettingsScreen.prototype.get _updateScriptDisabledCheckbox):
+        (WebInspector.SettingsScreen.prototype._javaScriptDisabledChanged):
+        * inspector/front-end/inspector.js:
+
 2012-04-26  Dominik Röttsches  <dominik.rottsc...@linux.intel.com>
 
         [cairo] CairoGraphicsContext fillRect (with Color) overrides composite operator

Modified: trunk/Source/WebCore/inspector/Inspector.json (115322 => 115323)


--- trunk/Source/WebCore/inspector/Inspector.json	2012-04-26 16:19:41 UTC (rev 115322)
+++ trunk/Source/WebCore/inspector/Inspector.json	2012-04-26 16:44:46 UTC (rev 115323)
@@ -335,6 +335,20 @@
                     { "name": "result", "type": "boolean", "description": "True for showing paint rectangles" }
                 ],
                 "hidden": true
+            },
+            {
+                "name": "getScriptExecutionStatus",
+                "description": "Determines if scripts can be executed in the page.",
+                "returns": [
+                    { "name": "result", "type": "string", "enum": ["allowed", "disabled", "forbidden"], "description": "Script execution status: \"allowed\" if scripts can be executed, \"disabled\" if script execution has been disabled through page settings, \"forbidden\" if script execution for the given page is not possible for other reasons." }
+                ]
+            },
+            {
+                "name": "setScriptExecutionDisabled",
+                "description": "Switches script execution in the page.",
+                "parameters": [
+                    { "name": "value", "type": "boolean", "description": "Whether script execution should be disabled in the page." }
+                ]
             }
         ],
         "events": [

Modified: trunk/Source/WebCore/inspector/InspectorPageAgent.cpp (115322 => 115323)


--- trunk/Source/WebCore/inspector/InspectorPageAgent.cpp	2012-04-26 16:19:41 UTC (rev 115322)
+++ trunk/Source/WebCore/inspector/InspectorPageAgent.cpp	2012-04-26 16:44:46 UTC (rev 115323)
@@ -66,6 +66,7 @@
 #include "RegularExpression.h"
 #include "ScriptObject.h"
 #include "SecurityOrigin.h"
+#include "Settings.h"
 #include "SharedBuffer.h"
 #include "TextEncoding.h"
 #include "TextResourceDecoder.h"
@@ -81,6 +82,7 @@
 
 namespace PageAgentState {
 static const char pageAgentEnabled[] = "pageAgentEnabled";
+static const char pageAgentScriptExecutionDisabled[] = "pageAgentScriptExecutionDisabled";
 static const char pageAgentScriptsToEvaluateOnLoad[] = "pageAgentScriptsToEvaluateOnLoad";
 static const char pageAgentScreenWidthOverride[] = "pageAgentScreenWidthOverride";
 static const char pageAgentScreenHeightOverride[] = "pageAgentScreenHeightOverride";
@@ -347,6 +349,8 @@
 void InspectorPageAgent::enable(ErrorString*)
 {
     m_state->setBoolean(PageAgentState::pageAgentEnabled, true);
+    bool scriptExecutionDisabled = m_state->getBoolean(PageAgentState::pageAgentScriptExecutionDisabled);
+    setScriptExecutionDisabled(0, scriptExecutionDisabled);
     m_instrumentingAgents->setInspectorPageAgent(this);
 }
 
@@ -355,6 +359,8 @@
     m_state->setBoolean(PageAgentState::pageAgentEnabled, false);
     m_instrumentingAgents->setInspectorPageAgent(0);
 
+    setScriptExecutionDisabled(0, false);
+
     // When disabling the agent, reset the override values.
     m_state->setLong(PageAgentState::pageAgentScreenWidthOverride, 0);
     m_state->setLong(PageAgentState::pageAgentScreenHeightOverride, 0);
@@ -688,6 +694,39 @@
         m_page->mainFrame()->view()->invalidate();
 }
 
+void InspectorPageAgent::getScriptExecutionStatus(ErrorString*, PageCommandHandler::Result::Enum* status)
+{
+    bool disabledByScriptController = false;
+    bool disabledInSettings = false;
+    Frame* frame = mainFrame();
+    if (frame) {
+        disabledByScriptController = !frame->script()->canExecuteScripts(NotAboutToExecuteScript);
+        if (frame->settings())
+            disabledInSettings = !frame->settings()->isScriptEnabled();
+    }
+
+    if (!disabledByScriptController) {
+        *status = PageCommandHandler::Result::Allowed;
+        return;
+    }
+
+    if (disabledInSettings)
+        *status = PageCommandHandler::Result::Disabled;
+    else
+        *status = PageCommandHandler::Result::Forbidden;
+}
+
+void InspectorPageAgent::setScriptExecutionDisabled(ErrorString*, bool value)
+{
+    m_state->setBoolean(PageAgentState::pageAgentScriptExecutionDisabled, value);
+    if (!mainFrame())
+        return;
+
+    Settings* settings = mainFrame()->settings();
+    if (settings)
+        settings->setScriptEnabled(!value);
+}
+
 void InspectorPageAgent::didClearWindowObjectInWorld(Frame* frame, DOMWrapperWorld* world)
 {
     if (world != mainThreadNormalWorld())

Modified: trunk/Source/WebCore/inspector/InspectorPageAgent.h (115322 => 115323)


--- trunk/Source/WebCore/inspector/InspectorPageAgent.h	2012-04-26 16:19:41 UTC (rev 115322)
+++ trunk/Source/WebCore/inspector/InspectorPageAgent.h	2012-04-26 16:44:46 UTC (rev 115323)
@@ -105,6 +105,8 @@
     virtual void canOverrideDeviceMetrics(ErrorString*, bool*);
     virtual void setDeviceMetricsOverride(ErrorString*, int width, int height, double fontScaleFactor, bool fitWindow);
     virtual void setShowPaintRects(ErrorString*, bool show);
+    virtual void getScriptExecutionStatus(ErrorString*, PageCommandHandler::Result::Enum*);
+    virtual void setScriptExecutionDisabled(ErrorString*, bool);
 
     // InspectorInstrumentation API
     void didClearWindowObjectInWorld(Frame*, DOMWrapperWorld*);

Modified: trunk/Source/WebCore/inspector/front-end/Settings.js (115322 => 115323)


--- trunk/Source/WebCore/inspector/front-end/Settings.js	2012-04-26 16:19:41 UTC (rev 115322)
+++ trunk/Source/WebCore/inspector/front-end/Settings.js	2012-04-26 16:44:46 UTC (rev 115323)
@@ -95,6 +95,7 @@
     this.showPaintRects = this.createSetting("showPaintRects", false);
     this.zoomLevel = this.createSetting("zoomLevel", 0);
     this.savedURLs = this.createSetting("savedURLs", {});
+    this._javascript_Disabled = this.createSetting("_javascript_Disabled", false);
 
     // If there are too many breakpoints in a storage, it is likely due to a recent bug that caused
     // periodical breakpoints duplication leading to inspector slowness.

Modified: trunk/Source/WebCore/inspector/front-end/SettingsScreen.js (115322 => 115323)


--- trunk/Source/WebCore/inspector/front-end/SettingsScreen.js	2012-04-26 16:19:41 UTC (rev 115322)
+++ trunk/Source/WebCore/inspector/front-end/SettingsScreen.js	2012-04-26 16:44:46 UTC (rev 115323)
@@ -38,15 +38,16 @@
 
     this._leftColumnElement = document.createElement("td");
     this._rightColumnElement = document.createElement("td");
-    var p;
-
-    if (Preferences.showDockToRight || Preferences.exposeDisableCache) {
-        p = this._appendSection(WebInspector.UIString("General"));
-        if (Preferences.showDockToRight)
-            p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Dock to right"), WebInspector.settings.dockToRight));
-        if (Preferences.exposeDisableCache)
-            p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Disable cache"), WebInspector.settings.cacheDisabled));
-    }
+    var p = this._appendSection(WebInspector.UIString("General"));
+    if (Preferences.showDockToRight)
+        p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Dock to right"), WebInspector.settings.dockToRight));
+    if (Preferences.exposeDisableCache)
+        p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Disable cache"), WebInspector.settings.cacheDisabled));
+    var disableJSElement = this._createCheckboxSetting(WebInspector.UIString("Disable _javascript_"), WebInspector.settings._javascript_Disabled);
+    p.appendChild(disableJSElement);
+    WebInspector.settings._javascript_Disabled.addChangeListener(this._javaScriptDisabledChanged, this);
+    this._disableJSCheckbox = disableJSElement.getElementsByTagName("input")[0];
+    this._updateScriptDisabledCheckbox();
     
     p = this._appendSection(WebInspector.UIString("Rendering"));
     p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Show paint rectangles"), WebInspector.settings.showPaintRects));
@@ -408,6 +409,36 @@
         PageAgent.setShowPaintRects(WebInspector.settings.showPaintRects.get());
     },
 
+    _updateScriptDisabledCheckbox: function()
+    {
+        function executionStatusCallback(error, status)
+        {
+            if (error || !status)
+                return;
+
+            switch (status) {
+            case "forbidden":
+                this._disableJSCheckbox.checked = true;
+                this._disableJSCheckbox.disabled = true;
+                break;
+            case "disabled":
+                this._disableJSCheckbox.checked = true;
+                break;
+            default:
+                this._disableJSCheckbox.checked = false;
+                break;
+            }
+        }
+
+        PageAgent.getScriptExecutionStatus(executionStatusCallback.bind(this));
+    },
+
+    _javaScriptDisabledChanged: function()
+    {
+        // We need to manually update the checkbox state, since enabling _javascript_ in the page can actually uncover the "forbidden" state.
+        PageAgent.setScriptExecutionDisabled(WebInspector.settings._javascript_Disabled.get(), this._updateScriptDisabledCheckbox.bind(this));
+    },
+
     _createDeviceMetricsControl: function()
     {
         const metricsSetting = WebInspector.settings.deviceMetrics.get();

Modified: trunk/Source/WebCore/inspector/front-end/inspector.js (115322 => 115323)


--- trunk/Source/WebCore/inspector/front-end/inspector.js	2012-04-26 16:19:41 UTC (rev 115322)
+++ trunk/Source/WebCore/inspector/front-end/inspector.js	2012-04-26 16:44:46 UTC (rev 115323)
@@ -481,6 +481,9 @@
     if (WebInspector.settings.showPaintRects.get())
         PageAgent.setShowPaintRects(true);
 
+    if (WebInspector.settings._javascript_Disabled.get())
+        PageAgent.setScriptExecutionDisabled(true);
+
     WebInspector.WorkerManager.loadCompleted();
     InspectorFrontendAPI.loadCompleted();
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to