blob: 5226137e29db759ce04713e188e5eec9bb58faa4 [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]8ec26472011-06-06 16:52:4534#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
35#include "chrome/browser/tab_contents/tab_util.h"
36#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]1fd1a502011-03-30 16:55:5637#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]b80f68432011-05-02 17:22:3038#include "chrome/common/child_process_logging.h"
39#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0440#include "chrome/common/extensions/extension.h"
[email protected]c5dbef02011-05-13 05:06:0941#include "chrome/common/extensions/extension_messages.h"
[email protected]f1933792011-06-14 00:49:3442#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1243#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3844#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0945#include "chrome/common/url_constants.h"
46#include "content/browser/browsing_instance.h"
47#include "content/browser/child_process_security_policy.h"
[email protected]b46442d7e2011-06-29 02:16:0648#include "content/browser/debugger/devtools_handler.h"
[email protected]97e6c4c2011-05-18 16:08:5149#include "content/browser/plugin_process_host.h"
[email protected]05fcf982011-04-19 00:44:1450#include "content/browser/renderer_host/browser_render_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2651#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4952#include "content/browser/resource_context.h"
[email protected]c5dbef02011-05-13 05:06:0953#include "content/browser/site_instance.h"
[email protected]8ec26472011-06-06 16:52:4554#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]763ec4ca2011-04-29 15:48:1255#include "content/browser/tab_contents/tab_contents.h"
[email protected]5327dfb2011-05-03 17:50:3656#include "content/browser/worker_host/worker_process_host.h"
[email protected]c5dbef02011-05-13 05:06:0957#include "content/common/bindings_policy.h"
[email protected]941623e2011-06-07 23:06:0458#include "content/common/desktop_notification_messages.h"
[email protected]29b25d092011-06-29 20:57:3459#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0160#include "net/base/cookie_monster.h"
61#include "net/base/cookie_options.h"
[email protected]ac55e292011-06-24 05:16:0862#include "ui/base/resource/resource_bundle.h"
[email protected]d977f9c2011-03-14 16:10:2663
[email protected]b80f68432011-05-02 17:22:3064#if defined(OS_LINUX)
65#include "base/linux_util.h"
66#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:4367#endif
[email protected]b80f68432011-05-02 17:22:3068
[email protected]37a72af2011-06-13 05:42:0169#if defined(USE_NSS)
70#include "chrome/browser/ui/crypto_module_password_dialog.h"
71#endif
72
[email protected]c5dbef02011-05-13 05:06:0973namespace {
74
75void InitRenderViewHostForExtensions(RenderViewHost* render_view_host) {
76 // Note that due to GetEffectiveURL(), even hosted apps will have a
77 // chrome-extension:// URL for their site, so we can ignore that wrinkle here.
78 SiteInstance* site_instance = render_view_host->site_instance();
79 const GURL& site = site_instance->site();
80 RenderProcessHost* process = render_view_host->process();
81
82 if (!site.SchemeIs(chrome::kExtensionScheme))
83 return;
84
85 Profile* profile = site_instance->browsing_instance()->profile();
86 ExtensionService* service = profile->GetExtensionService();
87 if (!service)
88 return;
89
90 ExtensionProcessManager* process_manager =
91 profile->GetExtensionProcessManager();
92 CHECK(process_manager);
93
94 // This can happen if somebody typos a chrome-extension:// URL.
95 const Extension* extension = service->GetExtensionByURL(site);
96 if (!extension)
97 return;
98
99 site_instance->GetProcess()->mark_is_extension_process();
100
101 // Register the association between extension and process with
102 // ExtensionProcessManager.
103 process_manager->RegisterExtensionProcess(extension->id(), process->id());
104
[email protected]80675fc2011-06-21 02:05:49105 if (extension->is_app()) {
106 render_view_host->Send(
107 new ExtensionMsg_ActivateApplication(extension->id()));
108 // Record which, if any, installed app is associated with this process.
109 // TODO(aa): Totally lame to store this state in a global map in extension
110 // service. Can we get it from EPM instead?
[email protected]c5dbef02011-05-13 05:06:09111 service->SetInstalledAppForRenderer(process->id(), extension);
[email protected]80675fc2011-06-21 02:05:49112 }
[email protected]c5dbef02011-05-13 05:06:09113
114 // Some extensions use chrome:// URLs.
115 Extension::Type type = extension->GetType();
116 if (type == Extension::TYPE_EXTENSION ||
117 type == Extension::TYPE_PACKAGED_APP) {
118 ChildProcessSecurityPolicy::GetInstance()->GrantScheme(
119 process->id(), chrome::kChromeUIScheme);
120 }
121
122 // Enable extension bindings for the renderer. Currently only extensions,
123 // packaged apps, and hosted component apps use extension bindings.
124 if (type == Extension::TYPE_EXTENSION ||
[email protected]2333bf22011-05-19 02:16:51125 type == Extension::TYPE_USER_SCRIPT ||
[email protected]c5dbef02011-05-13 05:06:09126 type == Extension::TYPE_PACKAGED_APP ||
127 (type == Extension::TYPE_HOSTED_APP &&
128 extension->location() == Extension::COMPONENT)) {
129 render_view_host->Send(new ExtensionMsg_ActivateExtension(extension->id()));
130 render_view_host->AllowBindings(BindingsPolicy::EXTENSION);
131 }
132}
133
[email protected]9dbfff12011-07-01 19:37:07134} // namespace
[email protected]c5dbef02011-05-13 05:06:09135
[email protected]d977f9c2011-03-14 16:10:26136namespace chrome {
137
[email protected]f364d1392011-04-08 21:03:10138void ChromeContentBrowserClient::RenderViewHostCreated(
139 RenderViewHost* render_view_host) {
[email protected]53a0afa2011-04-28 02:09:33140 new ChromeRenderViewHostObserver(render_view_host);
[email protected]f364d1392011-04-08 21:03:10141 new DevToolsHandler(render_view_host);
142 new ExtensionMessageHandler(render_view_host);
[email protected]f364d1392011-04-08 21:03:10143
[email protected]c5dbef02011-05-13 05:06:09144 InitRenderViewHostForExtensions(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26145}
146
[email protected]05fcf982011-04-19 00:44:14147void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
148 BrowserRenderProcessHost* host) {
[email protected]c47cfd62011-04-29 21:27:02149 int id = host->id();
150 Profile* profile = host->profile();
[email protected]05fcf982011-04-19 00:44:14151 host->channel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02152 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]05fcf982011-04-19 00:44:14153 host->channel()->AddFilter(new PrintingMessageFilter());
154 host->channel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02155 new SearchProviderInstallStateMessageFilter(id, profile));
156 host->channel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]d4cff272011-05-02 15:46:01157#if defined(OS_MACOSX)
158 host->channel()->AddFilter(new TextInputClientMessageFilter(host->id()));
159#endif
[email protected]3e69bc82011-05-26 23:22:38160
161 host->Send(new ViewMsg_SetIsIncognitoProcess(profile->IsOffTheRecord()));
[email protected]05fcf982011-04-19 00:44:14162}
163
[email protected]97e6c4c2011-05-18 16:08:51164void ChromeContentBrowserClient::PluginProcessHostCreated(
165 PluginProcessHost* host) {
166 host->AddFilter(new ChromePluginMessageFilter(host));
167}
168
[email protected]5327dfb2011-05-03 17:50:36169void ChromeContentBrowserClient::WorkerProcessHostCreated(
170 WorkerProcessHost* host) {
171 host->AddFilter(new ChromeWorkerMessageFilter(host));
172}
173
[email protected]1fd1a502011-03-30 16:55:56174content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
175 return ChromeWebUIFactory::GetInstance();
176}
177
[email protected]36fb2c7c2011-04-04 15:49:08178GURL ChromeContentBrowserClient::GetEffectiveURL(Profile* profile,
179 const GURL& url) {
180 // Get the effective URL for the given actual URL. If the URL is part of an
181 // installed app, the effective URL is an extension URL with the ID of that
182 // extension as the host. This has the effect of grouping apps together in
183 // a common SiteInstance.
184 if (!profile || !profile->GetExtensionService())
185 return url;
186
187 const Extension* extension =
188 profile->GetExtensionService()->GetExtensionByWebExtent(url);
189 if (!extension)
190 return url;
191
192 // If the URL is part of an extension's web extent, convert it to an
193 // extension URL.
194 return extension->GetResourceURL(url.path());
195}
196
[email protected]0f012df82011-05-19 14:15:29197bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03198 return url == GURL(chrome::kChromeUICrashURL) ||
199 url == GURL(chrome::kChromeUIKillURL) ||
200 url == GURL(chrome::kChromeUIHangURL) ||
201 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29202}
203
[email protected]763ec4ca2011-04-29 15:48:12204std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
205 const std::string& alias_name) {
206 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
207}
208
[email protected]b80f68432011-05-02 17:22:30209void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
210 CommandLine* command_line, int child_process_id) {
211#if defined(USE_LINUX_BREAKPAD)
212 if (IsCrashReporterEnabled()) {
213 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
214 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
215 }
216#elif defined(OS_MACOSX)
217 if (IsCrashReporterEnabled()) {
218 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
219 child_process_logging::GetClientId());
220 }
221#endif // OS_MACOSX
222
[email protected]f1933792011-06-14 00:49:34223 if (logging::DialogsAreSuppressed())
224 command_line->AppendSwitch(switches::kNoErrorDialogs);
225
[email protected]b80f68432011-05-02 17:22:30226 std::string process_type =
227 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17228 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]b80f68432011-05-02 17:22:30229 if (process_type == switches::kExtensionProcess ||
230 process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30231 FilePath user_data_dir =
232 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
233 if (!user_data_dir.empty())
234 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
235#if defined(OS_CHROMEOS)
236 const std::string& login_profile =
237 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
238 if (!login_profile.empty())
239 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
240#endif
241
242 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
243
244 PrefService* prefs = process->profile()->GetPrefs();
245 // Currently this pref is only registered if applied via a policy.
246 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
247 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
248 // Turn this policy into a command line switch.
249 command_line->AppendSwitch(switches::kDisable3DAPIs);
250 }
251
252 // Disable client-side phishing detection in the renderer if it is disabled
253 // in the browser process.
254 if (!g_browser_process->safe_browsing_detection_service())
255 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]4287a3d2011-06-13 23:56:51256
257 static const char* const kSwitchNames[] = {
258 switches::kAllowHTTPBackgroundPage,
259 switches::kAllowScriptingGallery,
260 switches::kAppsCheckoutURL,
261 switches::kAppsGalleryURL,
262 switches::kDebugPrint,
263#if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) && !defined(OS_MACOSX)
264 // Enabled by default in Google Chrome builds, except on CrOS.
265 switches::kDisablePrintPreview,
266#else
267 // Disabled by default in Chromium builds and on CrOS.
268 switches::kEnablePrintPreview,
269#endif
270 switches::kDomAutomationController,
271 switches::kDumpHistogramsOnExit,
272 switches::kEnableClickToPlay,
273 switches::kEnableCrxlessWebApps,
274 switches::kEnableExperimentalExtensionApis,
275 switches::kEnableInBrowserThumbnailing,
276 switches::kEnableIPCFuzzing,
277 switches::kEnableNaCl,
278 switches::kEnableRemoting,
279 switches::kEnableResourceContentSettings,
280 switches::kEnableSearchProviderApiV2,
281 switches::kEnableWatchdog,
282 switches::kExperimentalSpellcheckerFeatures,
283 switches::kMemoryProfiling,
284 switches::kMessageLoopHistogrammer,
285 switches::kPpapiFlashArgs,
286 switches::kPpapiFlashInProcess,
287 switches::kPpapiFlashPath,
288 switches::kPpapiFlashVersion,
289 switches::kProfilingAtStart,
290 switches::kProfilingFile,
291 switches::kProfilingFlush,
292 switches::kRemoteShellPort,
293 switches::kSilentDumpOnDCHECK,
294 };
295
296 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
297 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17298 } else if (process_type == switches::kUtilityProcess) {
299 if (browser_command_line.HasSwitch(
300 switches::kEnableExperimentalExtensionApis)) {
301 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
302 }
[email protected]4287a3d2011-06-13 23:56:51303 } else if (process_type == switches::kPluginProcess) {
304 static const char* const kSwitchNames[] = {
305 #if defined(OS_CHROMEOS)
306 switches::kLoginProfile,
307 #endif
308 switches::kMemoryProfiling,
309 switches::kSilentDumpOnDCHECK,
310 switches::kUserDataDir,
311 };
312
313 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
314 arraysize(kSwitchNames));
315 } else if (process_type == switches::kZygoteProcess) {
316 static const char* const kSwitchNames[] = {
317 switches::kEnableRemoting,
318 switches::kUserDataDir, // Make logs go to the right file.
319 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
320 switches::kPpapiFlashInProcess,
321 switches::kPpapiFlashPath,
322 switches::kPpapiFlashVersion,
323 };
324
325 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
326 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30327 }
328}
329
330std::string ChromeContentBrowserClient::GetApplicationLocale() {
331 return g_browser_process->GetApplicationLocale();
332}
333
[email protected]b5cca982011-05-26 04:42:08334std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
335 return tab->profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
336}
337
[email protected]ac55e292011-06-24 05:16:08338SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
339 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
340 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
341}
342
[email protected]a2176792011-05-08 19:30:49343bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09344 const GURL& manifest_url,
345 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32346 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
347 ProfileIOData* io_data =
348 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09349 // FIXME(jochen): get the correct top-level origin.
[email protected]efa55212011-05-13 16:19:38350 ContentSetting setting = io_data->GetHostContentSettingsMap()->
[email protected]5b52ad42011-05-26 14:26:09351 GetCookieContentSetting(manifest_url, manifest_url, true);
[email protected]a2176792011-05-08 19:30:49352 DCHECK(setting != CONTENT_SETTING_DEFAULT);
353 return setting != CONTENT_SETTING_BLOCK;
354}
355
[email protected]ed24fad2011-05-10 22:44:01356bool ChromeContentBrowserClient::AllowGetCookie(
357 const GURL& url,
358 const GURL& first_party,
359 const net::CookieList& cookie_list,
360 const content::ResourceContext& context,
361 int render_process_id,
362 int render_view_id) {
363 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32364 ProfileIOData* io_data =
365 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09366 ContentSetting setting = io_data->GetHostContentSettingsMap()->
367 GetCookieContentSetting(url, first_party, false);
368 bool allow = setting == CONTENT_SETTING_ALLOW ||
369 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01370
[email protected]8093a542011-05-13 07:29:32371 BrowserThread::PostTask(
372 BrowserThread::UI, FROM_HERE,
373 NewRunnableFunction(
374 &TabSpecificContentSettings::CookiesRead,
375 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01376 return allow;
377}
378
379bool ChromeContentBrowserClient::AllowSetCookie(
380 const GURL& url,
381 const GURL& first_party,
382 const std::string& cookie_line,
383 const content::ResourceContext& context,
384 int render_process_id,
385 int render_view_id,
386 net::CookieOptions* options) {
387 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32388 ProfileIOData* io_data =
389 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09390 ContentSetting setting = io_data->GetHostContentSettingsMap()->
391 GetCookieContentSetting(url, first_party, true);
[email protected]ed24fad2011-05-10 22:44:01392
[email protected]5b52ad42011-05-26 14:26:09393 if (setting == CONTENT_SETTING_SESSION_ONLY)
394 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01395
[email protected]5b52ad42011-05-26 14:26:09396 bool allow = setting == CONTENT_SETTING_ALLOW ||
397 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01398
[email protected]8093a542011-05-13 07:29:32399 BrowserThread::PostTask(
400 BrowserThread::UI, FROM_HERE,
401 NewRunnableFunction(
402 &TabSpecificContentSettings::CookieChanged,
403 render_process_id, render_view_id, url, cookie_line, *options,
404 !allow));
[email protected]ed24fad2011-05-10 22:44:01405 return allow;
406}
407
[email protected]d5a19162011-06-30 18:51:54408bool ChromeContentBrowserClient::AllowSaveLocalState(
409 const content::ResourceContext& context) {
410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
411 ProfileIOData* io_data =
412 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
413 return !io_data->clear_local_state_on_exit()->GetValue();
414}
415
[email protected]317f96c92011-05-31 06:53:41416QuotaPermissionContext*
417ChromeContentBrowserClient::CreateQuotaPermissionContext() {
418 return new ChromeQuotaPermissionContext();
419}
420
[email protected]0609b17f2011-05-31 20:13:42421void ChromeContentBrowserClient::RevealFolderInOS(const FilePath& path) {
422 // On Mac, this call needs to be done on the UI thread. On other platforms,
423 // do it on the FILE thread so we don't slow down UI.
424#if defined(OS_MACOSX)
425 platform_util::OpenItem(path);
426#else
427 BrowserThread::PostTask(
428 BrowserThread::FILE, FROM_HERE,
429 NewRunnableFunction(&platform_util::OpenItem, path));
430#endif
431}
432
[email protected]848dd042011-06-04 18:24:03433void ChromeContentBrowserClient::AllowCertificateError(
434 SSLCertErrorHandler* handler,
435 bool overridable,
436 Callback2<SSLCertErrorHandler*, bool>::Type* callback) {
437 SSLBlockingPage* blocking_page = new SSLBlockingPage(
438 handler, overridable, callback);
439 blocking_page->Show();
440}
441
[email protected]8ec26472011-06-06 16:52:45442void ChromeContentBrowserClient::ShowClientCertificateRequestDialog(
443 int render_process_id,
444 int render_view_id,
445 SSLClientAuthHandler* handler) {
446 TabContents* tab = tab_util::GetTabContentsByID(
447 render_process_id, render_view_id);
448 if (!tab) {
449 NOTREACHED();
450 return;
451 }
452
453 TabContentsWrapper* wrapper =
454 TabContentsWrapper::GetCurrentWrapperForContents(tab);
455 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler);
456}
457
458void ChromeContentBrowserClient::AddNewCertificate(
459 net::URLRequest* request,
460 net::X509Certificate* cert,
461 int render_process_id,
462 int render_view_id) {
463 // The handler will run the UI and delete itself when it's finished.
464 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
465}
466
[email protected]941623e2011-06-07 23:06:04467void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
468 const GURL& source_origin,
469 int callback_context,
470 int render_process_id,
471 int render_view_id) {
472 RenderViewHost* rvh = RenderViewHost::FromID(
473 render_process_id, render_view_id);
474 if (!rvh) {
475 NOTREACHED();
476 return;
477 }
478
479 RenderProcessHost* process = rvh->process();
480 DesktopNotificationService* service =
481 DesktopNotificationServiceFactory::GetForProfile(process->profile());
482 service->RequestPermission(
483 source_origin, render_process_id, render_view_id, callback_context,
484 tab_util::GetTabContentsByID(render_process_id, render_view_id));
485}
486
487WebKit::WebNotificationPresenter::Permission
488 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
489 const GURL& source_url,
490 const content::ResourceContext& context) {
491 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
492 ProfileIOData* io_data =
493 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
494
495 const Extension* extension =
496 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
497 if (extension &&
[email protected]0d3e4a22011-06-23 19:02:52498 extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) {
[email protected]941623e2011-06-07 23:06:04499 return WebKit::WebNotificationPresenter::PermissionAllowed;
500 }
501
502 // Fall back to the regular notification preferences, which works on an
503 // origin basis.
504 return io_data->GetNotificationService() ?
505 io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) :
506 WebKit::WebNotificationPresenter::PermissionNotAllowed;
507}
508
509void ChromeContentBrowserClient::ShowDesktopNotification(
510 const DesktopNotificationHostMsg_Show_Params& params,
511 int render_process_id,
512 int render_view_id,
513 bool worker) {
514 RenderViewHost* rvh = RenderViewHost::FromID(
515 render_process_id, render_view_id);
516 if (!rvh) {
517 NOTREACHED();
518 return;
519 }
520
521 RenderProcessHost* process = rvh->process();
522 DesktopNotificationService* service =
523 DesktopNotificationServiceFactory::GetForProfile(process->profile());
524 service->ShowDesktopNotification(
525 params, render_process_id, render_view_id,
526 worker ? DesktopNotificationService::WorkerNotification :
527 DesktopNotificationService::PageNotification);
528}
529
530void ChromeContentBrowserClient::CancelDesktopNotification(
531 int render_process_id,
532 int render_view_id,
533 int notification_id) {
534 RenderViewHost* rvh = RenderViewHost::FromID(
535 render_process_id, render_view_id);
536 if (!rvh) {
537 NOTREACHED();
538 return;
539 }
540
541 RenderProcessHost* process = rvh->process();
542 DesktopNotificationService* service =
543 DesktopNotificationServiceFactory::GetForProfile(process->profile());
544 service->CancelDesktopNotification(
545 render_process_id, render_view_id, notification_id);
546}
547
[email protected]9f3fba52011-06-08 20:37:19548bool ChromeContentBrowserClient::CanCreateWindow(
549 const GURL& source_url,
550 WindowContainerType container_type,
551 const content::ResourceContext& context) {
552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
553 // If the opener is trying to create a background window but doesn't have
554 // the appropriate permission, fail the attempt.
555 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
556 ProfileIOData* io_data =
557 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
558 const Extension* extension =
559 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
560 return (extension &&
[email protected]0d3e4a22011-06-23 19:02:52561 extension->HasAPIPermission(ExtensionAPIPermission::kBackground));
[email protected]9f3fba52011-06-08 20:37:19562 }
563 return true;
564}
565
566std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
567 const GURL& url, const content::ResourceContext& context) {
568 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
569 // Check if it's an extension-created worker, in which case we want to use
570 // the name of the extension.
571 ProfileIOData* io_data =
572 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
573 const Extension* extension =
574 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
575 return extension ? extension->name() : std::string();
576}
577
[email protected]3cb054e62011-06-13 05:21:17578ResourceDispatcherHost*
579 ChromeContentBrowserClient::GetResourceDispatcherHost() {
580 return g_browser_process->resource_dispatcher_host();
581}
582
583ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
584 return g_browser_process->clipboard();
585}
586
[email protected]dbae6b02011-06-29 23:51:41587bool ChromeContentBrowserClient::IsFastShutdownPossible() {
588 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
589 return !browser_command_line.HasSwitch(switches::kChromeFrame);
590}
591
[email protected]b80f68432011-05-02 17:22:30592#if defined(OS_LINUX)
593int ChromeContentBrowserClient::GetCrashSignalFD(
594 const std::string& process_type) {
595 if (process_type == switches::kRendererProcess)
596 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
597
[email protected]9dbfff12011-07-01 19:37:07598 if (process_type == switches::kExtensionProcess) {
599 ExtensionCrashHandlerHostLinux* crash_handler =
600 ExtensionCrashHandlerHostLinux::GetInstance();
601 return crash_handler->GetDeathSignalSocket();
602 }
603
[email protected]b80f68432011-05-02 17:22:30604 if (process_type == switches::kPluginProcess)
605 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
606
607 if (process_type == switches::kPpapiPluginProcess)
608 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
609
610 if (process_type == switches::kGpuProcess)
611 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
612
613 return -1;
614}
[email protected]9dbfff12011-07-01 19:37:07615#endif // defined(OS_LINUX)
[email protected]b80f68432011-05-02 17:22:30616
[email protected]37a72af2011-06-13 05:42:01617#if defined(USE_NSS)
618crypto::CryptoModuleBlockingPasswordDelegate*
619 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
620 const GURL& url) {
621 return browser::NewCryptoModuleBlockingDialogDelegate(
622 browser::kCryptoModulePasswordKeygen, url.host());
623}
624#endif
625
[email protected]d977f9c2011-03-14 16:10:26626} // namespace chrome