Title: [194311] trunk/Source/WebInspectorUI
Revision
194311
Author
[email protected]
Date
2015-12-18 22:44:50 -0800 (Fri, 18 Dec 2015)

Log Message

Web Inspector: Make it possible to debug injected scripts when the Debug UI is enabled
https://bugs.webkit.org/show_bug.cgi?id=152445

Reviewed by Joseph Pecoraro.

* UserInterface/Base/Main.js:
Added function to check for debug UI.

* UserInterface/Base/Object.js:
Added notification for debug UI enabled state change.

* UserInterface/Base/Utilities.js:
(isWebInspectorInternalScript):
(isWebInspectorDebugScript):
Added functions to check for internal and debug inspector scripts.

* UserInterface/Controllers/DebuggerManager.js:
(WebInspector.DebuggerManager):
Maintain a list of inspector debug scripts, so that the manager can
add and remove them when the debug UI is enabled/disabled.
(WebInspector.DebuggerManager.prototype.get knownNonResourceScripts):
(WebInspector.DebuggerManager.prototype.reset):
Clear the list of inspector debug scripts.
(WebInspector.DebuggerManager.prototype.debuggerDidPause):
(WebInspector.DebuggerManager.prototype.scriptDidParse):
Skip internal inspector scripts. Debug inspector scripts are tracked,
and an added event is dispatched if the debug UI is enabled.
(WebInspector.DebuggerManager.prototype._debugUIEnabledDidChange):
Dispatch added/removed events for inspector debug scripts.

* UserInterface/Debug/Bootstrap.js:
(WebInspector.runBootstrapOperations):
Expose changes to the debug UI setting to the reset of the UI, by dispatching
a WebInspector.Notification.DebugUIEnabledDidChange event.

* UserInterface/Protocol/RemoteObject.js:
(WebInspector.RemoteObject.prototype.findFunctionSourceCodeLocation):
Only resolve inspector debug source locations when the debug UI is enabled.

* UserInterface/Test/Test.js:
Reimplemented debug UI check for tests. Always returns false.

* UserInterface/Views/DebuggerSidebarPanel.js:
(WebInspector.DebuggerSidebarPanel.prototype._addScript):
Removed check for inspector debug scripts. DebuggerManager filters scripts as needed.
(WebInspector.DebuggerSidebarPanel.prototype._scriptRemoved):
Handle DebuggerManager ScriptRemoved events. Only applies to debug scripts.

* UserInterface/Views/ResourceSidebarPanel.js:
(WebInspector.ResourceSidebarPanel):
(WebInspector.ResourceSidebarPanel.prototype._scriptWasRemoved):
Handle DebuggerManager ScriptRemoved events. Only applies to debug scripts.
(WebInspector.ResourceSidebarPanel.prototype._scriptWasAdded):
Removed check for inspector debug scripts. DebuggerManager filters scripts as needed.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (194310 => 194311)


--- trunk/Source/WebInspectorUI/ChangeLog	2015-12-19 02:32:46 UTC (rev 194310)
+++ trunk/Source/WebInspectorUI/ChangeLog	2015-12-19 06:44:50 UTC (rev 194311)
@@ -1,3 +1,60 @@
+2015-12-18  Matt Baker  <[email protected]>
+
+        Web Inspector: Make it possible to debug injected scripts when the Debug UI is enabled
+        https://bugs.webkit.org/show_bug.cgi?id=152445
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/Base/Main.js:
+        Added function to check for debug UI.
+
+        * UserInterface/Base/Object.js:
+        Added notification for debug UI enabled state change.
+
+        * UserInterface/Base/Utilities.js:
+        (isWebInspectorInternalScript):
+        (isWebInspectorDebugScript):
+        Added functions to check for internal and debug inspector scripts.
+
+        * UserInterface/Controllers/DebuggerManager.js:
+        (WebInspector.DebuggerManager):
+        Maintain a list of inspector debug scripts, so that the manager can
+        add and remove them when the debug UI is enabled/disabled.
+        (WebInspector.DebuggerManager.prototype.get knownNonResourceScripts):
+        (WebInspector.DebuggerManager.prototype.reset):
+        Clear the list of inspector debug scripts.
+        (WebInspector.DebuggerManager.prototype.debuggerDidPause):
+        (WebInspector.DebuggerManager.prototype.scriptDidParse):
+        Skip internal inspector scripts. Debug inspector scripts are tracked,
+        and an added event is dispatched if the debug UI is enabled.
+        (WebInspector.DebuggerManager.prototype._debugUIEnabledDidChange):
+        Dispatch added/removed events for inspector debug scripts.
+
+        * UserInterface/Debug/Bootstrap.js:
+        (WebInspector.runBootstrapOperations):
+        Expose changes to the debug UI setting to the reset of the UI, by dispatching
+        a WebInspector.Notification.DebugUIEnabledDidChange event.
+
+        * UserInterface/Protocol/RemoteObject.js:
+        (WebInspector.RemoteObject.prototype.findFunctionSourceCodeLocation):
+        Only resolve inspector debug source locations when the debug UI is enabled.
+
+        * UserInterface/Test/Test.js:
+        Reimplemented debug UI check for tests. Always returns false.
+
+        * UserInterface/Views/DebuggerSidebarPanel.js:
+        (WebInspector.DebuggerSidebarPanel.prototype._addScript):
+        Removed check for inspector debug scripts. DebuggerManager filters scripts as needed.
+        (WebInspector.DebuggerSidebarPanel.prototype._scriptRemoved):
+        Handle DebuggerManager ScriptRemoved events. Only applies to debug scripts.
+
+        * UserInterface/Views/ResourceSidebarPanel.js:
+        (WebInspector.ResourceSidebarPanel):
+        (WebInspector.ResourceSidebarPanel.prototype._scriptWasRemoved):
+        Handle DebuggerManager ScriptRemoved events. Only applies to debug scripts.
+        (WebInspector.ResourceSidebarPanel.prototype._scriptWasAdded):
+        Removed check for inspector debug scripts. DebuggerManager filters scripts as needed.
+
 2015-12-17  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: Remove "local" scope type from the protocol

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Main.js (194310 => 194311)


