| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "base/debug/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 // are lazily initialized by Initialize and are leaked on shutdown to prevent | 79 // are lazily initialized by Initialize and are leaked on shutdown to prevent |
| 80 // any destructors from being called that will slow us down or cause problems. | 80 // any destructors from being called that will slow us down or cause problems. |
| 81 std::vector<SchemeWithType>* standard_schemes = nullptr; | 81 std::vector<SchemeWithType>* standard_schemes = nullptr; |
| 82 std::vector<SchemeWithType>* referrer_schemes = nullptr; | 82 std::vector<SchemeWithType>* referrer_schemes = nullptr; |
| 83 | 83 |
| 84 // Similar to above, initialized by the Init*Schemes methods. | 84 // Similar to above, initialized by the Init*Schemes methods. |
| 85 std::vector<std::string>* secure_schemes = nullptr; | 85 std::vector<std::string>* secure_schemes = nullptr; |
| 86 std::vector<std::string>* local_schemes = nullptr; | 86 std::vector<std::string>* local_schemes = nullptr; |
| 87 std::vector<std::string>* no_access_schemes = nullptr; | 87 std::vector<std::string>* no_access_schemes = nullptr; |
| 88 std::vector<std::string>* cors_enabled_schemes = nullptr; | 88 std::vector<std::string>* cors_enabled_schemes = nullptr; |
| 89 std::vector<std::string>* bypassing_csp_schemes = nullptr; |
| 89 | 90 |
| 90 // See the LockSchemeRegistries declaration in the header. | 91 // See the LockSchemeRegistries declaration in the header. |
| 91 bool scheme_registries_locked = false; | 92 bool scheme_registries_locked = false; |
| 92 | 93 |
| 93 // This template converts a given character type to the corresponding | 94 // This template converts a given character type to the corresponding |
| 94 // StringPiece type. | 95 // StringPiece type. |
| 95 template<typename CHAR> struct CharToStringPiece { | 96 template<typename CHAR> struct CharToStringPiece { |
| 96 }; | 97 }; |
| 97 template<> struct CharToStringPiece<char> { | 98 template<> struct CharToStringPiece<char> { |
| 98 typedef base::StringPiece Piece; | 99 typedef base::StringPiece Piece; |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 InitSchemesWithType(&standard_schemes, kStandardURLSchemes, | 506 InitSchemesWithType(&standard_schemes, kStandardURLSchemes, |
| 506 arraysize(kStandardURLSchemes)); | 507 arraysize(kStandardURLSchemes)); |
| 507 InitSchemesWithType(&referrer_schemes, kReferrerURLSchemes, | 508 InitSchemesWithType(&referrer_schemes, kReferrerURLSchemes, |
| 508 arraysize(kReferrerURLSchemes)); | 509 arraysize(kReferrerURLSchemes)); |
| 509 InitSchemes(&secure_schemes, kSecureSchemes, arraysize(kSecureSchemes)); | 510 InitSchemes(&secure_schemes, kSecureSchemes, arraysize(kSecureSchemes)); |
| 510 InitSchemes(&local_schemes, kLocalSchemes, arraysize(kLocalSchemes)); | 511 InitSchemes(&local_schemes, kLocalSchemes, arraysize(kLocalSchemes)); |
| 511 InitSchemes(&no_access_schemes, kNoAccessSchemes, | 512 InitSchemes(&no_access_schemes, kNoAccessSchemes, |
| 512 arraysize(kNoAccessSchemes)); | 513 arraysize(kNoAccessSchemes)); |
| 513 InitSchemes(&cors_enabled_schemes, kCORSEnabledSchemes, | 514 InitSchemes(&cors_enabled_schemes, kCORSEnabledSchemes, |
| 514 arraysize(kCORSEnabledSchemes)); | 515 arraysize(kCORSEnabledSchemes)); |
| 516 InitSchemes(&bypassing_csp_schemes, nullptr, 0); |
| 515 initialized = true; | 517 initialized = true; |
| 516 } | 518 } |
| 517 | 519 |
| 518 void Shutdown() { | 520 void Shutdown() { |
| 519 initialized = false; | 521 initialized = false; |
| 520 delete standard_schemes; | 522 delete standard_schemes; |
| 521 standard_schemes = nullptr; | 523 standard_schemes = nullptr; |
| 522 delete referrer_schemes; | 524 delete referrer_schemes; |
| 523 referrer_schemes = nullptr; | 525 referrer_schemes = nullptr; |
| 524 delete secure_schemes; | 526 delete secure_schemes; |
| 525 secure_schemes = nullptr; | 527 secure_schemes = nullptr; |
| 526 delete local_schemes; | 528 delete local_schemes; |
| 527 local_schemes = nullptr; | 529 local_schemes = nullptr; |
| 528 delete no_access_schemes; | 530 delete no_access_schemes; |
| 529 no_access_schemes = nullptr; | 531 no_access_schemes = nullptr; |
| 530 delete cors_enabled_schemes; | 532 delete cors_enabled_schemes; |
| 531 cors_enabled_schemes = nullptr; | 533 cors_enabled_schemes = nullptr; |
| 534 delete bypassing_csp_schemes; |
| 535 bypassing_csp_schemes = nullptr; |
| 532 } | 536 } |
| 533 | 537 |
| 534 void AddStandardScheme(const char* new_scheme, SchemeType type) { | 538 void AddStandardScheme(const char* new_scheme, SchemeType type) { |
| 535 Initialize(); | 539 Initialize(); |
| 536 DoAddSchemeWithType(new_scheme, type, standard_schemes); | 540 DoAddSchemeWithType(new_scheme, type, standard_schemes); |
| 537 } | 541 } |
| 538 | 542 |
| 539 void AddReferrerScheme(const char* new_scheme, SchemeType type) { | 543 void AddReferrerScheme(const char* new_scheme, SchemeType type) { |
| 540 Initialize(); | 544 Initialize(); |
| 541 DoAddSchemeWithType(new_scheme, type, referrer_schemes); | 545 DoAddSchemeWithType(new_scheme, type, referrer_schemes); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 void AddCORSEnabledScheme(const char* new_scheme) { | 578 void AddCORSEnabledScheme(const char* new_scheme) { |
| 575 Initialize(); | 579 Initialize(); |
| 576 DoAddScheme(new_scheme, cors_enabled_schemes); | 580 DoAddScheme(new_scheme, cors_enabled_schemes); |
| 577 } | 581 } |
| 578 | 582 |
| 579 const std::vector<std::string>& GetCORSEnabledSchemes() { | 583 const std::vector<std::string>& GetCORSEnabledSchemes() { |
| 580 Initialize(); | 584 Initialize(); |
| 581 return *cors_enabled_schemes; | 585 return *cors_enabled_schemes; |
| 582 } | 586 } |
| 583 | 587 |
| 588 void AddBypassingCSPScheme(const char* new_scheme) { |
| 589 Initialize(); |
| 590 DoAddScheme(new_scheme, bypassing_csp_schemes); |
| 591 } |
| 592 |
| 593 const std::vector<std::string>& GetBypassingCSPSchemes() { |
| 594 Initialize(); |
| 595 return *bypassing_csp_schemes; |
| 596 } |
| 597 |
| 584 void LockSchemeRegistries() { | 598 void LockSchemeRegistries() { |
| 585 scheme_registries_locked = true; | 599 scheme_registries_locked = true; |
| 586 } | 600 } |
| 587 | 601 |
| 588 bool IsStandard(const char* spec, const Component& scheme) { | 602 bool IsStandard(const char* spec, const Component& scheme) { |
| 589 SchemeType unused_scheme_type; | 603 SchemeType unused_scheme_type; |
| 590 return DoIsStandard(spec, scheme, &unused_scheme_type); | 604 return DoIsStandard(spec, scheme, &unused_scheme_type); |
| 591 } | 605 } |
| 592 | 606 |
| 593 bool GetStandardSchemeType(const char* spec, | 607 bool GetStandardSchemeType(const char* spec, |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 return DoCompareSchemeComponent(spec, component, compare_to); | 829 return DoCompareSchemeComponent(spec, component, compare_to); |
| 816 } | 830 } |
| 817 | 831 |
| 818 bool CompareSchemeComponent(const base::char16* spec, | 832 bool CompareSchemeComponent(const base::char16* spec, |
| 819 const Component& component, | 833 const Component& component, |
| 820 const char* compare_to) { | 834 const char* compare_to) { |
| 821 return DoCompareSchemeComponent(spec, component, compare_to); | 835 return DoCompareSchemeComponent(spec, component, compare_to); |
| 822 } | 836 } |
| 823 | 837 |
| 824 } // namespace url | 838 } // namespace url |
| OLD | NEW |