blob: 232c2c85b4e65c5436d2d5a41f9478cc29a010f4 [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]76411f412012-02-22 18:56:0637#include "chrome/browser/extensions/extension_host.h"
[email protected]d977f9c2011-03-14 16:10:2638#include "chrome/browser/extensions/extension_service.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]157cc902012-11-02 06:31:5894#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:3495#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:3796#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:1297#include "chrome/common/pref_names.h"
[email protected]4de75262013-12-18 23:16:1298#include "chrome/common/profile_management_switches.h"
[email protected]3e69bc82011-05-26 23:22:3899#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09100#include "chrome/common/url_constants.h"
[email protected]264c0acac2013-10-01 13:33:30101#include "chrome/installer/util/google_update_settings.h"
[email protected]e8f3f9982013-05-10 20:59:53102#include "chromeos/chromeos_constants.h"
[email protected]ef42ee8c82013-11-01 05:26:13103#include "components/nacl/browser/nacl_browser.h"
[email protected]7c766e92013-11-22 20:44:02104#include "components/nacl/browser/nacl_host_message_filter.h"
105#include "components/nacl/browser/nacl_process_host.h"
[email protected]d5d383252013-07-04 14:44:32106#include "components/nacl/common/nacl_process_type.h"
[email protected]1b4ec382014-03-07 02:32:24107#include "components/nacl/common/nacl_switches.h"
[email protected]eba93c92014-01-07 17:34:17108#include "components/translate/core/common/translate_switches.h"
[email protected]75fee372013-03-06 00:42:44109#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43110#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30111#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38112#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03113#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31114#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03115#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59116#include "content/public/browser/child_process_security_policy.h"
[email protected]094c8772013-12-21 17:54:50117#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30118#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33119#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05120#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33121#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19122#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10123#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43124#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18125#include "content/public/common/content_descriptors.h"
[email protected]22aa4f82013-09-24 17:01:44126#include "content/public/common/url_utils.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]49d9b142013-07-19 08:50:27141#include "extensions/common/switches.h"
[email protected]c9b6eb62011-10-18 20:49:39142#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23143#include "grit/ui_resources.h"
[email protected]3b455502012-12-11 18:22:58144#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34145#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06146#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57147#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38148#include "ppapi/host/ppapi_host.h"
[email protected]8ddc6b7c2013-12-12 20:42:06149#include "ppapi/shared_impl/ppapi_switches.h"
[email protected]c9b6eb62011-10-18 20:49:39150#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08151#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac14e2013-05-14 05:30:24152#include "ui/message_center/message_center_util.h"
[email protected]b40015c2013-06-26 08:13:31153#include "webkit/browser/fileapi/external_mount_points.h"
[email protected]fab55e72013-05-31 07:06:18154#include "webkit/common/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:26155
[email protected]b48c9182011-10-26 18:03:30156#if defined(OS_WIN)
[email protected]7fe75ce2014-01-28 02:12:24157#include "base/win/windows_version.h"
[email protected]199fc7a2011-09-28 22:45:38158#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18159#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38160#elif defined(OS_MACOSX)
161#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56162#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]0b818f72013-10-22 00:11:03163#include "components/breakpad/app/breakpad_mac.h"
[email protected]b48c9182011-10-26 18:03:30164#elif defined(OS_CHROMEOS)
165#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]07fe2752014-01-29 11:21:55166#include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
[email protected]f19bbf62013-07-09 01:22:32167#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]5c915252013-05-07 13:15:39168#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49169#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]c94ac692013-07-27 00:50:10170#include "chrome/browser/chromeos/system/input_device_settings.h"
[email protected]931d1042013-04-05 17:50:44171#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26172#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30173#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09174#elif defined(OS_ANDROID)
[email protected]916615b2013-09-11 18:19:44175#include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
[email protected]81054f812012-08-30 00:47:09176#include "chrome/browser/chrome_browser_main_android.h"
[email protected]2b12c322013-09-19 06:53:56177#include "chrome/browser/media/encrypted_media_message_filter_android.h"
[email protected]29699c22012-10-03 23:57:39178#include "chrome/common/descriptors_android.h"
[email protected]0b818f72013-10-22 00:11:03179#include "components/breakpad/browser/crash_dump_manager_android.h"
[email protected]b48c9182011-10-26 18:03:30180#elif defined(OS_POSIX)
181#include "chrome/browser/chrome_browser_main_posix.h"
182#endif
183
[email protected]a220b5932013-09-21 03:47:44184#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]779dd282013-10-19 15:57:02185#include "base/debug/leak_annotations.h"
[email protected]b80f68432011-05-02 17:22:30186#include "base/linux_util.h"
[email protected]0b818f72013-10-22 00:11:03187#include "components/breakpad/app/breakpad_linux.h"
188#include "components/breakpad/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43189#endif
[email protected]b80f68432011-05-02 17:22:30190
[email protected]1e87df32012-09-12 04:53:19191#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
192#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
193#endif
194
[email protected]29699c22012-10-03 23:57:39195#if defined(OS_ANDROID)
196#include "ui/base/ui_base_paths.h"
[email protected]b255a8e0e82013-10-22 04:03:59197#include "ui/gfx/android/device_display_info.h"
[email protected]29699c22012-10-03 23:57:39198#endif
199
[email protected]d5bcd06f2013-04-21 08:07:24200#if !defined(OS_CHROMEOS)
201#include "chrome/browser/signin/signin_manager.h"
202#include "chrome/browser/signin/signin_manager_factory.h"
203#endif
204
[email protected]02250952013-04-24 23:52:53205#if !defined(OS_ANDROID)
[email protected]f19bbf62013-07-09 01:22:32206#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
[email protected]02250952013-04-24 23:52:53207#endif
208
[email protected]6ef98b5a2013-05-31 23:58:31209#if defined(ENABLE_WEBRTC)
210#include "chrome/browser/media/webrtc_logging_handler_host.h"
211#endif
212
[email protected]855e18b2013-07-08 21:02:00213#if defined(ENABLE_INPUT_SPEECH)
214#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h"
215#endif
216
[email protected]ff9300872014-01-22 11:09:32217#if defined(OS_CHROMEOS)
[email protected]473c9a4f2013-09-05 03:09:46218#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]02a3dc122013-06-13 15:07:53219#endif
220
[email protected]e8b6ca02013-07-10 18:00:51221#if defined(TOOLKIT_GTK)
222#include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h"
223#endif
224
225#if defined(TOOLKIT_VIEWS)
226#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
227#endif
228
229#if defined(USE_ASH)
230#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
231#endif
232
233#if defined(USE_AURA)
234#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
235#endif
236
237#if defined(USE_X11)
238#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
239#endif
240
[email protected]c6ce08072013-07-31 07:48:53241#if defined(ENABLE_SPELLCHECK)
242#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
243#endif
244
[email protected]7e503f92014-02-19 02:35:51245
246#if defined(ENABLE_MDNS)
247#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]c7abd422012-09-25 00:20:08257using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00258using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11259using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33260using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13261using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06262using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34263using extensions::Extension;
[email protected]38427a12013-11-09 17:34:20264using extensions::InfoMap;
[email protected]1d5e58b2013-01-31 08:41:40265using extensions::Manifest;
[email protected]593d2a72013-07-26 08:48:38266using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39267
[email protected]c5dbef02011-05-13 05:06:09268namespace {
269
[email protected]eabbfb12013-04-05 23:28:35270// Cached version of the locale so we can return the locale on the I/O
271// thread.
272base::LazyInstance<std::string> g_io_thread_application_locale;
273
[email protected]93f72062013-05-29 20:29:40274#if defined(ENABLE_PLUGINS)
[email protected]10c39222013-11-13 20:09:25275const char* kPredefinedAllowedFileHandleOrigins[] = {
276 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
277 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
278};
279
[email protected]e461da2f2012-02-16 19:06:40280const char* kPredefinedAllowedSocketOrigins[] = {
281 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18282 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45283 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
284 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
285 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
286 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35287 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54288 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
289 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
290 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
291 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
292 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
293 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38294 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58295 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29296 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]3f6fca22013-08-12 23:13:42297 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
298 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
299 "4EB74897CB187C7633357C2FE832E0AD6A44883A", // see crbug.com/234789
300 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
301 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
302 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40303};
[email protected]93f72062013-05-29 20:29:40304#endif
[email protected]e461da2f2012-02-16 19:06:40305
[email protected]f8f93eb2012-09-25 03:06:24306// Returns a copy of the given url with its host set to given host and path set
307// to given path. Other parts of the url will be the same.
308GURL ReplaceURLHostAndPath(const GURL& url,
309 const std::string& host,
310 const std::string& path) {
311 url_canon::Replacements<char> replacements;
312 replacements.SetHost(host.c_str(),
313 url_parse::Component(0, host.length()));
314 replacements.SetPath(path.c_str(),
315 url_parse::Component(0, path.length()));
316 return url.ReplaceComponents(replacements);
317}
318
319// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
320GURL AddUberHost(const GURL& url) {
321 const std::string uber_host = chrome::kChromeUIUberHost;
322 const std::string new_path = url.host() + url.path();
323
324 return ReplaceURLHostAndPath(url, uber_host, new_path);
325}
326
[email protected]045bf7c2012-09-28 20:27:36327// If url->host() is "chrome" and url->path() has characters other than the
328// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
329// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24330bool RemoveUberHost(GURL* url) {
331 if (url->host() != chrome::kChromeUIUberHost)
332 return false;
333
[email protected]045bf7c2012-09-28 20:27:36334 if (url->path().empty() || url->path() == "/")
335 return false;
336
[email protected]f8f93eb2012-09-25 03:06:24337 const std::string old_path = url->path();
338
339 const std::string::size_type separator = old_path.find('/', 1);
340 std::string new_host;
341 std::string new_path;
342 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36343 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24344 } else {
345 new_host = old_path.substr(1, separator - 1);
346 new_path = old_path.substr(separator);
347 }
348
[email protected]44e8add2013-06-13 17:29:15349 // Do not allow URLs with paths empty before the first slash since we can't
350 // have an empty host. (e.g "foo://chrome//")
351 if (new_host.empty())
352 return false;
353
[email protected]f8f93eb2012-09-25 03:06:24354 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
355
[email protected]44e8add2013-06-13 17:29:15356 DCHECK(url->is_valid());
357
[email protected]f8f93eb2012-09-25 03:06:24358 return true;
359}
360
[email protected]b8148ac2011-07-13 22:03:25361// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42362bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24363 // Do not handle special URLs such as "about:foo"
364 if (!url->host().empty()) {
365 const GURL chrome_url = AddUberHost(*url);
366
367 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
368 // be called.
369 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
370 browser_context, chrome_url))
371 return true;
372 }
373
[email protected]863f70a2012-01-27 02:05:50374 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
375 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25376 return false;
377
[email protected]fe69558d2012-03-12 11:34:49378#if defined(OS_CHROMEOS)
379 // Special case : in ChromeOS in Guest mode bookmarks and history are
380 // disabled for security reasons. New tab page explains the reasons, so
381 // we redirect user to new tab page.
382 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
[email protected]2d9748b22014-02-11 00:17:29383 if (url->SchemeIs(content::kChromeUIScheme) &&
[email protected]fe69558d2012-03-12 11:34:49384 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
[email protected]b9171622013-10-01 22:05:23385#if defined(ENABLE_ENHANCED_BOOKMARKS)
386 url->DomainIs(chrome::kChromeUIEnhancedBookmarksHost) ||
387#endif
[email protected]fe69558d2012-03-12 11:34:49388 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);
664 registry->RegisterBooleanPref(
665 prefs::kEnableMemoryInfo,
666 false,
667 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23668}
669
[email protected]eabbfb12013-04-05 23:28:35670// static
671void ChromeContentBrowserClient::SetApplicationLocale(
672 const std::string& locale) {
673 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
674
675 // This object is guaranteed to outlive all threads so we don't have to
676 // worry about the lack of refcounting and can just post as Unretained.
677 //
678 // The common case is that this function is called early in Chrome startup
679 // before any threads are created (it will also be called later if the user
680 // changes the pref). In this case, there will be no threads created and
681 // posting will fail. When there are no threads, we can just set the string
682 // without worrying about threadsafety.
683 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
684 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
685 g_io_thread_application_locale.Get() = locale;
686 }
687}
688
[email protected]50462bf02011-11-21 19:13:31689content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
690 const content::MainFunctionParams& parameters) {
691 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30692 // Construct the Main browser parts based on the OS type.
693#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31694 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04695#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31696 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30697#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22698 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26699#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31700 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14701#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09702 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30703#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31704 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04705#else
[email protected]b48c9182011-10-26 18:03:30706 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31707 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30708#endif
709
[email protected]7e75e4a2013-05-17 17:20:03710 chrome::AddProfilesExtraParts(main_parts);
711
[email protected]c7480942011-11-08 19:18:27712 // Construct additional browser parts. Stages are called in the order in
713 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22714#if defined(TOOLKIT_GTK)
[email protected]e8b6ca02013-07-10 18:00:51715 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04716#endif
[email protected]c7480942011-11-08 19:18:27717
718#if defined(TOOLKIT_VIEWS)
[email protected]e8b6ca02013-07-10 18:00:51719 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27720#endif
721
[email protected]dc04be7c2012-03-15 23:57:49722#if defined(USE_ASH)
[email protected]e8b6ca02013-07-10 18:00:51723 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
[email protected]dc04be7c2012-03-15 23:57:49724#endif
725
[email protected]e050ef142012-03-21 01:04:24726#if defined(USE_AURA)
[email protected]e8b6ca02013-07-10 18:00:51727 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
728#endif
729
730#if defined(USE_X11)
731 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:24732#endif
733
[email protected]95132f52013-04-12 02:19:04734 chrome::AddMetricsExtraParts(main_parts);
735
[email protected]50462bf02011-11-21 19:13:31736 return main_parts;
[email protected]f967b722011-09-07 00:58:04737}
738
[email protected]e94bbcb2012-09-07 05:33:57739std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19740 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57741 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53742 std::string partition_id;
743
744 // The partition ID for webview guest processes is the string value of its
745 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
[email protected]4413d872014-02-20 20:26:55746 if (site.SchemeIs(content::kGuestScheme)) {
[email protected]1bc28312012-11-08 08:31:53747 partition_id = site.spec();
[email protected]4413d872014-02-20 20:26:55748 } else if (site.GetOrigin().spec() == kChromeUIChromeSigninURL) {
749 // Chrome signin page has an embedded iframe of extension and web content,
750 // thus it must be isolated from other webUI pages.
751 partition_id = site.GetOrigin().spec();
752 }
[email protected]1bc28312012-11-08 08:31:53753
[email protected]056efdc2013-04-06 00:14:53754 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53755 return partition_id;
756}
757
758bool ChromeContentBrowserClient::IsValidStoragePartitionId(
759 content::BrowserContext* browser_context,
760 const std::string& partition_id) {
761 // The default ID is empty and is always valid.
762 if (partition_id.empty())
763 return true;
764
765 return GURL(partition_id).is_valid();
766}
767
768void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
769 content::BrowserContext* browser_context,
770 const GURL& site,
[email protected]14acc642012-11-17 12:20:10771 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53772 std::string* partition_domain,
773 std::string* partition_name,
774 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10775 // Default to the browser-wide storage partition and override based on |site|
776 // below.
777 partition_domain->clear();
778 partition_name->clear();
779 *in_memory = false;
780
[email protected]3f24f97c2013-11-17 21:53:33781 bool success = GuestView::GetGuestPartitionConfigForSite(
782 site, partition_domain, partition_name, in_memory);
783
784 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
[email protected]14acc642012-11-17 12:20:10785 // If |can_be_default| is false, the caller is stating that the |site|
786 // should be parsed as if it had isolated storage. In particular it is
787 // important to NOT check ExtensionService for the is_storage_isolated()
788 // attribute because this code path is run during Extension uninstall
789 // to do cleanup after the Extension has already been unloaded from the
790 // ExtensionService.
791 bool is_isolated = !can_be_default;
792 if (can_be_default) {
793 const Extension* extension = NULL;
794 Profile* profile = Profile::FromBrowserContext(browser_context);
795 ExtensionService* extension_service =
796 extensions::ExtensionSystem::Get(profile)->extension_service();
797 if (extension_service) {
[email protected]be9915fb2013-07-18 09:28:55798 extension =
799 extension_service->extensions()->GetExtensionOrAppByURL(site);
[email protected]561e33d52013-04-03 06:58:43800 if (extension &&
801 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10802 is_isolated = true;
803 }
804 }
805 }
[email protected]1bc28312012-11-08 08:31:53806
[email protected]14acc642012-11-17 12:20:10807 if (is_isolated) {
808 CHECK(site.has_host());
809 // For extensions with isolated storage, the the host of the |site| is
810 // the |partition_domain|. The |in_memory| and |partition_name| are only
811 // used in guest schemes so they are cleared here.
812 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53813 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10814 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53815 }
[email protected]4413d872014-02-20 20:26:55816 } else if (site.GetOrigin().spec() == kChromeUIChromeSigninURL) {
817 // Chrome signin page has an embedded iframe of extension and web content,
818 // thus it must be isolated from other webUI pages.
819 *partition_domain = chrome::kChromeUIChromeSigninHost;
[email protected]d1198fd2012-08-13 22:50:19820 }
821
[email protected]14acc642012-11-17 12:20:10822 // Assert that if |can_be_default| is false, the code above must have found a
823 // non-default partition. If this fails, the caller has a serious logic
824 // error about which StoragePartition they expect to be in and it is not
825 // safe to continue.
826 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44827}
828
[email protected]38b098f2012-03-14 21:11:57829content::WebContentsViewDelegate*
830 ChromeContentBrowserClient::GetWebContentsViewDelegate(
831 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27832 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32833}
834
[email protected]738f57a2013-06-29 21:06:54835void ChromeContentBrowserClient::GuestWebContentsCreated(
[email protected]dbbce92c2013-10-31 16:51:19836 SiteInstance* guest_site_instance,
[email protected]738f57a2013-06-29 21:06:54837 WebContents* guest_web_contents,
838 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22839 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54840 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]dbbce92c2013-10-31 16:51:19841 if (!guest_site_instance) {
842 NOTREACHED();
843 return;
844 }
845 GURL guest_site_url = guest_site_instance->GetSiteURL();
846 const std::string& extension_id = guest_site_url.host();
847
848 Profile* profile = Profile::FromBrowserContext(
849 guest_web_contents->GetBrowserContext());
850 ExtensionService* service =
851 extensions::ExtensionSystem::Get(profile)->extension_service();
852 if (!service) {
853 NOTREACHED();
854 return;
855 }
856
857 /// TODO(fsamuel): In the future, certain types of GuestViews won't require
858 // extension bindings. At that point, we should clear |extension_id| instead
859 // of exiting early.
860 if (!service->GetExtensionById(extension_id, false) &&
861 !CommandLine::ForCurrentProcess()->HasSwitch(
862 switches::kEnableBrowserPluginForAllViewTypes)) {
863 NOTREACHED();
864 return;
865 }
866
[email protected]738f57a2013-06-29 21:06:54867 if (opener_web_contents) {
868 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
869 if (!guest) {
870 NOTREACHED();
871 return;
872 }
873
[email protected]50c827d2013-09-13 21:36:09874 // Create a new GuestView of the same type as the opener.
875 *guest_delegate =
[email protected]dbbce92c2013-10-31 16:51:19876 GuestView::Create(guest_web_contents,
877 extension_id,
878 guest->GetViewType());
[email protected]738f57a2013-06-29 21:06:54879 return;
880 }
881
882 if (!extra_params) {
883 NOTREACHED();
884 return;
885 }
886 std::string api_type;
[email protected]90547d72013-08-06 05:57:27887 extra_params->GetString(guestview::kParameterApi, &api_type);
[email protected]738f57a2013-06-29 21:06:54888
[email protected]dbbce92c2013-10-31 16:51:19889 if (api_type.empty())
890 return;
891
[email protected]50c827d2013-09-13 21:36:09892 *guest_delegate =
893 GuestView::Create(guest_web_contents,
[email protected]dbbce92c2013-10-31 16:51:19894 extension_id,
[email protected]50c827d2013-09-13 21:36:09895 GuestView::GetViewTypeFromString(api_type));
[email protected]738f57a2013-06-29 21:06:54896}
897
[email protected]44295a12013-06-05 08:45:46898void ChromeContentBrowserClient::GuestWebContentsAttached(
899 WebContents* guest_web_contents,
900 WebContents* embedder_web_contents,
[email protected]5715566a2013-06-25 00:04:53901 const base::DictionaryValue& extra_params) {
[email protected]22aa4f82013-09-24 17:01:44902
[email protected]dbbce92c2013-10-31 16:51:19903 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
904 if (!guest) {
[email protected]efd6fb02013-08-05 04:44:06905 // It's ok to return here, since we could be running a browser plugin
906 // outside an extension, and don't need to attach a
907 // BrowserPluginGuestDelegate in that case;
908 // e.g. running with flag --enable-browser-plugin-for-all-view-types.
[email protected]738f57a2013-06-29 21:06:54909 return;
[email protected]18699372013-06-25 20:42:55910 }
[email protected]dbbce92c2013-10-31 16:51:19911 guest->Attach(embedder_web_contents, extra_params);
[email protected]44703cc72013-01-24 04:56:06912}
913
[email protected]6f2862742013-12-20 07:53:19914void ChromeContentBrowserClient::RenderProcessWillLaunch(
[email protected]f3b1a082011-11-18 00:34:30915 content::RenderProcessHost* host) {
916 int id = host->GetID();
917 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41918 net::URLRequestContextGetter* context =
919 profile->GetRequestContextForRenderProcess(id);
920
[email protected]ba780c12013-10-01 17:07:06921 host->AddFilter(new ChromeRenderMessageFilter(id, profile, context));
[email protected]afed5112014-02-02 06:01:53922 host->AddFilter(new extensions::ExtensionMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55923#if defined(ENABLE_PLUGINS)
[email protected]ba780c12013-10-01 17:07:06924 host->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55925#endif
[email protected]1ea4c492014-02-15 19:45:17926 host->AddFilter(new cast::CastTransportHostFilter);
[email protected]658677f2012-06-09 06:04:02927#if defined(ENABLE_PRINTING)
[email protected]ba780c12013-10-01 17:07:06928 host->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03929#endif
[email protected]ba780c12013-10-01 17:07:06930 host->AddFilter(new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]c6ce08072013-07-31 07:48:53931#if defined(ENABLE_SPELLCHECK)
[email protected]ba780c12013-10-01 17:07:06932 host->AddFilter(new SpellCheckMessageFilter(id));
[email protected]c6ce08072013-07-31 07:48:53933#endif
[email protected]7ceb99012011-12-21 08:05:56934#if defined(OS_MACOSX)
[email protected]ba780c12013-10-01 17:07:06935 host->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56936#endif
[email protected]49aa5a32014-02-03 10:00:44937 host->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile, context));
[email protected]ba780c12013-10-01 17:07:06938 host->AddFilter(new prerender::PrerenderMessageFilter(id, profile));
[email protected]ba780c12013-10-01 17:07:06939 host->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31940#if defined(ENABLE_WEBRTC)
[email protected]10e5c5e52013-10-03 18:44:06941 WebRtcLoggingHandlerHost* webrtc_logging_handler_host =
[email protected]135bc1d2013-10-21 09:11:37942 new WebRtcLoggingHandlerHost(profile);
[email protected]e7b9b352014-01-29 16:35:27943 host->SetWebRtcLogMessageCallback(base::Bind(
944 &WebRtcLoggingHandlerHost::LogMessage, webrtc_logging_handler_host));
[email protected]10e5c5e52013-10-03 18:44:06945 host->AddFilter(webrtc_logging_handler_host);
946 host->SetUserData(host, new base::UserDataAdapter<WebRtcLoggingHandlerHost>(
947 webrtc_logging_handler_host));
[email protected]6ef98b5a2013-05-31 23:58:31948#endif
[email protected]01e59752013-06-18 00:17:35949#if !defined(DISABLE_NACL)
[email protected]7c766e92013-11-22 20:44:02950 host->AddFilter(new nacl::NaClHostMessageFilter(
[email protected]14230ca2013-06-26 23:33:03951 id, profile->IsOffTheRecord(),
[email protected]a2b4c5c2013-10-18 02:06:07952 profile->GetPath(),
[email protected]14230ca2013-06-26 23:33:03953 context));
[email protected]01e59752013-06-18 00:17:35954#endif
[email protected]2b12c322013-09-19 06:53:56955#if defined(OS_ANDROID)
[email protected]ba780c12013-10-01 17:07:06956 host->AddFilter(new EncryptedMediaMessageFilterAndroid());
[email protected]2b12c322013-09-19 06:53:56957#endif
[email protected]4de75262013-12-18 23:16:12958 if (switches::IsNewProfileManagement())
[email protected]914cf6712013-12-05 01:14:06959 host->AddFilter(new PrincipalsMessageFilter(id));
[email protected]3e69bc82011-05-26 23:22:38960
[email protected]2ccf45c2011-08-19 23:35:50961 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
962 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07963
964 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56965
966 RendererContentSettingRules rules;
[email protected]06153f02013-12-04 03:01:28967 if (host->IsGuest()) {
968 GuestView::GetDefaultContentSettingRules(&rules, profile->IsOffTheRecord());
969 } else {
970 GetRendererContentSettingRules(
971 profile->GetHostContentSettingsMap(), &rules);
972 }
[email protected]edece212011-11-16 11:56:56973 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14974}
975
[email protected]3d7474ff2011-07-27 17:47:37976GURL ChromeContentBrowserClient::GetEffectiveURL(
977 content::BrowserContext* browser_context, const GURL& url) {
978 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52979 if (!profile)
980 return url;
981
[email protected]b3cb3a32013-07-31 01:32:29982 // If the input |url| should be assigned to the Instant renderer, make its
983 // effective URL distinct from other URLs on the search provider's domain.
984 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
985 return chrome::GetEffectiveURLForInstant(url, profile);
986
[email protected]d5bcd06f2013-04-21 08:07:24987#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30988 // If the input |url| should be assigned to the Signin renderer, make its
989 // effective URL distinct from other URLs on the signin service's domain.
990 // Note that the signin renderer will be allowed to sign the user in to
991 // Chrome.
992 if (SigninManager::IsWebBasedSigninFlowURL(url))
993 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24994#endif
[email protected]970c63e2013-03-07 00:25:30995
[email protected]c5dec6292013-01-25 04:54:52996 // If the input |url| is part of an installed app, the effective URL is an
997 // extension URL with the ID of that extension as the host. This has the
998 // effect of grouping apps together in a common SiteInstance.
999 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:131000 extensions::ExtensionSystem::Get(profile)->extension_service();
1001 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:081002 return url;
1003
[email protected]06bdd2b2012-11-30 18:47:131004 const Extension* extension = extension_service->extensions()->
[email protected]be9915fb2013-07-18 09:28:551005 GetHostedAppByURL(url);
[email protected]36fb2c7c2011-04-04 15:49:081006 if (!extension)
1007 return url;
1008
[email protected]15877ca2011-11-18 22:40:521009 // Bookmark apps do not use the hosted app process model, and should be
1010 // treated as normal URLs.
1011 if (extension->from_bookmark())
1012 return url;
1013
[email protected]36fb2c7c2011-04-04 15:49:081014 // If the URL is part of an extension's web extent, convert it to an
1015 // extension URL.
1016 return extension->GetResourceURL(url.path());
1017}
1018
[email protected]056ad2a2011-07-12 02:13:551019bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:371020 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:521021 // Non-extension, non-Instant URLs should generally use
1022 // process-per-site-instance. Because we expect to use the effective URL,
1023 // URLs for hosted apps (apart from bookmark apps) should have an extension
1024 // scheme by now.
1025
1026 Profile* profile = Profile::FromBrowserContext(browser_context);
1027 if (!profile)
1028 return false;
1029
[email protected]df113a12013-07-24 04:56:081030 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:521031 return true;
1032
[email protected]d5bcd06f2013-04-21 08:07:241033#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301034 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
1035 return true;
[email protected]d5bcd06f2013-04-21 08:07:241036#endif
[email protected]970c63e2013-03-07 00:25:301037
[email protected]885c0e92012-11-13 20:27:421038 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:551039 return false;
1040
[email protected]c5dec6292013-01-25 04:54:521041 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:131042 extensions::ExtensionSystem::Get(profile)->extension_service();
1043 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:551044 return false;
1045
[email protected]be9915fb2013-07-18 09:28:551046 const Extension* extension =
1047 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
[email protected]056ad2a2011-07-12 02:13:551048 if (!extension)
1049 return false;
1050
1051 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:531052 // permission, or that does not allow JavaScript access to the background
1053 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:551054 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:401055 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:061056 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:291057 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:531058 return false;
1059 }
1060 }
[email protected]056ad2a2011-07-12 02:13:551061
[email protected]7b54ca02012-03-02 18:06:531062 // Hosted apps that have script access to their background page must use
1063 // process per site, since all instances can make synchronous calls to the
1064 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:551065 return true;
1066}
1067
[email protected]73b718f2014-01-27 02:59:461068// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1069// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411070void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1071 std::vector<std::string>* additional_schemes) {
1072 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]73b718f2014-01-27 02:59:461073 additional_schemes->push_back(chrome::kDomDistillerScheme);
[email protected]672c8c12013-03-07 12:30:061074}
1075
[email protected]7571263c2014-03-10 22:57:091076net::URLRequestContextGetter* ChromeContentBrowserClient::CreateRequestContext(
[email protected]6bd30072013-02-08 18:17:111077 content::BrowserContext* browser_context,
[email protected]7571263c2014-03-10 22:57:091078 content::ProtocolHandlerMap* protocol_handlers,
1079 content::ProtocolHandlerScopedVector protocol_interceptors) {
[email protected]6bd30072013-02-08 18:17:111080 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]7571263c2014-03-10 22:57:091081 return profile->CreateRequestContext(protocol_handlers,
1082 protocol_interceptors.Pass());
[email protected]6bd30072013-02-08 18:17:111083}
1084
1085net::URLRequestContextGetter*
1086ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
1087 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:401088 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:111089 bool in_memory,
[email protected]7571263c2014-03-10 22:57:091090 content::ProtocolHandlerMap* protocol_handlers,
1091 content::ProtocolHandlerScopedVector protocol_interceptors) {
[email protected]6bd30072013-02-08 18:17:111092 Profile* profile = Profile::FromBrowserContext(browser_context);
1093 return profile->CreateRequestContextForStoragePartition(
[email protected]7571263c2014-03-10 22:57:091094 partition_path,
1095 in_memory,
1096 protocol_handlers,
1097 protocol_interceptors.Pass());
[email protected]6bd30072013-02-08 18:17:111098}
1099
[email protected]46fb9442011-12-09 17:57:471100bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1101 return ProfileIOData::IsHandledURL(url);
1102}
1103
[email protected]c4365fa42013-05-14 01:08:241104bool ChromeContentBrowserClient::CanCommitURL(
1105 content::RenderProcessHost* process_host,
1106 const GURL& url) {
1107 // We need to let most extension URLs commit in any process, since this can
1108 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1109 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1110 // cannot be loaded in iframes and should never be requested outside its
1111 // process.
1112 Profile* profile =
1113 Profile::FromBrowserContext(process_host->GetBrowserContext());
1114 ExtensionService* service =
1115 extensions::ExtensionSystem::Get(profile)->extension_service();
1116 if (!service)
1117 return true;
1118 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551119 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]c4365fa42013-05-14 01:08:241120 if (new_extension &&
1121 new_extension->is_hosted_app() &&
1122 new_extension->id() == extension_misc::kWebStoreAppId &&
[email protected]fafdc842014-01-17 18:09:081123 !extensions::ProcessMap::Get(profile)->
1124 Contains(new_extension->id(), process_host->GetID())) {
[email protected]c4365fa42013-05-14 01:08:241125 return false;
1126 }
1127
1128 return true;
1129}
1130
[email protected]9a60d1602013-09-11 04:09:121131bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1132 content::SiteInstance* site_instance, const GURL& url) {
1133 GURL from_url = site_instance->GetSiteURL();
1134 // Do not allow pages from the web or other extensions navigate to
1135 // non-web-accessible extension resources.
1136 if (url.SchemeIs(extensions::kExtensionScheme) &&
1137 (from_url.SchemeIsHTTPOrHTTPS() ||
1138 from_url.SchemeIs(extensions::kExtensionScheme))) {
1139 Profile* profile = Profile::FromBrowserContext(
1140 site_instance->GetProcess()->GetBrowserContext());
1141 ExtensionService* service =
1142 extensions::ExtensionSystem::Get(profile)->extension_service();
1143 if (!service)
1144 return true;
1145 const Extension* extension =
1146 service->extensions()->GetExtensionOrAppByURL(url);
1147 if (!extension)
1148 return true;
1149 const Extension* from_extension =
1150 service->extensions()->GetExtensionOrAppByURL(
1151 site_instance->GetSiteURL());
1152 if (from_extension && from_extension->id() == extension->id())
1153 return true;
1154
1155 if (!extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
1156 extension, url.path()))
1157 return false;
1158 }
1159 return true;
1160}
1161
[email protected]2a5221b2011-09-27 23:07:311162bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301163 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311164 const GURL& site_url) {
1165 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301166 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521167 // This may be NULL during tests. In that case, just assume any site can
1168 // share any host.
1169 if (!profile)
1170 return true;
1171
[email protected]d43f99fe2013-04-03 00:20:141172 // Instant URLs should only be in the instant process and instant process
1173 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521174 InstantService* instant_service =
1175 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141176 if (instant_service) {
1177 bool is_instant_process = instant_service->IsInstantProcess(
1178 process_host->GetID());
1179 bool should_be_in_instant_process =
1180 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1181 if (is_instant_process || should_be_in_instant_process)
1182 return is_instant_process && should_be_in_instant_process;
1183 }
[email protected]c5dec6292013-01-25 04:54:521184
[email protected]d5bcd06f2013-04-21 08:07:241185#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301186 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1187 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1188 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241189#endif
[email protected]970c63e2013-03-07 00:25:301190
[email protected]06bdd2b2012-11-30 18:47:131191 ExtensionService* service =
1192 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]fafdc842014-01-17 18:09:081193 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile);
[email protected]2a5221b2011-09-27 23:07:311194
[email protected]ffa97602011-11-17 17:55:521195 // Don't allow the Task Manager to share a process with anything else.
1196 // Otherwise it can affect the renderers it is observing.
1197 // Note: we could create another RenderProcessHostPrivilege bucket for
1198 // this to allow multiple chrome://tasks instances to share, but that's
1199 // a very unlikely case without serious consequences.
1200 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1201 return false;
1202
[email protected]8d3132f62011-10-12 07:13:421203 // These may be NULL during tests. In that case, just assume any site can
1204 // share any host.
[email protected]6f371442011-11-09 06:45:461205 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311206 return true;
1207
[email protected]eec0b33c2011-12-05 22:09:451208 // Otherwise, just make sure the process privilege matches the privilege
1209 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571210 RenderProcessHostPrivilege privilege_required =
1211 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451212 return GetProcessPrivilege(process_host, process_map, service) ==
1213 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311214}
1215
[email protected]76411f412012-02-22 18:56:061216// This function is trying to limit the amount of processes used by extensions
1217// with background pages. It uses a globally set percentage of processes to
1218// run such extensions and if the limit is exceeded, it returns true, to
1219// indicate to the content module to group extensions together.
1220bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1221 content::BrowserContext* browser_context, const GURL& url) {
1222 // It has to be a valid URL for us to check for an extension.
1223 if (!url.is_valid())
1224 return false;
1225
1226 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191227 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131228 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061229 if (!service)
1230 return false;
1231
1232 // We have to have a valid extension with background page to proceed.
1233 const Extension* extension =
[email protected]be9915fb2013-07-18 09:28:551234 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]76411f412012-02-22 18:56:061235 if (!extension)
1236 return false;
[email protected]9367eabc2013-03-01 01:29:291237 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061238 return false;
1239
1240 std::set<int> process_ids;
1241 size_t max_process_count =
1242 content::RenderProcessHost::GetMaxRendererProcessCount();
1243
1244 // Go through all profiles to ensure we have total count of extension
1245 // processes containing background pages, otherwise one profile can
1246 // starve the other.
1247 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1248 GetLoadedProfiles();
1249 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]98b6d942013-11-10 00:34:071250 extensions::ProcessManager* epm =
[email protected]be93bba02012-10-24 16:44:031251 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]98b6d942013-11-10 00:34:071252 for (extensions::ProcessManager::const_iterator iter =
[email protected]d1fe1352012-04-26 00:47:321253 epm->background_hosts().begin();
1254 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131255 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321256 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061257 }
1258 }
1259
1260 if (process_ids.size() >
1261 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1262 return true;
1263 }
1264
1265 return false;
1266}
1267
[email protected]6f371442011-11-09 06:45:461268void ChromeContentBrowserClient::SiteInstanceGotProcess(
1269 SiteInstance* site_instance) {
1270 CHECK(site_instance->HasProcess());
1271
1272 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021273 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521274 if (!profile)
1275 return;
1276
1277 // Remember the ID of the Instant process to signal the renderer process
1278 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031279 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321280 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521281 InstantService* instant_service =
1282 InstantServiceFactory::GetForProfile(profile);
1283 if (instant_service)
1284 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1285 }
1286
[email protected]d5bcd06f2013-04-21 08:07:241287#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301288 // We only expect there to be one signin process as we use process-per-site
1289 // for signin URLs. The signin process will be cleared from SigninManager
1290 // when the renderer is destroyed.
1291 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1292 SigninManager* signin_manager =
1293 SigninManagerFactory::GetForProfile(profile);
1294 if (signin_manager)
1295 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461296 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:201297 BrowserThread::IO,
1298 FROM_HERE,
1299 base::Bind(&InfoMap::SetSigninProcess,
[email protected]1deace22013-05-22 06:14:461300 extensions::ExtensionSystem::Get(profile)->info_map(),
1301 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301302 }
[email protected]d5bcd06f2013-04-21 08:07:241303#endif
[email protected]970c63e2013-03-07 00:25:301304
[email protected]06bdd2b2012-11-30 18:47:131305 ExtensionService* service =
1306 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461307 if (!service)
1308 return;
1309
[email protected]be9915fb2013-07-18 09:28:551310 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1311 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461312 if (!extension)
1313 return;
1314
[email protected]fafdc842014-01-17 18:09:081315 extensions::ProcessMap::Get(profile)
1316 ->Insert(extension->id(),
1317 site_instance->GetProcess()->GetID(),
1318 site_instance->GetId());
1319
[email protected]6f371442011-11-09 06:45:461320 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:201321 BrowserThread::IO,
1322 FROM_HERE,
1323 base::Bind(&InfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591324 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461325 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351326 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331327 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461328}
1329
1330void ChromeContentBrowserClient::SiteInstanceDeleting(
1331 SiteInstance* site_instance) {
1332 if (!site_instance->HasProcess())
1333 return;
1334
1335 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021336 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131337 ExtensionService* service =
1338 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461339 if (!service)
1340 return;
1341
[email protected]be9915fb2013-07-18 09:28:551342 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1343 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461344 if (!extension)
1345 return;
1346
[email protected]fafdc842014-01-17 18:09:081347 extensions::ProcessMap::Get(profile)
1348 ->Remove(extension->id(),
1349 site_instance->GetProcess()->GetID(),
1350 site_instance->GetId());
1351
[email protected]6f371442011-11-09 06:45:461352 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:201353 BrowserThread::IO,
1354 FROM_HERE,
1355 base::Bind(&InfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591356 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461357 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351358 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331359 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461360}
1361
[email protected]896c6d52014-01-28 21:40:211362void ChromeContentBrowserClient::WorkerProcessCreated(
1363 SiteInstance* site_instance,
1364 int worker_process_id) {
1365 extensions::ExtensionRegistry* extension_registry =
1366 extensions::ExtensionRegistry::Get(site_instance->GetBrowserContext());
1367 if (!extension_registry)
1368 return;
1369 const Extension* extension =
1370 extension_registry->enabled_extensions().GetExtensionOrAppByURL(
1371 site_instance->GetSiteURL());
1372 if (!extension)
1373 return;
1374 extensions::ExtensionSystem* extension_system =
[email protected]59b0e602014-01-30 00:41:241375 extensions::ExtensionSystem::Get(site_instance->GetBrowserContext());
[email protected]896c6d52014-01-28 21:40:211376 extension_system->info_map()->RegisterExtensionWorkerProcess(
1377 extension->id(),
1378 worker_process_id,
1379 site_instance->GetId());
1380}
1381
1382void ChromeContentBrowserClient::WorkerProcessTerminated(
1383 SiteInstance* site_instance,
1384 int worker_process_id) {
1385 extensions::ExtensionSystem* extension_system =
[email protected]59b0e602014-01-30 00:41:241386 extensions::ExtensionSystem::Get(site_instance->GetBrowserContext());
[email protected]896c6d52014-01-28 21:40:211387 extension_system->info_map()->UnregisterExtensionWorkerProcess(
1388 worker_process_id);
1389}
1390
[email protected]453f5432013-11-26 19:43:001391bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141392 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081393 const GURL& current_url,
1394 const GURL& new_url) {
[email protected]2aca9a92013-12-03 05:16:071395 // If we don't have an ExtensionService, then rely on the SiteInstance logic
[email protected]a5a59482013-12-03 22:52:061396 // in RenderFrameHostManager to decide when to swap.
[email protected]e9841fbd2013-02-22 23:12:141397 Profile* profile =
1398 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1399 ExtensionService* service =
1400 extensions::ExtensionSystem::Get(profile)->extension_service();
1401 if (!service)
1402 return false;
1403
[email protected]2aca9a92013-12-03 05:16:071404 // We must use a new BrowsingInstance (forcing a process swap and disabling
1405 // scripting by existing tabs) if one of the URLs is an extension and the
1406 // other is not the exact same extension.
1407 //
1408 // We ignore hosted apps here so that other tabs in their BrowsingInstance can
1409 // use postMessage with them. (The exception is the Chrome Web Store, which
1410 // is a hosted app that requires its own BrowsingInstance.) Navigations
1411 // to/from a hosted app will still trigger a SiteInstance swap in
[email protected]a5a59482013-12-03 22:52:061412 // RenderFrameHostManager.
[email protected]2aca9a92013-12-03 05:16:071413 const Extension* current_extension =
1414 service->extensions()->GetExtensionOrAppByURL(current_url);
1415 if (current_extension &&
1416 current_extension->is_hosted_app() &&
1417 current_extension->id() != extension_misc::kWebStoreAppId)
1418 current_extension = NULL;
1419
[email protected]e9841fbd2013-02-22 23:12:141420 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551421 service->extensions()->GetExtensionOrAppByURL(new_url);
[email protected]e9841fbd2013-02-22 23:12:141422 if (new_extension &&
1423 new_extension->is_hosted_app() &&
1424 new_extension->id() != extension_misc::kWebStoreAppId)
1425 new_extension = NULL;
[email protected]2aca9a92013-12-03 05:16:071426
1427 // First do a process check. We should force a BrowsingInstance swap if the
1428 // current process doesn't know about new_extension, even if current_extension
1429 // is somehow the same as new_extension.
[email protected]fafdc842014-01-17 18:09:081430 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile);
[email protected]e9841fbd2013-02-22 23:12:141431 if (new_extension &&
1432 site_instance->HasProcess() &&
[email protected]fafdc842014-01-17 18:09:081433 !process_map->Contains(
1434 new_extension->id(), site_instance->GetProcess()->GetID()))
[email protected]e9841fbd2013-02-22 23:12:141435 return true;
1436
[email protected]2aca9a92013-12-03 05:16:071437 // Otherwise, swap BrowsingInstances if current_extension and new_extension
1438 // differ.
1439 return current_extension != new_extension;
[email protected]e3daf3c2011-10-05 21:17:081440}
1441
[email protected]395045c2012-05-22 15:04:381442bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1443 content::ResourceContext* resource_context, const GURL& current_url,
1444 const GURL& new_url) {
1445 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1446 return extensions::CrossesExtensionProcessBoundary(
1447 io_data->GetExtensionInfoMap()->extensions(),
[email protected]be9915fb2013-07-18 09:28:551448 current_url, new_url, false);
[email protected]395045c2012-05-22 15:04:381449}
1450
[email protected]3d831992013-07-04 01:13:291451bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1452 return !url.SchemeIs(chrome::kChromeNativeScheme);
1453}
1454
[email protected]763ec4ca2011-04-29 15:48:121455std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1456 const std::string& alias_name) {
1457 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1458}
1459
[email protected]b80f68432011-05-02 17:22:301460void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1461 CommandLine* command_line, int child_process_id) {
[email protected]264c0acac2013-10-01 13:33:301462#if defined(OS_POSIX)
[email protected]0b818f72013-10-22 00:11:031463 if (breakpad::IsCrashReporterEnabled()) {
[email protected]264c0acac2013-10-01 13:33:301464 std::string enable_crash_reporter;
1465 GoogleUpdateSettings::GetMetricsId(&enable_crash_reporter);
1466#if !defined(OS_MACOSX)
1467 enable_crash_reporter += "," + base::GetLinuxDistro();
1468#endif
[email protected]b80f68432011-05-02 17:22:301469 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
[email protected]264c0acac2013-10-01 13:33:301470 enable_crash_reporter);
[email protected]b80f68432011-05-02 17:22:301471 }
[email protected]264c0acac2013-10-01 13:33:301472#endif // OS_POSIX
[email protected]b80f68432011-05-02 17:22:301473
[email protected]f1933792011-06-14 00:49:341474 if (logging::DialogsAreSuppressed())
1475 command_line->AppendSwitch(switches::kNoErrorDialogs);
1476
[email protected]b80f68432011-05-02 17:22:301477 std::string process_type =
1478 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171479 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321480
[email protected]7c9b6f92013-09-10 18:11:351481 static const char* const kCommonSwitchNames[] = {
[email protected]aa051272014-03-10 05:56:561482 switches::kUserAgent,
[email protected]7c9b6f92013-09-10 18:11:351483 switches::kUserDataDir, // Make logs go to the right file.
1484 };
1485 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
1486 arraysize(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:321487
[email protected]8c64e282013-11-28 16:05:141488#if defined(ENABLE_IPC_FUZZER)
1489 static const char* const kIpcFuzzerSwitches[] = {
1490 switches::kIpcFuzzerTestcase,
1491 };
1492 command_line->CopySwitchesFrom(browser_command_line, kIpcFuzzerSwitches,
1493 arraysize(kIpcFuzzerSwitches));
1494#endif
1495
[email protected]718eab62011-10-05 21:16:521496 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:301497#if defined(OS_CHROMEOS)
1498 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441499 browser_command_line.GetSwitchValueASCII(
1500 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301501 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441502 command_line->AppendSwitchASCII(
1503 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301504#endif
1505
[email protected]50fa4d5f2013-11-05 00:53:231506#if defined(ENABLE_WEBRTC)
[email protected]30335fdf02014-02-26 19:51:271507 MaybeCopyDisableWebRtcEncryptionSwitch(command_line,
1508 browser_command_line,
1509 VersionInfo::GetChannel());
[email protected]50fa4d5f2013-11-05 00:53:231510#endif
1511
[email protected]f3b1a082011-11-18 00:34:301512 content::RenderProcessHost* process =
1513 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371514 if (process) {
1515 Profile* profile = Profile::FromBrowserContext(
1516 process->GetBrowserContext());
[email protected]fafdc842014-01-17 18:09:081517
1518 if (extensions::ProcessMap::Get(profile)->Contains(process->GetID()))
1519 command_line->AppendSwitch(extensions::switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:301520
[email protected]a8d851f82011-12-21 00:32:371521 PrefService* prefs = profile->GetPrefs();
1522 // Currently this pref is only registered if applied via a policy.
1523 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1524 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1525 // Turn this policy into a command line switch.
1526 command_line->AppendSwitch(switches::kDisable3DAPIs);
1527 }
[email protected]718eab62011-10-05 21:16:521528
[email protected]a8d851f82011-12-21 00:32:371529 // Disable client-side phishing detection in the renderer if it is
1530 // disabled in the Profile preferences or the browser process.
1531 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1532 !g_browser_process->safe_browsing_detection_service()) {
1533 command_line->AppendSwitch(
1534 switches::kDisableClientSidePhishingDetection);
1535 }
[email protected]0045b0f42012-07-26 11:52:081536
1537 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211538 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521539
1540 InstantService* instant_service =
1541 InstantServiceFactory::GetForProfile(profile);
1542 if (instant_service &&
1543 instant_service->IsInstantProcess(process->GetID()))
1544 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301545
[email protected]d5bcd06f2013-04-21 08:07:241546#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301547 SigninManager* signin_manager =
1548 SigninManagerFactory::GetForProfile(profile);
1549 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1550 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241551#endif
[email protected]47c7ec82012-01-18 03:29:211552 }
[email protected]4287a3d2011-06-13 23:56:511553
[email protected]47c7ec82012-01-18 03:29:211554 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511555 static const char* const kSwitchNames[] = {
[email protected]b785898a2014-02-05 06:54:431556 autofill::switches::kDisableIgnoreAutocompleteOff,
[email protected]000f3ad2013-05-16 02:19:171557 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]c3cc0632013-10-03 21:54:431558 autofill::switches::kDisablePasswordGeneration,
[email protected]000f3ad2013-05-16 02:19:171559 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]c3cc0632013-10-03 21:54:431560 autofill::switches::kEnablePasswordGeneration,
[email protected]3cbdf9362014-01-31 23:12:231561 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration,
[email protected]558878cc82013-11-09 01:25:511562 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:271563 extensions::switches::kAllowLegacyExtensionManifests,
1564 extensions::switches::kAllowScriptingGallery,
[email protected]c8d02992013-07-31 22:16:511565 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271566 extensions::switches::kExtensionsOnChromeURLs,
[email protected]9d450492013-06-13 23:08:371567 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1568 // to browser.
1569 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511570 switches::kAppsCheckoutURL,
1571 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311572 switches::kCloudPrintServiceURL,
[email protected]382fb0d2012-02-25 00:19:501573 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531574 switches::kDisableExtensionsResourceWhitelist,
[email protected]83c85262013-08-22 21:13:461575 switches::kDisablePnacl,
[email protected]b0553c7e2012-09-19 21:36:111576 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531577 switches::kEnableAdview,
[email protected]1f4da9e2013-06-27 05:23:441578 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211579 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511580 switches::kEnableNaCl,
[email protected]1b4ec382014-03-07 02:32:241581 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:481582 switches::kEnableNaClNonSfiMode,
[email protected]ce304ce2013-02-22 21:54:451583 switches::kEnableNetBenchmarking,
[email protected]c10b25f2014-01-14 14:57:001584 switches::kEnableStreamlinedHostedApps,
[email protected]4287a3d2011-06-13 23:56:511585 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511586 switches::kMemoryProfiling,
1587 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371588 switches::kNoJsRandomness,
[email protected]8f06e4d2013-11-25 23:20:181589 switches::kOutOfProcessPdf,
[email protected]f45c5f32012-04-18 19:26:371590 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511591 switches::kPpapiFlashArgs,
[email protected]4287a3d2011-06-13 23:56:511592 switches::kPpapiFlashPath,
1593 switches::kPpapiFlashVersion,
1594 switches::kProfilingAtStart,
1595 switches::kProfilingFile,
1596 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371597 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511598 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:381599 switches::kWhitelistedExtensionID,
[email protected]499e7c52013-10-04 16:03:091600 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:511601 };
1602
1603 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1604 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171605 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381606 static const char* const kSwitchNames[] = {
[email protected]558878cc82013-11-09 01:25:511607 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]c8d02992013-07-31 22:16:511608 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271609 extensions::switches::kExtensionsOnChromeURLs,
[email protected]a446534d2012-02-09 00:07:381610 switches::kWhitelistedExtensionID,
1611 };
1612
1613 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1614 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511615 } else if (process_type == switches::kPluginProcess) {
1616 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441617#if defined(OS_CHROMEOS)
1618 chromeos::switches::kLoginProfile,
1619#endif
[email protected]4287a3d2011-06-13 23:56:511620 switches::kMemoryProfiling,
1621 switches::kSilentDumpOnDCHECK,
[email protected]4287a3d2011-06-13 23:56:511622 };
1623
1624 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1625 arraysize(kSwitchNames));
1626 } else if (process_type == switches::kZygoteProcess) {
1627 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511628 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501629 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511630 switches::kPpapiFlashPath,
1631 switches::kPpapiFlashVersion,
1632 };
1633
1634 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1635 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111636 } else if (process_type == switches::kGpuProcess) {
1637 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1638 // because GPU is expected to be unreliable.
1639 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1640 !command_line->HasSwitch(switches::kDisableBreakpad))
1641 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301642 }
[email protected]6f08af82011-09-15 01:19:031643
1644 // The command line switch kEnableBenchmarking needs to be specified along
1645 // with the kEnableStatsTable switch to ensure that the stats table global
1646 // is initialized correctly.
1647 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1648 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301649}
1650
1651std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431652 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351653 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301654 return g_browser_process->GetApplicationLocale();
1655}
1656
[email protected]597a867b2011-11-18 18:31:201657std::string ChromeContentBrowserClient::GetAcceptLangs(
1658 content::BrowserContext* context) {
1659 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371660 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081661}
1662
[email protected]9ec0f452012-05-31 15:58:531663gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221664 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531665 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081666}
1667
[email protected]a2176792011-05-08 19:30:491668bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091669 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191670 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201671 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321672 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201673 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051674 return io_data->GetCookieSettings()->
1675 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491676}
1677
[email protected]ed24fad2011-05-10 22:44:011678bool ChromeContentBrowserClient::AllowGetCookie(
1679 const GURL& url,
1680 const GURL& first_party,
1681 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201682 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011683 int render_process_id,
[email protected]f3add922013-12-20 23:17:161684 int render_frame_id) {
[email protected]ed24fad2011-05-10 22:44:011685 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201686 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051687 bool allow = io_data->GetCookieSettings()->
1688 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011689
[email protected]8093a542011-05-13 07:29:321690 BrowserThread::PostTask(
1691 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031692 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]f3add922013-12-20 23:17:161693 render_frame_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011694 return allow;
1695}
1696
1697bool ChromeContentBrowserClient::AllowSetCookie(
1698 const GURL& url,
1699 const GURL& first_party,
1700 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201701 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011702 int render_process_id,
[email protected]f3add922013-12-20 23:17:161703 int render_frame_id,
[email protected]ed24fad2011-05-10 22:44:011704 net::CookieOptions* options) {
1705 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201706 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051707 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1708 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1709
[email protected]8093a542011-05-13 07:29:321710 BrowserThread::PostTask(
1711 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031712 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]f3add922013-12-20 23:17:161713 render_frame_id, url, first_party, cookie_line, *options,
[email protected]fd473d12012-04-05 11:38:431714 !allow));
[email protected]ed24fad2011-05-10 22:44:011715 return allow;
1716}
1717
[email protected]d5a19162011-06-30 18:51:541718bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201719 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541720 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201721 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431722 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1723 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261724
[email protected]bf510ed2012-06-05 08:31:431725 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1726 // Could we even support per-origin settings?
1727 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541728}
1729
[email protected]5c5a88e2011-11-12 00:45:351730bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351731 const GURL& url,
[email protected]96920152013-12-04 21:00:161732 const base::string16& name,
1733 const base::string16& display_name,
[email protected]5c5a88e2011-11-12 00:45:351734 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201735 content::ResourceContext* context,
[email protected]b765deb2013-12-18 06:43:301736 const std::vector<std::pair<int, int> >& render_frames) {
[email protected]5c5a88e2011-11-12 00:45:351737 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201738 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351739 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1740 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1741
[email protected]62151052012-02-01 18:40:481742 // Record access to database for potential display in UI.
1743 std::vector<std::pair<int, int> >::const_iterator i;
[email protected]b765deb2013-12-18 06:43:301744 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
[email protected]62151052012-02-01 18:40:481745 BrowserThread::PostTask(
1746 BrowserThread::UI, FROM_HERE,
1747 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1748 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351749 }
1750
1751 return allow;
1752}
1753
1754bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351755 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201756 content::ResourceContext* context,
[email protected]b765deb2013-12-18 06:43:301757 const std::vector<std::pair<int, int> >& render_frames) {
[email protected]5c5a88e2011-11-12 00:45:351758 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201759 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351760 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1761 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1762
[email protected]62151052012-02-01 18:40:481763 // Record access to file system for potential display in UI.
1764 std::vector<std::pair<int, int> >::const_iterator i;
[email protected]b765deb2013-12-18 06:43:301765 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
[email protected]62151052012-02-01 18:40:481766 BrowserThread::PostTask(
1767 BrowserThread::UI, FROM_HERE,
1768 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1769 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351770 }
1771
1772 return allow;
1773}
1774
[email protected]7c5ff9a2012-03-02 07:42:491775bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1776 const GURL& url,
[email protected]96920152013-12-04 21:00:161777 const base::string16& name,
[email protected]7c5ff9a2012-03-02 07:42:491778 content::ResourceContext* context,
[email protected]b765deb2013-12-18 06:43:301779 const std::vector<std::pair<int, int> >& render_frames) {
[email protected]7c5ff9a2012-03-02 07:42:491780 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1781 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1782 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1783 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1784
1785 // Record access to IndexedDB for potential display in UI.
1786 std::vector<std::pair<int, int> >::const_iterator i;
[email protected]b765deb2013-12-18 06:43:301787 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
[email protected]7c5ff9a2012-03-02 07:42:491788 BrowserThread::PostTask(
1789 BrowserThread::UI, FROM_HERE,
1790 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1791 i->first, i->second, url, name, !allow));
1792 }
1793
1794 return allow;
1795}
1796
[email protected]33ad6ce92013-08-27 14:39:081797net::URLRequestContext*
1798ChromeContentBrowserClient::OverrideRequestContextForURL(
1799 const GURL& url, content::ResourceContext* context) {
1800 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1801 if (url.SchemeIs(extensions::kExtensionScheme)) {
1802 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1803 return io_data->extensions_request_context();
1804 }
1805
1806 return NULL;
1807}
1808
[email protected]317f96c92011-05-31 06:53:411809QuotaPermissionContext*
1810ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1811 return new ChromeQuotaPermissionContext();
1812}
1813
[email protected]848dd042011-06-04 18:24:031814void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171815 int render_process_id,
[email protected]1a4e9752013-12-31 20:10:581816 int render_frame_id,
[email protected]4cf611e32012-02-13 16:06:171817 int cert_error,
1818 const net::SSLInfo& ssl_info,
1819 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021820 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031821 bool overridable,
[email protected]d9be47702012-05-16 03:41:221822 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171823 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001824 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021825 if (resource_type != ResourceType::MAIN_FRAME) {
1826 // A sub-resource has a certificate error. The user doesn't really
1827 // have a context for making the right decision, so block the
1828 // request hard, without an info bar to allow showing the insecure
1829 // content.
[email protected]8c965c22013-05-23 19:28:001830 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021831 return;
1832 }
1833
[email protected]f9034cf2011-07-21 12:43:411834 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]1a4e9752013-12-31 20:10:581835 content::RenderFrameHost* render_frame_host =
1836 content::RenderFrameHost::FromID(render_process_id, render_frame_id);
[email protected]1a4e9752013-12-31 20:10:581837 WebContents* tab = WebContents::FromRenderFrameHost(render_frame_host);
[email protected]f9034cf2011-07-21 12:43:411838 if (!tab) {
1839 NOTREACHED();
1840 return;
1841 }
[email protected]09667f02014-01-06 15:37:571842
1843 prerender::PrerenderContents* prerender_contents =
[email protected]294084d2014-01-06 22:22:021844 prerender::PrerenderContents::FromWebContents(tab);
[email protected]09667f02014-01-06 15:37:571845 if (prerender_contents) {
1846 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
1847 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
1848 return;
[email protected]f9034cf2011-07-21 12:43:411849 }
1850
[email protected]1e87df32012-09-12 04:53:191851#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231852 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1853 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1854 if (captive_portal_tab_helper)
1855 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191856#endif
1857
[email protected]f9034cf2011-07-21 12:43:411858 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221859 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1860 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031861}
1862
[email protected]c99c442e2011-08-24 11:37:301863void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451864 int render_process_id,
[email protected]094c8772013-12-21 17:54:501865 int render_frame_id,
[email protected]7a593db2012-02-13 21:19:401866 const net::HttpNetworkSession* network_session,
1867 net::SSLCertRequestInfo* cert_request_info,
1868 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]094c8772013-12-21 17:54:501869 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID(
1870 render_process_id, render_frame_id);
[email protected]294084d2014-01-06 22:22:021871 WebContents* tab = WebContents::FromRenderFrameHost(rfh);
1872 if (!tab) {
[email protected]094c8772013-12-21 17:54:501873 NOTREACHED();
1874 return;
1875 }
1876
[email protected]294084d2014-01-06 22:22:021877 prerender::PrerenderContents* prerender_contents =
1878 prerender::PrerenderContents::FromWebContents(tab);
1879 if (prerender_contents) {
1880 prerender_contents->Destroy(
1881 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
[email protected]8ec26472011-06-06 16:52:451882 return;
1883 }
1884
[email protected]791879c2013-12-17 07:22:411885 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
1886 DCHECK(requesting_url.is_valid())
1887 << "Invalid URL string: https://"
1888 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:451889
[email protected]627e0512011-12-21 22:55:301890 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]5bcdd99d2013-12-23 18:28:301891 scoped_ptr<base::Value> filter(
[email protected]6786bf402011-12-03 15:19:451892 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1893 requesting_url,
1894 requesting_url,
1895 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1896 std::string(), NULL));
1897
1898 if (filter.get()) {
1899 // Try to automatically select a client certificate.
[email protected]5bcdd99d2013-12-23 18:28:301900 if (filter->IsType(base::Value::TYPE_DICTIONARY)) {
1901 base::DictionaryValue* filter_dict =
1902 static_cast<base::DictionaryValue*>(filter.get());
[email protected]6786bf402011-12-03 15:19:451903
1904 const std::vector<scoped_refptr<net::X509Certificate> >&
1905 all_client_certs = cert_request_info->client_certs;
1906 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091907 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451908 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091909 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451910 return;
1911 }
1912 }
1913 } else {
1914 NOTREACHED();
1915 }
1916 }
1917
[email protected]11feec322012-09-18 03:58:521918 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1919 if (!ssl_tab_helper) {
1920 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451921 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141922 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401923 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451924 return;
1925 }
[email protected]11feec322012-09-18 03:58:521926 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401927 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451928}
1929
[email protected]3b455502012-12-11 18:22:581930void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451931 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581932 net::CertificateMimeType cert_type,
1933 const void* cert_data,
1934 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451935 int render_process_id,
1936 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581937 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1938 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451939}
1940
[email protected]dc73a7b2012-03-25 15:27:181941content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561942 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181943}
1944
[email protected]941623e2011-06-07 23:06:041945void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1946 const GURL& source_origin,
1947 int callback_context,
1948 int render_process_id,
1949 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111950#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021951 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1952 WebContents* contents =
1953 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1954 if (!contents) {
[email protected]941623e2011-06-07 23:06:041955 NOTREACHED();
1956 return;
1957 }
1958
[email protected]d0d9c3ee2012-06-19 03:07:021959 // Skip showing the infobar if the request comes from an extension, and that
1960 // extension has the 'notify' permission. (If the extension does not have the
1961 // permission, the user will still be prompted.)
1962 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]38427a12013-11-09 17:34:201963 InfoMap* extension_info_map =
[email protected]c7cd5942013-04-30 03:31:011964 extensions::ExtensionSystem::Get(profile)->info_map();
1965 DesktopNotificationService* notification_service =
1966 DesktopNotificationServiceFactory::GetForProfile(profile);
1967 const Extension* extension = NULL;
1968 if (extension_info_map) {
[email protected]289c44b2013-12-17 03:26:571969 extensions::ExtensionSet extensions;
[email protected]c7cd5942013-04-30 03:31:011970 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1971 source_origin, render_process_id,
1972 extensions::APIPermission::kNotification, &extensions);
[email protected]289c44b2013-12-17 03:26:571973 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
[email protected]c7cd5942013-04-30 03:31:011974 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381975 if (notification_service->IsNotifierEnabled(NotifierId(
1976 NotifierId::APPLICATION, (*iter)->id()))) {
[email protected]cadac622013-06-11 16:46:361977 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011978 break;
1979 }
1980 }
1981 }
[email protected]eb4832a2012-12-08 01:57:521982 RenderViewHost* rvh =
1983 RenderViewHost::FromID(render_process_id, render_view_id);
1984 if (IsExtensionWithPermissionOrSuggestInConsole(
1985 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021986 if (rvh)
1987 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1988 return;
1989 }
1990
[email protected]c7cd5942013-04-30 03:31:011991 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021992 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111993#else
1994 NOTIMPLEMENTED();
1995#endif
[email protected]941623e2011-06-07 23:06:041996}
1997
[email protected]a1221aea2013-11-07 01:31:301998blink::WebNotificationPresenter::Permission
[email protected]941623e2011-06-07 23:06:041999 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:022000 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:202001 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:022002 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:112003#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:042004 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]5c129792013-07-10 02:08:482005
[email protected]df02aca2012-02-09 21:03:202006 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9afacd22013-11-13 20:23:312007 InfoMap* extension_info_map = io_data->GetExtensionInfoMap();
[email protected]941623e2011-06-07 23:06:042008
[email protected]9afacd22013-11-13 20:23:312009 // We want to see if there is an extension that hasn't been manually disabled
2010 // that has the notifications permission and applies to this security origin.
2011 // First, get the list of extensions with permission for the origin.
[email protected]289c44b2013-12-17 03:26:572012 extensions::ExtensionSet extensions;
[email protected]9afacd22013-11-13 20:23:312013 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
2014 source_origin, render_process_id,
2015 extensions::APIPermission::kNotification, &extensions);
[email protected]289c44b2013-12-17 03:26:572016 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
[email protected]9afacd22013-11-13 20:23:312017 iter != extensions.end(); ++iter) {
2018 // Then, check to see if it's been disabled by the user.
2019 if (!extension_info_map->AreNotificationsDisabled((*iter)->id()))
2020 return blink::WebNotificationPresenter::PermissionAllowed;
[email protected]c7cd5942013-04-30 03:31:012021 }
2022
[email protected]9afacd22013-11-13 20:23:312023 // No enabled extensions exist, so check the normal host content settings.
2024 HostContentSettingsMap* host_content_settings_map =
2025 io_data->GetHostContentSettingsMap();
2026 ContentSetting setting = host_content_settings_map->GetContentSetting(
2027 source_origin,
2028 source_origin,
2029 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
2030 NO_RESOURCE_IDENTIFIER);
2031
2032 if (setting == CONTENT_SETTING_ALLOW)
2033 return blink::WebNotificationPresenter::PermissionAllowed;
2034 if (setting == CONTENT_SETTING_BLOCK)
2035 return blink::WebNotificationPresenter::PermissionDenied;
[email protected]a1221aea2013-11-07 01:31:302036 return blink::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:112037#else
[email protected]a1221aea2013-11-07 01:31:302038 return blink::WebNotificationPresenter::PermissionAllowed;
[email protected]5fd2e842012-03-01 00:29:112039#endif
[email protected]941623e2011-06-07 23:06:042040}
2041
2042void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:172043 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:042044 int render_process_id,
2045 int render_view_id,
2046 bool worker) {
[email protected]5fd2e842012-03-01 00:29:112047#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:042048 RenderViewHost* rvh = RenderViewHost::FromID(
2049 render_process_id, render_view_id);
2050 if (!rvh) {
2051 NOTREACHED();
2052 return;
2053 }
2054
[email protected]9f76c1e2012-03-05 15:15:582055 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:302056 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:042057 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:372058 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042059 service->ShowDesktopNotification(
2060 params, render_process_id, render_view_id,
2061 worker ? DesktopNotificationService::WorkerNotification :
2062 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:112063#else
2064 NOTIMPLEMENTED();
2065#endif
[email protected]941623e2011-06-07 23:06:042066}
2067
2068void ChromeContentBrowserClient::CancelDesktopNotification(
2069 int render_process_id,
2070 int render_view_id,
2071 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:112072#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:042073 RenderViewHost* rvh = RenderViewHost::FromID(
2074 render_process_id, render_view_id);
2075 if (!rvh) {
2076 NOTREACHED();
2077 return;
2078 }
2079
[email protected]9f76c1e2012-03-05 15:15:582080 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:302081 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:042082 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:372083 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042084 service->CancelDesktopNotification(
2085 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:112086#else
2087 NOTIMPLEMENTED();
2088#endif
[email protected]941623e2011-06-07 23:06:042089}
2090
[email protected]9f3fba52011-06-08 20:37:192091bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:352092 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:572093 const GURL& opener_top_level_frame_url,
[email protected]34eec7ffe32011-11-02 23:49:022094 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:192095 WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:232096 const GURL& target_url,
2097 const content::Referrer& referrer,
2098 WindowOpenDisposition disposition,
2099 const WebWindowFeatures& features,
2100 bool user_gesture,
2101 bool opener_suppressed,
[email protected]df02aca2012-02-09 21:03:202102 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:012103 int render_process_id,
[email protected]190e5e22013-07-27 05:59:232104 bool is_guest,
2105 int opener_id,
[email protected]03b6d552012-03-29 04:03:012106 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:192107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:012108
2109 *no_javascript_access = false;
2110
[email protected]5e5f55e262c52013-09-12 00:27:192111 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]38427a12013-11-09 17:34:202112 InfoMap* map = io_data->GetExtensionInfoMap();
[email protected]5e5f55e262c52013-09-12 00:27:192113
[email protected]9f3fba52011-06-08 20:37:192114 // If the opener is trying to create a background window but doesn't have
2115 // the appropriate permission, fail the attempt.
[email protected]6940eef82013-09-11 11:58:412116 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]03b6d552012-03-29 04:03:012117 if (!map->SecurityOriginHasAPIPermission(
2118 source_origin,
2119 render_process_id,
[email protected]c2e66e12012-06-27 06:27:062120 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:012121 return false;
2122 }
2123
[email protected]7b54ca02012-03-02 18:06:532124 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2125 // return a recently installed Extension even if this CanCreateWindow call
2126 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:012127 // because the permission check above would have caused an early return
2128 // already. We must use the full URL to find hosted apps, though, and not
2129 // just the origin.
[email protected]be9915fb2013-07-18 09:28:552130 const Extension* extension =
2131 map->extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:292132 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:012133 *no_javascript_access = true;
[email protected]190e5e22013-07-27 05:59:232134
2135 return true;
[email protected]9f3fba52011-06-08 20:37:192136 }
[email protected]056efdc2013-04-06 00:14:532137
2138 // No new browser window (popup or tab) in app mode.
2139 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
2140 chrome::IsRunningInForcedAppMode()) {
2141 return false;
2142 }
2143
[email protected]190e5e22013-07-27 05:59:232144 if (is_guest)
2145 return true;
2146
[email protected]190e5e22013-07-27 05:59:232147 HostContentSettingsMap* content_settings =
2148 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap();
[email protected]916615b2013-09-11 18:19:442149 BlockedWindowParams blocked_params(target_url,
2150 referrer,
2151 disposition,
2152 features,
2153 user_gesture,
2154 opener_suppressed,
2155 render_process_id,
2156 opener_id);
[email protected]190e5e22013-07-27 05:59:232157
[email protected]7f53dff2013-08-05 10:45:502158 if (!user_gesture && !CommandLine::ForCurrentProcess()->HasSwitch(
2159 switches::kDisablePopupBlocking)) {
[email protected]931bc922013-09-11 21:42:572160 if (content_settings->GetContentSetting(opener_top_level_frame_url,
2161 opener_top_level_frame_url,
[email protected]190e5e22013-07-27 05:59:232162 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]916615b2013-09-11 18:19:442163 std::string()) !=
[email protected]190e5e22013-07-27 05:59:232164 CONTENT_SETTING_ALLOW) {
[email protected]916615b2013-09-11 18:19:442165 BrowserThread::PostTask(BrowserThread::UI,
2166 FROM_HERE,
2167 base::Bind(&HandleBlockedPopupOnUIThread,
2168 blocked_params));
2169 return false;
[email protected]190e5e22013-07-27 05:59:232170 }
[email protected]916615b2013-09-11 18:19:442171 }
[email protected]190e5e22013-07-27 05:59:232172
[email protected]916615b2013-09-11 18:19:442173#if defined(OS_ANDROID)
2174 if (SingleTabModeTabHelper::IsRegistered(render_process_id, opener_id)) {
[email protected]190e5e22013-07-27 05:59:232175 BrowserThread::PostTask(BrowserThread::UI,
2176 FROM_HERE,
[email protected]916615b2013-09-11 18:19:442177 base::Bind(&HandleSingleTabModeBlockOnUIThread,
2178 blocked_params));
[email protected]190e5e22013-07-27 05:59:232179 return false;
2180 }
[email protected]916615b2013-09-11 18:19:442181#endif
[email protected]190e5e22013-07-27 05:59:232182
[email protected]9f3fba52011-06-08 20:37:192183 return true;
2184}
2185
2186std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:202187 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:192188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2189 // Check if it's an extension-created worker, in which case we want to use
2190 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:202191 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:192192 const Extension* extension =
2193 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
2194 return extension ? extension->name() : std::string();
2195}
2196
[email protected]99907362012-01-11 05:41:402197void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2198 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:172199}
2200
[email protected]7a06d282013-05-03 04:39:332201// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:022202content::SpeechRecognitionManagerDelegate*
2203 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002204#if defined(ENABLE_INPUT_SPEECH)
2205 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
[email protected]a03f2d32012-03-14 00:26:322206#else
[email protected]855e18b2013-07-08 21:02:002207 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
2208 // need the base delegate without the bubble UI.
2209 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:322210#endif
[email protected]66cfec62012-02-24 17:57:512211}
2212
[email protected]ae6e9912011-07-27 01:18:282213net::NetLog* ChromeContentBrowserClient::GetNetLog() {
2214 return g_browser_process->net_log();
2215}
2216
[email protected]32538d92011-08-25 00:09:232217AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
2218 return new ChromeAccessTokenStore();
2219}
2220
[email protected]dbae6b02011-06-29 23:51:412221bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:012222 return true;
[email protected]dbae6b02011-06-29 23:51:412223}
2224
[email protected]64d69de42012-02-06 00:19:542225void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:322226 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:062227 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582228 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:062229 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062230
[email protected]33b79542013-10-18 11:18:452231 // Fill per-script font preferences. These are not registered on Android
2232 // - http://crbug.com/308033.
2233#if !defined(OS_ANDROID)
[email protected]f3986f82012-01-03 20:00:062234 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542235 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:062236 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542237 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:062238 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542239 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062240 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542241 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062242 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542243 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:062244 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542245 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:032246 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
2247 &web_prefs->pictograph_font_family_map);
[email protected]33b79542013-10-18 11:18:452248#endif
[email protected]f3986f82012-01-03 20:00:062249
[email protected]64d69de42012-02-06 00:19:542250 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:402251 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:542252 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:402253 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:542254 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:402255 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:542256 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:402257 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:062258
[email protected]ddf72142012-05-22 04:52:402259 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062260
[email protected]64d69de42012-02-06 00:19:542261 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:402262 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:542263 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:062264 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:542265 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:062266 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
[email protected]5bcdd99d2013-12-23 18:28:302267 const base::DictionaryValue* inspector_settings =
[email protected]f3986f82012-01-03 20:00:062268 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2269 if (inspector_settings) {
[email protected]5bcdd99d2013-12-23 18:28:302270 for (base::DictionaryValue::Iterator iter(*inspector_settings);
2271 !iter.IsAtEnd();
[email protected]c40ef1c2013-02-25 18:42:182272 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062273 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182274 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542275 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182276 std::make_pair(iter.key(), value));
2277 }
[email protected]f3986f82012-01-03 20:00:062278 }
2279 }
[email protected]64d69de42012-02-06 00:19:542280 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062281
[email protected]ddf72142012-05-22 04:52:402282 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542283 web_prefs->javascript_enabled = false;
2284 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2285 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402286 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542287 web_prefs->plugins_enabled = false;
2288 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2289 web_prefs->java_enabled = false;
2290 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402291 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062292
[email protected]64d69de42012-02-06 00:19:542293 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2294 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062295
[email protected]64d69de42012-02-06 00:19:542296 web_prefs->memory_info_enabled =
2297 prefs->GetBoolean(prefs::kEnableMemoryInfo);
2298 web_prefs->allow_displaying_insecure_content =
2299 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2300 web_prefs->allow_running_insecure_content =
2301 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322302#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:052303 web_prefs->font_scale_factor =
2304 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2305 web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment();
[email protected]d3b935f2012-10-19 23:14:322306 web_prefs->force_enable_zoom =
2307 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
2308#endif
[email protected]5c915252013-05-07 13:15:392309
[email protected]af4256d52013-06-04 20:39:072310#if defined(OS_ANDROID)
2311 web_prefs->password_echo_enabled =
2312 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2313#else
[email protected]9d06d88d2012-02-23 22:37:082314 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072315#endif
2316
[email protected]cfadadd2013-04-03 04:43:022317 web_prefs->asynchronous_spell_checking_enabled = true;
2318 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572319
[email protected]64d69de42012-02-06 00:19:542320 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062321 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542322 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062323 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542324 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062325 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2326
2327 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542328 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062329 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542330 web_prefs->default_encoding);
2331 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402332 prefs->ClearPref(prefs::kDefaultCharset);
2333 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062334 }
[email protected]64d69de42012-02-06 00:19:542335 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062336
[email protected]299d7f12012-05-23 05:31:152337 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232338 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132339 ExtensionService* service =
2340 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062341 if (service) {
[email protected]1e6e2ea2014-01-04 02:01:402342 const GURL& site_url = rvh->GetSiteInstance()->GetSiteURL();
2343 const Extension* extension =
2344 service->extensions()->GetByID(site_url.host());
[email protected]1bc28312012-11-08 08:31:532345 // Ensure that we are only granting extension preferences to URLs with
2346 // the correct scheme. Without this check, chrome-guest:// schemes used by
2347 // webview tags as well as hosts that happen to match the id of an
2348 // installed extension would get the wrong preferences.
[email protected]1e6e2ea2014-01-04 02:01:402349 if (site_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532350 extension_webkit_preferences::SetPreferences(
2351 extension, view_type, web_prefs);
2352 }
[email protected]f3986f82012-01-03 20:00:062353 }
2354
[email protected]cb2edf22013-04-01 20:25:232355 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542356 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232357 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062358 // Disable all kinds of acceleration for background pages.
2359 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542360 web_prefs->force_compositing_mode = false;
2361 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062362 }
[email protected]2e21fe292012-03-02 22:52:322363
[email protected]ff9300872014-01-22 11:09:322364#if defined(OS_CHROMEOS)
[email protected]2e21fe292012-03-02 22:52:322365 // Override the default of suppressing HW compositing for WebUI pages for the
2366 // file manager, which is implemented using WebUI but wants HW acceleration
2367 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532368 if (url.SchemeIs(extensions::kExtensionScheme) &&
[email protected]2de96a52013-08-14 01:18:092369 url.host() == file_manager::kFileManagerAppId) {
[email protected]2e21fe292012-03-02 22:52:322370 web_prefs->accelerated_compositing_enabled = true;
2371 web_prefs->accelerated_2d_canvas_enabled = true;
2372 }
2373#endif
[email protected]181a95ee2011-07-12 19:26:362374}
2375
2376void ChromeContentBrowserClient::UpdateInspectorSetting(
2377 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062378 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582379 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062380 DictionaryPrefUpdate update(
2381 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2382 prefs::kWebKitInspectorSettings);
[email protected]5bcdd99d2013-12-23 18:28:302383 base::DictionaryValue* inspector_settings = update.Get();
2384 inspector_settings->SetWithoutPathExpansion(
2385 key, base::Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362386}
2387
[email protected]b8148ac2011-07-13 22:03:252388void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2389 BrowserURLHandler* handler) {
2390 // Add the default URL handlers.
2391 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2392 BrowserURLHandler::null_handler());
2393 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2394 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2395
[email protected]b3adbd02011-11-30 22:23:272396 // about: handler. Must come before chrome: handler, since it will
2397 // rewrite about: urls to chrome: URLs and then expect chrome: to
2398 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252399 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2400 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:032401
2402 // Handler to rewrite chrome://newtab for InstantExtended.
2403 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2404 &chrome::HandleNewTabURLReverseRewrite);
2405
[email protected]b8148ac2011-07-13 22:03:252406 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242407 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252408}
2409
2410void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372411 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582412 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472413 BrowsingDataRemover* remover =
2414 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552415 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2416 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252417 // BrowsingDataRemover takes care of deleting itself when done.
2418}
2419
2420void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372421 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582422 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472423 BrowsingDataRemover* remover =
2424 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232425 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552426 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252427 // BrowsingDataRemover takes care of deleting itself when done.
2428}
2429
[email protected]650b2d52013-02-10 03:41:452430base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:492431 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:322432}
2433
[email protected]c9b6eb62011-10-18 20:49:392434std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2435 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2436}
2437
[email protected]b7631cc2012-09-15 05:08:382438void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2439 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542440#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382441 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2442 scoped_ptr<ppapi::host::HostFactory>(
2443 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542444#endif
[email protected]b7631cc2012-09-15 05:08:382445}
2446
[email protected]0c7193742012-11-07 19:05:032447content::BrowserPpapiHost*
2448 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2449 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132450 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032451 while (!iter.Done()) {
[email protected]7c766e92013-11-22 20:44:022452 nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>(
2453 iter.GetDelegate());
[email protected]0c7193742012-11-07 19:05:032454 if (host->process() &&
2455 host->process()->GetData().id == plugin_process_id) {
2456 // Found the plugin.
2457 return host->browser_ppapi_host();
2458 }
2459 ++iter;
2460 }
2461 return NULL;
2462}
2463
[email protected]7b38b192013-03-23 18:39:312464bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2465 content::BrowserContext* browser_context, const GURL& site_url) {
2466 if (CommandLine::ForCurrentProcess()->HasSwitch(
2467 switches::kEnableBrowserPluginForAllViewTypes))
2468 return true;
2469
[email protected]22aa4f82013-09-24 17:01:442470 if (content::HasWebUIScheme(site_url))
2471 return true;
2472
[email protected]7b38b192013-03-23 18:39:312473 Profile* profile = Profile::FromBrowserContext(browser_context);
2474 ExtensionService* service =
2475 extensions::ExtensionSystem::Get(profile)->extension_service();
2476 if (!service)
2477 return false;
2478
[email protected]be9915fb2013-07-18 09:28:552479 const Extension* extension =
2480 service->extensions()->GetExtensionOrAppByURL(site_url);
[email protected]7b38b192013-03-23 18:39:312481 if (!extension)
2482 return false;
2483
[email protected]c2d2f102013-04-29 16:42:582484 return extension->HasAPIPermission(APIPermission::kWebView) ||
2485 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312486}
2487
[email protected]38cd8f7f2012-06-15 22:06:072488bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582489 content::BrowserContext* browser_context,
2490 const GURL& url,
[email protected]dda54822013-06-15 01:26:392491 bool private_api,
[email protected]8b92ed182013-09-21 04:47:122492 const content::SocketPermissionRequest* params) {
[email protected]93f72062013-05-29 20:29:402493#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372494 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]289c44b2013-12-17 03:26:572495 const extensions::ExtensionSet* extension_set = NULL;
[email protected]9d450492013-06-13 23:08:372496 if (profile) {
2497 extension_set = extensions::ExtensionSystem::Get(profile)->
2498 extension_service()->extensions();
2499 }
[email protected]dda54822013-06-15 01:26:392500
2501 if (private_api) {
2502 // Access to private socket APIs is controlled by the whitelist.
2503 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2504 allowed_socket_origins_)) {
2505 return true;
2506 }
2507 } else {
2508 // Access to public socket APIs is controlled by extension permissions.
2509 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2510 extension_set) {
2511 const Extension* extension = extension_set->GetByID(url.host());
2512 if (extension) {
[email protected]8b92ed182013-09-21 04:47:122513 if (params) {
2514 extensions::SocketPermission::CheckParam check_params(
2515 params->type, params->host, params->port);
2516 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2517 extension, extensions::APIPermission::kSocket,
2518 &check_params)) {
2519 return true;
2520 }
2521 } else {
2522 if (extensions::PermissionsData::HasAPIPermission(
2523 extension, extensions::APIPermission::kSocket)) {
2524 return true;
2525 }
[email protected]dda54822013-06-15 01:26:392526 }
2527 }
2528 }
2529 }
2530
2531 // Allow both public and private APIs if the command line says so.
2532 return IsHostAllowedByCommandLine(url, extension_set,
2533 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402534#else
[email protected]a658d452012-03-02 12:45:292535 return false;
[email protected]93f72062013-05-29 20:29:402536#endif
[email protected]e461da2f2012-02-16 19:06:402537}
2538
[email protected]a28e3302013-02-03 03:50:432539ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2540 WebContents* web_contents) {
2541 return new ChromeSelectFilePolicy(web_contents);
2542}
2543
[email protected]7d9424702013-04-14 13:14:162544void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2545 std::vector<std::string>* additional_allowed_schemes) {
2546 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2547 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:482548 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:292549 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]7d9424702013-04-14 13:14:162550 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
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]7e503f92014-02-19 02:35:512583#if defined(ENABLE_MDNS)
[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
2604 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_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]5db2b7492013-08-23 05:33:092607 base::PlatformFile f =
2608 base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
[email protected]29699c22012-10-03 23:57:392609 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372610 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392611 FileDescriptor(f, true)));
2612
2613 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452614 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392615 GetLocaleFilePath(locale, false);
2616 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2617 DCHECK(f != base::kInvalidPlatformFileValue);
2618 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2619 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382620
[email protected]650b2d52013-02-10 03:41:452621 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372622 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2623 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2624 DCHECK(f != base::kInvalidPlatformFileValue);
2625 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2626 FileDescriptor(f, true)));
2627
[email protected]0b818f72013-10-22 00:11:032628 if (breakpad::IsCrashReporterEnabled()) {
2629 f = breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2630 child_process_id);
[email protected]82174aa2013-01-22 21:53:432631 if (f == base::kInvalidPlatformFileValue) {
2632 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2633 "be disabled for this process.";
2634 } else {
2635 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2636 FileDescriptor(f, true)));
2637 }
[email protected]40da3e0c2012-10-24 22:03:382638 }
[email protected]40da3e0c2012-10-24 22:03:382639
2640#else
2641 int crash_signal_fd = GetCrashSignalFD(command_line);
2642 if (crash_signal_fd >= 0) {
2643 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2644 FileDescriptor(crash_signal_fd,
2645 false)));
2646 }
[email protected]29699c22012-10-03 23:57:392647#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302648}
[email protected]e60c0232011-11-11 19:56:352649#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302650
[email protected]4a65826d2011-08-25 16:04:012651#if defined(OS_WIN)
2652const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2653 return chrome::kBrowserResourcesDll;
2654}
[email protected]34f48682013-03-20 00:30:182655
2656void ChromeContentBrowserClient::PreSpawnRenderer(
2657 sandbox::TargetPolicy* policy,
2658 bool* success) {
2659 // This code is duplicated in nacl_exe_win_64.cc.
2660 // Allow the server side of a pipe restricted to the "chrome.nacl."
2661 // namespace so that it cannot impersonate other system or other chrome
2662 // service pipes.
2663 sandbox::ResultCode result = policy->AddRule(
2664 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2665 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2666 L"\\\\.\\pipe\\chrome.nacl.*");
2667 if (result != sandbox::SBOX_ALL_OK) {
2668 *success = false;
2669 return;
2670 }
2671
2672 // Renderers need to send named pipe handles and shared memory
2673 // segment handles to NaCl loader processes.
2674 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2675 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2676 L"File");
2677 if (result != sandbox::SBOX_ALL_OK) {
2678 *success = false;
2679 return;
2680 }
2681}
[email protected]4a65826d2011-08-25 16:04:012682#endif
2683
[email protected]a6868c22013-10-09 02:50:292684bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2685 content::BrowserContext* browser_context,
2686 const GURL& url) {
2687#if defined(ENABLE_PLUGINS)
2688 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]289c44b2013-12-17 03:26:572689 const extensions::ExtensionSet* extension_set = NULL;
[email protected]a6868c22013-10-09 02:50:292690 if (profile) {
2691 extension_set = extensions::ExtensionSystem::Get(profile)->
2692 extension_service()->extensions();
2693 }
2694 // TODO(teravest): Populate allowed_file_handle_origins_ when FileIO is moved
2695 // from the renderer to the browser.
2696 return IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2697 allowed_file_handle_origins_) ||
2698 IsHostAllowedByCommandLine(url, extension_set,
2699 switches::kAllowNaClFileHandleAPI);
2700#else
2701 return false;
2702#endif
2703}
2704
[email protected]8ddc6b7c2013-12-12 20:42:062705bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs() {
2706#if defined(ENABLE_PLUGINS)
2707 // Allow access for tests.
2708 if (CommandLine::ForCurrentProcess()->HasSwitch(
2709 switches::kEnablePepperTesting)) {
2710 return true;
2711 }
2712
2713 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
[email protected]5abe3e72013-12-19 18:58:542714 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown"
2715 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on
2716 // Chromium builds as well.
[email protected]8ddc6b7c2013-12-12 20:42:062717 return channel <= chrome::VersionInfo::CHANNEL_DEV;
2718#else
2719 return false;
2720#endif
2721}
2722
[email protected]30335fdf02014-02-26 19:51:272723#if defined(ENABLE_WEBRTC)
2724void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2725 CommandLine* to_command_line,
2726 const CommandLine& from_command_line,
2727 VersionInfo::Channel channel) {
2728#if defined(OS_ANDROID)
2729 const VersionInfo::Channel kMaxDisableEncryptionChannel =
2730 VersionInfo::CHANNEL_BETA;
2731#else
2732 const VersionInfo::Channel kMaxDisableEncryptionChannel =
2733 VersionInfo::CHANNEL_DEV;
2734#endif
2735 if (channel <= kMaxDisableEncryptionChannel) {
2736 static const char* const kWebRtcDevSwitchNames[] = {
2737 switches::kDisableWebRtcEncryption,
2738 };
2739 to_command_line->CopySwitchesFrom(from_command_line,
2740 kWebRtcDevSwitchNames,
2741 arraysize(kWebRtcDevSwitchNames));
2742 }
2743}
2744#endif // defined(ENABLE_WEBRTC)
[email protected]8ddc6b7c2013-12-12 20:42:062745
[email protected]d977f9c2011-03-14 16:10:262746} // namespace chrome