--- trunk/Source/WebInspectorUI/UserInterface/Base/Main.js	2015-12-19 02:32:46 UTC (rev 194310)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Main.js	2015-12-19 06:44:50 UTC (rev 194311)
@@ -1369,8 +1369,7 @@
     let proposedContextMenu;
 
     // This is setting is only defined in engineering builds.
-    let showDebugUI = WebInspector.showDebugUISetting && WebInspector.showDebugUISetting.value;
-    if (showDebugUI) {
+    if (WebInspector.isDebugUIEnabled()) {
         proposedContextMenu = WebInspector.ContextMenu.createFromEvent(event);
         proposedContextMenu.appendSeparator();
         proposedContextMenu.appendItem(WebInspector.unlocalizedString("Reload Web Inspector"), () => {
@@ -1385,6 +1384,11 @@
         proposedContextMenu.show();
 };
 
+WebInspector.isDebugUIEnabled = function()
+{
+    return WebInspector.showDebugUISetting && WebInspector.showDebugUISetting.value;
+}
+
 WebInspector._undock = function(event)
 {
     InspectorFrontendHost.requestSetDockSide("undocked");

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Object.js (194310 => 194311)


--- trunk/Source/WebInspectorUI/UserInterface/Base/Object.js	2015-12-19 02:32:46 UTC (rev 194310)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Object.js	2015-12-19 06:44:50 UTC (rev 194311)
@@ -209,4 +209,5 @@
     PageArchiveEnded: "page-archive-ended",
     ExtraDomainsActivated: "extra-domains-activated",
     TabTypesChanged: "tab-types-changed",
+    DebugUIEnabledDidChange: "debug-ui-enabled-did-change",
 };

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js (194310 => 194311)


--- trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js	2015-12-19 02:32:46 UTC (rev 194310)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js	2015-12-19 06:44:50 UTC (rev 194311)
@@ -1112,6 +1112,16 @@
     return string + "\n//# sourceURL=__WebInspectorInternal__\n";
 }
 
+function isWebInspectorInternalScript(url)
+{
+    return url ="" "__WebInspectorInternal__";
+}
+
+function isWebInspectorDebugScript(url)
+{
+    return url && url.startsWith("__WebInspector");
+}
+
 function isFunctionStringNativeCode(str)
 {
     return str.endsWith("{\n    [native code]\n}");

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js (194310 => 194311)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js	2015-12-19 02:32:46 UTC (rev 194310)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js	2015-12-19 06:44:50 UTC (rev 194311)
@@ -32,6 +32,8 @@
         if (window.DebuggerAgent)
             DebuggerAgent.enable();
 
+        WebInspector.notifications.addEventListener(WebInspector.Notification.DebugUIEnabledDidChange, this._debugUIEnabledDidChange, this);
+
         WebInspector.Breakpoint.addEventListener(WebInspector.Breakpoint.Event.DisplayLocationDidChange, this._breakpointDisplayLocationDidChange, this);
         WebInspector.Breakpoint.addEventListener(WebInspector.Breakpoint.Event.DisabledStateDidChange, this._breakpointDisabledStateDidChange, this);
         WebInspector.Breakpoint.addEventListener(WebInspector.Breakpoint.Event.ConditionDidChange, this._breakpointEditablePropertyDidChange, this);
@@ -62,6 +64,7 @@
         this._pauseReason = null;
         this._pauseData = null;
 
+        this._inspectorDebugScripts = [];
         this._scriptIdMap = new Map;
         this._scriptURLMap = new Map;
 
@@ -319,7 +322,7 @@
         for (let script of this._scriptIdMap.values()) {
             if (script.resource)
                 continue;
-            if (script.url && script.url.startsWith("__WebInspector"))
+            if (!WebInspector.isDebugUIEnabled() && isWebInspectorDebugScript(script.url))
                 continue;
             knownScripts.push(script);
         }
@@ -439,6 +442,7 @@
         this._pauseReason = null;
         this._pauseData = null;
 
+        this._inspectorDebugScripts = [];
         this._scriptIdMap.clear();
         this._scriptURLMap.clear();
 
@@ -486,8 +490,9 @@
                 continue;
             if (!sourceCodeLocation.sourceCode)
                 continue;
+
             // Exclude the case where the call frame is in the inspector code.
-            if (sourceCodeLocation.sourceCode.url && sourceCodeLocation.sourceCode.url.startsWith("__WebInspector"))
+            if (!WebInspector.isDebugUIEnabled() && isWebInspectorDebugScript(sourceCodeLocation.sourceCode.url))
                 continue;
 
             let scopeChain = this._scopeChainFromPayload(callFramePayload.scopeChain);
@@ -530,6 +535,9 @@
             return;
         }
 
+        if (isWebInspectorInternalScript(url))
+            return;
+
         var script = new WebInspector.Script(scriptIdentifier, new WebInspector.TextRange(startLine, startColumn, endLine, endColumn), url, isContentScript, sourceMapURL);
 
         this._scriptIdMap.set(scriptIdentifier, script);
@@ -543,6 +551,12 @@
             scripts.push(script);
         }
 
+        if (isWebInspectorDebugScript(script.url)) {
+            this._inspectorDebugScripts.push(script);
+            if (!WebInspector.isDebugUIEnabled())
+                return;
+        }
+
         this.dispatchEventToListeners(WebInspector.DebuggerManager.Event.ScriptAdded, {script});
     }
 
