| 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> | 7 #include "content/common/savable_url_schemes.h" |
| 8 | |
| 9 #include "base/string_util.h" | |
| 10 #include "content/public/common/content_client.h" | |
| 11 #include "googleurl/src/url_util.h" | |
| 12 | |
| 13 namespace { | |
| 14 const char* kDefaultSavableSchemes[] = { | |
| 15 chrome::kHttpScheme, | |
| 16 chrome::kHttpsScheme, | |
| 17 chrome::kFileScheme, | |
| 18 chrome::kFileSystemScheme, | |
| 19 chrome::kFtpScheme, | |
| 20 chrome::kChromeDevToolsScheme, | |
| 21 chrome::kChromeUIScheme, | |
| 22 chrome::kDataScheme, | |
| 23 NULL | |
| 24 }; | |
| 25 char** g_savable_schemes = const_cast<char**>(kDefaultSavableSchemes); | |
| 26 | |
| 27 void AddStandardSchemeHelper(const std::string& scheme) { | |
| 28 url_util::AddStandardScheme(scheme.c_str()); | |
| 29 } | |
| 30 | |
| 31 } // namespace | |
| 32 | 8 |
| 33 namespace chrome { | 9 namespace chrome { |
| 34 | 10 |
| 35 const char kAboutScheme[] = "about"; | 11 const char kAboutScheme[] = "about"; |
| 36 const char kBlobScheme[] = "blob"; | 12 const char kBlobScheme[] = "blob"; |
| 37 | 13 |
| 38 // Before adding new chrome schemes please check with security@chromium.org. | 14 // Before adding new chrome schemes please check with security@chromium.org. |
| 39 // There are security implications associated with introducing new schemes. | 15 // There are security implications associated with introducing new schemes. |
| 40 const char kChromeDevToolsScheme[] = "chrome-devtools"; | 16 const char kChromeDevToolsScheme[] = "chrome-devtools"; |
| 41 const char kChromeInternalScheme[] = "chrome-internal"; | 17 const char kChromeInternalScheme[] = "chrome-internal"; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 51 |
| 76 // This error URL is loaded in normal web renderer processes, so it should not | 52 // 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. | 53 // have a chrome:// scheme that might let it be confused with a WebUI page. |
| 78 const char kUnreachableWebDataURL[] = "data:text/html,chromewebdata"; | 54 const char kUnreachableWebDataURL[] = "data:text/html,chromewebdata"; |
| 79 | 55 |
| 80 // This URL is loaded when a page is swapped out and replaced by a page in a | 56 // 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 | 57 // different renderer process. It must have a unique origin that cannot be |
| 82 // scripted by other pages in the process. | 58 // scripted by other pages in the process. |
| 83 const char kSwappedOutURL[] = "swappedout://"; | 59 const char kSwappedOutURL[] = "swappedout://"; |
| 84 | 60 |
| 85 const char** GetSavableSchemes() { | 61 const char* const* GetSavableSchemes() { |
| 86 return const_cast<const char**>(g_savable_schemes); | 62 return GetSavableSchemesInternal(); |
| 87 } | |
| 88 | |
| 89 void RegisterContentSchemes(bool lock_standard_schemes) { | |
| 90 std::vector<std::string> additional_standard_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 } | 63 } |
| 129 | 64 |
| 130 } // namespace content | 65 } // namespace content |
| OLD | NEW |