• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/chrome_content_browser_client.h"
6 
7 #include "chrome/browser/debugger/devtools_handler.h"
8 #include "chrome/browser/desktop_notification_handler.h"
9 #include "chrome/browser/extensions/extension_message_handler.h"
10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/printing/printing_message_filter.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
14 #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
15 #include "chrome/browser/spellcheck_message_filter.h"
16 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
17 #include "content/browser/renderer_host/browser_render_process_host.h"
18 #include "content/browser/renderer_host/render_view_host.h"
19 
20 namespace chrome {
21 
RenderViewHostCreated(RenderViewHost * render_view_host)22 void ChromeContentBrowserClient::RenderViewHostCreated(
23     RenderViewHost* render_view_host) {
24   new DesktopNotificationHandler(render_view_host);
25   new DevToolsHandler(render_view_host);
26   new ExtensionMessageHandler(render_view_host);
27 }
28 
PreCreateRenderView(RenderViewHost * render_view_host,Profile * profile,const GURL & url)29 void ChromeContentBrowserClient::PreCreateRenderView(
30     RenderViewHost* render_view_host,
31     Profile* profile,
32     const GURL& url) {
33   // Tell the RenderViewHost whether it will be used for an extension process.
34   ExtensionService* service = profile->GetExtensionService();
35   if (service) {
36     bool is_extension_process = service->ExtensionBindingsAllowed(url);
37     render_view_host->set_is_extension_process(is_extension_process);
38 
39     const Extension* installed_app = service->GetInstalledApp(url);
40     static_cast<BrowserRenderProcessHost*>(render_view_host->process())->
41         set_installed_app(installed_app);
42   }
43 }
44 
BrowserRenderProcessHostCreated(BrowserRenderProcessHost * host)45 void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
46     BrowserRenderProcessHost* host) {
47   host->channel()->AddFilter(new ChromeRenderMessageFilter(
48       host->id(),
49       host->profile(),
50       host->profile()->GetRequestContextForPossibleApp(
51           host->installed_app())));
52   host->channel()->AddFilter(new PrintingMessageFilter());
53   host->channel()->AddFilter(
54       new SearchProviderInstallStateMessageFilter(host->id(), host->profile()));
55   host->channel()->AddFilter(new SpellCheckMessageFilter());
56 }
57 
GetWebUIFactory()58 content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
59   return ChromeWebUIFactory::GetInstance();
60 }
61 
GetEffectiveURL(Profile * profile,const GURL & url)62 GURL ChromeContentBrowserClient::GetEffectiveURL(Profile* profile,
63                                                  const GURL& url) {
64   // Get the effective URL for the given actual URL. If the URL is part of an
65   // installed app, the effective URL is an extension URL with the ID of that
66   // extension as the host. This has the effect of grouping apps together in
67   // a common SiteInstance.
68   if (!profile || !profile->GetExtensionService())
69     return url;
70 
71   const Extension* extension =
72       profile->GetExtensionService()->GetExtensionByWebExtent(url);
73   if (!extension)
74     return url;
75 
76   // If the URL is part of an extension's web extent, convert it to an
77   // extension URL.
78   return extension->GetResourceURL(url.path());
79 }
80 
81 }  // namespace chrome
82