OLD | NEW |
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 this.path = this.url; | 64 this.path = this.url; |
65 } | 65 } |
66 | 66 |
67 var lastSlashIndex = this.path.lastIndexOf("/"); | 67 var lastSlashIndex = this.path.lastIndexOf("/"); |
68 if (lastSlashIndex !== -1) { | 68 if (lastSlashIndex !== -1) { |
69 this.folderPathComponents = this.path.substring(0, lastSlashIndex); | 69 this.folderPathComponents = this.path.substring(0, lastSlashIndex); |
70 this.lastPathComponent = this.path.substring(lastSlashIndex + 1); | 70 this.lastPathComponent = this.path.substring(lastSlashIndex + 1); |
71 } else { | 71 } else { |
72 this.lastPathComponent = this.path; | 72 this.lastPathComponent = this.path; |
73 } | 73 } |
74 } | 74 }; |
75 | 75 |
76 /** | 76 /** |
77 * @param {string} fileSystemPath | 77 * @param {string} fileSystemPath |
78 * @return {string} | 78 * @return {string} |
79 */ | 79 */ |
80 WebInspector.ParsedURL.platformPathToURL = function(fileSystemPath) | 80 WebInspector.ParsedURL.platformPathToURL = function(fileSystemPath) |
81 { | 81 { |
82 fileSystemPath = fileSystemPath.replace(/\\/g, "/"); | 82 fileSystemPath = fileSystemPath.replace(/\\/g, "/"); |
83 if (!fileSystemPath.startsWith("file://")) { | 83 if (!fileSystemPath.startsWith("file://")) { |
84 if (fileSystemPath.startsWith("/")) | 84 if (fileSystemPath.startsWith("/")) |
85 fileSystemPath = "file://" + fileSystemPath; | 85 fileSystemPath = "file://" + fileSystemPath; |
86 else | 86 else |
87 fileSystemPath = "file:///" + fileSystemPath; | 87 fileSystemPath = "file:///" + fileSystemPath; |
88 } | 88 } |
89 return fileSystemPath; | 89 return fileSystemPath; |
90 } | 90 }; |
91 | 91 |
92 /** | 92 /** |
93 * @return {!RegExp} | 93 * @return {!RegExp} |
94 */ | 94 */ |
95 WebInspector.ParsedURL._urlRegex = function() | 95 WebInspector.ParsedURL._urlRegex = function() |
96 { | 96 { |
97 if (WebInspector.ParsedURL._urlRegexInstance) | 97 if (WebInspector.ParsedURL._urlRegexInstance) |
98 return WebInspector.ParsedURL._urlRegexInstance; | 98 return WebInspector.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("^" + schemeRegex.sour
ce + hostRegex.source + portRegex.source + pathRegex.source + queryRegex.source
+ fragmentRegex.source + "$"); | 113 WebInspector.ParsedURL._urlRegexInstance = new RegExp("^" + schemeRegex.sour
ce + hostRegex.source + portRegex.source + pathRegex.source + queryRegex.source
+ fragmentRegex.source + "$"); |
114 return WebInspector.ParsedURL._urlRegexInstance; | 114 return WebInspector.ParsedURL._urlRegexInstance; |
115 } | 115 }; |
116 | 116 |
117 /** | 117 /** |
118 * @param {string} url | 118 * @param {string} url |
119 * @return {string} | 119 * @return {string} |
120 */ | 120 */ |
121 WebInspector.ParsedURL.extractPath = function(url) | 121 WebInspector.ParsedURL.extractPath = function(url) |
122 { | 122 { |
123 var parsedURL = url.asParsedURL(); | 123 var parsedURL = url.asParsedURL(); |
124 return parsedURL ? parsedURL.path : ""; | 124 return parsedURL ? parsedURL.path : ""; |
125 } | 125 }; |
126 | 126 |
127 /** | 127 /** |
128 * @param {string} url | 128 * @param {string} url |
129 * @return {string} | 129 * @return {string} |
130 */ | 130 */ |
131 WebInspector.ParsedURL.extractOrigin = function(url) | 131 WebInspector.ParsedURL.extractOrigin = function(url) |
132 { | 132 { |
133 var parsedURL = url.asParsedURL(); | 133 var parsedURL = url.asParsedURL(); |
134 return parsedURL ? parsedURL.securityOrigin() : ""; | 134 return parsedURL ? parsedURL.securityOrigin() : ""; |
135 } | 135 }; |
136 | 136 |
137 /** | 137 /** |
138 * @param {string} url | 138 * @param {string} url |
139 * @return {string} | 139 * @return {string} |
140 */ | 140 */ |
141 WebInspector.ParsedURL.extractExtension = function(url) | 141 WebInspector.ParsedURL.extractExtension = function(url) |
142 { | 142 { |
143 var lastIndexOfDot = url.lastIndexOf("."); | 143 var lastIndexOfDot = url.lastIndexOf("."); |
144 var extension = lastIndexOfDot !== -1 ? url.substr(lastIndexOfDot + 1) : ""; | 144 var extension = lastIndexOfDot !== -1 ? url.substr(lastIndexOfDot + 1) : ""; |
145 var indexOfQuestionMark = extension.indexOf("?"); | 145 var indexOfQuestionMark = extension.indexOf("?"); |
146 if (indexOfQuestionMark !== -1) | 146 if (indexOfQuestionMark !== -1) |
147 extension = extension.substr(0, indexOfQuestionMark); | 147 extension = extension.substr(0, indexOfQuestionMark); |
148 return extension; | 148 return extension; |
149 } | 149 }; |
150 | 150 |
151 /** | 151 /** |
152 * @param {string} url | 152 * @param {string} url |
153 * @return {string} | 153 * @return {string} |
154 */ | 154 */ |
155 WebInspector.ParsedURL.extractName = function(url) | 155 WebInspector.ParsedURL.extractName = function(url) |
156 { | 156 { |
157 var index = url.lastIndexOf("/"); | 157 var index = url.lastIndexOf("/"); |
158 return index !== -1 ? url.substr(index + 1) : url; | 158 return index !== -1 ? url.substr(index + 1) : url; |
159 } | 159 }; |
160 | 160 |
161 /** | 161 /** |
162 * @param {string} baseURL | 162 * @param {string} baseURL |
163 * @param {string} href | 163 * @param {string} href |
164 * @return {?string} | 164 * @return {?string} |
165 */ | 165 */ |
166 WebInspector.ParsedURL.completeURL = function(baseURL, href) | 166 WebInspector.ParsedURL.completeURL = function(baseURL, href) |
167 { | 167 { |
168 // Return special URLs as-is. | 168 // Return special URLs as-is. |
169 var trimmedHref = href.trim(); | 169 var trimmedHref = href.trim(); |
(...skipping 29 matching lines...) Expand all Loading... |
199 return securityOrigin + pathText + queryText + href; | 199 return securityOrigin + pathText + queryText + href; |
200 | 200 |
201 if (href.charAt(0) === "?") | 201 if (href.charAt(0) === "?") |
202 return securityOrigin + pathText + href; | 202 return securityOrigin + pathText + href; |
203 | 203 |
204 var hrefPath = href.match(/^[^#?]*/)[0]; | 204 var hrefPath = href.match(/^[^#?]*/)[0]; |
205 var hrefSuffix = href.substring(hrefPath.length); | 205 var hrefSuffix = href.substring(hrefPath.length); |
206 if (hrefPath.charAt(0) !== "/") | 206 if (hrefPath.charAt(0) !== "/") |
207 hrefPath = parsedURL.folderPathComponents + "/" + hrefPath; | 207 hrefPath = parsedURL.folderPathComponents + "/" + hrefPath; |
208 return securityOrigin + Runtime.normalizePath(hrefPath) + hrefSuffix; | 208 return securityOrigin + Runtime.normalizePath(hrefPath) + hrefSuffix; |
209 } | 209 }; |
210 | 210 |
211 WebInspector.ParsedURL.prototype = { | 211 WebInspector.ParsedURL.prototype = { |
212 get displayName() | 212 get displayName() |
213 { | 213 { |
214 if (this._displayName) | 214 if (this._displayName) |
215 return this._displayName; | 215 return this._displayName; |
216 | 216 |
217 if (this.isDataURL()) | 217 if (this.isDataURL()) |
218 return this.dataURLDisplayName(); | 218 return this.dataURLDisplayName(); |
219 if (this.isAboutBlank()) | 219 if (this.isAboutBlank()) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 | 286 |
287 /** | 287 /** |
288 * @return {string} | 288 * @return {string} |
289 */ | 289 */ |
290 urlWithoutScheme: function() | 290 urlWithoutScheme: function() |
291 { | 291 { |
292 if (this.scheme && this.url.startsWith(this.scheme + "://")) | 292 if (this.scheme && this.url.startsWith(this.scheme + "://")) |
293 return this.url.substring(this.scheme.length + 3); | 293 return this.url.substring(this.scheme.length + 3); |
294 return this.url; | 294 return this.url; |
295 }, | 295 }, |
296 } | 296 }; |
297 | 297 |
298 /** | 298 /** |
299 * @param {string} string | 299 * @param {string} string |
300 * @return {!{url: string, lineNumber: (number|undefined), columnNumber: (number
|undefined)}} | 300 * @return {!{url: string, lineNumber: (number|undefined), columnNumber: (number
|undefined)}} |
301 */ | 301 */ |
302 WebInspector.ParsedURL.splitLineAndColumn = function(string) | 302 WebInspector.ParsedURL.splitLineAndColumn = function(string) |
303 { | 303 { |
304 var lineColumnRegEx = /(?::(\d+))?(?::(\d+))?$/; | 304 var lineColumnRegEx = /(?::(\d+))?(?::(\d+))?$/; |
305 var lineColumnMatch = lineColumnRegEx.exec(string); | 305 var lineColumnMatch = lineColumnRegEx.exec(string); |
306 var lineNumber; | 306 var lineNumber; |
307 var columnNumber; | 307 var columnNumber; |
308 console.assert(lineColumnMatch); | 308 console.assert(lineColumnMatch); |
309 | 309 |
310 if (typeof(lineColumnMatch[1]) === "string") { | 310 if (typeof(lineColumnMatch[1]) === "string") { |
311 lineNumber = parseInt(lineColumnMatch[1], 10); | 311 lineNumber = parseInt(lineColumnMatch[1], 10); |
312 // Immediately convert line and column to 0-based numbers. | 312 // Immediately convert line and column to 0-based numbers. |
313 lineNumber = isNaN(lineNumber) ? undefined : lineNumber - 1; | 313 lineNumber = isNaN(lineNumber) ? undefined : lineNumber - 1; |
314 } | 314 } |
315 if (typeof(lineColumnMatch[2]) === "string") { | 315 if (typeof(lineColumnMatch[2]) === "string") { |
316 columnNumber = parseInt(lineColumnMatch[2], 10); | 316 columnNumber = parseInt(lineColumnMatch[2], 10); |
317 columnNumber = isNaN(columnNumber) ? undefined : columnNumber - 1; | 317 columnNumber = isNaN(columnNumber) ? undefined : columnNumber - 1; |
318 } | 318 } |
319 | 319 |
320 return {url: string.substring(0, string.length - lineColumnMatch[0].length),
lineNumber: lineNumber, columnNumber: columnNumber}; | 320 return {url: string.substring(0, string.length - lineColumnMatch[0].length),
lineNumber: lineNumber, columnNumber: columnNumber}; |
321 } | 321 }; |
322 | 322 |
323 /** | 323 /** |
324 * @param {string} url | 324 * @param {string} url |
325 * @return {boolean} | 325 * @return {boolean} |
326 */ | 326 */ |
327 WebInspector.ParsedURL.isRelativeURL = function(url) | 327 WebInspector.ParsedURL.isRelativeURL = function(url) |
328 { | 328 { |
329 return !(/^[A-Za-z][A-Za-z0-9+.-]*:/.test(url)); | 329 return !(/^[A-Za-z][A-Za-z0-9+.-]*:/.test(url)); |
330 } | 330 }; |
331 | 331 |
332 /** | 332 /** |
333 * @return {?WebInspector.ParsedURL} | 333 * @return {?WebInspector.ParsedURL} |
334 */ | 334 */ |
335 String.prototype.asParsedURL = function() | 335 String.prototype.asParsedURL = function() |
336 { | 336 { |
337 var parsedURL = new WebInspector.ParsedURL(this.toString()); | 337 var parsedURL = new WebInspector.ParsedURL(this.toString()); |
338 if (parsedURL.isValid) | 338 if (parsedURL.isValid) |
339 return parsedURL; | 339 return parsedURL; |
340 return null; | 340 return null; |
341 } | 341 }; |
OLD | NEW |