2012-04-24 20:01:48 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/common/scheme_registrar_impl.h"
|
2012-04-24 20:01:48 +02:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2023-01-30 18:43:54 +01:00
|
|
|
#include "base/functional/bind.h"
|
2012-04-24 20:01:48 +02:00
|
|
|
#include "base/logging.h"
|
2017-01-23 18:36:54 +01:00
|
|
|
#include "base/strings/string_util.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/common/app_manager.h"
|
|
|
|
#include "cef/libcef/common/net/scheme_info.h"
|
|
|
|
#include "cef/libcef/common/net/scheme_registration.h"
|
2017-01-23 18:36:54 +01:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void AppendArray(const std::vector<std::string>& source,
|
|
|
|
std::vector<std::string>* target) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (source.empty()) {
|
2017-01-23 18:36:54 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-01-23 18:36:54 +01:00
|
|
|
target->insert(target->end(), source.begin(), source.end());
|
|
|
|
}
|
2019-02-26 17:45:12 +01:00
|
|
|
} // namespace
|
2012-04-24 20:01:48 +02:00
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
CefSchemeRegistrarImpl::CefSchemeRegistrarImpl() = default;
|
2012-04-24 20:01:48 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool CefSchemeRegistrarImpl::AddCustomScheme(const CefString& scheme_name,
|
2019-02-26 17:45:12 +01:00
|
|
|
int options) {
|
2017-01-23 18:36:54 +01:00
|
|
|
const std::string& scheme = base::ToLowerASCII(scheme_name.ToString());
|
|
|
|
if (scheme::IsInternalHandledScheme(scheme) ||
|
|
|
|
registered_schemes_.find(scheme) != registered_schemes_.end()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
registered_schemes_.insert(scheme);
|
2013-06-04 19:41:37 +02:00
|
|
|
|
2019-02-26 17:45:12 +01:00
|
|
|
const bool is_standard = options & CEF_SCHEME_OPTION_STANDARD;
|
|
|
|
const bool is_local = options & CEF_SCHEME_OPTION_LOCAL;
|
|
|
|
const bool is_display_isolated = options & CEF_SCHEME_OPTION_DISPLAY_ISOLATED;
|
|
|
|
const bool is_secure = options & CEF_SCHEME_OPTION_SECURE;
|
|
|
|
const bool is_cors_enabled = options & CEF_SCHEME_OPTION_CORS_ENABLED;
|
|
|
|
const bool is_csp_bypassing = options & CEF_SCHEME_OPTION_CSP_BYPASSING;
|
|
|
|
const bool is_fetch_enabled = options & CEF_SCHEME_OPTION_FETCH_ENABLED;
|
|
|
|
|
2017-01-23 18:36:54 +01:00
|
|
|
// The |is_display_isolated| value is excluded here because it's registered
|
|
|
|
// with Blink only.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (is_standard) {
|
2017-01-23 18:36:54 +01:00
|
|
|
schemes_.standard_schemes.push_back(scheme);
|
2023-11-17 00:19:27 +01:00
|
|
|
if (!is_local && !is_display_isolated) {
|
|
|
|
schemes_.referrer_schemes.push_back(scheme);
|
|
|
|
}
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (is_local) {
|
2017-01-23 18:36:54 +01:00
|
|
|
schemes_.local_schemes.push_back(scheme);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (is_secure) {
|
2017-01-23 18:36:54 +01:00
|
|
|
schemes_.secure_schemes.push_back(scheme);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (is_cors_enabled) {
|
2017-01-23 18:36:54 +01:00
|
|
|
schemes_.cors_enabled_schemes.push_back(scheme);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (is_csp_bypassing) {
|
2017-03-03 23:37:23 +01:00
|
|
|
schemes_.csp_bypassing_schemes.push_back(scheme);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-24 20:01:48 +02:00
|
|
|
|
2020-06-28 23:05:36 +02:00
|
|
|
CefSchemeInfo scheme_info = {
|
2019-02-04 23:31:31 +01:00
|
|
|
scheme, is_standard, is_local, is_display_isolated,
|
|
|
|
is_secure, is_cors_enabled, is_csp_bypassing, is_fetch_enabled};
|
2020-06-28 23:05:36 +02:00
|
|
|
CefAppManager::Get()->AddCustomScheme(&scheme_info);
|
2013-06-04 19:41:37 +02:00
|
|
|
|
2012-04-24 20:01:48 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-23 18:36:54 +01:00
|
|
|
void CefSchemeRegistrarImpl::GetSchemes(
|
|
|
|
content::ContentClient::Schemes* schemes) {
|
|
|
|
AppendArray(schemes_.standard_schemes, &schemes->standard_schemes);
|
2023-11-17 00:19:27 +01:00
|
|
|
AppendArray(schemes_.referrer_schemes, &schemes->referrer_schemes);
|
2017-01-23 18:36:54 +01:00
|
|
|
AppendArray(schemes_.local_schemes, &schemes->local_schemes);
|
|
|
|
AppendArray(schemes_.secure_schemes, &schemes->secure_schemes);
|
|
|
|
AppendArray(schemes_.cors_enabled_schemes, &schemes->cors_enabled_schemes);
|
2017-03-03 23:37:23 +01:00
|
|
|
AppendArray(schemes_.csp_bypassing_schemes, &schemes->csp_bypassing_schemes);
|
2012-04-24 20:01:48 +02:00
|
|
|
}
|