OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "url/url_util.h" | 5 #include "url/url_util.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 // Backend for LowerCaseEqualsASCII. | 29 // Backend for LowerCaseEqualsASCII. |
30 template<typename Iter> | 30 template<typename Iter> |
31 inline bool DoLowerCaseEqualsASCII(Iter a_begin, Iter a_end, const char* b) { | 31 inline bool DoLowerCaseEqualsASCII(Iter a_begin, Iter a_end, const char* b) { |
32 for (Iter it = a_begin; it != a_end; ++it, ++b) { | 32 for (Iter it = a_begin; it != a_end; ++it, ++b) { |
33 if (!*b || ToLowerASCII(*it) != *b) | 33 if (!*b || ToLowerASCII(*it) != *b) |
34 return false; | 34 return false; |
35 } | 35 } |
36 return *b == 0; | 36 return *b == 0; |
37 } | 37 } |
38 | 38 |
| 39 bool g_kurl_compat_mode = false; |
| 40 |
39 const int kNumStandardURLSchemes = 8; | 41 const int kNumStandardURLSchemes = 8; |
40 const char* kStandardURLSchemes[kNumStandardURLSchemes] = { | 42 const char* kStandardURLSchemes[kNumStandardURLSchemes] = { |
41 "http", | 43 "http", |
42 "https", | 44 "https", |
43 kFileScheme, // Yes, file urls can have a hostname! | 45 kFileScheme, // Yes, file urls can have a hostname! |
44 "ftp", | 46 "ftp", |
45 "gopher", | 47 "gopher", |
46 "ws", // WebSocket. | 48 "ws", // WebSocket. |
47 "wss", // WebSocket secure. | 49 "wss", // WebSocket secure. |
48 kFileSystemScheme, | 50 kFileSystemScheme, |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 base_parsed.scheme.is_nonempty() && | 228 base_parsed.scheme.is_nonempty() && |
227 DoIsStandard(base_spec, base_parsed.scheme); | 229 DoIsStandard(base_spec, base_parsed.scheme); |
228 | 230 |
229 bool is_relative; | 231 bool is_relative; |
230 url_parse::Component relative_component; | 232 url_parse::Component relative_component; |
231 if (!url_canon::IsRelativeURL(base_spec, base_parsed, | 233 if (!url_canon::IsRelativeURL(base_spec, base_parsed, |
232 relative, relative_length, | 234 relative, relative_length, |
233 (base_is_hierarchical || standard_base_scheme), | 235 (base_is_hierarchical || standard_base_scheme), |
234 &is_relative, | 236 &is_relative, |
235 &relative_component)) { | 237 &relative_component)) { |
| 238 if (g_kurl_compat_mode && relative_length && *relative == '#') { |
| 239 // Allow a fragemnt on its own to resolve against any base URL (even non- |
| 240 // hierarchical). First attempt to re-parse the path portion of the base |
| 241 // URL using a more relaxed algorithm for matching fragment sections. |
| 242 url_parse::Parsed base_reparsed = base_parsed; |
| 243 if (base_reparsed.path.is_valid() && |
| 244 !base_reparsed.query.is_valid() && |
| 245 !base_reparsed.ref.is_valid()) { |
| 246 const int path_end = base_reparsed.path.end(); |
| 247 for (int i = base_reparsed.path.begin; i < path_end; ++i) { |
| 248 if (base_spec[i] == '#') { |
| 249 base_reparsed.path.len = i - base_reparsed.path.begin; |
| 250 base_reparsed.ref = url_parse::MakeRange(i, path_end); |
| 251 break; |
| 252 } |
| 253 } |
| 254 } |
| 255 return url_canon::ResolveRelativeURL(base_spec, base_reparsed, |
| 256 false, relative, |
| 257 url_parse::MakeRange( |
| 258 0, relative_length), |
| 259 charset_converter, |
| 260 output, output_parsed); |
| 261 } |
236 // Error resolving. | 262 // Error resolving. |
237 return false; | 263 return false; |
238 } | 264 } |
239 | 265 |
240 // Pretend for a moment that |base_spec| is a standard URL. Normally | 266 // Pretend for a moment that |base_spec| is a standard URL. Normally |
241 // non-standard URLs are treated as PathURLs, but if the base has an | 267 // non-standard URLs are treated as PathURLs, but if the base has an |
242 // authority we would like to preserve it. | 268 // authority we would like to preserve it. |
243 if (is_relative && base_is_authority_based && !standard_base_scheme) { | 269 if (is_relative && base_is_authority_based && !standard_base_scheme) { |
244 url_parse::Parsed base_parsed_authority; | 270 url_parse::Parsed base_parsed_authority; |
245 ParseStandardURL(base_spec, base_spec_len, &base_parsed_authority); | 271 ParseStandardURL(base_spec, base_spec_len, &base_parsed_authority); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 InitStandardSchemes(); | 395 InitStandardSchemes(); |
370 } | 396 } |
371 | 397 |
372 void Shutdown() { | 398 void Shutdown() { |
373 if (standard_schemes) { | 399 if (standard_schemes) { |
374 delete standard_schemes; | 400 delete standard_schemes; |
375 standard_schemes = NULL; | 401 standard_schemes = NULL; |
376 } | 402 } |
377 } | 403 } |
378 | 404 |
| 405 void SetKURLCompatMode(bool enable) { |
| 406 g_kurl_compat_mode = enable; |
| 407 } |
| 408 |
379 void AddStandardScheme(const char* new_scheme) { | 409 void AddStandardScheme(const char* new_scheme) { |
380 // If this assert triggers, it means you've called AddStandardScheme after | 410 // If this assert triggers, it means you've called AddStandardScheme after |
381 // LockStandardSchemes have been called (see the header file for | 411 // LockStandardSchemes have been called (see the header file for |
382 // LockStandardSchemes for more). | 412 // LockStandardSchemes for more). |
383 // | 413 // |
384 // This normally means you're trying to set up a new standard scheme too late | 414 // This normally means you're trying to set up a new standard scheme too late |
385 // in your application's init process. Locate where your app does this | 415 // in your application's init process. Locate where your app does this |
386 // initialization and calls LockStandardScheme, and add your new standard | 416 // initialization and calls LockStandardScheme, and add your new standard |
387 // scheme there. | 417 // scheme there. |
388 DCHECK(!standard_schemes_locked) << | 418 DCHECK(!standard_schemes_locked) << |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 return DoCompareSchemeComponent(spec, component, compare_to); | 615 return DoCompareSchemeComponent(spec, component, compare_to); |
586 } | 616 } |
587 | 617 |
588 bool CompareSchemeComponent(const base::char16* spec, | 618 bool CompareSchemeComponent(const base::char16* spec, |
589 const url_parse::Component& component, | 619 const url_parse::Component& component, |
590 const char* compare_to) { | 620 const char* compare_to) { |
591 return DoCompareSchemeComponent(spec, component, compare_to); | 621 return DoCompareSchemeComponent(spec, component, compare_to); |
592 } | 622 } |
593 | 623 |
594 } // namespace url_util | 624 } // namespace url_util |
OLD | NEW |