blob: bbb5a8bbbcdb3d2e29e3ded70a6fd1f278f86361 [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]11158e2d2013-02-01 02:31:5649#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]95132f52013-04-12 02:19:0450#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
[email protected]a2b4c5c2013-10-18 02:06:0751#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
[email protected]ae6e9912011-07-27 01:18:2852#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0453#include "chrome/browser/notifications/desktop_notification_service.h"
54#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4255#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5656#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]190e5e22013-07-27 05:59:2357#include "chrome/browser/prerender/prerender_final_status.h"
[email protected]f9034cf2011-07-21 12:43:4158#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5059#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0760#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4161#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1462#include "chrome/browser/printing/printing_message_filter.h"
[email protected]7e75e4a2013-05-17 17:20:0363#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:1464#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3265#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0666#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1467#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3868#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4369#include "chrome/browser/search/instant_service.h"
70#include "chrome/browser/search/instant_service_factory.h"
71#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1472#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]914cf6712013-12-05 01:14:0673#include "chrome/browser/signin/principals_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0274#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3375#include "chrome/browser/speech/tts_message_filter.h"
[email protected]3b455502012-12-11 18:22:5876#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0377#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5278#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]180c66a62013-08-05 12:01:3679#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:4580#include "chrome/browser/tab_contents/tab_util.h"
[email protected]916615b2013-09-11 18:19:4481#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
[email protected]40aa8bb2013-08-23 20:28:2382#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
[email protected]a28e3302013-02-03 03:50:4383#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]329ac972013-06-21 15:24:2584#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:4485#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5086#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]4a65826d2011-08-25 16:04:0187#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1488#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3089#include "chrome/common/chrome_switches.h"
[email protected]50fa4d5f2013-11-05 00:53:2390#include "chrome/common/chrome_version_info.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]ef42ee82013-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]eba93c92014-01-07 17:34:17107#include "components/translate/core/common/translate_switches.h"
[email protected]75fee372013-03-06 00:42:44108#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43109#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30110#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38111#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03112#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31113#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03114#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59115#include "content/public/browser/child_process_security_policy.h"
[email protected]094c8772013-12-21 17:54:50116#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30117#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33118#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05119#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33120#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19121#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10122#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43123#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18124#include "content/public/common/content_descriptors.h"
[email protected]22aa4f82013-09-24 17:01:44125#include "content/public/common/url_utils.h"
[email protected]afed5112014-02-02 06:01:53126#include "extensions/browser/extension_message_filter.h"
[email protected]896c6d52014-01-28 21:40:21127#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:24128#include "extensions/browser/extension_system.h"
[email protected]38427a12013-11-09 17:34:20129#include "extensions/browser/info_map.h"
[email protected]98b6d942013-11-10 00:34:07130#include "extensions/browser/process_manager.h"
[email protected]fafdc842014-01-17 18:09:08131#include "extensions/browser/process_map.h"
[email protected]cb2edf22013-04-01 20:25:23132#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42133#include "extensions/common/constants.h"
[email protected]e4452d32013-11-15 23:07:41134#include "extensions/common/extension.h"
[email protected]289c44b2013-12-17 03:26:57135#include "extensions/common/extension_set.h"
[email protected]558878cc82013-11-09 01:25:51136#include "extensions/common/manifest_handlers/background_info.h"
[email protected]301116c62013-11-26 10:37:45137#include "extensions/common/manifest_handlers/shared_module_info.h"
[email protected]474b1f72014-01-16 02:38:07138#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
[email protected]e4452d32013-11-15 23:07:41139#include "extensions/common/permissions/permissions_data.h"
[email protected]49d9b142013-07-19 08:50:27140#include "extensions/common/switches.h"
[email protected]c9b6eb62011-10-18 20:49:39141#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23142#include "grit/ui_resources.h"
[email protected]3b455502012-12-11 18:22:58143#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34144#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06145#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57146#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38147#include "ppapi/host/ppapi_host.h"
[email protected]8ddc6b7c2013-12-12 20:42:06148#include "ppapi/shared_impl/ppapi_switches.h"
[email protected]c9b6eb62011-10-18 20:49:39149#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08150#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24151#include "ui/message_center/message_center_util.h"
[email protected]b40015c2013-06-26 08:13:31152#include "webkit/browser/fileapi/external_mount_points.h"
[email protected]fab55e72013-05-31 07:06:18153#include "webkit/common/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:26154
[email protected]b48c9182011-10-26 18:03:30155#if defined(OS_WIN)
[email protected]7fe75ce2014-01-28 02:12:24156#include "base/win/windows_version.h"
[email protected]199fc7a2011-09-28 22:45:38157#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18158#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38159#elif defined(OS_MACOSX)
160#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56161#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]0b818f72013-10-22 00:11:03162#include "components/breakpad/app/breakpad_mac.h"
[email protected]b48c9182011-10-26 18:03:30163#elif defined(OS_CHROMEOS)
164#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]07fe2752014-01-29 11:21:55165#include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
[email protected]f19bbf62013-07-09 01:22:32166#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]5c915252013-05-07 13:15:39167#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49168#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]c94ac692013-07-27 00:50:10169#include "chrome/browser/chromeos/system/input_device_settings.h"
[email protected]931d1042013-04-05 17:50:44170#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26171#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30172#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09173#elif defined(OS_ANDROID)
[email protected]916615b2013-09-11 18:19:44174#include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
[email protected]81054f812012-08-30 00:47:09175#include "chrome/browser/chrome_browser_main_android.h"
[email protected]2b12c322013-09-19 06:53:56176#include "chrome/browser/media/encrypted_media_message_filter_android.h"
[email protected]29699c22012-10-03 23:57:39177#include "chrome/common/descriptors_android.h"
[email protected]0b818f72013-10-22 00:11:03178#include "components/breakpad/browser/crash_dump_manager_android.h"
[email protected]b48c9182011-10-26 18:03:30179#elif defined(OS_POSIX)
180#include "chrome/browser/chrome_browser_main_posix.h"
181#endif
182
[email protected]a220b5932013-09-21 03:47:44183#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]779dd282013-10-19 15:57:02184#include "base/debug/leak_annotations.h"
[email protected]b80f68432011-05-02 17:22:30185#include "base/linux_util.h"
[email protected]0b818f72013-10-22 00:11:03186#include "components/breakpad/app/breakpad_linux.h"
187#include "components/breakpad/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43188#endif
[email protected]b80f68432011-05-02 17:22:30189
[email protected]1e87df32012-09-12 04:53:19190#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
191#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
192#endif
193
[email protected]29699c22012-10-03 23:57:39194#if defined(OS_ANDROID)
195#include "ui/base/ui_base_paths.h"
[email protected]b255a8e0e82013-10-22 04:03:59196#include "ui/gfx/android/device_display_info.h"
[email protected]29699c22012-10-03 23:57:39197#endif
198
[email protected]d5bcd06f2013-04-21 08:07:24199#if !defined(OS_CHROMEOS)
200#include "chrome/browser/signin/signin_manager.h"
201#include "chrome/browser/signin/signin_manager_factory.h"
202#endif
203
[email protected]02250952013-04-24 23:52:53204#if !defined(OS_ANDROID)
[email protected]f19bbf62013-07-09 01:22:32205#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
[email protected]02250952013-04-24 23:52:53206#endif
207
[email protected]6ef98b5a2013-05-31 23:58:31208#if defined(ENABLE_WEBRTC)
209#include "chrome/browser/media/webrtc_logging_handler_host.h"
210#endif
211
[email protected]855e18b2013-07-08 21:02:00212#if defined(ENABLE_INPUT_SPEECH)
213#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h"
214#endif
215
[email protected]ff9300872014-01-22 11:09:32216#if defined(OS_CHROMEOS)
[email protected]473c9a4f2013-09-05 03:09:46217#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]02a3dc122013-06-13 15:07:53218#endif
219
[email protected]e8b6ca02013-07-10 18:00:51220#if defined(TOOLKIT_GTK)
221#include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h"
222#endif
223
224#if defined(TOOLKIT_VIEWS)
225#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
226#endif
227
228#if defined(USE_ASH)
229#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
230#endif
231
232#if defined(USE_AURA)
233#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
234#endif
235
236#if defined(USE_X11)
237#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
238#endif
239
[email protected]c6ce08072013-07-31 07:48:53240#if defined(ENABLE_SPELLCHECK)
241#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
242#endif
243
[email protected]a1221aea2013-11-07 01:31:30244using blink::WebWindowFeatures;
[email protected]c7abd422012-09-25 00:20:08245using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47246using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03247using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39248using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31249using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59250using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08251using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00252using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11253using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33254using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13255using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06256using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34257using extensions::Extension;
[email protected]38427a12013-11-09 17:34:20258using extensions::InfoMap;
[email protected]1d5e58b2013-01-31 08:41:40259using extensions::Manifest;
[email protected]593d2a72013-07-26 08:48:38260using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39261
[email protected]c5dbef02011-05-13 05:06:09262namespace {
263
[email protected]eabbfb12013-04-05 23:28:35264// Cached version of the locale so we can return the locale on the I/O
265// thread.
266base::LazyInstance<std::string> g_io_thread_application_locale;
267
[email protected]93f72062013-05-29 20:29:40268#if defined(ENABLE_PLUGINS)
[email protected]10c39222013-11-13 20:09:25269const char* kPredefinedAllowedFileHandleOrigins[] = {
270 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
271 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
272};
273
[email protected]e461da2f2012-02-16 19:06:40274const char* kPredefinedAllowedSocketOrigins[] = {
275 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18276 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45277 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
278 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
279 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
280 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35281 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54282 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
283 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
284 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
285 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
286 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
287 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38288 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58289 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29290 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]3f6fca22013-08-12 23:13:42291 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
292 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
293 "4EB74897CB187C7633357C2FE832E0AD6A44883A", // see crbug.com/234789
294 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
295 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
296 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40297};
[email protected]93f72062013-05-29 20:29:40298#endif
[email protected]e461da2f2012-02-16 19:06:40299
[email protected]f8f93eb2012-09-25 03:06:24300// Returns a copy of the given url with its host set to given host and path set
301// to given path. Other parts of the url will be the same.
302GURL ReplaceURLHostAndPath(const GURL& url,
303 const std::string& host,
304 const std::string& path) {
305 url_canon::Replacements<char> replacements;
306 replacements.SetHost(host.c_str(),
307 url_parse::Component(0, host.length()));
308 replacements.SetPath(path.c_str(),
309 url_parse::Component(0, path.length()));
310 return url.ReplaceComponents(replacements);
311}
312
313// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
314GURL AddUberHost(const GURL& url) {
315 const std::string uber_host = chrome::kChromeUIUberHost;
316 const std::string new_path = url.host() + url.path();
317
318 return ReplaceURLHostAndPath(url, uber_host, new_path);
319}
320
[email protected]045bf7c2012-09-28 20:27:36321// If url->host() is "chrome" and url->path() has characters other than the
322// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
323// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24324bool RemoveUberHost(GURL* url) {
325 if (url->host() != chrome::kChromeUIUberHost)
326 return false;
327
[email protected]045bf7c2012-09-28 20:27:36328 if (url->path().empty() || url->path() == "/")
329 return false;
330
[email protected]f8f93eb2012-09-25 03:06:24331 const std::string old_path = url->path();
332
333 const std::string::size_type separator = old_path.find('/', 1);
334 std::string new_host;
335 std::string new_path;
336 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36337 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24338 } else {
339 new_host = old_path.substr(1, separator - 1);
340 new_path = old_path.substr(separator);
341 }
342
[email protected]44e8add2013-06-13 17:29:15343 // Do not allow URLs with paths empty before the first slash since we can't
344 // have an empty host. (e.g "foo://chrome//")
345 if (new_host.empty())
346 return false;
347
[email protected]f8f93eb2012-09-25 03:06:24348 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
349
[email protected]44e8add2013-06-13 17:29:15350 DCHECK(url->is_valid());
351
[email protected]f8f93eb2012-09-25 03:06:24352 return true;
353}
354
[email protected]b8148ac2011-07-13 22:03:25355// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42356bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24357 // Do not handle special URLs such as "about:foo"
358 if (!url->host().empty()) {
359 const GURL chrome_url = AddUberHost(*url);
360
361 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
362 // be called.
363 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
364 browser_context, chrome_url))
365 return true;
366 }
367
[email protected]863f70a2012-01-27 02:05:50368 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
369 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25370 return false;
371
[email protected]fe69558d2012-03-12 11:34:49372#if defined(OS_CHROMEOS)
373 // Special case : in ChromeOS in Guest mode bookmarks and history are
374 // disabled for security reasons. New tab page explains the reasons, so
375 // we redirect user to new tab page.
376 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
[email protected]2d9748b22014-02-11 00:17:29377 if (url->SchemeIs(content::kChromeUIScheme) &&
[email protected]fe69558d2012-03-12 11:34:49378 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
[email protected]b9171622013-10-01 22:05:23379#if defined(ENABLE_ENHANCED_BOOKMARKS)
380 url->DomainIs(chrome::kChromeUIEnhancedBookmarksHost) ||
381#endif
[email protected]fe69558d2012-03-12 11:34:49382 url->DomainIs(chrome::kChromeUIHistoryHost))) {
383 // Rewrite with new tab URL
384 *url = GURL(chrome::kChromeUINewTabURL);
385 }
386 }
387#endif
388
[email protected]b8148ac2011-07-13 22:03:25389 return true;
390}
391
[email protected]f8f93eb2012-09-25 03:06:24392// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
393// "chrome://foo/".
394bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
[email protected]2d9748b22014-02-11 00:17:29395 if (!url->is_valid() || !url->SchemeIs(content::kChromeUIScheme))
[email protected]f8f93eb2012-09-25 03:06:24396 return false;
397
398 return RemoveUberHost(url);
399}
400
[email protected]8d3132f62011-10-12 07:13:42401// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
402// below. Extension, and isolated apps require different privileges to be
403// granted to their RenderProcessHosts. This classification allows us to make
404// sure URLs are served by hosts with the right set of privileges.
405enum RenderProcessHostPrivilege {
406 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45407 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42408 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45409 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42410};
411
412RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
413 const GURL& url,
414 ExtensionService* service) {
415 // Default to a normal renderer cause it is lower privileged. This should only
416 // occur if the URL on a site instance is either malformed, or uninitialized.
417 // If it is malformed, then there is no need for better privileges anyways.
418 // If it is uninitialized, but eventually settles on being an a scheme other
419 // than normal webrenderer, the navigation logic will correct us out of band
420 // anyways.
421 if (!url.is_valid())
422 return PRIV_NORMAL;
423
[email protected]885c0e92012-11-13 20:27:42424 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44425 const Extension* extension =
426 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43427 if (extension &&
428 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42429 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45430 if (extension && extension->is_hosted_app())
431 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42432
433 return PRIV_EXTENSION;
434 }
435
436 return PRIV_NORMAL;
437}
438
439RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30440 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46441 extensions::ProcessMap* process_map,
442 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46443 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30444 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46445 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21446 return PRIV_NORMAL;
447
[email protected]6f371442011-11-09 06:45:46448 for (std::set<std::string>::iterator iter = extension_ids.begin();
449 iter != extension_ids.end(); ++iter) {
450 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43451 if (extension &&
452 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42453 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45454 if (extension && extension->is_hosted_app())
455 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42456 }
457
[email protected]676f6ab2011-10-19 20:23:21458 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42459}
460
[email protected]6786bf402011-12-03 15:19:45461bool CertMatchesFilter(const net::X509Certificate& cert,
462 const base::DictionaryValue& filter) {
463 // TODO(markusheintz): This is the minimal required filter implementation.
464 // Implement a better matcher.
465
466 // An empty filter matches any client certificate since no requirements are
467 // specified at all.
468 if (filter.empty())
469 return true;
470
471 std::string common_name;
472 if (filter.GetString("ISSUER.CN", &common_name) &&
473 (cert.issuer().common_name == common_name)) {
474 return true;
475 }
476 return false;
477}
478
[email protected]1d51882f2013-11-12 01:59:02479#if !defined(OS_ANDROID)
[email protected]f3986f82012-01-03 20:00:06480// Fills |map| with the per-script font prefs under path |map_name|.
481void FillFontFamilyMap(const PrefService* prefs,
482 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53483 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]33b79542013-10-18 11:18:45484 // TODO: Get rid of the brute-force scan over possible (font family / script)
485 // combinations - see http://crbug.com/308095.
[email protected]f3986f82012-01-03 20:00:06486 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
487 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
488 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
489 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23490 if (!font_family.empty())
[email protected]cc2a2a22013-12-24 23:12:15491 (*map)[script] = base::UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06492 }
493}
494
[email protected]a1733df2012-06-22 11:24:18495#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]0b818f72013-10-22 00:11:03496breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
497 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02498 base::FilePath dumps_path;
499 PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
500 {
501 ANNOTATE_SCOPED_MEMORY_LEAK;
[email protected]0b818f72013-10-22 00:11:03502 breakpad::CrashHandlerHostLinux* crash_handler =
503 new breakpad::CrashHandlerHostLinux(
504 process_type, dumps_path, getenv(env_vars::kHeadless) == NULL);
[email protected]779dd282013-10-19 15:57:02505 crash_handler->StartUploaderThread();
506 return crash_handler;
507 }
508}
509
[email protected]a1733df2012-06-22 11:24:18510int GetCrashSignalFD(const CommandLine& command_line) {
[email protected]cd0f7af2014-01-16 23:50:39511 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
[email protected]0b818f72013-10-22 00:11:03512 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02513 if (!crash_handler)
514 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18515 return crash_handler->GetDeathSignalSocket();
516 }
517
518 std::string process_type =
519 command_line.GetSwitchValueASCII(switches::kProcessType);
520
[email protected]779dd282013-10-19 15:57:02521 if (process_type == switches::kRendererProcess) {
[email protected]0b818f72013-10-22 00:11:03522 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02523 if (!crash_handler)
524 crash_handler = CreateCrashHandlerHost(process_type);
525 return crash_handler->GetDeathSignalSocket();
526 }
[email protected]a1733df2012-06-22 11:24:18527
[email protected]779dd282013-10-19 15:57:02528 if (process_type == switches::kPluginProcess) {
[email protected]0b818f72013-10-22 00:11:03529 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02530 if (!crash_handler)
531 crash_handler = CreateCrashHandlerHost(process_type);
532 return crash_handler->GetDeathSignalSocket();
533 }
[email protected]a1733df2012-06-22 11:24:18534
[email protected]779dd282013-10-19 15:57:02535 if (process_type == switches::kPpapiPluginProcess) {
[email protected]0b818f72013-10-22 00:11:03536 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02537 if (!crash_handler)
538 crash_handler = CreateCrashHandlerHost(process_type);
539 return crash_handler->GetDeathSignalSocket();
540 }
[email protected]a1733df2012-06-22 11:24:18541
[email protected]779dd282013-10-19 15:57:02542 if (process_type == switches::kGpuProcess) {
[email protected]0b818f72013-10-22 00:11:03543 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02544 if (!crash_handler)
545 crash_handler = CreateCrashHandlerHost(process_type);
546 return crash_handler->GetDeathSignalSocket();
547 }
[email protected]a1733df2012-06-22 11:24:18548
549 return -1;
550}
551#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]1d51882f2013-11-12 01:59:02552#endif // !defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18553
[email protected]d5bcd06f2013-04-21 08:07:24554#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30555GURL GetEffectiveURLForSignin(const GURL& url) {
556 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
557
558 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03559 // Copy the path because the argument to SetPathStr must outlive
560 // the Replacements object.
561 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30562 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03563 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30564 effective_url = effective_url.ReplaceComponents(replacements);
565 return effective_url;
566}
[email protected]d5bcd06f2013-04-21 08:07:24567#endif
[email protected]970c63e2013-03-07 00:25:30568
[email protected]eabbfb12013-04-05 23:28:35569void SetApplicationLocaleOnIOThread(const std::string& locale) {
570 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
571 g_io_thread_application_locale.Get() = locale;
572}
573
[email protected]916615b2013-09-11 18:19:44574void HandleBlockedPopupOnUIThread(const BlockedWindowParams& params) {
575 WebContents* tab = tab_util::GetWebContentsByID(params.render_process_id(),
576 params.opener_id());
[email protected]190e5e22013-07-27 05:59:23577 if (!tab)
578 return;
579
[email protected]f1cd3362014-01-07 20:43:01580 prerender::PrerenderContents* prerender_contents =
581 prerender::PrerenderContents::FromWebContents(tab);
582 if (prerender_contents) {
583 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW);
584 return;
585 }
586
[email protected]190e5e22013-07-27 05:59:23587 PopupBlockerTabHelper* popup_helper =
588 PopupBlockerTabHelper::FromWebContents(tab);
589 if (!popup_helper)
590 return;
[email protected]916615b2013-09-11 18:19:44591 popup_helper->AddBlockedPopup(params);
[email protected]190e5e22013-07-27 05:59:23592}
[email protected]190e5e22013-07-27 05:59:23593
[email protected]916615b2013-09-11 18:19:44594#if defined(OS_ANDROID)
[email protected]b255a8e0e82013-10-22 04:03:59595
[email protected]916615b2013-09-11 18:19:44596void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams& params) {
597 WebContents* web_contents =
598 tab_util::GetWebContentsByID(params.render_process_id(),
599 params.opener_id());
600 if (!web_contents)
601 return;
602
603 SingleTabModeTabHelper::FromWebContents(web_contents)->HandleOpenUrl(params);
604}
[email protected]b255a8e0e82013-10-22 04:03:59605
[email protected]ded00dc2013-11-01 00:37:05606float GetDeviceScaleAdjustment() {
[email protected]b255a8e0e82013-10-22 04:03:59607 static const float kMinFSM = 1.05f;
608 static const int kWidthForMinFSM = 320;
609 static const float kMaxFSM = 1.3f;
610 static const int kWidthForMaxFSM = 800;
611
612 gfx::DeviceDisplayInfo info;
613 int minWidth = info.GetSmallestDIPWidth();
614
615 if (minWidth <= kWidthForMinFSM)
616 return kMinFSM;
617 if (minWidth >= kWidthForMaxFSM)
618 return kMaxFSM;
619
620 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
621 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) /
622 (kWidthForMaxFSM - kWidthForMinFSM);
623 return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
624}
625
[email protected]916615b2013-09-11 18:19:44626#endif // defined(OS_ANDROID)
627
[email protected]9dbfff12011-07-01 19:37:07628} // namespace
[email protected]c5dbef02011-05-13 05:06:09629
[email protected]d977f9c2011-03-14 16:10:26630namespace chrome {
631
[email protected]e461da2f2012-02-16 19:06:40632ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40633#if defined(ENABLE_PLUGINS)
[email protected]10c39222013-11-13 20:09:25634 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i)
635 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40636 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
637 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40638#endif
[email protected]1deace22013-05-22 06:14:46639
640 permissions_policy_delegate_.reset(
641 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40642}
643
644ChromeContentBrowserClient::~ChromeContentBrowserClient() {
645}
646
[email protected]bca18382012-06-25 19:15:23647// static
[email protected]37ca3fe02013-07-05 15:32:44648void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34649 user_prefs::PrefRegistrySyncable* registry) {
650 registry->RegisterBooleanPref(
651 prefs::kDisable3DAPIs,
652 false,
653 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
654 registry->RegisterBooleanPref(
655 prefs::kEnableHyperlinkAuditing,
656 true,
657 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
658 registry->RegisterBooleanPref(
659 prefs::kEnableMemoryInfo,
660 false,
661 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23662}
663
[email protected]eabbfb12013-04-05 23:28:35664// static
665void ChromeContentBrowserClient::SetApplicationLocale(
666 const std::string& locale) {
667 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
668
669 // This object is guaranteed to outlive all threads so we don't have to
670 // worry about the lack of refcounting and can just post as Unretained.
671 //
672 // The common case is that this function is called early in Chrome startup
673 // before any threads are created (it will also be called later if the user
674 // changes the pref). In this case, there will be no threads created and
675 // posting will fail. When there are no threads, we can just set the string
676 // without worrying about threadsafety.
677 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
678 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
679 g_io_thread_application_locale.Get() = locale;
680 }
681}
682
[email protected]50462bf02011-11-21 19:13:31683content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
684 const content::MainFunctionParams& parameters) {
685 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30686 // Construct the Main browser parts based on the OS type.
687#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31688 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04689#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31690 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30691#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22692 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26693#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31694 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14695#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09696 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30697#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31698 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04699#else
[email protected]b48c9182011-10-26 18:03:30700 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31701 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30702#endif
703
[email protected]7e75e4a2013-05-17 17:20:03704 chrome::AddProfilesExtraParts(main_parts);
705
[email protected]c7480942011-11-08 19:18:27706 // Construct additional browser parts. Stages are called in the order in
707 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22708#if defined(TOOLKIT_GTK)
[email protected]e8b6ca02013-07-10 18:00:51709 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04710#endif
[email protected]c7480942011-11-08 19:18:27711
712#if defined(TOOLKIT_VIEWS)
[email protected]e8b6ca02013-07-10 18:00:51713 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27714#endif
715
[email protected]dc04be7c2012-03-15 23:57:49716#if defined(USE_ASH)
[email protected]e8b6ca02013-07-10 18:00:51717 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
[email protected]dc04be7c2012-03-15 23:57:49718#endif
719
[email protected]e050ef142012-03-21 01:04:24720#if defined(USE_AURA)
[email protected]e8b6ca02013-07-10 18:00:51721 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
722#endif
723
724#if defined(USE_X11)
725 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:24726#endif
727
[email protected]95132f52013-04-12 02:19:04728 chrome::AddMetricsExtraParts(main_parts);
729
[email protected]50462bf02011-11-21 19:13:31730 return main_parts;
[email protected]f967b722011-09-07 00:58:04731}
732
[email protected]e94bbcb2012-09-07 05:33:57733std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19734 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57735 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53736 std::string partition_id;
737
738 // The partition ID for webview guest processes is the string value of its
739 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
[email protected]6eb1a11e2013-10-09 00:54:37740 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:53741 partition_id = site.spec();
742
[email protected]056efdc2013-04-06 00:14:53743 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53744 return partition_id;
745}
746
747bool ChromeContentBrowserClient::IsValidStoragePartitionId(
748 content::BrowserContext* browser_context,
749 const std::string& partition_id) {
750 // The default ID is empty and is always valid.
751 if (partition_id.empty())
752 return true;
753
754 return GURL(partition_id).is_valid();
755}
756
757void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
758 content::BrowserContext* browser_context,
759 const GURL& site,
[email protected]14acc642012-11-17 12:20:10760 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53761 std::string* partition_domain,
762 std::string* partition_name,
763 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10764 // Default to the browser-wide storage partition and override based on |site|
765 // below.
766 partition_domain->clear();
767 partition_name->clear();
768 *in_memory = false;
769
[email protected]3f24f97c2013-11-17 21:53:33770 bool success = GuestView::GetGuestPartitionConfigForSite(
771 site, partition_domain, partition_name, in_memory);
772
773 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
[email protected]14acc642012-11-17 12:20:10774 // If |can_be_default| is false, the caller is stating that the |site|
775 // should be parsed as if it had isolated storage. In particular it is
776 // important to NOT check ExtensionService for the is_storage_isolated()
777 // attribute because this code path is run during Extension uninstall
778 // to do cleanup after the Extension has already been unloaded from the
779 // ExtensionService.
780 bool is_isolated = !can_be_default;
781 if (can_be_default) {
782 const Extension* extension = NULL;
783 Profile* profile = Profile::FromBrowserContext(browser_context);
784 ExtensionService* extension_service =
785 extensions::ExtensionSystem::Get(profile)->extension_service();
786 if (extension_service) {
[email protected]be9915fb2013-07-18 09:28:55787 extension =
788 extension_service->extensions()->GetExtensionOrAppByURL(site);
[email protected]561e33d52013-04-03 06:58:43789 if (extension &&
790 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10791 is_isolated = true;
792 }
793 }
794 }
[email protected]1bc28312012-11-08 08:31:53795
[email protected]14acc642012-11-17 12:20:10796 if (is_isolated) {
797 CHECK(site.has_host());
798 // For extensions with isolated storage, the the host of the |site| is
799 // the |partition_domain|. The |in_memory| and |partition_name| are only
800 // used in guest schemes so they are cleared here.
801 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53802 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10803 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53804 }
[email protected]d1198fd2012-08-13 22:50:19805 }
806
[email protected]14acc642012-11-17 12:20:10807 // Assert that if |can_be_default| is false, the code above must have found a
808 // non-default partition. If this fails, the caller has a serious logic
809 // error about which StoragePartition they expect to be in and it is not
810 // safe to continue.
811 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44812}
813
[email protected]38b098f2012-03-14 21:11:57814content::WebContentsViewDelegate*
815 ChromeContentBrowserClient::GetWebContentsViewDelegate(
816 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27817 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32818}
819
[email protected]738f57a2013-06-29 21:06:54820void ChromeContentBrowserClient::GuestWebContentsCreated(
[email protected]dbbce92c2013-10-31 16:51:19821 SiteInstance* guest_site_instance,
[email protected]738f57a2013-06-29 21:06:54822 WebContents* guest_web_contents,
823 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22824 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54825 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]dbbce92c2013-10-31 16:51:19826 if (!guest_site_instance) {
827 NOTREACHED();
828 return;
829 }
830 GURL guest_site_url = guest_site_instance->GetSiteURL();
831 const std::string& extension_id = guest_site_url.host();
832
833 Profile* profile = Profile::FromBrowserContext(
834 guest_web_contents->GetBrowserContext());
835 ExtensionService* service =
836 extensions::ExtensionSystem::Get(profile)->extension_service();
837 if (!service) {
838 NOTREACHED();
839 return;
840 }
841
842 /// TODO(fsamuel): In the future, certain types of GuestViews won't require
843 // extension bindings. At that point, we should clear |extension_id| instead
844 // of exiting early.
845 if (!service->GetExtensionById(extension_id, false) &&
846 !CommandLine::ForCurrentProcess()->HasSwitch(
847 switches::kEnableBrowserPluginForAllViewTypes)) {
848 NOTREACHED();
849 return;
850 }
851
[email protected]738f57a2013-06-29 21:06:54852 if (opener_web_contents) {
853 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
854 if (!guest) {
855 NOTREACHED();
856 return;
857 }
858
[email protected]50c827d2013-09-13 21:36:09859 // Create a new GuestView of the same type as the opener.
860 *guest_delegate =
[email protected]dbbce92c2013-10-31 16:51:19861 GuestView::Create(guest_web_contents,
862 extension_id,
863 guest->GetViewType());
[email protected]738f57a2013-06-29 21:06:54864 return;
865 }
866
867 if (!extra_params) {
868 NOTREACHED();
869 return;
870 }
871 std::string api_type;
[email protected]90547d72013-08-06 05:57:27872 extra_params->GetString(guestview::kParameterApi, &api_type);
[email protected]738f57a2013-06-29 21:06:54873
[email protected]dbbce92c2013-10-31 16:51:19874 if (api_type.empty())
875 return;
876
[email protected]50c827d2013-09-13 21:36:09877 *guest_delegate =
878 GuestView::Create(guest_web_contents,
[email protected]dbbce92c2013-10-31 16:51:19879 extension_id,
[email protected]50c827d2013-09-13 21:36:09880 GuestView::GetViewTypeFromString(api_type));
[email protected]738f57a2013-06-29 21:06:54881}
882
[email protected]44295a12013-06-05 08:45:46883void ChromeContentBrowserClient::GuestWebContentsAttached(
884 WebContents* guest_web_contents,
885 WebContents* embedder_web_contents,
[email protected]5715566a2013-06-25 00:04:53886 const base::DictionaryValue& extra_params) {
[email protected]22aa4f82013-09-24 17:01:44887
[email protected]dbbce92c2013-10-31 16:51:19888 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
889 if (!guest) {
[email protected]efd6fb02013-08-05 04:44:06890 // It's ok to return here, since we could be running a browser plugin
891 // outside an extension, and don't need to attach a
892 // BrowserPluginGuestDelegate in that case;
893 // e.g. running with flag --enable-browser-plugin-for-all-view-types.
[email protected]738f57a2013-06-29 21:06:54894 return;
[email protected]18699372013-06-25 20:42:55895 }
[email protected]dbbce92c2013-10-31 16:51:19896 guest->Attach(embedder_web_contents, extra_params);
[email protected]44703cc72013-01-24 04:56:06897}
898
[email protected]6f2862742013-12-20 07:53:19899void ChromeContentBrowserClient::RenderProcessWillLaunch(
[email protected]f3b1a082011-11-18 00:34:30900 content::RenderProcessHost* host) {
901 int id = host->GetID();
902 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41903 net::URLRequestContextGetter* context =
904 profile->GetRequestContextForRenderProcess(id);
905
[email protected]ba780c12013-10-01 17:07:06906 host->AddFilter(new ChromeRenderMessageFilter(id, profile, context));
[email protected]afed5112014-02-02 06:01:53907 host->AddFilter(new extensions::ExtensionMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55908#if defined(ENABLE_PLUGINS)
[email protected]ba780c12013-10-01 17:07:06909 host->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55910#endif
[email protected]658677f2012-06-09 06:04:02911#if defined(ENABLE_PRINTING)
[email protected]ba780c12013-10-01 17:07:06912 host->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03913#endif
[email protected]ba780c12013-10-01 17:07:06914 host->AddFilter(new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]c6ce08072013-07-31 07:48:53915#if defined(ENABLE_SPELLCHECK)
[email protected]ba780c12013-10-01 17:07:06916 host->AddFilter(new SpellCheckMessageFilter(id));
[email protected]c6ce08072013-07-31 07:48:53917#endif
[email protected]7ceb99012011-12-21 08:05:56918#if defined(OS_MACOSX)
[email protected]ba780c12013-10-01 17:07:06919 host->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56920#endif
[email protected]49aa5a32014-02-03 10:00:44921 host->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile, context));
[email protected]ba780c12013-10-01 17:07:06922 host->AddFilter(new prerender::PrerenderMessageFilter(id, profile));
[email protected]ba780c12013-10-01 17:07:06923 host->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31924#if defined(ENABLE_WEBRTC)
[email protected]10e5c5e52013-10-03 18:44:06925 WebRtcLoggingHandlerHost* webrtc_logging_handler_host =
[email protected]135bc1d2013-10-21 09:11:37926 new WebRtcLoggingHandlerHost(profile);
[email protected]e7b9b352014-01-29 16:35:27927 host->SetWebRtcLogMessageCallback(base::Bind(
928 &WebRtcLoggingHandlerHost::LogMessage, webrtc_logging_handler_host));
[email protected]10e5c5e52013-10-03 18:44:06929 host->AddFilter(webrtc_logging_handler_host);
930 host->SetUserData(host, new base::UserDataAdapter<WebRtcLoggingHandlerHost>(
931 webrtc_logging_handler_host));
[email protected]6ef98b5a2013-05-31 23:58:31932#endif
[email protected]01e59752013-06-18 00:17:35933#if !defined(DISABLE_NACL)
[email protected]7c766e92013-11-22 20:44:02934 host->AddFilter(new nacl::NaClHostMessageFilter(
[email protected]14230ca2013-06-26 23:33:03935 id, profile->IsOffTheRecord(),
[email protected]a2b4c5c2013-10-18 02:06:07936 profile->GetPath(),
[email protected]14230ca2013-06-26 23:33:03937 context));
[email protected]01e59752013-06-18 00:17:35938#endif
[email protected]2b12c322013-09-19 06:53:56939#if defined(OS_ANDROID)
[email protected]ba780c12013-10-01 17:07:06940 host->AddFilter(new EncryptedMediaMessageFilterAndroid());
[email protected]2b12c322013-09-19 06:53:56941#endif
[email protected]4de75262013-12-18 23:16:12942 if (switches::IsNewProfileManagement())
[email protected]914cf6712013-12-05 01:14:06943 host->AddFilter(new PrincipalsMessageFilter(id));
[email protected]3e69bc82011-05-26 23:22:38944
[email protected]2ccf45c2011-08-19 23:35:50945 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
946 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07947
948 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56949
950 RendererContentSettingRules rules;
[email protected]06153f02013-12-04 03:01:28951 if (host->IsGuest()) {
952 GuestView::GetDefaultContentSettingRules(&rules, profile->IsOffTheRecord());
953 } else {
954 GetRendererContentSettingRules(
955 profile->GetHostContentSettingsMap(), &rules);
956 }
[email protected]edece212011-11-16 11:56:56957 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14958}
959
[email protected]3d7474ff2011-07-27 17:47:37960GURL ChromeContentBrowserClient::GetEffectiveURL(
961 content::BrowserContext* browser_context, const GURL& url) {
962 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52963 if (!profile)
964 return url;
965
[email protected]b3cb3a32013-07-31 01:32:29966 // If the input |url| should be assigned to the Instant renderer, make its
967 // effective URL distinct from other URLs on the search provider's domain.
968 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
969 return chrome::GetEffectiveURLForInstant(url, profile);
970
[email protected]d5bcd06f2013-04-21 08:07:24971#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30972 // If the input |url| should be assigned to the Signin renderer, make its
973 // effective URL distinct from other URLs on the signin service's domain.
974 // Note that the signin renderer will be allowed to sign the user in to
975 // Chrome.
976 if (SigninManager::IsWebBasedSigninFlowURL(url))
977 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24978#endif
[email protected]970c63e2013-03-07 00:25:30979
[email protected]c5dec6292013-01-25 04:54:52980 // If the input |url| is part of an installed app, the effective URL is an
981 // extension URL with the ID of that extension as the host. This has the
982 // effect of grouping apps together in a common SiteInstance.
983 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13984 extensions::ExtensionSystem::Get(profile)->extension_service();
985 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08986 return url;
987
[email protected]06bdd2b2012-11-30 18:47:13988 const Extension* extension = extension_service->extensions()->
[email protected]be9915fb2013-07-18 09:28:55989 GetHostedAppByURL(url);
[email protected]36fb2c7c2011-04-04 15:49:08990 if (!extension)
991 return url;
992
[email protected]15877ca2011-11-18 22:40:52993 // Bookmark apps do not use the hosted app process model, and should be
994 // treated as normal URLs.
995 if (extension->from_bookmark())
996 return url;
997
[email protected]36fb2c7c2011-04-04 15:49:08998 // If the URL is part of an extension's web extent, convert it to an
999 // extension URL.
1000 return extension->GetResourceURL(url.path());
1001}
1002
[email protected]056ad2a2011-07-12 02:13:551003bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:371004 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:521005 // Non-extension, non-Instant URLs should generally use
1006 // process-per-site-instance. Because we expect to use the effective URL,
1007 // URLs for hosted apps (apart from bookmark apps) should have an extension
1008 // scheme by now.
1009
1010 Profile* profile = Profile::FromBrowserContext(browser_context);
1011 if (!profile)
1012 return false;
1013
[email protected]df113a12013-07-24 04:56:081014 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:521015 return true;
1016
[email protected]d5bcd06f2013-04-21 08:07:241017#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301018 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
1019 return true;
[email protected]d5bcd06f2013-04-21 08:07:241020#endif
[email protected]970c63e2013-03-07 00:25:301021
[email protected]885c0e92012-11-13 20:27:421022 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:551023 return false;
1024
[email protected]c5dec6292013-01-25 04:54:521025 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:131026 extensions::ExtensionSystem::Get(profile)->extension_service();
1027 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:551028 return false;
1029
[email protected]be9915fb2013-07-18 09:28:551030 const Extension* extension =
1031 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
[email protected]056ad2a2011-07-12 02:13:551032 if (!extension)
1033 return false;
1034
1035 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:531036 // permission, or that does not allow JavaScript access to the background
1037 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:551038 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:401039 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:061040 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:291041 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:531042 return false;
1043 }
1044 }
[email protected]056ad2a2011-07-12 02:13:551045
[email protected]7b54ca02012-03-02 18:06:531046 // Hosted apps that have script access to their background page must use
1047 // process per site, since all instances can make synchronous calls to the
1048 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:551049 return true;
1050}
1051
[email protected]73b718f2014-01-27 02:59:461052// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1053// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411054void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1055 std::vector<std::string>* additional_schemes) {
1056 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]73b718f2014-01-27 02:59:461057 additional_schemes->push_back(chrome::kDomDistillerScheme);
[email protected]672c8c12013-03-07 12:30:061058}
1059
[email protected]6bd30072013-02-08 18:17:111060net::URLRequestContextGetter*
1061ChromeContentBrowserClient::CreateRequestContext(
1062 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:061063 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:111064 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:061065 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111066}
1067
1068net::URLRequestContextGetter*
1069ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
1070 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:401071 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:111072 bool in_memory,
[email protected]672c8c12013-03-07 12:30:061073 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:111074 Profile* profile = Profile::FromBrowserContext(browser_context);
1075 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:061076 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111077}
1078
[email protected]46fb9442011-12-09 17:57:471079bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1080 return ProfileIOData::IsHandledURL(url);
1081}
1082
[email protected]c4365fa42013-05-14 01:08:241083bool ChromeContentBrowserClient::CanCommitURL(
1084 content::RenderProcessHost* process_host,
1085 const GURL& url) {
1086 // We need to let most extension URLs commit in any process, since this can
1087 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1088 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1089 // cannot be loaded in iframes and should never be requested outside its
1090 // process.
1091 Profile* profile =
1092 Profile::FromBrowserContext(process_host->GetBrowserContext());
1093 ExtensionService* service =
1094 extensions::ExtensionSystem::Get(profile)->extension_service();
1095 if (!service)
1096 return true;
1097 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551098 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]c4365fa42013-05-14 01:08:241099 if (new_extension &&
1100 new_extension->is_hosted_app() &&
1101 new_extension->id() == extension_misc::kWebStoreAppId &&
[email protected]fafdc842014-01-17 18:09:081102 !extensions::ProcessMap::Get(profile)->
1103 Contains(new_extension->id(), process_host->GetID())) {
[email protected]c4365fa42013-05-14 01:08:241104 return false;
1105 }
1106
1107 return true;
1108}
1109
[email protected]9a60d1602013-09-11 04:09:121110bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1111 content::SiteInstance* site_instance, const GURL& url) {
1112 GURL from_url = site_instance->GetSiteURL();
1113 // Do not allow pages from the web or other extensions navigate to
1114 // non-web-accessible extension resources.
1115 if (url.SchemeIs(extensions::kExtensionScheme) &&
1116 (from_url.SchemeIsHTTPOrHTTPS() ||
1117 from_url.SchemeIs(extensions::kExtensionScheme))) {
1118 Profile* profile = Profile::FromBrowserContext(
1119 site_instance->GetProcess()->GetBrowserContext());
1120 ExtensionService* service =
1121 extensions::ExtensionSystem::Get(profile)->extension_service();
1122 if (!service)
1123 return true;
1124 const Extension* extension =
1125 service->extensions()->GetExtensionOrAppByURL(url);
1126 if (!extension)
1127 return true;
1128 const Extension* from_extension =
1129 service->extensions()->GetExtensionOrAppByURL(
1130 site_instance->GetSiteURL());
1131 if (from_extension && from_extension->id() == extension->id())
1132 return true;
1133
1134 if (!extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
1135 extension, url.path()))
1136 return false;
1137 }
1138 return true;
1139}
1140
[email protected]2a5221b2011-09-27 23:07:311141bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301142 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311143 const GURL& site_url) {
1144 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301145 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521146 // This may be NULL during tests. In that case, just assume any site can
1147 // share any host.
1148 if (!profile)
1149 return true;
1150
[email protected]d43f99fe2013-04-03 00:20:141151 // Instant URLs should only be in the instant process and instant process
1152 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521153 InstantService* instant_service =
1154 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141155 if (instant_service) {
1156 bool is_instant_process = instant_service->IsInstantProcess(
1157 process_host->GetID());
1158 bool should_be_in_instant_process =
1159 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1160 if (is_instant_process || should_be_in_instant_process)
1161 return is_instant_process && should_be_in_instant_process;
1162 }
[email protected]c5dec6292013-01-25 04:54:521163
[email protected]d5bcd06f2013-04-21 08:07:241164#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301165 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1166 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1167 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241168#endif
[email protected]970c63e2013-03-07 00:25:301169
[email protected]06bdd2b2012-11-30 18:47:131170 ExtensionService* service =
1171 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]fafdc842014-01-17 18:09:081172 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile);
[email protected]2a5221b2011-09-27 23:07:311173
[email protected]ffa97602011-11-17 17:55:521174 // Don't allow the Task Manager to share a process with anything else.
1175 // Otherwise it can affect the renderers it is observing.
1176 // Note: we could create another RenderProcessHostPrivilege bucket for
1177 // this to allow multiple chrome://tasks instances to share, but that's
1178 // a very unlikely case without serious consequences.
1179 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1180 return false;
1181
[email protected]8d3132f62011-10-12 07:13:421182 // These may be NULL during tests. In that case, just assume any site can
1183 // share any host.
[email protected]6f371442011-11-09 06:45:461184 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311185 return true;
1186
[email protected]eec0b33c2011-12-05 22:09:451187 // Otherwise, just make sure the process privilege matches the privilege
1188 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571189 RenderProcessHostPrivilege privilege_required =
1190 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451191 return GetProcessPrivilege(process_host, process_map, service) ==
1192 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311193}
1194
[email protected]76411f412012-02-22 18:56:061195// This function is trying to limit the amount of processes used by extensions
1196// with background pages. It uses a globally set percentage of processes to
1197// run such extensions and if the limit is exceeded, it returns true, to
1198// indicate to the content module to group extensions together.
1199bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1200 content::BrowserContext* browser_context, const GURL& url) {
1201 // It has to be a valid URL for us to check for an extension.
1202 if (!url.is_valid())
1203 return false;
1204
1205 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191206 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131207 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061208 if (!service)
1209 return false;
1210
1211 // We have to have a valid extension with background page to proceed.
1212 const Extension* extension =
[email protected]be9915fb2013-07-18 09:28:551213 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]76411f412012-02-22 18:56:061214 if (!extension)
1215 return false;
[email protected]9367eabc2013-03-01 01:29:291216 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061217 return false;
1218
1219 std::set<int> process_ids;
1220 size_t max_process_count =
1221 content::RenderProcessHost::GetMaxRendererProcessCount();
1222
1223 // Go through all profiles to ensure we have total count of extension
1224 // processes containing background pages, otherwise one profile can
1225 // starve the other.
1226 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1227 GetLoadedProfiles();
1228 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]98b6d942013-11-10 00:34:071229 extensions::ProcessManager* epm =
[email protected]be93bba02012-10-24 16:44:031230 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]98b6d942013-11-10 00:34:071231 for (extensions::ProcessManager::const_iterator iter =
[email protected]d1fe1352012-04-26 00:47:321232 epm->background_hosts().begin();
1233 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131234 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321235 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061236 }
1237 }
1238
1239 if (process_ids.size() >
1240 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1241 return true;
1242 }
1243
1244 return false;
1245}
1246
[email protected]6f371442011-11-09 06:45:461247void ChromeContentBrowserClient::SiteInstanceGotProcess(
1248 SiteInstance* site_instance) {
1249 CHECK(site_instance->HasProcess());
1250
1251 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021252 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521253 if (!profile)
1254 return;
1255
1256 // Remember the ID of the Instant process to signal the renderer process
1257 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031258 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321259 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521260 InstantService* instant_service =
1261 InstantServiceFactory::GetForProfile(profile);
1262 if (instant_service)
1263 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1264 }
1265
[email protected]d5bcd06f2013-04-21 08:07:241266#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301267 // We only expect there to be one signin process as we use process-per-site
1268 // for signin URLs. The signin process will be cleared from SigninManager
1269 // when the renderer is destroyed.
1270 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1271 SigninManager* signin_manager =
1272 SigninManagerFactory::GetForProfile(profile);
1273 if (signin_manager)
1274 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461275 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:201276 BrowserThread::IO,
1277 FROM_HERE,
1278 base::Bind(&InfoMap::SetSigninProcess,
[email protected]1deace22013-05-22 06:14:461279 extensions::ExtensionSystem::Get(profile)->info_map(),
1280 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301281 }
[email protected]d5bcd06f2013-04-21 08:07:241282#endif
[email protected]970c63e2013-03-07 00:25:301283
[email protected]06bdd2b2012-11-30 18:47:131284 ExtensionService* service =
1285 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461286 if (!service)
1287 return;
1288
[email protected]be9915fb2013-07-18 09:28:551289 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1290 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461291 if (!extension)
1292 return;
1293
[email protected]fafdc842014-01-17 18:09:081294 extensions::ProcessMap::Get(profile)
1295 ->Insert(extension->id(),
1296 site_instance->GetProcess()->GetID(),
1297 site_instance->GetId());
1298
[email protected]6f371442011-11-09 06:45:461299 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:201300 BrowserThread::IO,
1301 FROM_HERE,
1302 base::Bind(&InfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591303 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461304 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351305 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331306 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461307}
1308
1309void ChromeContentBrowserClient::SiteInstanceDeleting(
1310 SiteInstance* site_instance) {
1311 if (!site_instance->HasProcess())
1312 return;
1313
1314 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021315 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131316 ExtensionService* service =
1317 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461318 if (!service)
1319 return;
1320
[email protected]be9915fb2013-07-18 09:28:551321 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1322 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461323 if (!extension)
1324 return;
1325
[email protected]fafdc842014-01-17 18:09:081326 extensions::ProcessMap::Get(profile)
1327 ->Remove(extension->id(),
1328 site_instance->GetProcess()->GetID(),
1329 site_instance->GetId());
1330
[email protected]6f371442011-11-09 06:45:461331 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:201332 BrowserThread::IO,
1333 FROM_HERE,
1334 base::Bind(&InfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591335 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461336 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351337 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331338 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461339}
1340
[email protected]896c6d52014-01-28 21:40:211341void ChromeContentBrowserClient::WorkerProcessCreated(
1342 SiteInstance* site_instance,
1343 int worker_process_id) {
1344 extensions::ExtensionRegistry* extension_registry =
1345 extensions::ExtensionRegistry::Get(site_instance->GetBrowserContext());
1346 if (!extension_registry)
1347 return;
1348 const Extension* extension =
1349 extension_registry->enabled_extensions().GetExtensionOrAppByURL(
1350 site_instance->GetSiteURL());
1351 if (!extension)
1352 return;
1353 extensions::ExtensionSystem* extension_system =
[email protected]59b0e602014-01-30 00:41:241354 extensions::ExtensionSystem::Get(site_instance->GetBrowserContext());
[email protected]896c6d52014-01-28 21:40:211355 extension_system->info_map()->RegisterExtensionWorkerProcess(
1356 extension->id(),
1357 worker_process_id,
1358 site_instance->GetId());
1359}
1360
1361void ChromeContentBrowserClient::WorkerProcessTerminated(
1362 SiteInstance* site_instance,
1363 int worker_process_id) {
1364 extensions::ExtensionSystem* extension_system =
[email protected]59b0e602014-01-30 00:41:241365 extensions::ExtensionSystem::Get(site_instance->GetBrowserContext());
[email protected]896c6d52014-01-28 21:40:211366 extension_system->info_map()->UnregisterExtensionWorkerProcess(
1367 worker_process_id);
1368}
1369
[email protected]453f5432013-11-26 19:43:001370bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141371 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081372 const GURL& current_url,
1373 const GURL& new_url) {
[email protected]2aca9a92013-12-03 05:16:071374 // If we don't have an ExtensionService, then rely on the SiteInstance logic
[email protected]a5a59482013-12-03 22:52:061375 // in RenderFrameHostManager to decide when to swap.
[email protected]e9841fbd2013-02-22 23:12:141376 Profile* profile =
1377 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1378 ExtensionService* service =
1379 extensions::ExtensionSystem::Get(profile)->extension_service();
1380 if (!service)
1381 return false;
1382
[email protected]2aca9a92013-12-03 05:16:071383 // We must use a new BrowsingInstance (forcing a process swap and disabling
1384 // scripting by existing tabs) if one of the URLs is an extension and the
1385 // other is not the exact same extension.
1386 //
1387 // We ignore hosted apps here so that other tabs in their BrowsingInstance can
1388 // use postMessage with them. (The exception is the Chrome Web Store, which
1389 // is a hosted app that requires its own BrowsingInstance.) Navigations
1390 // to/from a hosted app will still trigger a SiteInstance swap in
[email protected]a5a59482013-12-03 22:52:061391 // RenderFrameHostManager.
[email protected]2aca9a92013-12-03 05:16:071392 const Extension* current_extension =
1393 service->extensions()->GetExtensionOrAppByURL(current_url);
1394 if (current_extension &&
1395 current_extension->is_hosted_app() &&
1396 current_extension->id() != extension_misc::kWebStoreAppId)
1397 current_extension = NULL;
1398
[email protected]e9841fbd2013-02-22 23:12:141399 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551400 service->extensions()->GetExtensionOrAppByURL(new_url);
[email protected]e9841fbd2013-02-22 23:12:141401 if (new_extension &&
1402 new_extension->is_hosted_app() &&
1403 new_extension->id() != extension_misc::kWebStoreAppId)
1404 new_extension = NULL;
[email protected]2aca9a92013-12-03 05:16:071405
1406 // First do a process check. We should force a BrowsingInstance swap if the
1407 // current process doesn't know about new_extension, even if current_extension
1408 // is somehow the same as new_extension.
[email protected]fafdc842014-01-17 18:09:081409 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile);
[email protected]e9841fbd2013-02-22 23:12:141410 if (new_extension &&
1411 site_instance->HasProcess() &&
[email protected]fafdc842014-01-17 18:09:081412 !process_map->Contains(
1413 new_extension->id(), site_instance->GetProcess()->GetID()))
[email protected]e9841fbd2013-02-22 23:12:141414 return true;
1415
[email protected]2aca9a92013-12-03 05:16:071416 // Otherwise, swap BrowsingInstances if current_extension and new_extension
1417 // differ.
1418 return current_extension != new_extension;
[email protected]e3daf3c2011-10-05 21:17:081419}
1420
[email protected]395045c2012-05-22 15:04:381421bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1422 content::ResourceContext* resource_context, const GURL& current_url,
1423 const GURL& new_url) {
1424 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1425 return extensions::CrossesExtensionProcessBoundary(
1426 io_data->GetExtensionInfoMap()->extensions(),
[email protected]be9915fb2013-07-18 09:28:551427 current_url, new_url, false);
[email protected]395045c2012-05-22 15:04:381428}
1429
[email protected]3d831992013-07-04 01:13:291430bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1431 return !url.SchemeIs(chrome::kChromeNativeScheme);
1432}
1433
[email protected]763ec4ca2011-04-29 15:48:121434std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1435 const std::string& alias_name) {
1436 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1437}
1438
[email protected]b80f68432011-05-02 17:22:301439void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1440 CommandLine* command_line, int child_process_id) {
[email protected]264c0acac2013-10-01 13:33:301441#if defined(OS_POSIX)
[email protected]0b818f72013-10-22 00:11:031442 if (breakpad::IsCrashReporterEnabled()) {
[email protected]264c0acac2013-10-01 13:33:301443 std::string enable_crash_reporter;
1444 GoogleUpdateSettings::GetMetricsId(&enable_crash_reporter);
1445#if !defined(OS_MACOSX)
1446 enable_crash_reporter += "," + base::GetLinuxDistro();
1447#endif
[email protected]b80f68432011-05-02 17:22:301448 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
[email protected]264c0acac2013-10-01 13:33:301449 enable_crash_reporter);
[email protected]b80f68432011-05-02 17:22:301450 }
[email protected]264c0acac2013-10-01 13:33:301451#endif // OS_POSIX
[email protected]b80f68432011-05-02 17:22:301452
[email protected]f1933792011-06-14 00:49:341453 if (logging::DialogsAreSuppressed())
1454 command_line->AppendSwitch(switches::kNoErrorDialogs);
1455
[email protected]b80f68432011-05-02 17:22:301456 std::string process_type =
1457 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171458 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321459
[email protected]7c9b6f92013-09-10 18:11:351460 static const char* const kCommonSwitchNames[] = {
[email protected]7c9b6f92013-09-10 18:11:351461 switches::kUserDataDir, // Make logs go to the right file.
1462 };
1463 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
1464 arraysize(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:321465
[email protected]8c64e282013-11-28 16:05:141466#if defined(ENABLE_IPC_FUZZER)
1467 static const char* const kIpcFuzzerSwitches[] = {
1468 switches::kIpcFuzzerTestcase,
1469 };
1470 command_line->CopySwitchesFrom(browser_command_line, kIpcFuzzerSwitches,
1471 arraysize(kIpcFuzzerSwitches));
1472#endif
1473
[email protected]718eab62011-10-05 21:16:521474 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:301475#if defined(OS_CHROMEOS)
1476 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441477 browser_command_line.GetSwitchValueASCII(
1478 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301479 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441480 command_line->AppendSwitchASCII(
1481 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301482#endif
1483
[email protected]50fa4d5f2013-11-05 00:53:231484#if defined(ENABLE_WEBRTC)
[email protected]9ed49f82014-02-07 17:45:591485#if defined(OS_ANDROID)
1486 const VersionInfo::Channel kMaxDisableEncryptionChannel =
1487 VersionInfo::CHANNEL_BETA;
1488#else
1489 const VersionInfo::Channel kMaxDisableEncryptionChannel =
1490 VersionInfo::CHANNEL_DEV;
1491#endif
1492 if (VersionInfo::GetChannel() <= kMaxDisableEncryptionChannel) {
[email protected]50fa4d5f2013-11-05 00:53:231493 static const char* const kWebRtcDevSwitchNames[] = {
1494 switches::kDisableWebRtcEncryption,
1495 };
1496 command_line->CopySwitchesFrom(browser_command_line,
1497 kWebRtcDevSwitchNames,
1498 arraysize(kWebRtcDevSwitchNames));
1499 }
1500#endif
1501
[email protected]f3b1a082011-11-18 00:34:301502 content::RenderProcessHost* process =
1503 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371504 if (process) {
1505 Profile* profile = Profile::FromBrowserContext(
1506 process->GetBrowserContext());
[email protected]fafdc842014-01-17 18:09:081507
1508 if (extensions::ProcessMap::Get(profile)->Contains(process->GetID()))
1509 command_line->AppendSwitch(extensions::switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:301510
[email protected]a8d851f82011-12-21 00:32:371511 PrefService* prefs = profile->GetPrefs();
1512 // Currently this pref is only registered if applied via a policy.
1513 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1514 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1515 // Turn this policy into a command line switch.
1516 command_line->AppendSwitch(switches::kDisable3DAPIs);
1517 }
[email protected]718eab62011-10-05 21:16:521518
[email protected]a8d851f82011-12-21 00:32:371519 // Disable client-side phishing detection in the renderer if it is
1520 // disabled in the Profile preferences or the browser process.
1521 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1522 !g_browser_process->safe_browsing_detection_service()) {
1523 command_line->AppendSwitch(
1524 switches::kDisableClientSidePhishingDetection);
1525 }
[email protected]0045b0f42012-07-26 11:52:081526
1527 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211528 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521529
1530 InstantService* instant_service =
1531 InstantServiceFactory::GetForProfile(profile);
1532 if (instant_service &&
1533 instant_service->IsInstantProcess(process->GetID()))
1534 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301535
[email protected]d5bcd06f2013-04-21 08:07:241536#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301537 SigninManager* signin_manager =
1538 SigninManagerFactory::GetForProfile(profile);
1539 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1540 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241541#endif
[email protected]47c7ec82012-01-18 03:29:211542 }
[email protected]4287a3d2011-06-13 23:56:511543
[email protected]47c7ec82012-01-18 03:29:211544 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511545 static const char* const kSwitchNames[] = {
[email protected]b785898a2014-02-05 06:54:431546 autofill::switches::kDisableIgnoreAutocompleteOff,
[email protected]000f3ad2013-05-16 02:19:171547 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]c3cc0632013-10-03 21:54:431548 autofill::switches::kDisablePasswordGeneration,
[email protected]000f3ad2013-05-16 02:19:171549 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]c3cc0632013-10-03 21:54:431550 autofill::switches::kEnablePasswordGeneration,
[email protected]3cbdf9362014-01-31 23:12:231551 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration,
[email protected]558878cc82013-11-09 01:25:511552 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:271553 extensions::switches::kAllowLegacyExtensionManifests,
1554 extensions::switches::kAllowScriptingGallery,
[email protected]c8d02992013-07-31 22:16:511555 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271556 extensions::switches::kExtensionsOnChromeURLs,
[email protected]9d450492013-06-13 23:08:371557 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1558 // to browser.
1559 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511560 switches::kAppsCheckoutURL,
1561 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311562 switches::kCloudPrintServiceURL,
[email protected]382fb0d2012-02-25 00:19:501563 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531564 switches::kDisableExtensionsResourceWhitelist,
[email protected]83c85262013-08-22 21:13:461565 switches::kDisablePnacl,
[email protected]b0553c7e2012-09-19 21:36:111566 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531567 switches::kEnableAdview,
[email protected]1f4da9e2013-06-27 05:23:441568 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211569 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511570 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451571 switches::kEnableNetBenchmarking,
[email protected]c10b25f2014-01-14 14:57:001572 switches::kEnableStreamlinedHostedApps,
[email protected]4287a3d2011-06-13 23:56:511573 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511574 switches::kMemoryProfiling,
1575 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371576 switches::kNoJsRandomness,
[email protected]8f06e4d2013-11-25 23:20:181577 switches::kOutOfProcessPdf,
[email protected]f45c5f32012-04-18 19:26:371578 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511579 switches::kPpapiFlashArgs,
1580 switches::kPpapiFlashInProcess,
1581 switches::kPpapiFlashPath,
1582 switches::kPpapiFlashVersion,
1583 switches::kProfilingAtStart,
1584 switches::kProfilingFile,
1585 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371586 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511587 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:381588 switches::kWhitelistedExtensionID,
[email protected]499e7c52013-10-04 16:03:091589 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:511590 };
1591
1592 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1593 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171594 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381595 static const char* const kSwitchNames[] = {
[email protected]558878cc82013-11-09 01:25:511596 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]c8d02992013-07-31 22:16:511597 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271598 extensions::switches::kExtensionsOnChromeURLs,
[email protected]a446534d2012-02-09 00:07:381599 switches::kWhitelistedExtensionID,
1600 };
1601
1602 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1603 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511604 } else if (process_type == switches::kPluginProcess) {
1605 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441606#if defined(OS_CHROMEOS)
1607 chromeos::switches::kLoginProfile,
1608#endif
[email protected]4287a3d2011-06-13 23:56:511609 switches::kMemoryProfiling,
1610 switches::kSilentDumpOnDCHECK,
[email protected]4287a3d2011-06-13 23:56:511611 };
1612
1613 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1614 arraysize(kSwitchNames));
1615 } else if (process_type == switches::kZygoteProcess) {
1616 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511617 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501618 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511619 switches::kPpapiFlashInProcess,
1620 switches::kPpapiFlashPath,
1621 switches::kPpapiFlashVersion,
1622 };
1623
1624 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1625 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111626 } else if (process_type == switches::kGpuProcess) {
1627 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1628 // because GPU is expected to be unreliable.
1629 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1630 !command_line->HasSwitch(switches::kDisableBreakpad))
1631 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301632 }
[email protected]6f08af82011-09-15 01:19:031633
1634 // The command line switch kEnableBenchmarking needs to be specified along
1635 // with the kEnableStatsTable switch to ensure that the stats table global
1636 // is initialized correctly.
1637 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1638 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301639}
1640
1641std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431642 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351643 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301644 return g_browser_process->GetApplicationLocale();
1645}
1646
[email protected]597a867b2011-11-18 18:31:201647std::string ChromeContentBrowserClient::GetAcceptLangs(
1648 content::BrowserContext* context) {
1649 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371650 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081651}
1652
[email protected]9ec0f452012-05-31 15:58:531653gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221654 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531655 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081656}
1657
[email protected]a2176792011-05-08 19:30:491658bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091659 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191660 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201661 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201663 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051664 return io_data->GetCookieSettings()->
1665 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491666}
1667
[email protected]ed24fad2011-05-10 22:44:011668bool ChromeContentBrowserClient::AllowGetCookie(
1669 const GURL& url,
1670 const GURL& first_party,
1671 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201672 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011673 int render_process_id,
[email protected]f3add922013-12-20 23:17:161674 int render_frame_id) {
[email protected]ed24fad2011-05-10 22:44:011675 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201676 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051677 bool allow = io_data->GetCookieSettings()->
1678 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011679
[email protected]8093a542011-05-13 07:29:321680 BrowserThread::PostTask(
1681 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031682 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]f3add922013-12-20 23:17:161683 render_frame_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011684 return allow;
1685}
1686
1687bool ChromeContentBrowserClient::AllowSetCookie(
1688 const GURL& url,
1689 const GURL& first_party,
1690 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201691 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011692 int render_process_id,
[email protected]f3add922013-12-20 23:17:161693 int render_frame_id,
[email protected]ed24fad2011-05-10 22:44:011694 net::CookieOptions* options) {
1695 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201696 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051697 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1698 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1699
[email protected]8093a542011-05-13 07:29:321700 BrowserThread::PostTask(
1701 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031702 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]f3add922013-12-20 23:17:161703 render_frame_id, url, first_party, cookie_line, *options,
[email protected]fd473d12012-04-05 11:38:431704 !allow));
[email protected]ed24fad2011-05-10 22:44:011705 return allow;
1706}
1707
[email protected]d5a19162011-06-30 18:51:541708bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201709 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541710 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201711 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431712 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1713 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261714
[email protected]bf510ed2012-06-05 08:31:431715 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1716 // Could we even support per-origin settings?
1717 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541718}
1719
[email protected]5c5a88e2011-11-12 00:45:351720bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351721 const GURL& url,
[email protected]96920152013-12-04 21:00:161722 const base::string16& name,
1723 const base::string16& display_name,
[email protected]5c5a88e2011-11-12 00:45:351724 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201725 content::ResourceContext* context,
[email protected]b765deb2013-12-18 06:43:301726 const std::vector<std::pair<int, int> >& render_frames) {
[email protected]5c5a88e2011-11-12 00:45:351727 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201728 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351729 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1730 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1731
[email protected]62151052012-02-01 18:40:481732 // Record access to database for potential display in UI.
1733 std::vector<std::pair<int, int> >::const_iterator i;
[email protected]b765deb2013-12-18 06:43:301734 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
[email protected]62151052012-02-01 18:40:481735 BrowserThread::PostTask(
1736 BrowserThread::UI, FROM_HERE,
1737 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1738 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351739 }
1740
1741 return allow;
1742}
1743
1744bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351745 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201746 content::ResourceContext* context,
[email protected]b765deb2013-12-18 06:43:301747 const std::vector<std::pair<int, int> >& render_frames) {
[email protected]5c5a88e2011-11-12 00:45:351748 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201749 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351750 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1751 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1752
[email protected]62151052012-02-01 18:40:481753 // Record access to file system for potential display in UI.
1754 std::vector<std::pair<int, int> >::const_iterator i;
[email protected]b765deb2013-12-18 06:43:301755 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
[email protected]62151052012-02-01 18:40:481756 BrowserThread::PostTask(
1757 BrowserThread::UI, FROM_HERE,
1758 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1759 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351760 }
1761
1762 return allow;
1763}
1764
[email protected]7c5ff9a2012-03-02 07:42:491765bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1766 const GURL& url,
[email protected]96920152013-12-04 21:00:161767 const base::string16& name,
[email protected]7c5ff9a2012-03-02 07:42:491768 content::ResourceContext* context,
[email protected]b765deb2013-12-18 06:43:301769 const std::vector<std::pair<int, int> >& render_frames) {
[email protected]7c5ff9a2012-03-02 07:42:491770 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1771 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1772 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1773 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1774
1775 // Record access to IndexedDB for potential display in UI.
1776 std::vector<std::pair<int, int> >::const_iterator i;
[email protected]b765deb2013-12-18 06:43:301777 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
[email protected]7c5ff9a2012-03-02 07:42:491778 BrowserThread::PostTask(
1779 BrowserThread::UI, FROM_HERE,
1780 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1781 i->first, i->second, url, name, !allow));
1782 }
1783
1784 return allow;
1785}
1786
[email protected]33ad6ce92013-08-27 14:39:081787net::URLRequestContext*
1788ChromeContentBrowserClient::OverrideRequestContextForURL(
1789 const GURL& url, content::ResourceContext* context) {
1790 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1791 if (url.SchemeIs(extensions::kExtensionScheme)) {
1792 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1793 return io_data->extensions_request_context();
1794 }
1795
1796 return NULL;
1797}
1798
[email protected]317f96c92011-05-31 06:53:411799QuotaPermissionContext*
1800ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1801 return new ChromeQuotaPermissionContext();
1802}
1803
[email protected]848dd042011-06-04 18:24:031804void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171805 int render_process_id,
[email protected]1a4e9752013-12-31 20:10:581806 int render_frame_id,
[email protected]4cf611e32012-02-13 16:06:171807 int cert_error,
1808 const net::SSLInfo& ssl_info,
1809 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021810 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031811 bool overridable,
[email protected]d9be47702012-05-16 03:41:221812 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171813 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001814 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021815 if (resource_type != ResourceType::MAIN_FRAME) {
1816 // A sub-resource has a certificate error. The user doesn't really
1817 // have a context for making the right decision, so block the
1818 // request hard, without an info bar to allow showing the insecure
1819 // content.
[email protected]8c965c22013-05-23 19:28:001820 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021821 return;
1822 }
1823
[email protected]f9034cf2011-07-21 12:43:411824 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]1a4e9752013-12-31 20:10:581825 content::RenderFrameHost* render_frame_host =
1826 content::RenderFrameHost::FromID(render_process_id, render_frame_id);
[email protected]1a4e9752013-12-31 20:10:581827 WebContents* tab = WebContents::FromRenderFrameHost(render_frame_host);
[email protected]f9034cf2011-07-21 12:43:411828 if (!tab) {
1829 NOTREACHED();
1830 return;
1831 }
[email protected]09667f02014-01-06 15:37:571832
1833 prerender::PrerenderContents* prerender_contents =
[email protected]294084d2014-01-06 22:22:021834 prerender::PrerenderContents::FromWebContents(tab);
[email protected]09667f02014-01-06 15:37:571835 if (prerender_contents) {
1836 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
1837 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
1838 return;
[email protected]f9034cf2011-07-21 12:43:411839 }
1840
[email protected]1e87df32012-09-12 04:53:191841#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231842 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1843 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1844 if (captive_portal_tab_helper)
1845 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191846#endif
1847
[email protected]f9034cf2011-07-21 12:43:411848 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221849 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1850 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031851}
1852
[email protected]c99c442e2011-08-24 11:37:301853void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451854 int render_process_id,
[email protected]094c8772013-12-21 17:54:501855 int render_frame_id,
[email protected]7a593db2012-02-13 21:19:401856 const net::HttpNetworkSession* network_session,
1857 net::SSLCertRequestInfo* cert_request_info,
1858 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]094c8772013-12-21 17:54:501859 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID(
1860 render_process_id, render_frame_id);
[email protected]294084d2014-01-06 22:22:021861 WebContents* tab = WebContents::FromRenderFrameHost(rfh);
1862 if (!tab) {
[email protected]094c8772013-12-21 17:54:501863 NOTREACHED();
1864 return;
1865 }
1866
[email protected]294084d2014-01-06 22:22:021867 prerender::PrerenderContents* prerender_contents =
1868 prerender::PrerenderContents::FromWebContents(tab);
1869 if (prerender_contents) {
1870 prerender_contents->Destroy(
1871 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
[email protected]8ec26472011-06-06 16:52:451872 return;
1873 }
1874
[email protected]791879c2013-12-17 07:22:411875 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
1876 DCHECK(requesting_url.is_valid())
1877 << "Invalid URL string: https://"
1878 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:451879
[email protected]627e0512011-12-21 22:55:301880 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]5bcdd99d2013-12-23 18:28:301881 scoped_ptr<base::Value> filter(
[email protected]6786bf402011-12-03 15:19:451882 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1883 requesting_url,
1884 requesting_url,
1885 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1886 std::string(), NULL));
1887
1888 if (filter.get()) {
1889 // Try to automatically select a client certificate.
[email protected]5bcdd99d2013-12-23 18:28:301890 if (filter->IsType(base::Value::TYPE_DICTIONARY)) {
1891 base::DictionaryValue* filter_dict =
1892 static_cast<base::DictionaryValue*>(filter.get());
[email protected]6786bf402011-12-03 15:19:451893
1894 const std::vector<scoped_refptr<net::X509Certificate> >&
1895 all_client_certs = cert_request_info->client_certs;
1896 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091897 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451898 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091899 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451900 return;
1901 }
1902 }
1903 } else {
1904 NOTREACHED();
1905 }
1906 }
1907
[email protected]11feec322012-09-18 03:58:521908 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1909 if (!ssl_tab_helper) {
1910 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451911 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141912 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401913 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451914 return;
1915 }
[email protected]11feec322012-09-18 03:58:521916 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401917 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451918}
1919
[email protected]3b455502012-12-11 18:22:581920void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451921 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581922 net::CertificateMimeType cert_type,
1923 const void* cert_data,
1924 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451925 int render_process_id,
1926 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581927 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1928 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451929}
1930
[email protected]dc73a7b2012-03-25 15:27:181931content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561932 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181933}
1934
[email protected]941623e2011-06-07 23:06:041935void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1936 const GURL& source_origin,
1937 int callback_context,
1938 int render_process_id,
1939 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111940#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021941 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1942 WebContents* contents =
1943 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1944 if (!contents) {
[email protected]941623e2011-06-07 23:06:041945 NOTREACHED();
1946 return;
1947 }
1948
[email protected]d0d9c3ee2012-06-19 03:07:021949 // Skip showing the infobar if the request comes from an extension, and that
1950 // extension has the 'notify' permission. (If the extension does not have the
1951 // permission, the user will still be prompted.)
1952 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]38427a12013-11-09 17:34:201953 InfoMap* extension_info_map =
[email protected]c7cd5942013-04-30 03:31:011954 extensions::ExtensionSystem::Get(profile)->info_map();
1955 DesktopNotificationService* notification_service =
1956 DesktopNotificationServiceFactory::GetForProfile(profile);
1957 const Extension* extension = NULL;
1958 if (extension_info_map) {
[email protected]289c44b2013-12-17 03:26:571959 extensions::ExtensionSet extensions;
[email protected]c7cd5942013-04-30 03:31:011960 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1961 source_origin, render_process_id,
1962 extensions::APIPermission::kNotification, &extensions);
[email protected]289c44b2013-12-17 03:26:571963 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
[email protected]c7cd5942013-04-30 03:31:011964 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381965 if (notification_service->IsNotifierEnabled(NotifierId(
1966 NotifierId::APPLICATION, (*iter)->id()))) {
[email protected]cadac622013-06-11 16:46:361967 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011968 break;
1969 }
1970 }
1971 }
[email protected]eb4832a2012-12-08 01:57:521972 RenderViewHost* rvh =
1973 RenderViewHost::FromID(render_process_id, render_view_id);
1974 if (IsExtensionWithPermissionOrSuggestInConsole(
1975 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021976 if (rvh)
1977 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1978 return;
1979 }
1980
[email protected]c7cd5942013-04-30 03:31:011981 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021982 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111983#else
1984 NOTIMPLEMENTED();
1985#endif
[email protected]941623e2011-06-07 23:06:041986}
1987
[email protected]a1221aea2013-11-07 01:31:301988blink::WebNotificationPresenter::Permission
[email protected]941623e2011-06-07 23:06:041989 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021990 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201991 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021992 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111993#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041994 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]5c129792013-07-10 02:08:481995
[email protected]df02aca2012-02-09 21:03:201996 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9afacd22013-11-13 20:23:311997 InfoMap* extension_info_map = io_data->GetExtensionInfoMap();
[email protected]941623e2011-06-07 23:06:041998
[email protected]9afacd22013-11-13 20:23:311999 // We want to see if there is an extension that hasn't been manually disabled
2000 // that has the notifications permission and applies to this security origin.
2001 // First, get the list of extensions with permission for the origin.
[email protected]289c44b2013-12-17 03:26:572002 extensions::ExtensionSet extensions;
[email protected]9afacd22013-11-13 20:23:312003 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
2004 source_origin, render_process_id,
2005 extensions::APIPermission::kNotification, &extensions);
[email protected]289c44b2013-12-17 03:26:572006 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
[email protected]9afacd22013-11-13 20:23:312007 iter != extensions.end(); ++iter) {
2008 // Then, check to see if it's been disabled by the user.
2009 if (!extension_info_map->AreNotificationsDisabled((*iter)->id()))
2010 return blink::WebNotificationPresenter::PermissionAllowed;
[email protected]c7cd5942013-04-30 03:31:012011 }
2012
[email protected]9afacd22013-11-13 20:23:312013 // No enabled extensions exist, so check the normal host content settings.
2014 HostContentSettingsMap* host_content_settings_map =
2015 io_data->GetHostContentSettingsMap();
2016 ContentSetting setting = host_content_settings_map->GetContentSetting(
2017 source_origin,
2018 source_origin,
2019 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
2020 NO_RESOURCE_IDENTIFIER);
2021
2022 if (setting == CONTENT_SETTING_ALLOW)
2023 return blink::WebNotificationPresenter::PermissionAllowed;
2024 if (setting == CONTENT_SETTING_BLOCK)
2025 return blink::WebNotificationPresenter::PermissionDenied;
[email protected]a1221aea2013-11-07 01:31:302026 return blink::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:112027#else
[email protected]a1221aea2013-11-07 01:31:302028 return blink::WebNotificationPresenter::PermissionAllowed;
[email protected]5fd2e842012-03-01 00:29:112029#endif
[email protected]941623e2011-06-07 23:06:042030}
2031
2032void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:172033 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:042034 int render_process_id,
2035 int render_view_id,
2036 bool worker) {
[email protected]5fd2e842012-03-01 00:29:112037#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:042038 RenderViewHost* rvh = RenderViewHost::FromID(
2039 render_process_id, render_view_id);
2040 if (!rvh) {
2041 NOTREACHED();
2042 return;
2043 }
2044
[email protected]9f76c1e2012-03-05 15:15:582045 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:302046 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:042047 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:372048 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042049 service->ShowDesktopNotification(
2050 params, render_process_id, render_view_id,
2051 worker ? DesktopNotificationService::WorkerNotification :
2052 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:112053#else
2054 NOTIMPLEMENTED();
2055#endif
[email protected]941623e2011-06-07 23:06:042056}
2057
2058void ChromeContentBrowserClient::CancelDesktopNotification(
2059 int render_process_id,
2060 int render_view_id,
2061 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:112062#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:042063 RenderViewHost* rvh = RenderViewHost::FromID(
2064 render_process_id, render_view_id);
2065 if (!rvh) {
2066 NOTREACHED();
2067 return;
2068 }
2069
[email protected]9f76c1e2012-03-05 15:15:582070 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:302071 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:042072 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:372073 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042074 service->CancelDesktopNotification(
2075 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:112076#else
2077 NOTIMPLEMENTED();
2078#endif
[email protected]941623e2011-06-07 23:06:042079}
2080
[email protected]9f3fba52011-06-08 20:37:192081bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:352082 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:572083 const GURL& opener_top_level_frame_url,
[email protected]34eec7ffe32011-11-02 23:49:022084 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:192085 WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:232086 const GURL& target_url,
2087 const content::Referrer& referrer,
2088 WindowOpenDisposition disposition,
2089 const WebWindowFeatures& features,
2090 bool user_gesture,
2091 bool opener_suppressed,
[email protected]df02aca2012-02-09 21:03:202092 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:012093 int render_process_id,
[email protected]190e5e22013-07-27 05:59:232094 bool is_guest,
2095 int opener_id,
[email protected]03b6d552012-03-29 04:03:012096 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:192097 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:012098
2099 *no_javascript_access = false;
2100
[email protected]5e5f55e262c52013-09-12 00:27:192101 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]38427a12013-11-09 17:34:202102 InfoMap* map = io_data->GetExtensionInfoMap();
[email protected]5e5f55e262c52013-09-12 00:27:192103
[email protected]9f3fba52011-06-08 20:37:192104 // If the opener is trying to create a background window but doesn't have
2105 // the appropriate permission, fail the attempt.
[email protected]6940eef82013-09-11 11:58:412106 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]03b6d552012-03-29 04:03:012107 if (!map->SecurityOriginHasAPIPermission(
2108 source_origin,
2109 render_process_id,
[email protected]c2e66e12012-06-27 06:27:062110 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:012111 return false;
2112 }
2113
[email protected]7b54ca02012-03-02 18:06:532114 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2115 // return a recently installed Extension even if this CanCreateWindow call
2116 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:012117 // because the permission check above would have caused an early return
2118 // already. We must use the full URL to find hosted apps, though, and not
2119 // just the origin.
[email protected]be9915fb2013-07-18 09:28:552120 const Extension* extension =
2121 map->extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:292122 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:012123 *no_javascript_access = true;
[email protected]190e5e22013-07-27 05:59:232124
2125 return true;
[email protected]9f3fba52011-06-08 20:37:192126 }
[email protected]056efdc2013-04-06 00:14:532127
2128 // No new browser window (popup or tab) in app mode.
2129 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
2130 chrome::IsRunningInForcedAppMode()) {
2131 return false;
2132 }
2133
[email protected]190e5e22013-07-27 05:59:232134 if (is_guest)
2135 return true;
2136
[email protected]190e5e22013-07-27 05:59:232137 HostContentSettingsMap* content_settings =
2138 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap();
[email protected]916615b2013-09-11 18:19:442139 BlockedWindowParams blocked_params(target_url,
2140 referrer,
2141 disposition,
2142 features,
2143 user_gesture,
2144 opener_suppressed,
2145 render_process_id,
2146 opener_id);
[email protected]190e5e22013-07-27 05:59:232147
[email protected]7f53dff2013-08-05 10:45:502148 if (!user_gesture && !CommandLine::ForCurrentProcess()->HasSwitch(
2149 switches::kDisablePopupBlocking)) {
[email protected]931bc922013-09-11 21:42:572150 if (content_settings->GetContentSetting(opener_top_level_frame_url,
2151 opener_top_level_frame_url,
[email protected]190e5e22013-07-27 05:59:232152 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]916615b2013-09-11 18:19:442153 std::string()) !=
[email protected]190e5e22013-07-27 05:59:232154 CONTENT_SETTING_ALLOW) {
[email protected]916615b2013-09-11 18:19:442155 BrowserThread::PostTask(BrowserThread::UI,
2156 FROM_HERE,
2157 base::Bind(&HandleBlockedPopupOnUIThread,
2158 blocked_params));
2159 return false;
[email protected]190e5e22013-07-27 05:59:232160 }
[email protected]916615b2013-09-11 18:19:442161 }
[email protected]190e5e22013-07-27 05:59:232162
[email protected]916615b2013-09-11 18:19:442163#if defined(OS_ANDROID)
2164 if (SingleTabModeTabHelper::IsRegistered(render_process_id, opener_id)) {
[email protected]190e5e22013-07-27 05:59:232165 BrowserThread::PostTask(BrowserThread::UI,
2166 FROM_HERE,
[email protected]916615b2013-09-11 18:19:442167 base::Bind(&HandleSingleTabModeBlockOnUIThread,
2168 blocked_params));
[email protected]190e5e22013-07-27 05:59:232169 return false;
2170 }
[email protected]916615b2013-09-11 18:19:442171#endif
[email protected]190e5e22013-07-27 05:59:232172
[email protected]9f3fba52011-06-08 20:37:192173 return true;
2174}
2175
2176std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:202177 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:192178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2179 // Check if it's an extension-created worker, in which case we want to use
2180 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:202181 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:192182 const Extension* extension =
2183 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
2184 return extension ? extension->name() : std::string();
2185}
2186
[email protected]99907362012-01-11 05:41:402187void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2188 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:172189}
2190
[email protected]7a06d282013-05-03 04:39:332191// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:022192content::SpeechRecognitionManagerDelegate*
2193 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002194#if defined(ENABLE_INPUT_SPEECH)
2195 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
[email protected]a03f2d32012-03-14 00:26:322196#else
[email protected]855e18b2013-07-08 21:02:002197 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
2198 // need the base delegate without the bubble UI.
2199 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:322200#endif
[email protected]66cfec62012-02-24 17:57:512201}
2202
[email protected]ae6e9912011-07-27 01:18:282203net::NetLog* ChromeContentBrowserClient::GetNetLog() {
2204 return g_browser_process->net_log();
2205}
2206
[email protected]32538d92011-08-25 00:09:232207AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
2208 return new ChromeAccessTokenStore();
2209}
2210
[email protected]dbae6b02011-06-29 23:51:412211bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:012212 return true;
[email protected]dbae6b02011-06-29 23:51:412213}
2214
[email protected]64d69de42012-02-06 00:19:542215void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:322216 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:062217 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582218 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:062219 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062220
[email protected]33b79542013-10-18 11:18:452221 // Fill per-script font preferences. These are not registered on Android
2222 // - http://crbug.com/308033.
2223#if !defined(OS_ANDROID)
[email protected]f3986f82012-01-03 20:00:062224 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542225 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:062226 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542227 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:062228 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542229 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062230 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542231 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062232 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542233 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:062234 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542235 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:032236 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
2237 &web_prefs->pictograph_font_family_map);
[email protected]33b79542013-10-18 11:18:452238#endif
[email protected]f3986f82012-01-03 20:00:062239
[email protected]64d69de42012-02-06 00:19:542240 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:402241 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:542242 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:402243 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:542244 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:402245 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:542246 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:402247 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:062248
[email protected]ddf72142012-05-22 04:52:402249 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062250
[email protected]64d69de42012-02-06 00:19:542251 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:402252 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:542253 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:062254 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:542255 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:062256 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
[email protected]5bcdd99d2013-12-23 18:28:302257 const base::DictionaryValue* inspector_settings =
[email protected]f3986f82012-01-03 20:00:062258 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2259 if (inspector_settings) {
[email protected]5bcdd99d2013-12-23 18:28:302260 for (base::DictionaryValue::Iterator iter(*inspector_settings);
2261 !iter.IsAtEnd();
[email protected]c40ef1c2013-02-25 18:42:182262 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062263 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182264 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542265 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182266 std::make_pair(iter.key(), value));
2267 }
[email protected]f3986f82012-01-03 20:00:062268 }
2269 }
[email protected]64d69de42012-02-06 00:19:542270 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062271
[email protected]ddf72142012-05-22 04:52:402272 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542273 web_prefs->javascript_enabled = false;
2274 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2275 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402276 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542277 web_prefs->plugins_enabled = false;
2278 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2279 web_prefs->java_enabled = false;
2280 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402281 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062282
[email protected]64d69de42012-02-06 00:19:542283 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2284 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062285
[email protected]64d69de42012-02-06 00:19:542286 web_prefs->memory_info_enabled =
2287 prefs->GetBoolean(prefs::kEnableMemoryInfo);
2288 web_prefs->allow_displaying_insecure_content =
2289 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2290 web_prefs->allow_running_insecure_content =
2291 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322292#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:052293 web_prefs->font_scale_factor =
2294 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2295 web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment();
[email protected]d3b935f2012-10-19 23:14:322296 web_prefs->force_enable_zoom =
2297 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
2298#endif
[email protected]5c915252013-05-07 13:15:392299
[email protected]af4256d52013-06-04 20:39:072300#if defined(OS_ANDROID)
2301 web_prefs->password_echo_enabled =
2302 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2303#else
[email protected]9d06d88d2012-02-23 22:37:082304 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072305#endif
2306
[email protected]cfadadd2013-04-03 04:43:022307 web_prefs->asynchronous_spell_checking_enabled = true;
2308 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572309
[email protected]64d69de42012-02-06 00:19:542310 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062311 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542312 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062313 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542314 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062315 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2316
2317 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542318 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062319 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542320 web_prefs->default_encoding);
2321 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402322 prefs->ClearPref(prefs::kDefaultCharset);
2323 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062324 }
[email protected]64d69de42012-02-06 00:19:542325 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062326
[email protected]299d7f12012-05-23 05:31:152327 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232328 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132329 ExtensionService* service =
2330 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062331 if (service) {
[email protected]1e6e2ea2014-01-04 02:01:402332 const GURL& site_url = rvh->GetSiteInstance()->GetSiteURL();
2333 const Extension* extension =
2334 service->extensions()->GetByID(site_url.host());
[email protected]1bc28312012-11-08 08:31:532335 // Ensure that we are only granting extension preferences to URLs with
2336 // the correct scheme. Without this check, chrome-guest:// schemes used by
2337 // webview tags as well as hosts that happen to match the id of an
2338 // installed extension would get the wrong preferences.
[email protected]1e6e2ea2014-01-04 02:01:402339 if (site_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532340 extension_webkit_preferences::SetPreferences(
2341 extension, view_type, web_prefs);
2342 }
[email protected]f3986f82012-01-03 20:00:062343 }
2344
[email protected]cb2edf22013-04-01 20:25:232345 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542346 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232347 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062348 // Disable all kinds of acceleration for background pages.
2349 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542350 web_prefs->force_compositing_mode = false;
2351 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062352 }
[email protected]2e21fe292012-03-02 22:52:322353
[email protected]ff9300872014-01-22 11:09:322354#if defined(OS_CHROMEOS)
[email protected]2e21fe292012-03-02 22:52:322355 // Override the default of suppressing HW compositing for WebUI pages for the
2356 // file manager, which is implemented using WebUI but wants HW acceleration
2357 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532358 if (url.SchemeIs(extensions::kExtensionScheme) &&
[email protected]2de96a52013-08-14 01:18:092359 url.host() == file_manager::kFileManagerAppId) {
[email protected]2e21fe292012-03-02 22:52:322360 web_prefs->accelerated_compositing_enabled = true;
2361 web_prefs->accelerated_2d_canvas_enabled = true;
2362 }
2363#endif
[email protected]181a95ee2011-07-12 19:26:362364}
2365
2366void ChromeContentBrowserClient::UpdateInspectorSetting(
2367 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062368 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582369 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062370 DictionaryPrefUpdate update(
2371 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2372 prefs::kWebKitInspectorSettings);
[email protected]5bcdd99d2013-12-23 18:28:302373 base::DictionaryValue* inspector_settings = update.Get();
2374 inspector_settings->SetWithoutPathExpansion(
2375 key, base::Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362376}
2377
[email protected]b8148ac2011-07-13 22:03:252378void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2379 BrowserURLHandler* handler) {
2380 // Add the default URL handlers.
2381 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2382 BrowserURLHandler::null_handler());
2383 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2384 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2385
[email protected]b3adbd02011-11-30 22:23:272386 // about: handler. Must come before chrome: handler, since it will
2387 // rewrite about: urls to chrome: URLs and then expect chrome: to
2388 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252389 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2390 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:032391
2392 // Handler to rewrite chrome://newtab for InstantExtended.
2393 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2394 &chrome::HandleNewTabURLReverseRewrite);
2395
[email protected]b8148ac2011-07-13 22:03:252396 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242397 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252398}
2399
2400void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372401 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582402 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472403 BrowsingDataRemover* remover =
2404 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552405 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2406 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252407 // BrowsingDataRemover takes care of deleting itself when done.
2408}
2409
2410void ChromeContentBrowserClient::ClearCookies(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]dceaa912011-09-06 17:17:232415 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552416 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252417 // BrowsingDataRemover takes care of deleting itself when done.
2418}
2419
[email protected]650b2d52013-02-10 03:41:452420base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:492421 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:322422}
2423
[email protected]c9b6eb62011-10-18 20:49:392424std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2425 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2426}
2427
[email protected]b7631cc2012-09-15 05:08:382428void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2429 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542430#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382431 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2432 scoped_ptr<ppapi::host::HostFactory>(
2433 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542434#endif
[email protected]b7631cc2012-09-15 05:08:382435}
2436
[email protected]0c7193742012-11-07 19:05:032437content::BrowserPpapiHost*
2438 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2439 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132440 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032441 while (!iter.Done()) {
[email protected]7c766e92013-11-22 20:44:022442 nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>(
2443 iter.GetDelegate());
[email protected]0c7193742012-11-07 19:05:032444 if (host->process() &&
2445 host->process()->GetData().id == plugin_process_id) {
2446 // Found the plugin.
2447 return host->browser_ppapi_host();
2448 }
2449 ++iter;
2450 }
2451 return NULL;
2452}
2453
[email protected]7b38b192013-03-23 18:39:312454bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2455 content::BrowserContext* browser_context, const GURL& site_url) {
2456 if (CommandLine::ForCurrentProcess()->HasSwitch(
2457 switches::kEnableBrowserPluginForAllViewTypes))
2458 return true;
2459
[email protected]22aa4f82013-09-24 17:01:442460 if (content::HasWebUIScheme(site_url))
2461 return true;
2462
[email protected]7b38b192013-03-23 18:39:312463 Profile* profile = Profile::FromBrowserContext(browser_context);
2464 ExtensionService* service =
2465 extensions::ExtensionSystem::Get(profile)->extension_service();
2466 if (!service)
2467 return false;
2468
[email protected]be9915fb2013-07-18 09:28:552469 const Extension* extension =
2470 service->extensions()->GetExtensionOrAppByURL(site_url);
[email protected]7b38b192013-03-23 18:39:312471 if (!extension)
2472 return false;
2473
[email protected]c2d2f102013-04-29 16:42:582474 return extension->HasAPIPermission(APIPermission::kWebView) ||
2475 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312476}
2477
[email protected]38cd8f7f2012-06-15 22:06:072478bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582479 content::BrowserContext* browser_context,
2480 const GURL& url,
[email protected]dda54822013-06-15 01:26:392481 bool private_api,
[email protected]8b92ed182013-09-21 04:47:122482 const content::SocketPermissionRequest* params) {
[email protected]93f72062013-05-29 20:29:402483#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372484 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]289c44b2013-12-17 03:26:572485 const extensions::ExtensionSet* extension_set = NULL;
[email protected]9d450492013-06-13 23:08:372486 if (profile) {
2487 extension_set = extensions::ExtensionSystem::Get(profile)->
2488 extension_service()->extensions();
2489 }
[email protected]dda54822013-06-15 01:26:392490
2491 if (private_api) {
2492 // Access to private socket APIs is controlled by the whitelist.
2493 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2494 allowed_socket_origins_)) {
2495 return true;
2496 }
2497 } else {
2498 // Access to public socket APIs is controlled by extension permissions.
2499 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2500 extension_set) {
2501 const Extension* extension = extension_set->GetByID(url.host());
2502 if (extension) {
[email protected]8b92ed182013-09-21 04:47:122503 if (params) {
2504 extensions::SocketPermission::CheckParam check_params(
2505 params->type, params->host, params->port);
2506 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2507 extension, extensions::APIPermission::kSocket,
2508 &check_params)) {
2509 return true;
2510 }
2511 } else {
2512 if (extensions::PermissionsData::HasAPIPermission(
2513 extension, extensions::APIPermission::kSocket)) {
2514 return true;
2515 }
[email protected]dda54822013-06-15 01:26:392516 }
2517 }
2518 }
2519 }
2520
2521 // Allow both public and private APIs if the command line says so.
2522 return IsHostAllowedByCommandLine(url, extension_set,
2523 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402524#else
[email protected]a658d452012-03-02 12:45:292525 return false;
[email protected]93f72062013-05-29 20:29:402526#endif
[email protected]e461da2f2012-02-16 19:06:402527}
2528
[email protected]a28e3302013-02-03 03:50:432529ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2530 WebContents* web_contents) {
2531 return new ChromeSelectFilePolicy(web_contents);
2532}
2533
[email protected]7d9424702013-04-14 13:14:162534void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2535 std::vector<std::string>* additional_allowed_schemes) {
2536 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2537 additional_allowed_schemes);
[email protected]98fa9dc2013-12-09 16:31:412538 additional_allowed_schemes->push_back(kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:292539 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]7d9424702013-04-14 13:14:162540 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2541}
2542
[email protected]f19bbf62013-07-09 01:22:322543void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:312544 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:532545 const base::FilePath& storage_partition_path,
[email protected]f19bbf62013-07-09 01:22:322546 ScopedVector<fileapi::FileSystemBackend>* additional_backends) {
[email protected]02250952013-04-24 23:52:532547#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032548 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]f19bbf62013-07-09 01:22:322549 additional_backends->push_back(new MediaFileSystemBackend(
[email protected]30a306f42013-06-10 03:09:032550 storage_partition_path,
2551 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]f19bbf62013-07-09 01:22:322552 MediaFileSystemBackend::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532553#endif
[email protected]b40015c2013-06-26 08:13:312554#if defined(OS_CHROMEOS)
[email protected]0ff5eb52013-07-10 20:35:312555 fileapi::ExternalMountPoints* external_mount_points =
2556 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:312557 DCHECK(external_mount_points);
[email protected]f19bbf62013-07-09 01:22:322558 chromeos::FileSystemBackend* backend =
2559 new chromeos::FileSystemBackend(
[email protected]6b154b3c2014-02-05 08:27:292560 new drive::FileSystemBackendDelegate,
[email protected]0ff5eb52013-07-10 20:35:312561 browser_context->GetSpecialStoragePolicy(),
[email protected]b40015c2013-06-26 08:13:312562 external_mount_points,
2563 fileapi::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:322564 backend->AddSystemMountPoints();
2565 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal));
2566 additional_backends->push_back(backend);
[email protected]b40015c2013-06-26 08:13:312567#endif
[email protected]445b7db2013-08-02 04:58:272568
[email protected]e86e2be2013-08-30 11:20:392569 additional_backends->push_back(
2570 new sync_file_system::SyncFileSystemBackend(
2571 Profile::FromBrowserContext(browser_context)));
[email protected]eab6105d2014-01-17 20:55:102572
2573 if (CommandLine::ForCurrentProcess()->HasSwitch(
2574 switches::kEnablePrivetStorage)) {
2575 additional_backends->push_back(
2576 new local_discovery::PrivetFileSystemBackend(
2577 fileapi::ExternalMountPoints::GetSystemInstance()));
2578 }
[email protected]02250952013-04-24 23:52:532579}
2580
[email protected]e60c0232011-11-11 19:56:352581#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182582void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2583 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382584 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082585 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392586#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452587 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392588 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2589 DCHECK(!data_path.empty());
2590
2591 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452592 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392593 data_path.AppendASCII("chrome_100_percent.pak");
[email protected]5db2b7492013-08-23 05:33:092594 base::PlatformFile f =
2595 base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
[email protected]29699c22012-10-03 23:57:392596 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372597 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392598 FileDescriptor(f, true)));
2599
2600 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452601 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392602 GetLocaleFilePath(locale, false);
2603 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2604 DCHECK(f != base::kInvalidPlatformFileValue);
2605 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2606 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382607
[email protected]650b2d52013-02-10 03:41:452608 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372609 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2610 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2611 DCHECK(f != base::kInvalidPlatformFileValue);
2612 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2613 FileDescriptor(f, true)));
2614
[email protected]0b818f72013-10-22 00:11:032615 if (breakpad::IsCrashReporterEnabled()) {
2616 f = breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2617 child_process_id);
[email protected]82174aa2013-01-22 21:53:432618 if (f == base::kInvalidPlatformFileValue) {
2619 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2620 "be disabled for this process.";
2621 } else {
2622 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2623 FileDescriptor(f, true)));
2624 }
[email protected]40da3e0c2012-10-24 22:03:382625 }
[email protected]40da3e0c2012-10-24 22:03:382626
2627#else
2628 int crash_signal_fd = GetCrashSignalFD(command_line);
2629 if (crash_signal_fd >= 0) {
2630 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2631 FileDescriptor(crash_signal_fd,
2632 false)));
2633 }
[email protected]29699c22012-10-03 23:57:392634#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302635}
[email protected]e60c0232011-11-11 19:56:352636#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302637
[email protected]4a65826d2011-08-25 16:04:012638#if defined(OS_WIN)
2639const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2640 return chrome::kBrowserResourcesDll;
2641}
[email protected]34f48682013-03-20 00:30:182642
2643void ChromeContentBrowserClient::PreSpawnRenderer(
2644 sandbox::TargetPolicy* policy,
2645 bool* success) {
2646 // This code is duplicated in nacl_exe_win_64.cc.
2647 // Allow the server side of a pipe restricted to the "chrome.nacl."
2648 // namespace so that it cannot impersonate other system or other chrome
2649 // service pipes.
2650 sandbox::ResultCode result = policy->AddRule(
2651 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2652 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2653 L"\\\\.\\pipe\\chrome.nacl.*");
2654 if (result != sandbox::SBOX_ALL_OK) {
2655 *success = false;
2656 return;
2657 }
2658
2659 // Renderers need to send named pipe handles and shared memory
2660 // segment handles to NaCl loader processes.
2661 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2662 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2663 L"File");
2664 if (result != sandbox::SBOX_ALL_OK) {
2665 *success = false;
2666 return;
2667 }
2668}
[email protected]4a65826d2011-08-25 16:04:012669#endif
2670
[email protected]a6868c22013-10-09 02:50:292671bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2672 content::BrowserContext* browser_context,
2673 const GURL& url) {
2674#if defined(ENABLE_PLUGINS)
2675 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]289c44b2013-12-17 03:26:572676 const extensions::ExtensionSet* extension_set = NULL;
[email protected]a6868c22013-10-09 02:50:292677 if (profile) {
2678 extension_set = extensions::ExtensionSystem::Get(profile)->
2679 extension_service()->extensions();
2680 }
2681 // TODO(teravest): Populate allowed_file_handle_origins_ when FileIO is moved
2682 // from the renderer to the browser.
2683 return IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2684 allowed_file_handle_origins_) ||
2685 IsHostAllowedByCommandLine(url, extension_set,
2686 switches::kAllowNaClFileHandleAPI);
2687#else
2688 return false;
2689#endif
2690}
2691
[email protected]8ddc6b7c2013-12-12 20:42:062692bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs() {
2693#if defined(ENABLE_PLUGINS)
2694 // Allow access for tests.
2695 if (CommandLine::ForCurrentProcess()->HasSwitch(
2696 switches::kEnablePepperTesting)) {
2697 return true;
2698 }
2699
2700 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
[email protected]5abe3e72013-12-19 18:58:542701 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown"
2702 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on
2703 // Chromium builds as well.
[email protected]8ddc6b7c2013-12-12 20:42:062704 return channel <= chrome::VersionInfo::CHANNEL_DEV;
2705#else
2706 return false;
2707#endif
2708}
2709
2710
[email protected]d977f9c2011-03-14 16:10:262711} // namespace chrome