blob: f3cb9709f85f741838ea35dad3e78520abe7fc4d [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]763ec4ca2011-04-29 15:48:127#include "chrome/browser/character_encoding.h"
[email protected]f364d1392011-04-08 21:03:108#include "chrome/browser/debugger/devtools_handler.h"
9#include "chrome/browser/desktop_notification_handler.h"
[email protected]f364d1392011-04-08 21:03:1010#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2611#include "chrome/browser/extensions/extension_service.h"
[email protected]763ec4ca2011-04-29 15:48:1212#include "chrome/browser/google/google_util.h"
13#include "chrome/browser/prefs/pref_service.h"
[email protected]05fcf982011-04-19 00:44:1414#include "chrome/browser/printing/printing_message_filter.h"
15#include "chrome/browser/profiles/profile.h"
16#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3317#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]05fcf982011-04-19 00:44:1418#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
19#include "chrome/browser/spellcheck_message_filter.h"
[email protected]1fd1a502011-03-30 16:55:5620#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]763ec4ca2011-04-29 15:48:1221#include "chrome/common/pref_names.h"
[email protected]05fcf982011-04-19 00:44:1422#include "content/browser/renderer_host/browser_render_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2623#include "content/browser/renderer_host/render_view_host.h"
[email protected]763ec4ca2011-04-29 15:48:1224#include "content/browser/tab_contents/tab_contents.h"
[email protected]d977f9c2011-03-14 16:10:2625
26namespace chrome {
27
[email protected]f364d1392011-04-08 21:03:1028void ChromeContentBrowserClient::RenderViewHostCreated(
29 RenderViewHost* render_view_host) {
[email protected]53a0afa2011-04-28 02:09:3330 new ChromeRenderViewHostObserver(render_view_host);
[email protected]f364d1392011-04-08 21:03:1031 new DesktopNotificationHandler(render_view_host);
32 new DevToolsHandler(render_view_host);
33 new ExtensionMessageHandler(render_view_host);
34}
35
[email protected]490f79c12011-03-17 22:24:4336void ChromeContentBrowserClient::PreCreateRenderView(
[email protected]d977f9c2011-03-14 16:10:2637 RenderViewHost* render_view_host,
38 Profile* profile,
39 const GURL& url) {
40 // Tell the RenderViewHost whether it will be used for an extension process.
41 ExtensionService* service = profile->GetExtensionService();
42 if (service) {
43 bool is_extension_process = service->ExtensionBindingsAllowed(url);
44 render_view_host->set_is_extension_process(is_extension_process);
[email protected]d9696672011-03-15 22:45:0945
46 const Extension* installed_app = service->GetInstalledApp(url);
[email protected]da5683db2011-04-23 17:12:2147 if (installed_app) {
48 service->SetInstalledAppForRenderer(
49 render_view_host->process()->id(), installed_app);
50 }
[email protected]d977f9c2011-03-14 16:10:2651 }
52}
53
[email protected]05fcf982011-04-19 00:44:1454void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
55 BrowserRenderProcessHost* host) {
56 host->channel()->AddFilter(new ChromeRenderMessageFilter(
57 host->id(),
58 host->profile(),
[email protected]da5683db2011-04-23 17:12:2159 host->profile()->GetRequestContextForRenderProcess(host->id())));
[email protected]05fcf982011-04-19 00:44:1460 host->channel()->AddFilter(new PrintingMessageFilter());
61 host->channel()->AddFilter(
62 new SearchProviderInstallStateMessageFilter(host->id(), host->profile()));
63 host->channel()->AddFilter(new SpellCheckMessageFilter());
64}
65
[email protected]1fd1a502011-03-30 16:55:5666content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
67 return ChromeWebUIFactory::GetInstance();
68}
69
[email protected]36fb2c7c2011-04-04 15:49:0870GURL ChromeContentBrowserClient::GetEffectiveURL(Profile* profile,
71 const GURL& url) {
72 // Get the effective URL for the given actual URL. If the URL is part of an
73 // installed app, the effective URL is an extension URL with the ID of that
74 // extension as the host. This has the effect of grouping apps together in
75 // a common SiteInstance.
76 if (!profile || !profile->GetExtensionService())
77 return url;
78
79 const Extension* extension =
80 profile->GetExtensionService()->GetExtensionByWebExtent(url);
81 if (!extension)
82 return url;
83
84 // If the URL is part of an extension's web extent, convert it to an
85 // extension URL.
86 return extension->GetResourceURL(url.path());
87}
88
[email protected]763ec4ca2011-04-29 15:48:1289GURL ChromeContentBrowserClient::GetAlternateErrorPageURL(
90 const TabContents* tab) {
91 GURL url;
92 // Disable alternate error pages when in OffTheRecord/Incognito mode.
93 if (tab->profile()->IsOffTheRecord())
94 return url;
95
96 PrefService* prefs = tab->profile()->GetPrefs();
97 DCHECK(prefs);
98 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
99 url = google_util::AppendGoogleLocaleParam(
100 GURL(google_util::kLinkDoctorBaseURL));
101 url = google_util::AppendGoogleTLDParam(url);
102 }
103 return url;
104}
105
106std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
107 const std::string& alias_name) {
108 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
109}
110
[email protected]d977f9c2011-03-14 16:10:26111} // namespace chrome