diff options
64 files changed, 1348 insertions, 995 deletions
diff --git a/android_webview/browser/aw_browser_context.cc b/android_webview/browser/aw_browser_context.cc index 983cd3e..85a1c14 100644 --- a/android_webview/browser/aw_browser_context.cc +++ b/android_webview/browser/aw_browser_context.cc @@ -76,9 +76,21 @@ void AwBrowserContext::AddVisitedURLs(const std::vector<GURL>& urls) { } net::URLRequestContextGetter* AwBrowserContext::CreateRequestContext( - content::ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { CHECK(url_request_context_getter_); - url_request_context_getter_->SetProtocolHandlers(protocol_handlers); + url_request_context_getter_->SetProtocolHandlers( + blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass()); return url_request_context_getter_.get(); } @@ -86,7 +98,16 @@ net::URLRequestContextGetter* AwBrowserContext::CreateRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory, - content::ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { CHECK(url_request_context_getter_); return url_request_context_getter_.get(); } diff --git a/android_webview/browser/aw_browser_context.h b/android_webview/browser/aw_browser_context.h index 254a247..c0916c9 100644 --- a/android_webview/browser/aw_browser_context.h +++ b/android_webview/browser/aw_browser_context.h @@ -15,7 +15,6 @@ #include "base/memory/scoped_ptr.h" #include "components/visitedlink/browser/visitedlink_delegate.h" #include "content/public/browser/browser_context.h" -#include "content/public/browser/content_browser_client.h" #include "content/public/browser/geolocation_permission_context.h" #include "net/url_request/url_request_job_factory.h" @@ -59,11 +58,29 @@ class AwBrowserContext : public content::BrowserContext, void AddVisitedURLs(const std::vector<GURL>& urls); net::URLRequestContextGetter* CreateRequestContext( - content::ProtocolHandlerMap* protocol_handlers); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler); net::URLRequestContextGetter* CreateRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory, - content::ProtocolHandlerMap* protocol_handlers); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler); AwQuotaManagerBridge* GetQuotaManagerBridge(); diff --git a/android_webview/browser/aw_content_browser_client.cc b/android_webview/browser/aw_content_browser_client.cc index 78d8e27..3d8185e 100644 --- a/android_webview/browser/aw_content_browser_client.cc +++ b/android_webview/browser/aw_content_browser_client.cc @@ -118,9 +118,21 @@ void AwContentBrowserClient::RenderProcessHostCreated( net::URLRequestContextGetter* AwContentBrowserClient::CreateRequestContext( content::BrowserContext* browser_context, - content::ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { DCHECK(browser_context_.get() == browser_context); - return browser_context_->CreateRequestContext(protocol_handlers); + return browser_context_->CreateRequestContext( + blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass()); } net::URLRequestContextGetter* @@ -128,10 +140,22 @@ AwContentBrowserClient::CreateRequestContextForStoragePartition( content::BrowserContext* browser_context, const base::FilePath& partition_path, bool in_memory, - content::ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { DCHECK(browser_context_.get() == browser_context); return browser_context_->CreateRequestContextForStoragePartition( - partition_path, in_memory, protocol_handlers); + partition_path, in_memory, blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass()); } std::string AwContentBrowserClient::GetCanonicalEncodingNameByAliasName( diff --git a/android_webview/browser/aw_content_browser_client.h b/android_webview/browser/aw_content_browser_client.h index 874caa7..3aa78ec 100644 --- a/android_webview/browser/aw_content_browser_client.h +++ b/android_webview/browser/aw_content_browser_client.h @@ -41,12 +41,30 @@ class AwContentBrowserClient : public content::ContentBrowserClient { content::RenderProcessHost* host) OVERRIDE; virtual net::URLRequestContextGetter* CreateRequestContext( content::BrowserContext* browser_context, - content::ProtocolHandlerMap* protocol_handlers) OVERRIDE; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) OVERRIDE; virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition( content::BrowserContext* browser_context, const base::FilePath& partition_path, bool in_memory, - content::ProtocolHandlerMap* protocol_handlers) OVERRIDE; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) OVERRIDE; virtual std::string GetCanonicalEncodingNameByAliasName( const std::string& alias_name) OVERRIDE; virtual void AppendExtraCommandLineSwitches(CommandLine* command_line, diff --git a/android_webview/browser/net/aw_url_request_context_getter.cc b/android_webview/browser/net/aw_url_request_context_getter.cc index 9e7b8b0..1b7177b 100644 --- a/android_webview/browser/net/aw_url_request_context_getter.cc +++ b/android_webview/browser/net/aw_url_request_context_getter.cc @@ -106,22 +106,23 @@ net::URLRequestContext* AwURLRequestContextGetter::GetURLRequestContext() { set_protocol = job_factory->SetProtocolHandler( chrome::kDataScheme, new net::DataProtocolHandler()); DCHECK(set_protocol); + DCHECK(blob_protocol_handler_); set_protocol = job_factory->SetProtocolHandler( - chrome::kBlobScheme, protocol_handlers_[chrome::kBlobScheme].release()); + chrome::kBlobScheme, blob_protocol_handler_.release()); DCHECK(set_protocol); + DCHECK(file_system_protocol_handler_); set_protocol = job_factory->SetProtocolHandler( - chrome::kFileSystemScheme, - protocol_handlers_[chrome::kFileSystemScheme].release()); + chrome::kFileSystemScheme, file_system_protocol_handler_.release()); DCHECK(set_protocol); + DCHECK(chrome_protocol_handler_); set_protocol = job_factory->SetProtocolHandler( - chrome::kChromeUIScheme, - protocol_handlers_[chrome::kChromeUIScheme].release()); + chrome::kChromeUIScheme, chrome_protocol_handler_.release()); DCHECK(set_protocol); + DCHECK(chrome_devtools_protocol_handler_); set_protocol = job_factory->SetProtocolHandler( chrome::kChromeDevToolsScheme, - protocol_handlers_[chrome::kChromeDevToolsScheme].release()); + chrome_devtools_protocol_handler_.release()); DCHECK(set_protocol); - protocol_handlers_.clear(); // Create a chain of URLRequestJobFactories. Keep |job_factory_| pointed // at the beginning of the chain. job_factory_ = CreateAndroidJobFactory(job_factory.Pass()); @@ -129,6 +130,9 @@ net::URLRequestContext* AwURLRequestContextGetter::GetURLRequestContext() { job_factory_.Pass(), scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>( new AwRequestInterceptor()))); + job_factory_.reset(new net::ProtocolInterceptJobFactory( + job_factory_.Pass(), + developer_protocol_handler_.Pass())); url_request_context_->set_job_factory(job_factory_.get()); } return url_request_context_.get(); @@ -140,8 +144,21 @@ AwURLRequestContextGetter::GetNetworkTaskRunner() const { } void AwURLRequestContextGetter::SetProtocolHandlers( - content::ProtocolHandlerMap* protocol_handlers) { - std::swap(protocol_handlers_, *protocol_handlers); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { + blob_protocol_handler_ = blob_protocol_handler.Pass(); + file_system_protocol_handler_ = file_system_protocol_handler.Pass(); + developer_protocol_handler_ = developer_protocol_handler.Pass(); + chrome_protocol_handler_ = chrome_protocol_handler.Pass(); + chrome_devtools_protocol_handler_ = chrome_devtools_protocol_handler.Pass(); } } // namespace android_webview diff --git a/android_webview/browser/net/aw_url_request_context_getter.h b/android_webview/browser/net/aw_url_request_context_getter.h index 418e921..cc2d81f 100644 --- a/android_webview/browser/net/aw_url_request_context_getter.h +++ b/android_webview/browser/net/aw_url_request_context_getter.h @@ -9,7 +9,6 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "content/public/browser/browser_thread_delegate.h" -#include "content/public/browser/content_browser_client.h" #include "net/http/http_network_session.h" #include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_job_factory.h" @@ -53,7 +52,17 @@ class AwURLRequestContextGetter : public net::URLRequestContextGetter, // AwBrowserContext::CreateRequestContext() call SetProtocolHandlers(). // SetProtocolHandlers() is necessary because the ProtocolHandlers are created // on the UI thread while |job_factory_| must be created on the IO thread. - void SetProtocolHandlers(content::ProtocolHandlerMap* protocol_handlers); + void SetProtocolHandlers( + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler); void PopulateNetworkSessionParams(net::HttpNetworkSession::Params* params); @@ -65,7 +74,15 @@ class AwURLRequestContextGetter : public net::URLRequestContextGetter, // ProtocolHandlers are stored here between SetProtocolHandlers() and the // first GetURLRequestContext() call. - content::ProtocolHandlerMap protocol_handlers_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> blob_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler_; DISALLOW_COPY_AND_ASSIGN(AwURLRequestContextGetter); }; diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index 1cafe99..3eba46e 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -176,8 +176,6 @@ BrowserProcessImpl::BrowserProcessImpl( extensions::kExtensionScheme); ChildProcessSecurityPolicy::GetInstance()->RegisterWebSafeScheme( chrome::kExtensionResourceScheme); - ChildProcessSecurityPolicy::GetInstance()->RegisterWebSafeScheme( - chrome::kChromeSearchScheme); #if defined(OS_MACOSX) InitIdleMonitor(); diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 190918f..1a47b40 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -763,20 +763,25 @@ bool ChromeContentBrowserClient::ShouldUseProcessPerSite( return true; } -// These are treated as WebUI schemes but do not get WebUI bindings. -std::vector<std::string> -ChromeContentBrowserClient::GetAdditionalWebUISchemes() { - std::vector<std::string> additional_schemes; - additional_schemes.push_back(chrome::kChromeSearchScheme); - return additional_schemes; -} - net::URLRequestContextGetter* ChromeContentBrowserClient::CreateRequestContext( content::BrowserContext* browser_context, - content::ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { Profile* profile = Profile::FromBrowserContext(browser_context); - return profile->CreateRequestContext(protocol_handlers); + return profile->CreateRequestContext(blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), + chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass()); } net::URLRequestContextGetter* @@ -784,10 +789,25 @@ ChromeContentBrowserClient::CreateRequestContextForStoragePartition( content::BrowserContext* browser_context, const base::FilePath& partition_path, bool in_memory, - content::ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { Profile* profile = Profile::FromBrowserContext(browser_context); return profile->CreateRequestContextForStoragePartition( - partition_path, in_memory, protocol_handlers); + partition_path, + in_memory, + blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), + chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass()); } bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) { diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h index c5559c7..5d6d70b 100644 --- a/chrome/browser/chrome_content_browser_client.h +++ b/chrome/browser/chrome_content_browser_client.h @@ -64,15 +64,32 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient { const GURL& effective_url) OVERRIDE; virtual GURL GetEffectiveURL(content::BrowserContext* browser_context, const GURL& url) OVERRIDE; - virtual std::vector<std::string> GetAdditionalWebUISchemes() OVERRIDE; virtual net::URLRequestContextGetter* CreateRequestContext( content::BrowserContext* browser_context, - content::ProtocolHandlerMap* protocol_handlers) OVERRIDE; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) OVERRIDE; virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition( content::BrowserContext* browser_context, const base::FilePath& partition_path, bool in_memory, - content::ProtocolHandlerMap* protocol_handlers) OVERRIDE; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) OVERRIDE; virtual bool IsHandledURL(const GURL& url) OVERRIDE; virtual bool IsSuitableHost(content::RenderProcessHost* process_host, const GURL& url) OVERRIDE; diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc index e04f5c2..893712e 100644 --- a/chrome/browser/instant/instant_browsertest.cc +++ b/chrome/browser/instant/instant_browsertest.cc @@ -16,24 +16,30 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/host_desktop.h" -#include "chrome/browser/ui/omnibox/omnibox_view.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "chrome/common/chrome_notification_types.h" #include "chrome/common/url_constants.h" -#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/interactive_test_utils.h" #include "chrome/test/base/ui_test_utils.h" +#include "content/public/browser/notification_service.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/web_contents.h" -#include "content/public/test/browser_test_utils.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" -class InstantTest : public InProcessBrowserTest, public InstantTestBase { +class InstantTest : public InstantTestBase { protected: virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { ASSERT_TRUE(test_server()->Start()); - GURL instant_url = test_server()->GetURL("files/instant.html?"); - InstantTestBase::Init(instant_url); + instant_url_ = test_server()->GetURL("files/instant.html?"); + } + + void FocusOmniboxAndWaitForInstantSupport() { + content::WindowedNotificationObserver observer( + chrome::NOTIFICATION_INSTANT_OVERLAY_SUPPORT_DETERMINED, + content::NotificationService::AllSources()); + FocusOmnibox(); + observer.Wait(); } bool UpdateSearchState(content::WebContents* contents) WARN_UNUSED_RESULT { @@ -60,7 +66,7 @@ class InstantTest : public InProcessBrowserTest, public InstantTestBase { // Test that Instant is preloaded when the omnibox is focused. IN_PROC_BROWSER_TEST_F(InstantTest, OmniboxFocusLoadsInstant) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); // Explicitly unfocus the omnibox. EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); @@ -115,12 +121,12 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OmniboxFocusLoadsInstant) { #endif // Test that the onchange event is dispatched upon typing in the omnibox. IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnChangeEvent) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); // Use the Instant page as the active tab, so we can exploit its visibility // handler to check visibility transitions. - ui_test_utils::NavigateToURL(browser(), instant_url()); + ui_test_utils::NavigateToURL(browser(), instant_url_); content::WebContents* active_tab = browser()->tab_strip_model()->GetActiveWebContents(); @@ -157,7 +163,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnChangeEvent) { // Test that the onsubmit event is dispatched upon pressing Enter. IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); SetOmniboxTextAndWaitForOverlayToShow("search"); @@ -199,7 +205,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { EXPECT_EQ(2, overlay->GetController().GetEntryCount()); // Check that the omnibox contains the Instant URL we loaded. - EXPECT_EQ(instant_url(), omnibox()->model()->PermanentURL()); + EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); // Check that the searchbox API values have been reset. std::string value; @@ -217,7 +223,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { // Test that the oncancel event is dispatched upon clicking on the overlay. IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); FocusOmniboxAndWaitForInstantSupport(); SetOmniboxTextAndWaitForOverlayToShow("search"); @@ -260,7 +266,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { EXPECT_EQ(2, overlay->GetController().GetEntryCount()); // Check that the omnibox contains the Instant URL we loaded. - EXPECT_EQ(instant_url(), omnibox()->model()->PermanentURL()); + EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); // Check that the searchbox API values have been reset. std::string value; @@ -278,7 +284,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { // Test that the onreisze event is dispatched upon typing in the omnibox. IN_PROC_BROWSER_TEST_F(InstantTest, OnResizeEvent) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); @@ -297,7 +303,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnResizeEvent) { // Test that the INSTANT_COMPLETE_NOW behavior works as expected. IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNow) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); // Tell the JS to request the given behavior. @@ -320,7 +326,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNow) { // Test that the INSTANT_COMPLETE_NEVER behavior works as expected. IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNever) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); // Tell the JS to request the given behavior. @@ -343,7 +349,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNever) { // Test that a valid suggestion is accepted. IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsValidObject) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); // Tell the JS to use the given suggestion. @@ -356,7 +362,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsValidObject) { // Test that an invalid suggestion is rejected. IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsInvalidObject) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); // Tell the JS to use an object in an invalid format. @@ -369,7 +375,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsInvalidObject) { // Test that various forms of empty suggestions are rejected. IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsEmpty) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); EXPECT_TRUE(ExecuteScript("suggestion = {}")); @@ -391,7 +397,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsEmpty) { // Test that Instant doesn't process URLs. IN_PROC_BROWSER_TEST_F(InstantTest, RejectsURLs) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); // Note that we are not actually navigating to these URLs yet. We are just @@ -417,7 +423,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, RejectsURLs) { // Test that Instant doesn't fire for intranet paths that look like searches. // http://crbug.com/99836 IN_PROC_BROWSER_TEST_F(InstantTest, IntranetPathLooksLikeSearch) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); // Navigate to a URL that looks like a search (when the scheme is stripped). // It's okay if the host is bogus or the navigation fails, since we only care @@ -432,7 +438,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, IntranetPathLooksLikeSearch) { // Test that transitions between searches and non-searches work as expected. IN_PROC_BROWSER_TEST_F(InstantTest, TransitionsBetweenSearchAndURL) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); // Type a search, and immediately a URL, without waiting for Instant to show. @@ -496,7 +502,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, TransitionsBetweenSearchAndURL) { // Test that Instant can't be fooled into committing a URL. IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsOne) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); // Type a URL. The Instant overlay shouldn't be showing. @@ -532,7 +538,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsOne) { // Test that Instant can't be fooled into committing a URL. IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsTwo) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); // Type a query. This causes the overlay to be shown. @@ -566,23 +572,22 @@ IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsTwo) { // Test that a non-Instant search provider shows no overlays. IN_PROC_BROWSER_TEST_F(InstantTest, NonInstantSearchProvider) { - GURL instant_url = test_server()->GetURL("files/empty.html"); - InstantTestBase::Init(instant_url); - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + instant_url_ = test_server()->GetURL("files/empty.html"); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); // Focus the omnibox. When the support determination response comes back, // Instant will destroy the non-Instant page, and attempt to recreate it. // We can know this happened by looking at the blacklist. - EXPECT_EQ(0, instant()->blacklisted_urls_[instant_url.spec()]); + EXPECT_EQ(0, instant()->blacklisted_urls_[instant_url_.spec()]); FocusOmniboxAndWaitForInstantSupport(); - EXPECT_EQ(1, instant()->blacklisted_urls_[instant_url.spec()]); + EXPECT_EQ(1, instant()->blacklisted_urls_[instant_url_.spec()]); } // Test that the renderer doesn't crash if JavaScript is blocked. IN_PROC_BROWSER_TEST_F(InstantTest, NoCrashOnBlockedJS) { browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); // Wait for notification that the Instant API has been determined. As long as // we get the notification we're good (the renderer didn't crash). @@ -591,7 +596,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, NoCrashOnBlockedJS) { // Test that the overlay and active tab's visibility states are set correctly. IN_PROC_BROWSER_TEST_F(InstantTest, PageVisibility) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); content::WebContents* active_tab = @@ -639,7 +644,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, TaskManagerPrefix) { EXPECT_FALSE(StartsWith(title, prefix, true)) << title << " vs " << prefix; } - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmnibox(); // Now there should be two renderers, the second being the Instant overlay. @@ -675,7 +680,7 @@ void KeywordQueryDone(base::RunLoop* run_loop, // Test that the Instant page load is not added to history. IN_PROC_BROWSER_TEST_F(InstantTest, History) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( @@ -708,7 +713,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, History) { // The Instant URL should not be in history. base::RunLoop run_loop2; - history->QueryURL(instant_url(), false, &consumer, + history->QueryURL(instant_url_, false, &consumer, base::Bind(&HistoryQueryDone, &run_loop2, &found)); run_loop2.Run(); EXPECT_FALSE(found); @@ -733,7 +738,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, History) { #endif // Test that creating a new window hides any currently showing Instant overlay. IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_NewWindowDismissesInstant) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); FocusOmniboxAndWaitForInstantSupport(); SetOmniboxTextAndWaitForOverlayToShow("search"); @@ -760,7 +765,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_NewWindowDismissesInstant) { // - The overlay is not showing. // - The omnibox doesn't have focus. IN_PROC_BROWSER_TEST_F(InstantTest, InstantOverlayRefresh) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); // The overlay is refreshed only after all three conditions above are met. @@ -790,7 +795,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, InstantOverlayRefresh) { // Test that suggestions are case insensitive. http://crbug.com/150728 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreCaseInsensitive) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'INSTANT' } ]")); @@ -852,12 +857,12 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreCaseInsensitive) { #endif // Test that the overlay can be committed onto a new tab. IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_CommitInNewTab) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); // Use the Instant page as the active tab, so we can exploit its visibility // handler to check visibility transitions. - ui_test_utils::NavigateToURL(browser(), instant_url()); + ui_test_utils::NavigateToURL(browser(), instant_url_); content::WebContents* active_tab = browser()->tab_strip_model()->GetActiveWebContents(); @@ -882,7 +887,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_CommitInNewTab) { // The state of the active tab before the commit. EXPECT_NE(overlay, active_tab); EXPECT_EQ(2, active_tab->GetController().GetEntryCount()); - EXPECT_EQ(instant_url(), omnibox()->model()->PermanentURL()); + EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); active_tab_onvisibilitycalls = -1; EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls", &active_tab_onvisibilitycalls)); @@ -907,7 +912,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_CommitInNewTab) { EXPECT_EQ(1, overlay->GetController().GetEntryCount()); // Check that the omnibox contains the Instant URL we loaded. - EXPECT_EQ(instant_url(), omnibox()->model()->PermanentURL()); + EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); // Check that the searchbox API values have been reset. std::string value; @@ -931,7 +936,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_CommitInNewTab) { // Test that suggestions are reusable. IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreReusable) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'instant' } ];" @@ -952,7 +957,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreReusable) { // Test that the Instant overlay is recreated if it gets destroyed. IN_PROC_BROWSER_TEST_F(InstantTest, InstantRenderViewGone) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); // Type partial query, get suggestion to show. @@ -975,7 +980,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, ProcessIsolation) { EXPECT_EQ(0, instant_service->GetInstantProcessCount()); // Setup Instant. - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); // Now there should be a registered Instant render process. diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index 21d43e1..4387e2c 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -900,12 +900,10 @@ void InstantController::InstantPageRenderViewCreated( omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); overlay_->SetOmniboxBounds(omnibox_bounds_); overlay_->InitializeFonts(); - overlay_->GrantChromeSearchAccessFromOrigin(GURL(overlay_->instant_url())); } else if (IsContentsFrom(ntp(), contents)) { ntp_->SetDisplayInstantResults(instant_enabled_); ntp_->SetOmniboxBounds(omnibox_bounds_); ntp_->InitializeFonts(); - ntp_->GrantChromeSearchAccessFromOrigin(GURL(ntp_->instant_url())); } else { NOTREACHED(); } @@ -1236,7 +1234,6 @@ void InstantController::ResetInstantTab() { instant_tab_->SetDisplayInstantResults(instant_enabled_); instant_tab_->SetOmniboxBounds(omnibox_bounds_); instant_tab_->InitializeFonts(); - instant_tab_->GrantChromeSearchAccessFromOrigin(active_tab->GetURL()); StartListeningToMostVisitedChanges(); instant_tab_->KeyCaptureChanged( omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); diff --git a/chrome/browser/instant/instant_extended_browsertest.cc b/chrome/browser/instant/instant_extended_browsertest.cc index 54f6fd8..4068cc0 100644 --- a/chrome/browser/instant/instant_extended_browsertest.cc +++ b/chrome/browser/instant/instant_extended_browsertest.cc @@ -5,11 +5,7 @@ #include <sstream> #include "base/prefs/pref_service.h" -#include "chrome/browser/extensions/extension_browsertest.h" -#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/favicon/favicon_tab_helper.h" -#include "chrome/browser/history/history_types.h" -#include "chrome/browser/history/top_sites.h" #include "chrome/browser/instant/instant_commit_type.h" #include "chrome/browser/instant/instant_ntp.h" #include "chrome/browser/instant/instant_overlay.h" @@ -18,45 +14,21 @@ #include "chrome/browser/instant/instant_tab.h" #include "chrome/browser/instant/instant_test_utils.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/themes/theme_service.h" -#include "chrome/browser/themes/theme_service_factory.h" -#include "chrome/browser/ui/omnibox/omnibox_view.h" #include "chrome/browser/ui/search/search.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" -#include "chrome/browser/ui/webui/theme_source.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/pref_names.h" -#include "chrome/common/thumbnail_score.h" #include "chrome/common/url_constants.h" -#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/interactive_test_utils.h" #include "chrome/test/base/ui_test_utils.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/render_process_host.h" -#include "content/public/browser/render_view_host.h" #include "content/public/browser/site_instance.h" -#include "content/public/browser/url_data_source.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" -#include "content/public/common/bindings_policy.h" #include "content/public/test/browser_test_utils.h" -#include "third_party/skia/include/core/SkBitmap.h" -namespace { - -// Creates a bitmap of the specified color. Caller takes ownership. -gfx::Image CreateBitmap(SkColor color) { - SkBitmap thumbnail; - thumbnail.setConfig(SkBitmap::kARGB_8888_Config, 4, 4); - thumbnail.allocPixels(); - thumbnail.eraseColor(color); - return gfx::Image::CreateFrom1xBitmap(thumbnail); // adds ref. -} - -} // namespace - -class InstantExtendedTest : public InProcessBrowserTest, - public InstantTestBase { +class InstantExtendedTest : public InstantTestBase { public: InstantExtendedTest() : on_most_visited_change_calls_(0), @@ -66,10 +38,21 @@ class InstantExtendedTest : public InProcessBrowserTest, protected: virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { chrome::search::EnableInstantExtendedAPIForTesting(); - ASSERT_TRUE(https_test_server().Start()); - GURL instant_url = https_test_server().GetURL( - "files/instant_extended.html?strk=1&"); - InstantTestBase::Init(instant_url); + ASSERT_TRUE(https_test_server_.Start()); + instant_url_ = https_test_server_. + GetURL("files/instant_extended.html?strk=1&"); + } + + void FocusOmniboxAndWaitForInstantSupport() { + content::WindowedNotificationObserver ntp_observer( + chrome::NOTIFICATION_INSTANT_NTP_SUPPORT_DETERMINED, + content::NotificationService::AllSources()); + content::WindowedNotificationObserver overlay_observer( + chrome::NOTIFICATION_INSTANT_OVERLAY_SUPPORT_DETERMINED, + content::NotificationService::AllSources()); + FocusOmnibox(); + ntp_observer.Wait(); + overlay_observer.Wait(); } std::string GetOmniboxText() { @@ -108,51 +91,14 @@ class InstantExtendedTest : public InProcessBrowserTest, int first_most_visited_item_id_; }; -// Test class used to verify chrome-search: scheme and access policy from the -// Instant overlay. This is a subclass of |ExtensionBrowserTest| because it -// loads a theme that provides a background image. -class InstantPolicyTest : public ExtensionBrowserTest, public InstantTestBase { - public: - InstantPolicyTest() {} - - protected: - virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { - chrome::search::EnableInstantExtendedAPIForTesting(); - ASSERT_TRUE(https_test_server().Start()); - GURL instant_url = https_test_server().GetURL( - "files/instant_extended.html?strk=1&"); - InstantTestBase::Init(instant_url); - } - - void InstallThemeSource() { - ThemeSource* theme = new ThemeSource(profile()); - content::URLDataSource::Add(profile(), theme); - } - - void InstallThemeAndVerify(const std::string& theme_dir, - const std::string& theme_name) { - const base::FilePath theme_path = test_data_dir_.AppendASCII(theme_dir); - ASSERT_TRUE(InstallExtensionWithUIAutoConfirm( - theme_path, 1, ExtensionBrowserTest::browser())); - const extensions::Extension* theme = - ThemeServiceFactory::GetThemeForProfile( - ExtensionBrowserTest::browser()->profile()); - ASSERT_NE(static_cast<extensions::Extension*>(NULL), theme); - ASSERT_EQ(theme->name(), theme_name); - } - - private: - DISALLOW_COPY_AND_ASSIGN(InstantPolicyTest); -}; - IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); EXPECT_TRUE(instant()->extended_enabled_); } // Test that Instant is preloaded when the omnibox is focused. IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); // Explicitly unfocus the omnibox. EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); @@ -166,7 +112,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) { EXPECT_FALSE(instant()->GetOverlayContents()); // Refocus the omnibox. The InstantController should've preloaded Instant. - FocusOmniboxAndWaitForInstantExtendedSupport(); + FocusOmniboxAndWaitForInstantSupport(); EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); EXPECT_TRUE(omnibox()->model()->has_focus()); @@ -194,10 +140,10 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) { } IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputShowsOverlay) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); // Focus omnibox and confirm overlay isn't shown. - FocusOmniboxAndWaitForInstantExtendedSupport(); + FocusOmniboxAndWaitForInstantSupport(); content::WebContents* overlay = instant()->GetOverlayContents(); EXPECT_TRUE(overlay); EXPECT_FALSE(instant()->IsOverlayingSearchResults()); @@ -212,8 +158,8 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputShowsOverlay) { // Test that middle clicking on a suggestion opens the result in a new tab. IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MiddleClickOnSuggestionOpensInNewTab) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); + FocusOmniboxAndWaitForInstantSupport(); EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); EXPECT_EQ(1, browser()->tab_strip_model()->count()); @@ -243,16 +189,17 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, // Check that the new tab URL is as expected. content::WebContents* new_tab_contents = browser()->tab_strip_model()->GetWebContentsAt(1); - EXPECT_EQ(new_tab_contents->GetURL().spec(), instant_url().spec()+"q=santa"); + EXPECT_EQ(new_tab_contents->GetURL().spec(), instant_url_.spec()+"q=santa"); // Check that there are now two tabs. EXPECT_EQ(2, browser()->tab_strip_model()->count()); } // Test that omnibox text is correctly set when overlay is committed with Enter. -IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxTextUponEnterCommit) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); +IN_PROC_BROWSER_TEST_F(InstantExtendedTest, + OmniboxTextUponEnterCommit) { + ASSERT_NO_FATAL_FAILURE(SetupInstant()); + FocusOmniboxAndWaitForInstantSupport(); // The page will autocomplete once we set the omnibox value. EXPECT_TRUE(ExecuteScript("suggestion = 'santa claus';")); @@ -275,9 +222,10 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxTextUponEnterCommit) { } // Test that omnibox text is correctly set when committed with focus lost. -IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxTextUponFocusLostCommit) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); +IN_PROC_BROWSER_TEST_F(InstantExtendedTest, + OmniboxTextUponFocusLostCommit) { + ASSERT_NO_FATAL_FAILURE(SetupInstant()); + FocusOmniboxAndWaitForInstantSupport(); // Set autocomplete text (grey text). EXPECT_TRUE(ExecuteScript("suggestion = 'johnny depp';")); @@ -303,8 +251,8 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxTextUponFocusLostCommit) { IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxTextUponFocusedCommittedSERP) { // Setup Instant. - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); + FocusOmniboxAndWaitForInstantSupport(); // Do a search and commit it. SetOmniboxTextAndWaitForOverlayToShow("hello k"); @@ -331,8 +279,8 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, // This test simulates a search provider using the InstantExtended API to // navigate through the suggested results and back to the original user query. IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsWithArrowKeys) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); + FocusOmniboxAndWaitForInstantSupport(); SetOmniboxTextAndWaitForOverlayToShow("hello"); EXPECT_EQ("hello", GetOmniboxText()); @@ -369,8 +317,8 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsWithArrowKeys) { // navigate through the suggested results and hitting escape to get back to the // original user query. IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsAndHitEscape) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); + FocusOmniboxAndWaitForInstantSupport(); SetOmniboxTextAndWaitForOverlayToShow("hello"); EXPECT_EQ("hello", GetOmniboxText()); @@ -401,8 +349,8 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsAndHitEscape) { IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NTPIsPreloaded) { // Setup Instant. - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); + FocusOmniboxAndWaitForInstantSupport(); // NTP contents should be preloaded. ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); @@ -412,8 +360,8 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NTPIsPreloaded) { IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInNewTab) { // Setup Instant. - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); + FocusOmniboxAndWaitForInstantSupport(); // NTP contents should be preloaded. ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); @@ -434,8 +382,8 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInNewTab) { IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInSameTab) { // Setup Instant. - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); + FocusOmniboxAndWaitForInstantSupport(); // NTP contents should be preloaded. ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); @@ -456,8 +404,8 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInSameTab) { IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxHasFocusOnNewTab) { // Setup Instant. - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); + FocusOmniboxAndWaitForInstantSupport(); // Explicitly unfocus the omnibox. EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); @@ -477,8 +425,8 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxHasFocusOnNewTab) { IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxEmptyOnNewTabPage) { // Setup Instant. - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); + FocusOmniboxAndWaitForInstantSupport(); // Open new tab. Preloaded NTP contents should have been used. ui_test_utils::NavigateToURLWithDisposition( @@ -491,11 +439,10 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxEmptyOnNewTabPage) { EXPECT_TRUE(omnibox()->GetText().empty()); } -// TODO(dhollowa): Fix flakes. http://crbug.com/179930. -IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_NoFaviconOnNewTabPage) { +IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoFaviconOnNewTabPage) { // Setup Instant. - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); + FocusOmniboxAndWaitForInstantSupport(); // Open new tab. Preloaded NTP contents should have been used. ui_test_utils::NavigateToURLWithDisposition( @@ -519,10 +466,10 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_NoFaviconOnNewTabPage) { } IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputOnNTPDoesntShowOverlay) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); // Focus omnibox and confirm overlay isn't shown. - FocusOmniboxAndWaitForInstantExtendedSupport(); + FocusOmniboxAndWaitForInstantSupport(); content::WebContents* overlay = instant()->GetOverlayContents(); EXPECT_TRUE(overlay); EXPECT_FALSE(instant()->IsOverlayingSearchResults()); @@ -552,8 +499,8 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ProcessIsolation) { EXPECT_EQ(1, instant_service->GetInstantProcessCount()); // Setup Instant. - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); + FocusOmniboxAndWaitForInstantSupport(); // The registered Instant render process should still exist. EXPECT_EQ(1, instant_service->GetInstantProcessCount()); @@ -589,8 +536,8 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ProcessIsolation) { // Flaky: http://crbug.com/177516 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_UnrelatedSiteInstance) { // Setup Instant. - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); + FocusOmniboxAndWaitForInstantSupport(); // Check that the uncommited ntp page and uncommited overlay have unrelated // site instances. @@ -634,8 +581,8 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_UnrelatedSiteInstance) { // Tests that suggestions are sanity checked. IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ValidatesSuggestions) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); + FocusOmniboxAndWaitForInstantSupport(); // Do not set gray text that is not a suffix of the query. EXPECT_TRUE(ExecuteScript("behavior = 2")); @@ -687,14 +634,13 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ValidatesSuggestions) { EXPECT_EQ(ASCIIToUTF16("www.example.com/"), omnibox()->GetText()); } -// TODO(dhollowa): Fix flakes. http://crbug.com/179930. -IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_MostVisited) { +IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MostVisited) { content::WindowedNotificationObserver observer( chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, content::NotificationService::AllSources()); // Initialize Instant. - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); + FocusOmniboxAndWaitForInstantSupport(); // Get a handle to the NTP and the current state of the JS. ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); @@ -778,120 +724,6 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_MostVisited) { EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count); } -IN_PROC_BROWSER_TEST_F(InstantPolicyTest, ThemeBackgroundAccess) { - InstallThemeSource(); - ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme")); - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); - - // The "Instant" New Tab should have access to chrome-search: scheme but not - // chrome: scheme. - ui_test_utils::NavigateToURLWithDisposition( - browser(), - GURL(chrome::kChromeUINewTabURL), - NEW_FOREGROUND_TAB, - ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); - - content::RenderViewHost* rvh = - browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); - - const std::string chrome_url("chrome://theme/IDR_THEME_NTP_BACKGROUND"); - const std::string search_url( - "chrome-search://theme/IDR_THEME_NTP_BACKGROUND"); - bool loaded = false; - ASSERT_TRUE(LoadImage(rvh, chrome_url, &loaded)); - EXPECT_FALSE(loaded) << chrome_url; - ASSERT_TRUE(LoadImage(rvh, search_url, &loaded)); - EXPECT_TRUE(loaded) << search_url; -} - -// TODO(dhollowa): Fix flakes. http://crbug.com/179930. -IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_FaviconAccess) { - // Create a favicon. - history::TopSites* top_sites = browser()->profile()->GetTopSites(); - GURL url("http://www.google.com/foo.html"); - gfx::Image thumbnail(CreateBitmap(SK_ColorWHITE)); - ThumbnailScore high_score(0.0, true, true, base::Time::Now()); - EXPECT_TRUE(top_sites->SetPageThumbnail(url, thumbnail, high_score)); - - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); - - // The "Instant" New Tab should have access to chrome-search: scheme but not - // chrome: scheme. - ui_test_utils::NavigateToURLWithDisposition( - browser(), - GURL(chrome::kChromeUINewTabURL), - NEW_FOREGROUND_TAB, - ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); - - content::RenderViewHost* rvh = - browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); - - // Get the favicons. - const std::string chrome_favicon_url( - "chrome://favicon/largest/http://www.google.com/foo.html"); - const std::string search_favicon_url( - "chrome-search://favicon/largest/http://www.google.com/foo.html"); - bool loaded = false; - ASSERT_TRUE(LoadImage(rvh, chrome_favicon_url, &loaded)); - EXPECT_FALSE(loaded) << chrome_favicon_url; - ASSERT_TRUE(LoadImage(rvh, search_favicon_url, &loaded)); - EXPECT_TRUE(loaded) << search_favicon_url; -} - -// WebUIBindings should never be enabled on ANY Instant web contents. -IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoWebUIBindingsOnNTP) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); - - ui_test_utils::NavigateToURLWithDisposition( - browser(), - GURL(chrome::kChromeUINewTabURL), - NEW_FOREGROUND_TAB, - ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); - const content::WebContents* tab = - browser()->tab_strip_model()->GetActiveWebContents(); - - // Instant-provided NTP should not have any bindings enabled. - EXPECT_EQ(0, tab->GetRenderViewHost()->GetEnabledBindings()); -} - -// WebUIBindings should never be enabled on ANY Instant web contents. -IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoWebUIBindingsOnPreview) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); - - // Typing in the omnibox shows the overlay. - SetOmniboxTextAndWaitForOverlayToShow("query"); - EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); - content::WebContents* preview = instant()->GetOverlayContents(); - ASSERT_NE(static_cast<content::WebContents*>(NULL), preview); - - // Instant preview should not have any bindings enabled. - EXPECT_EQ(0, preview->GetRenderViewHost()->GetEnabledBindings()); -} - -// WebUIBindings should never be enabled on ANY Instant web contents. -IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoWebUIBindingsOnResults) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); - FocusOmniboxAndWaitForInstantExtendedSupport(); - - // Typing in the omnibox shows the overlay. - SetOmniboxTextAndWaitForOverlayToShow("query"); - content::WebContents* preview = instant()->GetOverlayContents(); - EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); - // Commit the search by pressing Enter. - browser()->window()->GetLocationBar()->AcceptInput(); - EXPECT_TRUE(instant()->model()->mode().is_default()); - const content::WebContents* tab = - browser()->tab_strip_model()->GetActiveWebContents(); - EXPECT_EQ(preview, tab); - - // The commited Instant page should not have any bindings enabled. - EXPECT_EQ(0, tab->GetRenderViewHost()->GetEnabledBindings()); -} - // Only implemented in Views and Mac currently: http://crbug.com/164723 #if defined(OS_WIN) || defined(OS_CHROMEOS) || defined(OS_MACOSX) #define MAYBE_HomeButtonAffectsMargin HomeButtonAffectsMargin @@ -901,7 +733,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoWebUIBindingsOnResults) { // Check that toggling the state of the home button changes the start-edge // margin and width. IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_HomeButtonAffectsMargin) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); // Get the current value of the start-edge margin and width. int start_margin; @@ -938,10 +770,10 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_HomeButtonAffectsMargin) { // shown at 100% height. IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_CommitWhenFocusLostInFullHeight) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); // Focus omnibox and confirm overlay isn't shown. - FocusOmniboxAndWaitForInstantExtendedSupport(); + FocusOmniboxAndWaitForInstantSupport(); content::WebContents* overlay = instant()->GetOverlayContents(); EXPECT_TRUE(overlay); EXPECT_TRUE(instant()->model()->mode().is_default()); @@ -968,10 +800,10 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, // in the omnibox. IN_PROC_BROWSER_TEST_F(InstantExtendedTest, CommitWhenShownInFullHeightWithoutFocus) { - ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); + ASSERT_NO_FATAL_FAILURE(SetupInstant()); // Focus omnibox and confirm overlay isn't shown. - FocusOmniboxAndWaitForInstantExtendedSupport(); + FocusOmniboxAndWaitForInstantSupport(); content::WebContents* overlay = instant()->GetOverlayContents(); EXPECT_TRUE(overlay); EXPECT_TRUE(instant()->model()->mode().is_default()); diff --git a/chrome/browser/instant/instant_io_context.cc b/chrome/browser/instant/instant_io_context.cc deleted file mode 100644 index 5de12f1..0000000 --- a/chrome/browser/instant/instant_io_context.cc +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/instant/instant_io_context.h" - -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/resource_context.h" -#include "content/public/browser/resource_request_info.h" -#include "net/url_request/url_request.h" - -using content::BrowserThread; - -namespace { - -const char kInstantIOContextKeyName[] = "instant_io_context"; - -// Retrieves the Instant data from the |context|'s named user-data. -InstantIOContext* GetDataForResourceContext( - content::ResourceContext* context) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - if (!context->GetUserData(kInstantIOContextKeyName)) - context->SetUserData(kInstantIOContextKeyName, new InstantIOContext()); - return static_cast<InstantIOContext*>( - context->GetUserData(kInstantIOContextKeyName)); -} - -} // namespace - -InstantIOContext::InstantIOContext() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); -} - -InstantIOContext::~InstantIOContext() { -} - -// static -void InstantIOContext::AddInstantProcessOnIO( - content::ResourceContext* context, int process_id) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - GetDataForResourceContext(context)->process_ids_.insert(process_id); -} - -// static -void InstantIOContext::RemoveInstantProcessOnIO( - content::ResourceContext* context, int process_id) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - GetDataForResourceContext(context)->process_ids_.erase(process_id); -} - -// static -void InstantIOContext::ClearInstantProcessesOnIO( - content::ResourceContext* context) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - GetDataForResourceContext(context)->process_ids_.clear(); -} - -// static -bool InstantIOContext::ShouldServiceRequest(const net::URLRequest* request) { - const content::ResourceRequestInfo* info = - content::ResourceRequestInfo::ForRequest(request); - if (!info) - return false; - - int process_id = -1; - int render_view_id = -1; - if (info->GetAssociatedRenderView(&process_id, &render_view_id) && - GetDataForResourceContext(info->GetContext())->IsInstantProcess( - process_id)) - return true; - return false; -} - -bool InstantIOContext::IsInstantProcess(int process_id) const { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - return process_ids_.count(process_id) != 0; -} diff --git a/chrome/browser/instant/instant_io_context.h b/chrome/browser/instant/instant_io_context.h deleted file mode 100644 index bf6388d..0000000 --- a/chrome/browser/instant/instant_io_context.h +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_INSTANT_INSTANT_IO_CONTEXT_ -#define CHROME_BROWSER_INSTANT_INSTANT_IO_CONTEXT_ - -#include <set> - -#include "base/basictypes.h" -#include "base/supports_user_data.h" - -namespace content { -class ResourceContext; -} - -namespace net { -class URLRequest; -} - -// IO thread data held for Instant. This reflects the data held in -// InstantService for use on the IO thread. Owned by ResourceContext -// as user data. -class InstantIOContext : public base::SupportsUserData::Data { - public: - InstantIOContext(); - virtual ~InstantIOContext(); - - // Add and remove RenderProcessHost IDs that are associated with Instant - // processes. Used to keep process IDs in sync with InstantService. - static void AddInstantProcessOnIO(content::ResourceContext* context, - int process_id); - static void RemoveInstantProcessOnIO(content::ResourceContext* context, - int process_id); - static void ClearInstantProcessesOnIO(content::ResourceContext* context); - - // Determine if this chrome-search: request is coming from an Instant render - // process. - static bool ShouldServiceRequest(const net::URLRequest* request); - - private: - // Check that |process_id| is in the known set of Instant processes, ie. - // |process_ids_|. - bool IsInstantProcess(int process_id) const; - - // The process IDs associated with Instant processes. Mirror of the process - // IDs in InstantService. Duplicated here for synchronous access on the IO - // thread. - std::set<int> process_ids_; - - DISALLOW_COPY_AND_ASSIGN(InstantIOContext); -}; - -#endif // CHROME_BROWSER_INSTANT_INSTANT_IO_CONTEXT_ diff --git a/chrome/browser/instant/instant_page.cc b/chrome/browser/instant/instant_page.cc index 899da53a..ba79353 100644 --- a/chrome/browser/instant/instant_page.cc +++ b/chrome/browser/instant/instant_page.cc @@ -56,12 +56,6 @@ void InstantPage::InitializeFonts() { routing_id(), omnibox_font_name, omnibox_font_size)); } -void InstantPage::GrantChromeSearchAccessFromOrigin(const GURL& origin_url) { - DCHECK(origin_url.is_valid()); - Send(new ChromeViewMsg_SearchBoxGrantChromeSearchAccessFromOrigin( - routing_id(), origin_url)); -} - void InstantPage::DetermineIfPageSupportsInstant() { Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id())); } diff --git a/chrome/browser/instant/instant_page.h b/chrome/browser/instant/instant_page.h index c438252..1260beb1 100644 --- a/chrome/browser/instant/instant_page.h +++ b/chrome/browser/instant/instant_page.h @@ -138,9 +138,6 @@ class InstantPage : public content::WebContentsObserver { // Tells the page about the font information. void InitializeFonts(); - // Grant renderer-side chrome-search: access rights for select origins. - void GrantChromeSearchAccessFromOrigin(const GURL& origin_url); - // Tells the renderer to determine if the page supports the Instant API, which // results in a call to InstantSupportDetermined() when the reply is received. void DetermineIfPageSupportsInstant(); diff --git a/chrome/browser/instant/instant_service.cc b/chrome/browser/instant/instant_service.cc index 7fa8422..1f6de61 100644 --- a/chrome/browser/instant/instant_service.cc +++ b/chrome/browser/instant/instant_service.cc @@ -4,27 +4,14 @@ #include "chrome/browser/instant/instant_service.h" -#include "chrome/browser/instant/instant_io_context.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/webui/ntp/thumbnail_source.h" -#include "chrome/common/chrome_notification_types.h" -#include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" #include "content/public/browser/render_process_host.h" -#include "content/public/browser/url_data_source.h" -using content::BrowserThread; - -InstantService::InstantService(Profile* profile) - : profile_(profile) { +InstantService::InstantService() { registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, content::NotificationService::AllSources()); - // Stub for unit tests. - if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) - return; - content::URLDataSource::Add(profile, new ThumbnailSource(profile)); } InstantService::~InstantService() { @@ -32,13 +19,6 @@ InstantService::~InstantService() { void InstantService::AddInstantProcess(int process_id) { process_ids_.insert(process_id); - - if (profile_ && profile_->GetResourceContext()) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&InstantIOContext::AddInstantProcessOnIO, - profile_->GetResourceContext(), process_id)); - } } bool InstantService::IsInstantProcess(int process_id) const { @@ -52,14 +32,6 @@ void InstantService::Shutdown() { void InstantService::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { - DCHECK_EQ(type, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED); int process_id = content::Source<content::RenderProcessHost>(source)->GetID(); process_ids_.erase(process_id); - - if (profile_ && profile_->GetResourceContext()) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&InstantIOContext::RemoveInstantProcessOnIO, - profile_->GetResourceContext(), process_id)); - } } diff --git a/chrome/browser/instant/instant_service.h b/chrome/browser/instant/instant_service.h index 3920102..9bf8f5d64 100644 --- a/chrome/browser/instant/instant_service.h +++ b/chrome/browser/instant/instant_service.h @@ -13,13 +13,11 @@ #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" -class Profile; - // Tracks render process host IDs that are associated with Instant. class InstantService : public ProfileKeyedService, public content::NotificationObserver { public: - explicit InstantService(Profile* profile); + InstantService(); virtual ~InstantService(); // Add, remove, and query RenderProcessHost IDs that are associated with @@ -42,8 +40,6 @@ class InstantService : public ProfileKeyedService, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; - Profile* const profile_; - // The process ids associated with Instant processes. std::set<int> process_ids_; diff --git a/chrome/browser/instant/instant_service_factory.cc b/chrome/browser/instant/instant_service_factory.cc index 0edac14..f24cdf5 100644 --- a/chrome/browser/instant/instant_service_factory.cc +++ b/chrome/browser/instant/instant_service_factory.cc @@ -33,5 +33,5 @@ bool InstantServiceFactory::ServiceRedirectedInIncognito() const { ProfileKeyedService* InstantServiceFactory::BuildServiceInstanceFor( Profile* profile) const { - return new InstantService(profile); + return new InstantService; } diff --git a/chrome/browser/instant/instant_test_utils.cc b/chrome/browser/instant/instant_test_utils.cc index 01de31c..242db0b 100644 --- a/chrome/browser/instant/instant_test_utils.cc +++ b/chrome/browser/instant/instant_test_utils.cc @@ -9,13 +9,9 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" -#include "chrome/browser/ui/omnibox/omnibox_view.h" -#include "chrome/common/chrome_notification_types.h" -#include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/interactive_test_utils.h" #include "chrome/test/base/ui_test_utils.h" -#include "content/public/browser/notification_service.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/web_contents.h" #include "content/public/common/result_codes.h" @@ -55,10 +51,9 @@ void InstantTestModelObserver::OverlayStateChanged( // InstantTestBase ----------------------------------------------------------- -void InstantTestBase::SetupInstant(Browser* browser) { - browser_ = browser; +void InstantTestBase::SetupInstant() { TemplateURLService* service = - TemplateURLServiceFactory::GetForProfile(browser_->profile()); + TemplateURLServiceFactory::GetForProfile(browser()->profile()); ui_test_utils::WaitForTemplateURLServiceToLoad(service); TemplateURLData data; @@ -69,21 +64,17 @@ void InstantTestBase::SetupInstant(Browser* browser) { data.alternate_urls.push_back(instant_url_.spec() + "#q={searchTerms}"); data.search_terms_replacement_key = "strk"; - TemplateURL* template_url = new TemplateURL(browser_->profile(), data); + TemplateURL* template_url = new TemplateURL(browser()->profile(), data); service->Add(template_url); // Takes ownership of |template_url|. service->SetDefaultSearchProvider(template_url); - browser_->profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, true); + browser()->profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, true); // TODO(shishir): Fix this ugly hack. instant()->SetInstantEnabled(false, true); instant()->SetInstantEnabled(true, false); } -void InstantTestBase::Init(const GURL& instant_url) { - instant_url_ = instant_url; -} - void InstantTestBase::KillInstantRenderView() { base::KillProcess( instant()->GetOverlayContents()->GetRenderProcessHost()->GetHandle(), @@ -97,30 +88,10 @@ void InstantTestBase::FocusOmnibox() { instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_VISIBLE, OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL); } else { - browser_->window()->GetLocationBar()->FocusLocation(false); + browser()->window()->GetLocationBar()->FocusLocation(false); } } -void InstantTestBase::FocusOmniboxAndWaitForInstantSupport() { - content::WindowedNotificationObserver observer( - chrome::NOTIFICATION_INSTANT_OVERLAY_SUPPORT_DETERMINED, - content::NotificationService::AllSources()); - FocusOmnibox(); - observer.Wait(); -} - -void InstantTestBase::FocusOmniboxAndWaitForInstantExtendedSupport() { - content::WindowedNotificationObserver ntp_observer( - chrome::NOTIFICATION_INSTANT_NTP_SUPPORT_DETERMINED, - content::NotificationService::AllSources()); - content::WindowedNotificationObserver overlay_observer( - chrome::NOTIFICATION_INSTANT_OVERLAY_SUPPORT_DETERMINED, - content::NotificationService::AllSources()); - FocusOmnibox(); - ntp_observer.Wait(); - overlay_observer.Wait(); -} - void InstantTestBase::SetOmniboxText(const std::string& text) { FocusOmnibox(); omnibox()->SetUserText(UTF8ToUTF16(text)); @@ -175,14 +146,3 @@ bool InstantTestBase::HasUserInputInProgress() { bool InstantTestBase::HasTemporaryText() { return omnibox()->model()->has_temporary_text_; } - -bool InstantTestBase::LoadImage(content::RenderViewHost* rvh, - const std::string& image, - bool* loaded) { - std::string js_chrome = - "var img = document.createElement('img');" - "img.onerror = function() { domAutomationController.send(false); };" - "img.onload = function() { domAutomationController.send(true); };" - "img.src = '" + image + "';"; - return content::ExecuteScriptAndExtractBool(rvh, js_chrome, loaded); -} diff --git a/chrome/browser/instant/instant_test_utils.h b/chrome/browser/instant/instant_test_utils.h index e09d276..60738b7 100644 --- a/chrome/browser/instant/instant_test_utils.h +++ b/chrome/browser/instant/instant_test_utils.h @@ -7,8 +7,6 @@ #include <string> -#include "base/basictypes.h" -#include "base/compiler_specific.h" #include "base/run_loop.h" #include "chrome/browser/instant/instant_controller.h" #include "chrome/browser/instant/instant_overlay_model_observer.h" @@ -16,17 +14,9 @@ #include "chrome/browser/ui/browser_instant_controller.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/omnibox/location_bar.h" +#include "chrome/browser/ui/omnibox/omnibox_view.h" #include "chrome/common/search_types.h" -#include "googleurl/src/gurl.h" -#include "net/test/test_server.h" - -class InstantController; -class InstantModel; -class OmniboxView; - -namespace content { -class WebContents; -}; +#include "chrome/test/base/in_process_browser_test.h" class InstantTestModelObserver : public InstantOverlayModelObserver { public: @@ -47,39 +37,30 @@ class InstantTestModelObserver : public InstantOverlayModelObserver { DISALLOW_COPY_AND_ASSIGN(InstantTestModelObserver); }; -// This utility class is meant to be used in a "mix-in" fashion, giving the -// derived test class additional Instant-related functionality. -class InstantTestBase { - protected: +class InstantTestBase : public InProcessBrowserTest { + public: InstantTestBase() : https_test_server_( net::TestServer::TYPE_HTTPS, net::BaseTestServer::SSLOptions(), base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))) { } - virtual ~InstantTestBase() {} protected: - void SetupInstant(Browser* browser); - void Init(const GURL& instant_url); + void SetupInstant(); InstantController* instant() { - return browser_->instant_controller()->instant(); + return browser()->instant_controller()->instant(); } OmniboxView* omnibox() { - return browser_->window()->GetLocationBar()->GetLocationEntry(); + return browser()->window()->GetLocationBar()->GetLocationEntry(); } - const GURL& instant_url() const { return instant_url_; } - - net::TestServer& https_test_server() { return https_test_server_; } - void KillInstantRenderView(); void FocusOmnibox(); void FocusOmniboxAndWaitForInstantSupport(); - void FocusOmniboxAndWaitForInstantExtendedSupport(); void SetOmniboxText(const std::string& text); void SetOmniboxTextAndWaitForOverlayToShow(const std::string& text); @@ -99,22 +80,10 @@ class InstantTestBase { bool HasUserInputInProgress(); bool HasTemporaryText(); - // Loads a named image from url |image| from the given |rvh| host. |loaded| - // returns whether the image was able to load without error. - // The method returns true if the JavaScript executed cleanly. - bool LoadImage(content::RenderViewHost* rvh, - const std::string& image, - bool* loaded); - - private: GURL instant_url_; - Browser* browser_; - // HTTPS Testing server, started on demand. net::TestServer https_test_server_; - - DISALLOW_COPY_AND_ASSIGN(InstantTestBase); }; #endif // CHROME_BROWSER_INSTANT_INSTANT_TEST_UTILS_H_ diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index f033aec..91d9375 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -42,19 +42,44 @@ class FactoryForMain : public ChromeURLRequestContextFactory { public: FactoryForMain( const ProfileIOData* profile_io_data, - content::ProtocolHandlerMap* protocol_handlers) - : profile_io_data_(profile_io_data) { - std::swap(protocol_handlers_, *protocol_handlers); - } + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) + : profile_io_data_(profile_io_data), + blob_protocol_handler_(blob_protocol_handler.Pass()), + file_system_protocol_handler_(file_system_protocol_handler.Pass()), + developer_protocol_handler_(developer_protocol_handler.Pass()), + chrome_protocol_handler_(chrome_protocol_handler.Pass()), + chrome_devtools_protocol_handler_( + chrome_devtools_protocol_handler.Pass()) {} virtual ChromeURLRequestContext* Create() OVERRIDE { - profile_io_data_->Init(&protocol_handlers_); + profile_io_data_->Init(blob_protocol_handler_.Pass(), + file_system_protocol_handler_.Pass(), + developer_protocol_handler_.Pass(), + chrome_protocol_handler_.Pass(), + chrome_devtools_protocol_handler_.Pass()); return profile_io_data_->GetMainRequestContext(); } private: const ProfileIOData* const profile_io_data_; - content::ProtocolHandlerMap protocol_handlers_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> blob_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler_; }; // Factory that creates the ChromeURLRequestContext for extensions. @@ -80,13 +105,26 @@ class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { ChromeURLRequestContextGetter* main_context, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers) + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) : profile_io_data_(profile_io_data), partition_descriptor_(partition_descriptor), main_request_context_getter_(main_context), - protocol_handler_interceptor_(protocol_handler_interceptor.Pass()) { - std::swap(protocol_handlers_, *protocol_handlers); - } + protocol_handler_interceptor_(protocol_handler_interceptor.Pass()), + blob_protocol_handler_(blob_protocol_handler.Pass()), + file_system_protocol_handler_(file_system_protocol_handler.Pass()), + developer_protocol_handler_(developer_protocol_handler.Pass()), + chrome_protocol_handler_(chrome_protocol_handler.Pass()), + chrome_devtools_protocol_handler_( + chrome_devtools_protocol_handler.Pass()) {} virtual ChromeURLRequestContext* Create() OVERRIDE { // We will copy most of the state from the main request context. @@ -96,9 +134,10 @@ class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { // state onwards. return profile_io_data_->GetIsolatedAppRequestContext( main_request_context_getter_->GetURLRequestContext(), - partition_descriptor_, - protocol_handler_interceptor_.Pass(), - &protocol_handlers_); + partition_descriptor_, protocol_handler_interceptor_.Pass(), + blob_protocol_handler_.Pass(), file_system_protocol_handler_.Pass(), + developer_protocol_handler_.Pass(), chrome_protocol_handler_.Pass(), + chrome_devtools_protocol_handler_.Pass()); } private: @@ -108,7 +147,16 @@ class FactoryForIsolatedApp : public ChromeURLRequestContextFactory { main_request_context_getter_; scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor_; - content::ProtocolHandlerMap protocol_handlers_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler_; }; // Factory that creates the media ChromeURLRequestContext for a given isolated @@ -196,10 +244,24 @@ ChromeURLRequestContextGetter::GetNetworkTaskRunner() const { ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::CreateOriginal( Profile* profile, const ProfileIOData* profile_io_data, - content::ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { DCHECK(!profile->IsOffTheRecord()); return new ChromeURLRequestContextGetter( - new FactoryForMain(profile_io_data, protocol_handlers)); + new FactoryForMain(profile_io_data, + blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), + chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass())); } // static @@ -228,15 +290,25 @@ ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( const StoragePartitionDescriptor& partition_descriptor, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { DCHECK(!profile->IsOffTheRecord()); ChromeURLRequestContextGetter* main_context = static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); return new ChromeURLRequestContextGetter( new FactoryForIsolatedApp(profile_io_data, partition_descriptor, - main_context, - protocol_handler_interceptor.Pass(), - protocol_handlers)); + main_context, protocol_handler_interceptor.Pass(), + blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass())); } // static @@ -257,10 +329,24 @@ ChromeURLRequestContextGetter* ChromeURLRequestContextGetter::CreateOffTheRecord( Profile* profile, const ProfileIOData* profile_io_data, - content::ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { DCHECK(profile->IsOffTheRecord()); return new ChromeURLRequestContextGetter( - new FactoryForMain(profile_io_data, protocol_handlers)); + new FactoryForMain(profile_io_data, + blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), + chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass())); } // static @@ -280,15 +366,25 @@ ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( const StoragePartitionDescriptor& partition_descriptor, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { DCHECK(profile->IsOffTheRecord()); ChromeURLRequestContextGetter* main_context = static_cast<ChromeURLRequestContextGetter*>(profile->GetRequestContext()); return new ChromeURLRequestContextGetter( new FactoryForIsolatedApp(profile_io_data, partition_descriptor, - main_context, - protocol_handler_interceptor.Pass(), - protocol_handlers)); + main_context, protocol_handler_interceptor.Pass(), + blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass())); } // ---------------------------------------------------------------------------- diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index db09992..88fcc50 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -92,7 +92,16 @@ class ChromeURLRequestContextGetter : public net::URLRequestContextGetter { static ChromeURLRequestContextGetter* CreateOriginal( Profile* profile, const ProfileIOData* profile_io_data, - content::ProtocolHandlerMap* protocol_handlers); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler); // Create an instance for an original profile for media. This is expected to // get called on UI thread. This method takes a profile and reuses the @@ -113,7 +122,16 @@ class ChromeURLRequestContextGetter : public net::URLRequestContextGetter { const StoragePartitionDescriptor& partition_descriptor, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler); // Create an instance for an original profile for media with isolated // storage. This is expected to get called on UI thread. @@ -128,7 +146,16 @@ class ChromeURLRequestContextGetter : public net::URLRequestContextGetter { static ChromeURLRequestContextGetter* CreateOffTheRecord( Profile* profile, const ProfileIOData* profile_io_data, - content::ProtocolHandlerMap* protocol_handlers); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler); // Create an instance for an OTR profile for extensions. This is expected // to get called on UI thread. @@ -143,7 +170,16 @@ class ChromeURLRequestContextGetter : public net::URLRequestContextGetter { const StoragePartitionDescriptor& partition_descriptor, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler); private: virtual ~ChromeURLRequestContextGetter(); diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc index 7ff079c..81062f47d 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.cc +++ b/chrome/browser/profiles/off_the_record_profile_impl.cc @@ -261,8 +261,19 @@ net::URLRequestContextGetter* OffTheRecordProfileImpl::GetRequestContext() { } net::URLRequestContextGetter* OffTheRecordProfileImpl::CreateRequestContext( - content::ProtocolHandlerMap* protocol_handlers) { - return io_data_.CreateMainRequestContextGetter(protocol_handlers); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { + return io_data_.CreateMainRequestContextGetter(blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), developer_protocol_handler.Pass(), + chrome_protocol_handler.Pass(), chrome_devtools_protocol_handler.Pass()); } net::URLRequestContextGetter* @@ -302,9 +313,20 @@ net::URLRequestContextGetter* OffTheRecordProfileImpl::CreateRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory, - content::ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { return io_data_.CreateIsolatedAppRequestContextGetter( - partition_path, in_memory, protocol_handlers); + partition_path, in_memory, blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), developer_protocol_handler.Pass(), + chrome_protocol_handler.Pass(), chrome_devtools_protocol_handler.Pass()); } content::ResourceContext* OffTheRecordProfileImpl::GetResourceContext() { diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h index 4b7759e..c26b3d3 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.h +++ b/chrome/browser/profiles/off_the_record_profile_impl.h @@ -11,7 +11,6 @@ #include "chrome/browser/profiles/off_the_record_profile_io_data.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser_list.h" -#include "content/public/browser/content_browser_client.h" #include "content/public/browser/host_zoom_map.h" using base::Time; @@ -51,11 +50,29 @@ class OffTheRecordProfileImpl : public Profile { virtual net::URLRequestContextGetter* GetRequestContextForExtensions() OVERRIDE; virtual net::URLRequestContextGetter* CreateRequestContext( - content::ProtocolHandlerMap* protocol_handlers) OVERRIDE; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) OVERRIDE; virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory, - content::ProtocolHandlerMap* protocol_handlers) OVERRIDE; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) OVERRIDE; virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE; virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE; virtual ProtocolHandlerRegistry* GetProtocolHandlerRegistry() OVERRIDE; diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.cc b/chrome/browser/profiles/off_the_record_profile_io_data.cc index 411de3a..dfe2a8b 100644 --- a/chrome/browser/profiles/off_the_record_profile_io_data.cc +++ b/chrome/browser/profiles/off_the_record_profile_io_data.cc @@ -70,7 +70,16 @@ OffTheRecordProfileIOData::Handle::GetResourceContextNoInit() const { scoped_refptr<ChromeURLRequestContextGetter> OffTheRecordProfileIOData::Handle::CreateMainRequestContextGetter( - content::ProtocolHandlerMap* protocol_handlers) const { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const { // TODO(oshima): Re-enable when ChromeOS only accesses the profile on the UI // thread. #if !defined(OS_CHROMEOS) @@ -80,7 +89,10 @@ OffTheRecordProfileIOData::Handle::CreateMainRequestContextGetter( DCHECK(!main_request_context_getter_); main_request_context_getter_ = ChromeURLRequestContextGetter::CreateOffTheRecord( - profile_, io_data_, protocol_handlers); + profile_, io_data_, blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass()); return main_request_context_getter_; } @@ -116,7 +128,16 @@ scoped_refptr<ChromeURLRequestContextGetter> OffTheRecordProfileIOData::Handle::CreateIsolatedAppRequestContextGetter( const base::FilePath& partition_path, bool in_memory, - content::ProtocolHandlerMap* protocol_handlers) const { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(!partition_path.empty()); LazyInitialize(); @@ -132,7 +153,9 @@ OffTheRecordProfileIOData::Handle::CreateIsolatedAppRequestContextGetter( ChromeURLRequestContextGetter* context = ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( profile_, io_data_, descriptor, protocol_handler_interceptor.Pass(), - protocol_handlers); + blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass()); app_request_context_getter_map_[descriptor] = context; return context; @@ -162,7 +185,16 @@ OffTheRecordProfileIOData::~OffTheRecordProfileIOData() { void OffTheRecordProfileIOData::InitializeInternal( ProfileParams* profile_params, - content::ProtocolHandlerMap* protocol_handlers) const { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const { ChromeURLRequestContext* main_context = main_request_context(); IOThread* const io_thread = profile_params->io_thread; @@ -222,13 +254,27 @@ void OffTheRecordProfileIOData::InitializeInternal( scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( new net::URLRequestJobFactoryImpl()); - InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); + bool set_protocol = main_job_factory->SetProtocolHandler( + chrome::kBlobScheme, blob_protocol_handler.release()); + DCHECK(set_protocol); + set_protocol = main_job_factory->SetProtocolHandler( + chrome::kFileSystemScheme, file_system_protocol_handler.release()); + DCHECK(set_protocol); + set_protocol = main_job_factory->SetProtocolHandler( + chrome::kChromeUIScheme, chrome_protocol_handler.release()); + DCHECK(set_protocol); + set_protocol = main_job_factory->SetProtocolHandler( + chrome::kChromeDevToolsScheme, + chrome_devtools_protocol_handler.release()); + DCHECK(set_protocol); main_job_factory_ = SetUpJobFactoryDefaults( main_job_factory.Pass(), profile_params->protocol_handler_interceptor.Pass(), network_delegate(), main_context->ftp_transaction_factory(), main_context->ftp_auth_cache()); + main_job_factory_.reset(new net::ProtocolInterceptJobFactory( + main_job_factory_.Pass(), developer_protocol_handler.Pass())); main_context->set_job_factory(main_job_factory_.get()); #if defined(ENABLE_EXTENSIONS) @@ -290,7 +336,16 @@ OffTheRecordProfileIOData::InitializeAppRequestContext( const StoragePartitionDescriptor& partition_descriptor, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers) const { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const { AppRequestContext* context = new AppRequestContext(load_time_stats()); // Copy most state from the main context. @@ -313,13 +368,27 @@ OffTheRecordProfileIOData::InitializeAppRequestContext( scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( new net::URLRequestJobFactoryImpl()); - InstallProtocolHandlers(job_factory.get(), protocol_handlers); + bool set_protocol = job_factory->SetProtocolHandler( + chrome::kBlobScheme, blob_protocol_handler.release()); + DCHECK(set_protocol); + set_protocol = job_factory->SetProtocolHandler( + chrome::kFileSystemScheme, file_system_protocol_handler.release()); + DCHECK(set_protocol); + set_protocol = job_factory->SetProtocolHandler( + chrome::kChromeUIScheme, chrome_protocol_handler.release()); + DCHECK(set_protocol); + set_protocol = job_factory->SetProtocolHandler( + chrome::kChromeDevToolsScheme, + chrome_devtools_protocol_handler.release()); + DCHECK(set_protocol); scoped_ptr<net::URLRequestJobFactory> top_job_factory; top_job_factory = SetUpJobFactoryDefaults(job_factory.Pass(), protocol_handler_interceptor.Pass(), network_delegate(), context->ftp_transaction_factory(), context->ftp_auth_cache()); + top_job_factory.reset(new net::ProtocolInterceptJobFactory( + top_job_factory.Pass(), developer_protocol_handler.Pass())); context->SetJobFactory(top_job_factory.Pass()); return context; } @@ -344,12 +413,25 @@ OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext( const StoragePartitionDescriptor& partition_descriptor, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers) const { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const { // We create per-app contexts on demand, unlike the others above. ChromeURLRequestContext* app_request_context = InitializeAppRequestContext(main_context, partition_descriptor, protocol_handler_interceptor.Pass(), - protocol_handlers); + blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), + chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass()); DCHECK(app_request_context); return app_request_context; } diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.h b/chrome/browser/profiles/off_the_record_profile_io_data.h index cfa6cb6..ed37d48 100644 --- a/chrome/browser/profiles/off_the_record_profile_io_data.h +++ b/chrome/browser/profiles/off_the_record_profile_io_data.h @@ -44,7 +44,16 @@ class OffTheRecordProfileIOData : public ProfileIOData { content::ResourceContext* GetResourceContextNoInit() const; scoped_refptr<ChromeURLRequestContextGetter> CreateMainRequestContextGetter( - content::ProtocolHandlerMap* protocol_handlers) const; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const; scoped_refptr<ChromeURLRequestContextGetter> GetExtensionsRequestContextGetter() const; scoped_refptr<ChromeURLRequestContextGetter> @@ -55,7 +64,16 @@ class OffTheRecordProfileIOData : public ProfileIOData { CreateIsolatedAppRequestContextGetter( const base::FilePath& partition_path, bool in_memory, - content::ProtocolHandlerMap* protocol_handlers) const; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const; private: typedef std::map<StoragePartitionDescriptor, @@ -102,7 +120,16 @@ class OffTheRecordProfileIOData : public ProfileIOData { virtual void InitializeInternal( ProfileParams* profile_params, - content::ProtocolHandlerMap* protocol_handlers) const OVERRIDE; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const OVERRIDE; virtual void InitializeExtensionsRequestContext( ProfileParams* profile_params) const OVERRIDE; virtual ChromeURLRequestContext* InitializeAppRequestContext( @@ -110,7 +137,16 @@ class OffTheRecordProfileIOData : public ProfileIOData { const StoragePartitionDescriptor& partition_descriptor, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers) const OVERRIDE; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const OVERRIDE; virtual ChromeURLRequestContext* InitializeMediaRequestContext( ChromeURLRequestContext* original_context, const StoragePartitionDescriptor& partition_descriptor) const OVERRIDE; @@ -122,7 +158,16 @@ class OffTheRecordProfileIOData : public ProfileIOData { const StoragePartitionDescriptor& partition_descriptor, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers) const OVERRIDE; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const OVERRIDE; virtual ChromeURLRequestContext* AcquireIsolatedMediaRequestContext( ChromeURLRequestContext* app_context, diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h index a5ae599..1256c36 100644 --- a/chrome/browser/profiles/profile.h +++ b/chrome/browser/profiles/profile.h @@ -14,7 +14,6 @@ #include "base/logging.h" #include "chrome/browser/net/pref_proxy_config_tracker.h" #include "content/public/browser/browser_context.h" -#include "content/public/browser/content_browser_client.h" #include "net/url_request/url_request_job_factory.h" class ChromeAppCacheService; @@ -256,7 +255,16 @@ class Profile : public content::BrowserContext { // ContextBrowserClient to call this function. // TODO(ajwong): Remove once http://crbug.com/159193 is resolved. virtual net::URLRequestContextGetter* CreateRequestContext( - content::ProtocolHandlerMap* protocol_handlers) = 0; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) = 0; // Creates the net::URLRequestContextGetter for a StoragePartition. Should // only be called once per partition_path per ContentBrowserClient object. @@ -267,7 +275,16 @@ class Profile : public content::BrowserContext { virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory, - content::ProtocolHandlerMap* protocol_handlers) = 0; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) = 0; // Returns the last directory that was chosen for uploading or opening a file. virtual base::FilePath last_selected_directory() = 0; diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 2b1020d..128197d 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -821,9 +821,22 @@ base::FilePath ProfileImpl::GetPrefFilePath() { } net::URLRequestContextGetter* ProfileImpl::CreateRequestContext( - content::ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { return io_data_.CreateMainRequestContextGetter( - protocol_handlers, + blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), + chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass(), g_browser_process->local_state(), g_browser_process->io_thread()); } @@ -875,9 +888,20 @@ net::URLRequestContextGetter* ProfileImpl::CreateRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory, - content::ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { return io_data_.CreateIsolatedAppRequestContextGetter( - partition_path, in_memory, protocol_handlers); + partition_path, in_memory, blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), developer_protocol_handler.Pass(), + chrome_protocol_handler.Pass(), chrome_devtools_protocol_handler.Pass()); } net::SSLConfigService* ProfileImpl::GetSSLConfigService() { diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index 455414c..7e0fa0e 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -17,7 +17,6 @@ #include "base/timer.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_impl_io_data.h" -#include "content/public/browser/content_browser_client.h" #include "content/public/browser/host_zoom_map.h" class NetPrefObserver; @@ -107,11 +106,29 @@ class ProfileImpl : public Profile { virtual bool IsSameProfile(Profile* profile) OVERRIDE; virtual base::Time GetStartTime() const OVERRIDE; virtual net::URLRequestContextGetter* CreateRequestContext( - content::ProtocolHandlerMap* protocol_handlers) OVERRIDE; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) OVERRIDE; virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory, - content::ProtocolHandlerMap* protocol_handlers) OVERRIDE; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) OVERRIDE; virtual base::FilePath last_selected_directory() OVERRIDE; virtual void set_last_selected_directory(const base::FilePath& path) OVERRIDE; virtual chrome_browser_net::Predictor* GetNetworkPredictor() OVERRIDE; diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc index 644377d..f4ee923 100644 --- a/chrome/browser/profiles/profile_impl_io_data.cc +++ b/chrome/browser/profiles/profile_impl_io_data.cc @@ -128,14 +128,25 @@ ProfileImplIOData::Handle::GetResourceContextNoInit() const { scoped_refptr<ChromeURLRequestContextGetter> ProfileImplIOData::Handle::CreateMainRequestContextGetter( - content::ProtocolHandlerMap* protocol_handlers, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler, PrefService* local_state, IOThread* io_thread) const { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); LazyInitialize(); DCHECK(!main_request_context_getter_); main_request_context_getter_ = ChromeURLRequestContextGetter::CreateOriginal( - profile_, io_data_, protocol_handlers); + profile_, io_data_, blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), developer_protocol_handler.Pass(), + chrome_protocol_handler.Pass(), chrome_devtools_protocol_handler.Pass()); io_data_->predictor_->InitNetworkPredictor(profile_->GetPrefs(), local_state, @@ -177,7 +188,16 @@ scoped_refptr<ChromeURLRequestContextGetter> ProfileImplIOData::Handle::CreateIsolatedAppRequestContextGetter( const base::FilePath& partition_path, bool in_memory, - content::ProtocolHandlerMap* protocol_handlers) const { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // Check that the partition_path is not the same as the base profile path. We // expect isolated partition, which will never go to the default profile path. @@ -198,8 +218,10 @@ ProfileImplIOData::Handle::CreateIsolatedAppRequestContextGetter( ChromeURLRequestContextGetter* context = ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( profile_, io_data_, descriptor, - protocol_handler_interceptor.Pass(), - protocol_handlers); + protocol_handler_interceptor.Pass(), blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass()); app_request_context_getter_map_[descriptor] = context; return context; @@ -295,7 +317,16 @@ ProfileImplIOData::~ProfileImplIOData() { void ProfileImplIOData::InitializeInternal( ProfileParams* profile_params, - content::ProtocolHandlerMap* protocol_handlers) const { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const { ChromeURLRequestContext* main_context = main_request_context(); IOThread* const io_thread = profile_params->io_thread; @@ -416,13 +447,27 @@ void ProfileImplIOData::InitializeInternal( scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( new net::URLRequestJobFactoryImpl()); - InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); + bool set_protocol = main_job_factory->SetProtocolHandler( + chrome::kBlobScheme, blob_protocol_handler.release()); + DCHECK(set_protocol); + set_protocol = main_job_factory->SetProtocolHandler( + chrome::kFileSystemScheme, file_system_protocol_handler.release()); + DCHECK(set_protocol); + set_protocol = main_job_factory->SetProtocolHandler( + chrome::kChromeUIScheme, chrome_protocol_handler.release()); + DCHECK(set_protocol); + set_protocol = main_job_factory->SetProtocolHandler( + chrome::kChromeDevToolsScheme, + chrome_devtools_protocol_handler.release()); + DCHECK(set_protocol); main_job_factory_ = SetUpJobFactoryDefaults( main_job_factory.Pass(), profile_params->protocol_handler_interceptor.Pass(), network_delegate(), main_context->ftp_transaction_factory(), main_context->ftp_auth_cache()); + main_job_factory_.reset(new net::ProtocolInterceptJobFactory( + main_job_factory_.Pass(), developer_protocol_handler.Pass())); main_context->set_job_factory(main_job_factory_.get()); #if defined(ENABLE_EXTENSIONS) @@ -494,7 +539,16 @@ ProfileImplIOData::InitializeAppRequestContext( const StoragePartitionDescriptor& partition_descriptor, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers) const { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const { // Copy most state from the main context. AppRequestContext* context = new AppRequestContext(load_time_stats()); context->CopyFrom(main_context); @@ -566,7 +620,19 @@ ProfileImplIOData::InitializeAppRequestContext( scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( new net::URLRequestJobFactoryImpl()); - InstallProtocolHandlers(job_factory.get(), protocol_handlers); + bool set_protocol = job_factory->SetProtocolHandler( + chrome::kBlobScheme, blob_protocol_handler.release()); + DCHECK(set_protocol); + set_protocol = job_factory->SetProtocolHandler( + chrome::kFileSystemScheme, file_system_protocol_handler.release()); + DCHECK(set_protocol); + set_protocol = job_factory->SetProtocolHandler( + chrome::kChromeUIScheme, chrome_protocol_handler.release()); + DCHECK(set_protocol); + set_protocol = job_factory->SetProtocolHandler( + chrome::kChromeDevToolsScheme, + chrome_devtools_protocol_handler.release()); + DCHECK(set_protocol); scoped_ptr<net::URLRequestJobFactory> top_job_factory; // Overwrite the job factory that we inherit from the main context so // that we can later provide our own handlers for storage related protocols. @@ -581,6 +647,8 @@ ProfileImplIOData::InitializeAppRequestContext( } else { top_job_factory = job_factory.PassAs<net::URLRequestJobFactory>(); } + top_job_factory.reset(new net::ProtocolInterceptJobFactory( + top_job_factory.Pass(), developer_protocol_handler.Pass())); context->SetJobFactory(top_job_factory.Pass()); return context; @@ -646,12 +714,25 @@ ProfileImplIOData::AcquireIsolatedAppRequestContext( const StoragePartitionDescriptor& partition_descriptor, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers) const { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const { // We create per-app contexts on demand, unlike the others above. ChromeURLRequestContext* app_request_context = InitializeAppRequestContext(main_context, partition_descriptor, protocol_handler_interceptor.Pass(), - protocol_handlers); + blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), + chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass()); DCHECK(app_request_context); return app_request_context; } diff --git a/chrome/browser/profiles/profile_impl_io_data.h b/chrome/browser/profiles/profile_impl_io_data.h index 8fa27a7..670d3b7 100644 --- a/chrome/browser/profiles/profile_impl_io_data.h +++ b/chrome/browser/profiles/profile_impl_io_data.h @@ -54,14 +54,32 @@ class ProfileImplIOData : public ProfileIOData { // these functions. scoped_refptr<ChromeURLRequestContextGetter> CreateMainRequestContextGetter( - content::ProtocolHandlerMap* protocol_handlers, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler, PrefService* local_state, IOThread* io_thread) const; scoped_refptr<ChromeURLRequestContextGetter> CreateIsolatedAppRequestContextGetter( const base::FilePath& partition_path, bool in_memory, - content::ProtocolHandlerMap* protocol_handlers) const; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const; content::ResourceContext* GetResourceContext() const; // GetResourceContextNoInit() does not call LazyInitialize() so it can be @@ -148,7 +166,16 @@ class ProfileImplIOData : public ProfileIOData { virtual void InitializeInternal( ProfileParams* profile_params, - content::ProtocolHandlerMap* protocol_handlers) const OVERRIDE; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const OVERRIDE; virtual void InitializeExtensionsRequestContext( ProfileParams* profile_params) const OVERRIDE; virtual ChromeURLRequestContext* InitializeAppRequestContext( @@ -156,7 +183,16 @@ class ProfileImplIOData : public ProfileIOData { const StoragePartitionDescriptor& partition_descriptor, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers) const OVERRIDE; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const OVERRIDE; virtual ChromeURLRequestContext* InitializeMediaRequestContext( ChromeURLRequestContext* original_context, const StoragePartitionDescriptor& partition_descriptor) const OVERRIDE; @@ -168,7 +204,16 @@ class ProfileImplIOData : public ProfileIOData { const StoragePartitionDescriptor& partition_descriptor, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers) const OVERRIDE; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const OVERRIDE; virtual ChromeURLRequestContext* AcquireIsolatedMediaRequestContext( ChromeURLRequestContext* app_context, diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc index 9dc346c..f3b2bd8 100644 --- a/chrome/browser/profiles/profile_io_data.cc +++ b/chrome/browser/profiles/profile_io_data.cc @@ -431,7 +431,6 @@ bool ProfileIOData::IsHandledProtocol(const std::string& scheme) { chrome::kBlobScheme, chrome::kFileSystemScheme, chrome::kExtensionResourceScheme, - chrome::kChromeSearchScheme, }; for (size_t i = 0; i < arraysize(kProtocolList); ++i) { if (scheme == kProtocolList[i]) @@ -440,7 +439,6 @@ bool ProfileIOData::IsHandledProtocol(const std::string& scheme) { return net::URLRequest::IsHandledProtocol(scheme); } -// static bool ProfileIOData::IsHandledURL(const GURL& url) { if (!url.is_valid()) { // We handle error cases. @@ -450,21 +448,6 @@ bool ProfileIOData::IsHandledURL(const GURL& url) { return IsHandledProtocol(url.scheme()); } -// static -void ProfileIOData::InstallProtocolHandlers( - net::URLRequestJobFactoryImpl* job_factory, - content::ProtocolHandlerMap* protocol_handlers) { - for (content::ProtocolHandlerMap::iterator it = - protocol_handlers->begin(); - it != protocol_handlers->end(); - ++it) { - bool set_protocol = job_factory->SetProtocolHandler( - it->first, it->second.release()); - DCHECK(set_protocol); - } - protocol_handlers->clear(); -} - content::ResourceContext* ProfileIOData::GetResourceContext() const { return resource_context_.get(); } @@ -491,7 +474,16 @@ ChromeURLRequestContext* ProfileIOData::GetIsolatedAppRequestContext( const StoragePartitionDescriptor& partition_descriptor, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers) const { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const { DCHECK(initialized_); ChromeURLRequestContext* context = NULL; if (ContainsKey(app_request_context_map_, partition_descriptor)) { @@ -499,7 +491,9 @@ ChromeURLRequestContext* ProfileIOData::GetIsolatedAppRequestContext( } else { context = AcquireIsolatedAppRequestContext( main_context, partition_descriptor, protocol_handler_interceptor.Pass(), - protocol_handlers); + blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass()); app_request_context_map_[partition_descriptor] = context; } DCHECK(context); @@ -609,7 +603,17 @@ std::string ProfileIOData::GetSSLSessionCacheShard() { return StringPrintf("profile/%u", ssl_session_cache_instance++); } -void ProfileIOData::Init(content::ProtocolHandlerMap* protocol_handlers) const { +void ProfileIOData::Init( + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const { // The basic logic is implemented here. The specific initialization // is done in InitializeInternal(), implemented by subtypes. Static helper // functions have been provided to assist in common operations. @@ -691,7 +695,12 @@ void ProfileIOData::Init(content::ProtocolHandlerMap* protocol_handlers) const { managed_mode_url_filter_ = profile_params_->managed_mode_url_filter; #endif - InitializeInternal(profile_params_.get(), protocol_handlers); + InitializeInternal(profile_params_.get(), + blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), + chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass()); profile_params_.reset(); initialized_ = true; diff --git a/chrome/browser/profiles/profile_io_data.h b/chrome/browser/profiles/profile_io_data.h index 406fa98..ba57faf 100644 --- a/chrome/browser/profiles/profile_io_data.h +++ b/chrome/browser/profiles/profile_io_data.h @@ -19,7 +19,6 @@ #include "chrome/browser/io_thread.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/profiles/storage_partition_descriptor.h" -#include "content/public/browser/content_browser_client.h" #include "content/public/browser/resource_context.h" #include "net/cookies/cookie_monster.h" #include "net/http/http_network_session.h" @@ -78,20 +77,23 @@ class ProfileIOData { // net::URLRequest. static bool IsHandledURL(const GURL& url); - // Utility to install additional WebUI handlers into the |job_factory|. - // Ownership of the handlers is transfered from |protocol_handlers| - // to the |job_factory|. - static void InstallProtocolHandlers( - net::URLRequestJobFactoryImpl* job_factory, - content::ProtocolHandlerMap* protocol_handlers); - // Called by Profile. content::ResourceContext* GetResourceContext() const; // Initializes the ProfileIOData object and primes the RequestContext // generation. Must be called prior to any of the Get*() methods other than // GetResouceContext or GetMetricsEnabledStateOnIOThread. - void Init(content::ProtocolHandlerMap* protocol_handlers) const; + void Init( + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const; ChromeURLRequestContext* GetMainRequestContext() const; ChromeURLRequestContext* GetMediaRequestContext() const; @@ -101,7 +103,16 @@ class ProfileIOData { const StoragePartitionDescriptor& partition_descriptor, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers) const; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const; ChromeURLRequestContext* GetIsolatedMediaRequestContext( ChromeURLRequestContext* app_context, const StoragePartitionDescriptor& partition_descriptor) const; @@ -375,7 +386,16 @@ class ProfileIOData { // should use the static helper functions above to implement this. virtual void InitializeInternal( ProfileParams* profile_params, - content::ProtocolHandlerMap* protocol_handlers) const = 0; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const = 0; // Initializes the RequestContext for extensions. virtual void InitializeExtensionsRequestContext( @@ -387,7 +407,16 @@ class ProfileIOData { const StoragePartitionDescriptor& details, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers) const = 0; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const = 0; // Does an on-demand initialization of a media RequestContext for the given // isolated app. @@ -405,7 +434,16 @@ class ProfileIOData { const StoragePartitionDescriptor& partition_descriptor, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers) const = 0; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const = 0; virtual ChromeURLRequestContext* AcquireIsolatedMediaRequestContext( ChromeURLRequestContext* app_context, diff --git a/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc b/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc index 47834e9..fe68163 100644 --- a/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc +++ b/chrome/browser/ui/sync/one_click_signin_helper_unittest.cc @@ -90,7 +90,16 @@ class TestProfileIOData : public ProfileIOData { // ProfileIOData overrides: virtual void InitializeInternal( ProfileParams* profile_params, - content::ProtocolHandlerMap* protocol_handlers) const OVERRIDE { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const OVERRIDE { NOTREACHED(); } virtual void InitializeExtensionsRequestContext( @@ -102,7 +111,16 @@ class TestProfileIOData : public ProfileIOData { const StoragePartitionDescriptor& details, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers) const OVERRIDE { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const OVERRIDE { NOTREACHED(); return NULL; } @@ -123,7 +141,16 @@ class TestProfileIOData : public ProfileIOData { const StoragePartitionDescriptor& partition_descriptor, scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> protocol_handler_interceptor, - content::ProtocolHandlerMap* protocol_handlers) const OVERRIDE { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) const OVERRIDE { NOTREACHED(); return NULL; } diff --git a/chrome/browser/ui/webui/favicon_source.cc b/chrome/browser/ui/webui/favicon_source.cc index 3c86582..9f90270 100644 --- a/chrome/browser/ui/webui/favicon_source.cc +++ b/chrome/browser/ui/webui/favicon_source.cc @@ -9,12 +9,10 @@ #include "base/strings/string_number_conversions.h" #include "chrome/browser/favicon/favicon_service_factory.h" #include "chrome/browser/history/top_sites.h" -#include "chrome/browser/instant/instant_io_context.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/url_constants.h" #include "grit/locale_settings.h" #include "grit/ui_resources.h" -#include "net/url_request/url_request.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/layout.h" #include "ui/base/resource/resource_bundle.h" @@ -218,12 +216,6 @@ bool FaviconSource::ShouldReplaceExistingSource() const { return false; } -bool FaviconSource::ShouldServiceRequest(const net::URLRequest* request) const { - if (request->url().SchemeIs(chrome::kChromeSearchScheme)) - return InstantIOContext::ShouldServiceRequest(request); - return URLDataSource::ShouldServiceRequest(request); -} - bool FaviconSource::HandleMissingResource(const IconRequest& request) { // No additional checks to locate the favicon resource in the base // implementation. diff --git a/chrome/browser/ui/webui/favicon_source.h b/chrome/browser/ui/webui/favicon_source.h index 28cb9ad..eb34b02 100644 --- a/chrome/browser/ui/webui/favicon_source.h +++ b/chrome/browser/ui/webui/favicon_source.h @@ -76,8 +76,6 @@ class FaviconSource : public content::URLDataSource { const content::URLDataSource::GotDataCallback& callback) OVERRIDE; virtual std::string GetMimeType(const std::string&) const OVERRIDE; virtual bool ShouldReplaceExistingSource() const OVERRIDE; - virtual bool ShouldServiceRequest( - const net::URLRequest* request) const OVERRIDE; protected: struct IconRequest { diff --git a/chrome/browser/ui/webui/ntp/thumbnail_source.cc b/chrome/browser/ui/webui/ntp/thumbnail_source.cc index 706b760..561adb5 100644 --- a/chrome/browser/ui/webui/ntp/thumbnail_source.cc +++ b/chrome/browser/ui/webui/ntp/thumbnail_source.cc @@ -7,14 +7,12 @@ #include "base/callback.h" #include "base/message_loop.h" #include "base/memory/ref_counted_memory.h" -#include "chrome/browser/instant/instant_io_context.h" #include "chrome/browser/thumbnails/thumbnail_service.h" #include "chrome/browser/thumbnails/thumbnail_service_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" #include "grit/theme_resources.h" -#include "net/url_request/url_request.h" #include "ui/base/resource/resource_bundle.h" // Set ThumbnailService now as Profile isn't thread safe. @@ -54,10 +52,3 @@ MessageLoop* ThumbnailSource::MessageLoopForRequestPath( return thumbnail_service_.get() ? NULL : content::URLDataSource::MessageLoopForRequestPath(path); } - -bool ThumbnailSource::ShouldServiceRequest( - const net::URLRequest* request) const { - if (request->url().SchemeIs(chrome::kChromeSearchScheme)) - return InstantIOContext::ShouldServiceRequest(request); - return URLDataSource::ShouldServiceRequest(request); -} diff --git a/chrome/browser/ui/webui/ntp/thumbnail_source.h b/chrome/browser/ui/webui/ntp/thumbnail_source.h index dc98851..e2f4214 100644 --- a/chrome/browser/ui/webui/ntp/thumbnail_source.h +++ b/chrome/browser/ui/webui/ntp/thumbnail_source.h @@ -36,8 +36,6 @@ class ThumbnailSource : public content::URLDataSource { virtual std::string GetMimeType(const std::string& path) const OVERRIDE; virtual MessageLoop* MessageLoopForRequestPath( const std::string& path) const OVERRIDE; - virtual bool ShouldServiceRequest( - const net::URLRequest* request) const OVERRIDE; private: virtual ~ThumbnailSource(); diff --git a/chrome/browser/ui/webui/theme_source.cc b/chrome/browser/ui/webui/theme_source.cc index 53eeba7..304e24c 100644 --- a/chrome/browser/ui/webui/theme_source.cc +++ b/chrome/browser/ui/webui/theme_source.cc @@ -7,7 +7,6 @@ #include "base/memory/ref_counted_memory.h" #include "base/message_loop.h" #include "base/strings/string_number_conversions.h" -#include "chrome/browser/instant/instant_io_context.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/resources_util.h" #include "chrome/browser/themes/theme_properties.h" @@ -18,7 +17,6 @@ #include "chrome/common/url_constants.h" #include "content/public/browser/browser_thread.h" #include "googleurl/src/gurl.h" -#include "net/url_request/url_request.h" #include "ui/base/layout.h" #include "ui/base/resource/resource_bundle.h" #include "ui/webui/web_ui_util.h" @@ -124,12 +122,6 @@ bool ThemeSource::ShouldReplaceExistingSource() const { return true; } -bool ThemeSource::ShouldServiceRequest(const net::URLRequest* request) const { - if (request->url().SchemeIs(chrome::kChromeSearchScheme)) - return InstantIOContext::ShouldServiceRequest(request); - return URLDataSource::ShouldServiceRequest(request); -} - //////////////////////////////////////////////////////////////////////////////// // ThemeSource, private: diff --git a/chrome/browser/ui/webui/theme_source.h b/chrome/browser/ui/webui/theme_source.h index 2ec2f22..e232722 100644 --- a/chrome/browser/ui/webui/theme_source.h +++ b/chrome/browser/ui/webui/theme_source.h @@ -33,8 +33,6 @@ class ThemeSource : public content::URLDataSource { virtual MessageLoop* MessageLoopForRequestPath( const std::string& path) const OVERRIDE; virtual bool ShouldReplaceExistingSource() const OVERRIDE; - virtual bool ShouldServiceRequest( - const net::URLRequest* request) const OVERRIDE; private: // Fetch and send the theme bitmap. diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 52d73a7..89ef8c5 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -943,8 +943,6 @@ 'browser/instant/instant_commit_type.h', 'browser/instant/instant_controller.cc', 'browser/instant/instant_controller.h', - 'browser/instant/instant_io_context.cc', - 'browser/instant/instant_io_context.h', 'browser/instant/instant_loader.cc', 'browser/instant/instant_loader.h', 'browser/instant/instant_ntp.cc', diff --git a/chrome/common/chrome_content_client.cc b/chrome/common/chrome_content_client.cc index 08e56b1..adcdf14 100644 --- a/chrome/common/chrome_content_client.cc +++ b/chrome/common/chrome_content_client.cc @@ -382,7 +382,6 @@ void ChromeContentClient::AddAdditionalSchemes( standard_schemes->push_back(kExtensionResourceScheme); savable_schemes->push_back(kExtensionResourceScheme); standard_schemes->push_back(chrome::kChromeSearchScheme); - savable_schemes->push_back(chrome::kChromeSearchScheme); #if defined(OS_CHROMEOS) standard_schemes->push_back(kCrosScheme); #endif diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index c7d78d4..d569a12 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -340,9 +340,6 @@ IPC_MESSAGE_ROUTED2(ChromeViewMsg_SearchBoxFontInformation, IPC_MESSAGE_ROUTED1(ChromeViewMsg_SearchBoxKeyCaptureChanged, bool /* is_key_capture_enabled */) -IPC_MESSAGE_ROUTED1(ChromeViewMsg_SearchBoxGrantChromeSearchAccessFromOrigin, - GURL /* origin_url */) - IPC_MESSAGE_ROUTED1(ChromeViewMsg_InstantMostVisitedItemsChanged, std::vector<MostVisitedItem> /* items */) diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h index 0eec02b..4441e2a 100644 --- a/chrome/common/url_constants.h +++ b/chrome/common/url_constants.h @@ -411,11 +411,6 @@ extern const int kNumberOfChromeDebugURLs; // Canonical schemes you can use as input to GURL.SchemeIs(). extern const char kExtensionResourceScheme[]; -// The chrome-search: scheme is served by the same backend as chrome:. However, -// only specific URLDataSources are enabled to serve requests via the -// chrome-search: scheme. See |InstantIOContext::ShouldServiceRequest| and its -// callers for details. Note that WebUIBindings should never be granted to -// chrome-search: pages. extern const char kChromeSearchScheme[]; #if defined(OS_CHROMEOS) diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc index f2c3e00..a867b39 100644 --- a/chrome/renderer/chrome_content_renderer_client.cc +++ b/chrome/renderer/chrome_content_renderer_client.cc @@ -239,16 +239,13 @@ void ChromeContentRendererClient::RenderThreadStarted() { if (command_line->HasSwitch(switches::kEnableIPCFuzzing)) { thread->GetChannel()->set_outgoing_message_filter(LoadExternalIPCFuzzer()); } - // chrome:, chrome-search:, chrome-devtools:, and chrome-internal: pages - // should not be accessible by normal content, and should also be unable to - // script anything but themselves (to help limit the damage that a corrupt + // chrome:, chrome-devtools:, and chrome-internal: pages should not be + // accessible by normal content, and should also be unable to script + // anything but themselves (to help limit the damage that a corrupt // page could cause). WebString chrome_ui_scheme(ASCIIToUTF16(chrome::kChromeUIScheme)); WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(chrome_ui_scheme); - WebString chrome_search_scheme(ASCIIToUTF16(chrome::kChromeSearchScheme)); - WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(chrome_search_scheme); - WebString dev_tools_scheme(ASCIIToUTF16(chrome::kChromeDevToolsScheme)); WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(dev_tools_scheme); @@ -260,17 +257,14 @@ void ChromeContentRendererClient::RenderThreadStarted() { WebSecurityPolicy::registerURLSchemeAsLocal(drive_scheme); #endif - // chrome: and chrome-search: pages should not be accessible by bookmarklets - // or javascript: URLs typed in the omnibox. + // chrome: pages should not be accessible by bookmarklets or javascript: + // URLs typed in the omnibox. WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs( chrome_ui_scheme); - WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs( - chrome_search_scheme); - // chrome:, chrome-search:, and chrome-extension: resources shouldn't trigger - // insecure content warnings. + // chrome:, and chrome-extension: resources shouldn't trigger insecure + // content warnings. WebSecurityPolicy::registerURLSchemeAsSecure(chrome_ui_scheme); - WebSecurityPolicy::registerURLSchemeAsSecure(chrome_search_scheme); WebString extension_scheme(ASCIIToUTF16(extensions::kExtensionScheme)); WebSecurityPolicy::registerURLSchemeAsSecure(extension_scheme); diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc index ec7ef46..3631412 100644 --- a/chrome/renderer/searchbox/searchbox.cc +++ b/chrome/renderer/searchbox/searchbox.cc @@ -6,10 +6,8 @@ #include "base/utf_string_conversions.h" #include "chrome/common/render_messages.h" -#include "chrome/common/url_constants.h" #include "chrome/renderer/searchbox/searchbox_extension.h" #include "content/public/renderer/render_view.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" namespace { @@ -154,9 +152,6 @@ bool SearchBox::OnMessageReceived(const IPC::Message& message) { OnThemeChanged) IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFontInformation, OnFontInformationReceived) - IPC_MESSAGE_HANDLER( - ChromeViewMsg_SearchBoxGrantChromeSearchAccessFromOrigin, - OnGrantChromeSearchAccessFromOrigin) IPC_MESSAGE_HANDLER(ChromeViewMsg_InstantMostVisitedItemsChanged, OnMostVisitedChanged) IPC_MESSAGE_UNHANDLED(handled = false) @@ -291,31 +286,6 @@ void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { } } -void SearchBox::OnFontInformationReceived(const string16& omnibox_font, - size_t omnibox_font_size) { - omnibox_font_ = omnibox_font; - omnibox_font_size_ = omnibox_font_size; -} - -void SearchBox::OnGrantChromeSearchAccessFromOrigin(const GURL& origin_url) { - string16 chrome_search_scheme(ASCIIToUTF16(chrome::kChromeSearchScheme)); - WebKit::WebSecurityPolicy::addOriginAccessWhitelistEntry( - origin_url, - chrome_search_scheme, - ASCIIToUTF16(chrome::kChromeUIFaviconHost), - false); - WebKit::WebSecurityPolicy::addOriginAccessWhitelistEntry( - origin_url, - chrome_search_scheme, - ASCIIToUTF16(chrome::kChromeUIThemeHost), - false); - WebKit::WebSecurityPolicy::addOriginAccessWhitelistEntry( - origin_url, - chrome_search_scheme, - ASCIIToUTF16(chrome::kChromeUIThumbnailHost), - false); -} - double SearchBox::GetZoom() const { WebKit::WebView* web_view = render_view()->GetWebView(); if (web_view) { @@ -326,6 +296,12 @@ double SearchBox::GetZoom() const { return 1.0; } +void SearchBox::OnFontInformationReceived(const string16& omnibox_font, + size_t omnibox_font_size) { + omnibox_font_ = omnibox_font; + omnibox_font_size_ = omnibox_font_size; +} + void SearchBox::Reset() { query_.clear(); verbatim_ = false; diff --git a/chrome/renderer/searchbox/searchbox.h b/chrome/renderer/searchbox/searchbox.h index 4fc2d49..445d4dc 100644 --- a/chrome/renderer/searchbox/searchbox.h +++ b/chrome/renderer/searchbox/searchbox.h @@ -111,7 +111,6 @@ class SearchBox : public content::RenderViewObserver, void OnThemeAreaHeightChanged(int height); void OnFontInformationReceived(const string16& omnibox_font, size_t omnibox_font_size); - void OnGrantChromeSearchAccessFromOrigin(const GURL& origin_url); void OnMostVisitedChanged(const std::vector<MostVisitedItem>& items); // Returns the current zoom factor of the render view or 1 on failure. diff --git a/chrome/renderer/searchbox/searchbox_extension.cc b/chrome/renderer/searchbox/searchbox_extension.cc index 04520ed..cb74530 100644 --- a/chrome/renderer/searchbox/searchbox_extension.cc +++ b/chrome/renderer/searchbox/searchbox_extension.cc @@ -23,8 +23,8 @@ namespace { -const char kCSSBackgroundImageFormat[] = "-webkit-image-set(" - "url(chrome-search://theme/IDR_THEME_NTP_BACKGROUND?%s) 1x)"; +const char kCSSBackgroundImageFormat[] = + "-webkit-image-set(url(chrome://theme/IDR_THEME_BACKGROUND?%s) 1x)"; const char kCSSBackgroundColorFormat[] = "rgba(%d,%d,%d,%s)"; diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc index a10f39a..561c0f0 100644 --- a/chrome/test/base/testing_profile.cc +++ b/chrome/test/base/testing_profile.cc @@ -591,7 +591,16 @@ net::URLRequestContextGetter* TestingProfile::GetRequestContext() { } net::URLRequestContextGetter* TestingProfile::CreateRequestContext( - content::ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { return request_context_.get(); } @@ -650,7 +659,16 @@ net::URLRequestContextGetter* TestingProfile::CreateRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory, - content::ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { // We don't test storage partitions here yet, so returning the same dummy // context is sufficient for now. return GetRequestContext(); diff --git a/chrome/test/base/testing_profile.h b/chrome/test/base/testing_profile.h index 148b468..88b048e 100644 --- a/chrome/test/base/testing_profile.h +++ b/chrome/test/base/testing_profile.h @@ -186,7 +186,16 @@ class TestingProfile : public Profile { // the CookieMonster. See implementation comments for more details. virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; virtual net::URLRequestContextGetter* CreateRequestContext( - content::ProtocolHandlerMap* protocol_handlers) OVERRIDE; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( int renderer_child_id) OVERRIDE; virtual content::ResourceContext* GetResourceContext() OVERRIDE; @@ -242,7 +251,16 @@ class TestingProfile : public Profile { virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory, - content::ProtocolHandlerMap* protocol_handlers) OVERRIDE; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) OVERRIDE; virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE; virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE; virtual std::wstring GetName(); diff --git a/content/browser/storage_partition_impl_map.cc b/content/browser/storage_partition_impl_map.cc index 78c1188..4d947e1 100644 --- a/content/browser/storage_partition_impl_map.cc +++ b/content/browser/storage_partition_impl_map.cc @@ -16,9 +16,13 @@ #include "content/browser/appcache/chrome_appcache_service.h" #include "content/browser/fileapi/browser_file_system_helper.h" #include "content/browser/fileapi/chrome_blob_storage_context.h" +#include "content/browser/histogram_internals_request_job.h" #include "content/browser/loader/resource_request_info_impl.h" +#include "content/browser/net/view_blob_internals_job_factory.h" +#include "content/browser/net/view_http_cache_job_factory.h" #include "content/browser/resource_context_impl.h" #include "content/browser/storage_partition_impl.h" +#include "content/browser/tcmalloc_internals_request_job.h" #include "content/browser/webui/url_data_manager_backend.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" @@ -29,6 +33,7 @@ #include "crypto/sha2.h" #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context_getter.h" +#include "webkit/appcache/view_appcache_internals_job.h" #include "webkit/blob/blob_data.h" #include "webkit/blob/blob_url_request_job_factory.h" #include "webkit/fileapi/file_system_url_request_job_factory.h" @@ -102,6 +107,62 @@ class BlobProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); }; +// Adds a bunch of debugging urls. We use an interceptor instead of a protocol +// handler because we want to reuse the chrome://scheme (everyone is familiar +// with it, and no need to expose the content/chrome separation through our UI). +class DeveloperProtocolHandler + : public net::URLRequestJobFactory::ProtocolHandler { + public: + DeveloperProtocolHandler( + AppCacheService* appcache_service, + ChromeBlobStorageContext* blob_storage_context) + : appcache_service_(appcache_service), + blob_storage_context_(blob_storage_context) {} + virtual ~DeveloperProtocolHandler() {} + + virtual net::URLRequestJob* MaybeCreateJob( + net::URLRequest* request, + net::NetworkDelegate* network_delegate) const OVERRIDE { + // Check for chrome://view-http-cache/*, which uses its own job type. + if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) + return ViewHttpCacheJobFactory::CreateJobForRequest(request, + network_delegate); + + // Next check for chrome://appcache-internals/, which uses its own job type. + if (request->url().SchemeIs(chrome::kChromeUIScheme) && + request->url().host() == chrome::kChromeUIAppCacheInternalsHost) { + return appcache::ViewAppCacheInternalsJobFactory::CreateJobForRequest( + request, network_delegate, appcache_service_); + } + + // Next check for chrome://blob-internals/, which uses its own job type. + if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) { + return ViewBlobInternalsJobFactory::CreateJobForRequest( + request, network_delegate, blob_storage_context_->controller()); + } + +#if defined(USE_TCMALLOC) + // Next check for chrome://tcmalloc/, which uses its own job type. + if (request->url().SchemeIs(chrome::kChromeUIScheme) && + request->url().host() == chrome::kChromeUITcmallocHost) { + return new TcmallocInternalsRequestJob(request, network_delegate); + } +#endif + + // Next check for chrome://histograms/, which uses its own job type. + if (request->url().SchemeIs(chrome::kChromeUIScheme) && + request->url().host() == chrome::kChromeUIHistogramHost) { + return new HistogramInternalsRequestJob(request, network_delegate); + } + + return NULL; + } + + private: + AppCacheService* appcache_service_; + ChromeBlobStorageContext* blob_storage_context_; +}; + // These constants are used to create the directory structure under the profile // where renderers with a non-default storage partition keep their persistent // state. This will contain a set of directories that partially mirror the @@ -386,51 +447,40 @@ StoragePartitionImpl* StoragePartitionImplMap::Get( ChromeBlobStorageContext* blob_storage_context = ChromeBlobStorageContext::GetFor(browser_context_); - ProtocolHandlerMap protocol_handlers; - protocol_handlers[chrome::kBlobScheme] = - linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( - new BlobProtocolHandler(blob_storage_context, - partition->GetFileSystemContext())); - protocol_handlers[chrome::kFileSystemScheme] = - linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( - CreateFileSystemProtocolHandler(partition->GetFileSystemContext())); - protocol_handlers[chrome::kChromeUIScheme] = - linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> blob_protocol_handler( + new BlobProtocolHandler(blob_storage_context, + partition->GetFileSystemContext())); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler( + CreateFileSystemProtocolHandler(partition->GetFileSystemContext())); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler( + new DeveloperProtocolHandler(partition->GetAppCacheService(), + blob_storage_context)); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler( URLDataManagerBackend::CreateProtocolHandler( browser_context_->GetResourceContext(), - browser_context_->IsOffTheRecord(), - partition->GetAppCacheService(), - blob_storage_context)); - std::vector<std::string> additional_webui_schemes = - GetContentClient()->browser()->GetAdditionalWebUISchemes(); - for (std::vector<std::string>::const_iterator it = - additional_webui_schemes.begin(); - it != additional_webui_schemes.end(); - ++it) { - protocol_handlers[*it] = - linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( - URLDataManagerBackend::CreateProtocolHandler( - browser_context_->GetResourceContext(), - browser_context_->IsOffTheRecord(), - partition->GetAppCacheService(), - blob_storage_context)); - } - protocol_handlers[chrome::kChromeDevToolsScheme] = - linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( + browser_context_->IsOffTheRecord())); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler( CreateDevToolsProtocolHandler(browser_context_->GetResourceContext(), browser_context_->IsOffTheRecord())); // These calls must happen after StoragePartitionImpl::Create(). if (partition_domain.empty()) { partition->SetURLRequestContext( - GetContentClient()->browser()->CreateRequestContext( - browser_context_, - &protocol_handlers)); + GetContentClient()->browser()->CreateRequestContext(browser_context_, + blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass())); } else { partition->SetURLRequestContext( GetContentClient()->browser()->CreateRequestContextForStoragePartition( browser_context_, partition->GetPath(), in_memory, - &protocol_handlers)); + blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass())); } partition->SetMediaURLRequestContext( partition_domain.empty() ? diff --git a/content/browser/webui/url_data_manager_backend.cc b/content/browser/webui/url_data_manager_backend.cc index 2f28b2a..8290b79 100644 --- a/content/browser/webui/url_data_manager_backend.cc +++ b/content/browser/webui/url_data_manager_backend.cc @@ -18,16 +18,10 @@ #include "base/memory/weak_ptr.h" #include "base/message_loop.h" #include "base/string_util.h" -#include "content/browser/fileapi/chrome_blob_storage_context.h" -#include "content/browser/histogram_internals_request_job.h" -#include "content/browser/net/view_blob_internals_job_factory.h" -#include "content/browser/net/view_http_cache_job_factory.h" #include "content/browser/resource_context_impl.h" -#include "content/browser/tcmalloc_internals_request_job.h" #include "content/browser/webui/shared_resources_data_source.h" #include "content/browser/webui/url_data_source_impl.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/content_browser_client.h" #include "content/public/common/url_constants.h" #include "googleurl/src/url_util.h" #include "net/base/io_buffer.h" @@ -37,9 +31,6 @@ #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_job.h" #include "net/url_request/url_request_job_factory.h" -#include "webkit/appcache/view_appcache_internals_job.h" - -using appcache::AppCacheService; namespace content { @@ -52,20 +43,12 @@ const char kChromeURLContentSecurityPolicyHeaderBase[] = const char kChromeURLXFrameOptionsHeader[] = "X-Frame-Options: DENY"; -bool SchemeIsInSchemes(const std::string& scheme, - const std::vector<std::string>& schemes) { - return std::find(schemes.begin(), schemes.end(), scheme) != schemes.end(); -} - // Parse a URL into the components used to resolve its request. |source_name| // is the hostname and |path| is the remaining portion of the URL. void URLToRequest(const GURL& url, std::string* source_name, std::string* path) { DCHECK(url.SchemeIs(chrome::kChromeDevToolsScheme) || - url.SchemeIs(chrome::kChromeUIScheme) || - SchemeIsInSchemes( - url.scheme(), - GetContentClient()->browser()->GetAdditionalWebUISchemes())); + url.SchemeIs(chrome::kChromeUIScheme)); if (!url.is_valid()) { NOTREACHED(); @@ -321,7 +304,7 @@ void URLRequestChromeJob::StartAsync() { if (!request_) return; - if (!backend_->StartRequest(request_, this)) { + if (!backend_->StartRequest(request_->url(), this)) { NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, net::ERR_INVALID_URL)); } @@ -351,58 +334,13 @@ class ChromeProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { public: // |is_incognito| should be set for incognito profiles. - ChromeProtocolHandler(ResourceContext* resource_context, - bool is_incognito, - AppCacheService* appcache_service, - ChromeBlobStorageContext* blob_storage_context) - : resource_context_(resource_context), - is_incognito_(is_incognito), - appcache_service_(appcache_service), - blob_storage_context_(blob_storage_context) {} - virtual ~ChromeProtocolHandler() {} + explicit ChromeProtocolHandler(content::ResourceContext* resource_context, + bool is_incognito); + virtual ~ChromeProtocolHandler(); virtual net::URLRequestJob* MaybeCreateJob( net::URLRequest* request, - net::NetworkDelegate* network_delegate) const OVERRIDE { - DCHECK(request); - - // Check for chrome://view-http-cache/*, which uses its own job type. - if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) - return ViewHttpCacheJobFactory::CreateJobForRequest(request, - network_delegate); - - // Next check for chrome://appcache-internals/, which uses its own job type. - if (request->url().SchemeIs(chrome::kChromeUIScheme) && - request->url().host() == chrome::kChromeUIAppCacheInternalsHost) { - return appcache::ViewAppCacheInternalsJobFactory::CreateJobForRequest( - request, network_delegate, appcache_service_); - } - - // Next check for chrome://blob-internals/, which uses its own job type. - if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) { - return ViewBlobInternalsJobFactory::CreateJobForRequest( - request, network_delegate, blob_storage_context_->controller()); - } - -#if defined(USE_TCMALLOC) - // Next check for chrome://tcmalloc/, which uses its own job type. - if (request->url().SchemeIs(chrome::kChromeUIScheme) && - request->url().host() == chrome::kChromeUITcmallocHost) { - return new TcmallocInternalsRequestJob(request, network_delegate); - } -#endif - - // Next check for chrome://histograms/, which uses its own job type. - if (request->url().SchemeIs(chrome::kChromeUIScheme) && - request->url().host() == chrome::kChromeUIHistogramHost) { - return new HistogramInternalsRequestJob(request, network_delegate); - } - - // Fall back to using a custom handler - return new URLRequestChromeJob( - request, network_delegate, - GetURLDataManagerForResourceContext(resource_context_), is_incognito_); - } + net::NetworkDelegate* network_delegate) const OVERRIDE; private: // These members are owned by ProfileIOData, which owns this ProtocolHandler. @@ -410,12 +348,26 @@ class ChromeProtocolHandler // True when generated from an incognito profile. const bool is_incognito_; - AppCacheService* appcache_service_; - ChromeBlobStorageContext* blob_storage_context_; DISALLOW_COPY_AND_ASSIGN(ChromeProtocolHandler); }; +ChromeProtocolHandler::ChromeProtocolHandler( + content::ResourceContext* resource_context, bool is_incognito) + : resource_context_(resource_context), is_incognito_(is_incognito) {} + +ChromeProtocolHandler::~ChromeProtocolHandler() {} + +net::URLRequestJob* ChromeProtocolHandler::MaybeCreateJob( + net::URLRequest* request, net::NetworkDelegate* network_delegate) const { + DCHECK(request); + + // Fall back to using a custom handler + return new URLRequestChromeJob( + request, network_delegate, + GetURLDataManagerForResourceContext(resource_context_), is_incognito_); +} + } // namespace URLDataManagerBackend::URLDataManagerBackend() @@ -437,13 +389,9 @@ URLDataManagerBackend::~URLDataManagerBackend() { // static net::URLRequestJobFactory::ProtocolHandler* URLDataManagerBackend::CreateProtocolHandler( - content::ResourceContext* resource_context, - bool is_incognito, - AppCacheService* appcache_service, - ChromeBlobStorageContext* blob_storage_context) { + content::ResourceContext* resource_context, bool is_incognito) { DCHECK(resource_context); - return new ChromeProtocolHandler( - resource_context, is_incognito, appcache_service, blob_storage_context); + return new ChromeProtocolHandler(resource_context, is_incognito); } void URLDataManagerBackend::AddDataSource( @@ -469,12 +417,12 @@ bool URLDataManagerBackend::HasPendingJob( return false; } -bool URLDataManagerBackend::StartRequest(const net::URLRequest* request, +bool URLDataManagerBackend::StartRequest(const GURL& url, URLRequestChromeJob* job) { // Parse the URL into a request for a source and path. std::string source_name; std::string path; - URLToRequest(request->url(), &source_name, &path); + URLToRequest(url, &source_name, &path); // Look up the data source for the request. DataSourceMap::iterator i = data_sources_.find(source_name); @@ -483,9 +431,6 @@ bool URLDataManagerBackend::StartRequest(const net::URLRequest* request, URLDataSourceImpl* source = i->second; - if (!source->source()->ShouldServiceRequest(request)) - return false; - // Save this request so we know where to send the data. RequestID request_id = next_request_id_++; pending_requests_.insert(std::make_pair(request_id, job)); diff --git a/content/browser/webui/url_data_manager_backend.h b/content/browser/webui/url_data_manager_backend.h index 3181369..58daa4e 100644 --- a/content/browser/webui/url_data_manager_backend.h +++ b/content/browser/webui/url_data_manager_backend.h @@ -17,16 +17,11 @@ class GURL; -namespace appcache { -class AppCacheService; -} - namespace base { class RefCountedMemory; } namespace content { -class ChromeBlobStorageContext; class ResourceContext; class URLDataManagerBackend; class URLDataSourceImpl; @@ -46,9 +41,7 @@ class URLDataManagerBackend : public base::SupportsUserData::Data { // be set for incognito profiles. Called on the UI thread. static net::URLRequestJobFactory::ProtocolHandler* CreateProtocolHandler( content::ResourceContext* resource_context, - bool is_incognito, - appcache::AppCacheService* appcache_service, - ChromeBlobStorageContext* blob_storage_context); + bool is_incognito); // Adds a DataSource to the collection of data sources. void AddDataSource(URLDataSourceImpl* source); @@ -68,7 +61,7 @@ class URLDataManagerBackend : public base::SupportsUserData::Data { // Called by the job when it's starting up. // Returns false if |url| is not a URL managed by this object. - bool StartRequest(const net::URLRequest* request, URLRequestChromeJob* job); + bool StartRequest(const GURL& url, URLRequestChromeJob* job); // Helper function to call StartDataRequest on |source|'s delegate. This is // needed because while we want to call URLDataSourceDelegate's method, we diff --git a/content/public/browser/content_browser_client.cc b/content/public/browser/content_browser_client.cc index 72349d5..00b62a7 100644 --- a/content/public/browser/content_browser_client.cc +++ b/content/public/browser/content_browser_client.cc @@ -36,13 +36,18 @@ bool ContentBrowserClient::ShouldUseProcessPerSite( return false; } -std::vector<std::string> ContentBrowserClient::GetAdditionalWebUISchemes() { - return std::vector<std::string>(); -} - net::URLRequestContextGetter* ContentBrowserClient::CreateRequestContext( BrowserContext* browser_context, - ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { return NULL; } @@ -51,7 +56,16 @@ ContentBrowserClient::CreateRequestContextForStoragePartition( BrowserContext* browser_context, const base::FilePath& partition_path, bool in_memory, - ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { return NULL; } diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h index 5f8ffa3..af10346 100644 --- a/content/public/browser/content_browser_client.h +++ b/content/public/browser/content_browser_client.h @@ -5,13 +5,11 @@ #ifndef CONTENT_PUBLIC_BROWSER_CONTENT_BROWSER_CLIENT_H_ #define CONTENT_PUBLIC_BROWSER_CONTENT_BROWSER_CLIENT_H_ -#include <map> #include <string> #include <utility> #include <vector> #include "base/callback_forward.h" -#include "base/memory/linked_ptr.h" #include "base/memory/scoped_ptr.h" #include "content/public/browser/file_descriptor_info.h" #include "content/public/common/socket_permission_request.h" @@ -84,12 +82,6 @@ class WebContentsViewPort; struct MainFunctionParams; struct ShowDesktopNotificationHostMsgParams; -// A mapping from the scheme name to the protocol handler that services its -// content. -typedef std::map< - std::string, linked_ptr<net::URLRequestJobFactory::ProtocolHandler> > - ProtocolHandlerMap; - // Embedder API (or SPI) for participating in browser logic, to be implemented // by the client of the content browser. See ChromeContentBrowserClient for the // principal implementation. The methods are assumed to be called on the UI @@ -147,18 +139,21 @@ class CONTENT_EXPORT ContentBrowserClient { virtual bool ShouldUseProcessPerSite(BrowserContext* browser_context, const GURL& effective_url); - // Returns a list additional WebUI schemes, if any. These additional schemes - // act as aliases to the chrome: scheme. The additional schemes may or may - // not serve specific WebUI pages depending on the particular URLDataSource - // and its override of URLDataSource::ShouldServiceRequest. - virtual std::vector<std::string> GetAdditionalWebUISchemes(); - // Creates the main net::URLRequestContextGetter. Should only be called once // per ContentBrowserClient object. // TODO(ajwong): Remove once http://crbug.com/159193 is resolved. virtual net::URLRequestContextGetter* CreateRequestContext( BrowserContext* browser_context, - ProtocolHandlerMap* protocol_handlers); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler); // Creates the net::URLRequestContextGetter for a StoragePartition. Should // only be called once per partition_path per ContentBrowserClient object. @@ -167,7 +162,16 @@ class CONTENT_EXPORT ContentBrowserClient { BrowserContext* browser_context, const base::FilePath& partition_path, bool in_memory, - ProtocolHandlerMap* protocol_handlers); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler); // Returns whether a specified URL is handled by the embedder's internal // protocol handlers. diff --git a/content/public/browser/url_data_source.cc b/content/public/browser/url_data_source.cc index b3c62b3..44239d6 100644 --- a/content/public/browser/url_data_source.cc +++ b/content/public/browser/url_data_source.cc @@ -6,8 +6,6 @@ #include "content/browser/webui/url_data_manager.h" #include "content/public/browser/browser_thread.h" -#include "content/public/common/url_constants.h" -#include "net/url_request/url_request.h" namespace content { @@ -45,11 +43,4 @@ bool URLDataSource::ShouldDenyXFrameOptions() const { return true; } -bool URLDataSource::ShouldServiceRequest(const net::URLRequest* request) const { - if (request->url().SchemeIs(chrome::kChromeDevToolsScheme) || - request->url().SchemeIs(chrome::kChromeUIScheme)) - return true; - return false; -} - } // namespace content diff --git a/content/public/browser/url_data_source.h b/content/public/browser/url_data_source.h index 49daf87..7d8847c 100644 --- a/content/public/browser/url_data_source.h +++ b/content/public/browser/url_data_source.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_PUBLIC_BROWSER_URL_DATA_SOURCE_H_ -#define CONTENT_PUBLIC_BROWSER_URL_DATA_SOURCE_H_ +#ifndef CONTENT_PUBLIC_BROWSER_URL_DATA_SOURCE_DELEGATE_H_ +#define CONTENT_PUBLIC_BROWSER_URL_DATA_SOURCE_DELEGATE_H_ #include <string> @@ -16,14 +16,10 @@ namespace base { class RefCountedMemory; } -namespace net { -class URLRequest; -} - namespace content { class BrowserContext; -// A URLDataSource is an object that can answer requests for WebUI data +// A URLDataSource is an object that can answer requests for data // asynchronously. An implementation of URLDataSource should handle calls to // StartDataRequest() by starting its (implementation-specific) asynchronous // request for the data, then running the callback given in that method to @@ -99,15 +95,8 @@ class CONTENT_EXPORT URLDataSource { // By default, the "X-Frame-Options: DENY" header is sent. To stop this from // happening, return false. It is OK to return false as needed. virtual bool ShouldDenyXFrameOptions() const; - - // By default, only chrome: and chrome-devtools: requests are allowed. - // Override in specific WebUI data sources to enable for additional schemes or - // to implement fancier access control. Typically used in concert with - // ContentBrowserClient::GetAdditionalWebUISchemes() to permit additional - // WebUI scheme support for an embedder. - virtual bool ShouldServiceRequest(const net::URLRequest* request) const; }; } // namespace content -#endif // CONTENT_PUBLIC_BROWSER_URL_DATA_SOURCE_H_ +#endif // CONTENT_PUBLIC_BROWSER_URL_DATA_SOURCE_DELEGATE_H_ diff --git a/content/shell/shell_browser_context.cc b/content/shell/shell_browser_context.cc index 2938b63..1acfa79 100644 --- a/content/shell/shell_browser_context.cc +++ b/content/shell/shell_browser_context.cc @@ -131,14 +131,27 @@ net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() { } net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext( - ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { DCHECK(!url_request_getter_); url_request_getter_ = new ShellURLRequestContextGetter( ignore_certificate_errors_, GetPath(), BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE), - protocol_handlers); + blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), + chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass()); resource_context_->set_url_request_context_getter(url_request_getter_.get()); return url_request_getter_.get(); } @@ -171,7 +184,16 @@ net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory, - ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { return NULL; } diff --git a/content/shell/shell_browser_context.h b/content/shell/shell_browser_context.h index 9146499..fa61e66 100644 --- a/content/shell/shell_browser_context.h +++ b/content/shell/shell_browser_context.h @@ -10,7 +10,6 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "content/public/browser/browser_context.h" -#include "content/public/browser/content_browser_client.h" #include "net/url_request/url_request_job_factory.h" namespace content { @@ -47,11 +46,29 @@ class ShellBrowserContext : public BrowserContext { virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; net::URLRequestContextGetter* CreateRequestContext( - ProtocolHandlerMap* protocol_handlers); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler); net::URLRequestContextGetter* CreateRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory, - ProtocolHandlerMap* protocol_handlers); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler); private: class ShellResourceContext; diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc index bd44716e..6ea4eb4 100644 --- a/content/shell/shell_content_browser_client.cc +++ b/content/shell/shell_content_browser_client.cc @@ -116,10 +116,22 @@ void ShellContentBrowserClient::RenderProcessHostCreated( net::URLRequestContextGetter* ShellContentBrowserClient::CreateRequestContext( BrowserContext* content_browser_context, - ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { ShellBrowserContext* shell_browser_context = ShellBrowserContextForBrowserContext(content_browser_context); - return shell_browser_context->CreateRequestContext(protocol_handlers); + return shell_browser_context->CreateRequestContext( + blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass()); } net::URLRequestContextGetter* @@ -127,11 +139,23 @@ ShellContentBrowserClient::CreateRequestContextForStoragePartition( BrowserContext* content_browser_context, const base::FilePath& partition_path, bool in_memory, - ProtocolHandlerMap* protocol_handlers) { + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { ShellBrowserContext* shell_browser_context = ShellBrowserContextForBrowserContext(content_browser_context); return shell_browser_context->CreateRequestContextForStoragePartition( - partition_path, in_memory, protocol_handlers); + partition_path, in_memory, blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass()); } void ShellContentBrowserClient::AppendExtraCommandLineSwitches( diff --git a/content/shell/shell_content_browser_client.h b/content/shell/shell_content_browser_client.h index 015b82d..85cb33c 100644 --- a/content/shell/shell_content_browser_client.h +++ b/content/shell/shell_content_browser_client.h @@ -30,12 +30,30 @@ class ShellContentBrowserClient : public ContentBrowserClient { virtual void RenderProcessHostCreated(RenderProcessHost* host) OVERRIDE; virtual net::URLRequestContextGetter* CreateRequestContext( BrowserContext* browser_context, - ProtocolHandlerMap* protocol_handlers) OVERRIDE; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) OVERRIDE; virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition( BrowserContext* browser_context, const base::FilePath& partition_path, bool in_memory, - ProtocolHandlerMap* protocol_handlers) OVERRIDE; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) OVERRIDE; virtual void AppendExtraCommandLineSwitches(CommandLine* command_line, int child_process_id) OVERRIDE; virtual void OverrideWebkitPrefs(RenderViewHost* render_view_host, diff --git a/content/shell/shell_url_request_context_getter.cc b/content/shell/shell_url_request_context_getter.cc index b4c25c2..c5ba28a 100644 --- a/content/shell/shell_url_request_context_getter.cc +++ b/content/shell/shell_url_request_context_getter.cc @@ -35,38 +35,34 @@ namespace content { -namespace { - -void InstallProtocolHandlers(net::URLRequestJobFactoryImpl* job_factory, - ProtocolHandlerMap* protocol_handlers) { - for (ProtocolHandlerMap::iterator it = - protocol_handlers->begin(); - it != protocol_handlers->end(); - ++it) { - bool set_protocol = job_factory->SetProtocolHandler( - it->first, it->second.release()); - DCHECK(set_protocol); - } - protocol_handlers->clear(); -} - -} // namespace - ShellURLRequestContextGetter::ShellURLRequestContextGetter( bool ignore_certificate_errors, const base::FilePath& base_path, MessageLoop* io_loop, MessageLoop* file_loop, - ProtocolHandlerMap* protocol_handlers) + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) : ignore_certificate_errors_(ignore_certificate_errors), base_path_(base_path), io_loop_(io_loop), - file_loop_(file_loop) { + file_loop_(file_loop), + blob_protocol_handler_(blob_protocol_handler.Pass()), + file_system_protocol_handler_(file_system_protocol_handler.Pass()), + developer_protocol_handler_(developer_protocol_handler.Pass()), + chrome_protocol_handler_(chrome_protocol_handler.Pass()), + chrome_devtools_protocol_handler_( + chrome_devtools_protocol_handler.Pass()) { // Must first be created on the UI thread. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - std::swap(protocol_handlers_, *protocol_handlers); - // We must create the proxy config service on the UI loop on Linux because it // must synchronously run on the glib message loop. This will be passed to // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). @@ -177,8 +173,22 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( new net::URLRequestJobFactoryImpl()); - InstallProtocolHandlers(job_factory.get(), &protocol_handlers_); - storage_->set_job_factory(job_factory.release()); + bool set_protocol = job_factory->SetProtocolHandler( + chrome::kBlobScheme, blob_protocol_handler_.release()); + DCHECK(set_protocol); + set_protocol = job_factory->SetProtocolHandler( + chrome::kFileSystemScheme, file_system_protocol_handler_.release()); + DCHECK(set_protocol); + set_protocol = job_factory->SetProtocolHandler( + chrome::kChromeUIScheme, chrome_protocol_handler_.release()); + DCHECK(set_protocol); + set_protocol = job_factory->SetProtocolHandler( + chrome::kChromeDevToolsScheme, + chrome_devtools_protocol_handler_.release()); + DCHECK(set_protocol); + storage_->set_job_factory(new net::ProtocolInterceptJobFactory( + job_factory.PassAs<net::URLRequestJobFactory>(), + developer_protocol_handler_.Pass())); } return url_request_context_.get(); diff --git a/content/shell/shell_url_request_context_getter.h b/content/shell/shell_url_request_context_getter.h index 846c5d3..23f79d1 100644 --- a/content/shell/shell_url_request_context_getter.h +++ b/content/shell/shell_url_request_context_getter.h @@ -9,7 +9,6 @@ #include "base/files/file_path.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" -#include "content/public/browser/content_browser_client.h" #include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_job_factory.h" @@ -32,7 +31,16 @@ class ShellURLRequestContextGetter : public net::URLRequestContextGetter { const base::FilePath& base_path, MessageLoop* io_loop, MessageLoop* file_loop, - ProtocolHandlerMap* protocol_handlers); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler); // net::URLRequestContextGetter implementation. virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; @@ -54,7 +62,16 @@ class ShellURLRequestContextGetter : public net::URLRequestContextGetter { scoped_ptr<net::NetworkDelegate> network_delegate_; scoped_ptr<net::URLRequestContextStorage> storage_; scoped_ptr<net::URLRequestContext> url_request_context_; - ProtocolHandlerMap protocol_handlers_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler_; DISALLOW_COPY_AND_ASSIGN(ShellURLRequestContextGetter); }; |