blob: 68f3b72d4ba605ff6820e7b1d69ff3da0529a435 [file] [log] [blame]
[email protected]1de7a172012-05-28 18:36:431// Copyright (c) 2012 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 "content/common/url_schemes.h"
6
7#include <string.h>
8
9#include <algorithm>
[email protected]1de7a172012-05-28 18:36:4310
[email protected]30fe1f92013-06-12 16:34:3411#include "base/strings/string_util.h"
[email protected]1de7a172012-05-28 18:36:4312#include "content/public/common/content_client.h"
13#include "content/public/common/url_constants.h"
[email protected]707e1c42013-07-09 21:18:5814#include "url/url_util.h"
[email protected]1de7a172012-05-28 18:36:4315
jame0dcd982017-01-11 03:13:4516namespace content {
[email protected]1de7a172012-05-28 18:36:4317namespace {
18
jame0dcd982017-01-11 03:13:4519// These lists are lazily initialized below and are leaked on shutdown to
20// prevent any destructors from being called that will slow us down or cause
21// problems.
22std::vector<std::string>* savable_schemes = nullptr;
jame0dcd982017-01-11 03:13:4523// Note we store GURLs here instead of strings to deal with canonicalization.
24std::vector<GURL>* secure_origins = nullptr;
25std::vector<std::string>* service_worker_schemes = nullptr;
26
27const char* const kDefaultSavableSchemes[] = {
28 url::kHttpScheme,
29 url::kHttpsScheme,
30 url::kFileScheme,
31 url::kFileSystemScheme,
32 url::kFtpScheme,
33 kChromeDevToolsScheme,
34 kChromeUIScheme,
35 url::kDataScheme
36};
37
[email protected]1de7a172012-05-28 18:36:4338} // namespace
39
lizeb5120f6dc2016-02-19 09:29:4440void RegisterContentSchemes(bool lock_schemes) {
jame0dcd982017-01-11 03:13:4541 ContentClient::Schemes schemes;
42 GetContentClient()->AddAdditionalSchemes(&schemes);
[email protected]1de7a172012-05-28 18:36:4343
tyoshino11a7c9fe2015-08-19 08:51:4644 url::AddStandardScheme(kChromeDevToolsScheme, url::SCHEME_WITHOUT_PORT);
45 url::AddStandardScheme(kChromeUIScheme, url::SCHEME_WITHOUT_PORT);
46 url::AddStandardScheme(kGuestScheme, url::SCHEME_WITHOUT_PORT);
[email protected]1de7a172012-05-28 18:36:4347
jame0dcd982017-01-11 03:13:4548 for (auto& scheme : schemes.standard_schemes)
49 url::AddStandardScheme(scheme.c_str(), url::SCHEME_WITHOUT_PORT);
lizeb5120f6dc2016-02-19 09:29:4450
jame0dcd982017-01-11 03:13:4551 for (auto& scheme : schemes.referrer_schemes)
52 url::AddReferrerScheme(scheme.c_str(), url::SCHEME_WITHOUT_PORT);
lizeb5120f6dc2016-02-19 09:29:4453
jam09015352017-01-19 01:49:0254 schemes.secure_schemes.push_back(kChromeUIScheme);
Alex Moshchuk71f485592017-08-16 16:20:0055 schemes.secure_schemes.push_back(kChromeErrorScheme);
jam09015352017-01-19 01:49:0256 for (auto& scheme : schemes.secure_schemes)
57 url::AddSecureScheme(scheme.c_str());
58
59 for (auto& scheme : schemes.local_schemes)
60 url::AddLocalScheme(scheme.c_str());
61
Alex Moshchuk71f485592017-08-16 16:20:0062 schemes.no_access_schemes.push_back(kChromeErrorScheme);
jam09015352017-01-19 01:49:0263 for (auto& scheme : schemes.no_access_schemes)
64 url::AddNoAccessScheme(scheme.c_str());
65
66 schemes.cors_enabled_schemes.push_back(kChromeUIScheme);
67 for (auto& scheme : schemes.cors_enabled_schemes)
68 url::AddCORSEnabledScheme(scheme.c_str());
69
Alex Moshchuk71f485592017-08-16 16:20:0070 // TODO(mkwst): Investigate whether chrome-error should be included in
71 // csp_bypassing_schemes.
arthursonzognieb73e432017-02-09 11:54:4972 for (auto& scheme : schemes.csp_bypassing_schemes)
73 url::AddCSPBypassingScheme(scheme.c_str());
74
jamcc2df162017-03-23 23:54:0175 for (auto& scheme : schemes.empty_document_schemes)
76 url::AddEmptyDocumentScheme(scheme.c_str());
77
lizeb5120f6dc2016-02-19 09:29:4478 // Prevent future modification of the scheme lists. This is to prevent
79 // accidental creation of data races in the program. Add*Scheme aren't
80 // threadsafe so must be called when GURL isn't used on any other thread. This
81 // is really easy to mess up, so we say that all calls to Add*Scheme in Chrome
82 // must be inside this function.
83 if (lock_schemes)
84 url::LockSchemeRegistries();
[email protected]1de7a172012-05-28 18:36:4385
jame0dcd982017-01-11 03:13:4586 // Combine the default savable schemes with the additional ones given.
jam09015352017-01-19 01:49:0287 delete savable_schemes;
jame0dcd982017-01-11 03:13:4588 savable_schemes = new std::vector<std::string>;
vmpstr6d9996c82017-02-23 00:43:2589 for (auto* default_scheme : kDefaultSavableSchemes)
jame0dcd982017-01-11 03:13:4590 savable_schemes->push_back(default_scheme);
91 savable_schemes->insert(savable_schemes->end(),
92 schemes.savable_schemes.begin(),
93 schemes.savable_schemes.end());
[email protected]1de7a172012-05-28 18:36:4394
jam09015352017-01-19 01:49:0295 delete service_worker_schemes;
jame0dcd982017-01-11 03:13:4596 service_worker_schemes = new std::vector<std::string>;
97 *service_worker_schemes = std::move(schemes.service_worker_schemes);
98
jam09015352017-01-19 01:49:0299 delete secure_origins;
jame0dcd982017-01-11 03:13:45100 secure_origins = new std::vector<GURL>;
101 *secure_origins = std::move(schemes.secure_origins);
102}
103
104const std::vector<std::string>& GetSavableSchemes() {
105 return *savable_schemes;
106}
107
jame0dcd982017-01-11 03:13:45108const std::vector<GURL>& GetSecureOrigins() {
109 return *secure_origins;
110}
111
112const std::vector<std::string>& GetServiceWorkerSchemes() {
113 return *service_worker_schemes;
114}
115
[email protected]1de7a172012-05-28 18:36:43116} // namespace content