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