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