blob: a31734f79a7deb1a7f65a1ab3b86b43af491dece [file] [log] [blame]
Googler11871152020-10-01 14:59:09 -04001// 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
Googler39a97572023-12-13 22:53:26 +00009#include "libcef/common/app_manager.h"
10#include "libcef/common/net/scheme_info.h"
Googler11871152020-10-01 14:59:09 -040011#include "libcef/common/net/scheme_registration.h"
12
Googler39a97572023-12-13 22:53:26 +000013#include "base/functional/bind.h"
Googler11871152020-10-01 14:59:09 -040014#include "base/logging.h"
15#include "base/strings/string_util.h"
16
17namespace {
18
19void AppendArray(const std::vector<std::string>& source,
20 std::vector<std::string>* target) {
Googler39a97572023-12-13 22:53:26 +000021 if (source.empty()) {
Googler11871152020-10-01 14:59:09 -040022 return;
Googler39a97572023-12-13 22:53:26 +000023 }
Googler11871152020-10-01 14:59:09 -040024 target->insert(target->end(), source.begin(), source.end());
25}
26} // namespace
27
28CefSchemeRegistrarImpl::CefSchemeRegistrarImpl() {}
29
30bool 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.
Googler39a97572023-12-13 22:53:26 +000050 if (is_standard) {
Googler11871152020-10-01 14:59:09 -040051 schemes_.standard_schemes.push_back(scheme);
Googler39a97572023-12-13 22:53:26 +000052 }
53 if (is_local) {
Googler11871152020-10-01 14:59:09 -040054 schemes_.local_schemes.push_back(scheme);
Googler39a97572023-12-13 22:53:26 +000055 }
56 if (is_secure) {
Googler11871152020-10-01 14:59:09 -040057 schemes_.secure_schemes.push_back(scheme);
Googler39a97572023-12-13 22:53:26 +000058 }
59 if (is_cors_enabled) {
Googler11871152020-10-01 14:59:09 -040060 schemes_.cors_enabled_schemes.push_back(scheme);
Googler39a97572023-12-13 22:53:26 +000061 }
62 if (is_csp_bypassing) {
Googler11871152020-10-01 14:59:09 -040063 schemes_.csp_bypassing_schemes.push_back(scheme);
Googler39a97572023-12-13 22:53:26 +000064 }
Googler11871152020-10-01 14:59:09 -040065
Googler39a97572023-12-13 22:53:26 +000066 CefSchemeInfo scheme_info = {
Googler11871152020-10-01 14:59:09 -040067 scheme, is_standard, is_local, is_display_isolated,
68 is_secure, is_cors_enabled, is_csp_bypassing, is_fetch_enabled};
Googler39a97572023-12-13 22:53:26 +000069 CefAppManager::Get()->AddCustomScheme(&scheme_info);
Googler11871152020-10-01 14:59:09 -040070
71 return true;
72}
73
74void 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}