[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] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 9 | #include "chrome/browser/profiles/profile.h" |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame^] | 10 | #include "chrome/browser/extensions/extension_message_handler.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 12 | #include "chrome/browser/renderer_host/browser_render_process_host.h" |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 13 | #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 14 | #include "content/browser/renderer_host/render_view_host.h" |
| 15 | |
| 16 | namespace chrome { |
| 17 | |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame^] | 18 | void ChromeContentBrowserClient::RenderViewHostCreated( |
| 19 | RenderViewHost* render_view_host) { |
| 20 | new DesktopNotificationHandler(render_view_host); |
| 21 | new DevToolsHandler(render_view_host); |
| 22 | new ExtensionMessageHandler(render_view_host); |
| 23 | } |
| 24 | |
[email protected] | 490f79c1 | 2011-03-17 22:24:43 | [diff] [blame] | 25 | void ChromeContentBrowserClient::PreCreateRenderView( |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 26 | RenderViewHost* render_view_host, |
| 27 | Profile* profile, |
| 28 | const GURL& url) { |
| 29 | // Tell the RenderViewHost whether it will be used for an extension process. |
| 30 | ExtensionService* service = profile->GetExtensionService(); |
| 31 | if (service) { |
| 32 | bool is_extension_process = service->ExtensionBindingsAllowed(url); |
| 33 | render_view_host->set_is_extension_process(is_extension_process); |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 34 | |
| 35 | const Extension* installed_app = service->GetInstalledApp(url); |
| 36 | static_cast<BrowserRenderProcessHost*>(render_view_host->process())-> |
| 37 | set_installed_app(installed_app); |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 41 | content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() { |
| 42 | return ChromeWebUIFactory::GetInstance(); |
| 43 | } |
| 44 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 45 | GURL ChromeContentBrowserClient::GetEffectiveURL(Profile* profile, |
| 46 | const GURL& url) { |
| 47 | // Get the effective URL for the given actual URL. If the URL is part of an |
| 48 | // installed app, the effective URL is an extension URL with the ID of that |
| 49 | // extension as the host. This has the effect of grouping apps together in |
| 50 | // a common SiteInstance. |
| 51 | if (!profile || !profile->GetExtensionService()) |
| 52 | return url; |
| 53 | |
| 54 | const Extension* extension = |
| 55 | profile->GetExtensionService()->GetExtensionByWebExtent(url); |
| 56 | if (!extension) |
| 57 | return url; |
| 58 | |
| 59 | // If the URL is part of an extension's web extent, convert it to an |
| 60 | // extension URL. |
| 61 | return extension->GetResourceURL(url.path()); |
| 62 | } |
| 63 | |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 64 | } // namespace chrome |