OLD | NEW |
1 /*! | 1 /*! |
2 * Parts of original code from ipv6.js <https://github.com/beaugunderson/javascr
ipt-ipv6> | 2 * Parts of original code from ipv6.js <https://github.com/beaugunderson/javascr
ipt-ipv6> |
3 * Copyright 2011 Beau Gunderson | 3 * Copyright 2011 Beau Gunderson |
4 * Available under MIT license <http://mths.be/mit> | 4 * Available under MIT license <http://mths.be/mit> |
5 */ | 5 */ |
6 | 6 |
7 const RE_V4 = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|0x[0-9a-f][0-9a-f]?|0
[0-7]{3})\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|0x[0-9a-f][0-9a-f]?|0[0-7
]{3})$/i; | 7 const RE_V4 = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|0x[0-9a-f][0-9a-f]?|0
[0-7]{3})\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|0x[0-9a-f][0-9a-f]?|0[0-7
]{3})$/i; |
8 const RE_V4_HEX = /^0x([0-9a-f]{8})$/i; | 8 const RE_V4_HEX = /^0x([0-9a-f]{8})$/i; |
9 const RE_V4_NUMERIC = /^[0-9]+$/; | 9 const RE_V4_NUMERIC = /^[0-9]+$/; |
10 const RE_V4inV6 = /(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2
[0-4][0-9]|[01]?[0-9][0-9]?)$/; | 10 const RE_V4inV6 = /(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2
[0-4][0-9]|[01]?[0-9][0-9]?)$/; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 { | 151 { |
152 // Keep the empty string for invalid URIs. | 152 // Keep the empty string for invalid URIs. |
153 } | 153 } |
154 | 154 |
155 extractHostFromURL._lastURL = url; | 155 extractHostFromURL._lastURL = url; |
156 extractHostFromURL._lastDomain = host; | 156 extractHostFromURL._lastDomain = host; |
157 return host; | 157 return host; |
158 } | 158 } |
159 | 159 |
160 /** | 160 /** |
| 161 * Extracts host name from the URL of the given frame. If the URL don't have hos
t |
| 162 * information (like about:blank or data: URLs) it falls back to the parent fram
e. |
| 163 */ |
| 164 function extractHostFromFrame(frame) |
| 165 { |
| 166 var host = extractHostFromURL(frame.url); |
| 167 if (!host) |
| 168 { |
| 169 var parentFrame = frame.parent; |
| 170 if (parentFrame) |
| 171 return extractHostFromFrame(parentFrame); |
| 172 } |
| 173 return host; |
| 174 } |
| 175 |
| 176 /** |
| 177 * Strips the fragment from a URL. |
| 178 */ |
| 179 function stripFragmentFromURL(/**String*/ url) |
| 180 { |
| 181 return url.replace(/#.*/, ""); |
| 182 } |
| 183 |
| 184 /** |
161 * Parses URLs and provides an interface similar to nsIURI in Gecko, see | 185 * Parses URLs and provides an interface similar to nsIURI in Gecko, see |
162 * https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIURI. | 186 * https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIURI. |
163 * TODO: Make sure the parsing actually works the same as nsStandardURL. | 187 * TODO: Make sure the parsing actually works the same as nsStandardURL. |
164 * @constructor | 188 * @constructor |
165 */ | 189 */ |
166 function URI(/**String*/ spec) | 190 function URI(/**String*/ spec) |
167 { | 191 { |
168 this.spec = spec; | 192 this.spec = spec; |
169 this._schemeEnd = spec.indexOf(":"); | 193 this._schemeEnd = spec.indexOf(":"); |
170 if (this._schemeEnd < 0) | 194 if (this._schemeEnd < 0) |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 }, | 271 }, |
248 get path() | 272 get path() |
249 { | 273 { |
250 return this.spec.substring(this._hostPortEnd); | 274 return this.spec.substring(this._hostPortEnd); |
251 }, | 275 }, |
252 get prePath() | 276 get prePath() |
253 { | 277 { |
254 return this.spec.substring(0, this._hostPortEnd); | 278 return this.spec.substring(0, this._hostPortEnd); |
255 } | 279 } |
256 }; | 280 }; |
OLD | NEW |