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.
5 WebInspector.BlackboxSupport = {}
11 WebInspector.BlackboxSupport._urlToRegExpString = function(url)
13 var parsedURL = new WebInspector.ParsedURL(url);
14 if (parsedURL.isAboutBlank() || parsedURL.isDataURL())
16 if (!parsedURL.isValid)
17 return "^" + url.escapeForRegExp() + "$";
18 var name = parsedURL.lastPathComponent;
21 else if (parsedURL.folderPathComponents)
22 name = parsedURL.folderPathComponents + "/";
24 name = parsedURL.host;
27 var scheme = parsedURL.scheme;
29 if (scheme && scheme !== "http" && scheme !== "https") {
30 prefix = "^" + scheme + "://";
31 if (scheme === "chrome-extension")
32 prefix += parsedURL.host + "\\b";
35 return prefix + name.escapeForRegExp() + (url.endsWith(name) ? "$" : "\\b");
42 WebInspector.BlackboxSupport.canBlackboxURL = function(url)
44 return !!WebInspector.BlackboxSupport._urlToRegExpString(url);
50 WebInspector.BlackboxSupport.blackboxURL = function(url)
52 var regexPatterns = WebInspector.moduleSetting("skipStackFramesPattern").getAsArray();
53 var regexValue = WebInspector.BlackboxSupport._urlToRegExpString(url);
57 for (var i = 0; i < regexPatterns.length; ++i) {
58 var item = regexPatterns[i];
59 if (item.pattern === regexValue) {
60 item.disabled = false;
66 regexPatterns.push({ pattern: regexValue });
67 WebInspector.moduleSetting("skipStackFramesPattern").setAsArray(regexPatterns);
72 * @param {boolean} isContentScript
74 WebInspector.BlackboxSupport.unblackbox = function(url, isContentScript)
77 WebInspector.moduleSetting("skipContentScripts").set(false);
79 var regexPatterns = WebInspector.moduleSetting("skipStackFramesPattern").getAsArray();
80 var regexValue = WebInspector.BlackboxSupport._urlToRegExpString(url);
83 regexPatterns = regexPatterns.filter(function(item) {
84 return item.pattern !== regexValue;
86 for (var i = 0; i < regexPatterns.length; ++i) {
87 var item = regexPatterns[i];
91 var regex = new RegExp(item.pattern);
97 WebInspector.moduleSetting("skipStackFramesPattern").setAsArray(regexPatterns);
101 * @param {string} url
104 WebInspector.BlackboxSupport.isBlackboxedURL = function(url)
106 var regex = WebInspector.moduleSetting("skipStackFramesPattern").asRegExp();
107 return regex && regex.test(url);
111 * @param {string} url
112 * @param {boolean} isContentScript
115 WebInspector.BlackboxSupport.isBlackboxed = function(url, isContentScript)
117 if (isContentScript && WebInspector.moduleSetting("skipContentScripts").get())
119 return WebInspector.BlackboxSupport.isBlackboxedURL(url);
123 * @param {function(!WebInspector.Event)} listener
124 * @param {!Object=} thisObject
126 WebInspector.BlackboxSupport.addChangeListener = function(listener, thisObject)
128 WebInspector.moduleSetting("skipStackFramesPattern").addChangeListener(listener, thisObject);
132 * @param {function(!WebInspector.Event)} listener
133 * @param {!Object=} thisObject
135 WebInspector.BlackboxSupport.removeChangeListener = function(listener, thisObject)
137 WebInspector.moduleSetting("skipStackFramesPattern").removeChangeListener(listener, thisObject);