@@ -901,6 +915,13 @@
 
         this._ignoreBreakpointDisplayLocationDidChangeEvent = false;
     }
+
+    _debugUIEnabledDidChange()
+    {
+        let eventType = WebInspector.isDebugUIEnabled() ? WebInspector.DebuggerManager.Event.ScriptAdded : WebInspector.DebuggerManager.Event.ScriptRemoved;
+        for (let script of this._inspectorDebugScripts)
+            this.dispatchEventToListeners(eventType, {script});
+    }
 };
 
 WebInspector.DebuggerManager.Event = {
@@ -913,6 +934,7 @@
     CallFramesDidChange: "debugger-manager-call-frames-did-change",
     ActiveCallFrameDidChange: "debugger-manager-active-call-frame-did-change",
     ScriptAdded: "debugger-manager-script-added",
+    ScriptRemoved: "debugger-manager-script-removed",
     ScriptsCleared: "debugger-manager-scripts-cleared",
     BreakpointsEnabledDidChange: "debugger-manager-breakpoints-enabled-did-change"
 };

Modified: trunk/Source/WebInspectorUI/UserInterface/Debug/Bootstrap.js (194310 => 194311)


--- trunk/Source/WebInspectorUI/UserInterface/Debug/Bootstrap.js	2015-12-19 02:32:46 UTC (rev 194310)
+++ trunk/Source/WebInspectorUI/UserInterface/Debug/Bootstrap.js	2015-12-19 06:44:50 UTC (rev 194311)
@@ -52,6 +52,10 @@
         debugInspectorToolbarButton.hidden = !WebInspector.showDebugUISetting.value;
     }
 
-    WebInspector.showDebugUISetting.addEventListener(WebInspector.Setting.Event.Changed, updateDebugUI);
+    WebInspector.showDebugUISetting.addEventListener(WebInspector.Setting.Event.Changed, () => {
+        updateDebugUI();
+        WebInspector.notifications.dispatchEventToListeners(WebInspector.Notification.DebugUIEnabledDidChange);
+    });
+
     updateDebugUI();
 }

Modified: trunk/Source/WebInspectorUI/UserInterface/Protocol/RemoteObject.js (194310 => 194311)


--- trunk/Source/WebInspectorUI/UserInterface/Protocol/RemoteObject.js	2015-12-19 02:32:46 UTC (rev 194310)
+++ trunk/Source/WebInspectorUI/UserInterface/Protocol/RemoteObject.js	2015-12-19 06:44:50 UTC (rev 194311)
@@ -511,7 +511,7 @@
             var location = response.location;
             var sourceCode = WebInspector.debuggerManager.scriptForIdentifier(location.scriptId);
 
