Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: Source/devtools/front_end/sdk/BlackboxSupport.js

Issue 548323002: DevTools: Blackbox content scripts - frontend. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: added a test Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 WebInspector.BlackboxSupport = function() 5 WebInspector.BlackboxSupport = {}
6 {
7 }
8 6
9 /** 7 /**
10 * @param {string} url 8 * @param {string} url
11 * @return {string} 9 * @return {string}
12 */ 10 */
13 WebInspector.BlackboxSupport._urlToRegExpString = function(url) 11 WebInspector.BlackboxSupport._urlToRegExpString = function(url)
14 { 12 {
15 var name = new WebInspector.ParsedURL(url).lastPathComponent; 13 var parsedURL = new WebInspector.ParsedURL(url);
16 return "/" + name.escapeForRegExp() + (url.endsWith(name) ? "$" : "\\b"); 14 if (parsedURL.isAboutBlank() || parsedURL.isDataURL())
15 return "";
16 if (!parsedURL.isValid)
17 return "^" + url.escapeForRegExp() + "$";
18 var name = parsedURL.lastPathComponent;
19 if (name)
20 name = "/" + name;
21 else if (parsedURL.folderPathComponents)
22 name = parsedURL.folderPathComponents + "/";
23 if (!name)
24 return "";
25 var scheme = parsedURL.scheme;
26 var prefix = "";
27 if (scheme && scheme !== "http" && scheme !== "https") {
28 prefix = "^" + scheme + "://";
29 if (scheme === "chrome-extension")
30 prefix += parsedURL.host + "\\b";
31 prefix += ".*";
32 }
33 return prefix + name.escapeForRegExp() + (url.endsWith(name) ? "$" : "\\b");
17 } 34 }
18 35
19 /** 36 /**
37 * @param {string} url
38 * @return {boolean}
39 */
40 WebInspector.BlackboxSupport.canBlackboxURL = function(url)
41 {
42 return !!WebInspector.BlackboxSupport._urlToRegExpString(url);
43 }
44
45 /**
20 * @param {string} url 46 * @param {string} url
21 */ 47 */
22 WebInspector.BlackboxSupport.blackboxURL = function(url) 48 WebInspector.BlackboxSupport.blackboxURL = function(url)
23 { 49 {
24 var regexPatterns = WebInspector.settings.skipStackFramesPattern.getAsArray( ); 50 var regexPatterns = WebInspector.settings.skipStackFramesPattern.getAsArray( );
25 var regexValue = WebInspector.BlackboxSupport._urlToRegExpString(url); 51 var regexValue = WebInspector.BlackboxSupport._urlToRegExpString(url);
52 if (!regexValue)
53 return;
26 var found = false; 54 var found = false;
27 for (var i = 0; i < regexPatterns.length; ++i) { 55 for (var i = 0; i < regexPatterns.length; ++i) {
28 var item = regexPatterns[i]; 56 var item = regexPatterns[i];
29 if (item.pattern === regexValue) { 57 if (item.pattern === regexValue) {
30 item.disabled = false; 58 item.disabled = false;
31 found = true; 59 found = true;
32 break; 60 break;
33 } 61 }
34 } 62 }
35 if (!found) 63 if (!found)
36 regexPatterns.push({ pattern: regexValue }); 64 regexPatterns.push({ pattern: regexValue });
37 WebInspector.settings.skipStackFramesPattern.setAsArray(regexPatterns); 65 WebInspector.settings.skipStackFramesPattern.setAsArray(regexPatterns);
38 } 66 }
39 67
40 /** 68 /**
41 * @param {string} url 69 * @param {string} url
70 * @param {boolean} isContentScript
42 */ 71 */
43 WebInspector.BlackboxSupport.unblackboxURL = function(url) 72 WebInspector.BlackboxSupport.unblackbox = function(url, isContentScript)
44 { 73 {
74 if (isContentScript)
75 WebInspector.settings.skipContentScripts.set(false);
76
45 var regexPatterns = WebInspector.settings.skipStackFramesPattern.getAsArray( ); 77 var regexPatterns = WebInspector.settings.skipStackFramesPattern.getAsArray( );
46 var regexValue = WebInspector.BlackboxSupport._urlToRegExpString(url); 78 var regexValue = WebInspector.BlackboxSupport._urlToRegExpString(url);
79 if (!regexValue)
80 return;
47 regexPatterns = regexPatterns.filter(function(item) { 81 regexPatterns = regexPatterns.filter(function(item) {
48 return item.pattern !== regexValue; 82 return item.pattern !== regexValue;
49 }); 83 });
50 for (var i = 0; i < regexPatterns.length; ++i) { 84 for (var i = 0; i < regexPatterns.length; ++i) {
51 var item = regexPatterns[i]; 85 var item = regexPatterns[i];
52 if (item.disabled) 86 if (item.disabled)
53 continue; 87 continue;
54 try { 88 try {
55 var regex = new RegExp(item.pattern); 89 var regex = new RegExp(item.pattern);
56 if (regex.test(url)) 90 if (regex.test(url))
57 item.disabled = true; 91 item.disabled = true;
58 } catch (e) { 92 } catch (e) {
59 } 93 }
60 } 94 }
61 WebInspector.settings.skipStackFramesPattern.setAsArray(regexPatterns); 95 WebInspector.settings.skipStackFramesPattern.setAsArray(regexPatterns);
62 } 96 }
63 97
64 /** 98 /**
65 * @param {string} url 99 * @param {string} url
66 * @return {boolean} 100 * @return {boolean}
67 */ 101 */
68 WebInspector.BlackboxSupport.isBlackboxedURL = function(url) 102 WebInspector.BlackboxSupport.isBlackboxedURL = function(url)
69 { 103 {
70 var regex = WebInspector.settings.skipStackFramesPattern.asRegExp(); 104 var regex = WebInspector.settings.skipStackFramesPattern.asRegExp();
71 return (url && regex) ? regex.test(url) : false; 105 return (url && regex) ? regex.test(url) : false;
72 } 106 }
107
108 /**
109 * @param {string} url
110 * @param {boolean} isContentScript
111 * @return {boolean}
112 */
113 WebInspector.BlackboxSupport.isBlackboxed = function(url, isContentScript)
114 {
115 if (isContentScript && WebInspector.settings.skipContentScripts.get())
116 return true;
117 return WebInspector.BlackboxSupport.isBlackboxedURL(url);
118 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/helpScreen.css ('k') | Source/devtools/front_end/sdk/DebuggerModel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698