blob: 3cc99b843bc57b8f01fb6d6f6fd855ea1c620e86 [file] [log] [blame]
[email protected]d977f9c2011-03-14 16:10:261// 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]b80f68432011-05-02 17:22:307#include "base/command_line.h"
8#include "chrome/app/breakpad_mac.h"
9#include "chrome/browser/browser_process.h"
[email protected]763ec4ca2011-04-29 15:48:1210#include "chrome/browser/character_encoding.h"
[email protected]97e6c4c2011-05-18 16:08:5111#include "chrome/browser/chrome_plugin_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4112#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]5327dfb2011-05-03 17:50:3613#include "chrome/browser/chrome_worker_message_filter.h"
[email protected]a2176792011-05-08 19:30:4914#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3215#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]941623e2011-06-07 23:06:0416#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1017#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2618#include "chrome/browser/extensions/extension_service.h"
[email protected]763ec4ca2011-04-29 15:48:1219#include "chrome/browser/google/google_util.h"
[email protected]941623e2011-06-07 23:06:0420#include "chrome/browser/notifications/desktop_notification_service.h"
21#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4222#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1223#include "chrome/browser/prefs/pref_service.h"
[email protected]05fcf982011-04-19 00:44:1424#include "chrome/browser/printing/printing_message_filter.h"
25#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3226#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1427#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3328#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]d4cff272011-05-02 15:46:0129#include "chrome/browser/renderer_host/text_input_client_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1430#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
31#include "chrome/browser/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4532#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0333#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]181a95ee2011-07-12 19:26:3634#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
[email protected]8ec26472011-06-06 16:52:4535#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]1fd1a502011-03-30 16:55:5638#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]b80f68432011-05-02 17:22:3039#include "chrome/common/child_process_logging.h"
40#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0441#include "chrome/common/extensions/extension.h"
[email protected]c5dbef02011-05-13 05:06:0942#include "chrome/common/extensions/extension_messages.h"
[email protected]f1933792011-06-14 00:49:3443#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1244#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3845#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0946#include "chrome/common/url_constants.h"
47#include "content/browser/browsing_instance.h"
48#include "content/browser/child_process_security_policy.h"
[email protected]b46442d7e2011-06-29 02:16:0649#include "content/browser/debugger/devtools_handler.h"
[email protected]97e6c4c2011-05-18 16:08:5150#include "content/browser/plugin_process_host.h"
[email protected]05fcf982011-04-19 00:44:1451#include "content/browser/renderer_host/browser_render_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2652#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4953#include "content/browser/resource_context.h"
[email protected]c5dbef02011-05-13 05:06:0954#include "content/browser/site_instance.h"
[email protected]8ec26472011-06-06 16:52:4555#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]763ec4ca2011-04-29 15:48:1256#include "content/browser/tab_contents/tab_contents.h"
[email protected]5327dfb2011-05-03 17:50:3657#include "content/browser/worker_host/worker_process_host.h"
[email protected]c5dbef02011-05-13 05:06:0958#include "content/common/bindings_policy.h"
[email protected]941623e2011-06-07 23:06:0459#include "content/common/desktop_notification_messages.h"
[email protected]29b25d092011-06-29 20:57:3460#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0161#include "net/base/cookie_monster.h"
62#include "net/base/cookie_options.h"
[email protected]ac55e292011-06-24 05:16:0863#include "ui/base/resource/resource_bundle.h"
[email protected]d977f9c2011-03-14 16:10:2664
[email protected]b80f68432011-05-02 17:22:3065#if defined(OS_LINUX)
66#include "base/linux_util.h"
67#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:4368#endif
[email protected]b80f68432011-05-02 17:22:3069
[email protected]37a72af2011-06-13 05:42:0170#if defined(USE_NSS)
71#include "chrome/browser/ui/crypto_module_password_dialog.h"
72#endif
73
[email protected]c5dbef02011-05-13 05:06:0974namespace {
75
76void 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]056ad2a2011-07-12 02:13:55102 // Register the association between extension and SiteInstance with
[email protected]c5dbef02011-05-13 05:06:09103 // ExtensionProcessManager.
[email protected]056ad2a2011-07-12 02:13:55104 // TODO(creis): Use this to replace SetInstalledAppForRenderer below.
105 process_manager->RegisterExtensionSiteInstance(site_instance->id(),
106 extension->id());
[email protected]c5dbef02011-05-13 05:06:09107
[email protected]80675fc2011-06-21 02:05:49108 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]c5dbef02011-05-13 05:06:09114 service->SetInstalledAppForRenderer(process->id(), extension);
[email protected]80675fc2011-06-21 02:05:49115 }
[email protected]c5dbef02011-05-13 05:06:09116
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]2333bf22011-05-19 02:16:51128 type == Extension::TYPE_USER_SCRIPT ||
[email protected]c5dbef02011-05-13 05:06:09129 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]9dbfff12011-07-01 19:37:07137} // namespace
[email protected]c5dbef02011-05-13 05:06:09138
[email protected]d977f9c2011-03-14 16:10:26139namespace chrome {
140
[email protected]f364d1392011-04-08 21:03:10141void ChromeContentBrowserClient::RenderViewHostCreated(
142 RenderViewHost* render_view_host) {
[email protected]53a0afa2011-04-28 02:09:33143 new ChromeRenderViewHostObserver(render_view_host);
[email protected]f364d1392011-04-08 21:03:10144 new DevToolsHandler(render_view_host);
145 new ExtensionMessageHandler(render_view_host);
[email protected]f364d1392011-04-08 21:03:10146
[email protected]c5dbef02011-05-13 05:06:09147 InitRenderViewHostForExtensions(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26148}
149
[email protected]05fcf982011-04-19 00:44:14150void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
151 BrowserRenderProcessHost* host) {
[email protected]c47cfd62011-04-29 21:27:02152 int id = host->id();
153 Profile* profile = host->profile();
[email protected]05fcf982011-04-19 00:44:14154 host->channel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02155 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]05fcf982011-04-19 00:44:14156 host->channel()->AddFilter(new PrintingMessageFilter());
157 host->channel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02158 new SearchProviderInstallStateMessageFilter(id, profile));
159 host->channel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]d4cff272011-05-02 15:46:01160#if defined(OS_MACOSX)
161 host->channel()->AddFilter(new TextInputClientMessageFilter(host->id()));
162#endif
[email protected]3e69bc82011-05-26 23:22:38163
164 host->Send(new ViewMsg_SetIsIncognitoProcess(profile->IsOffTheRecord()));
[email protected]05fcf982011-04-19 00:44:14165}
166
[email protected]97e6c4c2011-05-18 16:08:51167void ChromeContentBrowserClient::PluginProcessHostCreated(
168 PluginProcessHost* host) {
169 host->AddFilter(new ChromePluginMessageFilter(host));
170}
171
[email protected]5327dfb2011-05-03 17:50:36172void ChromeContentBrowserClient::WorkerProcessHostCreated(
173 WorkerProcessHost* host) {
174 host->AddFilter(new ChromeWorkerMessageFilter(host));
175}
176
[email protected]1fd1a502011-03-30 16:55:56177content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
178 return ChromeWebUIFactory::GetInstance();
179}
180
[email protected]36fb2c7c2011-04-04 15:49:08181GURL 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]056ad2a2011-07-12 02:13:55200bool 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]0f012df82011-05-19 14:15:29230bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03231 return url == GURL(chrome::kChromeUICrashURL) ||
232 url == GURL(chrome::kChromeUIKillURL) ||
233 url == GURL(chrome::kChromeUIHangURL) ||
234 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29235}
236
[email protected]763ec4ca2011-04-29 15:48:12237std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
238 const std::string& alias_name) {
239 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
240}
241
[email protected]b80f68432011-05-02 17:22:30242void 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]f1933792011-06-14 00:49:34256 if (logging::DialogsAreSuppressed())
257 command_line->AppendSwitch(switches::kNoErrorDialogs);
258
[email protected]b80f68432011-05-02 17:22:30259 std::string process_type =
260 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17261 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]b80f68432011-05-02 17:22:30262 if (process_type == switches::kExtensionProcess ||
263 process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30264 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]4287a3d2011-06-13 23:56:51289
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]3cb054e62011-06-13 05:21:17331 } else if (process_type == switches::kUtilityProcess) {
332 if (browser_command_line.HasSwitch(
333 switches::kEnableExperimentalExtensionApis)) {
334 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
335 }
[email protected]4287a3d2011-06-13 23:56:51336 } 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]b80f68432011-05-02 17:22:30360 }
361}
362
363std::string ChromeContentBrowserClient::GetApplicationLocale() {
364 return g_browser_process->GetApplicationLocale();
365}
366
[email protected]b5cca982011-05-26 04:42:08367std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
368 return tab->profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
369}
370
[email protected]ac55e292011-06-24 05:16:08371SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
372 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
373 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
374}
375
[email protected]a2176792011-05-08 19:30:49376bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09377 const GURL& manifest_url,
378 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
380 ProfileIOData* io_data =
381 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09382 // FIXME(jochen): get the correct top-level origin.
[email protected]efa55212011-05-13 16:19:38383 ContentSetting setting = io_data->GetHostContentSettingsMap()->
[email protected]5b52ad42011-05-26 14:26:09384 GetCookieContentSetting(manifest_url, manifest_url, true);
[email protected]a2176792011-05-08 19:30:49385 DCHECK(setting != CONTENT_SETTING_DEFAULT);
386 return setting != CONTENT_SETTING_BLOCK;
387}
388
[email protected]ed24fad2011-05-10 22:44:01389bool 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]8093a542011-05-13 07:29:32397 ProfileIOData* io_data =
398 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09399 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]ed24fad2011-05-10 22:44:01403
[email protected]8093a542011-05-13 07:29:32404 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]ed24fad2011-05-10 22:44:01409 return allow;
410}
411
412bool 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]8093a542011-05-13 07:29:32421 ProfileIOData* io_data =
422 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09423 ContentSetting setting = io_data->GetHostContentSettingsMap()->
424 GetCookieContentSetting(url, first_party, true);
[email protected]ed24fad2011-05-10 22:44:01425
[email protected]5b52ad42011-05-26 14:26:09426 if (setting == CONTENT_SETTING_SESSION_ONLY)
427 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01428
[email protected]5b52ad42011-05-26 14:26:09429 bool allow = setting == CONTENT_SETTING_ALLOW ||
430 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01431
[email protected]8093a542011-05-13 07:29:32432 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]ed24fad2011-05-10 22:44:01438 return allow;
439}
440
[email protected]d5a19162011-06-30 18:51:54441bool 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]6133f922011-07-01 21:34:34449net::URLRequestContext*
450ChromeContentBrowserClient::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]317f96c92011-05-31 06:53:41462QuotaPermissionContext*
463ChromeContentBrowserClient::CreateQuotaPermissionContext() {
464 return new ChromeQuotaPermissionContext();
465}
466
[email protected]0609b17f2011-05-31 20:13:42467void 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]848dd042011-06-04 18:24:03479void 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]8ec26472011-06-06 16:52:45488void 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
504void 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]941623e2011-06-07 23:06:04513void 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
533WebKit::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]0d3e4a22011-06-23 19:02:52544 extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) {
[email protected]941623e2011-06-07 23:06:04545 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
555void 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
576void 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]9f3fba52011-06-08 20:37:19594bool 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]0d3e4a22011-06-23 19:02:52607 extension->HasAPIPermission(ExtensionAPIPermission::kBackground));
[email protected]9f3fba52011-06-08 20:37:19608 }
609 return true;
610}
611
612std::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]3cb054e62011-06-13 05:21:17624ResourceDispatcherHost*
625 ChromeContentBrowserClient::GetResourceDispatcherHost() {
626 return g_browser_process->resource_dispatcher_host();
627}
628
629ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
630 return g_browser_process->clipboard();
631}
632
[email protected]dbae6b02011-06-29 23:51:41633bool ChromeContentBrowserClient::IsFastShutdownPossible() {
634 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
635 return !browser_command_line.HasSwitch(switches::kChromeFrame);
636}
637
[email protected]181a95ee2011-07-12 19:26:36638WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(Profile* profile,
639 bool is_web_ui) {
640 return RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_web_ui);
641}
642
643void ChromeContentBrowserClient::UpdateInspectorSetting(
644 RenderViewHost* rvh, const std::string& key, const std::string& value) {
645 RenderViewHostDelegateHelper::UpdateInspectorSetting(
646 rvh->process()->profile(), key, value);
647}
648
649void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
650 RenderViewHostDelegateHelper::ClearInspectorSettings(
651 rvh->process()->profile());
652}
653
[email protected]b80f68432011-05-02 17:22:30654#if defined(OS_LINUX)
655int ChromeContentBrowserClient::GetCrashSignalFD(
656 const std::string& process_type) {
657 if (process_type == switches::kRendererProcess)
658 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
659
[email protected]9dbfff12011-07-01 19:37:07660 if (process_type == switches::kExtensionProcess) {
661 ExtensionCrashHandlerHostLinux* crash_handler =
662 ExtensionCrashHandlerHostLinux::GetInstance();
663 return crash_handler->GetDeathSignalSocket();
664 }
665
[email protected]b80f68432011-05-02 17:22:30666 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]9dbfff12011-07-01 19:37:07677#endif // defined(OS_LINUX)
[email protected]b80f68432011-05-02 17:22:30678
[email protected]37a72af2011-06-13 05:42:01679#if defined(USE_NSS)
680crypto::CryptoModuleBlockingPasswordDelegate*
681 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
682 const GURL& url) {
683 return browser::NewCryptoModuleBlockingDialogDelegate(
684 browser::kCryptoModulePasswordKeygen, url.host());
685}
686#endif
687
[email protected]d977f9c2011-03-14 16:10:26688} // namespace chrome