• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
9 #include "libcef/common/app_manager.h"
10 #include "libcef/common/net/scheme_info.h"
11 #include "libcef/common/net/scheme_registration.h"
12 
13 #include "base/bind.h"
14 #include "base/logging.h"
15 #include "base/strings/string_util.h"
16 
17 namespace {
18 
AppendArray(const std::vector<std::string> & source,std::vector<std::string> * target)19 void AppendArray(const std::vector<std::string>& source,
20                  std::vector<std::string>* target) {
21   if (source.empty())
22     return;
23   target->insert(target->end(), source.begin(), source.end());
24 }
25 }  // namespace
26 
CefSchemeRegistrarImpl()27 CefSchemeRegistrarImpl::CefSchemeRegistrarImpl() {}
28 
AddCustomScheme(const CefString & scheme_name,int options)29 bool CefSchemeRegistrarImpl::AddCustomScheme(const CefString& scheme_name,
30                                              int options) {
31   const std::string& scheme = base::ToLowerASCII(scheme_name.ToString());
32   if (scheme::IsInternalHandledScheme(scheme) ||
33       registered_schemes_.find(scheme) != registered_schemes_.end()) {
34     return false;
35   }
36 
37   registered_schemes_.insert(scheme);
38 
39   const bool is_standard = options & CEF_SCHEME_OPTION_STANDARD;
40   const bool is_local = options & CEF_SCHEME_OPTION_LOCAL;
41   const bool is_display_isolated = options & CEF_SCHEME_OPTION_DISPLAY_ISOLATED;
42   const bool is_secure = options & CEF_SCHEME_OPTION_SECURE;
43   const bool is_cors_enabled = options & CEF_SCHEME_OPTION_CORS_ENABLED;
44   const bool is_csp_bypassing = options & CEF_SCHEME_OPTION_CSP_BYPASSING;
45   const bool is_fetch_enabled = options & CEF_SCHEME_OPTION_FETCH_ENABLED;
46 
47   // The |is_display_isolated| value is excluded here because it's registered
48   // with Blink only.
49   if (is_standard)
50     schemes_.standard_schemes.push_back(scheme);
51   if (is_local)
52     schemes_.local_schemes.push_back(scheme);
53   if (is_secure)
54     schemes_.secure_schemes.push_back(scheme);
55   if (is_cors_enabled)
56     schemes_.cors_enabled_schemes.push_back(scheme);
57   if (is_csp_bypassing)
58     schemes_.csp_bypassing_schemes.push_back(scheme);
59 
60   CefSchemeInfo scheme_info = {
61       scheme,    is_standard,     is_local,         is_display_isolated,
62       is_secure, is_cors_enabled, is_csp_bypassing, is_fetch_enabled};
63   CefAppManager::Get()->AddCustomScheme(&scheme_info);
64 
65   return true;
66 }
67 
GetSchemes(content::ContentClient::Schemes * schemes)68 void CefSchemeRegistrarImpl::GetSchemes(
69     content::ContentClient::Schemes* schemes) {
70   AppendArray(schemes_.standard_schemes, &schemes->standard_schemes);
71   AppendArray(schemes_.local_schemes, &schemes->local_schemes);
72   AppendArray(schemes_.secure_schemes, &schemes->secure_schemes);
73   AppendArray(schemes_.cors_enabled_schemes, &schemes->cors_enabled_schemes);
74   AppendArray(schemes_.csp_bypassing_schemes, &schemes->csp_bypassing_schemes);
75 }
76