| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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_constants.h" | |
| 6 | |
| 7 #include "base/string_util.h" | |
| 8 #include "googleurl/src/url_util.h" | |
| 9 | |
| 10 namespace { | |
| 11 const char* kDefaultSavableSchemes[] = { | |
| 12 chrome::kHttpScheme, | |
| 13 chrome::kHttpsScheme, | |
| 14 chrome::kFileScheme, | |
| 15 chrome::kFtpScheme, | |
| 16 chrome::kChromeDevToolsScheme, | |
| 17 chrome::kChromeUIScheme, | |
| 18 NULL | |
| 19 }; | |
| 20 char** g_savable_schemes = const_cast<char**>(kDefaultSavableSchemes); | |
| 21 } // namespace | |
| 22 | |
| 23 namespace chrome { | |
| 24 | |
| 25 const char kAboutScheme[] = "about"; | |
| 26 const char kBlobScheme[] = "blob"; | |
| 27 | |
| 28 // Before adding new chrome schemes please check with security@chromium.org. | |
| 29 // There are security implications associated with introducing new schemes. | |
| 30 const char kChromeDevToolsScheme[] = "chrome-devtools"; | |
| 31 const char kChromeInternalScheme[] = "chrome-internal"; | |
| 32 const char kChromeUIScheme[] = "chrome"; | |
| 33 const char kDataScheme[] = "data"; | |
| 34 const char kFileScheme[] = "file"; | |
| 35 const char kFileSystemScheme[] = "filesystem"; | |
| 36 const char kFtpScheme[] = "ftp"; | |
| 37 const char kHttpScheme[] = "http"; | |
| 38 const char kHttpsScheme[] = "https"; | |
| 39 const char kJavaScriptScheme[] = "javascript"; | |
| 40 const char kMailToScheme[] = "mailto"; | |
| 41 const char kMetadataScheme[] = "metadata"; | |
| 42 const char kViewSourceScheme[] = "view-source"; | |
| 43 | |
| 44 const char kStandardSchemeSeparator[] = "://"; | |
| 45 | |
| 46 const char kAboutBlankURL[] = "about:blank"; | |
| 47 const char kAboutCrashURL[] = "about:crash"; | |
| 48 | |
| 49 const char kUnreachableWebDataURL[] = "chrome://chromewebdata/"; | |
| 50 | |
| 51 const char** GetSavableSchemes() { | |
| 52 return const_cast<const char**>(g_savable_schemes); | |
| 53 } | |
| 54 | |
| 55 void RegisterContentSchemes(const char** additional_savable_schemes) { | |
| 56 // Don't need "chrome-internal" which was used in old versions of Chrome for | |
| 57 // the new tab page. | |
| 58 url_util::AddStandardScheme(kChromeDevToolsScheme); | |
| 59 url_util::AddStandardScheme(kChromeUIScheme); | |
| 60 url_util::AddStandardScheme(kMetadataScheme); | |
| 61 | |
| 62 // Prevent future modification of the standard schemes list. This is to | |
| 63 // prevent accidental creation of data races in the program. AddStandardScheme | |
| 64 // isn't threadsafe so must be called when GURL isn't used on any other | |
| 65 // thread. This is really easy to mess up, so we say that all calls to | |
| 66 // AddStandardScheme in Chrome must be inside this function. | |
| 67 url_util::LockStandardSchemes(); | |
| 68 | |
| 69 // We rely on the above lock to protect this part from being invoked twice. | |
| 70 if (additional_savable_schemes) { | |
| 71 int schemes = 0; | |
| 72 while (additional_savable_schemes[++schemes]); | |
| 73 // The array, and the copied schemes won't be freed, but will remain | |
| 74 // reachable. | |
| 75 g_savable_schemes = new char*[schemes + arraysize(kDefaultSavableSchemes)]; | |
| 76 memcpy(g_savable_schemes, | |
| 77 kDefaultSavableSchemes, | |
| 78 arraysize(kDefaultSavableSchemes) * sizeof(char*)); | |
| 79 for (int i = 0; i < schemes; ++i) { | |
| 80 g_savable_schemes[arraysize(kDefaultSavableSchemes) + i - 1] = | |
| 81 base::strdup(additional_savable_schemes[i]); | |
| 82 } | |
| 83 g_savable_schemes[arraysize(kDefaultSavableSchemes) + schemes - 1] = 0; | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 } // namespace chrome | |
| OLD | NEW |