| OLD | NEW |
| 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 Loading... |
| 69 | 77 |
| 70 // This URL is loaded when a page is swapped out and replaced by a page in a | 78 // This URL is loaded when a page is swapped out and replaced by a page in a |
| 71 // different renderer process. It must have a unique origin that cannot be | 79 // different renderer process. It must have a unique origin that cannot be |
| 72 // scripted by other pages in the process. | 80 // scripted by other pages in the process. |
| 73 const char kSwappedOutURL[] = "swappedout://"; | 81 const char kSwappedOutURL[] = "swappedout://"; |
| 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 GetContentClient()->AddAdditionalSchemes( |
| 91 &additional_standard_schemes, |
| 92 &additional_savable_schemes); |
| 93 |
| 80 // Don't need "chrome-internal" which was used in old versions of Chrome for | 94 // Don't need "chrome-internal" which was used in old versions of Chrome for |
| 81 // the new tab page. | 95 // the new tab page. |
| 82 url_util::AddStandardScheme(chrome::kChromeDevToolsScheme); | 96 url_util::AddStandardScheme(chrome::kChromeDevToolsScheme); |
| 83 url_util::AddStandardScheme(chrome::kChromeUIScheme); | 97 url_util::AddStandardScheme(chrome::kChromeUIScheme); |
| 84 url_util::AddStandardScheme(chrome::kMetadataScheme); | 98 url_util::AddStandardScheme(chrome::kMetadataScheme); |
| 99 std::for_each(additional_standard_schemes.begin(), |
| 100 additional_standard_schemes.end(), |
| 101 AddStandardSchemeHelper); |
| 85 | 102 |
| 86 // Prevent future modification of the standard schemes list. This is to | 103 // Prevent future modification of the standard schemes list. This is to |
| 87 // prevent accidental creation of data races in the program. AddStandardScheme | 104 // 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 | 105 // 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 | 106 // thread. This is really easy to mess up, so we say that all calls to |
| 90 // AddStandardScheme in Chrome must be inside this function. | 107 // AddStandardScheme in Chrome must be inside this function. |
| 91 url_util::LockStandardSchemes(); | 108 if (lock_standard_schemes) |
| 109 url_util::LockStandardSchemes(); |
| 92 | 110 |
| 93 // We rely on the above lock to protect this part from being invoked twice. | 111 // We rely on the above lock to protect this part from being invoked twice. |
| 94 if (additional_savable_schemes) { | 112 if (!additional_savable_schemes.empty()) { |
| 95 int schemes = 0; | 113 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 | 114 // The array, and the copied schemes won't be freed, but will remain |
| 98 // reachable. | 115 // reachable. |
| 99 g_savable_schemes = new char*[schemes + arraysize(kDefaultSavableSchemes)]; | 116 g_savable_schemes = new char*[schemes + arraysize(kDefaultSavableSchemes)]; |
| 100 memcpy(g_savable_schemes, | 117 memcpy(g_savable_schemes, |
| 101 kDefaultSavableSchemes, | 118 kDefaultSavableSchemes, |
| 102 arraysize(kDefaultSavableSchemes) * sizeof(char*)); | 119 arraysize(kDefaultSavableSchemes) * sizeof(char*)); |
| 103 for (int i = 0; i < schemes; ++i) { | 120 for (int i = 0; i < schemes; ++i) { |
| 104 g_savable_schemes[arraysize(kDefaultSavableSchemes) + i - 1] = | 121 g_savable_schemes[arraysize(kDefaultSavableSchemes) + i - 1] = |
| 105 base::strdup(additional_savable_schemes[i]); | 122 base::strdup(additional_savable_schemes[i].c_str()); |
| 106 } | 123 } |
| 107 g_savable_schemes[arraysize(kDefaultSavableSchemes) + schemes - 1] = 0; | 124 g_savable_schemes[arraysize(kDefaultSavableSchemes) + schemes - 1] = 0; |
| 108 } | 125 } |
| 109 } | 126 } |
| 110 | 127 |
| 111 } // namespace content | 128 } // namespace content |
| OLD | NEW |