| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @constructor | |
| 7 */ | |
| 8 WebInspector.BlackboxManager = function() | |
| 9 { | |
| 10 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI
nspector.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSource, this
); | |
| 11 WebInspector.moduleSetting("skipStackFramesPattern").addChangeListener(this.
_patternChanged.bind(this)); | |
| 12 WebInspector.moduleSetting("skipContentScripts").addChangeListener(this._pat
ternChanged.bind(this)); | |
| 13 } | |
| 14 | |
| 15 WebInspector.BlackboxManager.prototype = { | |
| 16 /** | |
| 17 * @param {!WebInspector.Event} event | |
| 18 */ | |
| 19 _parsedScriptSource: function(event) | |
| 20 { | |
| 21 var script = /** @type {!WebInspector.Script} */ (event.data); | |
| 22 this._blackboxScriptIfNeeded(script); | |
| 23 }, | |
| 24 | |
| 25 _patternChanged: function() | |
| 26 { | |
| 27 for (var debuggerModel of WebInspector.DebuggerModel.instances()) { | |
| 28 for (var scriptId in debuggerModel.scripts) | |
| 29 this._blackboxScriptIfNeeded(debuggerModel.scripts[scriptId]); | |
| 30 } | |
| 31 }, | |
| 32 | |
| 33 /** | |
| 34 * @param {!WebInspector.Script} script | |
| 35 */ | |
| 36 _blackboxScriptIfNeeded: function(script) | |
| 37 { | |
| 38 if (WebInspector.BlackboxSupport.isBlackboxed(script.sourceURL, script.i
sContentScript())) | |
| 39 script.setBlackboxedRanges([ { line: 0, column: 0 } ]); | |
| 40 else | |
| 41 script.setBlackboxedRanges([]); | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 WebInspector.BlackboxSupport = {} | |
| 46 | |
| 47 /** | |
| 48 * @param {string} url | |
| 49 * @return {string} | |
| 50 */ | |
| 51 WebInspector.BlackboxSupport._urlToRegExpString = function(url) | |
| 52 { | |
| 53 var parsedURL = new WebInspector.ParsedURL(url); | |
| 54 if (parsedURL.isAboutBlank() || parsedURL.isDataURL()) | |
| 55 return ""; | |
| 56 if (!parsedURL.isValid) | |
| 57 return "^" + url.escapeForRegExp() + "$"; | |
| 58 var name = parsedURL.lastPathComponent; | |
| 59 if (name) | |
| 60 name = "/" + name; | |
| 61 else if (parsedURL.folderPathComponents) | |
| 62 name = parsedURL.folderPathComponents + "/"; | |
| 63 if (!name) | |
| 64 name = parsedURL.host; | |
| 65 if (!name) | |
| 66 return ""; | |
| 67 var scheme = parsedURL.scheme; | |
| 68 var prefix = ""; | |
| 69 if (scheme && scheme !== "http" && scheme !== "https") { | |
| 70 prefix = "^" + scheme + "://"; | |
| 71 if (scheme === "chrome-extension") | |
| 72 prefix += parsedURL.host + "\\b"; | |
| 73 prefix += ".*"; | |
| 74 } | |
| 75 return prefix + name.escapeForRegExp() + (url.endsWith(name) ? "$" : "\\b"); | |
| 76 } | |
| 77 | |
| 78 /** | |
| 79 * @param {string} url | |
| 80 * @return {boolean} | |
| 81 */ | |
| 82 WebInspector.BlackboxSupport.canBlackboxURL = function(url) | |
| 83 { | |
| 84 return !!WebInspector.BlackboxSupport._urlToRegExpString(url); | |
| 85 } | |
| 86 | |
| 87 /** | |
| 88 * @param {string} url | |
| 89 */ | |
| 90 WebInspector.BlackboxSupport.blackboxURL = function(url) | |
| 91 { | |
| 92 var regexPatterns = WebInspector.moduleSetting("skipStackFramesPattern").get
AsArray(); | |
| 93 var regexValue = WebInspector.BlackboxSupport._urlToRegExpString(url); | |
| 94 if (!regexValue) | |
| 95 return; | |
| 96 var found = false; | |
| 97 for (var i = 0; i < regexPatterns.length; ++i) { | |
| 98 var item = regexPatterns[i]; | |
| 99 if (item.pattern === regexValue) { | |
| 100 item.disabled = false; | |
| 101 found = true; | |
| 102 break; | |
| 103 } | |
| 104 } | |
| 105 if (!found) | |
| 106 regexPatterns.push({ pattern: regexValue }); | |
| 107 WebInspector.moduleSetting("skipStackFramesPattern").setAsArray(regexPattern
s); | |
| 108 } | |
| 109 | |
| 110 /** | |
| 111 * @param {string} url | |
| 112 * @param {boolean} isContentScript | |
| 113 */ | |
| 114 WebInspector.BlackboxSupport.unblackbox = function(url, isContentScript) | |
| 115 { | |
| 116 if (isContentScript) | |
| 117 WebInspector.moduleSetting("skipContentScripts").set(false); | |
| 118 | |
| 119 var regexPatterns = WebInspector.moduleSetting("skipStackFramesPattern").get
AsArray(); | |
| 120 var regexValue = WebInspector.BlackboxSupport._urlToRegExpString(url); | |
| 121 if (!regexValue) | |
| 122 return; | |
| 123 regexPatterns = regexPatterns.filter(function(item) { | |
| 124 return item.pattern !== regexValue; | |
| 125 }); | |
| 126 for (var i = 0; i < regexPatterns.length; ++i) { | |
| 127 var item = regexPatterns[i]; | |
| 128 if (item.disabled) | |
| 129 continue; | |
| 130 try { | |
| 131 var regex = new RegExp(item.pattern); | |
| 132 if (regex.test(url)) | |
| 133 item.disabled = true; | |
| 134 } catch (e) { | |
| 135 } | |
| 136 } | |
| 137 WebInspector.moduleSetting("skipStackFramesPattern").setAsArray(regexPattern
s); | |
| 138 } | |
| 139 | |
| 140 /** | |
| 141 * @param {string} url | |
| 142 * @return {boolean} | |
| 143 */ | |
| 144 WebInspector.BlackboxSupport.isBlackboxedURL = function(url) | |
| 145 { | |
| 146 var regex = WebInspector.moduleSetting("skipStackFramesPattern").asRegExp(); | |
| 147 return regex && regex.test(url); | |
| 148 } | |
| 149 | |
| 150 /** | |
| 151 * @param {string} url | |
| 152 * @param {boolean} isContentScript | |
| 153 * @return {boolean} | |
| 154 */ | |
| 155 WebInspector.BlackboxSupport.isBlackboxed = function(url, isContentScript) | |
| 156 { | |
| 157 if (isContentScript && WebInspector.moduleSetting("skipContentScripts").get(
)) | |
| 158 return true; | |
| 159 return WebInspector.BlackboxSupport.isBlackboxedURL(url); | |
| 160 } | |
| 161 | |
| 162 /** | |
| 163 * @param {function(!WebInspector.Event)} listener | |
| 164 * @param {!Object=} thisObject | |
| 165 */ | |
| 166 WebInspector.BlackboxSupport.addChangeListener = function(listener, thisObject) | |
| 167 { | |
| 168 WebInspector.moduleSetting("skipStackFramesPattern").addChangeListener(liste
ner, thisObject); | |
| 169 } | |
| 170 | |
| 171 /** | |
| 172 * @param {function(!WebInspector.Event)} listener | |
| 173 * @param {!Object=} thisObject | |
| 174 */ | |
| 175 WebInspector.BlackboxSupport.removeChangeListener = function(listener, thisObjec
t) | |
| 176 { | |
| 177 WebInspector.moduleSetting("skipStackFramesPattern").removeChangeListener(li
stener, thisObject); | |
| 178 } | |
| OLD | NEW |