blob: 4a1264d2536aeb1a355201461181b45958c235ac [file] [log] [blame]
[email protected]d977f9c2011-03-14 16:10:261// 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]f364d1392011-04-08 21:03:107#include "chrome/browser/debugger/devtools_handler.h"
8#include "chrome/browser/desktop_notification_handler.h"
[email protected]f364d1392011-04-08 21:03:109#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2610#include "chrome/browser/extensions/extension_service.h"
[email protected]05fcf982011-04-19 00:44:1411#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"
[email protected]1fd1a502011-03-30 16:55:5616#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]05fcf982011-04-19 00:44:1417#include "content/browser/renderer_host/browser_render_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2618#include "content/browser/renderer_host/render_view_host.h"
19
20namespace chrome {
21
[email protected]f364d1392011-04-08 21:03:1022void 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
[email protected]490f79c12011-03-17 22:24:4329void ChromeContentBrowserClient::PreCreateRenderView(
[email protected]d977f9c2011-03-14 16:10:2630 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);
[email protected]d9696672011-03-15 22:45:0938
39 const Extension* installed_app = service->GetInstalledApp(url);
[email protected]da5683db2011-04-23 17:12:2140 if (installed_app) {
41 service->SetInstalledAppForRenderer(
42 render_view_host->process()->id(), installed_app);
43 }
[email protected]d977f9c2011-03-14 16:10:2644 }
45}
46
[email protected]05fcf982011-04-19 00:44:1447void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
48 BrowserRenderProcessHost* host) {
49 host->channel()->AddFilter(new ChromeRenderMessageFilter(
50 host->id(),
51 host->profile(),
[email protected]da5683db2011-04-23 17:12:2152 host->profile()->GetRequestContextForRenderProcess(host->id())));
[email protected]05fcf982011-04-19 00:44:1453 host->channel()->AddFilter(new PrintingMessageFilter());
54 host->channel()->AddFilter(
55 new SearchProviderInstallStateMessageFilter(host->id(), host->profile()));
56 host->channel()->AddFilter(new SpellCheckMessageFilter());
57}
58
[email protected]1fd1a502011-03-30 16:55:5659content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
60 return ChromeWebUIFactory::GetInstance();
61}
62
[email protected]36fb2c7c2011-04-04 15:49:0863GURL ChromeContentBrowserClient::GetEffectiveURL(Profile* profile,
64 const GURL& url) {
65 // Get the effective URL for the given actual URL. If the URL is part of an
66 // installed app, the effective URL is an extension URL with the ID of that
67 // extension as the host. This has the effect of grouping apps together in
68 // a common SiteInstance.
69 if (!profile || !profile->GetExtensionService())
70 return url;
71
72 const Extension* extension =
73 profile->GetExtensionService()->GetExtensionByWebExtent(url);
74 if (!extension)
75 return url;
76
77 // If the URL is part of an extension's web extent, convert it to an
78 // extension URL.
79 return extension->GetResourceURL(url.path());
80}
81
[email protected]d977f9c2011-03-14 16:10:2682} // namespace chrome