Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: content/public/common/url_constants.cc

Issue 10383298: Move RegisterContentSchemes from public url_constants into non-public url_schemes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: take RegisterContentSchemes out of public Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/public/common/url_constants.h" 5 #include "content/public/common/url_constants.h"
6 6
7 #include <algorithm> 7 #include <stddef.h>
8
9 #include "base/string_util.h"
10 #include "content/public/common/content_client.h"
11 #include "googleurl/src/url_util.h"
12 8
13 namespace { 9 namespace {
14 const char* kDefaultSavableSchemes[] = { 10
11 const char* const kDefaultSavableSchemes[] = {
15 chrome::kHttpScheme, 12 chrome::kHttpScheme,
16 chrome::kHttpsScheme, 13 chrome::kHttpsScheme,
17 chrome::kFileScheme, 14 chrome::kFileScheme,
18 chrome::kFileSystemScheme, 15 chrome::kFileSystemScheme,
19 chrome::kFtpScheme, 16 chrome::kFtpScheme,
20 chrome::kChromeDevToolsScheme, 17 chrome::kChromeDevToolsScheme,
21 chrome::kChromeUIScheme, 18 chrome::kChromeUIScheme,
22 chrome::kDataScheme, 19 chrome::kDataScheme,
23 NULL 20 NULL
24 }; 21 };
25 char** g_savable_schemes = const_cast<char**>(kDefaultSavableSchemes);
26 22
27 void AddStandardSchemeHelper(const std::string& scheme) { 23 const char* const* g_savable_schemes = kDefaultSavableSchemes;
28 url_util::AddStandardScheme(scheme.c_str());
29 }
30 24
31 } // namespace 25 } // namespace
32 26
33 namespace chrome { 27 namespace chrome {
34 28
35 const char kAboutScheme[] = "about"; 29 const char kAboutScheme[] = "about";
36 const char kBlobScheme[] = "blob"; 30 const char kBlobScheme[] = "blob";
37 31
38 // Before adding new chrome schemes please check with security@chromium.org. 32 // Before adding new chrome schemes please check with security@chromium.org.
39 // There are security implications associated with introducing new schemes. 33 // There are security implications associated with introducing new schemes.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 69
76 // This error URL is loaded in normal web renderer processes, so it should not 70 // This error URL is loaded in normal web renderer processes, so it should not
77 // have a chrome:// scheme that might let it be confused with a WebUI page. 71 // have a chrome:// scheme that might let it be confused with a WebUI page.
78 const char kUnreachableWebDataURL[] = "data:text/html,chromewebdata"; 72 const char kUnreachableWebDataURL[] = "data:text/html,chromewebdata";
79 73
80 // This URL is loaded when a page is swapped out and replaced by a page in a 74 // This URL is loaded when a page is swapped out and replaced by a page in a
81 // different renderer process. It must have a unique origin that cannot be 75 // different renderer process. It must have a unique origin that cannot be
82 // scripted by other pages in the process. 76 // scripted by other pages in the process.
83 const char kSwappedOutURL[] = "swappedout://"; 77 const char kSwappedOutURL[] = "swappedout://";
84 78
85 const char** GetSavableSchemes() { 79 const char* const* GetSavableSchemes() {
86 return const_cast<const char**>(g_savable_schemes); 80 return g_savable_schemes;
87 } 81 }
88 82
89 void RegisterContentSchemes(bool lock_standard_schemes) { 83 void SetSavableSchemes(const char* const* savable_schemes) {
90 std::vector<std::string> additional_standard_schemes; 84 g_savable_schemes = savable_schemes;
91 std::vector<std::string> additional_savable_schemes;
92 GetContentClient()->AddAdditionalSchemes(
93 &additional_standard_schemes,
94 &additional_savable_schemes);
95
96 // Don't need "chrome-internal" which was used in old versions of Chrome for
97 // the new tab page.
98 url_util::AddStandardScheme(chrome::kChromeDevToolsScheme);
99 url_util::AddStandardScheme(chrome::kChromeUIScheme);
100 url_util::AddStandardScheme(chrome::kMetadataScheme);
101 std::for_each(additional_standard_schemes.begin(),
102 additional_standard_schemes.end(),
103 AddStandardSchemeHelper);
104
105 // Prevent future modification of the standard schemes list. This is to
106 // prevent accidental creation of data races in the program. AddStandardScheme
107 // isn't threadsafe so must be called when GURL isn't used on any other
108 // thread. This is really easy to mess up, so we say that all calls to
109 // AddStandardScheme in Chrome must be inside this function.
110 if (lock_standard_schemes)
111 url_util::LockStandardSchemes();
112
113 // We rely on the above lock to protect this part from being invoked twice.
114 if (!additional_savable_schemes.empty()) {
115 int schemes = static_cast<int>(additional_savable_schemes.size());
116 // The array, and the copied schemes won't be freed, but will remain
117 // reachable.
118 g_savable_schemes = new char*[schemes + arraysize(kDefaultSavableSchemes)];
119 memcpy(g_savable_schemes,
120 kDefaultSavableSchemes,
121 arraysize(kDefaultSavableSchemes) * sizeof(char*));
122 for (int i = 0; i < schemes; ++i) {
123 g_savable_schemes[arraysize(kDefaultSavableSchemes) + i - 1] =
124 base::strdup(additional_savable_schemes[i].c_str());
125 }
126 g_savable_schemes[arraysize(kDefaultSavableSchemes) + schemes - 1] = 0;
127 }
128 } 85 }
129 86
130 } // namespace content 87 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698