[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] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 7 | #include "base/command_line.h" |
| 8 | #include "chrome/app/breakpad_mac.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 9 | #include "chrome/browser/browser_about_handler.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 10 | #include "chrome/browser/browser_process.h" |
[email protected] | 3b8f7e3 | 2011-07-13 11:52:23 | [diff] [blame] | 11 | #include "chrome/browser/browsing_data_remover.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 12 | #include "chrome/browser/character_encoding.h" |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 13 | #include "chrome/browser/chrome_benchmarking_message_filter.h" |
[email protected] | 97e6c4c | 2011-05-18 16:08:51 | [diff] [blame] | 14 | #include "chrome/browser/chrome_plugin_message_filter.h" |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 15 | #include "chrome/browser/chrome_quota_permission_context.h" |
[email protected] | 5327dfb | 2011-05-03 17:50:36 | [diff] [blame] | 16 | #include "chrome/browser/chrome_worker_message_filter.h" |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 17 | #include "chrome/browser/content_settings/host_content_settings_map.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 18 | #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
[email protected] | e1d16eb9 | 2011-08-18 23:19:32 | [diff] [blame] | 19 | #include "chrome/browser/download/download_util.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 20 | #include "chrome/browser/extensions/extension_info_map.h" |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 21 | #include "chrome/browser/extensions/extension_message_handler.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 22 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 23 | #include "chrome/browser/extensions/extension_web_ui.h" |
[email protected] | 32538d9 | 2011-08-25 00:09:23 | [diff] [blame] | 24 | #include "chrome/browser/geolocation/chrome_access_token_store.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 25 | #include "chrome/browser/google/google_util.h" |
[email protected] | ae6e991 | 2011-07-27 01:18:28 | [diff] [blame] | 26 | #include "chrome/browser/net/chrome_net_log.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 27 | #include "chrome/browser/notifications/desktop_notification_service.h" |
| 28 | #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 29 | #include "chrome/browser/platform_util.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 30 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 31 | #include "chrome/browser/prerender/prerender_manager.h" |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 32 | #include "chrome/browser/prerender/prerender_manager_factory.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 33 | #include "chrome/browser/prerender/prerender_tracker.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 34 | #include "chrome/browser/printing/printing_message_filter.h" |
| 35 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 36 | #include "chrome/browser/profiles/profile_io_data.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 37 | #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
[email protected] | 53a0afa | 2011-04-28 02:09:33 | [diff] [blame] | 38 | #include "chrome/browser/renderer_host/chrome_render_view_host_observer.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 39 | #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h" |
[email protected] | 3bc0b56 | 2011-08-24 23:51:04 | [diff] [blame] | 40 | #include "chrome/browser/speech/chrome_speech_input_manager.h" |
[email protected] | 8ec7126 | 2011-07-28 08:12:46 | [diff] [blame] | 41 | #include "chrome/browser/spellchecker/spellcheck_message_filter.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 42 | #include "chrome/browser/ssl/ssl_add_cert_handler.h" |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 43 | #include "chrome/browser/ssl/ssl_blocking_page.h" |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 44 | #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 45 | #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" |
| 46 | #include "chrome/browser/tab_contents/tab_util.h" |
| 47 | #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 48 | #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 49 | #include "chrome/common/child_process_logging.h" |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 50 | #include "chrome/common/chrome_constants.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 51 | #include "chrome/common/chrome_switches.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 52 | #include "chrome/common/extensions/extension.h" |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 53 | #include "chrome/common/logging_chrome.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 54 | #include "chrome/common/pref_names.h" |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 55 | #include "chrome/common/render_messages.h" |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 56 | #include "chrome/common/url_constants.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 57 | #include "content/browser/browser_url_handler.h" |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 58 | #include "content/browser/browsing_instance.h" |
[email protected] | 97e6c4c | 2011-05-18 16:08:51 | [diff] [blame] | 59 | #include "content/browser/plugin_process_host.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 60 | #include "content/browser/renderer_host/browser_render_process_host.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 61 | #include "content/browser/renderer_host/render_view_host.h" |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 62 | #include "content/browser/resource_context.h" |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 63 | #include "content/browser/site_instance.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 64 | #include "content/browser/ssl/ssl_cert_error_handler.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 65 | #include "content/browser/ssl/ssl_client_auth_handler.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 66 | #include "content/browser/tab_contents/tab_contents.h" |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 67 | #include "content/browser/tab_contents/tab_contents_view.h" |
[email protected] | 5327dfb | 2011-05-03 17:50:36 | [diff] [blame] | 68 | #include "content/browser/worker_host/worker_process_host.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 69 | #include "content/common/desktop_notification_messages.h" |
[email protected] | 29b25d09 | 2011-06-29 20:57:34 | [diff] [blame] | 70 | #include "grit/ui_resources.h" |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 71 | #include "net/base/cookie_monster.h" |
| 72 | #include "net/base/cookie_options.h" |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 73 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 74 | |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 75 | #if defined(USE_AURA) |
| 76 | #include "chrome/browser/chrome_browser_main_aura.h" |
| 77 | #elif defined(OS_WIN) |
| 78 | #include "chrome/browser/chrome_browser_main_win.h" |
| 79 | #elif defined(OS_MACOSX) |
| 80 | #include "chrome/browser/chrome_browser_main_mac.h" |
| 81 | #elif defined(OS_CHROMEOS) |
| 82 | #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h" |
| 83 | #elif defined(OS_LINUX) |
| 84 | #include "chrome/browser/chrome_browser_main_gtk.h" |
| 85 | #endif |
| 86 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 87 | #if defined(OS_LINUX) |
| 88 | #include "base/linux_util.h" |
| 89 | #include "chrome/browser/crash_handler_host_linux.h" |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 90 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 91 | |
[email protected] | 080f34f | 2011-09-20 05:39:26 | [diff] [blame] | 92 | #if defined(TOOLKIT_VIEWS) |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 93 | #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" |
| 94 | #elif defined(OS_LINUX) |
| 95 | #include "chrome/browser/tab_contents/tab_contents_view_gtk.h" |
| 96 | #elif defined(OS_MACOSX) |
| 97 | #include "chrome/browser/tab_contents/tab_contents_view_mac.h" |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 98 | #endif |
| 99 | |
[email protected] | 37a72af | 2011-06-13 05:42:01 | [diff] [blame] | 100 | #if defined(USE_NSS) |
| 101 | #include "chrome/browser/ui/crypto_module_password_dialog.h" |
| 102 | #endif |
| 103 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 104 | namespace { |
| 105 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 106 | // Handles rewriting Web UI URLs. |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 107 | static bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { |
| 108 | if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url)) |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 109 | return false; |
| 110 | |
| 111 | // Special case the new tab page. In older versions of Chrome, the new tab |
| 112 | // page was hosted at chrome-internal:<blah>. This might be in people's saved |
| 113 | // sessions or bookmarks, so we say any URL with that scheme triggers the new |
| 114 | // tab page. |
| 115 | if (url->SchemeIs(chrome::kChromeInternalScheme)) { |
| 116 | // Rewrite it with the proper new tab URL. |
| 117 | *url = GURL(chrome::kChromeUINewTabURL); |
| 118 | } |
| 119 | |
| 120 | return true; |
| 121 | } |
| 122 | |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 123 | } // namespace |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 124 | |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 125 | namespace chrome { |
| 126 | |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 127 | content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( |
| 128 | const MainFunctionParams& parameters) { |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 129 | #if defined(USE_AURA) |
| 130 | return new ChromeBrowserMainPartsAura(parameters); |
| 131 | #elif defined(OS_WIN) |
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 132 | return new ChromeBrowserMainPartsWin(parameters); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 133 | #elif defined(OS_MACOSX) |
[email protected] | 46c83b6 | 2011-09-08 22:09:04 | [diff] [blame] | 134 | return new ChromeBrowserMainPartsMac(parameters); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 135 | #elif defined(OS_CHROMEOS) |
[email protected] | 46c83b6 | 2011-09-08 22:09:04 | [diff] [blame] | 136 | return new ChromeBrowserMainPartsChromeos(parameters); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 137 | #elif defined(OS_LINUX) |
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 138 | return new ChromeBrowserMainPartsGtk(parameters); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 139 | #else |
| 140 | return NULL; |
| 141 | #endif |
| 142 | } |
| 143 | |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 144 | TabContentsView* ChromeContentBrowserClient::CreateTabContentsView( |
| 145 | TabContents* tab_contents) { |
[email protected] | 080f34f | 2011-09-20 05:39:26 | [diff] [blame] | 146 | #if defined(TOOLKIT_VIEWS) |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 147 | return new TabContentsViewViews(tab_contents); |
| 148 | #elif defined(OS_LINUX) |
| 149 | return new TabContentsViewGtk(tab_contents); |
| 150 | #elif defined(OS_MACOSX) |
| 151 | return tab_contents_view_mac::CreateTabContentsView(tab_contents); |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 152 | #else |
| 153 | #error Need to create your platform TabContentsView here. |
| 154 | #endif |
| 155 | } |
| 156 | |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 157 | void ChromeContentBrowserClient::RenderViewHostCreated( |
| 158 | RenderViewHost* render_view_host) { |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 159 | |
| 160 | SiteInstance* site_instance = render_view_host->site_instance(); |
| 161 | Profile* profile = Profile::FromBrowserContext( |
| 162 | site_instance->browsing_instance()->browser_context()); |
| 163 | |
| 164 | new ChromeRenderViewHostObserver(render_view_host, |
| 165 | profile->GetNetworkPredictor()); |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 166 | new ExtensionMessageHandler(render_view_host); |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 167 | } |
| 168 | |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 169 | void ChromeContentBrowserClient::BrowserRenderProcessHostCreated( |
| 170 | BrowserRenderProcessHost* host) { |
[email protected] | c47cfd6 | 2011-04-29 21:27:02 | [diff] [blame] | 171 | int id = host->id(); |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 172 | Profile* profile = Profile::FromBrowserContext(host->browser_context()); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 173 | host->channel()->AddFilter(new ChromeRenderMessageFilter( |
[email protected] | c47cfd6 | 2011-04-29 21:27:02 | [diff] [blame] | 174 | id, profile, profile->GetRequestContextForRenderProcess(id))); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 175 | host->channel()->AddFilter(new PrintingMessageFilter()); |
| 176 | host->channel()->AddFilter( |
[email protected] | c47cfd6 | 2011-04-29 21:27:02 | [diff] [blame] | 177 | new SearchProviderInstallStateMessageFilter(id, profile)); |
| 178 | host->channel()->AddFilter(new SpellCheckMessageFilter(id)); |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 179 | host->channel()->AddFilter(new ChromeBenchmarkingMessageFilter( |
| 180 | id, profile, profile->GetRequestContextForRenderProcess(id))); |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 181 | |
[email protected] | 2ccf45c | 2011-08-19 23:35:50 | [diff] [blame] | 182 | host->Send(new ChromeViewMsg_SetIsIncognitoProcess( |
| 183 | profile->IsOffTheRecord())); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 184 | } |
| 185 | |
[email protected] | 97e6c4c | 2011-05-18 16:08:51 | [diff] [blame] | 186 | void ChromeContentBrowserClient::PluginProcessHostCreated( |
| 187 | PluginProcessHost* host) { |
| 188 | host->AddFilter(new ChromePluginMessageFilter(host)); |
| 189 | } |
| 190 | |
[email protected] | 5327dfb | 2011-05-03 17:50:36 | [diff] [blame] | 191 | void ChromeContentBrowserClient::WorkerProcessHostCreated( |
| 192 | WorkerProcessHost* host) { |
| 193 | host->AddFilter(new ChromeWorkerMessageFilter(host)); |
| 194 | } |
| 195 | |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 196 | content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() { |
| 197 | return ChromeWebUIFactory::GetInstance(); |
| 198 | } |
| 199 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 200 | GURL ChromeContentBrowserClient::GetEffectiveURL( |
| 201 | content::BrowserContext* browser_context, const GURL& url) { |
| 202 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 203 | // Get the effective URL for the given actual URL. If the URL is part of an |
| 204 | // installed app, the effective URL is an extension URL with the ID of that |
| 205 | // extension as the host. This has the effect of grouping apps together in |
| 206 | // a common SiteInstance. |
| 207 | if (!profile || !profile->GetExtensionService()) |
| 208 | return url; |
| 209 | |
| 210 | const Extension* extension = |
| 211 | profile->GetExtensionService()->GetExtensionByWebExtent(url); |
| 212 | if (!extension) |
| 213 | return url; |
| 214 | |
| 215 | // If the URL is part of an extension's web extent, convert it to an |
| 216 | // extension URL. |
| 217 | return extension->GetResourceURL(url.path()); |
| 218 | } |
| 219 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 220 | bool ChromeContentBrowserClient::ShouldUseProcessPerSite( |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 221 | content::BrowserContext* browser_context, const GURL& effective_url) { |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 222 | // Non-extension URLs should generally use process-per-site-instance. |
| 223 | // Because we expect to use the effective URL, hosted apps URLs should have |
| 224 | // an extension scheme by now. |
| 225 | if (!effective_url.SchemeIs(chrome::kExtensionScheme)) |
| 226 | return false; |
| 227 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 228 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 229 | if (!profile || !profile->GetExtensionService()) |
| 230 | return false; |
| 231 | |
| 232 | const Extension* extension = |
| 233 | profile->GetExtensionService()->GetExtensionByURL(effective_url); |
| 234 | if (!extension) |
| 235 | return false; |
| 236 | |
| 237 | // If the URL is part of a hosted app that does not have the background |
| 238 | // permission, we want to give each instance its own process to improve |
| 239 | // responsiveness. |
| 240 | if (extension->GetType() == Extension::TYPE_HOSTED_APP && |
| 241 | !extension->HasAPIPermission(ExtensionAPIPermission::kBackground)) |
| 242 | return false; |
| 243 | |
| 244 | // Hosted apps that have the background permission must use process per site, |
| 245 | // since all instances can make synchronous calls to the background window. |
| 246 | // Other extensions should use process per site as well. |
| 247 | return true; |
| 248 | } |
| 249 | |
[email protected] | 0f012df8 | 2011-05-19 14:15:29 | [diff] [blame] | 250 | bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) { |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 251 | return url == GURL(chrome::kChromeUICrashURL) || |
| 252 | url == GURL(chrome::kChromeUIKillURL) || |
| 253 | url == GURL(chrome::kChromeUIHangURL) || |
| 254 | url == GURL(chrome::kChromeUIShorthangURL); |
[email protected] | 0f012df8 | 2011-05-19 14:15:29 | [diff] [blame] | 255 | } |
| 256 | |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 257 | bool ChromeContentBrowserClient::IsSuitableHost( |
| 258 | RenderProcessHost* process_host, |
| 259 | const GURL& site_url) { |
| 260 | Profile* profile = |
| 261 | Profile::FromBrowserContext(process_host->browser_context()); |
| 262 | ExtensionProcessManager* extension_process_manager = |
| 263 | profile->GetExtensionProcessManager(); |
| 264 | |
| 265 | // Maybe NULL during tests. |
| 266 | if (!extension_process_manager) |
| 267 | return true; |
| 268 | |
| 269 | bool is_extension_host = |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame^] | 270 | extension_process_manager->IsExtensionProcess(process_host->id()); |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 271 | return site_url.SchemeIs(chrome::kExtensionScheme) == is_extension_host; |
| 272 | } |
| 273 | |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 274 | std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName( |
| 275 | const std::string& alias_name) { |
| 276 | return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name); |
| 277 | } |
| 278 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 279 | void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( |
| 280 | CommandLine* command_line, int child_process_id) { |
| 281 | #if defined(USE_LINUX_BREAKPAD) |
| 282 | if (IsCrashReporterEnabled()) { |
| 283 | command_line->AppendSwitchASCII(switches::kEnableCrashReporter, |
| 284 | child_process_logging::GetClientId() + "," + base::GetLinuxDistro()); |
| 285 | } |
| 286 | #elif defined(OS_MACOSX) |
| 287 | if (IsCrashReporterEnabled()) { |
| 288 | command_line->AppendSwitchASCII(switches::kEnableCrashReporter, |
| 289 | child_process_logging::GetClientId()); |
| 290 | } |
| 291 | #endif // OS_MACOSX |
| 292 | |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 293 | if (logging::DialogsAreSuppressed()) |
| 294 | command_line->AppendSwitch(switches::kNoErrorDialogs); |
| 295 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 296 | std::string process_type = |
| 297 | command_line->GetSwitchValueASCII(switches::kProcessType); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 298 | const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame^] | 299 | if (process_type == switches::kRendererProcess) { |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 300 | FilePath user_data_dir = |
| 301 | browser_command_line.GetSwitchValuePath(switches::kUserDataDir); |
| 302 | if (!user_data_dir.empty()) |
| 303 | command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); |
| 304 | #if defined(OS_CHROMEOS) |
| 305 | const std::string& login_profile = |
| 306 | browser_command_line.GetSwitchValueASCII(switches::kLoginProfile); |
| 307 | if (!login_profile.empty()) |
| 308 | command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile); |
| 309 | #endif |
| 310 | |
| 311 | RenderProcessHost* process = RenderProcessHost::FromID(child_process_id); |
| 312 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 313 | Profile* profile = Profile::FromBrowserContext(process->browser_context()); |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame^] | 314 | |
| 315 | ExtensionProcessManager* extension_process_manager = |
| 316 | profile->GetExtensionProcessManager(); |
| 317 | if (extension_process_manager->IsExtensionProcess( |
| 318 | process->id())) { |
| 319 | command_line->AppendSwitch(switches::kExtensionProcess); |
| 320 | } |
| 321 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 322 | PrefService* prefs = profile->GetPrefs(); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 323 | // Currently this pref is only registered if applied via a policy. |
| 324 | if (prefs->HasPrefPath(prefs::kDisable3DAPIs) && |
| 325 | prefs->GetBoolean(prefs::kDisable3DAPIs)) { |
| 326 | // Turn this policy into a command line switch. |
| 327 | command_line->AppendSwitch(switches::kDisable3DAPIs); |
| 328 | } |
| 329 | |
| 330 | // Disable client-side phishing detection in the renderer if it is disabled |
[email protected] | 8c40da6 | 2011-07-13 22:58:46 | [diff] [blame] | 331 | // in the Profile preferences or the browser process. |
| 332 | if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) || |
| 333 | !g_browser_process->safe_browsing_detection_service()) { |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 334 | command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection); |
[email protected] | 8c40da6 | 2011-07-13 22:58:46 | [diff] [blame] | 335 | } |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 336 | |
| 337 | static const char* const kSwitchNames[] = { |
| 338 | switches::kAllowHTTPBackgroundPage, |
| 339 | switches::kAllowScriptingGallery, |
| 340 | switches::kAppsCheckoutURL, |
| 341 | switches::kAppsGalleryURL, |
[email protected] | be9d9c8 | 2011-07-13 04:17:31 | [diff] [blame] | 342 | switches::kCloudPrintServiceURL, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 343 | switches::kDebugPrint, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 344 | switches::kDisablePrintPreview, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 345 | switches::kDomAutomationController, |
| 346 | switches::kDumpHistogramsOnExit, |
| 347 | switches::kEnableClickToPlay, |
| 348 | switches::kEnableCrxlessWebApps, |
| 349 | switches::kEnableExperimentalExtensionApis, |
| 350 | switches::kEnableInBrowserThumbnailing, |
| 351 | switches::kEnableIPCFuzzing, |
| 352 | switches::kEnableNaCl, |
[email protected] | 5714ee3 | 2011-08-18 01:51:24 | [diff] [blame] | 353 | switches::kEnablePrintPreview, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 354 | switches::kEnableResourceContentSettings, |
| 355 | switches::kEnableSearchProviderApiV2, |
| 356 | switches::kEnableWatchdog, |
| 357 | switches::kExperimentalSpellcheckerFeatures, |
| 358 | switches::kMemoryProfiling, |
| 359 | switches::kMessageLoopHistogrammer, |
[email protected] | 2a6bb0b1 | 2011-10-05 19:18:04 | [diff] [blame] | 360 | switches::kNoRunningInsecureContent, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 361 | switches::kPpapiFlashArgs, |
| 362 | switches::kPpapiFlashInProcess, |
| 363 | switches::kPpapiFlashPath, |
| 364 | switches::kPpapiFlashVersion, |
| 365 | switches::kProfilingAtStart, |
| 366 | switches::kProfilingFile, |
| 367 | switches::kProfilingFlush, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 368 | switches::kSilentDumpOnDCHECK, |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 369 | switches::kEnableBenchmarking, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 370 | }; |
| 371 | |
| 372 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 373 | arraysize(kSwitchNames)); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 374 | } else if (process_type == switches::kUtilityProcess) { |
| 375 | if (browser_command_line.HasSwitch( |
| 376 | switches::kEnableExperimentalExtensionApis)) { |
| 377 | command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
| 378 | } |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 379 | } else if (process_type == switches::kPluginProcess) { |
| 380 | static const char* const kSwitchNames[] = { |
| 381 | #if defined(OS_CHROMEOS) |
| 382 | switches::kLoginProfile, |
| 383 | #endif |
| 384 | switches::kMemoryProfiling, |
| 385 | switches::kSilentDumpOnDCHECK, |
| 386 | switches::kUserDataDir, |
| 387 | }; |
| 388 | |
| 389 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 390 | arraysize(kSwitchNames)); |
| 391 | } else if (process_type == switches::kZygoteProcess) { |
| 392 | static const char* const kSwitchNames[] = { |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 393 | switches::kUserDataDir, // Make logs go to the right file. |
| 394 | // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox. |
| 395 | switches::kPpapiFlashInProcess, |
| 396 | switches::kPpapiFlashPath, |
| 397 | switches::kPpapiFlashVersion, |
| 398 | }; |
| 399 | |
| 400 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 401 | arraysize(kSwitchNames)); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 402 | } |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 403 | |
| 404 | // The command line switch kEnableBenchmarking needs to be specified along |
| 405 | // with the kEnableStatsTable switch to ensure that the stats table global |
| 406 | // is initialized correctly. |
| 407 | if (command_line->HasSwitch(switches::kEnableBenchmarking)) |
| 408 | DCHECK(command_line->HasSwitch(switches::kEnableStatsTable)); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | std::string ChromeContentBrowserClient::GetApplicationLocale() { |
| 412 | return g_browser_process->GetApplicationLocale(); |
| 413 | } |
| 414 | |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 415 | std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 416 | Profile* profile = Profile::FromBrowserContext(tab->browser_context()); |
| 417 | return profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 418 | } |
| 419 | |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 420 | SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() { |
| 421 | ResourceBundle &rb = ResourceBundle::GetSharedInstance(); |
| 422 | return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); |
| 423 | } |
| 424 | |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 425 | bool ChromeContentBrowserClient::AllowAppCache( |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 426 | const GURL& manifest_url, |
[email protected] | 0a60884 | 2011-09-08 10:55:19 | [diff] [blame] | 427 | const GURL& first_party, |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 428 | const content::ResourceContext& context) { |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 429 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 430 | ProfileIOData* io_data = |
| 431 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
[email protected] | efa5521 | 2011-05-13 16:19:38 | [diff] [blame] | 432 | ContentSetting setting = io_data->GetHostContentSettingsMap()-> |
[email protected] | 0a60884 | 2011-09-08 10:55:19 | [diff] [blame] | 433 | GetCookieContentSetting(manifest_url, first_party, true); |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 434 | DCHECK(setting != CONTENT_SETTING_DEFAULT); |
| 435 | return setting != CONTENT_SETTING_BLOCK; |
| 436 | } |
| 437 | |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 438 | bool ChromeContentBrowserClient::AllowGetCookie( |
| 439 | const GURL& url, |
| 440 | const GURL& first_party, |
| 441 | const net::CookieList& cookie_list, |
| 442 | const content::ResourceContext& context, |
| 443 | int render_process_id, |
| 444 | int render_view_id) { |
| 445 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 446 | ProfileIOData* io_data = |
| 447 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 448 | ContentSetting setting = io_data->GetHostContentSettingsMap()-> |
| 449 | GetCookieContentSetting(url, first_party, false); |
| 450 | bool allow = setting == CONTENT_SETTING_ALLOW || |
| 451 | setting == CONTENT_SETTING_SESSION_ONLY; |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 452 | |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 453 | BrowserThread::PostTask( |
| 454 | BrowserThread::UI, FROM_HERE, |
| 455 | NewRunnableFunction( |
| 456 | &TabSpecificContentSettings::CookiesRead, |
| 457 | render_process_id, render_view_id, url, cookie_list, !allow)); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 458 | return allow; |
| 459 | } |
| 460 | |
| 461 | bool ChromeContentBrowserClient::AllowSetCookie( |
| 462 | const GURL& url, |
| 463 | const GURL& first_party, |
| 464 | const std::string& cookie_line, |
| 465 | const content::ResourceContext& context, |
| 466 | int render_process_id, |
| 467 | int render_view_id, |
| 468 | net::CookieOptions* options) { |
| 469 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 470 | ProfileIOData* io_data = |
| 471 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 472 | ContentSetting setting = io_data->GetHostContentSettingsMap()-> |
| 473 | GetCookieContentSetting(url, first_party, true); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 474 | |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 475 | if (setting == CONTENT_SETTING_SESSION_ONLY) |
| 476 | options->set_force_session(); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 477 | |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 478 | bool allow = setting == CONTENT_SETTING_ALLOW || |
| 479 | setting == CONTENT_SETTING_SESSION_ONLY; |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 480 | |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 481 | BrowserThread::PostTask( |
| 482 | BrowserThread::UI, FROM_HERE, |
| 483 | NewRunnableFunction( |
| 484 | &TabSpecificContentSettings::CookieChanged, |
| 485 | render_process_id, render_view_id, url, cookie_line, *options, |
| 486 | !allow)); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 487 | return allow; |
| 488 | } |
| 489 | |
[email protected] | d5a1916 | 2011-06-30 18:51:54 | [diff] [blame] | 490 | bool ChromeContentBrowserClient::AllowSaveLocalState( |
| 491 | const content::ResourceContext& context) { |
| 492 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 493 | ProfileIOData* io_data = |
| 494 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
| 495 | return !io_data->clear_local_state_on_exit()->GetValue(); |
| 496 | } |
| 497 | |
[email protected] | 6133f92 | 2011-07-01 21:34:34 | [diff] [blame] | 498 | net::URLRequestContext* |
| 499 | ChromeContentBrowserClient::OverrideRequestContextForURL( |
| 500 | const GURL& url, const content::ResourceContext& context) { |
| 501 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 502 | if (url.SchemeIs(chrome::kExtensionScheme)) { |
| 503 | ProfileIOData* io_data = |
| 504 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
| 505 | return io_data->extensions_request_context(); |
| 506 | } |
| 507 | |
| 508 | return NULL; |
| 509 | } |
| 510 | |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 511 | QuotaPermissionContext* |
| 512 | ChromeContentBrowserClient::CreateQuotaPermissionContext() { |
| 513 | return new ChromeQuotaPermissionContext(); |
| 514 | } |
| 515 | |
[email protected] | a0ce328 | 2011-08-19 20:49:52 | [diff] [blame] | 516 | void ChromeContentBrowserClient::OpenItem(const FilePath& path) { |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 517 | // On Mac, this call needs to be done on the UI thread. On other platforms, |
| 518 | // do it on the FILE thread so we don't slow down UI. |
| 519 | #if defined(OS_MACOSX) |
| 520 | platform_util::OpenItem(path); |
| 521 | #else |
| 522 | BrowserThread::PostTask( |
| 523 | BrowserThread::FILE, FROM_HERE, |
| 524 | NewRunnableFunction(&platform_util::OpenItem, path)); |
| 525 | #endif |
| 526 | } |
| 527 | |
[email protected] | a0ce328 | 2011-08-19 20:49:52 | [diff] [blame] | 528 | void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) { |
| 529 | #if defined(OS_MACOSX) |
| 530 | // Mac needs to run this operation on the UI thread. |
| 531 | platform_util::ShowItemInFolder(path); |
| 532 | #else |
| 533 | BrowserThread::PostTask( |
| 534 | BrowserThread::FILE, FROM_HERE, |
| 535 | NewRunnableFunction(&platform_util::ShowItemInFolder, path)); |
| 536 | #endif |
| 537 | } |
| 538 | |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 539 | void ChromeContentBrowserClient::AllowCertificateError( |
| 540 | SSLCertErrorHandler* handler, |
| 541 | bool overridable, |
[email protected] | 8a27abf | 2011-09-30 21:59:58 | [diff] [blame] | 542 | const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) { |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 543 | // If the tab is being prerendered, cancel the prerender and the request. |
| 544 | TabContents* tab = tab_util::GetTabContentsByID( |
| 545 | handler->render_process_host_id(), |
| 546 | handler->tab_contents_id()); |
| 547 | if (!tab) { |
| 548 | NOTREACHED(); |
| 549 | return; |
| 550 | } |
| 551 | prerender::PrerenderManager* prerender_manager = |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 552 | prerender::PrerenderManagerFactory::GetForProfile( |
| 553 | Profile::FromBrowserContext(tab->browser_context())); |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 554 | if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) { |
| 555 | if (prerender_manager->prerender_tracker()->TryCancel( |
| 556 | handler->render_process_host_id(), |
| 557 | handler->tab_contents_id(), |
| 558 | prerender::FINAL_STATUS_SSL_ERROR)) { |
| 559 | handler->CancelRequest(); |
| 560 | return; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | // Otherwise, display an SSL blocking page. |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 565 | SSLBlockingPage* blocking_page = new SSLBlockingPage( |
| 566 | handler, overridable, callback); |
| 567 | blocking_page->Show(); |
| 568 | } |
| 569 | |
[email protected] | c99c442e | 2011-08-24 11:37:30 | [diff] [blame] | 570 | void ChromeContentBrowserClient::SelectClientCertificate( |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 571 | int render_process_id, |
| 572 | int render_view_id, |
| 573 | SSLClientAuthHandler* handler) { |
| 574 | TabContents* tab = tab_util::GetTabContentsByID( |
| 575 | render_process_id, render_view_id); |
| 576 | if (!tab) { |
| 577 | NOTREACHED(); |
| 578 | return; |
| 579 | } |
| 580 | |
| 581 | TabContentsWrapper* wrapper = |
| 582 | TabContentsWrapper::GetCurrentWrapperForContents(tab); |
[email protected] | c99c442e | 2011-08-24 11:37:30 | [diff] [blame] | 583 | wrapper->ssl_helper()->SelectClientCertificate(handler); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | void ChromeContentBrowserClient::AddNewCertificate( |
| 587 | net::URLRequest* request, |
| 588 | net::X509Certificate* cert, |
| 589 | int render_process_id, |
| 590 | int render_view_id) { |
| 591 | // The handler will run the UI and delete itself when it's finished. |
| 592 | new SSLAddCertHandler(request, cert, render_process_id, render_view_id); |
| 593 | } |
| 594 | |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 595 | void ChromeContentBrowserClient::RequestDesktopNotificationPermission( |
| 596 | const GURL& source_origin, |
| 597 | int callback_context, |
| 598 | int render_process_id, |
| 599 | int render_view_id) { |
| 600 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 601 | render_process_id, render_view_id); |
| 602 | if (!rvh) { |
| 603 | NOTREACHED(); |
| 604 | return; |
| 605 | } |
| 606 | |
| 607 | RenderProcessHost* process = rvh->process(); |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 608 | Profile* profile = Profile::FromBrowserContext(process->browser_context()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 609 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 610 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 611 | service->RequestPermission( |
| 612 | source_origin, render_process_id, render_view_id, callback_context, |
| 613 | tab_util::GetTabContentsByID(render_process_id, render_view_id)); |
| 614 | } |
| 615 | |
| 616 | WebKit::WebNotificationPresenter::Permission |
| 617 | ChromeContentBrowserClient::CheckDesktopNotificationPermission( |
| 618 | const GURL& source_url, |
| 619 | const content::ResourceContext& context) { |
| 620 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 621 | ProfileIOData* io_data = |
| 622 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
| 623 | |
| 624 | const Extension* extension = |
| 625 | io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url); |
| 626 | if (extension && |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 627 | extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) { |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 628 | return WebKit::WebNotificationPresenter::PermissionAllowed; |
| 629 | } |
| 630 | |
| 631 | // Fall back to the regular notification preferences, which works on an |
| 632 | // origin basis. |
| 633 | return io_data->GetNotificationService() ? |
| 634 | io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) : |
| 635 | WebKit::WebNotificationPresenter::PermissionNotAllowed; |
| 636 | } |
| 637 | |
| 638 | void ChromeContentBrowserClient::ShowDesktopNotification( |
| 639 | const DesktopNotificationHostMsg_Show_Params& params, |
| 640 | int render_process_id, |
| 641 | int render_view_id, |
| 642 | bool worker) { |
| 643 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 644 | render_process_id, render_view_id); |
| 645 | if (!rvh) { |
| 646 | NOTREACHED(); |
| 647 | return; |
| 648 | } |
| 649 | |
| 650 | RenderProcessHost* process = rvh->process(); |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 651 | Profile* profile = Profile::FromBrowserContext(process->browser_context()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 652 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 653 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 654 | service->ShowDesktopNotification( |
| 655 | params, render_process_id, render_view_id, |
| 656 | worker ? DesktopNotificationService::WorkerNotification : |
| 657 | DesktopNotificationService::PageNotification); |
| 658 | } |
| 659 | |
| 660 | void ChromeContentBrowserClient::CancelDesktopNotification( |
| 661 | int render_process_id, |
| 662 | int render_view_id, |
| 663 | int notification_id) { |
| 664 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 665 | render_process_id, render_view_id); |
| 666 | if (!rvh) { |
| 667 | NOTREACHED(); |
| 668 | return; |
| 669 | } |
| 670 | |
| 671 | RenderProcessHost* process = rvh->process(); |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 672 | Profile* profile = Profile::FromBrowserContext(process->browser_context()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 673 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 674 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 675 | service->CancelDesktopNotification( |
| 676 | render_process_id, render_view_id, notification_id); |
| 677 | } |
| 678 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 679 | bool ChromeContentBrowserClient::CanCreateWindow( |
| 680 | const GURL& source_url, |
| 681 | WindowContainerType container_type, |
| 682 | const content::ResourceContext& context) { |
| 683 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 684 | // If the opener is trying to create a background window but doesn't have |
| 685 | // the appropriate permission, fail the attempt. |
| 686 | if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { |
| 687 | ProfileIOData* io_data = |
| 688 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
| 689 | const Extension* extension = |
| 690 | io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url); |
| 691 | return (extension && |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 692 | extension->HasAPIPermission(ExtensionAPIPermission::kBackground)); |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 693 | } |
| 694 | return true; |
| 695 | } |
| 696 | |
| 697 | std::string ChromeContentBrowserClient::GetWorkerProcessTitle( |
| 698 | const GURL& url, const content::ResourceContext& context) { |
| 699 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 700 | // Check if it's an extension-created worker, in which case we want to use |
| 701 | // the name of the extension. |
| 702 | ProfileIOData* io_data = |
| 703 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
| 704 | const Extension* extension = |
| 705 | io_data->GetExtensionInfoMap()->extensions().GetByID(url.host()); |
| 706 | return extension ? extension->name() : std::string(); |
| 707 | } |
| 708 | |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 709 | ResourceDispatcherHost* |
| 710 | ChromeContentBrowserClient::GetResourceDispatcherHost() { |
| 711 | return g_browser_process->resource_dispatcher_host(); |
| 712 | } |
| 713 | |
| 714 | ui::Clipboard* ChromeContentBrowserClient::GetClipboard() { |
| 715 | return g_browser_process->clipboard(); |
| 716 | } |
| 717 | |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 718 | MHTMLGenerationManager* |
| 719 | ChromeContentBrowserClient::GetMHTMLGenerationManager() { |
| 720 | return g_browser_process->mhtml_generation_manager(); |
| 721 | } |
| 722 | |
[email protected] | dce50276 | 2011-07-20 08:53:49 | [diff] [blame] | 723 | DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() { |
| 724 | return g_browser_process->devtools_manager(); |
| 725 | } |
| 726 | |
[email protected] | ae6e991 | 2011-07-27 01:18:28 | [diff] [blame] | 727 | net::NetLog* ChromeContentBrowserClient::GetNetLog() { |
| 728 | return g_browser_process->net_log(); |
| 729 | } |
| 730 | |
[email protected] | 3bc0b56 | 2011-08-24 23:51:04 | [diff] [blame] | 731 | speech_input::SpeechInputManager* |
| 732 | ChromeContentBrowserClient::GetSpeechInputManager() { |
| 733 | return speech_input::ChromeSpeechInputManager::GetInstance(); |
| 734 | } |
| 735 | |
[email protected] | 32538d9 | 2011-08-25 00:09:23 | [diff] [blame] | 736 | AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() { |
| 737 | return new ChromeAccessTokenStore(); |
| 738 | } |
| 739 | |
[email protected] | dbae6b0 | 2011-06-29 23:51:41 | [diff] [blame] | 740 | bool ChromeContentBrowserClient::IsFastShutdownPossible() { |
| 741 | const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 742 | return !browser_command_line.HasSwitch(switches::kChromeFrame); |
| 743 | } |
| 744 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 745 | WebPreferences ChromeContentBrowserClient::GetWebkitPrefs( |
| 746 | content::BrowserContext* browser_context, bool is_web_ui) { |
| 747 | return RenderViewHostDelegateHelper::GetWebkitPrefs(browser_context, |
| 748 | is_web_ui); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | void ChromeContentBrowserClient::UpdateInspectorSetting( |
| 752 | RenderViewHost* rvh, const std::string& key, const std::string& value) { |
| 753 | RenderViewHostDelegateHelper::UpdateInspectorSetting( |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 754 | rvh->process()->browser_context(), key, value); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) { |
| 758 | RenderViewHostDelegateHelper::ClearInspectorSettings( |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 759 | rvh->process()->browser_context()); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 760 | } |
| 761 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 762 | void ChromeContentBrowserClient::BrowserURLHandlerCreated( |
| 763 | BrowserURLHandler* handler) { |
| 764 | // Add the default URL handlers. |
| 765 | handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride, |
| 766 | BrowserURLHandler::null_handler()); |
| 767 | handler->AddHandlerPair(BrowserURLHandler::null_handler(), |
| 768 | &ExtensionWebUI::HandleChromeURLOverrideReverse); |
| 769 | |
| 770 | // about: |
| 771 | handler->AddHandlerPair(&WillHandleBrowserAboutURL, |
| 772 | BrowserURLHandler::null_handler()); |
| 773 | // chrome: & friends. |
| 774 | handler->AddHandlerPair(&HandleWebUI, |
| 775 | BrowserURLHandler::null_handler()); |
| 776 | } |
| 777 | |
| 778 | void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 779 | Profile* profile = Profile::FromBrowserContext( |
| 780 | rvh->site_instance()->GetProcess()->browser_context()); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 781 | BrowsingDataRemover* remover = new BrowsingDataRemover(profile, |
| 782 | BrowsingDataRemover::EVERYTHING, |
| 783 | base::Time()); |
| 784 | remover->Remove(BrowsingDataRemover::REMOVE_CACHE); |
| 785 | // BrowsingDataRemover takes care of deleting itself when done. |
| 786 | } |
| 787 | |
| 788 | void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 789 | Profile* profile = Profile::FromBrowserContext( |
| 790 | rvh->site_instance()->GetProcess()->browser_context()); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 791 | BrowsingDataRemover* remover = new BrowsingDataRemover(profile, |
| 792 | BrowsingDataRemover::EVERYTHING, |
| 793 | base::Time()); |
[email protected] | dceaa91 | 2011-09-06 17:17:23 | [diff] [blame] | 794 | int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA; |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 795 | remover->Remove(remove_mask); |
| 796 | // BrowsingDataRemover takes care of deleting itself when done. |
| 797 | } |
| 798 | |
[email protected] | e1d16eb9 | 2011-08-18 23:19:32 | [diff] [blame] | 799 | FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { |
| 800 | return download_util::GetDefaultDownloadDirectory(); |
| 801 | } |
| 802 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 803 | #if defined(OS_LINUX) |
| 804 | int ChromeContentBrowserClient::GetCrashSignalFD( |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame^] | 805 | const CommandLine& command_line) { |
| 806 | if (command_line.HasSwitch(switches::kExtensionProcess)) { |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 807 | ExtensionCrashHandlerHostLinux* crash_handler = |
| 808 | ExtensionCrashHandlerHostLinux::GetInstance(); |
| 809 | return crash_handler->GetDeathSignalSocket(); |
| 810 | } |
| 811 | |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame^] | 812 | std::string process_type = |
| 813 | command_line.GetSwitchValueASCII(switches::kProcessType); |
| 814 | |
| 815 | if (process_type == switches::kRendererProcess) |
| 816 | return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 817 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 818 | if (process_type == switches::kPluginProcess) |
| 819 | return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 820 | |
| 821 | if (process_type == switches::kPpapiPluginProcess) |
| 822 | return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 823 | |
| 824 | if (process_type == switches::kGpuProcess) |
| 825 | return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 826 | |
| 827 | return -1; |
| 828 | } |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 829 | #endif // defined(OS_LINUX) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 830 | |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 831 | #if defined(OS_WIN) |
| 832 | const wchar_t* ChromeContentBrowserClient::GetResourceDllName() { |
| 833 | return chrome::kBrowserResourcesDll; |
| 834 | } |
| 835 | #endif |
| 836 | |
[email protected] | 37a72af | 2011-06-13 05:42:01 | [diff] [blame] | 837 | #if defined(USE_NSS) |
| 838 | crypto::CryptoModuleBlockingPasswordDelegate* |
| 839 | ChromeContentBrowserClient::GetCryptoPasswordDelegate( |
| 840 | const GURL& url) { |
| 841 | return browser::NewCryptoModuleBlockingDialogDelegate( |
| 842 | browser::kCryptoModulePasswordKeygen, url.host()); |
| 843 | } |
| 844 | #endif |
| 845 | |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 846 | } // namespace chrome |