-            if (!sourceCode || sourceCode.url.startsWith("__WebInspector")) {
+            if (!sourceCode || (!WebInspector.isDebugUIEnabled() && isWebInspectorDebugScript(sourceCode.url))) {
                 result.resolve(WebInspector.RemoteObject.SourceCodeLocationPromise.NoSourceFound);
                 return;
             }

Modified: trunk/Source/WebInspectorUI/UserInterface/Test/Test.js (194310 => 194311)


--- trunk/Source/WebInspectorUI/UserInterface/Test/Test.js	2015-12-19 02:32:46 UTC (rev 194310)
+++ trunk/Source/WebInspectorUI/UserInterface/Test/Test.js	2015-12-19 06:44:50 UTC (rev 194311)
@@ -87,6 +87,8 @@
     InspectorFrontendHost.loaded();
 }
 
+WebInspector.isDebugUIEnabled = () => false;
+
 WebInspector.UIString = (string) => string;
 
 // Add stubs that are called by the frontend API.

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/DebuggerSidebarPanel.js (194310 => 194311)


--- trunk/Source/WebInspectorUI/UserInterface/Views/DebuggerSidebarPanel.js	2015-12-19 02:32:46 UTC (rev 194310)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/DebuggerSidebarPanel.js	2015-12-19 06:44:50 UTC (rev 194311)
@@ -39,6 +39,7 @@
         WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.BreakpointAdded, this._breakpointAdded, this);
         WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.BreakpointRemoved, this._breakpointRemoved, this);
         WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ScriptAdded, this._scriptAdded, this);
+        WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ScriptRemoved, this._scriptRemoved, this);
         WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ScriptsCleared, this._scriptsCleared, this);
         WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.Paused, this._debuggerDidPause, this);
         WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.Resumed, this._debuggerDidResume, this);
@@ -394,15 +395,10 @@
 
     _addScript(script)
     {
-        // FIXME: Allow for scripts generated by eval statements to appear, but filter out JSC internals
-        // and other WebInspector internals lacking __WebInspector in the url attribute.
+        // COMPATIBILITY(iOS 9): Backends could send the frontend built-in code, filter out JSC internals.
         if (!script.url)
             return;
 
-        // Exclude inspector scripts.
-        if (script.url && script.url.startsWith("__WebInspector"))
-            return;
-
         // Don't add breakpoints if the script is represented by a Resource. They were
         // already added by _resourceAdded.
         if (script.resource)
@@ -416,6 +412,16 @@
             this.showDefaultContentViewForTreeElement(treeElement);
     }
 
+    _scriptRemoved(event)
+    {
+        let script = event.data.script;
+        let scriptTreeElement = this._breakpointsContentTreeOutline.getCachedTreeElement(script);
+        if (!scriptTreeElement)
+            return;
+
+        scriptTreeElement.parent.removeChild(scriptTreeElement);
+    }
+
     _scriptsCleared(event)
     {
         for (var i = this._breakpointsContentTreeOutline.children.length - 1; i >= 0; --i) {

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ResourceSidebarPanel.js (194310 => 194311)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ResourceSidebarPanel.js	2015-12-19 02:32:46 UTC (rev 194310)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ResourceSidebarPanel.js	2015-12-19 06:44:50 UTC (rev 194311)
@@ -58,6 +58,7 @@
         WebInspector.frameResourceManager.addEventListener(WebInspector.FrameResourceManager.Event.MainFrameDidChange, this._mainFrameDidChange, this);
 
         WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ScriptAdded, this._scriptWasAdded, this);
+        WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ScriptRemoved, this._scriptWasRemoved, this);
         WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ScriptsCleared, this._scriptsCleared, this);
 
         WebInspector.notifications.addEventListener(WebInspector.Notification.ExtraDomainsActivated, this._extraDomainsActivated, this);
@@ -270,10 +271,6 @@
         if (!script.url)
             return;
 
-        // Exclude inspector scripts.
-        if (script.url.startsWith("__WebInspector"))
-            return;
-
         // If the script URL matches a resource we can assume it is part of that resource and does not need added.
         if (script.resource)
             return;
@@ -309,6 +306,16 @@
         }
     }
 
+    _scriptWasRemoved(event)
+    {
+        let script = event.data.script;
+        let scriptTreeElement = this.contentTreeOutline.getCachedTreeElement(script);
+        if (!scriptTreeElement)
+            return;
+
+        scriptTreeElement.parent.removeChild(scriptTreeElement);
+    }
+
     _scriptsCleared(event)
     {
         const suppressOnDeselect = true;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to