diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-26 01:56:02 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-26 01:56:02 +0000 |
commit | dcf7d3525aa9b1f16b56a16d16108262db0571ee (patch) | |
tree | 91228f9d96aa74f102df742cdf76598cbb328958 | |
parent | 387b71b7d1d1bf267cbe088136610959b319f3b3 (diff) | |
download | chromium_src-dcf7d3525aa9b1f16b56a16d16108262db0571ee.zip chromium_src-dcf7d3525aa9b1f16b56a16d16108262db0571ee.tar.gz chromium_src-dcf7d3525aa9b1f16b56a16d16108262db0571ee.tar.bz2 |
Coalesce more hardcoded schemes to using predefined constants.
Review URL: http://codereview.chromium.org/31008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10437 0039d316-1c4b-4281-b951-d872f2087c98
32 files changed, 140 insertions, 94 deletions
diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc index 97ccd03..7ecba26 100644 --- a/chrome/browser/autocomplete/history_url_provider.cc +++ b/chrome/browser/autocomplete/history_url_provider.cc @@ -19,6 +19,7 @@ #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/common/sqlite_utils.h" +#include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" #include "googleurl/src/url_parse.h" #include "googleurl/src/url_util.h" @@ -344,8 +345,9 @@ std::wstring HistoryURLProvider::FixupUserInput(const std::wstring& input) { // Don't prepend a scheme when the user didn't have one. Since the fixer // upper only prepends the "http" scheme, that's all we need to check for. url_parse::Component scheme; - if (canonical_gurl.SchemeIs("http") && - !url_util::FindAndCompareScheme(WideToUTF8(input), "http", &scheme)) + if (canonical_gurl.SchemeIs(chrome::kHttpScheme) && + !url_util::FindAndCompareScheme(WideToUTF8(input), chrome::kHttpScheme, + &scheme)) TrimHttpPrefix(&output); // Make the number of trailing slashes on the output exactly match the input. @@ -380,7 +382,8 @@ std::wstring HistoryURLProvider::FixupUserInput(const std::wstring& input) { // static size_t HistoryURLProvider::TrimHttpPrefix(std::wstring* url) { url_parse::Component scheme; - if (!url_util::FindAndCompareScheme(WideToUTF8(*url), "http", &scheme)) + if (!url_util::FindAndCompareScheme(WideToUTF8(*url), chrome::kHttpScheme, + &scheme)) return 0; // Not "http". // Erase scheme plus up to two slashes. @@ -593,7 +596,7 @@ void HistoryURLProvider::RunAutocompletePasses(const AutocompleteInput& input, // Create a match for exactly what the user typed. This will always be one // of the top two results we return. const bool trim_http = !url_util::FindAndCompareScheme( - WideToUTF8(input.text()), "http", NULL); + WideToUTF8(input.text()), chrome::kHttpScheme, NULL); SuggestExactInput(input, trim_http); // We'll need the history service to run both passes, so try to obtain it. diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc index 477543d..1b51449 100644 --- a/chrome/browser/autocomplete/search_provider.cc +++ b/chrome/browser/autocomplete/search_provider.cc @@ -15,6 +15,7 @@ #include "chrome/common/l10n_util.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" +#include "chrome/common/url_constants.h" #include "googleurl/src/url_util.h" #include "grit/generated_resources.h" #include "net/base/escape.h" @@ -606,7 +607,8 @@ AutocompleteMatch SearchProvider::NavigationToMatch( // static size_t SearchProvider::TrimHttpPrefix(std::wstring* url) { url_parse::Component scheme; - if (!url_util::FindAndCompareScheme(WideToUTF8(*url), "http", &scheme)) + if (!url_util::FindAndCompareScheme(WideToUTF8(*url), chrome::kHttpScheme, + &scheme)) return 0; // Not "http". // Erase scheme plus up to two slashes. diff --git a/chrome/browser/back_forward_menu_model_unittest.cc b/chrome/browser/back_forward_menu_model_unittest.cc index 0e642b5..217a485 100644 --- a/chrome/browser/back_forward_menu_model_unittest.cc +++ b/chrome/browser/back_forward_menu_model_unittest.cc @@ -11,6 +11,7 @@ #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents_factory.h" +#include "chrome/common/url_constants.h" #include "testing/gtest/include/gtest/gtest.h" #if defined(OS_WIN) @@ -55,7 +56,7 @@ class BackFwdMenuModelTestTabContentsFactory : public TabContentsFactory { } virtual bool CanHandleURL(const GURL& url) { - return url.scheme() == "http"; + return url.SchemeIs(chrome::kHttpScheme); } }; diff --git a/chrome/browser/bookmarks/bookmark_drag_data.cc b/chrome/browser/bookmarks/bookmark_drag_data.cc index 1194751..b64562e 100644 --- a/chrome/browser/bookmarks/bookmark_drag_data.cc +++ b/chrome/browser/bookmarks/bookmark_drag_data.cc @@ -9,6 +9,7 @@ #include "base/string_util.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/profile.h" +#include "chrome/common/url_constants.h" // TODO(port): Port this file. #if defined(OS_WIN) @@ -95,7 +96,7 @@ void BookmarkDragData::Write(Profile* profile, OSExchangeData* data) const { // If there is only one element and it is a URL, write the URL to the // clipboard. if (elements.size() == 1 && elements[0].is_url) { - if (elements[0].url.SchemeIs("javascript")) { + if (elements[0].url.SchemeIs(chrome::kJavaScriptScheme)) { data->SetString(ASCIIToWide(elements[0].url.spec())); } else { data->SetURL(elements[0].url, elements[0].title); diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc index 34f2556..511c4d1 100644 --- a/chrome/browser/browser_about_handler.cc +++ b/chrome/browser/browser_about_handler.cc @@ -30,6 +30,7 @@ #include "chrome/common/pref_service.h" #include "chrome/common/render_messages.h" #include "chrome/common/resource_bundle.h" +#include "chrome/common/url_constants.h" #include "chrome/renderer/about_handler.h" #include "googleurl/src/gurl.h" #include "grit/browser_resources.h" @@ -235,7 +236,7 @@ BrowserAboutHandler::BrowserAboutHandler(Profile* profile, bool BrowserAboutHandler::SupportsURL(GURL* url) { // Enable this tab contents to access javascript urls. - if (url->SchemeIs("javascript")) + if (url->SchemeIs(chrome::kJavaScriptScheme)) return true; return WebContents::SupportsURL(url); } diff --git a/chrome/browser/browsing_instance.cc b/chrome/browser/browsing_instance.cc index 90a61e4..4b7ee6c 100644 --- a/chrome/browser/browsing_instance.cc +++ b/chrome/browser/browsing_instance.cc @@ -7,6 +7,7 @@ #include "base/command_line.h" #include "chrome/browser/tab_contents/site_instance.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/url_constants.h" /*static*/ BrowsingInstance::ProfileSiteInstanceMap @@ -28,7 +29,7 @@ bool BrowsingInstance::ShouldUseProcessPerSite(const GURL& url) { // Note that --single-process may have been specified, but that affects the // process creation logic in RenderProcessHost, so we do not need to worry // about it here. - if (url.SchemeIs("chrome-ui")) + if (url.SchemeIs(chrome::kChromeUIScheme)) // Always consolidate instances of the new tab page (and instances of any // other internal resource urls). return true; diff --git a/chrome/browser/dom_ui/dom_ui_contents.cc b/chrome/browser/dom_ui/dom_ui_contents.cc index 68334bb..f7b83a2 100644 --- a/chrome/browser/dom_ui/dom_ui_contents.cc +++ b/chrome/browser/dom_ui/dom_ui_contents.cc @@ -12,10 +12,7 @@ #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/common/resource_bundle.h" - -// The scheme used for DOMUIContentses -// TODO(glen): Merge this with the scheme in chrome_url_data_manager -static const char kURLScheme[] = "chrome-ui"; +#include "chrome/common/url_constants.h" // The path used in internal URLs to thumbnail data. static const char kThumbnailPath[] = "thumb"; @@ -126,7 +123,8 @@ void ThumbnailSource::OnThumbnailDataAvailable( bool DOMUIContentsCanHandleURL(GURL* url, TabContentsType* result_type) { // chrome-internal is a scheme we used to use for the new tab page. - if (!url->SchemeIs(kURLScheme) && !url->SchemeIs("chrome-internal")) + if (!url->SchemeIs(chrome::kChromeUIScheme) && + !url->SchemeIs(chrome::kChromeInternalScheme)) return false; *result_type = TAB_CONTENTS_DOM_UI; @@ -225,14 +223,14 @@ void DOMUIContents::ProcessDOMUIMessage(const std::string& message, // static const std::string DOMUIContents::GetScheme() { - return kURLScheme; + return chrome::kChromeUIScheme; } DOMUI* DOMUIContents::GetDOMUIForURL(const GURL &url) { #if defined(OS_WIN) // TODO(port): include this once these are converted to HTML if (url.host() == NewTabUI::GetBaseURL().host() || - url.SchemeIs("chrome-internal")) { + url.SchemeIs(chrome::kChromeInternalScheme)) { return new NewTabUI(this); } else if (url.host() == HistoryUI::GetBaseURL().host()) { return new HistoryUI(this); diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc index 9db2610..1bccaa9 100644 --- a/chrome/browser/download/save_package.cc +++ b/chrome/browser/download/save_package.cc @@ -28,6 +28,7 @@ #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/common/stl_util-inl.h" +#include "chrome/common/url_constants.h" #include "grit/generated_resources.h" #include "net/base/io_buffer.h" #include "net/base/mime_util.h" @@ -1068,8 +1069,10 @@ bool SavePackage::GetSaveInfo(const FilePath& suggest_name, // Static bool SavePackage::IsSavableURL(const GURL& url) { - return url.SchemeIs("http") || url.SchemeIs("https") || - url.SchemeIs("file") || url.SchemeIs("ftp"); + return url.SchemeIs(chrome::kHttpScheme) || + url.SchemeIs(chrome::kHttpsScheme) || + url.SchemeIs(chrome::kFileScheme) || + url.SchemeIs(chrome::kFtpScheme); } // Static diff --git a/chrome/browser/extensions/extension.cc b/chrome/browser/extensions/extension.cc index d75ed5e..9efdd37 100644 --- a/chrome/browser/extensions/extension.cc +++ b/chrome/browser/extensions/extension.cc @@ -9,9 +9,7 @@ #include "base/string_util.h" #include "net/base/net_util.h" #include "chrome/common/extensions/user_script.h" - -const char kExtensionURLScheme[] = "chrome-extension"; -const char kUserScriptURLScheme[] = "chrome-user-script"; +#include "chrome/common/url_constants.h" const char Extension::kManifestFilename[] = "manifest.json"; @@ -75,13 +73,10 @@ const std::string Extension::VersionString() const { return version_->GetString(); } -// Defined in extension_protocols.h. -extern const char kExtensionURLScheme[]; - // static GURL Extension::GetResourceURL(const GURL& extension_url, const std::string& relative_path) { - DCHECK(extension_url.SchemeIs(kExtensionURLScheme)); + DCHECK(extension_url.SchemeIs(chrome::kExtensionScheme)); DCHECK(extension_url.path() == "/"); GURL ret_val = GURL(extension_url.spec() + relative_path); @@ -195,7 +190,8 @@ bool Extension::InitFromValue(const DictionaryValue& source, } // Initialize URL. - extension_url_ = GURL(std::string(kExtensionURLScheme) + "://" + id_ + "/"); + extension_url_ = GURL(std::string(chrome::kExtensionScheme) + + chrome::kStandardSchemeSeparator + id_ + "/"); // Initialize version. std::string version_str; diff --git a/chrome/browser/extensions/extension.h b/chrome/browser/extensions/extension.h index cc44cd5..39e5fff 100644 --- a/chrome/browser/extensions/extension.h +++ b/chrome/browser/extensions/extension.h @@ -16,14 +16,6 @@ #include "chrome/browser/extensions/user_script_master.h" #include "googleurl/src/gurl.h" -// The URL schemes Chromium extensions and user scripts are served from. These -// really should be in extension_protocols.h, but that causes link errors on -// linux because extension_protocols.cc refers to undefined symbols. -// TODO(aa): Move these back to extension_protocols.h when more of Linux and -// Mac are up and running. -extern const char kExtensionURLScheme[]; -extern const char kUserScriptURLScheme[]; - // Represents a Chromium extension. class Extension { public: diff --git a/chrome/browser/extensions/extension_protocols.cc b/chrome/browser/extensions/extension_protocols.cc index bc33592..5cf75f5 100644 --- a/chrome/browser/extensions/extension_protocols.cc +++ b/chrome/browser/extensions/extension_protocols.cc @@ -7,14 +7,11 @@ #include "base/string_util.h" #include "chrome/browser/extensions/extension.h" #include "chrome/browser/net/chrome_url_request_context.h" +#include "chrome/common/url_constants.h" #include "googleurl/src/url_util.h" #include "net/base/net_util.h" #include "net/url_request/url_request_file_job.h" -// Defined in extension.h. -extern const char kExtensionURLScheme[]; -extern const char kUserScriptURLScheme[]; - // Factory registered with URLRequest to create URLRequestJobs for extension:// // URLs. static URLRequestJob* CreateExtensionURLRequestJob(URLRequest* request, @@ -51,10 +48,10 @@ static URLRequestJob* CreateUserScriptURLRequestJob(URLRequest* request, void RegisterExtensionProtocols() { // Being a standard scheme allows us to resolve relative paths. This is used // by extensions, but not by standalone user scripts. - url_util::AddStandardScheme(kExtensionURLScheme); + url_util::AddStandardScheme(chrome::kExtensionScheme); - URLRequest::RegisterProtocolFactory(kExtensionURLScheme, + URLRequest::RegisterProtocolFactory(chrome::kExtensionScheme, &CreateExtensionURLRequestJob); - URLRequest::RegisterProtocolFactory(kUserScriptURLScheme, + URLRequest::RegisterProtocolFactory(chrome::kUserScriptScheme, &CreateUserScriptURLRequestJob); } diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc index a6af109..c37e1bb 100644 --- a/chrome/browser/extensions/user_script_master.cc +++ b/chrome/browser/extensions/user_script_master.cc @@ -14,12 +14,9 @@ #include "base/string_util.h" #include "chrome/common/notification_service.h" #include "chrome/common/stl_util-inl.h" +#include "chrome/common/url_constants.h" #include "net/base/net_util.h" -// Defined in extension.h. -extern const char kExtensionURLScheme[]; -extern const char kUserScriptURLScheme[]; - // static bool GetDeclarationValue(const StringPiece& line, const StringPiece& prefix, std::string* value) { @@ -158,7 +155,7 @@ base::SharedMemory* UserScriptMaster::ScriptReloader::GetNewScripts( file = enumerator.Next()) { all_scripts.push_back(UserScript()); UserScript& info = all_scripts.back(); - info.set_url(GURL(std::string(kUserScriptURLScheme) + ":/" + + info.set_url(GURL(std::string(chrome::kUserScriptScheme) + ":/" + net::FilePathToFileURL(file.ToWStringHack()).ExtractFileName())); info.set_path(file); } diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc index 015f442..94c309a 100644 --- a/chrome/browser/history/history_backend.cc +++ b/chrome/browser/history/history_backend.cc @@ -22,6 +22,7 @@ #include "chrome/common/chrome_constants.h" #include "chrome/common/notification_type.h" #include "chrome/common/sqlite_utils.h" +#include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" #include "net/base/registry_controlled_domain.h" @@ -368,7 +369,7 @@ void HistoryBackend::AddPage(scoped_refptr<HistoryAddPageArgs> request) { PageTransition::Type redirect_info = PageTransition::CHAIN_START; - if (request->redirects[0].SchemeIs("about")) { + if (request->redirects[0].SchemeIs(chrome::kAboutScheme)) { // When the redirect source + referrer is "about" we skip it. This // happens when a page opens a new frame/window to about:blank and then // script sets the URL to somewhere else (used to hide the referrer). It diff --git a/chrome/browser/history/visit_database.cc b/chrome/browser/history/visit_database.cc index 09f1231..9fd02ec 100644 --- a/chrome/browser/history/visit_database.cc +++ b/chrome/browser/history/visit_database.cc @@ -11,6 +11,7 @@ #include "chrome/browser/history/url_database.h" #include "chrome/common/page_transition_types.h" +#include "chrome/common/url_constants.h" using base::Time; @@ -326,7 +327,7 @@ bool VisitDatabase::GetRedirectFromVisit(VisitID from_visit, bool VisitDatabase::GetVisitCountToHost(const GURL& url, int* count, Time* first_visit) { - if (!url.SchemeIs("http") && !url.SchemeIs("https")) + if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme)) return false; // We need to search for URLs with a matching host/port. One way to query for diff --git a/chrome/browser/importer/firefox2_importer.cc b/chrome/browser/importer/firefox2_importer.cc index 2494bd1..77fd49f 100644 --- a/chrome/browser/importer/firefox2_importer.cc +++ b/chrome/browser/importer/firefox2_importer.cc @@ -15,6 +15,7 @@ #include "chrome/browser/search_engines/template_url_parser.h" #include "chrome/common/l10n_util.h" #include "chrome/common/time_format.h" +#include "chrome/common/url_constants.h" #include "grit/generated_resources.h" #include "net/base/data_url.h" @@ -527,7 +528,7 @@ void Firefox2Importer::DataURLToFaviconUsage( const GURL& favicon_data, std::vector<history::ImportedFavIconUsage>* favicons) { if (!link_url.is_valid() || !favicon_data.is_valid() || - !favicon_data.SchemeIs("data")) + !favicon_data.SchemeIs(chrome::kDataScheme)) return; // Parse the data URL. diff --git a/chrome/browser/importer/ie_importer.cc b/chrome/browser/importer/ie_importer.cc index 0d0e3e7..5d2dbff 100644 --- a/chrome/browser/importer/ie_importer.cc +++ b/chrome/browser/importer/ie_importer.cc @@ -22,6 +22,7 @@ #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/common/l10n_util.h" #include "chrome/common/time_format.h" +#include "chrome/common/url_constants.h" #include "chrome/common/win_util.h" #include "googleurl/src/gurl.h" #include "grit/generated_resources.h" @@ -194,8 +195,8 @@ void IEImporter::ImportPasswordsIE6() { continue; GURL url(ac_list[i].key.c_str()); - if (!(LowerCaseEqualsASCII(url.scheme(), "http") || - LowerCaseEqualsASCII(url.scheme(), "https"))) { + if (!(LowerCaseEqualsASCII(url.scheme(), chrome::kHttpScheme) || + LowerCaseEqualsASCII(url.scheme(), chrome::kHttpsScheme))) { continue; } @@ -272,7 +273,10 @@ void IEImporter::ImportPasswordsIE7() { // Reads history information from COM interface. void IEImporter::ImportHistory() { - const std::string kSchemes[] = {"http", "https", "ftp", "file"}; + const std::string kSchemes[] = {chrome::kHttpScheme, + chrome::kHttpsScheme, + chrome::kFtpScheme, + chrome::kFileScheme}; int total_schemes = arraysize(kSchemes); CComPtr<IUrlHistoryStg2> url_history_stg2; diff --git a/chrome/browser/net/url_fixer_upper.cc b/chrome/browser/net/url_fixer_upper.cc index ec908cd..121807b 100644 --- a/chrome/browser/net/url_fixer_upper.cc +++ b/chrome/browser/net/url_fixer_upper.cc @@ -10,6 +10,7 @@ #include "base/logging.h" #include "base/string_util.h" #include "chrome/common/gfx/text_elider.h" +#include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" #include "googleurl/src/url_canon.h" #include "googleurl/src/url_file.h" @@ -303,14 +304,16 @@ string URLFixerUpper::SegmentURL(const string& text, // When we couldn't find a scheme in the input, we need to pick one. Normally // we choose http, but if the URL starts with "ftp.", we match other browsers // and choose ftp. - if (!parts->scheme.is_valid()) - scheme.assign(StartsWithASCII(text, "ftp.", false) ? "ftp" : "http"); + if (!parts->scheme.is_valid()) { + scheme.assign(StartsWithASCII(text, "ftp.", false) ? + chrome::kFtpScheme : chrome::kHttpScheme); + } // Cannonicalize the scheme. StringToLowerASCII(&scheme); // Not segmenting file schemes or nonstandard schemes. - if ((scheme == "file") || + if ((scheme == chrome::kFileScheme) || !url_util::IsStandard(scheme.c_str(), static_cast<int>(scheme.length()), url_parse::Component(0, static_cast<int>(scheme.length())))) return scheme; diff --git a/chrome/browser/renderer_host/buffered_resource_handler.cc b/chrome/browser/renderer_host/buffered_resource_handler.cc index f70ac9e..6439a14 100644 --- a/chrome/browser/renderer_host/buffered_resource_handler.cc +++ b/chrome/browser/renderer_host/buffered_resource_handler.cc @@ -9,6 +9,7 @@ #include "net/base/mime_sniffer.h" #include "chrome/browser/renderer_host/download_throttling_resource_handler.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" +#include "chrome/common/url_constants.h" #include "net/base/mime_sniffer.h" #include "net/base/io_buffer.h" #include "net/http/http_response_headers.h" @@ -164,8 +165,8 @@ bool BufferedResourceHandler::ShouldBuffer(const GURL& url, const std::string& mime_type) { // We are willing to buffer for HTTP and HTTPS. bool sniffable_scheme = url.is_empty() || - url.SchemeIs("http") || - url.SchemeIs("https"); + url.SchemeIs(chrome::kHttpScheme) || + url.SchemeIs(chrome::kHttpsScheme); if (!sniffable_scheme) return false; diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 0af9211..5e644c2 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -28,6 +28,7 @@ #include "chrome/common/resource_bundle.h" #include "chrome/common/notification_service.h" #include "chrome/common/notification_type.h" +#include "chrome/common/url_constants.h" #include "chrome/common/thumbnail_score.h" #include "net/base/net_util.h" #include "skia/include/SkBitmap.h" @@ -41,10 +42,10 @@ void FilterURL(RendererSecurityPolicy* policy, int renderer_id, GURL* url) { if (!url->is_valid()) return; // We don't need to block invalid URLs. - if (url->SchemeIs("about")) { + if (url->SchemeIs(chrome::kAboutScheme)) { // The renderer treats all URLs in the about: scheme as being about:blank. // Canonicalize about: URLs to about:blank. - *url = GURL("about:blank"); + *url = GURL(chrome::kAboutBlankURL); } if (!policy->CanRequestURL(renderer_id, *url)) { diff --git a/chrome/browser/renderer_host/renderer_security_policy.cc b/chrome/browser/renderer_host/renderer_security_policy.cc index 71a71ec..e33b0d1 100644 --- a/chrome/browser/renderer_host/renderer_security_policy.cc +++ b/chrome/browser/renderer_host/renderer_security_policy.cc @@ -78,10 +78,10 @@ class RendererSecurityPolicy::SecurityState { RendererSecurityPolicy::RendererSecurityPolicy() { // We know about these schemes and believe them to be safe. - RegisterWebSafeScheme("http"); - RegisterWebSafeScheme("https"); - RegisterWebSafeScheme("ftp"); - RegisterWebSafeScheme("data"); + RegisterWebSafeScheme(chrome::kHttpScheme); + RegisterWebSafeScheme(chrome::kHttpsScheme); + RegisterWebSafeScheme(chrome::kFtpScheme); + RegisterWebSafeScheme(chrome::kDataScheme); RegisterWebSafeScheme("feed"); RegisterWebSafeScheme("chrome-extension"); @@ -156,7 +156,7 @@ void RendererSecurityPolicy::GrantRequestURL(int renderer_id, const GURL& url) { if (IsPseudoScheme(url.scheme())) { // The view-source scheme is a special case of a pseudo URL that eventually // results in requesting its embedded URL. - if (url.SchemeIs("view-source")) { + if (url.SchemeIs(chrome::kViewSourceScheme)) { // URLs with the view-source scheme typically look like: // view-source:http://www.google.com/a // In order to request these URLs, the renderer needs to be able to request @@ -199,7 +199,7 @@ void RendererSecurityPolicy::GrantInspectElement(int renderer_id) { // The inspector is served from a chrome-ui: URL. In order to run the // inspector, the renderer needs to be able to load chrome-ui URLs. - state->second->GrantScheme("chrome-ui"); + state->second->GrantScheme(chrome::kChromeUIScheme); } void RendererSecurityPolicy::GrantDOMUIBindings(int renderer_id) { @@ -212,10 +212,10 @@ void RendererSecurityPolicy::GrantDOMUIBindings(int renderer_id) { state->second->GrantDOMUIBindings(); // DOM UI bindings need the ability to request chrome-ui URLs. - state->second->GrantScheme("chrome-ui"); + state->second->GrantScheme(chrome::kChromeUIScheme); // DOM UI pages can contain links to file:// URLs. - state->second->GrantScheme("file"); + state->second->GrantScheme(chrome::kFileScheme); } bool RendererSecurityPolicy::CanRequestURL(int renderer_id, const GURL& url) { @@ -228,13 +228,13 @@ bool RendererSecurityPolicy::CanRequestURL(int renderer_id, const GURL& url) { if (IsPseudoScheme(url.scheme())) { // There are a number of special cases for pseudo schemes. - if (url.SchemeIs("view-source")) { + if (url.SchemeIs(chrome::kViewSourceScheme)) { // A view-source URL is allowed if the renderer is permitted to request // the embedded URL. return CanRequestURL(renderer_id, GURL(url.path())); } - if (LowerCaseEqualsASCII(url.spec(), "about:blank")) + if (LowerCaseEqualsASCII(url.spec(), chrome::kAboutBlankURL)) return true; // Every renderer can request <about:blank>. // URLs like <about:memory> and <about:crash> shouldn't be requestable by diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc index 04e55a7..04fb702 100644 --- a/chrome/browser/safe_browsing/safe_browsing_service.cc +++ b/chrome/browser/safe_browsing/safe_browsing_service.cc @@ -25,6 +25,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" +#include "chrome/common/url_constants.h" #include "net/base/registry_controlled_domain.h" using base::Time; @@ -170,7 +171,8 @@ void SafeBrowsingService::OnEnable(bool enabled) { } bool SafeBrowsingService::CanCheckUrl(const GURL& url) const { - return url.SchemeIs("http") || url.SchemeIs("https"); + return url.SchemeIs(chrome::kHttpScheme) || + url.SchemeIs(chrome::kHttpsScheme); } bool SafeBrowsingService::CheckUrl(const GURL& url, Client* client) { diff --git a/chrome/browser/search_engines/template_url_model.cc b/chrome/browser/search_engines/template_url_model.cc index c1a4415..316ad80 100644 --- a/chrome/browser/search_engines/template_url_model.cc +++ b/chrome/browser/search_engines/template_url_model.cc @@ -20,6 +20,7 @@ #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/common/stl_util-inl.h" +#include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" #include "googleurl/src/url_parse.h" #include "grit/locale_settings.h" @@ -159,7 +160,7 @@ std::wstring TemplateURLModel::GenerateKeyword(const GURL& url, // elements and update AutocompletePopup to look for keywords using the path. // See http://b/issue?id=863583. if (!url.is_valid() || - (autodetected && (url.has_query() || (url.scheme() != "http") || + (autodetected && (url.has_query() || !url.SchemeIs(chrome::kHttpScheme) || ((url.path() != "") && (url.path() != "/"))))) return std::wstring(); diff --git a/chrome/browser/search_engines/template_url_parser.cc b/chrome/browser/search_engines/template_url_parser.cc index c3d6c7e..0bec982 100644 --- a/chrome/browser/search_engines/template_url_parser.cc +++ b/chrome/browser/search_engines/template_url_parser.cc @@ -11,6 +11,7 @@ #include "base/scoped_ptr.h" #include "base/string_util.h" #include "chrome/browser/search_engines/template_url.h" +#include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" #include "libxml/parser.h" #include "libxml/xmlwriter.h" @@ -482,7 +483,7 @@ void EndElementImpl(void *ctx, const xmlChar *name) { break; case ParsingContext::IMAGE: { GURL image_url(WideToUTF8(context->GetString())); - if (image_url.SchemeIs("data")) { + if (image_url.SchemeIs(chrome::kDataScheme)) { // TODO (jcampan): bug 1169256: when dealing with data URL, we need to // decode the data URL in the renderer. For now, we'll just point to the // fav icon from the URL. @@ -523,7 +524,8 @@ bool IsHTTPRef(const TemplateURLRef* ref) { if (ref == NULL) return true; GURL url(WideToUTF8(ref->url())); - return (url.is_valid() && (url.SchemeIs("http") || url.SchemeIs("https"))); + return (url.is_valid() && (url.SchemeIs(chrome::kHttpScheme) || + url.SchemeIs(chrome::kHttpsScheme))); } // Returns true if the TemplateURL is legal. A legal TemplateURL is one @@ -536,7 +538,8 @@ bool IsLegal(TemplateURL* url) { for (size_t i = 0; i < image_refs.size(); i++) { GURL image_url(image_refs[i].url); if (!image_url.is_valid() || - !(image_url.SchemeIs("http") || image_url.SchemeIs("https"))) { + !(image_url.SchemeIs(chrome::kHttpScheme) || + image_url.SchemeIs(chrome::kHttpsScheme))) { return false; } } diff --git a/chrome/browser/ssl/ssl_policy.cc b/chrome/browser/ssl/ssl_policy.cc index 1648a48..4a0fdef 100644 --- a/chrome/browser/ssl/ssl_policy.cc +++ b/chrome/browser/ssl/ssl_policy.cc @@ -20,6 +20,7 @@ #include "chrome/common/resource_bundle.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/time_format.h" +#include "chrome/common/url_constants.h" #include "grit/browser_resources.h" #include "grit/generated_resources.h" #include "net/base/cert_status_flags.h" @@ -376,8 +377,9 @@ void SSLPolicy::OnRequestStarted(SSLManager* manager, const GURL& url, ResourceType::Type resource_type, int ssl_cert_id, int ssl_cert_status) { // These schemes never leave the browser and don't require a warning. - if (url.SchemeIs("data") || url.SchemeIs("javascript") || - url.SchemeIs("about")) + if (url.SchemeIs(chrome::kDataScheme) || + url.SchemeIs(chrome::kJavaScriptScheme) || + url.SchemeIs(chrome::kAboutScheme)) return; NavigationEntry* entry = manager->controller()->GetActiveEntry(); diff --git a/chrome/browser/tab_contents/render_view_context_menu_controller.cc b/chrome/browser/tab_contents/render_view_context_menu_controller.cc index fe2de71..714f24c 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_controller.cc +++ b/chrome/browser/tab_contents/render_view_context_menu_controller.cc @@ -78,7 +78,7 @@ void RenderViewContextMenuController::WriteTextToClipboard( } void RenderViewContextMenuController::WriteURLToClipboard(const GURL& url) { - if (url.SchemeIs("mailto")) + if (url.SchemeIs(chrome::kMailToScheme)) WriteTextToClipboard(UTF8ToWide(url.path())); else WriteTextToClipboard(UTF8ToWide(url.spec())); @@ -99,7 +99,7 @@ std::wstring RenderViewContextMenuController::GetLabel(int id) const { } case IDS_CONTENT_CONTEXT_COPYLINKLOCATION: - if (params_.link_url.SchemeIs("mailto")) + if (params_.link_url.SchemeIs(chrome::kMailToScheme)) return l10n_util::GetString(IDS_CONTENT_CONTEXT_COPYEMAILADDRESS); default: diff --git a/chrome/browser/tab_contents/site_instance.cc b/chrome/browser/tab_contents/site_instance.cc index 832d8db..a2a051f 100644 --- a/chrome/browser/tab_contents/site_instance.cc +++ b/chrome/browser/tab_contents/site_instance.cc @@ -5,6 +5,7 @@ #include "chrome/browser/tab_contents/site_instance.h" #include "chrome/browser/renderer_host/browser_render_process_host.h" +#include "chrome/common/url_constants.h" #include "net/base/registry_controlled_domain.h" SiteInstance::~SiteInstance() { @@ -124,7 +125,8 @@ bool SiteInstance::IsSameWebSite(const GURL& url1, const GURL& url2) { // We must treat javascript: URLs as part of the same site, regardless of // the site. - if (url1.SchemeIs("javascript") || url2.SchemeIs("javascript")) + if (url1.SchemeIs(chrome::kJavaScriptScheme) || + url2.SchemeIs(chrome::kJavaScriptScheme)) return true; // We treat about:crash, about:hang, and about:shorthang as the same site as diff --git a/chrome/browser/tab_contents/web_contents_view_win.cc b/chrome/browser/tab_contents/web_contents_view_win.cc index 52989e4..b88a899 100644 --- a/chrome/browser/tab_contents/web_contents_view_win.cc +++ b/chrome/browser/tab_contents/web_contents_view_win.cc @@ -23,6 +23,7 @@ #include "chrome/browser/views/sad_tab_view.h" #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/os_exchange_data.h" +#include "chrome/common/url_constants.h" #include "net/base/net_util.h" #include "webkit/glue/plugins/webplugin_delegate_impl.h" #include "webkit/glue/webdropdata.h" @@ -123,7 +124,7 @@ void WebContentsViewWin::StartDragging(const WebDropData& drop_data) { if (!drop_data.text_html.empty()) data->SetHtml(drop_data.text_html, drop_data.html_base_url); if (drop_data.url.is_valid()) { - if (drop_data.url.SchemeIs("javascript")) { + if (drop_data.url.SchemeIs(chrome::kJavaScriptScheme)) { // We don't want to allow javascript URLs to be dragged to the desktop, // but we do want to allow them to be added to the bookmarks bar // (bookmarklets). diff --git a/chrome/browser/tabs/tab_strip_model_unittest.cc b/chrome/browser/tabs/tab_strip_model_unittest.cc index f8c1ed2..48a16b4 100644 --- a/chrome/browser/tabs/tab_strip_model_unittest.cc +++ b/chrome/browser/tabs/tab_strip_model_unittest.cc @@ -16,6 +16,7 @@ #include "chrome/browser/tabs/tab_strip_model_order_controller.h" #include "chrome/common/pref_names.h" #include "chrome/common/stl_util-inl.h" +#include "chrome/common/url_constants.h" #include "testing/gtest/include/gtest/gtest.h" const TabContentsType kHTTPTabContentsType = @@ -82,7 +83,7 @@ class TabStripModelTestTabContentsFactory : public TabContentsFactory { } virtual bool CanHandleURL(const GURL& url) { - return url.scheme() == "http"; + return url.SchemeIs(chrome::kHttpScheme); } }; diff --git a/chrome/common/extensions/url_pattern.cc b/chrome/common/extensions/url_pattern.cc index ce345ca..7f705f2 100644 --- a/chrome/common/extensions/url_pattern.cc +++ b/chrome/common/extensions/url_pattern.cc @@ -2,21 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/common/extensions/url_pattern.h" + #include "base/string_piece.h" #include "base/string_util.h" -#include "chrome/common/extensions/url_pattern.h" +#include "chrome/common/url_constants.h" // TODO(aa): Consider adding chrome-extension? What about more obscure ones // like data: and javascript: ? static const char* kValidSchemes[] = { - "http", - "https", - "file", - "ftp", - "chrome-ui" + chrome::kHttpScheme, + chrome::kHttpsScheme, + chrome::kFileScheme, + chrome::kFtpScheme, + chrome::kChromeUIScheme, }; -static const char kSchemeSeparator[] = "://"; static const char kPathSeparator[] = "/"; static bool IsValidScheme(const std::string& scheme) { @@ -29,7 +30,7 @@ static bool IsValidScheme(const std::string& scheme) { } bool URLPattern::Parse(const std::string& pattern) { - size_t scheme_end_pos = pattern.find(kSchemeSeparator); + size_t scheme_end_pos = pattern.find(chrome::kStandardSchemeSeparator); if (scheme_end_pos == std::string::npos) return false; @@ -37,7 +38,8 @@ bool URLPattern::Parse(const std::string& pattern) { if (!IsValidScheme(scheme_)) return false; - size_t host_start_pos = scheme_end_pos + strlen(kSchemeSeparator); + size_t host_start_pos = scheme_end_pos + + strlen(chrome::kStandardSchemeSeparator); if (host_start_pos >= pattern.length()) return false; @@ -128,7 +130,7 @@ bool URLPattern::MatchesPath(const GURL& test) { } std::string URLPattern::GetAsString() const { - std::string spec = scheme_ + kSchemeSeparator; + std::string spec = scheme_ + chrome::kStandardSchemeSeparator; if (match_subdomains_) { spec += "*"; diff --git a/chrome/common/url_constants.cc b/chrome/common/url_constants.cc index cb96bf7..fad79f3 100644 --- a/chrome/common/url_constants.cc +++ b/chrome/common/url_constants.cc @@ -7,9 +7,21 @@ namespace chrome {
const char kAboutScheme[] = "about";
+const char kChromeInternalScheme[] = "chrome-internal";
const char kChromeUIScheme[] = "chrome-ui";
const char kDataScheme[] = "data";
+const char kExtensionScheme[] = "chrome-extension"; +const char kFileScheme[] = "file";
+const char kFtpScheme[] = "ftp";
+const char kHttpScheme[] = "http";
+const char kHttpsScheme[] = "https";
const char kJavaScriptScheme[] = "javascript";
+const char kMailToScheme[] = "mailto"; +const char kUserScriptScheme[] = "chrome-user-script"; const char kViewSourceScheme[] = "view-source";
+const char kStandardSchemeSeparator[] = "://";
+
+const char kAboutBlankURL[] = "about:blank";
+
} // namespace chrome
diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h index d738d22..1cbf97b 100644 --- a/chrome/common/url_constants.h +++ b/chrome/common/url_constants.h @@ -11,11 +11,25 @@ namespace chrome { // Canonical schemes you can use as input to GURL.SchemeIs().
extern const char kAboutScheme[];
-extern const char kChromeUIScheme[];
+extern const char kChromeInternalScheme[]; // Used for new tab page.
+extern const char kChromeUIScheme[]; // The scheme used for DOMUIContentses.
extern const char kDataScheme[];
+extern const char kExtensionScheme[]; +extern const char kFileScheme[];
+extern const char kFtpScheme[];
+extern const char kHttpScheme[];
+extern const char kHttpsScheme[];
extern const char kJavaScriptScheme[];
+extern const char kMailToScheme[];
+extern const char kUserScriptScheme[]; extern const char kViewSourceScheme[];
+// Used to separate a standard scheme and the hostname: "://".
+extern const char kStandardSchemeSeparator[];
+
+// About URLs (including schmes).
+extern const char kAboutBlankURL[];
+
} // namespace chrome
#endif // CHROME_COMMON_URL_CONSTANTS_H_
diff --git a/chrome/plugin/webplugin_proxy.cc b/chrome/plugin/webplugin_proxy.cc index 478300a..d029fa1 100644 --- a/chrome/plugin/webplugin_proxy.cc +++ b/chrome/plugin/webplugin_proxy.cc @@ -11,6 +11,7 @@ #include "base/waitable_event.h" #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/plugin_messages.h" +#include "chrome/common/url_constants.h" #include "chrome/common/win_util.h" #include "chrome/plugin/npobject_proxy.h" #include "chrome/plugin/npobject_util.h" @@ -272,8 +273,9 @@ void WebPluginProxy::HandleURLRequest(const char *method, if (delegate_->GetQuirks() & WebPluginDelegate::PLUGIN_QUIRK_BLOCK_NONSTANDARD_GETURL_REQUESTS) { GURL request_url(url); - if (!request_url.SchemeIs("http") && !request_url.SchemeIs("https") && - !request_url.SchemeIs("ftp")) { + if (!request_url.SchemeIs(chrome::kHttpScheme) && + !request_url.SchemeIs(chrome::kHttpsScheme) && + !request_url.SchemeIs(chrome::kFtpScheme)) { return; } } |