blob: 182af74dbe77e391c2dec00dbee5131b509081ac [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// 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]7c3228a2011-11-11 21:35:227#include <set>
[email protected]1033acd2012-02-08 08:46:278#include <utility>
[email protected]7c3228a2011-11-11 21:35:229#include <vector>
10
[email protected]317c58f02011-11-09 02:15:0311#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3012#include "base/command_line.h"
[email protected]eabbfb12013-04-05 23:28:3513#include "base/lazy_instance.h"
[email protected]29699c22012-10-03 23:57:3914#include "base/path_service.h"
[email protected]3853a4c2013-02-11 17:15:5715#include "base/prefs/pref_service.h"
[email protected]9eec53fe2013-10-30 20:21:1716#include "base/prefs/scoped_user_pref_update.h"
[email protected]e7463412013-06-10 22:53:4617#include "base/strings/string_number_conversions.h"
[email protected]135cb802013-06-09 16:44:2018#include "base/strings/utf_string_conversions.h"
[email protected]30a306f42013-06-10 03:09:0319#include "base/threading/sequenced_worker_pool.h"
[email protected]056efdc2013-04-06 00:14:5320#include "chrome/browser/app_mode/app_mode_utils.h"
[email protected]b8148ac2011-07-13 22:03:2521#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3022#include "chrome/browser/browser_process.h"
[email protected]5c129792013-07-10 02:08:4823#include "chrome/browser/browser_shutdown.h"
[email protected]b0cb5e82012-07-19 19:22:4724#include "chrome/browser/browsing_data/browsing_data_helper.h"
25#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1226#include "chrome/browser/character_encoding.h"
[email protected]43535512013-02-20 20:41:4127#include "chrome/browser/chrome_net_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4128#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5629#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0530#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4531#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3232#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0833#include "chrome/browser/defaults.h"
[email protected]b1d97272013-08-17 13:38:4934#include "chrome/browser/download/download_prefs.h"
[email protected]2b33dcd02012-03-18 01:34:1635#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]1deace22013-05-22 06:14:4636#include "chrome/browser/extensions/browser_permissions_policy_delegate.h"
[email protected]d977f9c2011-03-14 16:10:2637#include "chrome/browser/extensions/extension_service.h"
[email protected]ca0336342014-03-21 12:58:3438#include "chrome/browser/extensions/extension_util.h"
[email protected]b8148ac2011-07-13 22:03:2539#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0640#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]eb4832a2012-12-08 01:57:5241#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2342#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1243#include "chrome/browser/google/google_util.h"
[email protected]0533cc6d2013-06-27 22:44:0544#include "chrome/browser/guestview/adview/adview_guest.h"
[email protected]3f24f97c2013-11-17 21:53:3345#include "chrome/browser/guestview/guestview.h"
[email protected]0533cc6d2013-06-27 22:44:0546#include "chrome/browser/guestview/guestview_constants.h"
47#include "chrome/browser/guestview/webview/webview_guest.h"
[email protected]eab6105d2014-01-17 20:55:1048#include "chrome/browser/local_discovery/storage/privet_filesystem_backend.h"
[email protected]1ea4c492014-02-15 19:45:1749#include "chrome/browser/media/cast_transport_host_filter.h"
[email protected]11158e2d2013-02-01 02:31:5650#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]95132f52013-04-12 02:19:0451#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
[email protected]a2b4c5c2013-10-18 02:06:0752#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
[email protected]ae6e9912011-07-27 01:18:2853#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0454#include "chrome/browser/notifications/desktop_notification_service.h"
55#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4256#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5657#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]190e5e22013-07-27 05:59:2358#include "chrome/browser/prerender/prerender_final_status.h"
[email protected]f9034cf2011-07-21 12:43:4159#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5060#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0761#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4162#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1463#include "chrome/browser/printing/printing_message_filter.h"
[email protected]7e75e4a2013-05-17 17:20:0364#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:1465#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3266#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0667#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1468#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3869#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4370#include "chrome/browser/search/instant_service.h"
71#include "chrome/browser/search/instant_service_factory.h"
72#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1473#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]914cf6712013-12-05 01:14:0674#include "chrome/browser/signin/principals_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0275#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3376#include "chrome/browser/speech/tts_message_filter.h"
[email protected]3b455502012-12-11 18:22:5877#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0378#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5279#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]180c66a62013-08-05 12:01:3680#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:4581#include "chrome/browser/tab_contents/tab_util.h"
[email protected]916615b2013-09-11 18:19:4482#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
[email protected]40aa8bb2013-08-23 20:28:2383#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
[email protected]a28e3302013-02-03 03:50:4384#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]329ac972013-06-21 15:24:2585#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:4486#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5087#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]4a65826d2011-08-25 16:04:0188#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1489#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3090#include "chrome/common/chrome_switches.h"
[email protected]779dd282013-10-19 15:57:0291#include "chrome/common/env_vars.h"
[email protected]395045c2012-05-22 15:04:3892#include "chrome/common/extensions/extension_process_policy.h"
[email protected]561e33d52013-04-03 06:58:4393#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]f1933792011-06-14 00:49:3494#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:3795#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:1296#include "chrome/common/pref_names.h"
[email protected]4de75262013-12-18 23:16:1297#include "chrome/common/profile_management_switches.h"
[email protected]3e69bc82011-05-26 23:22:3898#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0999#include "chrome/common/url_constants.h"
[email protected]264c0acac2013-10-01 13:33:30100#include "chrome/installer/util/google_update_settings.h"
[email protected]e8f3f9982013-05-10 20:59:53101#include "chromeos/chromeos_constants.h"
[email protected]ef42ee82013-11-01 05:26:13102#include "components/nacl/browser/nacl_browser.h"
[email protected]7c766e92013-11-22 20:44:02103#include "components/nacl/browser/nacl_host_message_filter.h"
104#include "components/nacl/browser/nacl_process_host.h"
[email protected]d5d383252013-07-04 14:44:32105#include "components/nacl/common/nacl_process_type.h"
[email protected]1b4ec382014-03-07 02:32:24106#include "components/nacl/common/nacl_switches.h"
[email protected]eba93c92014-01-07 17:34:17107#include "components/translate/core/common/translate_switches.h"
[email protected]75fee372013-03-06 00:42:44108#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43109#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30110#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38111#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03112#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31113#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03114#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59115#include "content/public/browser/child_process_security_policy.h"
[email protected]094c8772013-12-21 17:54:50116#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30117#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33118#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05119#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33120#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19121#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10122#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43123#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18124#include "content/public/common/content_descriptors.h"
[email protected]22aa4f82013-09-24 17:01:44125#include "content/public/common/url_utils.h"
[email protected]22401dc2014-03-21 01:38:57126#include "extensions/browser/extension_host.h"
[email protected]afed5112014-02-02 06:01:53127#include "extensions/browser/extension_message_filter.h"
[email protected]896c6d52014-01-28 21:40:21128#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:24129#include "extensions/browser/extension_system.h"
[email protected]38427a12013-11-09 17:34:20130#include "extensions/browser/info_map.h"
[email protected]98b6d942013-11-10 00:34:07131#include "extensions/browser/process_manager.h"
[email protected]fafdc842014-01-17 18:09:08132#include "extensions/browser/process_map.h"
[email protected]cb2edf22013-04-01 20:25:23133#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42134#include "extensions/common/constants.h"
[email protected]e4452d32013-11-15 23:07:41135#include "extensions/common/extension.h"
[email protected]289c44b2013-12-17 03:26:57136#include "extensions/common/extension_set.h"
[email protected]558878cc82013-11-09 01:25:51137#include "extensions/common/manifest_handlers/background_info.h"
[email protected]301116c62013-11-26 10:37:45138#include "extensions/common/manifest_handlers/shared_module_info.h"
[email protected]474b1f72014-01-16 02:38:07139#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
[email protected]e4452d32013-11-15 23:07:41140#include "extensions/common/permissions/permissions_data.h"
[email protected]91add6a2014-03-21 11:48:22141#include "extensions/common/permissions/socket_permission.h"
[email protected]49d9b142013-07-19 08:50:27142#include "extensions/common/switches.h"
[email protected]c9b6eb62011-10-18 20:49:39143#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23144#include "grit/ui_resources.h"
[email protected]3b455502012-12-11 18:22:58145#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34146#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06147#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57148#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38149#include "ppapi/host/ppapi_host.h"
[email protected]8ddc6b7c2013-12-12 20:42:06150#include "ppapi/shared_impl/ppapi_switches.h"
[email protected]c9b6eb62011-10-18 20:49:39151#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08152#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24153#include "ui/message_center/message_center_util.h"
[email protected]b40015c2013-06-26 08:13:31154#include "webkit/browser/fileapi/external_mount_points.h"
[email protected]fab55e72013-05-31 07:06:18155#include "webkit/common/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:26156
[email protected]b48c9182011-10-26 18:03:30157#if defined(OS_WIN)
[email protected]7fe75ce2014-01-28 02:12:24158#include "base/win/windows_version.h"
[email protected]199fc7a2011-09-28 22:45:38159#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18160#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38161#elif defined(OS_MACOSX)
162#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56163#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]0b818f72013-10-22 00:11:03164#include "components/breakpad/app/breakpad_mac.h"
[email protected]b48c9182011-10-26 18:03:30165#elif defined(OS_CHROMEOS)
166#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]07fe2752014-01-29 11:21:55167#include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
[email protected]f19bbf62013-07-09 01:22:32168#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]5c915252013-05-07 13:15:39169#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49170#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]c94ac692013-07-27 00:50:10171#include "chrome/browser/chromeos/system/input_device_settings.h"
[email protected]931d1042013-04-05 17:50:44172#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26173#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30174#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09175#elif defined(OS_ANDROID)
[email protected]916615b2013-09-11 18:19:44176#include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
[email protected]81054f812012-08-30 00:47:09177#include "chrome/browser/chrome_browser_main_android.h"
[email protected]2b12c322013-09-19 06:53:56178#include "chrome/browser/media/encrypted_media_message_filter_android.h"
[email protected]29699c22012-10-03 23:57:39179#include "chrome/common/descriptors_android.h"
[email protected]0b818f72013-10-22 00:11:03180#include "components/breakpad/browser/crash_dump_manager_android.h"
[email protected]b48c9182011-10-26 18:03:30181#elif defined(OS_POSIX)
182#include "chrome/browser/chrome_browser_main_posix.h"
183#endif
184
[email protected]a220b5932013-09-21 03:47:44185#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]779dd282013-10-19 15:57:02186#include "base/debug/leak_annotations.h"
[email protected]b80f68432011-05-02 17:22:30187#include "base/linux_util.h"
[email protected]0b818f72013-10-22 00:11:03188#include "components/breakpad/app/breakpad_linux.h"
189#include "components/breakpad/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43190#endif
[email protected]b80f68432011-05-02 17:22:30191
[email protected]1e87df32012-09-12 04:53:19192#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
193#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
194#endif
195
[email protected]29699c22012-10-03 23:57:39196#if defined(OS_ANDROID)
197#include "ui/base/ui_base_paths.h"
[email protected]b255a8e0e82013-10-22 04:03:59198#include "ui/gfx/android/device_display_info.h"
[email protected]29699c22012-10-03 23:57:39199#endif
200
[email protected]d5bcd06f2013-04-21 08:07:24201#if !defined(OS_CHROMEOS)
202#include "chrome/browser/signin/signin_manager.h"
203#include "chrome/browser/signin/signin_manager_factory.h"
204#endif
205
[email protected]02250952013-04-24 23:52:53206#if !defined(OS_ANDROID)
[email protected]f19bbf62013-07-09 01:22:32207#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
[email protected]02250952013-04-24 23:52:53208#endif
209
[email protected]6ef98b5a2013-05-31 23:58:31210#if defined(ENABLE_WEBRTC)
211#include "chrome/browser/media/webrtc_logging_handler_host.h"
212#endif
213
[email protected]855e18b2013-07-08 21:02:00214#if defined(ENABLE_INPUT_SPEECH)
215#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h"
216#endif
217
[email protected]ff9300872014-01-22 11:09:32218#if defined(OS_CHROMEOS)
[email protected]473c9a4f2013-09-05 03:09:46219#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]02a3dc122013-06-13 15:07:53220#endif
221
[email protected]e8b6ca02013-07-10 18:00:51222#if defined(TOOLKIT_GTK)
223#include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h"
224#endif
225
226#if defined(TOOLKIT_VIEWS)
227#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
228#endif
229
230#if defined(USE_ASH)
231#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
232#endif
233
234#if defined(USE_AURA)
235#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
236#endif
237
238#if defined(USE_X11)
239#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
240#endif
241
[email protected]c6ce08072013-07-31 07:48:53242#if defined(ENABLE_SPELLCHECK)
243#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
244#endif
245
[email protected]2188c8d2014-03-21 00:58:56246#if defined(ENABLE_SERVICE_DISCOVERY)
[email protected]7e503f92014-02-19 02:35:51247#include "chrome/browser/local_discovery/storage/privet_filesystem_backend.h"
248#endif
249
[email protected]a1221aea2013-11-07 01:31:30250using blink::WebWindowFeatures;
[email protected]c7abd422012-09-25 00:20:08251using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47252using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03253using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39254using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31255using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59256using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00257using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11258using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33259using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13260using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06261using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34262using extensions::Extension;
[email protected]38427a12013-11-09 17:34:20263using extensions::InfoMap;
[email protected]1d5e58b2013-01-31 08:41:40264using extensions::Manifest;
[email protected]593d2a72013-07-26 08:48:38265using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39266
[email protected]0daaebfe2014-03-15 00:09:05267#if defined(OS_POSIX)
268using content::FileDescriptorInfo;
269#endif
270
[email protected]c5dbef02011-05-13 05:06:09271namespace {
272
[email protected]eabbfb12013-04-05 23:28:35273// Cached version of the locale so we can return the locale on the I/O
274// thread.
275base::LazyInstance<std::string> g_io_thread_application_locale;
276
[email protected]93f72062013-05-29 20:29:40277#if defined(ENABLE_PLUGINS)
[email protected]10c39222013-11-13 20:09:25278const char* kPredefinedAllowedFileHandleOrigins[] = {
279 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
280 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
281};
282
[email protected]e461da2f2012-02-16 19:06:40283const char* kPredefinedAllowedSocketOrigins[] = {
284 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18285 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45286 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
287 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
288 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
289 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35290 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54291 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
292 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
293 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
294 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
295 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
296 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38297 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58298 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29299 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]3f6fca22013-08-12 23:13:42300 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
301 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
302 "4EB74897CB187C7633357C2FE832E0AD6A44883A", // see crbug.com/234789
303 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
304 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
305 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40306};
[email protected]93f72062013-05-29 20:29:40307#endif
[email protected]e461da2f2012-02-16 19:06:40308
[email protected]f8f93eb2012-09-25 03:06:24309// Returns a copy of the given url with its host set to given host and path set
310// to given path. Other parts of the url will be the same.
311GURL ReplaceURLHostAndPath(const GURL& url,
312 const std::string& host,
313 const std::string& path) {
314 url_canon::Replacements<char> replacements;
315 replacements.SetHost(host.c_str(),
316 url_parse::Component(0, host.length()));
317 replacements.SetPath(path.c_str(),
318 url_parse::Component(0, path.length()));
319 return url.ReplaceComponents(replacements);
320}
321
322// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
323GURL AddUberHost(const GURL& url) {
324 const std::string uber_host = chrome::kChromeUIUberHost;
325 const std::string new_path = url.host() + url.path();
326
327 return ReplaceURLHostAndPath(url, uber_host, new_path);
328}
329
[email protected]045bf7c2012-09-28 20:27:36330// If url->host() is "chrome" and url->path() has characters other than the
331// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
332// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24333bool RemoveUberHost(GURL* url) {
334 if (url->host() != chrome::kChromeUIUberHost)
335 return false;
336
[email protected]045bf7c2012-09-28 20:27:36337 if (url->path().empty() || url->path() == "/")
338 return false;
339
[email protected]f8f93eb2012-09-25 03:06:24340 const std::string old_path = url->path();
341
342 const std::string::size_type separator = old_path.find('/', 1);
343 std::string new_host;
344 std::string new_path;
345 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36346 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24347 } else {
348 new_host = old_path.substr(1, separator - 1);
349 new_path = old_path.substr(separator);
350 }
351
[email protected]44e8add2013-06-13 17:29:15352 // Do not allow URLs with paths empty before the first slash since we can't
353 // have an empty host. (e.g "foo://chrome//")
354 if (new_host.empty())
355 return false;
356
[email protected]f8f93eb2012-09-25 03:06:24357 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
358
[email protected]44e8add2013-06-13 17:29:15359 DCHECK(url->is_valid());
360
[email protected]f8f93eb2012-09-25 03:06:24361 return true;
362}
363
[email protected]b8148ac2011-07-13 22:03:25364// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42365bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24366 // Do not handle special URLs such as "about:foo"
367 if (!url->host().empty()) {
368 const GURL chrome_url = AddUberHost(*url);
369
370 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
371 // be called.
372 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
373 browser_context, chrome_url))
374 return true;
375 }
376
[email protected]863f70a2012-01-27 02:05:50377 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
378 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25379 return false;
380
[email protected]fe69558d2012-03-12 11:34:49381#if defined(OS_CHROMEOS)
382 // Special case : in ChromeOS in Guest mode bookmarks and history are
383 // disabled for security reasons. New tab page explains the reasons, so
384 // we redirect user to new tab page.
385 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
[email protected]2d9748b22014-02-11 00:17:29386 if (url->SchemeIs(content::kChromeUIScheme) &&
[email protected]fe69558d2012-03-12 11:34:49387 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
388 url->DomainIs(chrome::kChromeUIHistoryHost))) {
389 // Rewrite with new tab URL
390 *url = GURL(chrome::kChromeUINewTabURL);
391 }
392 }
393#endif
394
[email protected]b8148ac2011-07-13 22:03:25395 return true;
396}
397
[email protected]f8f93eb2012-09-25 03:06:24398// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
399// "chrome://foo/".
400bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
[email protected]2d9748b22014-02-11 00:17:29401 if (!url->is_valid() || !url->SchemeIs(content::kChromeUIScheme))
[email protected]f8f93eb2012-09-25 03:06:24402 return false;
403
404 return RemoveUberHost(url);
405}
406
[email protected]8d3132f62011-10-12 07:13:42407// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
408// below. Extension, and isolated apps require different privileges to be
409// granted to their RenderProcessHosts. This classification allows us to make
410// sure URLs are served by hosts with the right set of privileges.
411enum RenderProcessHostPrivilege {
412 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45413 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42414 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45415 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42416};
417
418RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
419 const GURL& url,
420 ExtensionService* service) {
421 // Default to a normal renderer cause it is lower privileged. This should only
422 // occur if the URL on a site instance is either malformed, or uninitialized.
423 // If it is malformed, then there is no need for better privileges anyways.
424 // If it is uninitialized, but eventually settles on being an a scheme other
425 // than normal webrenderer, the navigation logic will correct us out of band
426 // anyways.
427 if (!url.is_valid())
428 return PRIV_NORMAL;
429
[email protected]885c0e92012-11-13 20:27:42430 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44431 const Extension* extension =
432 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43433 if (extension &&
434 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42435 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45436 if (extension && extension->is_hosted_app())
437 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42438
439 return PRIV_EXTENSION;
440 }
441
442 return PRIV_NORMAL;
443}
444
445RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30446 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46447 extensions::ProcessMap* process_map,
448 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46449 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30450 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46451 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21452 return PRIV_NORMAL;
453
[email protected]6f371442011-11-09 06:45:46454 for (std::set<std::string>::iterator iter = extension_ids.begin();
455 iter != extension_ids.end(); ++iter) {
456 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43457 if (extension &&
458 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42459 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45460 if (extension && extension->is_hosted_app())
461 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42462 }
463
[email protected]676f6ab2011-10-19 20:23:21464 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42465}
466
[email protected]6786bf402011-12-03 15:19:45467bool CertMatchesFilter(const net::X509Certificate& cert,
468 const base::DictionaryValue& filter) {
469 // TODO(markusheintz): This is the minimal required filter implementation.
470 // Implement a better matcher.
471
472 // An empty filter matches any client certificate since no requirements are
473 // specified at all.
474 if (filter.empty())
475 return true;
476
477 std::string common_name;
478 if (filter.GetString("ISSUER.CN", &common_name) &&
479 (cert.issuer().common_name == common_name)) {
480 return true;
481 }
482 return false;
483}
484
[email protected]1d51882f2013-11-12 01:59:02485#if !defined(OS_ANDROID)
[email protected]f3986f82012-01-03 20:00:06486// Fills |map| with the per-script font prefs under path |map_name|.
487void FillFontFamilyMap(const PrefService* prefs,
488 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53489 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]33b79542013-10-18 11:18:45490 // TODO: Get rid of the brute-force scan over possible (font family / script)
491 // combinations - see http://crbug.com/308095.
[email protected]f3986f82012-01-03 20:00:06492 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
493 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
494 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
495 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23496 if (!font_family.empty())
[email protected]cc2a2a22013-12-24 23:12:15497 (*map)[script] = base::UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06498 }
499}
500
[email protected]a1733df2012-06-22 11:24:18501#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]0b818f72013-10-22 00:11:03502breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
503 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02504 base::FilePath dumps_path;
505 PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
506 {
507 ANNOTATE_SCOPED_MEMORY_LEAK;
[email protected]0b818f72013-10-22 00:11:03508 breakpad::CrashHandlerHostLinux* crash_handler =
509 new breakpad::CrashHandlerHostLinux(
510 process_type, dumps_path, getenv(env_vars::kHeadless) == NULL);
[email protected]779dd282013-10-19 15:57:02511 crash_handler->StartUploaderThread();
512 return crash_handler;
513 }
514}
515
[email protected]a1733df2012-06-22 11:24:18516int GetCrashSignalFD(const CommandLine& command_line) {
[email protected]cd0f7af2014-01-16 23:50:39517 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
[email protected]0b818f72013-10-22 00:11:03518 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02519 if (!crash_handler)
520 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18521 return crash_handler->GetDeathSignalSocket();
522 }
523
524 std::string process_type =
525 command_line.GetSwitchValueASCII(switches::kProcessType);
526
[email protected]779dd282013-10-19 15:57:02527 if (process_type == switches::kRendererProcess) {
[email protected]0b818f72013-10-22 00:11:03528 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02529 if (!crash_handler)
530 crash_handler = CreateCrashHandlerHost(process_type);
531 return crash_handler->GetDeathSignalSocket();
532 }
[email protected]a1733df2012-06-22 11:24:18533
[email protected]779dd282013-10-19 15:57:02534 if (process_type == switches::kPluginProcess) {
[email protected]0b818f72013-10-22 00:11:03535 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02536 if (!crash_handler)
537 crash_handler = CreateCrashHandlerHost(process_type);
538 return crash_handler->GetDeathSignalSocket();
539 }
[email protected]a1733df2012-06-22 11:24:18540
[email protected]779dd282013-10-19 15:57:02541 if (process_type == switches::kPpapiPluginProcess) {
[email protected]0b818f72013-10-22 00:11:03542 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02543 if (!crash_handler)
544 crash_handler = CreateCrashHandlerHost(process_type);
545 return crash_handler->GetDeathSignalSocket();
546 }
[email protected]a1733df2012-06-22 11:24:18547
[email protected]779dd282013-10-19 15:57:02548 if (process_type == switches::kGpuProcess) {
[email protected]0b818f72013-10-22 00:11:03549 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02550 if (!crash_handler)
551 crash_handler = CreateCrashHandlerHost(process_type);
552 return crash_handler->GetDeathSignalSocket();
553 }
[email protected]a1733df2012-06-22 11:24:18554
555 return -1;
556}
557#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]1d51882f2013-11-12 01:59:02558#endif // !defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18559
[email protected]d5bcd06f2013-04-21 08:07:24560#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30561GURL GetEffectiveURLForSignin(const GURL& url) {
562 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
563
564 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03565 // Copy the path because the argument to SetPathStr must outlive
566 // the Replacements object.
567 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30568 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03569 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30570 effective_url = effective_url.ReplaceComponents(replacements);
571 return effective_url;
572}
[email protected]d5bcd06f2013-04-21 08:07:24573#endif
[email protected]970c63e2013-03-07 00:25:30574
[email protected]eabbfb12013-04-05 23:28:35575void SetApplicationLocaleOnIOThread(const std::string& locale) {
576 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
577 g_io_thread_application_locale.Get() = locale;
578}
579
[email protected]916615b2013-09-11 18:19:44580void HandleBlockedPopupOnUIThread(const BlockedWindowParams& params) {
581 WebContents* tab = tab_util::GetWebContentsByID(params.render_process_id(),
582 params.opener_id());
[email protected]190e5e22013-07-27 05:59:23583 if (!tab)
584 return;
585
[email protected]f1cd3362014-01-07 20:43:01586 prerender::PrerenderContents* prerender_contents =
587 prerender::PrerenderContents::FromWebContents(tab);
588 if (prerender_contents) {
589 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW);
590 return;
591 }
592
[email protected]190e5e22013-07-27 05:59:23593 PopupBlockerTabHelper* popup_helper =
594 PopupBlockerTabHelper::FromWebContents(tab);
595 if (!popup_helper)
596 return;
[email protected]916615b2013-09-11 18:19:44597 popup_helper->AddBlockedPopup(params);
[email protected]190e5e22013-07-27 05:59:23598}
[email protected]190e5e22013-07-27 05:59:23599
[email protected]916615b2013-09-11 18:19:44600#if defined(OS_ANDROID)
[email protected]b255a8e0e82013-10-22 04:03:59601
[email protected]916615b2013-09-11 18:19:44602void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams& params) {
603 WebContents* web_contents =
604 tab_util::GetWebContentsByID(params.render_process_id(),
605 params.opener_id());
606 if (!web_contents)
607 return;
608
609 SingleTabModeTabHelper::FromWebContents(web_contents)->HandleOpenUrl(params);
610}
[email protected]b255a8e0e82013-10-22 04:03:59611
[email protected]ded00dc2013-11-01 00:37:05612float GetDeviceScaleAdjustment() {
[email protected]b255a8e0e82013-10-22 04:03:59613 static const float kMinFSM = 1.05f;
614 static const int kWidthForMinFSM = 320;
615 static const float kMaxFSM = 1.3f;
616 static const int kWidthForMaxFSM = 800;
617
618 gfx::DeviceDisplayInfo info;
619 int minWidth = info.GetSmallestDIPWidth();
620
621 if (minWidth <= kWidthForMinFSM)
622 return kMinFSM;
623 if (minWidth >= kWidthForMaxFSM)
624 return kMaxFSM;
625
626 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
627 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) /
628 (kWidthForMaxFSM - kWidthForMinFSM);
629 return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
630}
631
[email protected]916615b2013-09-11 18:19:44632#endif // defined(OS_ANDROID)
633
[email protected]9dbfff12011-07-01 19:37:07634} // namespace
[email protected]c5dbef02011-05-13 05:06:09635
[email protected]d977f9c2011-03-14 16:10:26636namespace chrome {
637
[email protected]e461da2f2012-02-16 19:06:40638ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40639#if defined(ENABLE_PLUGINS)
[email protected]10c39222013-11-13 20:09:25640 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i)
641 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40642 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
643 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40644#endif
[email protected]1deace22013-05-22 06:14:46645
646 permissions_policy_delegate_.reset(
647 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40648}
649
650ChromeContentBrowserClient::~ChromeContentBrowserClient() {
651}
652
[email protected]bca18382012-06-25 19:15:23653// static
[email protected]37ca3fe02013-07-05 15:32:44654void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34655 user_prefs::PrefRegistrySyncable* registry) {
656 registry->RegisterBooleanPref(
657 prefs::kDisable3DAPIs,
658 false,
659 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
660 registry->RegisterBooleanPref(
661 prefs::kEnableHyperlinkAuditing,
662 true,
663 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23664}
665
[email protected]eabbfb12013-04-05 23:28:35666// static
667void ChromeContentBrowserClient::SetApplicationLocale(
668 const std::string& locale) {
669 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
670
671 // This object is guaranteed to outlive all threads so we don't have to
672 // worry about the lack of refcounting and can just post as Unretained.
673 //
674 // The common case is that this function is called early in Chrome startup
675 // before any threads are created (it will also be called later if the user
676 // changes the pref). In this case, there will be no threads created and
677 // posting will fail. When there are no threads, we can just set the string
678 // without worrying about threadsafety.
679 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
680 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
681 g_io_thread_application_locale.Get() = locale;
682 }
683}
684
[email protected]50462bf02011-11-21 19:13:31685content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
686 const content::MainFunctionParams& parameters) {
687 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30688 // Construct the Main browser parts based on the OS type.
689#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31690 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04691#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31692 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30693#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22694 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26695#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31696 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14697#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09698 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30699#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31700 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04701#else
[email protected]b48c9182011-10-26 18:03:30702 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31703 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30704#endif
705
[email protected]7e75e4a2013-05-17 17:20:03706 chrome::AddProfilesExtraParts(main_parts);
707
[email protected]c7480942011-11-08 19:18:27708 // Construct additional browser parts. Stages are called in the order in
709 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22710#if defined(TOOLKIT_GTK)
[email protected]e8b6ca02013-07-10 18:00:51711 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04712#endif
[email protected]c7480942011-11-08 19:18:27713
714#if defined(TOOLKIT_VIEWS)
[email protected]e8b6ca02013-07-10 18:00:51715 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27716#endif
717
[email protected]dc04be7c2012-03-15 23:57:49718#if defined(USE_ASH)
[email protected]e8b6ca02013-07-10 18:00:51719 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
[email protected]dc04be7c2012-03-15 23:57:49720#endif
721
[email protected]e050ef142012-03-21 01:04:24722#if defined(USE_AURA)
[email protected]e8b6ca02013-07-10 18:00:51723 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
724#endif
725
726#if defined(USE_X11)
727 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:24728#endif
729
[email protected]95132f52013-04-12 02:19:04730 chrome::AddMetricsExtraParts(main_parts);
731
[email protected]50462bf02011-11-21 19:13:31732 return main_parts;
[email protected]f967b722011-09-07 00:58:04733}
734
[email protected]e94bbcb2012-09-07 05:33:57735std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19736 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57737 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53738 std::string partition_id;
739
740 // The partition ID for webview guest processes is the string value of its
741 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
[email protected]4413d872014-02-20 20:26:55742 if (site.SchemeIs(content::kGuestScheme)) {
[email protected]1bc28312012-11-08 08:31:53743 partition_id = site.spec();
[email protected]4413d872014-02-20 20:26:55744 } else if (site.GetOrigin().spec() == kChromeUIChromeSigninURL) {
745 // Chrome signin page has an embedded iframe of extension and web content,
746 // thus it must be isolated from other webUI pages.
747 partition_id = site.GetOrigin().spec();
748 }
[email protected]1bc28312012-11-08 08:31:53749
[email protected]056efdc2013-04-06 00:14:53750 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53751 return partition_id;
752}
753
754bool ChromeContentBrowserClient::IsValidStoragePartitionId(
755 content::BrowserContext* browser_context,
756 const std::string& partition_id) {
757 // The default ID is empty and is always valid.
758 if (partition_id.empty())
759 return true;
760
761 return GURL(partition_id).is_valid();
762}
763
764void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
765 content::BrowserContext* browser_context,
766 const GURL& site,
[email protected]14acc642012-11-17 12:20:10767 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53768 std::string* partition_domain,
769 std::string* partition_name,
770 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10771 // Default to the browser-wide storage partition and override based on |site|
772 // below.
773 partition_domain->clear();
774 partition_name->clear();
775 *in_memory = false;
776
[email protected]3f24f97c2013-11-17 21:53:33777 bool success = GuestView::GetGuestPartitionConfigForSite(
778 site, partition_domain, partition_name, in_memory);
779
780 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
[email protected]14acc642012-11-17 12:20:10781 // If |can_be_default| is false, the caller is stating that the |site|
782 // should be parsed as if it had isolated storage. In particular it is
783 // important to NOT check ExtensionService for the is_storage_isolated()
784 // attribute because this code path is run during Extension uninstall
785 // to do cleanup after the Extension has already been unloaded from the
786 // ExtensionService.
787 bool is_isolated = !can_be_default;
788 if (can_be_default) {
[email protected]ca0336342014-03-21 12:58:34789 if (extensions::util::SiteHasIsolatedStorage(site, browser_context))
790 is_isolated = true;
[email protected]14acc642012-11-17 12:20:10791 }
[email protected]1bc28312012-11-08 08:31:53792
[email protected]14acc642012-11-17 12:20:10793 if (is_isolated) {
794 CHECK(site.has_host());
795 // For extensions with isolated storage, the the host of the |site| is
796 // the |partition_domain|. The |in_memory| and |partition_name| are only
797 // used in guest schemes so they are cleared here.
798 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53799 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10800 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53801 }
[email protected]4413d872014-02-20 20:26:55802 } else if (site.GetOrigin().spec() == kChromeUIChromeSigninURL) {
803 // Chrome signin page has an embedded iframe of extension and web content,
804 // thus it must be isolated from other webUI pages.
805 *partition_domain = chrome::kChromeUIChromeSigninHost;
[email protected]d1198fd2012-08-13 22:50:19806 }
807
[email protected]14acc642012-11-17 12:20:10808 // Assert that if |can_be_default| is false, the code above must have found a
809 // non-default partition. If this fails, the caller has a serious logic
810 // error about which StoragePartition they expect to be in and it is not
811 // safe to continue.
812 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44813}
814
[email protected]38b098f2012-03-14 21:11:57815content::WebContentsViewDelegate*
816 ChromeContentBrowserClient::GetWebContentsViewDelegate(
817 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27818 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32819}
820
[email protected]738f57a2013-06-29 21:06:54821void ChromeContentBrowserClient::GuestWebContentsCreated(
[email protected]dbbce92c2013-10-31 16:51:19822 SiteInstance* guest_site_instance,
[email protected]738f57a2013-06-29 21:06:54823 WebContents* guest_web_contents,
824 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22825 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54826 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]dbbce92c2013-10-31 16:51:19827 if (!guest_site_instance) {
828 NOTREACHED();
829 return;
830 }
831 GURL guest_site_url = guest_site_instance->GetSiteURL();
832 const std::string& extension_id = guest_site_url.host();
833
834 Profile* profile = Profile::FromBrowserContext(
835 guest_web_contents->GetBrowserContext());
836 ExtensionService* service =
837 extensions::ExtensionSystem::Get(profile)->extension_service();
838 if (!service) {
839 NOTREACHED();
840 return;
841 }
842
843 /// TODO(fsamuel): In the future, certain types of GuestViews won't require
844 // extension bindings. At that point, we should clear |extension_id| instead
845 // of exiting early.
846 if (!service->GetExtensionById(extension_id, false) &&
847 !CommandLine::ForCurrentProcess()->HasSwitch(
848 switches::kEnableBrowserPluginForAllViewTypes)) {
849 NOTREACHED();
850 return;
851 }
852
[email protected]738f57a2013-06-29 21:06:54853 if (opener_web_contents) {
854 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
855 if (!guest) {
856 NOTREACHED();
857 return;
858 }
859
[email protected]50c827d2013-09-13 21:36:09860 // Create a new GuestView of the same type as the opener.
861 *guest_delegate =
[email protected]dbbce92c2013-10-31 16:51:19862 GuestView::Create(guest_web_contents,
863 extension_id,
864 guest->GetViewType());
[email protected]738f57a2013-06-29 21:06:54865 return;
866 }
867
868 if (!extra_params) {
869 NOTREACHED();
870 return;
871 }
872 std::string api_type;
[email protected]90547d72013-08-06 05:57:27873 extra_params->GetString(guestview::kParameterApi, &api_type);
[email protected]738f57a2013-06-29 21:06:54874
[email protected]dbbce92c2013-10-31 16:51:19875 if (api_type.empty())
876 return;
877
[email protected]50c827d2013-09-13 21:36:09878 *guest_delegate =
879 GuestView::Create(guest_web_contents,
[email protected]dbbce92c2013-10-31 16:51:19880 extension_id,
[email protected]50c827d2013-09-13 21:36:09881 GuestView::GetViewTypeFromString(api_type));
[email protected]738f57a2013-06-29 21:06:54882}
883
[email protected]44295a12013-06-05 08:45:46884void ChromeContentBrowserClient::GuestWebContentsAttached(
885 WebContents* guest_web_contents,
886 WebContents* embedder_web_contents,
[email protected]5715566a2013-06-25 00:04:53887 const base::DictionaryValue& extra_params) {
[email protected]22aa4f82013-09-24 17:01:44888
[email protected]dbbce92c2013-10-31 16:51:19889 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
890 if (!guest) {
[email protected]efd6fb02013-08-05 04:44:06891 // It's ok to return here, since we could be running a browser plugin
892 // outside an extension, and don't need to attach a
893 // BrowserPluginGuestDelegate in that case;
894 // e.g. running with flag --enable-browser-plugin-for-all-view-types.
[email protected]738f57a2013-06-29 21:06:54895 return;
[email protected]18699372013-06-25 20:42:55896 }
[email protected]dbbce92c2013-10-31 16:51:19897 guest->Attach(embedder_web_contents, extra_params);
[email protected]44703cc72013-01-24 04:56:06898}
899
[email protected]6f2862742013-12-20 07:53:19900void ChromeContentBrowserClient::RenderProcessWillLaunch(
[email protected]f3b1a082011-11-18 00:34:30901 content::RenderProcessHost* host) {
902 int id = host->GetID();
903 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41904 net::URLRequestContextGetter* context =
905 profile->GetRequestContextForRenderProcess(id);
906
[email protected]ba780c12013-10-01 17:07:06907 host->AddFilter(new ChromeRenderMessageFilter(id, profile, context));
[email protected]afed5112014-02-02 06:01:53908 host->AddFilter(new extensions::ExtensionMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55909#if defined(ENABLE_PLUGINS)
[email protected]ba780c12013-10-01 17:07:06910 host->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55911#endif
[email protected]1ea4c492014-02-15 19:45:17912 host->AddFilter(new cast::CastTransportHostFilter);
[email protected]658677f2012-06-09 06:04:02913#if defined(ENABLE_PRINTING)
[email protected]ba780c12013-10-01 17:07:06914 host->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03915#endif
[email protected]ba780c12013-10-01 17:07:06916 host->AddFilter(new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]c6ce08072013-07-31 07:48:53917#if defined(ENABLE_SPELLCHECK)
[email protected]ba780c12013-10-01 17:07:06918 host->AddFilter(new SpellCheckMessageFilter(id));
[email protected]c6ce08072013-07-31 07:48:53919#endif
[email protected]7ceb99012011-12-21 08:05:56920#if defined(OS_MACOSX)
[email protected]ba780c12013-10-01 17:07:06921 host->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56922#endif
[email protected]49aa5a32014-02-03 10:00:44923 host->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile, context));
[email protected]ba780c12013-10-01 17:07:06924 host->AddFilter(new prerender::PrerenderMessageFilter(id, profile));
[email protected]ba780c12013-10-01 17:07:06925 host->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31926#if defined(ENABLE_WEBRTC)
[email protected]10e5c5e52013-10-03 18:44:06927 WebRtcLoggingHandlerHost* webrtc_logging_handler_host =
[email protected]135bc1d2013-10-21 09:11:37928 new WebRtcLoggingHandlerHost(profile);
[email protected]e7b9b352014-01-29 16:35:27929 host->SetWebRtcLogMessageCallback(base::Bind(
930 &WebRtcLoggingHandlerHost::LogMessage, webrtc_logging_handler_host));
[email protected]10e5c5e52013-10-03 18:44:06931 host->AddFilter(webrtc_logging_handler_host);
932 host->SetUserData(host, new base::UserDataAdapter<WebRtcLoggingHandlerHost>(
933 webrtc_logging_handler_host));
[email protected]6ef98b5a2013-05-31 23:58:31934#endif
[email protected]01e59752013-06-18 00:17:35935#if !defined(DISABLE_NACL)
[email protected]7c766e92013-11-22 20:44:02936 host->AddFilter(new nacl::NaClHostMessageFilter(
[email protected]14230ca2013-06-26 23:33:03937 id, profile->IsOffTheRecord(),
[email protected]a2b4c5c2013-10-18 02:06:07938 profile->GetPath(),
[email protected]14230ca2013-06-26 23:33:03939 context));
[email protected]01e59752013-06-18 00:17:35940#endif
[email protected]2b12c322013-09-19 06:53:56941#if defined(OS_ANDROID)
[email protected]ba780c12013-10-01 17:07:06942 host->AddFilter(new EncryptedMediaMessageFilterAndroid());
[email protected]2b12c322013-09-19 06:53:56943#endif
[email protected]4de75262013-12-18 23:16:12944 if (switches::IsNewProfileManagement())
[email protected]914cf6712013-12-05 01:14:06945 host->AddFilter(new PrincipalsMessageFilter(id));
[email protected]3e69bc82011-05-26 23:22:38946
[email protected]2ccf45c2011-08-19 23:35:50947 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
948 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07949
950 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56951
952 RendererContentSettingRules rules;
[email protected]06153f02013-12-04 03:01:28953 if (host->IsGuest()) {
954 GuestView::GetDefaultContentSettingRules(&rules, profile->IsOffTheRecord());
955 } else {
956 GetRendererContentSettingRules(
957 profile->GetHostContentSettingsMap(), &rules);
958 }
[email protected]edece212011-11-16 11:56:56959 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14960}
961
[email protected]3d7474ff2011-07-27 17:47:37962GURL ChromeContentBrowserClient::GetEffectiveURL(
963 content::BrowserContext* browser_context, const GURL& url) {
964 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52965 if (!profile)
966 return url;
967
[email protected]b3cb3a32013-07-31 01:32:29968 // If the input |url| should be assigned to the Instant renderer, make its
969 // effective URL distinct from other URLs on the search provider's domain.
970 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
971 return chrome::GetEffectiveURLForInstant(url, profile);
972
[email protected]d5bcd06f2013-04-21 08:07:24973#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30974 // If the input |url| should be assigned to the Signin renderer, make its
975 // effective URL distinct from other URLs on the signin service's domain.
976 // Note that the signin renderer will be allowed to sign the user in to
977 // Chrome.
978 if (SigninManager::IsWebBasedSigninFlowURL(url))
979 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24980#endif
[email protected]970c63e2013-03-07 00:25:30981
[email protected]c5dec6292013-01-25 04:54:52982 // If the input |url| is part of an installed app, the effective URL is an
983 // extension URL with the ID of that extension as the host. This has the
984 // effect of grouping apps together in a common SiteInstance.
985 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13986 extensions::ExtensionSystem::Get(profile)->extension_service();
987 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08988 return url;
989
[email protected]06bdd2b2012-11-30 18:47:13990 const Extension* extension = extension_service->extensions()->
[email protected]be9915fb2013-07-18 09:28:55991 GetHostedAppByURL(url);
[email protected]36fb2c7c2011-04-04 15:49:08992 if (!extension)
993 return url;
994
[email protected]15877ca2011-11-18 22:40:52995 // Bookmark apps do not use the hosted app process model, and should be
996 // treated as normal URLs.
997 if (extension->from_bookmark())
998 return url;
999
[email protected]36fb2c7c2011-04-04 15:49:081000 // If the URL is part of an extension's web extent, convert it to an
1001 // extension URL.
1002 return extension->GetResourceURL(url.path());
1003}
1004
[email protected]056ad2a2011-07-12 02:13:551005bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:371006 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:521007 // Non-extension, non-Instant URLs should generally use
1008 // process-per-site-instance. Because we expect to use the effective URL,
1009 // URLs for hosted apps (apart from bookmark apps) should have an extension
1010 // scheme by now.
1011
1012 Profile* profile = Profile::FromBrowserContext(browser_context);
1013 if (!profile)
1014 return false;
1015
[email protected]df113a12013-07-24 04:56:081016 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:521017 return true;
1018
[email protected]d5bcd06f2013-04-21 08:07:241019#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301020 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
1021 return true;
[email protected]d5bcd06f2013-04-21 08:07:241022#endif
[email protected]970c63e2013-03-07 00:25:301023
[email protected]885c0e92012-11-13 20:27:421024 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:551025 return false;
1026
[email protected]c5dec6292013-01-25 04:54:521027 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:131028 extensions::ExtensionSystem::Get(profile)->extension_service();
1029 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:551030 return false;
1031
[email protected]be9915fb2013-07-18 09:28:551032 const Extension* extension =
1033 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
[email protected]056ad2a2011-07-12 02:13:551034 if (!extension)
1035 return false;
1036
1037 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:531038 // permission, or that does not allow JavaScript access to the background
1039 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:551040 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:401041 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:061042 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:291043 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:531044 return false;
1045 }
1046 }
[email protected]056ad2a2011-07-12 02:13:551047
[email protected]7b54ca02012-03-02 18:06:531048 // Hosted apps that have script access to their background page must use
1049 // process per site, since all instances can make synchronous calls to the
1050 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:551051 return true;
1052}
1053
[email protected]73b718f2014-01-27 02:59:461054// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1055// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411056void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1057 std::vector<std::string>* additional_schemes) {
1058 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]73b718f2014-01-27 02:59:461059 additional_schemes->push_back(chrome::kDomDistillerScheme);
[email protected]672c8c12013-03-07 12:30:061060}
1061
[email protected]70b89cd2014-03-18 00:33:241062void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck(
1063 std::vector<std::string>* hosts) {
1064 hosts->push_back(chrome::kChromeUIExtensionIconHost);
1065 hosts->push_back(chrome::kChromeUIFaviconHost);
1066 hosts->push_back(chrome::kChromeUIThemeHost);
1067 hosts->push_back(chrome::kChromeUIThumbnailHost);
1068 hosts->push_back(chrome::kChromeUIThumbnailHost2);
1069 hosts->push_back(chrome::kChromeUIThumbnailListHost);
1070}
1071
1072net::URLRequestContextGetter*
1073ChromeContentBrowserClient::CreateRequestContext(
[email protected]6bd30072013-02-08 18:17:111074 content::BrowserContext* browser_context,
[email protected]7571263c2014-03-10 22:57:091075 content::ProtocolHandlerMap* protocol_handlers,
1076 content::ProtocolHandlerScopedVector protocol_interceptors) {
[email protected]6bd30072013-02-08 18:17:111077 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]7571263c2014-03-10 22:57:091078 return profile->CreateRequestContext(protocol_handlers,
1079 protocol_interceptors.Pass());
[email protected]6bd30072013-02-08 18:17:111080}
1081
1082net::URLRequestContextGetter*
1083ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
1084 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:401085 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:111086 bool in_memory,
[email protected]7571263c2014-03-10 22:57:091087 content::ProtocolHandlerMap* protocol_handlers,
1088 content::ProtocolHandlerScopedVector protocol_interceptors) {
[email protected]6bd30072013-02-08 18:17:111089 Profile* profile = Profile::FromBrowserContext(browser_context);
1090 return profile->CreateRequestContextForStoragePartition(
[email protected]7571263c2014-03-10 22:57:091091 partition_path,
1092 in_memory,
1093 protocol_handlers,
1094 protocol_interceptors.Pass());
[email protected]6bd30072013-02-08 18:17:111095}
1096
[email protected]46fb9442011-12-09 17:57:471097bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1098 return ProfileIOData::IsHandledURL(url);
1099}
1100
[email protected]c4365fa42013-05-14 01:08:241101bool ChromeContentBrowserClient::CanCommitURL(
1102 content::RenderProcessHost* process_host,
1103 const GURL& url) {
1104 // We need to let most extension URLs commit in any process, since this can
1105 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1106 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1107 // cannot be loaded in iframes and should never be requested outside its
1108 // process.
1109 Profile* profile =
1110 Profile::FromBrowserContext(process_host->GetBrowserContext());
1111 ExtensionService* service =
1112 extensions::ExtensionSystem::Get(profile)->extension_service();
1113 if (!service)
1114 return true;
1115 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551116 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]c4365fa42013-05-14 01:08:241117 if (new_extension &&
1118 new_extension->is_hosted_app() &&
1119 new_extension->id() == extension_misc::kWebStoreAppId &&
[email protected]fafdc842014-01-17 18:09:081120 !extensions::ProcessMap::Get(profile)->
1121 Contains(new_extension->id(), process_host->GetID())) {
[email protected]c4365fa42013-05-14 01:08:241122 return false;
1123 }
1124
1125 return true;
1126}
1127
[email protected]9a60d1602013-09-11 04:09:121128bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1129 content::SiteInstance* site_instance, const GURL& url) {
1130 GURL from_url = site_instance->GetSiteURL();
1131 // Do not allow pages from the web or other extensions navigate to
1132 // non-web-accessible extension resources.
1133 if (url.SchemeIs(extensions::kExtensionScheme) &&
1134 (from_url.SchemeIsHTTPOrHTTPS() ||
1135 from_url.SchemeIs(extensions::kExtensionScheme))) {
1136 Profile* profile = Profile::FromBrowserContext(
1137 site_instance->GetProcess()->GetBrowserContext());
1138 ExtensionService* service =
1139 extensions::ExtensionSystem::Get(profile)->extension_service();
1140 if (!service)
1141 return true;
1142 const Extension* extension =
1143 service->extensions()->GetExtensionOrAppByURL(url);
1144 if (!extension)
1145 return true;
1146 const Extension* from_extension =
1147 service->extensions()->GetExtensionOrAppByURL(
1148 site_instance->GetSiteURL());
1149 if (from_extension && from_extension->id() == extension->id())
1150 return true;
1151
1152 if (!extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
1153 extension, url.path()))
1154 return false;
1155 }
1156 return true;
1157}
1158
[email protected]2a5221b2011-09-27 23:07:311159bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301160 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311161 const GURL& site_url) {
1162 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301163 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521164 // This may be NULL during tests. In that case, just assume any site can
1165 // share any host.
1166 if (!profile)
1167 return true;
1168
[email protected]d43f99fe2013-04-03 00:20:141169 // Instant URLs should only be in the instant process and instant process
1170 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521171 InstantService* instant_service =
1172 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141173 if (instant_service) {
1174 bool is_instant_process = instant_service->IsInstantProcess(
1175 process_host->GetID());
1176 bool should_be_in_instant_process =
1177 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1178 if (is_instant_process || should_be_in_instant_process)
1179 return is_instant_process && should_be_in_instant_process;
1180 }
[email protected]c5dec6292013-01-25 04:54:521181
[email protected]d5bcd06f2013-04-21 08:07:241182#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301183 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1184 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1185 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241186#endif
[email protected]970c63e2013-03-07 00:25:301187
[email protected]06bdd2b2012-11-30 18:47:131188 ExtensionService* service =
1189 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]fafdc842014-01-17 18:09:081190 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile);
[email protected]2a5221b2011-09-27 23:07:311191
[email protected]ffa97602011-11-17 17:55:521192 // Don't allow the Task Manager to share a process with anything else.
1193 // Otherwise it can affect the renderers it is observing.
1194 // Note: we could create another RenderProcessHostPrivilege bucket for
1195 // this to allow multiple chrome://tasks instances to share, but that's
1196 // a very unlikely case without serious consequences.
1197 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1198 return false;
1199
[email protected]8d3132f62011-10-12 07:13:421200 // These may be NULL during tests. In that case, just assume any site can
1201 // share any host.
[email protected]6f371442011-11-09 06:45:461202 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311203 return true;
1204
[email protected]eec0b33c2011-12-05 22:09:451205 // Otherwise, just make sure the process privilege matches the privilege
1206 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571207 RenderProcessHostPrivilege privilege_required =
1208 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451209 return GetProcessPrivilege(process_host, process_map, service) ==
1210 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311211}
1212
[email protected]76411f412012-02-22 18:56:061213// This function is trying to limit the amount of processes used by extensions
1214// with background pages. It uses a globally set percentage of processes to
1215// run such extensions and if the limit is exceeded, it returns true, to
1216// indicate to the content module to group extensions together.
1217bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1218 content::BrowserContext* browser_context, const GURL& url) {
1219 // It has to be a valid URL for us to check for an extension.
1220 if (!url.is_valid())
1221 return false;
1222
1223 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191224 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131225 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061226 if (!service)
1227 return false;
1228
1229 // We have to have a valid extension with background page to proceed.
1230 const Extension* extension =
[email protected]be9915fb2013-07-18 09:28:551231 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]76411f412012-02-22 18:56:061232 if (!extension)
1233 return false;
[email protected]9367eabc2013-03-01 01:29:291234 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061235 return false;
1236
1237 std::set<int> process_ids;
1238 size_t max_process_count =
1239 content::RenderProcessHost::GetMaxRendererProcessCount();
1240
1241 // Go through all profiles to ensure we have total count of extension
1242 // processes containing background pages, otherwise one profile can
1243 // starve the other.
1244 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1245 GetLoadedProfiles();
1246 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]98b6d942013-11-10 00:34:071247 extensions::ProcessManager* epm =
[email protected]be93bba02012-10-24 16:44:031248 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]98b6d942013-11-10 00:34:071249 for (extensions::ProcessManager::const_iterator iter =
[email protected]d1fe1352012-04-26 00:47:321250 epm->background_hosts().begin();
1251 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131252 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321253 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061254 }
1255 }
1256
1257 if (process_ids.size() >
1258 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1259 return true;
1260 }
1261
1262 return false;
1263}
1264
[email protected]6f371442011-11-09 06:45:461265void ChromeContentBrowserClient::SiteInstanceGotProcess(
1266 SiteInstance* site_instance) {
1267 CHECK(site_instance->HasProcess());
1268
1269 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021270 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521271 if (!profile)
1272 return;
1273
1274 // Remember the ID of the Instant process to signal the renderer process
1275 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031276 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321277 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521278 InstantService* instant_service =
1279 InstantServiceFactory::GetForProfile(profile);
1280 if (instant_service)
1281 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1282 }
1283
[email protected]d5bcd06f2013-04-21 08:07:241284#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301285 // We only expect there to be one signin process as we use process-per-site
1286 // for signin URLs. The signin process will be cleared from SigninManager
1287 // when the renderer is destroyed.
1288 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1289 SigninManager* signin_manager =
1290 SigninManagerFactory::GetForProfile(profile);
1291 if (signin_manager)
1292 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461293 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:201294 BrowserThread::IO,
1295 FROM_HERE,
1296 base::Bind(&InfoMap::SetSigninProcess,
[email protected]1deace22013-05-22 06:14:461297 extensions::ExtensionSystem::Get(profile)->info_map(),
1298 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301299 }
[email protected]d5bcd06f2013-04-21 08:07:241300#endif
[email protected]970c63e2013-03-07 00:25:301301
[email protected]06bdd2b2012-11-30 18:47:131302 ExtensionService* service =
1303 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461304 if (!service)
1305 return;
1306
[email protected]be9915fb2013-07-18 09:28:551307 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1308 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461309 if (!extension)
1310 return;
1311
[email protected]fafdc842014-01-17 18:09:081312 extensions::ProcessMap::Get(profile)
1313 ->Insert(extension->id(),
1314 site_instance->GetProcess()->GetID(),
1315 site_instance->GetId());
1316
[email protected]6f371442011-11-09 06:45:461317 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:201318 BrowserThread::IO,
1319 FROM_HERE,
1320 base::Bind(&InfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591321 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461322 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351323 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331324 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461325}
1326
1327void ChromeContentBrowserClient::SiteInstanceDeleting(
1328 SiteInstance* site_instance) {
1329 if (!site_instance->HasProcess())
1330 return;
1331
1332 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021333 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131334 ExtensionService* service =
1335 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461336 if (!service)
1337 return;
1338
[email protected]be9915fb2013-07-18 09:28:551339 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1340 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461341 if (!extension)
1342 return;
1343
[email protected]fafdc842014-01-17 18:09:081344 extensions::ProcessMap::Get(profile)
1345 ->Remove(extension->id(),
1346 site_instance->GetProcess()->GetID(),
1347 site_instance->GetId());
1348
[email protected]6f371442011-11-09 06:45:461349 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:201350 BrowserThread::IO,
1351 FROM_HERE,
1352 base::Bind(&InfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591353 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461354 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351355 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331356 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461357}
1358
[email protected]896c6d52014-01-28 21:40:211359void ChromeContentBrowserClient::WorkerProcessCreated(
1360 SiteInstance* site_instance,
1361 int worker_process_id) {
1362 extensions::ExtensionRegistry* extension_registry =
1363 extensions::ExtensionRegistry::Get(site_instance->GetBrowserContext());
1364 if (!extension_registry)
1365 return;
1366 const Extension* extension =
1367 extension_registry->enabled_extensions().GetExtensionOrAppByURL(
1368 site_instance->GetSiteURL());
1369 if (!extension)
1370 return;
1371 extensions::ExtensionSystem* extension_system =
[email protected]59b0e602014-01-30 00:41:241372 extensions::ExtensionSystem::Get(site_instance->GetBrowserContext());
[email protected]896c6d52014-01-28 21:40:211373 extension_system->info_map()->RegisterExtensionWorkerProcess(
1374 extension->id(),
1375 worker_process_id,
1376 site_instance->GetId());
1377}
1378
1379void ChromeContentBrowserClient::WorkerProcessTerminated(
1380 SiteInstance* site_instance,
1381 int worker_process_id) {
1382 extensions::ExtensionSystem* extension_system =
[email protected]59b0e602014-01-30 00:41:241383 extensions::ExtensionSystem::Get(site_instance->GetBrowserContext());
[email protected]896c6d52014-01-28 21:40:211384 extension_system->info_map()->UnregisterExtensionWorkerProcess(
1385 worker_process_id);
1386}
1387
[email protected]453f5432013-11-26 19:43:001388bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141389 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081390 const GURL& current_url,
1391 const GURL& new_url) {
[email protected]2aca9a92013-12-03 05:16:071392 // If we don't have an ExtensionService, then rely on the SiteInstance logic
[email protected]a5a59482013-12-03 22:52:061393 // in RenderFrameHostManager to decide when to swap.
[email protected]e9841fbd2013-02-22 23:12:141394 Profile* profile =
1395 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1396 ExtensionService* service =
1397 extensions::ExtensionSystem::Get(profile)->extension_service();
1398 if (!service)
1399 return false;
1400
[email protected]2aca9a92013-12-03 05:16:071401 // We must use a new BrowsingInstance (forcing a process swap and disabling
1402 // scripting by existing tabs) if one of the URLs is an extension and the
1403 // other is not the exact same extension.
1404 //
1405 // We ignore hosted apps here so that other tabs in their BrowsingInstance can
1406 // use postMessage with them. (The exception is the Chrome Web Store, which
1407 // is a hosted app that requires its own BrowsingInstance.) Navigations
1408 // to/from a hosted app will still trigger a SiteInstance swap in
[email protected]a5a59482013-12-03 22:52:061409 // RenderFrameHostManager.
[email protected]2aca9a92013-12-03 05:16:071410 const Extension* current_extension =
1411 service->extensions()->GetExtensionOrAppByURL(current_url);
1412 if (current_extension &&
1413 current_extension->is_hosted_app() &&
1414 current_extension->id() != extension_misc::kWebStoreAppId)
1415 current_extension = NULL;
1416
[email protected]e9841fbd2013-02-22 23:12:141417 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551418 service->extensions()->GetExtensionOrAppByURL(new_url);
[email protected]e9841fbd2013-02-22 23:12:141419 if (new_extension &&
1420 new_extension->is_hosted_app() &&
1421 new_extension->id() != extension_misc::kWebStoreAppId)
1422 new_extension = NULL;
[email protected]2aca9a92013-12-03 05:16:071423
1424 // First do a process check. We should force a BrowsingInstance swap if the
1425 // current process doesn't know about new_extension, even if current_extension
1426 // is somehow the same as new_extension.
[email protected]fafdc842014-01-17 18:09:081427 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile);
[email protected]e9841fbd2013-02-22 23:12:141428 if (new_extension &&
1429 site_instance->HasProcess() &&
[email protected]fafdc842014-01-17 18:09:081430 !process_map->Contains(
1431 new_extension->id(), site_instance->GetProcess()->GetID()))
[email protected]e9841fbd2013-02-22 23:12:141432 return true;
1433
[email protected]2aca9a92013-12-03 05:16:071434 // Otherwise, swap BrowsingInstances if current_extension and new_extension
1435 // differ.
1436 return current_extension != new_extension;
[email protected]e3daf3c2011-10-05 21:17:081437}
1438
[email protected]395045c2012-05-22 15:04:381439bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1440 content::ResourceContext* resource_context, const GURL& current_url,
1441 const GURL& new_url) {
1442 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1443 return extensions::CrossesExtensionProcessBoundary(
1444 io_data->GetExtensionInfoMap()->extensions(),
[email protected]be9915fb2013-07-18 09:28:551445 current_url, new_url, false);
[email protected]395045c2012-05-22 15:04:381446}
1447
[email protected]3d831992013-07-04 01:13:291448bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1449 return !url.SchemeIs(chrome::kChromeNativeScheme);
1450}
1451
[email protected]763ec4ca2011-04-29 15:48:121452std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1453 const std::string& alias_name) {
1454 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1455}
1456
[email protected]b80f68432011-05-02 17:22:301457void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1458 CommandLine* command_line, int child_process_id) {
[email protected]264c0acac2013-10-01 13:33:301459#if defined(OS_POSIX)
[email protected]0b818f72013-10-22 00:11:031460 if (breakpad::IsCrashReporterEnabled()) {
[email protected]264c0acac2013-10-01 13:33:301461 std::string enable_crash_reporter;
1462 GoogleUpdateSettings::GetMetricsId(&enable_crash_reporter);
1463#if !defined(OS_MACOSX)
1464 enable_crash_reporter += "," + base::GetLinuxDistro();
1465#endif
[email protected]b80f68432011-05-02 17:22:301466 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
[email protected]264c0acac2013-10-01 13:33:301467 enable_crash_reporter);
[email protected]b80f68432011-05-02 17:22:301468 }
[email protected]264c0acac2013-10-01 13:33:301469#endif // OS_POSIX
[email protected]b80f68432011-05-02 17:22:301470
[email protected]f1933792011-06-14 00:49:341471 if (logging::DialogsAreSuppressed())
1472 command_line->AppendSwitch(switches::kNoErrorDialogs);
1473
[email protected]b80f68432011-05-02 17:22:301474 std::string process_type =
1475 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171476 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321477
[email protected]7c9b6f92013-09-10 18:11:351478 static const char* const kCommonSwitchNames[] = {
[email protected]aa051272014-03-10 05:56:561479 switches::kUserAgent,
[email protected]7c9b6f92013-09-10 18:11:351480 switches::kUserDataDir, // Make logs go to the right file.
1481 };
1482 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
1483 arraysize(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:321484
[email protected]8c64e282013-11-28 16:05:141485#if defined(ENABLE_IPC_FUZZER)
1486 static const char* const kIpcFuzzerSwitches[] = {
1487 switches::kIpcFuzzerTestcase,
1488 };
1489 command_line->CopySwitchesFrom(browser_command_line, kIpcFuzzerSwitches,
1490 arraysize(kIpcFuzzerSwitches));
1491#endif
1492
[email protected]718eab62011-10-05 21:16:521493 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:301494#if defined(OS_CHROMEOS)
1495 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441496 browser_command_line.GetSwitchValueASCII(
1497 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301498 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441499 command_line->AppendSwitchASCII(
1500 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301501#endif
1502
[email protected]50fa4d5f2013-11-05 00:53:231503#if defined(ENABLE_WEBRTC)
[email protected]30335fdf02014-02-26 19:51:271504 MaybeCopyDisableWebRtcEncryptionSwitch(command_line,
1505 browser_command_line,
1506 VersionInfo::GetChannel());
[email protected]50fa4d5f2013-11-05 00:53:231507#endif
1508
[email protected]f3b1a082011-11-18 00:34:301509 content::RenderProcessHost* process =
1510 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371511 if (process) {
1512 Profile* profile = Profile::FromBrowserContext(
1513 process->GetBrowserContext());
[email protected]fafdc842014-01-17 18:09:081514
1515 if (extensions::ProcessMap::Get(profile)->Contains(process->GetID()))
1516 command_line->AppendSwitch(extensions::switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:301517
[email protected]a8d851f82011-12-21 00:32:371518 PrefService* prefs = profile->GetPrefs();
1519 // Currently this pref is only registered if applied via a policy.
1520 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1521 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1522 // Turn this policy into a command line switch.
1523 command_line->AppendSwitch(switches::kDisable3DAPIs);
1524 }
[email protected]718eab62011-10-05 21:16:521525
[email protected]a8d851f82011-12-21 00:32:371526 // Disable client-side phishing detection in the renderer if it is
1527 // disabled in the Profile preferences or the browser process.
1528 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1529 !g_browser_process->safe_browsing_detection_service()) {
1530 command_line->AppendSwitch(
1531 switches::kDisableClientSidePhishingDetection);
1532 }
[email protected]0045b0f42012-07-26 11:52:081533
1534 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211535 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521536
1537 InstantService* instant_service =
1538 InstantServiceFactory::GetForProfile(profile);
1539 if (instant_service &&
1540 instant_service->IsInstantProcess(process->GetID()))
1541 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301542
[email protected]d5bcd06f2013-04-21 08:07:241543#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301544 SigninManager* signin_manager =
1545 SigninManagerFactory::GetForProfile(profile);
1546 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1547 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241548#endif
[email protected]47c7ec82012-01-18 03:29:211549 }
[email protected]4287a3d2011-06-13 23:56:511550
[email protected]47c7ec82012-01-18 03:29:211551 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511552 static const char* const kSwitchNames[] = {
[email protected]b785898a2014-02-05 06:54:431553 autofill::switches::kDisableIgnoreAutocompleteOff,
[email protected]000f3ad2013-05-16 02:19:171554 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]c3cc0632013-10-03 21:54:431555 autofill::switches::kDisablePasswordGeneration,
[email protected]000f3ad2013-05-16 02:19:171556 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]c3cc0632013-10-03 21:54:431557 autofill::switches::kEnablePasswordGeneration,
[email protected]3cbdf9362014-01-31 23:12:231558 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration,
[email protected]558878cc82013-11-09 01:25:511559 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:271560 extensions::switches::kAllowLegacyExtensionManifests,
1561 extensions::switches::kAllowScriptingGallery,
[email protected]c8d02992013-07-31 22:16:511562 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271563 extensions::switches::kExtensionsOnChromeURLs,
[email protected]9d450492013-06-13 23:08:371564 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1565 // to browser.
1566 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511567 switches::kAppsCheckoutURL,
1568 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311569 switches::kCloudPrintServiceURL,
[email protected]382fb0d2012-02-25 00:19:501570 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531571 switches::kDisableExtensionsResourceWhitelist,
[email protected]83c85262013-08-22 21:13:461572 switches::kDisablePnacl,
[email protected]b0553c7e2012-09-19 21:36:111573 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531574 switches::kEnableAdview,
[email protected]1f4da9e2013-06-27 05:23:441575 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211576 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511577 switches::kEnableNaCl,
[email protected]1b4ec382014-03-07 02:32:241578 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:481579 switches::kEnableNaClNonSfiMode,
[email protected]ce304ce2013-02-22 21:54:451580 switches::kEnableNetBenchmarking,
[email protected]9fe9760a2014-03-15 00:11:591581 switches::kEnableOfflineAutoReload,
[email protected]c10b25f2014-01-14 14:57:001582 switches::kEnableStreamlinedHostedApps,
[email protected]4287a3d2011-06-13 23:56:511583 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511584 switches::kMemoryProfiling,
1585 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371586 switches::kNoJsRandomness,
[email protected]8f06e4d2013-11-25 23:20:181587 switches::kOutOfProcessPdf,
[email protected]f45c5f32012-04-18 19:26:371588 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511589 switches::kPpapiFlashArgs,
[email protected]4287a3d2011-06-13 23:56:511590 switches::kPpapiFlashPath,
1591 switches::kPpapiFlashVersion,
1592 switches::kProfilingAtStart,
1593 switches::kProfilingFile,
1594 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371595 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511596 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:381597 switches::kWhitelistedExtensionID,
[email protected]499e7c52013-10-04 16:03:091598 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:511599 };
1600
1601 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1602 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171603 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381604 static const char* const kSwitchNames[] = {
[email protected]558878cc82013-11-09 01:25:511605 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]c8d02992013-07-31 22:16:511606 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271607 extensions::switches::kExtensionsOnChromeURLs,
[email protected]a446534d2012-02-09 00:07:381608 switches::kWhitelistedExtensionID,
1609 };
1610
1611 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1612 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511613 } else if (process_type == switches::kPluginProcess) {
1614 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441615#if defined(OS_CHROMEOS)
1616 chromeos::switches::kLoginProfile,
1617#endif
[email protected]4287a3d2011-06-13 23:56:511618 switches::kMemoryProfiling,
1619 switches::kSilentDumpOnDCHECK,
[email protected]4287a3d2011-06-13 23:56:511620 };
1621
1622 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1623 arraysize(kSwitchNames));
1624 } else if (process_type == switches::kZygoteProcess) {
1625 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511626 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501627 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511628 switches::kPpapiFlashPath,
1629 switches::kPpapiFlashVersion,
1630 };
1631
1632 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1633 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111634 } else if (process_type == switches::kGpuProcess) {
1635 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1636 // because GPU is expected to be unreliable.
1637 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1638 !command_line->HasSwitch(switches::kDisableBreakpad))
1639 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301640 }
[email protected]6f08af82011-09-15 01:19:031641
1642 // The command line switch kEnableBenchmarking needs to be specified along
1643 // with the kEnableStatsTable switch to ensure that the stats table global
1644 // is initialized correctly.
1645 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1646 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301647}
1648
1649std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431650 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351651 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301652 return g_browser_process->GetApplicationLocale();
1653}
1654
[email protected]597a867b2011-11-18 18:31:201655std::string ChromeContentBrowserClient::GetAcceptLangs(
1656 content::BrowserContext* context) {
1657 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371658 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081659}
1660
[email protected]9ec0f452012-05-31 15:58:531661gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221662 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531663 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081664}
1665
[email protected]a2176792011-05-08 19:30:491666bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091667 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191668 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201669 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321670 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201671 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051672 return io_data->GetCookieSettings()->
1673 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491674}
1675
[email protected]ed24fad2011-05-10 22:44:011676bool ChromeContentBrowserClient::AllowGetCookie(
1677 const GURL& url,
1678 const GURL& first_party,
1679 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201680 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011681 int render_process_id,
[email protected]f3add922013-12-20 23:17:161682 int render_frame_id) {
[email protected]ed24fad2011-05-10 22:44:011683 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201684 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051685 bool allow = io_data->GetCookieSettings()->
1686 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011687
[email protected]8093a542011-05-13 07:29:321688 BrowserThread::PostTask(
1689 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031690 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]f7fa5b62014-03-19 15:20:061691 render_frame_id, url, first_party, cookie_list, !allow, true));
[email protected]ed24fad2011-05-10 22:44:011692 return allow;
1693}
1694
1695bool ChromeContentBrowserClient::AllowSetCookie(
1696 const GURL& url,
1697 const GURL& first_party,
1698 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201699 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011700 int render_process_id,
[email protected]f3add922013-12-20 23:17:161701 int render_frame_id,
[email protected]ed24fad2011-05-10 22:44:011702 net::CookieOptions* options) {
1703 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201704 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051705 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1706 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1707
[email protected]8093a542011-05-13 07:29:321708 BrowserThread::PostTask(
1709 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031710 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]f3add922013-12-20 23:17:161711 render_frame_id, url, first_party, cookie_line, *options,
[email protected]fd473d12012-04-05 11:38:431712 !allow));
[email protected]ed24fad2011-05-10 22:44:011713 return allow;
1714}
1715
[email protected]d5a19162011-06-30 18:51:541716bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201717 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541718 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201719 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431720 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1721 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261722
[email protected]bf510ed2012-06-05 08:31:431723 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1724 // Could we even support per-origin settings?
1725 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541726}
1727
[email protected]5c5a88e2011-11-12 00:45:351728bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351729 const GURL& url,
[email protected]96920152013-12-04 21:00:161730 const base::string16& name,
1731 const base::string16& display_name,
[email protected]5c5a88e2011-11-12 00:45:351732 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201733 content::ResourceContext* context,
[email protected]b765deb2013-12-18 06:43:301734 const std::vector<std::pair<int, int> >& render_frames) {
[email protected]5c5a88e2011-11-12 00:45:351735 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201736 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351737 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1738 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1739
[email protected]62151052012-02-01 18:40:481740 // Record access to database for potential display in UI.
1741 std::vector<std::pair<int, int> >::const_iterator i;
[email protected]b765deb2013-12-18 06:43:301742 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
[email protected]62151052012-02-01 18:40:481743 BrowserThread::PostTask(
1744 BrowserThread::UI, FROM_HERE,
1745 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1746 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351747 }
1748
1749 return allow;
1750}
1751
1752bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351753 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201754 content::ResourceContext* context,
[email protected]b765deb2013-12-18 06:43:301755 const std::vector<std::pair<int, int> >& render_frames) {
[email protected]5c5a88e2011-11-12 00:45:351756 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201757 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351758 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1759 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1760
[email protected]62151052012-02-01 18:40:481761 // Record access to file system for potential display in UI.
1762 std::vector<std::pair<int, int> >::const_iterator i;
[email protected]b765deb2013-12-18 06:43:301763 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
[email protected]62151052012-02-01 18:40:481764 BrowserThread::PostTask(
1765 BrowserThread::UI, FROM_HERE,
1766 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1767 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351768 }
1769
1770 return allow;
1771}
1772
[email protected]7c5ff9a2012-03-02 07:42:491773bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1774 const GURL& url,
[email protected]96920152013-12-04 21:00:161775 const base::string16& name,
[email protected]7c5ff9a2012-03-02 07:42:491776 content::ResourceContext* context,
[email protected]b765deb2013-12-18 06:43:301777 const std::vector<std::pair<int, int> >& render_frames) {
[email protected]7c5ff9a2012-03-02 07:42:491778 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1779 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1780 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1781 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1782
1783 // Record access to IndexedDB for potential display in UI.
1784 std::vector<std::pair<int, int> >::const_iterator i;
[email protected]b765deb2013-12-18 06:43:301785 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
[email protected]7c5ff9a2012-03-02 07:42:491786 BrowserThread::PostTask(
1787 BrowserThread::UI, FROM_HERE,
1788 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1789 i->first, i->second, url, name, !allow));
1790 }
1791
1792 return allow;
1793}
1794
[email protected]33ad6ce92013-08-27 14:39:081795net::URLRequestContext*
1796ChromeContentBrowserClient::OverrideRequestContextForURL(
1797 const GURL& url, content::ResourceContext* context) {
1798 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1799 if (url.SchemeIs(extensions::kExtensionScheme)) {
1800 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1801 return io_data->extensions_request_context();
1802 }
1803
1804 return NULL;
1805}
1806
[email protected]317f96c92011-05-31 06:53:411807QuotaPermissionContext*
1808ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1809 return new ChromeQuotaPermissionContext();
1810}
1811
[email protected]848dd042011-06-04 18:24:031812void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171813 int render_process_id,
[email protected]1a4e9752013-12-31 20:10:581814 int render_frame_id,
[email protected]4cf611e32012-02-13 16:06:171815 int cert_error,
1816 const net::SSLInfo& ssl_info,
1817 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021818 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031819 bool overridable,
[email protected]d9be47702012-05-16 03:41:221820 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171821 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001822 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021823 if (resource_type != ResourceType::MAIN_FRAME) {
1824 // A sub-resource has a certificate error. The user doesn't really
1825 // have a context for making the right decision, so block the
1826 // request hard, without an info bar to allow showing the insecure
1827 // content.
[email protected]8c965c22013-05-23 19:28:001828 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021829 return;
1830 }
1831
[email protected]f9034cf2011-07-21 12:43:411832 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]1a4e9752013-12-31 20:10:581833 content::RenderFrameHost* render_frame_host =
1834 content::RenderFrameHost::FromID(render_process_id, render_frame_id);
[email protected]1a4e9752013-12-31 20:10:581835 WebContents* tab = WebContents::FromRenderFrameHost(render_frame_host);
[email protected]f9034cf2011-07-21 12:43:411836 if (!tab) {
1837 NOTREACHED();
1838 return;
1839 }
[email protected]09667f02014-01-06 15:37:571840
1841 prerender::PrerenderContents* prerender_contents =
[email protected]294084d2014-01-06 22:22:021842 prerender::PrerenderContents::FromWebContents(tab);
[email protected]09667f02014-01-06 15:37:571843 if (prerender_contents) {
1844 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
1845 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
1846 return;
[email protected]f9034cf2011-07-21 12:43:411847 }
1848
[email protected]1e87df32012-09-12 04:53:191849#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231850 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1851 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1852 if (captive_portal_tab_helper)
1853 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191854#endif
1855
[email protected]f9034cf2011-07-21 12:43:411856 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221857 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1858 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031859}
1860
[email protected]c99c442e2011-08-24 11:37:301861void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451862 int render_process_id,
[email protected]094c8772013-12-21 17:54:501863 int render_frame_id,
[email protected]7a593db2012-02-13 21:19:401864 const net::HttpNetworkSession* network_session,
1865 net::SSLCertRequestInfo* cert_request_info,
1866 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]094c8772013-12-21 17:54:501867 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID(
1868 render_process_id, render_frame_id);
[email protected]294084d2014-01-06 22:22:021869 WebContents* tab = WebContents::FromRenderFrameHost(rfh);
1870 if (!tab) {
[email protected]094c8772013-12-21 17:54:501871 NOTREACHED();
1872 return;
1873 }
1874
[email protected]294084d2014-01-06 22:22:021875 prerender::PrerenderContents* prerender_contents =
1876 prerender::PrerenderContents::FromWebContents(tab);
1877 if (prerender_contents) {
1878 prerender_contents->Destroy(
1879 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
[email protected]8ec26472011-06-06 16:52:451880 return;
1881 }
1882
[email protected]791879c2013-12-17 07:22:411883 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
1884 DCHECK(requesting_url.is_valid())
1885 << "Invalid URL string: https://"
1886 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:451887
[email protected]627e0512011-12-21 22:55:301888 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]5bcdd99d2013-12-23 18:28:301889 scoped_ptr<base::Value> filter(
[email protected]6786bf402011-12-03 15:19:451890 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1891 requesting_url,
1892 requesting_url,
1893 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1894 std::string(), NULL));
1895
1896 if (filter.get()) {
1897 // Try to automatically select a client certificate.
[email protected]5bcdd99d2013-12-23 18:28:301898 if (filter->IsType(base::Value::TYPE_DICTIONARY)) {
1899 base::DictionaryValue* filter_dict =
1900 static_cast<base::DictionaryValue*>(filter.get());
[email protected]6786bf402011-12-03 15:19:451901
1902 const std::vector<scoped_refptr<net::X509Certificate> >&
1903 all_client_certs = cert_request_info->client_certs;
1904 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091905 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451906 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091907 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451908 return;
1909 }
1910 }
1911 } else {
1912 NOTREACHED();
1913 }
1914 }
1915
[email protected]11feec322012-09-18 03:58:521916 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1917 if (!ssl_tab_helper) {
1918 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451919 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141920 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401921 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451922 return;
1923 }
[email protected]11feec322012-09-18 03:58:521924 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401925 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451926}
1927
[email protected]3b455502012-12-11 18:22:581928void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451929 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581930 net::CertificateMimeType cert_type,
1931 const void* cert_data,
1932 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451933 int render_process_id,
1934 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581935 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1936 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451937}
1938
[email protected]dc73a7b2012-03-25 15:27:181939content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561940 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181941}
1942
[email protected]941623e2011-06-07 23:06:041943void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1944 const GURL& source_origin,
1945 int callback_context,
1946 int render_process_id,
1947 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111948#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021949 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1950 WebContents* contents =
1951 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1952 if (!contents) {
[email protected]941623e2011-06-07 23:06:041953 NOTREACHED();
1954 return;
1955 }
1956
[email protected]d0d9c3ee2012-06-19 03:07:021957 // Skip showing the infobar if the request comes from an extension, and that
1958 // extension has the 'notify' permission. (If the extension does not have the
1959 // permission, the user will still be prompted.)
1960 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]38427a12013-11-09 17:34:201961 InfoMap* extension_info_map =
[email protected]c7cd5942013-04-30 03:31:011962 extensions::ExtensionSystem::Get(profile)->info_map();
1963 DesktopNotificationService* notification_service =
1964 DesktopNotificationServiceFactory::GetForProfile(profile);
1965 const Extension* extension = NULL;
1966 if (extension_info_map) {
[email protected]289c44b2013-12-17 03:26:571967 extensions::ExtensionSet extensions;
[email protected]c7cd5942013-04-30 03:31:011968 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1969 source_origin, render_process_id,
1970 extensions::APIPermission::kNotification, &extensions);
[email protected]289c44b2013-12-17 03:26:571971 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
[email protected]c7cd5942013-04-30 03:31:011972 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381973 if (notification_service->IsNotifierEnabled(NotifierId(
1974 NotifierId::APPLICATION, (*iter)->id()))) {
[email protected]cadac622013-06-11 16:46:361975 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011976 break;
1977 }
1978 }
1979 }
[email protected]eb4832a2012-12-08 01:57:521980 RenderViewHost* rvh =
1981 RenderViewHost::FromID(render_process_id, render_view_id);
1982 if (IsExtensionWithPermissionOrSuggestInConsole(
1983 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021984 if (rvh)
1985 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1986 return;
1987 }
1988
[email protected]c7cd5942013-04-30 03:31:011989 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021990 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111991#else
1992 NOTIMPLEMENTED();
1993#endif
[email protected]941623e2011-06-07 23:06:041994}
1995
[email protected]a1221aea2013-11-07 01:31:301996blink::WebNotificationPresenter::Permission
[email protected]941623e2011-06-07 23:06:041997 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021998 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201999 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:022000 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:112001#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:042002 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]5c129792013-07-10 02:08:482003
[email protected]df02aca2012-02-09 21:03:202004 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9afacd22013-11-13 20:23:312005 InfoMap* extension_info_map = io_data->GetExtensionInfoMap();
[email protected]941623e2011-06-07 23:06:042006
[email protected]9afacd22013-11-13 20:23:312007 // We want to see if there is an extension that hasn't been manually disabled
2008 // that has the notifications permission and applies to this security origin.
2009 // First, get the list of extensions with permission for the origin.
[email protected]289c44b2013-12-17 03:26:572010 extensions::ExtensionSet extensions;
[email protected]9afacd22013-11-13 20:23:312011 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
2012 source_origin, render_process_id,
2013 extensions::APIPermission::kNotification, &extensions);
[email protected]289c44b2013-12-17 03:26:572014 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
[email protected]9afacd22013-11-13 20:23:312015 iter != extensions.end(); ++iter) {
2016 // Then, check to see if it's been disabled by the user.
2017 if (!extension_info_map->AreNotificationsDisabled((*iter)->id()))
2018 return blink::WebNotificationPresenter::PermissionAllowed;
[email protected]c7cd5942013-04-30 03:31:012019 }
2020
[email protected]9afacd22013-11-13 20:23:312021 // No enabled extensions exist, so check the normal host content settings.
2022 HostContentSettingsMap* host_content_settings_map =
2023 io_data->GetHostContentSettingsMap();
2024 ContentSetting setting = host_content_settings_map->GetContentSetting(
2025 source_origin,
2026 source_origin,
2027 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
2028 NO_RESOURCE_IDENTIFIER);
2029
2030 if (setting == CONTENT_SETTING_ALLOW)
2031 return blink::WebNotificationPresenter::PermissionAllowed;
2032 if (setting == CONTENT_SETTING_BLOCK)
2033 return blink::WebNotificationPresenter::PermissionDenied;
[email protected]a1221aea2013-11-07 01:31:302034 return blink::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:112035#else
[email protected]a1221aea2013-11-07 01:31:302036 return blink::WebNotificationPresenter::PermissionAllowed;
[email protected]5fd2e842012-03-01 00:29:112037#endif
[email protected]941623e2011-06-07 23:06:042038}
2039
2040void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:172041 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:042042 int render_process_id,
2043 int render_view_id,
2044 bool worker) {
[email protected]5fd2e842012-03-01 00:29:112045#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:042046 RenderViewHost* rvh = RenderViewHost::FromID(
2047 render_process_id, render_view_id);
2048 if (!rvh) {
2049 NOTREACHED();
2050 return;
2051 }
2052
[email protected]9f76c1e2012-03-05 15:15:582053 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:302054 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:042055 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:372056 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042057 service->ShowDesktopNotification(
2058 params, render_process_id, render_view_id,
2059 worker ? DesktopNotificationService::WorkerNotification :
2060 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:112061#else
2062 NOTIMPLEMENTED();
2063#endif
[email protected]941623e2011-06-07 23:06:042064}
2065
2066void ChromeContentBrowserClient::CancelDesktopNotification(
2067 int render_process_id,
2068 int render_view_id,
2069 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:112070#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:042071 RenderViewHost* rvh = RenderViewHost::FromID(
2072 render_process_id, render_view_id);
2073 if (!rvh) {
2074 NOTREACHED();
2075 return;
2076 }
2077
[email protected]9f76c1e2012-03-05 15:15:582078 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:302079 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:042080 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:372081 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042082 service->CancelDesktopNotification(
2083 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:112084#else
2085 NOTIMPLEMENTED();
2086#endif
[email protected]941623e2011-06-07 23:06:042087}
2088
[email protected]9f3fba52011-06-08 20:37:192089bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:352090 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:572091 const GURL& opener_top_level_frame_url,
[email protected]34eec7ffe32011-11-02 23:49:022092 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:192093 WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:232094 const GURL& target_url,
2095 const content::Referrer& referrer,
2096 WindowOpenDisposition disposition,
2097 const WebWindowFeatures& features,
2098 bool user_gesture,
2099 bool opener_suppressed,
[email protected]df02aca2012-02-09 21:03:202100 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:012101 int render_process_id,
[email protected]190e5e22013-07-27 05:59:232102 bool is_guest,
2103 int opener_id,
[email protected]03b6d552012-03-29 04:03:012104 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:192105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:012106
2107 *no_javascript_access = false;
2108
[email protected]5e5f55e262c52013-09-12 00:27:192109 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]38427a12013-11-09 17:34:202110 InfoMap* map = io_data->GetExtensionInfoMap();
[email protected]5e5f55e262c52013-09-12 00:27:192111
[email protected]9f3fba52011-06-08 20:37:192112 // If the opener is trying to create a background window but doesn't have
2113 // the appropriate permission, fail the attempt.
[email protected]6940eef82013-09-11 11:58:412114 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]03b6d552012-03-29 04:03:012115 if (!map->SecurityOriginHasAPIPermission(
2116 source_origin,
2117 render_process_id,
[email protected]c2e66e12012-06-27 06:27:062118 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:012119 return false;
2120 }
2121
[email protected]7b54ca02012-03-02 18:06:532122 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2123 // return a recently installed Extension even if this CanCreateWindow call
2124 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:012125 // because the permission check above would have caused an early return
2126 // already. We must use the full URL to find hosted apps, though, and not
2127 // just the origin.
[email protected]be9915fb2013-07-18 09:28:552128 const Extension* extension =
2129 map->extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:292130 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:012131 *no_javascript_access = true;
[email protected]190e5e22013-07-27 05:59:232132
2133 return true;
[email protected]9f3fba52011-06-08 20:37:192134 }
[email protected]056efdc2013-04-06 00:14:532135
2136 // No new browser window (popup or tab) in app mode.
2137 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
2138 chrome::IsRunningInForcedAppMode()) {
2139 return false;
2140 }
2141
[email protected]190e5e22013-07-27 05:59:232142 if (is_guest)
2143 return true;
2144
[email protected]190e5e22013-07-27 05:59:232145 HostContentSettingsMap* content_settings =
2146 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap();
[email protected]916615b2013-09-11 18:19:442147 BlockedWindowParams blocked_params(target_url,
2148 referrer,
2149 disposition,
2150 features,
2151 user_gesture,
2152 opener_suppressed,
2153 render_process_id,
2154 opener_id);
[email protected]190e5e22013-07-27 05:59:232155
[email protected]7f53dff2013-08-05 10:45:502156 if (!user_gesture && !CommandLine::ForCurrentProcess()->HasSwitch(
2157 switches::kDisablePopupBlocking)) {
[email protected]931bc922013-09-11 21:42:572158 if (content_settings->GetContentSetting(opener_top_level_frame_url,
2159 opener_top_level_frame_url,
[email protected]190e5e22013-07-27 05:59:232160 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]916615b2013-09-11 18:19:442161 std::string()) !=
[email protected]190e5e22013-07-27 05:59:232162 CONTENT_SETTING_ALLOW) {
[email protected]916615b2013-09-11 18:19:442163 BrowserThread::PostTask(BrowserThread::UI,
2164 FROM_HERE,
2165 base::Bind(&HandleBlockedPopupOnUIThread,
2166 blocked_params));
2167 return false;
[email protected]190e5e22013-07-27 05:59:232168 }
[email protected]916615b2013-09-11 18:19:442169 }
[email protected]190e5e22013-07-27 05:59:232170
[email protected]916615b2013-09-11 18:19:442171#if defined(OS_ANDROID)
2172 if (SingleTabModeTabHelper::IsRegistered(render_process_id, opener_id)) {
[email protected]190e5e22013-07-27 05:59:232173 BrowserThread::PostTask(BrowserThread::UI,
2174 FROM_HERE,
[email protected]916615b2013-09-11 18:19:442175 base::Bind(&HandleSingleTabModeBlockOnUIThread,
2176 blocked_params));
[email protected]190e5e22013-07-27 05:59:232177 return false;
2178 }
[email protected]916615b2013-09-11 18:19:442179#endif
[email protected]190e5e22013-07-27 05:59:232180
[email protected]9f3fba52011-06-08 20:37:192181 return true;
2182}
2183
2184std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:202185 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:192186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2187 // Check if it's an extension-created worker, in which case we want to use
2188 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:202189 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:192190 const Extension* extension =
2191 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
2192 return extension ? extension->name() : std::string();
2193}
2194
[email protected]99907362012-01-11 05:41:402195void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2196 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:172197}
2198
[email protected]7a06d282013-05-03 04:39:332199// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:022200content::SpeechRecognitionManagerDelegate*
2201 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002202#if defined(ENABLE_INPUT_SPEECH)
2203 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
[email protected]a03f2d32012-03-14 00:26:322204#else
[email protected]855e18b2013-07-08 21:02:002205 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
2206 // need the base delegate without the bubble UI.
2207 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:322208#endif
[email protected]66cfec62012-02-24 17:57:512209}
2210
[email protected]ae6e9912011-07-27 01:18:282211net::NetLog* ChromeContentBrowserClient::GetNetLog() {
2212 return g_browser_process->net_log();
2213}
2214
[email protected]32538d92011-08-25 00:09:232215AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
2216 return new ChromeAccessTokenStore();
2217}
2218
[email protected]dbae6b02011-06-29 23:51:412219bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:012220 return true;
[email protected]dbae6b02011-06-29 23:51:412221}
2222
[email protected]64d69de42012-02-06 00:19:542223void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:322224 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:062225 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582226 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:062227 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062228
[email protected]33b79542013-10-18 11:18:452229 // Fill per-script font preferences. These are not registered on Android
2230 // - http://crbug.com/308033.
2231#if !defined(OS_ANDROID)
[email protected]f3986f82012-01-03 20:00:062232 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542233 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:062234 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542235 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:062236 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542237 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062238 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542239 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062240 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542241 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:062242 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542243 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:032244 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
2245 &web_prefs->pictograph_font_family_map);
[email protected]33b79542013-10-18 11:18:452246#endif
[email protected]f3986f82012-01-03 20:00:062247
[email protected]64d69de42012-02-06 00:19:542248 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:402249 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:542250 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:402251 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:542252 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:402253 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:542254 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:402255 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:062256
[email protected]ddf72142012-05-22 04:52:402257 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062258
[email protected]64d69de42012-02-06 00:19:542259 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:402260 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:542261 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:062262 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:542263 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:062264 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
[email protected]5bcdd99d2013-12-23 18:28:302265 const base::DictionaryValue* inspector_settings =
[email protected]f3986f82012-01-03 20:00:062266 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2267 if (inspector_settings) {
[email protected]5bcdd99d2013-12-23 18:28:302268 for (base::DictionaryValue::Iterator iter(*inspector_settings);
2269 !iter.IsAtEnd();
[email protected]c40ef1c2013-02-25 18:42:182270 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062271 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182272 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542273 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182274 std::make_pair(iter.key(), value));
2275 }
[email protected]f3986f82012-01-03 20:00:062276 }
2277 }
[email protected]64d69de42012-02-06 00:19:542278 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062279
[email protected]ddf72142012-05-22 04:52:402280 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542281 web_prefs->javascript_enabled = false;
2282 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2283 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402284 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542285 web_prefs->plugins_enabled = false;
2286 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2287 web_prefs->java_enabled = false;
2288 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402289 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062290
[email protected]64d69de42012-02-06 00:19:542291 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2292 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062293
[email protected]64d69de42012-02-06 00:19:542294 web_prefs->allow_displaying_insecure_content =
2295 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2296 web_prefs->allow_running_insecure_content =
2297 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322298#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:052299 web_prefs->font_scale_factor =
2300 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2301 web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment();
[email protected]d3b935f2012-10-19 23:14:322302 web_prefs->force_enable_zoom =
2303 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
2304#endif
[email protected]5c915252013-05-07 13:15:392305
[email protected]af4256d52013-06-04 20:39:072306#if defined(OS_ANDROID)
2307 web_prefs->password_echo_enabled =
2308 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2309#else
[email protected]9d06d88d2012-02-23 22:37:082310 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072311#endif
2312
[email protected]cfadadd2013-04-03 04:43:022313 web_prefs->asynchronous_spell_checking_enabled = true;
2314 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572315
[email protected]64d69de42012-02-06 00:19:542316 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062317 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542318 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062319 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542320 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062321 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2322
2323 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542324 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062325 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542326 web_prefs->default_encoding);
2327 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402328 prefs->ClearPref(prefs::kDefaultCharset);
2329 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062330 }
[email protected]64d69de42012-02-06 00:19:542331 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062332
[email protected]299d7f12012-05-23 05:31:152333 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232334 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132335 ExtensionService* service =
2336 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062337 if (service) {
[email protected]1e6e2ea2014-01-04 02:01:402338 const GURL& site_url = rvh->GetSiteInstance()->GetSiteURL();
2339 const Extension* extension =
2340 service->extensions()->GetByID(site_url.host());
[email protected]1bc28312012-11-08 08:31:532341 // Ensure that we are only granting extension preferences to URLs with
2342 // the correct scheme. Without this check, chrome-guest:// schemes used by
2343 // webview tags as well as hosts that happen to match the id of an
2344 // installed extension would get the wrong preferences.
[email protected]1e6e2ea2014-01-04 02:01:402345 if (site_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532346 extension_webkit_preferences::SetPreferences(
2347 extension, view_type, web_prefs);
2348 }
[email protected]f3986f82012-01-03 20:00:062349 }
2350
[email protected]cb2edf22013-04-01 20:25:232351 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542352 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232353 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062354 // Disable all kinds of acceleration for background pages.
2355 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542356 web_prefs->force_compositing_mode = false;
2357 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062358 }
[email protected]2e21fe292012-03-02 22:52:322359
[email protected]ff9300872014-01-22 11:09:322360#if defined(OS_CHROMEOS)
[email protected]2e21fe292012-03-02 22:52:322361 // Override the default of suppressing HW compositing for WebUI pages for the
2362 // file manager, which is implemented using WebUI but wants HW acceleration
2363 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532364 if (url.SchemeIs(extensions::kExtensionScheme) &&
[email protected]2de96a52013-08-14 01:18:092365 url.host() == file_manager::kFileManagerAppId) {
[email protected]2e21fe292012-03-02 22:52:322366 web_prefs->accelerated_compositing_enabled = true;
2367 web_prefs->accelerated_2d_canvas_enabled = true;
2368 }
2369#endif
[email protected]181a95ee2011-07-12 19:26:362370}
2371
2372void ChromeContentBrowserClient::UpdateInspectorSetting(
2373 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062374 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582375 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062376 DictionaryPrefUpdate update(
2377 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2378 prefs::kWebKitInspectorSettings);
[email protected]5bcdd99d2013-12-23 18:28:302379 base::DictionaryValue* inspector_settings = update.Get();
2380 inspector_settings->SetWithoutPathExpansion(
2381 key, base::Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362382}
2383
[email protected]b8148ac2011-07-13 22:03:252384void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2385 BrowserURLHandler* handler) {
2386 // Add the default URL handlers.
2387 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2388 BrowserURLHandler::null_handler());
2389 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2390 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2391
[email protected]b3adbd02011-11-30 22:23:272392 // about: handler. Must come before chrome: handler, since it will
2393 // rewrite about: urls to chrome: URLs and then expect chrome: to
2394 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252395 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2396 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:032397
2398 // Handler to rewrite chrome://newtab for InstantExtended.
2399 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2400 &chrome::HandleNewTabURLReverseRewrite);
2401
[email protected]b8148ac2011-07-13 22:03:252402 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242403 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252404}
2405
2406void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372407 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582408 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472409 BrowsingDataRemover* remover =
2410 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552411 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2412 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252413 // BrowsingDataRemover takes care of deleting itself when done.
2414}
2415
2416void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372417 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582418 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472419 BrowsingDataRemover* remover =
2420 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232421 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552422 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252423 // BrowsingDataRemover takes care of deleting itself when done.
2424}
2425
[email protected]650b2d52013-02-10 03:41:452426base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:492427 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:322428}
2429
[email protected]c9b6eb62011-10-18 20:49:392430std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2431 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2432}
2433
[email protected]b7631cc2012-09-15 05:08:382434void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2435 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542436#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382437 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2438 scoped_ptr<ppapi::host::HostFactory>(
2439 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542440#endif
[email protected]b7631cc2012-09-15 05:08:382441}
2442
[email protected]0c7193742012-11-07 19:05:032443content::BrowserPpapiHost*
2444 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2445 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132446 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032447 while (!iter.Done()) {
[email protected]7c766e92013-11-22 20:44:022448 nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>(
2449 iter.GetDelegate());
[email protected]0c7193742012-11-07 19:05:032450 if (host->process() &&
2451 host->process()->GetData().id == plugin_process_id) {
2452 // Found the plugin.
2453 return host->browser_ppapi_host();
2454 }
2455 ++iter;
2456 }
2457 return NULL;
2458}
2459
[email protected]7b38b192013-03-23 18:39:312460bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2461 content::BrowserContext* browser_context, const GURL& site_url) {
2462 if (CommandLine::ForCurrentProcess()->HasSwitch(
2463 switches::kEnableBrowserPluginForAllViewTypes))
2464 return true;
2465
[email protected]22aa4f82013-09-24 17:01:442466 if (content::HasWebUIScheme(site_url))
2467 return true;
2468
[email protected]7b38b192013-03-23 18:39:312469 Profile* profile = Profile::FromBrowserContext(browser_context);
2470 ExtensionService* service =
2471 extensions::ExtensionSystem::Get(profile)->extension_service();
2472 if (!service)
2473 return false;
2474
[email protected]be9915fb2013-07-18 09:28:552475 const Extension* extension =
2476 service->extensions()->GetExtensionOrAppByURL(site_url);
[email protected]7b38b192013-03-23 18:39:312477 if (!extension)
2478 return false;
2479
[email protected]c2d2f102013-04-29 16:42:582480 return extension->HasAPIPermission(APIPermission::kWebView) ||
2481 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312482}
2483
[email protected]38cd8f7f2012-06-15 22:06:072484bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582485 content::BrowserContext* browser_context,
2486 const GURL& url,
[email protected]dda54822013-06-15 01:26:392487 bool private_api,
[email protected]8b92ed182013-09-21 04:47:122488 const content::SocketPermissionRequest* params) {
[email protected]93f72062013-05-29 20:29:402489#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372490 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]289c44b2013-12-17 03:26:572491 const extensions::ExtensionSet* extension_set = NULL;
[email protected]9d450492013-06-13 23:08:372492 if (profile) {
2493 extension_set = extensions::ExtensionSystem::Get(profile)->
2494 extension_service()->extensions();
2495 }
[email protected]dda54822013-06-15 01:26:392496
2497 if (private_api) {
2498 // Access to private socket APIs is controlled by the whitelist.
2499 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2500 allowed_socket_origins_)) {
2501 return true;
2502 }
2503 } else {
2504 // Access to public socket APIs is controlled by extension permissions.
2505 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2506 extension_set) {
2507 const Extension* extension = extension_set->GetByID(url.host());
2508 if (extension) {
[email protected]8b92ed182013-09-21 04:47:122509 if (params) {
2510 extensions::SocketPermission::CheckParam check_params(
2511 params->type, params->host, params->port);
2512 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2513 extension, extensions::APIPermission::kSocket,
2514 &check_params)) {
2515 return true;
2516 }
2517 } else {
2518 if (extensions::PermissionsData::HasAPIPermission(
2519 extension, extensions::APIPermission::kSocket)) {
2520 return true;
2521 }
[email protected]dda54822013-06-15 01:26:392522 }
2523 }
2524 }
2525 }
2526
2527 // Allow both public and private APIs if the command line says so.
2528 return IsHostAllowedByCommandLine(url, extension_set,
2529 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402530#else
[email protected]a658d452012-03-02 12:45:292531 return false;
[email protected]93f72062013-05-29 20:29:402532#endif
[email protected]e461da2f2012-02-16 19:06:402533}
2534
[email protected]a28e3302013-02-03 03:50:432535ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2536 WebContents* web_contents) {
2537 return new ChromeSelectFilePolicy(web_contents);
2538}
2539
[email protected]7d9424702013-04-14 13:14:162540void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2541 std::vector<std::string>* additional_allowed_schemes) {
2542 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2543 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:482544 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:292545 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]7d9424702013-04-14 13:14:162546 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2547}
2548
[email protected]c79859b82014-03-20 22:43:552549void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
2550 std::vector<fileapi::URLRequestAutoMountHandler>* handlers) {
2551}
2552
[email protected]f19bbf62013-07-09 01:22:322553void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:312554 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:532555 const base::FilePath& storage_partition_path,
[email protected]f19bbf62013-07-09 01:22:322556 ScopedVector<fileapi::FileSystemBackend>* additional_backends) {
[email protected]02250952013-04-24 23:52:532557#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032558 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]f19bbf62013-07-09 01:22:322559 additional_backends->push_back(new MediaFileSystemBackend(
[email protected]30a306f42013-06-10 03:09:032560 storage_partition_path,
2561 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]f19bbf62013-07-09 01:22:322562 MediaFileSystemBackend::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532563#endif
[email protected]b40015c2013-06-26 08:13:312564#if defined(OS_CHROMEOS)
[email protected]0ff5eb52013-07-10 20:35:312565 fileapi::ExternalMountPoints* external_mount_points =
2566 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:312567 DCHECK(external_mount_points);
[email protected]f19bbf62013-07-09 01:22:322568 chromeos::FileSystemBackend* backend =
2569 new chromeos::FileSystemBackend(
[email protected]6b154b3c2014-02-05 08:27:292570 new drive::FileSystemBackendDelegate,
[email protected]0ff5eb52013-07-10 20:35:312571 browser_context->GetSpecialStoragePolicy(),
[email protected]b40015c2013-06-26 08:13:312572 external_mount_points,
2573 fileapi::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:322574 backend->AddSystemMountPoints();
2575 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal));
2576 additional_backends->push_back(backend);
[email protected]b40015c2013-06-26 08:13:312577#endif
[email protected]445b7db2013-08-02 04:58:272578
[email protected]e86e2be2013-08-30 11:20:392579 additional_backends->push_back(
2580 new sync_file_system::SyncFileSystemBackend(
2581 Profile::FromBrowserContext(browser_context)));
[email protected]eab6105d2014-01-17 20:55:102582
[email protected]2188c8d2014-03-21 00:58:562583#if defined(ENABLE_SERVICE_DISCOVERY)
[email protected]eab6105d2014-01-17 20:55:102584 if (CommandLine::ForCurrentProcess()->HasSwitch(
2585 switches::kEnablePrivetStorage)) {
2586 additional_backends->push_back(
2587 new local_discovery::PrivetFileSystemBackend(
[email protected]7e503f92014-02-19 02:35:512588 fileapi::ExternalMountPoints::GetSystemInstance(),
2589 browser_context));
[email protected]eab6105d2014-01-17 20:55:102590 }
[email protected]7e503f92014-02-19 02:35:512591#endif
[email protected]02250952013-04-24 23:52:532592}
2593
[email protected]e60c0232011-11-11 19:56:352594#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182595void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2596 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382597 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082598 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392599#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452600 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392601 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2602 DCHECK(!data_path.empty());
2603
[email protected]0daaebfe2014-03-15 00:09:052604 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
[email protected]650b2d52013-02-10 03:41:452605 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392606 data_path.AppendASCII("chrome_100_percent.pak");
[email protected]0daaebfe2014-03-15 00:09:052607 base::File file(chrome_resources_pak, flags);
2608 DCHECK(file.IsValid());
[email protected]73592382013-01-18 19:22:372609 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]0daaebfe2014-03-15 00:09:052610 FileDescriptor(file.Pass())));
[email protected]29699c22012-10-03 23:57:392611
2612 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452613 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392614 GetLocaleFilePath(locale, false);
[email protected]0daaebfe2014-03-15 00:09:052615 file.Initialize(locale_pak, flags);
2616 DCHECK(file.IsValid());
[email protected]29699c22012-10-03 23:57:392617 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
[email protected]0daaebfe2014-03-15 00:09:052618 FileDescriptor(file.Pass())));
[email protected]40da3e0c2012-10-24 22:03:382619
[email protected]650b2d52013-02-10 03:41:452620 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372621 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
[email protected]0daaebfe2014-03-15 00:09:052622 file.Initialize(resources_pack_path, flags);
2623 DCHECK(file.IsValid());
[email protected]73592382013-01-18 19:22:372624 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
[email protected]0daaebfe2014-03-15 00:09:052625 FileDescriptor(file.Pass())));
[email protected]73592382013-01-18 19:22:372626
[email protected]0b818f72013-10-22 00:11:032627 if (breakpad::IsCrashReporterEnabled()) {
[email protected]0daaebfe2014-03-15 00:09:052628 file = breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2629 child_process_id);
2630 if (file.IsValid()) {
2631 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2632 FileDescriptor(file.Pass())));
2633 } else {
[email protected]82174aa2013-01-22 21:53:432634 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2635 "be disabled for this process.";
[email protected]82174aa2013-01-22 21:53:432636 }
[email protected]40da3e0c2012-10-24 22:03:382637 }
[email protected]40da3e0c2012-10-24 22:03:382638
2639#else
2640 int crash_signal_fd = GetCrashSignalFD(command_line);
2641 if (crash_signal_fd >= 0) {
2642 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2643 FileDescriptor(crash_signal_fd,
2644 false)));
2645 }
[email protected]29699c22012-10-03 23:57:392646#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302647}
[email protected]e60c0232011-11-11 19:56:352648#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302649
[email protected]4a65826d2011-08-25 16:04:012650#if defined(OS_WIN)
2651const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2652 return chrome::kBrowserResourcesDll;
2653}
[email protected]34f48682013-03-20 00:30:182654
2655void ChromeContentBrowserClient::PreSpawnRenderer(
2656 sandbox::TargetPolicy* policy,
2657 bool* success) {
2658 // This code is duplicated in nacl_exe_win_64.cc.
2659 // Allow the server side of a pipe restricted to the "chrome.nacl."
2660 // namespace so that it cannot impersonate other system or other chrome
2661 // service pipes.
2662 sandbox::ResultCode result = policy->AddRule(
2663 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2664 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2665 L"\\\\.\\pipe\\chrome.nacl.*");
2666 if (result != sandbox::SBOX_ALL_OK) {
2667 *success = false;
2668 return;
2669 }
2670
2671 // Renderers need to send named pipe handles and shared memory
2672 // segment handles to NaCl loader processes.
2673 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2674 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2675 L"File");
2676 if (result != sandbox::SBOX_ALL_OK) {
2677 *success = false;
2678 return;
2679 }
2680}
[email protected]4a65826d2011-08-25 16:04:012681#endif
2682
[email protected]a6868c22013-10-09 02:50:292683bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2684 content::BrowserContext* browser_context,
2685 const GURL& url) {
2686#if defined(ENABLE_PLUGINS)
2687 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]289c44b2013-12-17 03:26:572688 const extensions::ExtensionSet* extension_set = NULL;
[email protected]a6868c22013-10-09 02:50:292689 if (profile) {
2690 extension_set = extensions::ExtensionSystem::Get(profile)->
2691 extension_service()->extensions();
2692 }
2693 // TODO(teravest): Populate allowed_file_handle_origins_ when FileIO is moved
2694 // from the renderer to the browser.
2695 return IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2696 allowed_file_handle_origins_) ||
2697 IsHostAllowedByCommandLine(url, extension_set,
2698 switches::kAllowNaClFileHandleAPI);
2699#else
2700 return false;
2701#endif
2702}
2703
[email protected]8ddc6b7c2013-12-12 20:42:062704bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs() {
2705#if defined(ENABLE_PLUGINS)
2706 // Allow access for tests.
2707 if (CommandLine::ForCurrentProcess()->HasSwitch(
2708 switches::kEnablePepperTesting)) {
2709 return true;
2710 }
2711
2712 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
[email protected]5abe3e72013-12-19 18:58:542713 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown"
2714 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on
2715 // Chromium builds as well.
[email protected]8ddc6b7c2013-12-12 20:42:062716 return channel <= chrome::VersionInfo::CHANNEL_DEV;
2717#else
2718 return false;
2719#endif
2720}
2721
[email protected]30335fdf02014-02-26 19:51:272722#if defined(ENABLE_WEBRTC)
2723void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2724 CommandLine* to_command_line,
2725 const CommandLine& from_command_line,
2726 VersionInfo::Channel channel) {
2727#if defined(OS_ANDROID)
2728 const VersionInfo::Channel kMaxDisableEncryptionChannel =
2729 VersionInfo::CHANNEL_BETA;
2730#else
2731 const VersionInfo::Channel kMaxDisableEncryptionChannel =
2732 VersionInfo::CHANNEL_DEV;
2733#endif
2734 if (channel <= kMaxDisableEncryptionChannel) {
2735 static const char* const kWebRtcDevSwitchNames[] = {
2736 switches::kDisableWebRtcEncryption,
2737 };
2738 to_command_line->CopySwitchesFrom(from_command_line,
2739 kWebRtcDevSwitchNames,
2740 arraysize(kWebRtcDevSwitchNames));
2741 }
2742}
2743#endif // defined(ENABLE_WEBRTC)
[email protected]8ddc6b7c2013-12-12 20:42:062744
[email protected]d977f9c2011-03-14 16:10:262745} // namespace chrome