[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] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame^] | 7 | #include "chrome/browser/character_encoding.h" |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 8 | #include "chrome/browser/debugger/devtools_handler.h" |
9 | #include "chrome/browser/desktop_notification_handler.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] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame^] | 12 | #include "chrome/browser/google/google_util.h" |
13 | #include "chrome/browser/prefs/pref_service.h" | ||||
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 14 | #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] | 53a0afa | 2011-04-28 02:09:33 | [diff] [blame] | 17 | #include "chrome/browser/renderer_host/chrome_render_view_host_observer.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 18 | #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h" |
19 | #include "chrome/browser/spellcheck_message_filter.h" | ||||
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 20 | #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame^] | 21 | #include "chrome/common/pref_names.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 22 | #include "content/browser/renderer_host/browser_render_process_host.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 23 | #include "content/browser/renderer_host/render_view_host.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame^] | 24 | #include "content/browser/tab_contents/tab_contents.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 25 | |
26 | namespace chrome { | ||||
27 | |||||
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 28 | void ChromeContentBrowserClient::RenderViewHostCreated( |
29 | RenderViewHost* render_view_host) { | ||||
[email protected] | 53a0afa | 2011-04-28 02:09:33 | [diff] [blame] | 30 | new ChromeRenderViewHostObserver(render_view_host); |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 31 | new DesktopNotificationHandler(render_view_host); |
32 | new DevToolsHandler(render_view_host); | ||||
33 | new ExtensionMessageHandler(render_view_host); | ||||
34 | } | ||||
35 | |||||
[email protected] | 490f79c1 | 2011-03-17 22:24:43 | [diff] [blame] | 36 | void ChromeContentBrowserClient::PreCreateRenderView( |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 37 | 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] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 45 | |
46 | const Extension* installed_app = service->GetInstalledApp(url); | ||||
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 47 | if (installed_app) { |
48 | service->SetInstalledAppForRenderer( | ||||
49 | render_view_host->process()->id(), installed_app); | ||||
50 | } | ||||
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 51 | } |
52 | } | ||||
53 | |||||
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 54 | void ChromeContentBrowserClient::BrowserRenderProcessHostCreated( |
55 | BrowserRenderProcessHost* host) { | ||||
56 | host->channel()->AddFilter(new ChromeRenderMessageFilter( | ||||
57 | host->id(), | ||||
58 | host->profile(), | ||||
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 59 | host->profile()->GetRequestContextForRenderProcess(host->id()))); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 60 | 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] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 66 | content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() { |
67 | return ChromeWebUIFactory::GetInstance(); | ||||
68 | } | ||||
69 | |||||
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 70 | GURL 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] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame^] | 89 | GURL 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 | |||||
106 | std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName( | ||||
107 | const std::string& alias_name) { | ||||
108 | return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name); | ||||
109 | } | ||||
110 | |||||
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 111 | } // namespace chrome |