Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights |
| 2 | // reserved. Use of this source code is governed by a BSD-style license that can |
| 3 | // be found in the LICENSE file. |
| 4 | |
| 5 | #include "libcef/common/scheme_registrar_impl.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 9 | #include "libcef/common/app_manager.h" |
| 10 | #include "libcef/common/net/scheme_info.h" |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 11 | #include "libcef/common/net/scheme_registration.h" |
| 12 | |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 13 | #include "base/functional/bind.h" |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 14 | #include "base/logging.h" |
| 15 | #include "base/strings/string_util.h" |
| 16 | |
| 17 | namespace { |
| 18 | |
| 19 | void AppendArray(const std::vector<std::string>& source, |
| 20 | std::vector<std::string>* target) { |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 21 | if (source.empty()) { |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 22 | return; |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 23 | } |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 24 | target->insert(target->end(), source.begin(), source.end()); |
| 25 | } |
| 26 | } // namespace |
| 27 | |
| 28 | CefSchemeRegistrarImpl::CefSchemeRegistrarImpl() {} |
| 29 | |
| 30 | bool CefSchemeRegistrarImpl::AddCustomScheme(const CefString& scheme_name, |
| 31 | int options) { |
| 32 | const std::string& scheme = base::ToLowerASCII(scheme_name.ToString()); |
| 33 | if (scheme::IsInternalHandledScheme(scheme) || |
| 34 | registered_schemes_.find(scheme) != registered_schemes_.end()) { |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | registered_schemes_.insert(scheme); |
| 39 | |
| 40 | const bool is_standard = options & CEF_SCHEME_OPTION_STANDARD; |
| 41 | const bool is_local = options & CEF_SCHEME_OPTION_LOCAL; |
| 42 | const bool is_display_isolated = options & CEF_SCHEME_OPTION_DISPLAY_ISOLATED; |
| 43 | const bool is_secure = options & CEF_SCHEME_OPTION_SECURE; |
| 44 | const bool is_cors_enabled = options & CEF_SCHEME_OPTION_CORS_ENABLED; |
| 45 | const bool is_csp_bypassing = options & CEF_SCHEME_OPTION_CSP_BYPASSING; |
| 46 | const bool is_fetch_enabled = options & CEF_SCHEME_OPTION_FETCH_ENABLED; |
| 47 | |
| 48 | // The |is_display_isolated| value is excluded here because it's registered |
| 49 | // with Blink only. |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 50 | if (is_standard) { |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 51 | schemes_.standard_schemes.push_back(scheme); |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 52 | } |
| 53 | if (is_local) { |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 54 | schemes_.local_schemes.push_back(scheme); |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 55 | } |
| 56 | if (is_secure) { |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 57 | schemes_.secure_schemes.push_back(scheme); |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 58 | } |
| 59 | if (is_cors_enabled) { |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 60 | schemes_.cors_enabled_schemes.push_back(scheme); |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 61 | } |
| 62 | if (is_csp_bypassing) { |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 63 | schemes_.csp_bypassing_schemes.push_back(scheme); |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 64 | } |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 65 | |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 66 | CefSchemeInfo scheme_info = { |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 67 | scheme, is_standard, is_local, is_display_isolated, |
| 68 | is_secure, is_cors_enabled, is_csp_bypassing, is_fetch_enabled}; |
Googler | 39a9757 | 2023-12-13 22:53:26 +0000 | [diff] [blame^] | 69 | CefAppManager::Get()->AddCustomScheme(&scheme_info); |
Googler | 1187115 | 2020-10-01 14:59:09 -0400 | [diff] [blame] | 70 | |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | void CefSchemeRegistrarImpl::GetSchemes( |
| 75 | content::ContentClient::Schemes* schemes) { |
| 76 | AppendArray(schemes_.standard_schemes, &schemes->standard_schemes); |
| 77 | AppendArray(schemes_.local_schemes, &schemes->local_schemes); |
| 78 | AppendArray(schemes_.secure_schemes, &schemes->secure_schemes); |
| 79 | AppendArray(schemes_.cors_enabled_schemes, &schemes->cors_enabled_schemes); |
| 80 | AppendArray(schemes_.csp_bypassing_schemes, &schemes->csp_bypassing_schemes); |
| 81 | } |