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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/common/ParsedURL.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
(...skipping 11 matching lines...) Expand all
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 /** 29 /**
30 * @unrestricted 30 * @unrestricted
31 */ 31 */
32 WebInspector.ParsedURL = class { 32 Common.ParsedURL = class {
33 /** 33 /**
34 * @param {string} url 34 * @param {string} url
35 */ 35 */
36 constructor(url) { 36 constructor(url) {
37 this.isValid = false; 37 this.isValid = false;
38 this.url = url; 38 this.url = url;
39 this.scheme = ''; 39 this.scheme = '';
40 this.host = ''; 40 this.host = '';
41 this.port = ''; 41 this.port = '';
42 this.path = ''; 42 this.path = '';
43 this.queryParams = ''; 43 this.queryParams = '';
44 this.fragment = ''; 44 this.fragment = '';
45 this.folderPathComponents = ''; 45 this.folderPathComponents = '';
46 this.lastPathComponent = ''; 46 this.lastPathComponent = '';
47 47
48 var match = url.match(WebInspector.ParsedURL._urlRegex()); 48 var match = url.match(Common.ParsedURL._urlRegex());
49 if (match) { 49 if (match) {
50 this.isValid = true; 50 this.isValid = true;
51 this.scheme = match[1].toLowerCase(); 51 this.scheme = match[1].toLowerCase();
52 this.host = match[2]; 52 this.host = match[2];
53 this.port = match[3]; 53 this.port = match[3];
54 this.path = match[4] || '/'; 54 this.path = match[4] || '/';
55 this.queryParams = match[5] || ''; 55 this.queryParams = match[5] || '';
56 this.fragment = match[6]; 56 this.fragment = match[6];
57 } else { 57 } else {
58 if (this.url.startsWith('data:')) { 58 if (this.url.startsWith('data:')) {
(...skipping 28 matching lines...) Expand all
87 else 87 else
88 fileSystemPath = 'file:///' + fileSystemPath; 88 fileSystemPath = 'file:///' + fileSystemPath;
89 } 89 }
90 return fileSystemPath; 90 return fileSystemPath;
91 } 91 }
92 92
93 /** 93 /**
94 * @return {!RegExp} 94 * @return {!RegExp}
95 */ 95 */
96 static _urlRegex() { 96 static _urlRegex() {
97 if (WebInspector.ParsedURL._urlRegexInstance) 97 if (Common.ParsedURL._urlRegexInstance)
98 return WebInspector.ParsedURL._urlRegexInstance; 98 return Common.ParsedURL._urlRegexInstance;
99 // RegExp groups: 99 // RegExp groups:
100 // 1 - scheme (using the RFC3986 grammar) 100 // 1 - scheme (using the RFC3986 grammar)
101 // 2 - hostname 101 // 2 - hostname
102 // 3 - ?port 102 // 3 - ?port
103 // 4 - ?path 103 // 4 - ?path
104 // 5 - ?query 104 // 5 - ?query
105 // 6 - ?fragment 105 // 6 - ?fragment
106 var schemeRegex = /([A-Za-z][A-Za-z0-9+.-]*):\/\//; 106 var schemeRegex = /([A-Za-z][A-Za-z0-9+.-]*):\/\//;
107 var hostRegex = /([^\s\/:]*)/; 107 var hostRegex = /([^\s\/:]*)/;
108 var portRegex = /(?::([\d]+))?/; 108 var portRegex = /(?::([\d]+))?/;
109 var pathRegex = /(\/[^#?]*)?/; 109 var pathRegex = /(\/[^#?]*)?/;
110 var queryRegex = /(?:\?([^#]*))?/; 110 var queryRegex = /(?:\?([^#]*))?/;
111 var fragmentRegex = /(?:#(.*))?/; 111 var fragmentRegex = /(?:#(.*))?/;
112 112
113 WebInspector.ParsedURL._urlRegexInstance = new RegExp( 113 Common.ParsedURL._urlRegexInstance = new RegExp(
114 '^' + schemeRegex.source + hostRegex.source + portRegex.source + pathReg ex.source + queryRegex.source + 114 '^' + schemeRegex.source + hostRegex.source + portRegex.source + pathReg ex.source + queryRegex.source +
115 fragmentRegex.source + '$'); 115 fragmentRegex.source + '$');
116 return WebInspector.ParsedURL._urlRegexInstance; 116 return Common.ParsedURL._urlRegexInstance;
117 } 117 }
118 118
119 /** 119 /**
120 * @param {string} url 120 * @param {string} url
121 * @return {string} 121 * @return {string}
122 */ 122 */
123 static extractPath(url) { 123 static extractPath(url) {
124 var parsedURL = url.asParsedURL(); 124 var parsedURL = url.asParsedURL();
125 return parsedURL ? parsedURL.path : ''; 125 return parsedURL ? parsedURL.path : '';
126 } 126 }
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 */ 314 */
315 urlWithoutScheme() { 315 urlWithoutScheme() {
316 if (this.scheme && this.url.startsWith(this.scheme + '://')) 316 if (this.scheme && this.url.startsWith(this.scheme + '://'))
317 return this.url.substring(this.scheme.length + 3); 317 return this.url.substring(this.scheme.length + 3);
318 return this.url; 318 return this.url;
319 } 319 }
320 }; 320 };
321 321
322 322
323 /** 323 /**
324 * @return {?WebInspector.ParsedURL} 324 * @return {?Common.ParsedURL}
325 */ 325 */
326 String.prototype.asParsedURL = function() { 326 String.prototype.asParsedURL = function() {
327 var parsedURL = new WebInspector.ParsedURL(this.toString()); 327 var parsedURL = new Common.ParsedURL(this.toString());
328 if (parsedURL.isValid) 328 if (parsedURL.isValid)
329 return parsedURL; 329 return parsedURL;
330 return null; 330 return null;
331 }; 331 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698