diff options
author | creis@google.com <creis@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-14 16:10:26 +0000 |
---|---|---|
committer | creis@google.com <creis@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-14 16:10:26 +0000 |
commit | d977f9cb570f849777ce19c9706233fb57fe3c9c (patch) | |
tree | e9a50d7d246df6cdc42c6bbb9cec1fbaae33fc71 | |
parent | d3b94c23bfd798c2fa9c72e1da23e9dfa7834862 (diff) | |
download | chromium_src-d977f9cb570f849777ce19c9706233fb57fe3c9c.zip chromium_src-d977f9cb570f849777ce19c9706233fb57fe3c9c.tar.gz chromium_src-d977f9cb570f849777ce19c9706233fb57fe3c9c.tar.bz2 |
Add a ContentBrowserClient interface to let content code delegate to embedder.
Starts with an OnRenderViewCreation method that will be useful for another CL.
BUG=none
TEST=ExtensionBrowserTest.*, TabRestoreServiceTest.*
Review URL: http://codereview.chromium.org/6674004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78037 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser_main.cc | 7 | ||||
-rw-r--r-- | chrome/browser/chrome_content_browser_client.cc | 25 | ||||
-rw-r--r-- | chrome/browser/chrome_content_browser_client.h | 22 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/test/unit/chrome_test_suite.cc | 4 | ||||
-rw-r--r-- | chrome/test/unit/chrome_test_suite.h | 4 | ||||
-rw-r--r-- | content/browser/content_browser_client.h | 26 | ||||
-rw-r--r-- | content/browser/renderer_host/test_render_view_host.cc | 6 | ||||
-rw-r--r-- | content/browser/tab_contents/render_view_host_manager.cc | 9 | ||||
-rw-r--r-- | content/common/content_client.cc | 3 | ||||
-rw-r--r-- | content/common/content_client.h | 15 | ||||
-rw-r--r-- | content/content_browser.gypi | 1 |
12 files changed, 119 insertions, 5 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 8b3cb1b..f8a6726 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -32,6 +32,7 @@ #include "build/build_config.h" #include "chrome/browser/about_flags.h" #include "chrome/browser/browser_main_win.h" +#include "chrome/browser/chrome_content_browser_client.h" #include "chrome/browser/defaults.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process_impl.h" @@ -90,6 +91,7 @@ #include "content/browser/plugin_service.h" #include "content/browser/renderer_host/resource_dispatcher_host.h" #include "content/common/child_process.h" +#include "content/common/content_client.h" #include "content/common/hi_res_timer_manager.h" #include "content/common/main_function_params.h" #include "grit/app_locale_settings.h" @@ -1473,6 +1475,11 @@ int BrowserMain(const MainFunctionParams& parameters) { PrefService* user_prefs = profile->GetPrefs(); DCHECK(user_prefs); + // Override the default ContentBrowserClient to let Chrome participate in + // content logic. Must be done before any tabs are created. + content::GetContentClient()->set_browser_client( + new chrome::ChromeContentBrowserClient()); + // Tests should be able to tune login manager before showing it. // Thus only show login manager in normal (non-testing) mode. if (!parameters.ui_task) { diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc new file mode 100644 index 0000000..0c2502c --- /dev/null +++ b/chrome/browser/chrome_content_browser_client.cc @@ -0,0 +1,25 @@ +// Copyright (c) 2011 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/chrome_content_browser_client.h" + +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/extensions/extension_service.h" +#include "content/browser/renderer_host/render_view_host.h" + +namespace chrome { + +void ChromeContentBrowserClient::OnRenderViewCreation( + RenderViewHost* render_view_host, + Profile* profile, + const GURL& url) { + // Tell the RenderViewHost whether it will be used for an extension process. + ExtensionService* service = profile->GetExtensionService(); + if (service) { + bool is_extension_process = service->ExtensionBindingsAllowed(url); + render_view_host->set_is_extension_process(is_extension_process); + } +} + +} // namespace chrome diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h new file mode 100644 index 0000000..580c9e0 --- /dev/null +++ b/chrome/browser/chrome_content_browser_client.h @@ -0,0 +1,22 @@ +// Copyright (c) 2011 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_CHROME_CONTENT_BROWSER_CLIENT_H_ +#define CHROME_BROWSER_CHROME_CONTENT_BROWSER_CLIENT_H_ +#pragma once + +#include "content/browser/content_browser_client.h" + +namespace chrome { + +class ChromeContentBrowserClient : public content::ContentBrowserClient { + public: + virtual void OnRenderViewCreation(RenderViewHost* render_view_host, + Profile* profile, + const GURL& url); +}; + +} // namespace chrome + +#endif // CHROME_BROWSER_CHROME_CONTENT_BROWSER_CLIENT_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index b022328..e05e520 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -344,6 +344,8 @@ 'browser/character_encoding.h', 'browser/chrome_browser_application_mac.h', 'browser/chrome_browser_application_mac.mm', + 'browser/chrome_content_browser_client.cc', + 'browser/chrome_content_browser_client.h', 'browser/chromeos/audio_handler.cc', 'browser/chromeos/audio_handler.h', 'browser/chromeos/audio_mixer.h', diff --git a/chrome/test/unit/chrome_test_suite.cc b/chrome/test/unit/chrome_test_suite.cc index d6860ca..7fbc48b 100644 --- a/chrome/test/unit/chrome_test_suite.cc +++ b/chrome/test/unit/chrome_test_suite.cc @@ -13,6 +13,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/browser_process.h" #include "chrome/common/chrome_constants.h" +#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/url_constants.h" #include "chrome/test/testing_browser_process.h" @@ -96,6 +97,9 @@ void ChromeTestSuite::Initialize() { base::TestSuite::Initialize(); + // Initialize the content client which that code uses to talk to Chrome. + content::SetContentClient(&chrome_content_client_); + chrome::RegisterChromeSchemes(); host_resolver_proc_ = new LocalHostResolverProc(); scoped_host_resolver_proc_.Init(host_resolver_proc_.get()); diff --git a/chrome/test/unit/chrome_test_suite.h b/chrome/test/unit/chrome_test_suite.h index 87a644d..5c61700 100644 --- a/chrome/test/unit/chrome_test_suite.h +++ b/chrome/test/unit/chrome_test_suite.h @@ -15,6 +15,7 @@ #include "base/ref_counted.h" #include "base/test/test_suite.h" #include "chrome/app/scoped_ole_initializer.h" +#include "chrome/common/chrome_content_client.h" #include "testing/gtest/include/gtest/gtest.h" #include "net/base/mock_host_resolver.h" #include "net/base/net_util.h" @@ -52,6 +53,9 @@ class ChromeTestSuite : public base::TestSuite { browser_dir_ = browser_dir; } + // Client for embedding content in Chrome. + chrome::ChromeContentClient chrome_content_client_; + base::StatsTable* stats_table_; // The name used for the stats file so it can be cleaned up on posix during diff --git a/content/browser/content_browser_client.h b/content/browser/content_browser_client.h new file mode 100644 index 0000000..7d5e916 --- /dev/null +++ b/content/browser/content_browser_client.h @@ -0,0 +1,26 @@ +// Copyright (c) 2011 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 CONTENT_BROWSER_CONTENT_BROWSER_CLIENT_H_ +#define CONTENT_BROWSER_CONTENT_BROWSER_CLIENT_H_ +#pragma once + +class GURL; +class Profile; +class RenderViewHost; + +namespace content { + +// Embedder API for participating in browser logic. +class ContentBrowserClient { + public: + // Initialize a RenderViewHost before its CreateRenderView method is called. + virtual void OnRenderViewCreation(RenderViewHost* render_view_host, + Profile* profile, + const GURL& url) {} +}; + +} // namespace content + +#endif // CONTENT_BROWSER_CONTENT_BROWSER_CLIENT_H_ diff --git a/content/browser/renderer_host/test_render_view_host.cc b/content/browser/renderer_host/test_render_view_host.cc index eaf2398..ac1caae 100644 --- a/content/browser/renderer_host/test_render_view_host.cc +++ b/content/browser/renderer_host/test_render_view_host.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "chrome/browser/browser_url_handler.h" +#include "chrome/browser/chrome_content_browser_client.h" #include "chrome/common/dom_storage_common.h" #include "chrome/common/render_messages.h" #include "chrome/common/render_messages_params.h" @@ -12,6 +13,7 @@ #include "content/browser/site_instance.h" #include "content/browser/tab_contents/navigation_controller.h" #include "content/browser/tab_contents/test_tab_contents.h" +#include "content/common/content_client.h" #include "ui/gfx/rect.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/webpreferences.h" @@ -338,6 +340,10 @@ void RenderViewHostTestHarness::Reload() { } void RenderViewHostTestHarness::SetUp() { + // Initialize Chrome's ContentBrowserClient here, since we won't go through + // BrowserMain. + content::GetContentClient()->set_browser_client( + new chrome::ChromeContentBrowserClient()); contents_.reset(CreateTestTabContents()); } diff --git a/content/browser/tab_contents/render_view_host_manager.cc b/content/browser/tab_contents/render_view_host_manager.cc index 3c382c2..0b49c33 100644 --- a/content/browser/tab_contents/render_view_host_manager.cc +++ b/content/browser/tab_contents/render_view_host_manager.cc @@ -6,7 +6,6 @@ #include "base/command_line.h" #include "base/logging.h" -#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/render_messages.h" @@ -22,6 +21,7 @@ #include "content/browser/tab_contents/tab_contents_view.h" #include "content/browser/webui/web_ui.h" #include "content/browser/webui/web_ui_factory.h" +#include "content/common/content_client.h" #include "content/common/notification_service.h" #include "content/common/notification_type.h" @@ -485,11 +485,10 @@ bool RenderViewHostManager::InitRenderView(RenderViewHost* render_view_host, if (pending_web_ui_.get()) render_view_host->AllowBindings(pending_web_ui_->bindings()); - // Tell the RenderView whether it will be used for an extension process. + // Give the embedder a chance to initialize the render view. Profile* profile = delegate_->GetControllerForRenderManager().profile(); - bool is_extension_process = profile->GetExtensionService() && - profile->GetExtensionService()->ExtensionBindingsAllowed(entry.url()); - render_view_host->set_is_extension_process(is_extension_process); + content::GetContentClient()->browser_client()->OnRenderViewCreation( + render_view_host, profile, entry.url()); return delegate_->CreateRenderViewForRenderManager(render_view_host); } diff --git a/content/common/content_client.cc b/content/common/content_client.cc index 6fa7ace..fb22d84 100644 --- a/content/common/content_client.cc +++ b/content/common/content_client.cc @@ -16,4 +16,7 @@ ContentClient* GetContentClient() { return g_client; } +ContentClient::ContentClient() : + browser_client_(NULL) {} + } // namespace content diff --git a/content/common/content_client.h b/content/common/content_client.h index 8a9b536..4f93638 100644 --- a/content/common/content_client.h +++ b/content/common/content_client.h @@ -7,6 +7,7 @@ #pragma once #include "base/basictypes.h" +#include "content/browser/content_browser_client.h" class GURL; struct GPUInfo; @@ -22,12 +23,26 @@ ContentClient* GetContentClient(); // Interface that the embedder implements. class ContentClient { public: + ContentClient(); + + // Gets or sets the embedder API for participating in browser logic. + // The client must be set early, before any content code is called. + ContentBrowserClient* browser_client() { + return browser_client_; + } + void set_browser_client(ContentBrowserClient* client) { + browser_client_ = client; + } + // Sets the URL that is logged if the child process crashes. Use GURL() to // clear the URL. virtual void SetActiveURL(const GURL& url) {} // Sets the data on the gpu to send along with crash reports. virtual void SetGpuInfo(const GPUInfo& gpu_info) {} + + private: + ContentBrowserClient* browser_client_; }; } // namespace content diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 028573a..793c3ae 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -51,6 +51,7 @@ 'browser/child_process_security_policy.h', 'browser/chrome_blob_storage_context.cc', 'browser/chrome_blob_storage_context.h', + 'browser/content_browser_client.h', 'browser/cross_site_request_manager.cc', 'browser/cross_site_request_manager.h', 'browser/device_orientation/accelerometer_mac.cc', |