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

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

Issue 2422803002: DevTools: prefix node.js scripts's sourceURL with "file://" to make them a valid url (Closed)
Patch Set: Created 4 years, 2 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
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 var pathRegex = /(\/[^#?]*)?/; 93 var pathRegex = /(\/[^#?]*)?/;
94 var queryRegex = /(?:\?([^#]*))?/; 94 var queryRegex = /(?:\?([^#]*))?/;
95 var fragmentRegex = /(?:#(.*))?/; 95 var fragmentRegex = /(?:#(.*))?/;
96 96
97 WebInspector.ParsedURL._urlRegexInstance = new RegExp("^" + schemeRegex.sour ce + hostRegex.source + portRegex.source + pathRegex.source + queryRegex.source + fragmentRegex.source + "$"); 97 WebInspector.ParsedURL._urlRegexInstance = new RegExp("^" + schemeRegex.sour ce + hostRegex.source + portRegex.source + pathRegex.source + queryRegex.source + fragmentRegex.source + "$");
98 return WebInspector.ParsedURL._urlRegexInstance; 98 return WebInspector.ParsedURL._urlRegexInstance;
99 } 99 }
100 100
101 /** 101 /**
102 * @param {string} url 102 * @param {string} url
103 * @return {!Array.<string>} 103 * @return {string}
104 */ 104 */
105 WebInspector.ParsedURL.splitURLIntoPathComponents = function(url) 105 WebInspector.ParsedURL.extractPath = function(url)
106 { 106 {
107 if (url.startsWith("/")) 107 var parsedURL = url.asParsedURL();
108 url = "file://" + url; 108 return parsedURL ? parsedURL.path : "";
109 var parsedURL = new WebInspector.ParsedURL(url);
110 var origin;
111 var folderPath;
112 var name;
113 if (parsedURL.isValid) {
114 origin = parsedURL.scheme + "://" + parsedURL.host;
115 if (parsedURL.port)
116 origin += ":" + parsedURL.port;
117 folderPath = parsedURL.folderPathComponents;
118 name = parsedURL.lastPathComponent;
119 if (parsedURL.queryParams)
120 name += "?" + parsedURL.queryParams;
121 } else {
122 origin = "";
123 folderPath = "";
124 name = url;
125 }
126 var result = [origin];
127 var splittedPath = folderPath.split("/");
128 for (var i = 1; i < splittedPath.length; ++i) {
129 if (!splittedPath[i])
130 continue;
131 result.push(splittedPath[i]);
132 }
133 result.push(name);
134 return result;
135 } 109 }
136 110
137 /** 111 /**
138 * @param {string} url 112 * @param {string} url
139 * @return {string} 113 * @return {string}
140 */ 114 */
141 WebInspector.ParsedURL.extractOrigin = function(url) 115 WebInspector.ParsedURL.extractOrigin = function(url)
142 { 116 {
143 var parsedURL = new WebInspector.ParsedURL(url); 117 var parsedURL = url.asParsedURL();
144 if (!parsedURL.isValid) 118 return parsedURL ? parsedURL.securityOrigin() : "";
145 return "";
146
147 var origin = parsedURL.scheme + "://" + parsedURL.host;
148 if (parsedURL.port)
149 origin += ":" + parsedURL.port;
150 return origin;
151 } 119 }
152 120
153 /** 121 /**
154 * @param {string} url 122 * @param {string} url
155 * @return {string} 123 * @return {string}
156 */ 124 */
157 WebInspector.ParsedURL.extractExtension = function(url) 125 WebInspector.ParsedURL.extractExtension = function(url)
158 { 126 {
159 var lastIndexOfDot = url.lastIndexOf("."); 127 var lastIndexOfDot = url.lastIndexOf(".");
160 var extension = lastIndexOfDot !== -1 ? url.substr(lastIndexOfDot + 1) : ""; 128 var extension = lastIndexOfDot !== -1 ? url.substr(lastIndexOfDot + 1) : "";
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 /** 316 /**
349 * @return {?WebInspector.ParsedURL} 317 * @return {?WebInspector.ParsedURL}
350 */ 318 */
351 String.prototype.asParsedURL = function() 319 String.prototype.asParsedURL = function()
352 { 320 {
353 var parsedURL = new WebInspector.ParsedURL(this.toString()); 321 var parsedURL = new WebInspector.ParsedURL(this.toString());
354 if (parsedURL.isValid) 322 if (parsedURL.isValid)
355 return parsedURL; 323 return parsedURL;
356 return null; 324 return null;
357 } 325 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698