Javier Fernández García-Boente | 03816ca3 | 2021-08-06 15:41:37 | [diff] [blame^] | 1 | // Copyright 2020 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "third_party/blink/public/common/scheme_registry.h" |
| 6 | |
| 7 | #include <unordered_set> |
| 8 | |
| 9 | #include "base/no_destructor.h" |
| 10 | #include "base/strings/string_util.h" |
| 11 | |
| 12 | namespace blink { |
| 13 | |
| 14 | using URLSchemesSet = std::unordered_set<std::string>; |
| 15 | |
| 16 | URLSchemesSet& GetMutableExtensionSchemes() { |
| 17 | static base::NoDestructor<URLSchemesSet> extension_schemes; |
| 18 | return *extension_schemes; |
| 19 | } |
| 20 | |
| 21 | const URLSchemesSet& GetExtensionSchemes() { |
| 22 | return GetMutableExtensionSchemes(); |
| 23 | } |
| 24 | |
| 25 | void CommonSchemeRegistry::RegisterURLSchemeAsExtension( |
| 26 | const std::string& scheme) { |
| 27 | DCHECK_EQ(scheme, base::ToLowerASCII(scheme)); |
| 28 | GetMutableExtensionSchemes().insert(scheme); |
| 29 | } |
| 30 | |
| 31 | void CommonSchemeRegistry::RemoveURLSchemeAsExtensionForTest( |
| 32 | const std::string& scheme) { |
| 33 | GetMutableExtensionSchemes().erase(scheme); |
| 34 | } |
| 35 | |
| 36 | bool CommonSchemeRegistry::IsExtensionScheme(const std::string& scheme) { |
| 37 | if (scheme.empty()) |
| 38 | return false; |
| 39 | DCHECK_EQ(scheme, base::ToLowerASCII(scheme)); |
| 40 | return GetExtensionSchemes().find(scheme) != GetExtensionSchemes().end(); |
| 41 | } |
| 42 | |
| 43 | } // namespace blink |