blob: 8f780c3ecbdda88e878dfb0df16594cd8b284f58 [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,
[email protected]be9d9c82011-07-13 04:17:31295 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51296 switches::kDebugPrint,
297#if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) && !defined(OS_MACOSX)
298 // Enabled by default in Google Chrome builds, except on CrOS.
299 switches::kDisablePrintPreview,
300#else
301 // Disabled by default in Chromium builds and on CrOS.
302 switches::kEnablePrintPreview,
303#endif
304 switches::kDomAutomationController,
305 switches::kDumpHistogramsOnExit,
306 switches::kEnableClickToPlay,
307 switches::kEnableCrxlessWebApps,
308 switches::kEnableExperimentalExtensionApis,
309 switches::kEnableInBrowserThumbnailing,
310 switches::kEnableIPCFuzzing,
311 switches::kEnableNaCl,
312 switches::kEnableRemoting,
313 switches::kEnableResourceContentSettings,
314 switches::kEnableSearchProviderApiV2,
315 switches::kEnableWatchdog,
316 switches::kExperimentalSpellcheckerFeatures,
317 switches::kMemoryProfiling,
318 switches::kMessageLoopHistogrammer,
319 switches::kPpapiFlashArgs,
320 switches::kPpapiFlashInProcess,
321 switches::kPpapiFlashPath,
322 switches::kPpapiFlashVersion,
323 switches::kProfilingAtStart,
324 switches::kProfilingFile,
325 switches::kProfilingFlush,
326 switches::kRemoteShellPort,
327 switches::kSilentDumpOnDCHECK,
328 };
329
330 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
331 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17332 } else if (process_type == switches::kUtilityProcess) {
333 if (browser_command_line.HasSwitch(
334 switches::kEnableExperimentalExtensionApis)) {
335 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
336 }
[email protected]4287a3d2011-06-13 23:56:51337 } else if (process_type == switches::kPluginProcess) {
338 static const char* const kSwitchNames[] = {
339 #if defined(OS_CHROMEOS)
340 switches::kLoginProfile,
341 #endif
342 switches::kMemoryProfiling,
343 switches::kSilentDumpOnDCHECK,
344 switches::kUserDataDir,
345 };
346
347 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
348 arraysize(kSwitchNames));
349 } else if (process_type == switches::kZygoteProcess) {
350 static const char* const kSwitchNames[] = {
351 switches::kEnableRemoting,
352 switches::kUserDataDir, // Make logs go to the right file.
353 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
354 switches::kPpapiFlashInProcess,
355 switches::kPpapiFlashPath,
356 switches::kPpapiFlashVersion,
357 };
358
359 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
360 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30361 }
362}
363
364std::string ChromeContentBrowserClient::GetApplicationLocale() {
365 return g_browser_process->GetApplicationLocale();
366}
367
[email protected]b5cca982011-05-26 04:42:08368std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
369 return tab->profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
370}
371
[email protected]ac55e292011-06-24 05:16:08372SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
373 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
374 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
375}
376
[email protected]a2176792011-05-08 19:30:49377bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09378 const GURL& manifest_url,
379 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
381 ProfileIOData* io_data =
382 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09383 // FIXME(jochen): get the correct top-level origin.
[email protected]efa55212011-05-13 16:19:38384 ContentSetting setting = io_data->GetHostContentSettingsMap()->
[email protected]5b52ad42011-05-26 14:26:09385 GetCookieContentSetting(manifest_url, manifest_url, true);
[email protected]a2176792011-05-08 19:30:49386 DCHECK(setting != CONTENT_SETTING_DEFAULT);
387 return setting != CONTENT_SETTING_BLOCK;
388}
389
[email protected]ed24fad2011-05-10 22:44:01390bool ChromeContentBrowserClient::AllowGetCookie(
391 const GURL& url,
392 const GURL& first_party,
393 const net::CookieList& cookie_list,
394 const content::ResourceContext& context,
395 int render_process_id,
396 int render_view_id) {
397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32398 ProfileIOData* io_data =
399 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09400 ContentSetting setting = io_data->GetHostContentSettingsMap()->
401 GetCookieContentSetting(url, first_party, false);
402 bool allow = setting == CONTENT_SETTING_ALLOW ||
403 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01404
[email protected]8093a542011-05-13 07:29:32405 BrowserThread::PostTask(
406 BrowserThread::UI, FROM_HERE,
407 NewRunnableFunction(
408 &TabSpecificContentSettings::CookiesRead,
409 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01410 return allow;
411}
412
413bool ChromeContentBrowserClient::AllowSetCookie(
414 const GURL& url,
415 const GURL& first_party,
416 const std::string& cookie_line,
417 const content::ResourceContext& context,
418 int render_process_id,
419 int render_view_id,
420 net::CookieOptions* options) {
421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32422 ProfileIOData* io_data =
423 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09424 ContentSetting setting = io_data->GetHostContentSettingsMap()->
425 GetCookieContentSetting(url, first_party, true);
[email protected]ed24fad2011-05-10 22:44:01426
[email protected]5b52ad42011-05-26 14:26:09427 if (setting == CONTENT_SETTING_SESSION_ONLY)
428 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01429
[email protected]5b52ad42011-05-26 14:26:09430 bool allow = setting == CONTENT_SETTING_ALLOW ||
431 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01432
[email protected]8093a542011-05-13 07:29:32433 BrowserThread::PostTask(
434 BrowserThread::UI, FROM_HERE,
435 NewRunnableFunction(
436 &TabSpecificContentSettings::CookieChanged,
437 render_process_id, render_view_id, url, cookie_line, *options,
438 !allow));
[email protected]ed24fad2011-05-10 22:44:01439 return allow;
440}
441
[email protected]d5a19162011-06-30 18:51:54442bool ChromeContentBrowserClient::AllowSaveLocalState(
443 const content::ResourceContext& context) {
444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
445 ProfileIOData* io_data =
446 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
447 return !io_data->clear_local_state_on_exit()->GetValue();
448}
449
[email protected]6133f922011-07-01 21:34:34450net::URLRequestContext*
451ChromeContentBrowserClient::OverrideRequestContextForURL(
452 const GURL& url, const content::ResourceContext& context) {
453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
454 if (url.SchemeIs(chrome::kExtensionScheme)) {
455 ProfileIOData* io_data =
456 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
457 return io_data->extensions_request_context();
458 }
459
460 return NULL;
461}
462
[email protected]317f96c92011-05-31 06:53:41463QuotaPermissionContext*
464ChromeContentBrowserClient::CreateQuotaPermissionContext() {
465 return new ChromeQuotaPermissionContext();
466}
467
[email protected]0609b17f2011-05-31 20:13:42468void ChromeContentBrowserClient::RevealFolderInOS(const FilePath& path) {
469 // On Mac, this call needs to be done on the UI thread. On other platforms,
470 // do it on the FILE thread so we don't slow down UI.
471#if defined(OS_MACOSX)
472 platform_util::OpenItem(path);
473#else
474 BrowserThread::PostTask(
475 BrowserThread::FILE, FROM_HERE,
476 NewRunnableFunction(&platform_util::OpenItem, path));
477#endif
478}
479
[email protected]848dd042011-06-04 18:24:03480void ChromeContentBrowserClient::AllowCertificateError(
481 SSLCertErrorHandler* handler,
482 bool overridable,
483 Callback2<SSLCertErrorHandler*, bool>::Type* callback) {
484 SSLBlockingPage* blocking_page = new SSLBlockingPage(
485 handler, overridable, callback);
486 blocking_page->Show();
487}
488
[email protected]8ec26472011-06-06 16:52:45489void ChromeContentBrowserClient::ShowClientCertificateRequestDialog(
490 int render_process_id,
491 int render_view_id,
492 SSLClientAuthHandler* handler) {
493 TabContents* tab = tab_util::GetTabContentsByID(
494 render_process_id, render_view_id);
495 if (!tab) {
496 NOTREACHED();
497 return;
498 }
499
500 TabContentsWrapper* wrapper =
501 TabContentsWrapper::GetCurrentWrapperForContents(tab);
502 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler);
503}
504
505void ChromeContentBrowserClient::AddNewCertificate(
506 net::URLRequest* request,
507 net::X509Certificate* cert,
508 int render_process_id,
509 int render_view_id) {
510 // The handler will run the UI and delete itself when it's finished.
511 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
512}
513
[email protected]941623e2011-06-07 23:06:04514void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
515 const GURL& source_origin,
516 int callback_context,
517 int render_process_id,
518 int render_view_id) {
519 RenderViewHost* rvh = RenderViewHost::FromID(
520 render_process_id, render_view_id);
521 if (!rvh) {
522 NOTREACHED();
523 return;
524 }
525
526 RenderProcessHost* process = rvh->process();
527 DesktopNotificationService* service =
528 DesktopNotificationServiceFactory::GetForProfile(process->profile());
529 service->RequestPermission(
530 source_origin, render_process_id, render_view_id, callback_context,
531 tab_util::GetTabContentsByID(render_process_id, render_view_id));
532}
533
534WebKit::WebNotificationPresenter::Permission
535 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
536 const GURL& source_url,
537 const content::ResourceContext& context) {
538 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
539 ProfileIOData* io_data =
540 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
541
542 const Extension* extension =
543 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
544 if (extension &&
[email protected]0d3e4a22011-06-23 19:02:52545 extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) {
[email protected]941623e2011-06-07 23:06:04546 return WebKit::WebNotificationPresenter::PermissionAllowed;
547 }
548
549 // Fall back to the regular notification preferences, which works on an
550 // origin basis.
551 return io_data->GetNotificationService() ?
552 io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) :
553 WebKit::WebNotificationPresenter::PermissionNotAllowed;
554}
555
556void ChromeContentBrowserClient::ShowDesktopNotification(
557 const DesktopNotificationHostMsg_Show_Params& params,
558 int render_process_id,
559 int render_view_id,
560 bool worker) {
561 RenderViewHost* rvh = RenderViewHost::FromID(
562 render_process_id, render_view_id);
563 if (!rvh) {
564 NOTREACHED();
565 return;
566 }
567
568 RenderProcessHost* process = rvh->process();
569 DesktopNotificationService* service =
570 DesktopNotificationServiceFactory::GetForProfile(process->profile());
571 service->ShowDesktopNotification(
572 params, render_process_id, render_view_id,
573 worker ? DesktopNotificationService::WorkerNotification :
574 DesktopNotificationService::PageNotification);
575}
576
577void ChromeContentBrowserClient::CancelDesktopNotification(
578 int render_process_id,
579 int render_view_id,
580 int notification_id) {
581 RenderViewHost* rvh = RenderViewHost::FromID(
582 render_process_id, render_view_id);
583 if (!rvh) {
584 NOTREACHED();
585 return;
586 }
587
588 RenderProcessHost* process = rvh->process();
589 DesktopNotificationService* service =
590 DesktopNotificationServiceFactory::GetForProfile(process->profile());
591 service->CancelDesktopNotification(
592 render_process_id, render_view_id, notification_id);
593}
594
[email protected]9f3fba52011-06-08 20:37:19595bool ChromeContentBrowserClient::CanCreateWindow(
596 const GURL& source_url,
597 WindowContainerType container_type,
598 const content::ResourceContext& context) {
599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
600 // If the opener is trying to create a background window but doesn't have
601 // the appropriate permission, fail the attempt.
602 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
603 ProfileIOData* io_data =
604 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
605 const Extension* extension =
606 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
607 return (extension &&
[email protected]0d3e4a22011-06-23 19:02:52608 extension->HasAPIPermission(ExtensionAPIPermission::kBackground));
[email protected]9f3fba52011-06-08 20:37:19609 }
610 return true;
611}
612
613std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
614 const GURL& url, const content::ResourceContext& context) {
615 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
616 // Check if it's an extension-created worker, in which case we want to use
617 // the name of the extension.
618 ProfileIOData* io_data =
619 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
620 const Extension* extension =
621 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
622 return extension ? extension->name() : std::string();
623}
624
[email protected]3cb054e62011-06-13 05:21:17625ResourceDispatcherHost*
626 ChromeContentBrowserClient::GetResourceDispatcherHost() {
627 return g_browser_process->resource_dispatcher_host();
628}
629
630ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
631 return g_browser_process->clipboard();
632}
633
[email protected]dbae6b02011-06-29 23:51:41634bool ChromeContentBrowserClient::IsFastShutdownPossible() {
635 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
636 return !browser_command_line.HasSwitch(switches::kChromeFrame);
637}
638
[email protected]181a95ee2011-07-12 19:26:36639WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(Profile* profile,
640 bool is_web_ui) {
641 return RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_web_ui);
642}
643
644void ChromeContentBrowserClient::UpdateInspectorSetting(
645 RenderViewHost* rvh, const std::string& key, const std::string& value) {
646 RenderViewHostDelegateHelper::UpdateInspectorSetting(
647 rvh->process()->profile(), key, value);
648}
649
650void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
651 RenderViewHostDelegateHelper::ClearInspectorSettings(
652 rvh->process()->profile());
653}
654
[email protected]b80f68432011-05-02 17:22:30655#if defined(OS_LINUX)
656int ChromeContentBrowserClient::GetCrashSignalFD(
657 const std::string& process_type) {
658 if (process_type == switches::kRendererProcess)
659 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
660
[email protected]9dbfff12011-07-01 19:37:07661 if (process_type == switches::kExtensionProcess) {
662 ExtensionCrashHandlerHostLinux* crash_handler =
663 ExtensionCrashHandlerHostLinux::GetInstance();
664 return crash_handler->GetDeathSignalSocket();
665 }
666
[email protected]b80f68432011-05-02 17:22:30667 if (process_type == switches::kPluginProcess)
668 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
669
670 if (process_type == switches::kPpapiPluginProcess)
671 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
672
673 if (process_type == switches::kGpuProcess)
674 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
675
676 return -1;
677}
[email protected]9dbfff12011-07-01 19:37:07678#endif // defined(OS_LINUX)
[email protected]b80f68432011-05-02 17:22:30679
[email protected]37a72af2011-06-13 05:42:01680#if defined(USE_NSS)
681crypto::CryptoModuleBlockingPasswordDelegate*
682 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
683 const GURL& url) {
684 return browser::NewCryptoModuleBlockingDialogDelegate(
685 browser::kCryptoModulePasswordKeygen, url.host());
686}
687#endif
688
[email protected]d977f9c2011-03-14 16:10:26689} // namespace chrome