[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 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 | |||||
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 7 | #include "chrome/browser/debugger/devtools_handler.h" |
8 | #include "chrome/browser/desktop_notification_handler.h" | ||||
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 9 | #include "chrome/browser/extensions/extension_message_handler.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 10 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 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" | ||||
[email protected] | 53a0afa | 2011-04-28 02:09:33 | [diff] [blame^] | 14 | #include "chrome/browser/renderer_host/chrome_render_view_host_observer.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 15 | #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h" |
16 | #include "chrome/browser/spellcheck_message_filter.h" | ||||
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 17 | #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 18 | #include "content/browser/renderer_host/browser_render_process_host.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 19 | #include "content/browser/renderer_host/render_view_host.h" |
20 | |||||
21 | namespace chrome { | ||||
22 | |||||
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 23 | void ChromeContentBrowserClient::RenderViewHostCreated( |
24 | RenderViewHost* render_view_host) { | ||||
[email protected] | 53a0afa | 2011-04-28 02:09:33 | [diff] [blame^] | 25 | new ChromeRenderViewHostObserver(render_view_host); |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 26 | new DesktopNotificationHandler(render_view_host); |
27 | new DevToolsHandler(render_view_host); | ||||
28 | new ExtensionMessageHandler(render_view_host); | ||||
29 | } | ||||
30 | |||||
[email protected] | 490f79c1 | 2011-03-17 22:24:43 | [diff] [blame] | 31 | void ChromeContentBrowserClient::PreCreateRenderView( |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 32 | RenderViewHost* render_view_host, |
33 | Profile* profile, | ||||
34 | const GURL& url) { | ||||
35 | // Tell the RenderViewHost whether it will be used for an extension process. | ||||
36 | ExtensionService* service = profile->GetExtensionService(); | ||||
37 | if (service) { | ||||
38 | bool is_extension_process = service->ExtensionBindingsAllowed(url); | ||||
39 | render_view_host->set_is_extension_process(is_extension_process); | ||||
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 40 | |
41 | const Extension* installed_app = service->GetInstalledApp(url); | ||||
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 42 | if (installed_app) { |
43 | service->SetInstalledAppForRenderer( | ||||
44 | render_view_host->process()->id(), installed_app); | ||||
45 | } | ||||
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 46 | } |
47 | } | ||||
48 | |||||
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 49 | void ChromeContentBrowserClient::BrowserRenderProcessHostCreated( |
50 | BrowserRenderProcessHost* host) { | ||||
51 | host->channel()->AddFilter(new ChromeRenderMessageFilter( | ||||
52 | host->id(), | ||||
53 | host->profile(), | ||||
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 54 | host->profile()->GetRequestContextForRenderProcess(host->id()))); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 55 | host->channel()->AddFilter(new PrintingMessageFilter()); |
56 | host->channel()->AddFilter( | ||||
57 | new SearchProviderInstallStateMessageFilter(host->id(), host->profile())); | ||||
58 | host->channel()->AddFilter(new SpellCheckMessageFilter()); | ||||
59 | } | ||||
60 | |||||
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 61 | content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() { |
62 | return ChromeWebUIFactory::GetInstance(); | ||||
63 | } | ||||
64 | |||||
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 65 | GURL ChromeContentBrowserClient::GetEffectiveURL(Profile* profile, |
66 | const GURL& url) { | ||||
67 | // Get the effective URL for the given actual URL. If the URL is part of an | ||||
68 | // installed app, the effective URL is an extension URL with the ID of that | ||||
69 | // extension as the host. This has the effect of grouping apps together in | ||||
70 | // a common SiteInstance. | ||||
71 | if (!profile || !profile->GetExtensionService()) | ||||
72 | return url; | ||||
73 | |||||
74 | const Extension* extension = | ||||
75 | profile->GetExtensionService()->GetExtensionByWebExtent(url); | ||||
76 | if (!extension) | ||||
77 | return url; | ||||
78 | |||||
79 | // If the URL is part of an extension's web extent, convert it to an | ||||
80 | // extension URL. | ||||
81 | return extension->GetResourceURL(url.path()); | ||||
82 | } | ||||
83 | |||||
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 84 | } // namespace chrome |