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

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

Issue 9950040: Get chrome:// dev tool urls hooked up in content_shell. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 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>
8
7 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "content/public/common/content_client.h"
8 #include "googleurl/src/url_util.h" 11 #include "googleurl/src/url_util.h"
9 12
10 namespace { 13 namespace {
11 const char* kDefaultSavableSchemes[] = { 14 const char* kDefaultSavableSchemes[] = {
12 chrome::kHttpScheme, 15 chrome::kHttpScheme,
13 chrome::kHttpsScheme, 16 chrome::kHttpsScheme,
14 chrome::kFileScheme, 17 chrome::kFileScheme,
15 chrome::kFileSystemScheme, 18 chrome::kFileSystemScheme,
16 chrome::kFtpScheme, 19 chrome::kFtpScheme,
17 chrome::kChromeDevToolsScheme, 20 chrome::kChromeDevToolsScheme,
18 chrome::kChromeUIScheme, 21 chrome::kChromeUIScheme,
19 NULL 22 NULL
20 }; 23 };
21 char** g_savable_schemes = const_cast<char**>(kDefaultSavableSchemes); 24 char** g_savable_schemes = const_cast<char**>(kDefaultSavableSchemes);
25
26 void AddStandardSchemeHelper(const std::string& scheme) {
27 url_util::AddStandardScheme(scheme.c_str());
28 }
29
22 } // namespace 30 } // namespace
23 31
24 namespace chrome { 32 namespace chrome {
25 33
26 const char kAboutScheme[] = "about"; 34 const char kAboutScheme[] = "about";
27 const char kBlobScheme[] = "blob"; 35 const char kBlobScheme[] = "blob";
28 36
29 // Before adding new chrome schemes please check with security@chromium.org. 37 // Before adding new chrome schemes please check with security@chromium.org.
30 // There are security implications associated with introducing new schemes. 38 // There are security implications associated with introducing new schemes.
31 const char kChromeDevToolsScheme[] = "chrome-devtools"; 39 const char kChromeDevToolsScheme[] = "chrome-devtools";
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 const char kSwappedOutURL[] = "swappedout://"; 77 const char kSwappedOutURL[] = "swappedout://";
70 78
71 } // namespace chrome 79 } // namespace chrome
72 80
73 namespace content { 81 namespace content {
74 82
75 const char** GetSavableSchemes() { 83 const char** GetSavableSchemes() {
76 return const_cast<const char**>(g_savable_schemes); 84 return const_cast<const char**>(g_savable_schemes);
77 } 85 }
78 86
79 void RegisterContentSchemes(const char** additional_savable_schemes) { 87 void RegisterContentSchemes(bool lock_standard_schemes) {
88 std::vector<std::string> additional_standard_schemes;
89 std::vector<std::string> additional_savable_schemes;
90 if (GetContentClient()) {
jam 2012/04/17 03:30:10 we don't usually null check GetContentClient by de
michaeln 2012/04/17 04:08:26 I noticed that. Yes, this is for content_unittest
91 GetContentClient()->AddAdditionalSchemes(
92 &additional_standard_schemes,
93 &additional_savable_schemes);
94 }
95
80 // Don't need "chrome-internal" which was used in old versions of Chrome for 96 // Don't need "chrome-internal" which was used in old versions of Chrome for
81 // the new tab page. 97 // the new tab page.
82 url_util::AddStandardScheme(chrome::kChromeDevToolsScheme); 98 url_util::AddStandardScheme(chrome::kChromeDevToolsScheme);
83 url_util::AddStandardScheme(chrome::kChromeUIScheme); 99 url_util::AddStandardScheme(chrome::kChromeUIScheme);
84 url_util::AddStandardScheme(chrome::kMetadataScheme); 100 url_util::AddStandardScheme(chrome::kMetadataScheme);
101 std::for_each(additional_standard_schemes.begin(),
102 additional_standard_schemes.end(),
103 AddStandardSchemeHelper);
85 104
86 // Prevent future modification of the standard schemes list. This is to 105 // Prevent future modification of the standard schemes list. This is to
87 // prevent accidental creation of data races in the program. AddStandardScheme 106 // prevent accidental creation of data races in the program. AddStandardScheme
88 // isn't threadsafe so must be called when GURL isn't used on any other 107 // isn't threadsafe so must be called when GURL isn't used on any other
89 // thread. This is really easy to mess up, so we say that all calls to 108 // thread. This is really easy to mess up, so we say that all calls to
90 // AddStandardScheme in Chrome must be inside this function. 109 // AddStandardScheme in Chrome must be inside this function.
91 url_util::LockStandardSchemes(); 110 if (lock_standard_schemes)
111 url_util::LockStandardSchemes();
92 112
93 // We rely on the above lock to protect this part from being invoked twice. 113 // We rely on the above lock to protect this part from being invoked twice.
94 if (additional_savable_schemes) { 114 if (!additional_savable_schemes.empty()) {
95 int schemes = 0; 115 int schemes = static_cast<int>(additional_savable_schemes.size());
96 while (additional_savable_schemes[++schemes]);
97 // The array, and the copied schemes won't be freed, but will remain 116 // The array, and the copied schemes won't be freed, but will remain
98 // reachable. 117 // reachable.
99 g_savable_schemes = new char*[schemes + arraysize(kDefaultSavableSchemes)]; 118 g_savable_schemes = new char*[schemes + arraysize(kDefaultSavableSchemes)];
100 memcpy(g_savable_schemes, 119 memcpy(g_savable_schemes,
101 kDefaultSavableSchemes, 120 kDefaultSavableSchemes,
102 arraysize(kDefaultSavableSchemes) * sizeof(char*)); 121 arraysize(kDefaultSavableSchemes) * sizeof(char*));
103 for (int i = 0; i < schemes; ++i) { 122 for (int i = 0; i < schemes; ++i) {
104 g_savable_schemes[arraysize(kDefaultSavableSchemes) + i - 1] = 123 g_savable_schemes[arraysize(kDefaultSavableSchemes) + i - 1] =
105 base::strdup(additional_savable_schemes[i]); 124 base::strdup(additional_savable_schemes[i].c_str());
106 } 125 }
107 g_savable_schemes[arraysize(kDefaultSavableSchemes) + schemes - 1] = 0; 126 g_savable_schemes[arraysize(kDefaultSavableSchemes) + schemes - 1] = 0;
108 } 127 }
109 } 128 }
110 129
111 } // namespace content 130 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698