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