diff options
18 files changed, 107 insertions, 104 deletions
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index ca40867..6dbe1f6 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -6,6 +6,7 @@ #include "base/command_line.h" #include "chrome/app/breakpad_mac.h" +#include "chrome/browser/browser_about_handler.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browsing_data_remover.h" #include "chrome/browser/character_encoding.h" @@ -17,6 +18,7 @@ #include "chrome/browser/extensions/extension_info_map.h" #include "chrome/browser/extensions/extension_message_handler.h" #include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/extensions/extension_web_ui.h" #include "chrome/browser/google/google_util.h" #include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/notifications/desktop_notification_service_factory.h" @@ -45,6 +47,7 @@ #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" #include "chrome/common/url_constants.h" +#include "content/browser/browser_url_handler.h" #include "content/browser/browsing_instance.h" #include "content/browser/child_process_security_policy.h" #include "content/browser/debugger/devtools_handler.h" @@ -135,6 +138,23 @@ void InitRenderViewHostForExtensions(RenderViewHost* render_view_host) { } } +// Handles rewriting Web UI URLs. +static bool HandleWebUI(GURL* url, Profile* profile) { + if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(profile, *url)) + return false; + + // Special case the new tab page. In older versions of Chrome, the new tab + // page was hosted at chrome-internal:<blah>. This might be in people's saved + // sessions or bookmarks, so we say any URL with that scheme triggers the new + // tab page. + if (url->SchemeIs(chrome::kChromeInternalScheme)) { + // Rewrite it with the proper new tab URL. + *url = GURL(chrome::kChromeUINewTabURL); + } + + return true; +} + } // namespace namespace chrome { @@ -653,6 +673,41 @@ void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) { rvh->process()->profile()); } +void ChromeContentBrowserClient::BrowserURLHandlerCreated( + BrowserURLHandler* handler) { + // Add the default URL handlers. + handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride, + BrowserURLHandler::null_handler()); + handler->AddHandlerPair(BrowserURLHandler::null_handler(), + &ExtensionWebUI::HandleChromeURLOverrideReverse); + + // about: + handler->AddHandlerPair(&WillHandleBrowserAboutURL, + BrowserURLHandler::null_handler()); + // chrome: & friends. + handler->AddHandlerPair(&HandleWebUI, + BrowserURLHandler::null_handler()); +} + +void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { + Profile* profile = rvh->site_instance()->GetProcess()->profile(); + BrowsingDataRemover* remover = new BrowsingDataRemover(profile, + BrowsingDataRemover::EVERYTHING, + base::Time()); + remover->Remove(BrowsingDataRemover::REMOVE_CACHE); + // BrowsingDataRemover takes care of deleting itself when done. +} + +void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) { + Profile* profile = rvh->site_instance()->GetProcess()->profile(); + BrowsingDataRemover* remover = new BrowsingDataRemover(profile, + BrowsingDataRemover::EVERYTHING, + base::Time()); + int remove_mask = BrowsingDataRemover::REMOVE_COOKIES; + remover->Remove(remove_mask); + // BrowsingDataRemover takes care of deleting itself when done. +} + #if defined(OS_LINUX) int ChromeContentBrowserClient::GetCrashSignalFD( const std::string& process_type) { @@ -687,23 +742,4 @@ crypto::CryptoModuleBlockingPasswordDelegate* } #endif -void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { - Profile* profile = rvh->site_instance()->GetProcess()->profile(); - BrowsingDataRemover* remover = new BrowsingDataRemover(profile, - BrowsingDataRemover::EVERYTHING, - base::Time()); - remover->Remove(BrowsingDataRemover::REMOVE_CACHE); - // BrowsingDataRemover takes care of deleting itself when done. -} - -void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) { - Profile* profile = rvh->site_instance()->GetProcess()->profile(); - BrowsingDataRemover* remover = new BrowsingDataRemover(profile, - BrowsingDataRemover::EVERYTHING, - base::Time()); - int remove_mask = BrowsingDataRemover::REMOVE_COOKIES; - remover->Remove(remove_mask); - // BrowsingDataRemover takes care of deleting itself when done. -} - } // namespace chrome diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h index b181278..edc23d9 100644 --- a/chrome/browser/chrome_content_browser_client.h +++ b/chrome/browser/chrome_content_browser_client.h @@ -99,6 +99,9 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient { const std::string& key, const std::string& value) OVERRIDE; virtual void ClearInspectorSettings(RenderViewHost* rvh) OVERRIDE; + virtual void BrowserURLHandlerCreated(BrowserURLHandler* handler) OVERRIDE; + virtual void ClearCache(RenderViewHost* rvh); + virtual void ClearCookies(RenderViewHost* rvh); #if defined(OS_POSIX) && !defined(OS_MACOSX) // Can return an optional fd for crash handling, otherwise returns -1. @@ -109,9 +112,6 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient { crypto::CryptoModuleBlockingPasswordDelegate* GetCryptoPasswordDelegate( const GURL& url) OVERRIDE; #endif - - virtual void ClearCache(RenderViewHost* rvh); - virtual void ClearCookies(RenderViewHost* rvh); }; } // namespace chrome diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index cbf6b6a..d2b131a 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -29,7 +29,6 @@ #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_shutdown.h" -#include "chrome/browser/browser_url_handler.h" #include "chrome/browser/character_encoding.h" #include "chrome/browser/download/download_item.h" #include "chrome/browser/download/download_item_model.h" @@ -107,6 +106,7 @@ #include "chrome/common/profiling.h" #include "chrome/common/url_constants.h" #include "chrome/common/web_apps.h" +#include "content/browser/browser_url_handler.h" #include "content/browser/debugger/devtools_manager.h" #include "content/browser/debugger/devtools_toggle_action.h" #include "content/browser/debugger/devtools_window.h" diff --git a/chrome/browser/ui/browser_navigator.cc b/chrome/browser/ui/browser_navigator.cc index 6352440..6075d73 100644 --- a/chrome/browser/ui/browser_navigator.cc +++ b/chrome/browser/ui/browser_navigator.cc @@ -8,7 +8,6 @@ #include "base/command_line.h" #include "chrome/browser/browser_about_handler.h" -#include "chrome/browser/browser_url_handler.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_tab_helper.h" #include "chrome/browser/profiles/profile.h" @@ -24,6 +23,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/url_constants.h" +#include "content/browser/browser_url_handler.h" #include "content/browser/site_instance.h" #include "content/browser/tab_contents/tab_contents.h" diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 5c8c965..c991939 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -299,8 +299,6 @@ 'browser/browser_signin.h', 'browser/browser_trial.cc', 'browser/browser_trial.h', - 'browser/browser_url_handler.cc', - 'browser/browser_url_handler.h', 'browser/browser_util_win.cc', 'browser/browser_util_win.h', 'browser/browsing_data_appcache_helper.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 4520c72..342d803 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1300,7 +1300,6 @@ 'browser/browser_about_handler_unittest.cc', 'browser/browser_commands_unittest.cc', 'browser/browser_main_unittest.cc', - 'browser/browser_url_handler_unittest.cc', 'browser/browsing_data_appcache_helper_unittest.cc', 'browser/browsing_data_database_helper_unittest.cc', 'browser/browsing_data_file_system_helper_unittest.cc', @@ -1965,6 +1964,7 @@ 'tools/convert_dict/convert_dict_unittest.cc', '../content/browser/appcache/chrome_appcache_service_unittest.cc', '../content/browser/browser_thread_unittest.cc', + '../content/browser/browser_url_handler_unittest.cc', '../content/browser/child_process_security_policy_unittest.cc', '../content/browser/debugger/devtools_manager_unittest.cc', '../content/browser/debugger/devtools_remote_listen_socket_unittest.cc', diff --git a/content/browser/DEPS b/content/browser/DEPS index 4c5f007..28434b1 100644 --- a/content/browser/DEPS +++ b/content/browser/DEPS @@ -7,8 +7,6 @@ include_rules = [ # See https://sites.google.com/a/chromium.org/dev/developers/content-module # for more information. - "+chrome/browser/browser_url_handler.h", - # http://crbug.com/82782 "+chrome/browser/download/download_file_manager.h", "+chrome/browser/download/download_manager.h", diff --git a/chrome/browser/browser_url_handler.cc b/content/browser/browser_url_handler.cc index c766312..e6e76a0 100644 --- a/chrome/browser/browser_url_handler.cc +++ b/content/browser/browser_url_handler.cc @@ -2,15 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/browser_url_handler.h" +#include "content/browser/browser_url_handler.h" #include "base/string_util.h" -#include "chrome/browser/browser_about_handler.h" -#include "chrome/browser/extensions/extension_web_ui.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/webui/chrome_web_ui_factory.h" -#include "chrome/common/url_constants.h" +#include "content/browser/content_browser_client.h" #include "content/browser/webui/web_ui.h" +#include "content/common/url_constants.h" #include "googleurl/src/gurl.h" // Handles rewriting view-source URLs for what we'll actually load. @@ -60,23 +57,6 @@ static bool ReverseViewSource(GURL* url, Profile* profile) { return true; } -// Handles rewriting Web UI URLs. -static bool HandleWebUI(GURL* url, Profile* profile) { - if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(profile, *url)) - return false; - - // Special case the new tab page. In older versions of Chrome, the new tab - // page was hosted at chrome-internal:<blah>. This might be in people's saved - // sessions or bookmarks, so we say any URL with that scheme triggers the new - // tab page. - if (url->SchemeIs(chrome::kChromeInternalScheme)) { - // Rewrite it with the proper new tab URL. - *url = GURL(chrome::kChromeUINewTabURL); - } - - return true; -} - // static BrowserURLHandler* BrowserURLHandler::GetInstance() { return Singleton<BrowserURLHandler>::get(); @@ -95,6 +75,10 @@ BrowserURLHandler::URLHandler BrowserURLHandler::null_handler() { } BrowserURLHandler::BrowserURLHandler() { + content::GetContentClient()->browser()->BrowserURLHandlerCreated(this); + + // view-source: + AddHandlerPair(&HandleViewSource, &ReverseViewSource); } BrowserURLHandler::~BrowserURLHandler() { @@ -105,27 +89,8 @@ void BrowserURLHandler::AddHandlerPair(URLHandler handler, url_handlers_.push_back(HandlerPair(handler, reverse_handler)); } -void BrowserURLHandler::InitURLHandlers() { - if (!url_handlers_.empty()) - return; - - // Add the default URL handlers. - AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride, null_handler()); - AddHandlerPair(null_handler(), - &ExtensionWebUI::HandleChromeURLOverrideReverse); - - // about: - AddHandlerPair(&WillHandleBrowserAboutURL, null_handler()); - // chrome: & friends. - AddHandlerPair(&HandleWebUI, null_handler()); - // view-source: - AddHandlerPair(&HandleViewSource, &ReverseViewSource); -} - void BrowserURLHandler::RewriteURLIfNecessary(GURL* url, Profile* profile, bool* reverse_on_redirect) { - if (url_handlers_.empty()) - InitURLHandlers(); for (size_t i = 0; i < url_handlers_.size(); ++i) { URLHandler handler = *url_handlers_[i].first; if (handler && handler(url, profile)) { diff --git a/chrome/browser/browser_url_handler.h b/content/browser/browser_url_handler.h index 9dc2e46..dc86a72 100644 --- a/chrome/browser/browser_url_handler.h +++ b/content/browser/browser_url_handler.h @@ -9,8 +9,8 @@ // random web pages (because from the resource loader's perspective, these // URL schemes don't exist). -#ifndef CHROME_BROWSER_BROWSER_URL_HANDLER_H_ -#define CHROME_BROWSER_BROWSER_URL_HANDLER_H_ +#ifndef CONTENT_BROWSER_BROWSER_URL_HANDLER_H_ +#define CONTENT_BROWSER_BROWSER_URL_HANDLER_H_ #pragma once #include <vector> @@ -46,9 +46,11 @@ class BrowserURLHandler { bool ReverseURLRewrite(GURL* url, const GURL& original, Profile* profile); - // We initialize the list of url_handlers_ lazily the first time - // RewriteURLIfNecessary is called. - void InitURLHandlers(); + // Add the specified handler pair to the list of URL handlers. + void AddHandlerPair(URLHandler handler, URLHandler reverse_handler); + + // Returns the null handler for use with |AddHandlerPair()|. + static URLHandler null_handler(); private: // This object is a singleton: @@ -60,16 +62,10 @@ class BrowserURLHandler { typedef std::pair<URLHandler, URLHandler> HandlerPair; std::vector<HandlerPair> url_handlers_; - // Returns the null handler for use with |AddHandlerPair()|. - static URLHandler null_handler(); - - // Add the specified handler pair to the list of URL handlers. - void AddHandlerPair(URLHandler handler, URLHandler reverse_handler); - FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerTest, BasicRewriteAndReverse); FRIEND_TEST_ALL_PREFIXES(BrowserURLHandlerTest, NullHandlerReverse); DISALLOW_COPY_AND_ASSIGN(BrowserURLHandler); }; -#endif // CHROME_BROWSER_BROWSER_URL_HANDLER_H_ +#endif // CONTENT_BROWSER_BROWSER_URL_HANDLER_H_ diff --git a/chrome/browser/browser_url_handler_unittest.cc b/content/browser/browser_url_handler_unittest.cc index 59fbdbc..fec59e5 100644 --- a/chrome/browser/browser_url_handler_unittest.cc +++ b/content/browser/browser_url_handler_unittest.cc @@ -2,9 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/browser_url_handler.h" - #include "chrome/test/testing_profile.h" +#include "content/browser/browser_url_handler.h" #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/content/browser/content_browser_client.h b/content/browser/content_browser_client.h index 79c88bc..2086537 100644 --- a/content/browser/content_browser_client.h +++ b/content/browser/content_browser_client.h @@ -14,6 +14,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebNotificationPresenter.h" class BrowserRenderProcessHost; +class BrowserURLHandler; class CommandLine; class FilePath; class GURL; @@ -243,6 +244,16 @@ class ContentBrowserClient { // Clear the Inspector settings. virtual void ClearInspectorSettings(RenderViewHost* rvh) = 0; + // Notifies that BrowserURLHandler has been created, so that the embedder can + // optionally add their own handlers. + virtual void BrowserURLHandlerCreated(BrowserURLHandler* handler) = 0; + + // Clears browser cache. + virtual void ClearCache(RenderViewHost* rvh) = 0; + + // Clears browser cookies. + virtual void ClearCookies(RenderViewHost* rvh) = 0; + #if defined(OS_POSIX) && !defined(OS_MACOSX) // Can return an optional fd for crash handling, otherwise returns -1. virtual int GetCrashSignalFD(const std::string& process_type) = 0; @@ -255,12 +266,6 @@ class ContentBrowserClient { crypto::CryptoModuleBlockingPasswordDelegate* GetCryptoPasswordDelegate( const GURL& url) = 0; #endif - - // Clears browser cache. - virtual void ClearCache(RenderViewHost* rvh) = 0; - - // Clears browser cookies. - virtual void ClearCookies(RenderViewHost* rvh) = 0; }; } // namespace content diff --git a/content/browser/mock_content_browser_client.cc b/content/browser/mock_content_browser_client.cc index 7377840..0e5d242 100644 --- a/content/browser/mock_content_browser_client.cc +++ b/content/browser/mock_content_browser_client.cc @@ -196,6 +196,16 @@ void MockContentBrowserClient::UpdateInspectorSetting( void MockContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) { } +void MockContentBrowserClient::BrowserURLHandlerCreated( + BrowserURLHandler* handler) { +} + +void MockContentBrowserClient::ClearCache(RenderViewHost* rvh) { +} + +void MockContentBrowserClient::ClearCookies(RenderViewHost* rvh) { +} + #if defined(OS_POSIX) && !defined(OS_MACOSX) int MockContentBrowserClient::GetCrashSignalFD( const std::string& process_type) { @@ -210,10 +220,4 @@ crypto::CryptoModuleBlockingPasswordDelegate* } #endif -void MockContentBrowserClient::ClearCache(RenderViewHost* rvh) { -} - -void MockContentBrowserClient::ClearCookies(RenderViewHost* rvh) { -} - } // namespace content diff --git a/content/browser/mock_content_browser_client.h b/content/browser/mock_content_browser_client.h index 47ccfe1..a407bb7 100644 --- a/content/browser/mock_content_browser_client.h +++ b/content/browser/mock_content_browser_client.h @@ -99,6 +99,9 @@ class MockContentBrowserClient : public ContentBrowserClient { const std::string& key, const std::string& value) OVERRIDE; virtual void ClearInspectorSettings(RenderViewHost* rvh) OVERRIDE; + virtual void BrowserURLHandlerCreated(BrowserURLHandler* handler) OVERRIDE; + virtual void ClearCache(RenderViewHost* rvh); + virtual void ClearCookies(RenderViewHost* rvh); #if defined(OS_POSIX) && !defined(OS_MACOSX) virtual int GetCrashSignalFD(const std::string& process_type) OVERRIDE; @@ -109,9 +112,6 @@ class MockContentBrowserClient : public ContentBrowserClient { crypto::CryptoModuleBlockingPasswordDelegate* GetCryptoPasswordDelegate( const GURL& url) OVERRIDE; #endif - - virtual void ClearCache(RenderViewHost* rvh); - virtual void ClearCookies(RenderViewHost* rvh); }; } // namespace content diff --git a/content/browser/renderer_host/test_render_view_host.cc b/content/browser/renderer_host/test_render_view_host.cc index ab228d9..dcccb05 100644 --- a/content/browser/renderer_host/test_render_view_host.cc +++ b/content/browser/renderer_host/test_render_view_host.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/browser_url_handler.h" #include "chrome/test/testing_profile.h" +#include "content/browser/browser_url_handler.h" #include "content/browser/renderer_host/test_backing_store.h" #include "content/browser/renderer_host/test_render_view_host.h" #include "content/browser/site_instance.h" diff --git a/content/browser/tab_contents/navigation_controller.cc b/content/browser/tab_contents/navigation_controller.cc index 1e28654..2e0e8b6 100644 --- a/content/browser/tab_contents/navigation_controller.cc +++ b/content/browser/tab_contents/navigation_controller.cc @@ -9,8 +9,8 @@ #include "base/string_util.h" #include "base/time.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/browser_url_handler.h" #include "chrome/browser/profiles/profile.h" +#include "content/browser/browser_url_handler.h" #include "content/browser/child_process_security_policy.h" #include "content/browser/in_process_webkit/session_storage_namespace.h" #include "content/browser/site_instance.h" diff --git a/content/browser/tab_contents/render_view_host_manager_unittest.cc b/content/browser/tab_contents/render_view_host_manager_unittest.cc index 30e6605..a6a462d 100644 --- a/content/browser/tab_contents/render_view_host_manager_unittest.cc +++ b/content/browser/tab_contents/render_view_host_manager_unittest.cc @@ -2,10 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/browser_url_handler.h" #include "chrome/test/test_notification_tracker.h" #include "chrome/test/testing_profile.h" #include "content/browser/browser_thread.h" +#include "content/browser/browser_url_handler.h" #include "content/browser/renderer_host/test_render_view_host.h" #include "content/browser/site_instance.h" #include "content/browser/tab_contents/navigation_controller.h" diff --git a/content/browser/tab_contents/test_tab_contents.cc b/content/browser/tab_contents/test_tab_contents.cc index b9bc0cd..d9eef10 100644 --- a/content/browser/tab_contents/test_tab_contents.cc +++ b/content/browser/tab_contents/test_tab_contents.cc @@ -6,7 +6,7 @@ #include <utility> -#include "chrome/browser/browser_url_handler.h" +#include "content/browser/browser_url_handler.h" #include "content/browser/renderer_host/mock_render_process_host.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/renderer_host/test_render_view_host.h" diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 50414b5..44b82c3 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -57,6 +57,8 @@ 'browser/browser_message_filter.h', 'browser/browser_thread.cc', 'browser/browser_thread.h', + 'browser/browser_url_handler.cc', + 'browser/browser_url_handler.h', 'browser/browsing_instance.cc', 'browser/browsing_instance.h', 'browser/cancelable_request.cc', |