From 8c6c1b463d95db10d937501e119c5e7b5f4a7044 Mon Sep 17 00:00:00 2001 From: kozyatinskiy Date: Thu, 25 Feb 2016 19:10:39 -0800 Subject: [PATCH] [DevTools] Replace (un)blackboxURL methods with (un)blackboxUISourceCode It's preparation step for anonymous script blackboxing. BUG=583193 R=dgozman@chromium.org Review URL: https://codereview.chromium.org/1742463003 Cr-Commit-Position: refs/heads/master@{#377794} --- front_end/bindings/BlackboxManager.js | 64 ++++++++++++++++++---- front_end/sources/CallStackSidebarPane.js | 51 ++++++----------- front_end/sources/JavaScriptSourceFrame.js | 19 ++++--- front_end/sources/SourcesPanel.js | 8 +-- 4 files changed, 83 insertions(+), 59 deletions(-) diff --git a/front_end/bindings/BlackboxManager.js b/front_end/bindings/BlackboxManager.js index 68609f95a2..a848f1a854 100644 --- a/front_end/bindings/BlackboxManager.js +++ b/front_end/bindings/BlackboxManager.js @@ -77,9 +77,8 @@ WebInspector.BlackboxManager.prototype = { var isContentScript = projectType === WebInspector.projectTypes.ContentScripts; if (isContentScript && WebInspector.moduleSetting("skipContentScripts").get()) return true; - var networkURL = this._networkMapping.networkURL(uiSourceCode); - var url = projectType === WebInspector.projectTypes.Formatter ? uiSourceCode.url() : networkURL; - return this.isBlackboxedURL(url); + var url = this._uiSourceCodeURL(uiSourceCode); + return url ? this.isBlackboxedURL(url) : false; }, /** @@ -155,18 +154,63 @@ WebInspector.BlackboxManager.prototype = { }, /** - * @param {string} url + * @param {!WebInspector.UISourceCode} uiSourceCode + * @return {?string} + */ + _uiSourceCodeURL: function(uiSourceCode) + { + var networkURL = this._networkMapping.networkURL(uiSourceCode); + var projectType = uiSourceCode.project().type(); + if (projectType === WebInspector.projectTypes.Debugger) + return null; + var url = projectType === WebInspector.projectTypes.Formatter ? uiSourceCode.url() : networkURL; + return url ? url : null; + }, + + /** + * @param {!WebInspector.UISourceCode} uiSourceCode * @return {boolean} */ - canBlackboxURL: function(url) + canBlackboxUISourceCode: function(uiSourceCode) + { + var url = this._uiSourceCodeURL(uiSourceCode); + return url ? !!this._urlToRegExpString(url) : false; + }, + + /** + * @param {!WebInspector.UISourceCode} uiSourceCode + */ + blackboxUISourceCode: function(uiSourceCode) + { + var url = this._uiSourceCodeURL(uiSourceCode); + if (url) + this._blackboxURL(url); + }, + + /** + * @param {!WebInspector.UISourceCode} uiSourceCode + */ + unblackboxUISourceCode: function(uiSourceCode) + { + var url = this._uiSourceCodeURL(uiSourceCode); + if (url) + this._unblackboxURL(url); + }, + + blackboxContentScripts: function() { - return !!this._urlToRegExpString(url); + WebInspector.moduleSetting("skipContentScripts").set(true); + }, + + unblackboxContentScripts: function() + { + WebInspector.moduleSetting("skipContentScripts").set(false); }, /** * @param {string} url */ - blackboxURL: function(url) + _blackboxURL: function(url) { var regexPatterns = WebInspector.moduleSetting("skipStackFramesPattern").getAsArray(); var regexValue = this._urlToRegExpString(url); @@ -188,13 +232,9 @@ WebInspector.BlackboxManager.prototype = { /** * @param {string} url - * @param {boolean} isContentScript */ - unblackbox: function(url, isContentScript) + _unblackboxURL: function(url) { - if (isContentScript) - WebInspector.moduleSetting("skipContentScripts").set(false); - var regexPatterns = WebInspector.moduleSetting("skipStackFramesPattern").getAsArray(); var regexValue = WebInspector.blackboxManager._urlToRegExpString(url); if (!regexValue) diff --git a/front_end/sources/CallStackSidebarPane.js b/front_end/sources/CallStackSidebarPane.js index 588a449d52..e5652a3f75 100644 --- a/front_end/sources/CallStackSidebarPane.js +++ b/front_end/sources/CallStackSidebarPane.js @@ -169,9 +169,8 @@ WebInspector.CallStackSidebarPane.prototype = { contextMenu.appendItem(WebInspector.UIString.capitalize("Copy ^stack ^trace"), this._copyStackTrace.bind(this)); - var isBlackboxed = WebInspector.blackboxManager.isBlackboxedRawLocation(callFrame._callFrame.location()); - var script = callFrame._callFrame.script; - this.appendBlackboxURLContextMenuItems(contextMenu, script.sourceURL, script.isContentScript(), isBlackboxed); + var uiLocation = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(callFrame._callFrame.location()); + this.appendBlackboxURLContextMenuItems(contextMenu, uiLocation.uiSourceCode); contextMenu.show(); }, @@ -193,40 +192,26 @@ WebInspector.CallStackSidebarPane.prototype = { /** * @param {!WebInspector.ContextMenu} contextMenu - * @param {string} url - * @param {boolean} isContentScript - * @param {boolean} isBlackboxed + * @param {!WebInspector.UISourceCode} uiSourceCode */ - appendBlackboxURLContextMenuItems: function(contextMenu, url, isContentScript, isBlackboxed) + appendBlackboxURLContextMenuItems: function(contextMenu, uiSourceCode) { - var canBlackBox = WebInspector.blackboxManager.canBlackboxURL(url); - if (!isBlackboxed && !isContentScript && !canBlackBox) - return; - - if (isBlackboxed) { - contextMenu.appendItem(WebInspector.UIString.capitalize("Stop ^blackboxing"), this._handleContextMenuBlackboxURL.bind(this, url, isContentScript, false)); - } else { - if (canBlackBox) - contextMenu.appendItem(WebInspector.UIString.capitalize("Blackbox ^script"), this._handleContextMenuBlackboxURL.bind(this, url, false, true)); - if (isContentScript) - contextMenu.appendItem(WebInspector.UIString.capitalize("Blackbox ^all ^content ^scripts"), this._handleContextMenuBlackboxURL.bind(this, url, true, true)); + var canBlackbox = WebInspector.blackboxManager.canBlackboxUISourceCode(uiSourceCode); + var isBlackboxed = WebInspector.blackboxManager.isBlackboxedUISourceCode(uiSourceCode); + var isContentScript = uiSourceCode.project().type() === WebInspector.projectTypes.ContentScripts; + + var manager = WebInspector.blackboxManager; + if (canBlackbox) { + if (isBlackboxed) + contextMenu.appendItem(WebInspector.UIString.capitalize("Stop ^blackboxing"), manager.unblackboxUISourceCode.bind(manager, uiSourceCode)); + else + contextMenu.appendItem(WebInspector.UIString.capitalize("Blackbox ^script"), manager.blackboxUISourceCode.bind(manager, uiSourceCode)); } - }, - - /** - * @param {string} url - * @param {boolean} isContentScript - * @param {boolean} blackbox - */ - _handleContextMenuBlackboxURL: function(url, isContentScript, blackbox) - { - if (blackbox) { - if (isContentScript) - WebInspector.moduleSetting("skipContentScripts").set(true); + if (isContentScript) { + if (isBlackboxed) + contextMenu.appendItem(WebInspector.UIString.capitalize("Stop blackboxing ^all ^content ^scripts"), manager.blackboxContentScripts.bind(manager)); else - WebInspector.blackboxManager.blackboxURL(url); - } else { - WebInspector.blackboxManager.unblackbox(url, isContentScript); + contextMenu.appendItem(WebInspector.UIString.capitalize("Blackbox ^all ^content ^scripts"), manager.unblackboxContentScripts.bind(manager)); } }, diff --git a/front_end/sources/JavaScriptSourceFrame.js b/front_end/sources/JavaScriptSourceFrame.js index 5a73f41a97..05e319d461 100644 --- a/front_end/sources/JavaScriptSourceFrame.js +++ b/front_end/sources/JavaScriptSourceFrame.js @@ -142,15 +142,16 @@ WebInspector.JavaScriptSourceFrame.prototype = { _showBlackboxInfobarIfNeeded: function() { - if (!this.uiSourceCode().contentType().hasScripts()) + var uiSourceCode = this.uiSourceCode(); + if (!uiSourceCode.contentType().hasScripts()) return; - var projectType = this.uiSourceCode().project().type(); + var projectType = uiSourceCode.project().type(); if (projectType === WebInspector.projectTypes.Snippets) return; - var networkURL = WebInspector.networkMapping.networkURL(this.uiSourceCode()); - var url = projectType === WebInspector.projectTypes.Formatter ? this.uiSourceCode().url() : networkURL; + var networkURL = WebInspector.networkMapping.networkURL(uiSourceCode); + var url = projectType === WebInspector.projectTypes.Formatter ? uiSourceCode.url() : networkURL; var isContentScript = projectType === WebInspector.projectTypes.ContentScripts; - if (!WebInspector.blackboxManager.isBlackboxedUISourceCode(this.uiSourceCode())) { + if (!WebInspector.blackboxManager.isBlackboxedUISourceCode(uiSourceCode)) { this._hideBlackboxInfobar(); return; } @@ -163,8 +164,8 @@ WebInspector.JavaScriptSourceFrame.prototype = { infobar.createDetailsRowMessage(WebInspector.UIString("Debugger will skip stepping through this script, and will not stop on exceptions")); - var scriptFile = this._scriptFileForTarget.valuesArray()[0]; - if (scriptFile.hasSourceMapURL()) + var scriptFile = this._scriptFileForTarget.size ? this._scriptFileForTarget.valuesArray()[0] : null; + if (scriptFile && scriptFile.hasSourceMapURL()) infobar.createDetailsRowMessage(WebInspector.UIString("Source map found, but ignored for blackboxed file.")); infobar.createDetailsRowMessage(); infobar.createDetailsRowMessage(WebInspector.UIString("Possible ways to cancel this behavior are:")); @@ -176,7 +177,9 @@ WebInspector.JavaScriptSourceFrame.prototype = { function unblackbox() { - WebInspector.blackboxManager.unblackbox(url, isContentScript); + WebInspector.blackboxManager.unblackboxUISourceCode(uiSourceCode); + if (projectType === WebInspector.projectTypes.ContentScripts) + WebInspector.blackboxManager.unblackboxContentScripts(); } this._updateInfobars(); diff --git a/front_end/sources/SourcesPanel.js b/front_end/sources/SourcesPanel.js index efc8026cea..603e73aa29 100644 --- a/front_end/sources/SourcesPanel.js +++ b/front_end/sources/SourcesPanel.js @@ -931,12 +931,8 @@ WebInspector.SourcesPanel.prototype = { contextMenu.appendItem(WebInspector.UIString.capitalize("Continue to ^here"), this._continueToLocation.bind(this, uiLocation)); } - if (contentType.hasScripts() && projectType !== WebInspector.projectTypes.Snippets) { - var networkURL = this._networkMapping.networkURL(uiSourceCode); - var url = projectType === WebInspector.projectTypes.Formatter ? uiSourceCode.url() : networkURL; - var isBlackboxed = WebInspector.blackboxManager.isBlackboxedUISourceCode(uiSourceCode); - this.sidebarPanes.callstack.appendBlackboxURLContextMenuItems(contextMenu, url, projectType === WebInspector.projectTypes.ContentScripts, isBlackboxed); - } + if (contentType.hasScripts() && projectType !== WebInspector.projectTypes.Snippets) + this.sidebarPanes.callstack.appendBlackboxURLContextMenuItems(contextMenu, uiSourceCode); }, /**