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