blob: 870b8775dbaad56541f63596f52d0585a2eeb355 [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
[email protected]7c3228a2011-11-11 21:35:227#include <set>
[email protected]1033acd2012-02-08 08:46:278#include <utility>
[email protected]7c3228a2011-11-11 21:35:229#include <vector>
10
[email protected]317c58f02011-11-09 02:15:0311#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3012#include "base/command_line.h"
[email protected]eabbfb12013-04-05 23:28:3513#include "base/lazy_instance.h"
[email protected]29699c22012-10-03 23:57:3914#include "base/path_service.h"
[email protected]3853a4c2013-02-11 17:15:5715#include "base/prefs/pref_service.h"
[email protected]9eec53fe2013-10-30 20:21:1716#include "base/prefs/scoped_user_pref_update.h"
[email protected]e7463412013-06-10 22:53:4617#include "base/strings/string_number_conversions.h"
[email protected]135cb802013-06-09 16:44:2018#include "base/strings/utf_string_conversions.h"
[email protected]30a306f42013-06-10 03:09:0319#include "base/threading/sequenced_worker_pool.h"
[email protected]056efdc2013-04-06 00:14:5320#include "chrome/browser/app_mode/app_mode_utils.h"
[email protected]b8148ac2011-07-13 22:03:2521#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3022#include "chrome/browser/browser_process.h"
[email protected]5c129792013-07-10 02:08:4823#include "chrome/browser/browser_shutdown.h"
[email protected]b0cb5e82012-07-19 19:22:4724#include "chrome/browser/browsing_data/browsing_data_helper.h"
25#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1226#include "chrome/browser/character_encoding.h"
[email protected]43535512013-02-20 20:41:4127#include "chrome/browser/chrome_net_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4128#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5629#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0530#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4531#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3232#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0833#include "chrome/browser/defaults.h"
[email protected]b1d97272013-08-17 13:38:4934#include "chrome/browser/download/download_prefs.h"
[email protected]2b33dcd02012-03-18 01:34:1635#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]1deace22013-05-22 06:14:4636#include "chrome/browser/extensions/browser_permissions_policy_delegate.h"
[email protected]d977f9c2011-03-14 16:10:2637#include "chrome/browser/extensions/extension_service.h"
[email protected]b8148ac2011-07-13 22:03:2538#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0639#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]eb4832a2012-12-08 01:57:5240#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2341#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1242#include "chrome/browser/google/google_util.h"
[email protected]0533cc6d2013-06-27 22:44:0543#include "chrome/browser/guestview/adview/adview_guest.h"
[email protected]3f24f97c2013-11-17 21:53:3344#include "chrome/browser/guestview/guestview.h"
[email protected]0533cc6d2013-06-27 22:44:0545#include "chrome/browser/guestview/guestview_constants.h"
46#include "chrome/browser/guestview/webview/webview_guest.h"
[email protected]eab6105d2014-01-17 20:55:1047#include "chrome/browser/local_discovery/storage/privet_filesystem_backend.h"
[email protected]1ea4c492014-02-15 19:45:1748#include "chrome/browser/media/cast_transport_host_filter.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]779dd282013-10-19 15:57:0290#include "chrome/common/env_vars.h"
[email protected]395045c2012-05-22 15:04:3891#include "chrome/common/extensions/extension_process_policy.h"
[email protected]561e33d52013-04-03 06:58:4392#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]f1933792011-06-14 00:49:3493#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:3794#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:1295#include "chrome/common/pref_names.h"
[email protected]4de75262013-12-18 23:16:1296#include "chrome/common/profile_management_switches.h"
[email protected]3e69bc82011-05-26 23:22:3897#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0998#include "chrome/common/url_constants.h"
[email protected]264c0acac2013-10-01 13:33:3099#include "chrome/installer/util/google_update_settings.h"
[email protected]e8f3f9982013-05-10 20:59:53100#include "chromeos/chromeos_constants.h"
[email protected]ef42ee82013-11-01 05:26:13101#include "components/nacl/browser/nacl_browser.h"
[email protected]7c766e92013-11-22 20:44:02102#include "components/nacl/browser/nacl_host_message_filter.h"
103#include "components/nacl/browser/nacl_process_host.h"
[email protected]d5d383252013-07-04 14:44:32104#include "components/nacl/common/nacl_process_type.h"
[email protected]1b4ec382014-03-07 02:32:24105#include "components/nacl/common/nacl_switches.h"
[email protected]eba93c92014-01-07 17:34:17106#include "components/translate/core/common/translate_switches.h"
[email protected]75fee372013-03-06 00:42:44107#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43108#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30109#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38110#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03111#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31112#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03113#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59114#include "content/public/browser/child_process_security_policy.h"
[email protected]094c8772013-12-21 17:54:50115#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30116#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33117#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05118#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33119#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19120#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10121#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43122#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18123#include "content/public/common/content_descriptors.h"
[email protected]22aa4f82013-09-24 17:01:44124#include "content/public/common/url_utils.h"
[email protected]22401dc2014-03-21 01:38:57125#include "extensions/browser/extension_host.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]91add6a2014-03-21 11:48:22140#include "extensions/common/permissions/socket_permission.h"
[email protected]49d9b142013-07-19 08:50:27141#include "extensions/common/switches.h"
[email protected]c9b6eb62011-10-18 20:49:39142#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23143#include "grit/ui_resources.h"
[email protected]3b455502012-12-11 18:22:58144#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34145#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06146#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57147#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38148#include "ppapi/host/ppapi_host.h"
[email protected]8ddc6b7c2013-12-12 20:42:06149#include "ppapi/shared_impl/ppapi_switches.h"
[email protected]c9b6eb62011-10-18 20:49:39150#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08151#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24152#include "ui/message_center/message_center_util.h"
[email protected]b40015c2013-06-26 08:13:31153#include "webkit/browser/fileapi/external_mount_points.h"
[email protected]fab55e72013-05-31 07:06:18154#include "webkit/common/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:26155
[email protected]b48c9182011-10-26 18:03:30156#if defined(OS_WIN)
[email protected]7fe75ce2014-01-28 02:12:24157#include "base/win/windows_version.h"
[email protected]199fc7a2011-09-28 22:45:38158#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18159#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38160#elif defined(OS_MACOSX)
161#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56162#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]0b818f72013-10-22 00:11:03163#include "components/breakpad/app/breakpad_mac.h"
[email protected]b48c9182011-10-26 18:03:30164#elif defined(OS_CHROMEOS)
165#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]07fe2752014-01-29 11:21:55166#include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h"
[email protected]f19bbf62013-07-09 01:22:32167#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]5c915252013-05-07 13:15:39168#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49169#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]c94ac692013-07-27 00:50:10170#include "chrome/browser/chromeos/system/input_device_settings.h"
[email protected]931d1042013-04-05 17:50:44171#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26172#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30173#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09174#elif defined(OS_ANDROID)
[email protected]916615b2013-09-11 18:19:44175#include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
[email protected]81054f812012-08-30 00:47:09176#include "chrome/browser/chrome_browser_main_android.h"
[email protected]2b12c322013-09-19 06:53:56177#include "chrome/browser/media/encrypted_media_message_filter_android.h"
[email protected]29699c22012-10-03 23:57:39178#include "chrome/common/descriptors_android.h"
[email protected]0b818f72013-10-22 00:11:03179#include "components/breakpad/browser/crash_dump_manager_android.h"
[email protected]b48c9182011-10-26 18:03:30180#elif defined(OS_POSIX)
181#include "chrome/browser/chrome_browser_main_posix.h"
182#endif
183
[email protected]a220b5932013-09-21 03:47:44184#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]779dd282013-10-19 15:57:02185#include "base/debug/leak_annotations.h"
[email protected]b80f68432011-05-02 17:22:30186#include "base/linux_util.h"
[email protected]0b818f72013-10-22 00:11:03187#include "components/breakpad/app/breakpad_linux.h"
188#include "components/breakpad/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43189#endif
[email protected]b80f68432011-05-02 17:22:30190
[email protected]1e87df32012-09-12 04:53:19191#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
192#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
193#endif
194
[email protected]29699c22012-10-03 23:57:39195#if defined(OS_ANDROID)
196#include "ui/base/ui_base_paths.h"
[email protected]b255a8e0e82013-10-22 04:03:59197#include "ui/gfx/android/device_display_info.h"
[email protected]29699c22012-10-03 23:57:39198#endif
199
[email protected]d5bcd06f2013-04-21 08:07:24200#if !defined(OS_CHROMEOS)
201#include "chrome/browser/signin/signin_manager.h"
202#include "chrome/browser/signin/signin_manager_factory.h"
203#endif
204
[email protected]02250952013-04-24 23:52:53205#if !defined(OS_ANDROID)
[email protected]f19bbf62013-07-09 01:22:32206#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
[email protected]02250952013-04-24 23:52:53207#endif
208
[email protected]6ef98b5a2013-05-31 23:58:31209#if defined(ENABLE_WEBRTC)
210#include "chrome/browser/media/webrtc_logging_handler_host.h"
211#endif
212
[email protected]855e18b2013-07-08 21:02:00213#if defined(ENABLE_INPUT_SPEECH)
214#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h"
215#endif
216
[email protected]ff9300872014-01-22 11:09:32217#if defined(OS_CHROMEOS)
[email protected]473c9a4f2013-09-05 03:09:46218#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]02a3dc122013-06-13 15:07:53219#endif
220
[email protected]e8b6ca02013-07-10 18:00:51221#if defined(TOOLKIT_GTK)
222#include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h"
223#endif
224
225#if defined(TOOLKIT_VIEWS)
226#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
227#endif
228
229#if defined(USE_ASH)
230#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
231#endif
232
233#if defined(USE_AURA)
234#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
235#endif
236
237#if defined(USE_X11)
238#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
239#endif
240
[email protected]c6ce08072013-07-31 07:48:53241#if defined(ENABLE_SPELLCHECK)
242#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
243#endif
244
[email protected]2188c8d2014-03-21 00:58:56245#if defined(ENABLE_SERVICE_DISCOVERY)
[email protected]7e503f92014-02-19 02:35:51246#include "chrome/browser/local_discovery/storage/privet_filesystem_backend.h"
247#endif
248
[email protected]a1221aea2013-11-07 01:31:30249using blink::WebWindowFeatures;
[email protected]c7abd422012-09-25 00:20:08250using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47251using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03252using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39253using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31254using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59255using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00256using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11257using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33258using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13259using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06260using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34261using extensions::Extension;
[email protected]38427a12013-11-09 17:34:20262using extensions::InfoMap;
[email protected]1d5e58b2013-01-31 08:41:40263using extensions::Manifest;
[email protected]593d2a72013-07-26 08:48:38264using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39265
[email protected]0daaebfe2014-03-15 00:09:05266#if defined(OS_POSIX)
267using content::FileDescriptorInfo;
268#endif
269
[email protected]c5dbef02011-05-13 05:06:09270namespace {
271
[email protected]eabbfb12013-04-05 23:28:35272// Cached version of the locale so we can return the locale on the I/O
273// thread.
274base::LazyInstance<std::string> g_io_thread_application_locale;
275
[email protected]93f72062013-05-29 20:29:40276#if defined(ENABLE_PLUGINS)
[email protected]10c39222013-11-13 20:09:25277const char* kPredefinedAllowedFileHandleOrigins[] = {
278 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
279 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
280};
281
[email protected]e461da2f2012-02-16 19:06:40282const char* kPredefinedAllowedSocketOrigins[] = {
283 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18284 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45285 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
286 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
287 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
288 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35289 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54290 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
291 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
292 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
293 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
294 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
295 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38296 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58297 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29298 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]3f6fca22013-08-12 23:13:42299 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
300 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
301 "4EB74897CB187C7633357C2FE832E0AD6A44883A", // see crbug.com/234789
302 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
303 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
304 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40305};
[email protected]93f72062013-05-29 20:29:40306#endif
[email protected]e461da2f2012-02-16 19:06:40307
[email protected]f8f93eb2012-09-25 03:06:24308// Returns a copy of the given url with its host set to given host and path set
309// to given path. Other parts of the url will be the same.
310GURL ReplaceURLHostAndPath(const GURL& url,
311 const std::string& host,
312 const std::string& path) {
313 url_canon::Replacements<char> replacements;
314 replacements.SetHost(host.c_str(),
315 url_parse::Component(0, host.length()));
316 replacements.SetPath(path.c_str(),
317 url_parse::Component(0, path.length()));
318 return url.ReplaceComponents(replacements);
319}
320
321// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
322GURL AddUberHost(const GURL& url) {
323 const std::string uber_host = chrome::kChromeUIUberHost;
324 const std::string new_path = url.host() + url.path();
325
326 return ReplaceURLHostAndPath(url, uber_host, new_path);
327}
328
[email protected]045bf7c2012-09-28 20:27:36329// If url->host() is "chrome" and url->path() has characters other than the
330// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
331// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24332bool RemoveUberHost(GURL* url) {
333 if (url->host() != chrome::kChromeUIUberHost)
334 return false;
335
[email protected]045bf7c2012-09-28 20:27:36336 if (url->path().empty() || url->path() == "/")
337 return false;
338
[email protected]f8f93eb2012-09-25 03:06:24339 const std::string old_path = url->path();
340
341 const std::string::size_type separator = old_path.find('/', 1);
342 std::string new_host;
343 std::string new_path;
344 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36345 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24346 } else {
347 new_host = old_path.substr(1, separator - 1);
348 new_path = old_path.substr(separator);
349 }
350
[email protected]44e8add2013-06-13 17:29:15351 // Do not allow URLs with paths empty before the first slash since we can't
352 // have an empty host. (e.g "foo://chrome//")
353 if (new_host.empty())
354 return false;
355
[email protected]f8f93eb2012-09-25 03:06:24356 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
357
[email protected]44e8add2013-06-13 17:29:15358 DCHECK(url->is_valid());
359
[email protected]f8f93eb2012-09-25 03:06:24360 return true;
361}
362
[email protected]b8148ac2011-07-13 22:03:25363// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42364bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24365 // Do not handle special URLs such as "about:foo"
366 if (!url->host().empty()) {
367 const GURL chrome_url = AddUberHost(*url);
368
369 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
370 // be called.
371 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
372 browser_context, chrome_url))
373 return true;
374 }
375
[email protected]863f70a2012-01-27 02:05:50376 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
377 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25378 return false;
379
[email protected]fe69558d2012-03-12 11:34:49380#if defined(OS_CHROMEOS)
381 // Special case : in ChromeOS in Guest mode bookmarks and history are
382 // disabled for security reasons. New tab page explains the reasons, so
383 // we redirect user to new tab page.
384 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
[email protected]2d9748b22014-02-11 00:17:29385 if (url->SchemeIs(content::kChromeUIScheme) &&
[email protected]fe69558d2012-03-12 11:34:49386 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
387 url->DomainIs(chrome::kChromeUIHistoryHost))) {
388 // Rewrite with new tab URL
389 *url = GURL(chrome::kChromeUINewTabURL);
390 }
391 }
392#endif
393
[email protected]b8148ac2011-07-13 22:03:25394 return true;
395}
396
[email protected]f8f93eb2012-09-25 03:06:24397// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
398// "chrome://foo/".
399bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
[email protected]2d9748b22014-02-11 00:17:29400 if (!url->is_valid() || !url->SchemeIs(content::kChromeUIScheme))
[email protected]f8f93eb2012-09-25 03:06:24401 return false;
402
403 return RemoveUberHost(url);
404}
405
[email protected]8d3132f62011-10-12 07:13:42406// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
407// below. Extension, and isolated apps require different privileges to be
408// granted to their RenderProcessHosts. This classification allows us to make
409// sure URLs are served by hosts with the right set of privileges.
410enum RenderProcessHostPrivilege {
411 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45412 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42413 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45414 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42415};
416
417RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
418 const GURL& url,
419 ExtensionService* service) {
420 // Default to a normal renderer cause it is lower privileged. This should only
421 // occur if the URL on a site instance is either malformed, or uninitialized.
422 // If it is malformed, then there is no need for better privileges anyways.
423 // If it is uninitialized, but eventually settles on being an a scheme other
424 // than normal webrenderer, the navigation logic will correct us out of band
425 // anyways.
426 if (!url.is_valid())
427 return PRIV_NORMAL;
428
[email protected]885c0e92012-11-13 20:27:42429 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44430 const Extension* extension =
431 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43432 if (extension &&
433 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42434 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45435 if (extension && extension->is_hosted_app())
436 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42437
438 return PRIV_EXTENSION;
439 }
440
441 return PRIV_NORMAL;
442}
443
444RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30445 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46446 extensions::ProcessMap* process_map,
447 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46448 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30449 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46450 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21451 return PRIV_NORMAL;
452
[email protected]6f371442011-11-09 06:45:46453 for (std::set<std::string>::iterator iter = extension_ids.begin();
454 iter != extension_ids.end(); ++iter) {
455 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43456 if (extension &&
457 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42458 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45459 if (extension && extension->is_hosted_app())
460 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42461 }
462
[email protected]676f6ab2011-10-19 20:23:21463 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42464}
465
[email protected]6786bf402011-12-03 15:19:45466bool CertMatchesFilter(const net::X509Certificate& cert,
467 const base::DictionaryValue& filter) {
468 // TODO(markusheintz): This is the minimal required filter implementation.
469 // Implement a better matcher.
470
471 // An empty filter matches any client certificate since no requirements are
472 // specified at all.
473 if (filter.empty())
474 return true;
475
476 std::string common_name;
477 if (filter.GetString("ISSUER.CN", &common_name) &&
478 (cert.issuer().common_name == common_name)) {
479 return true;
480 }
481 return false;
482}
483
[email protected]1d51882f2013-11-12 01:59:02484#if !defined(OS_ANDROID)
[email protected]f3986f82012-01-03 20:00:06485// Fills |map| with the per-script font prefs under path |map_name|.
486void FillFontFamilyMap(const PrefService* prefs,
487 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53488 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]33b79542013-10-18 11:18:45489 // TODO: Get rid of the brute-force scan over possible (font family / script)
490 // combinations - see http://crbug.com/308095.
[email protected]f3986f82012-01-03 20:00:06491 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
492 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
493 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
494 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23495 if (!font_family.empty())
[email protected]cc2a2a22013-12-24 23:12:15496 (*map)[script] = base::UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06497 }
498}
499
[email protected]a1733df2012-06-22 11:24:18500#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]0b818f72013-10-22 00:11:03501breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
502 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02503 base::FilePath dumps_path;
504 PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
505 {
506 ANNOTATE_SCOPED_MEMORY_LEAK;
[email protected]0b818f72013-10-22 00:11:03507 breakpad::CrashHandlerHostLinux* crash_handler =
508 new breakpad::CrashHandlerHostLinux(
509 process_type, dumps_path, getenv(env_vars::kHeadless) == NULL);
[email protected]779dd282013-10-19 15:57:02510 crash_handler->StartUploaderThread();
511 return crash_handler;
512 }
513}
514
[email protected]a1733df2012-06-22 11:24:18515int GetCrashSignalFD(const CommandLine& command_line) {
[email protected]cd0f7af2014-01-16 23:50:39516 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
[email protected]0b818f72013-10-22 00:11:03517 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02518 if (!crash_handler)
519 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18520 return crash_handler->GetDeathSignalSocket();
521 }
522
523 std::string process_type =
524 command_line.GetSwitchValueASCII(switches::kProcessType);
525
[email protected]779dd282013-10-19 15:57:02526 if (process_type == switches::kRendererProcess) {
[email protected]0b818f72013-10-22 00:11:03527 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02528 if (!crash_handler)
529 crash_handler = CreateCrashHandlerHost(process_type);
530 return crash_handler->GetDeathSignalSocket();
531 }
[email protected]a1733df2012-06-22 11:24:18532
[email protected]779dd282013-10-19 15:57:02533 if (process_type == switches::kPluginProcess) {
[email protected]0b818f72013-10-22 00:11:03534 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02535 if (!crash_handler)
536 crash_handler = CreateCrashHandlerHost(process_type);
537 return crash_handler->GetDeathSignalSocket();
538 }
[email protected]a1733df2012-06-22 11:24:18539
[email protected]779dd282013-10-19 15:57:02540 if (process_type == switches::kPpapiPluginProcess) {
[email protected]0b818f72013-10-22 00:11:03541 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02542 if (!crash_handler)
543 crash_handler = CreateCrashHandlerHost(process_type);
544 return crash_handler->GetDeathSignalSocket();
545 }
[email protected]a1733df2012-06-22 11:24:18546
[email protected]779dd282013-10-19 15:57:02547 if (process_type == switches::kGpuProcess) {
[email protected]0b818f72013-10-22 00:11:03548 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02549 if (!crash_handler)
550 crash_handler = CreateCrashHandlerHost(process_type);
551 return crash_handler->GetDeathSignalSocket();
552 }
[email protected]a1733df2012-06-22 11:24:18553
554 return -1;
555}
556#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]1d51882f2013-11-12 01:59:02557#endif // !defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18558
[email protected]d5bcd06f2013-04-21 08:07:24559#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30560GURL GetEffectiveURLForSignin(const GURL& url) {
561 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
562
563 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03564 // Copy the path because the argument to SetPathStr must outlive
565 // the Replacements object.
566 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30567 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03568 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30569 effective_url = effective_url.ReplaceComponents(replacements);
570 return effective_url;
571}
[email protected]d5bcd06f2013-04-21 08:07:24572#endif
[email protected]970c63e2013-03-07 00:25:30573
[email protected]eabbfb12013-04-05 23:28:35574void SetApplicationLocaleOnIOThread(const std::string& locale) {
575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
576 g_io_thread_application_locale.Get() = locale;
577}
578
[email protected]916615b2013-09-11 18:19:44579void HandleBlockedPopupOnUIThread(const BlockedWindowParams& params) {
580 WebContents* tab = tab_util::GetWebContentsByID(params.render_process_id(),
581 params.opener_id());
[email protected]190e5e22013-07-27 05:59:23582 if (!tab)
583 return;
584
[email protected]f1cd3362014-01-07 20:43:01585 prerender::PrerenderContents* prerender_contents =
586 prerender::PrerenderContents::FromWebContents(tab);
587 if (prerender_contents) {
588 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW);
589 return;
590 }
591
[email protected]190e5e22013-07-27 05:59:23592 PopupBlockerTabHelper* popup_helper =
593 PopupBlockerTabHelper::FromWebContents(tab);
594 if (!popup_helper)
595 return;
[email protected]916615b2013-09-11 18:19:44596 popup_helper->AddBlockedPopup(params);
[email protected]190e5e22013-07-27 05:59:23597}
[email protected]190e5e22013-07-27 05:59:23598
[email protected]916615b2013-09-11 18:19:44599#if defined(OS_ANDROID)
[email protected]b255a8e0e82013-10-22 04:03:59600
[email protected]916615b2013-09-11 18:19:44601void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams& params) {
602 WebContents* web_contents =
603 tab_util::GetWebContentsByID(params.render_process_id(),
604 params.opener_id());
605 if (!web_contents)
606 return;
607
608 SingleTabModeTabHelper::FromWebContents(web_contents)->HandleOpenUrl(params);
609}
[email protected]b255a8e0e82013-10-22 04:03:59610
[email protected]ded00dc2013-11-01 00:37:05611float GetDeviceScaleAdjustment() {
[email protected]b255a8e0e82013-10-22 04:03:59612 static const float kMinFSM = 1.05f;
613 static const int kWidthForMinFSM = 320;
614 static const float kMaxFSM = 1.3f;
615 static const int kWidthForMaxFSM = 800;
616
617 gfx::DeviceDisplayInfo info;
618 int minWidth = info.GetSmallestDIPWidth();
619
620 if (minWidth <= kWidthForMinFSM)
621 return kMinFSM;
622 if (minWidth >= kWidthForMaxFSM)
623 return kMaxFSM;
624
625 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
626 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) /
627 (kWidthForMaxFSM - kWidthForMinFSM);
628 return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
629}
630
[email protected]916615b2013-09-11 18:19:44631#endif // defined(OS_ANDROID)
632
[email protected]9dbfff12011-07-01 19:37:07633} // namespace
[email protected]c5dbef02011-05-13 05:06:09634
[email protected]d977f9c2011-03-14 16:10:26635namespace chrome {
636
[email protected]e461da2f2012-02-16 19:06:40637ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40638#if defined(ENABLE_PLUGINS)
[email protected]10c39222013-11-13 20:09:25639 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i)
640 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40641 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
642 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40643#endif
[email protected]1deace22013-05-22 06:14:46644
645 permissions_policy_delegate_.reset(
646 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40647}
648
649ChromeContentBrowserClient::~ChromeContentBrowserClient() {
650}
651
[email protected]bca18382012-06-25 19:15:23652// static
[email protected]37ca3fe02013-07-05 15:32:44653void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34654 user_prefs::PrefRegistrySyncable* registry) {
655 registry->RegisterBooleanPref(
656 prefs::kDisable3DAPIs,
657 false,
658 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
659 registry->RegisterBooleanPref(
660 prefs::kEnableHyperlinkAuditing,
661 true,
662 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23663}
664
[email protected]eabbfb12013-04-05 23:28:35665// static
666void ChromeContentBrowserClient::SetApplicationLocale(
667 const std::string& locale) {
668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
669
670 // This object is guaranteed to outlive all threads so we don't have to
671 // worry about the lack of refcounting and can just post as Unretained.
672 //
673 // The common case is that this function is called early in Chrome startup
674 // before any threads are created (it will also be called later if the user
675 // changes the pref). In this case, there will be no threads created and
676 // posting will fail. When there are no threads, we can just set the string
677 // without worrying about threadsafety.
678 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
679 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
680 g_io_thread_application_locale.Get() = locale;
681 }
682}
683
[email protected]50462bf02011-11-21 19:13:31684content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
685 const content::MainFunctionParams& parameters) {
686 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30687 // Construct the Main browser parts based on the OS type.
688#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31689 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04690#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31691 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30692#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22693 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26694#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31695 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14696#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09697 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30698#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31699 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04700#else
[email protected]b48c9182011-10-26 18:03:30701 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31702 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30703#endif
704
[email protected]7e75e4a2013-05-17 17:20:03705 chrome::AddProfilesExtraParts(main_parts);
706
[email protected]c7480942011-11-08 19:18:27707 // Construct additional browser parts. Stages are called in the order in
708 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22709#if defined(TOOLKIT_GTK)
[email protected]e8b6ca02013-07-10 18:00:51710 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04711#endif
[email protected]c7480942011-11-08 19:18:27712
713#if defined(TOOLKIT_VIEWS)
[email protected]e8b6ca02013-07-10 18:00:51714 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27715#endif
716
[email protected]dc04be7c2012-03-15 23:57:49717#if defined(USE_ASH)
[email protected]e8b6ca02013-07-10 18:00:51718 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
[email protected]dc04be7c2012-03-15 23:57:49719#endif
720
[email protected]e050ef142012-03-21 01:04:24721#if defined(USE_AURA)
[email protected]e8b6ca02013-07-10 18:00:51722 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
723#endif
724
725#if defined(USE_X11)
726 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:24727#endif
728
[email protected]95132f52013-04-12 02:19:04729 chrome::AddMetricsExtraParts(main_parts);
730
[email protected]50462bf02011-11-21 19:13:31731 return main_parts;
[email protected]f967b722011-09-07 00:58:04732}
733
[email protected]e94bbcb2012-09-07 05:33:57734std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19735 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57736 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53737 std::string partition_id;
738
739 // The partition ID for webview guest processes is the string value of its
740 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
[email protected]4413d872014-02-20 20:26:55741 if (site.SchemeIs(content::kGuestScheme)) {
[email protected]1bc28312012-11-08 08:31:53742 partition_id = site.spec();
[email protected]4413d872014-02-20 20:26:55743 } else if (site.GetOrigin().spec() == kChromeUIChromeSigninURL) {
744 // Chrome signin page has an embedded iframe of extension and web content,
745 // thus it must be isolated from other webUI pages.
746 partition_id = site.GetOrigin().spec();
747 }
[email protected]1bc28312012-11-08 08:31:53748
[email protected]056efdc2013-04-06 00:14:53749 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53750 return partition_id;
751}
752
753bool ChromeContentBrowserClient::IsValidStoragePartitionId(
754 content::BrowserContext* browser_context,
755 const std::string& partition_id) {
756 // The default ID is empty and is always valid.
757 if (partition_id.empty())
758 return true;
759
760 return GURL(partition_id).is_valid();
761}
762
763void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
764 content::BrowserContext* browser_context,
765 const GURL& site,
[email protected]14acc642012-11-17 12:20:10766 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53767 std::string* partition_domain,
768 std::string* partition_name,
769 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10770 // Default to the browser-wide storage partition and override based on |site|
771 // below.
772 partition_domain->clear();
773 partition_name->clear();
774 *in_memory = false;
775
[email protected]3f24f97c2013-11-17 21:53:33776 bool success = GuestView::GetGuestPartitionConfigForSite(
777 site, partition_domain, partition_name, in_memory);
778
779 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
[email protected]14acc642012-11-17 12:20:10780 // If |can_be_default| is false, the caller is stating that the |site|
781 // should be parsed as if it had isolated storage. In particular it is
782 // important to NOT check ExtensionService for the is_storage_isolated()
783 // attribute because this code path is run during Extension uninstall
784 // to do cleanup after the Extension has already been unloaded from the
785 // ExtensionService.
786 bool is_isolated = !can_be_default;
787 if (can_be_default) {
788 const Extension* extension = NULL;
789 Profile* profile = Profile::FromBrowserContext(browser_context);
790 ExtensionService* extension_service =
791 extensions::ExtensionSystem::Get(profile)->extension_service();
792 if (extension_service) {
[email protected]be9915fb2013-07-18 09:28:55793 extension =
794 extension_service->extensions()->GetExtensionOrAppByURL(site);
[email protected]561e33d52013-04-03 06:58:43795 if (extension &&
796 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10797 is_isolated = true;
798 }
799 }
800 }
[email protected]1bc28312012-11-08 08:31:53801
[email protected]14acc642012-11-17 12:20:10802 if (is_isolated) {
803 CHECK(site.has_host());
804 // For extensions with isolated storage, the the host of the |site| is
805 // the |partition_domain|. The |in_memory| and |partition_name| are only
806 // used in guest schemes so they are cleared here.
807 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53808 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10809 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53810 }
[email protected]4413d872014-02-20 20:26:55811 } else if (site.GetOrigin().spec() == kChromeUIChromeSigninURL) {
812 // Chrome signin page has an embedded iframe of extension and web content,
813 // thus it must be isolated from other webUI pages.
814 *partition_domain = chrome::kChromeUIChromeSigninHost;
[email protected]d1198fd2012-08-13 22:50:19815 }
816
[email protected]14acc642012-11-17 12:20:10817 // Assert that if |can_be_default| is false, the code above must have found a
818 // non-default partition. If this fails, the caller has a serious logic
819 // error about which StoragePartition they expect to be in and it is not
820 // safe to continue.
821 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44822}
823
[email protected]38b098f2012-03-14 21:11:57824content::WebContentsViewDelegate*
825 ChromeContentBrowserClient::GetWebContentsViewDelegate(
826 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27827 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32828}
829
[email protected]738f57a2013-06-29 21:06:54830void ChromeContentBrowserClient::GuestWebContentsCreated(
[email protected]dbbce92c2013-10-31 16:51:19831 SiteInstance* guest_site_instance,
[email protected]738f57a2013-06-29 21:06:54832 WebContents* guest_web_contents,
833 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22834 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54835 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]dbbce92c2013-10-31 16:51:19836 if (!guest_site_instance) {
837 NOTREACHED();
838 return;
839 }
840 GURL guest_site_url = guest_site_instance->GetSiteURL();
841 const std::string& extension_id = guest_site_url.host();
842
843 Profile* profile = Profile::FromBrowserContext(
844 guest_web_contents->GetBrowserContext());
845 ExtensionService* service =
846 extensions::ExtensionSystem::Get(profile)->extension_service();
847 if (!service) {
848 NOTREACHED();
849 return;
850 }
851
852 /// TODO(fsamuel): In the future, certain types of GuestViews won't require
853 // extension bindings. At that point, we should clear |extension_id| instead
854 // of exiting early.
855 if (!service->GetExtensionById(extension_id, false) &&
856 !CommandLine::ForCurrentProcess()->HasSwitch(
857 switches::kEnableBrowserPluginForAllViewTypes)) {
858 NOTREACHED();
859 return;
860 }
861
[email protected]738f57a2013-06-29 21:06:54862 if (opener_web_contents) {
863 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
864 if (!guest) {
865 NOTREACHED();
866 return;
867 }
868
[email protected]50c827d2013-09-13 21:36:09869 // Create a new GuestView of the same type as the opener.
870 *guest_delegate =
[email protected]dbbce92c2013-10-31 16:51:19871 GuestView::Create(guest_web_contents,
872 extension_id,
873 guest->GetViewType());
[email protected]738f57a2013-06-29 21:06:54874 return;
875 }
876
877 if (!extra_params) {
878 NOTREACHED();
879 return;
880 }
881 std::string api_type;
[email protected]90547d72013-08-06 05:57:27882 extra_params->GetString(guestview::kParameterApi, &api_type);
[email protected]738f57a2013-06-29 21:06:54883
[email protected]dbbce92c2013-10-31 16:51:19884 if (api_type.empty())
885 return;
886
[email protected]50c827d2013-09-13 21:36:09887 *guest_delegate =
888 GuestView::Create(guest_web_contents,
[email protected]dbbce92c2013-10-31 16:51:19889 extension_id,
[email protected]50c827d2013-09-13 21:36:09890 GuestView::GetViewTypeFromString(api_type));
[email protected]738f57a2013-06-29 21:06:54891}
892
[email protected]44295a12013-06-05 08:45:46893void ChromeContentBrowserClient::GuestWebContentsAttached(
894 WebContents* guest_web_contents,
895 WebContents* embedder_web_contents,
[email protected]5715566a2013-06-25 00:04:53896 const base::DictionaryValue& extra_params) {
[email protected]22aa4f82013-09-24 17:01:44897
[email protected]dbbce92c2013-10-31 16:51:19898 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
899 if (!guest) {
[email protected]efd6fb02013-08-05 04:44:06900 // It's ok to return here, since we could be running a browser plugin
901 // outside an extension, and don't need to attach a
902 // BrowserPluginGuestDelegate in that case;
903 // e.g. running with flag --enable-browser-plugin-for-all-view-types.
[email protected]738f57a2013-06-29 21:06:54904 return;
[email protected]18699372013-06-25 20:42:55905 }
[email protected]dbbce92c2013-10-31 16:51:19906 guest->Attach(embedder_web_contents, extra_params);
[email protected]44703cc72013-01-24 04:56:06907}
908
[email protected]6f2862742013-12-20 07:53:19909void ChromeContentBrowserClient::RenderProcessWillLaunch(
[email protected]f3b1a082011-11-18 00:34:30910 content::RenderProcessHost* host) {
911 int id = host->GetID();
912 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41913 net::URLRequestContextGetter* context =
914 profile->GetRequestContextForRenderProcess(id);
915
[email protected]ba780c12013-10-01 17:07:06916 host->AddFilter(new ChromeRenderMessageFilter(id, profile, context));
[email protected]afed5112014-02-02 06:01:53917 host->AddFilter(new extensions::ExtensionMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55918#if defined(ENABLE_PLUGINS)
[email protected]ba780c12013-10-01 17:07:06919 host->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55920#endif
[email protected]1ea4c492014-02-15 19:45:17921 host->AddFilter(new cast::CastTransportHostFilter);
[email protected]658677f2012-06-09 06:04:02922#if defined(ENABLE_PRINTING)
[email protected]ba780c12013-10-01 17:07:06923 host->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03924#endif
[email protected]ba780c12013-10-01 17:07:06925 host->AddFilter(new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]c6ce08072013-07-31 07:48:53926#if defined(ENABLE_SPELLCHECK)
[email protected]ba780c12013-10-01 17:07:06927 host->AddFilter(new SpellCheckMessageFilter(id));
[email protected]c6ce08072013-07-31 07:48:53928#endif
[email protected]7ceb99012011-12-21 08:05:56929#if defined(OS_MACOSX)
[email protected]ba780c12013-10-01 17:07:06930 host->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56931#endif
[email protected]49aa5a32014-02-03 10:00:44932 host->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile, context));
[email protected]ba780c12013-10-01 17:07:06933 host->AddFilter(new prerender::PrerenderMessageFilter(id, profile));
[email protected]ba780c12013-10-01 17:07:06934 host->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31935#if defined(ENABLE_WEBRTC)
[email protected]10e5c5e52013-10-03 18:44:06936 WebRtcLoggingHandlerHost* webrtc_logging_handler_host =
[email protected]135bc1d2013-10-21 09:11:37937 new WebRtcLoggingHandlerHost(profile);
[email protected]e7b9b352014-01-29 16:35:27938 host->SetWebRtcLogMessageCallback(base::Bind(
939 &WebRtcLoggingHandlerHost::LogMessage, webrtc_logging_handler_host));
[email protected]10e5c5e52013-10-03 18:44:06940 host->AddFilter(webrtc_logging_handler_host);
941 host->SetUserData(host, new base::UserDataAdapter<WebRtcLoggingHandlerHost>(
942 webrtc_logging_handler_host));
[email protected]6ef98b5a2013-05-31 23:58:31943#endif
[email protected]01e59752013-06-18 00:17:35944#if !defined(DISABLE_NACL)
[email protected]7c766e92013-11-22 20:44:02945 host->AddFilter(new nacl::NaClHostMessageFilter(
[email protected]14230ca2013-06-26 23:33:03946 id, profile->IsOffTheRecord(),
[email protected]a2b4c5c2013-10-18 02:06:07947 profile->GetPath(),
[email protected]14230ca2013-06-26 23:33:03948 context));
[email protected]01e59752013-06-18 00:17:35949#endif
[email protected]2b12c322013-09-19 06:53:56950#if defined(OS_ANDROID)
[email protected]ba780c12013-10-01 17:07:06951 host->AddFilter(new EncryptedMediaMessageFilterAndroid());
[email protected]2b12c322013-09-19 06:53:56952#endif
[email protected]4de75262013-12-18 23:16:12953 if (switches::IsNewProfileManagement())
[email protected]914cf6712013-12-05 01:14:06954 host->AddFilter(new PrincipalsMessageFilter(id));
[email protected]3e69bc82011-05-26 23:22:38955
[email protected]2ccf45c2011-08-19 23:35:50956 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
957 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07958
959 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56960
961 RendererContentSettingRules rules;
[email protected]06153f02013-12-04 03:01:28962 if (host->IsGuest()) {
963 GuestView::GetDefaultContentSettingRules(&rules, profile->IsOffTheRecord());
964 } else {
965 GetRendererContentSettingRules(
966 profile->GetHostContentSettingsMap(), &rules);
967 }
[email protected]edece212011-11-16 11:56:56968 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14969}
970
[email protected]3d7474ff2011-07-27 17:47:37971GURL ChromeContentBrowserClient::GetEffectiveURL(
972 content::BrowserContext* browser_context, const GURL& url) {
973 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52974 if (!profile)
975 return url;
976
[email protected]b3cb3a32013-07-31 01:32:29977 // If the input |url| should be assigned to the Instant renderer, make its
978 // effective URL distinct from other URLs on the search provider's domain.
979 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
980 return chrome::GetEffectiveURLForInstant(url, profile);
981
[email protected]d5bcd06f2013-04-21 08:07:24982#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30983 // If the input |url| should be assigned to the Signin renderer, make its
984 // effective URL distinct from other URLs on the signin service's domain.
985 // Note that the signin renderer will be allowed to sign the user in to
986 // Chrome.
987 if (SigninManager::IsWebBasedSigninFlowURL(url))
988 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24989#endif
[email protected]970c63e2013-03-07 00:25:30990
[email protected]c5dec6292013-01-25 04:54:52991 // If the input |url| is part of an installed app, the effective URL is an
992 // extension URL with the ID of that extension as the host. This has the
993 // effect of grouping apps together in a common SiteInstance.
994 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13995 extensions::ExtensionSystem::Get(profile)->extension_service();
996 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08997 return url;
998
[email protected]06bdd2b2012-11-30 18:47:13999 const Extension* extension = extension_service->extensions()->
[email protected]be9915fb2013-07-18 09:28:551000 GetHostedAppByURL(url);
[email protected]36fb2c7c2011-04-04 15:49:081001 if (!extension)
1002 return url;
1003
[email protected]15877ca2011-11-18 22:40:521004 // Bookmark apps do not use the hosted app process model, and should be
1005 // treated as normal URLs.
1006 if (extension->from_bookmark())
1007 return url;
1008
[email protected]36fb2c7c2011-04-04 15:49:081009 // If the URL is part of an extension's web extent, convert it to an
1010 // extension URL.
1011 return extension->GetResourceURL(url.path());
1012}
1013
[email protected]056ad2a2011-07-12 02:13:551014bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:371015 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:521016 // Non-extension, non-Instant URLs should generally use
1017 // process-per-site-instance. Because we expect to use the effective URL,
1018 // URLs for hosted apps (apart from bookmark apps) should have an extension
1019 // scheme by now.
1020
1021 Profile* profile = Profile::FromBrowserContext(browser_context);
1022 if (!profile)
1023 return false;
1024
[email protected]df113a12013-07-24 04:56:081025 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:521026 return true;
1027
[email protected]d5bcd06f2013-04-21 08:07:241028#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301029 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
1030 return true;
[email protected]d5bcd06f2013-04-21 08:07:241031#endif
[email protected]970c63e2013-03-07 00:25:301032
[email protected]885c0e92012-11-13 20:27:421033 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:551034 return false;
1035
[email protected]c5dec6292013-01-25 04:54:521036 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:131037 extensions::ExtensionSystem::Get(profile)->extension_service();
1038 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:551039 return false;
1040
[email protected]be9915fb2013-07-18 09:28:551041 const Extension* extension =
1042 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
[email protected]056ad2a2011-07-12 02:13:551043 if (!extension)
1044 return false;
1045
1046 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:531047 // permission, or that does not allow JavaScript access to the background
1048 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:551049 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:401050 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:061051 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:291052 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:531053 return false;
1054 }
1055 }
[email protected]056ad2a2011-07-12 02:13:551056
[email protected]7b54ca02012-03-02 18:06:531057 // Hosted apps that have script access to their background page must use
1058 // process per site, since all instances can make synchronous calls to the
1059 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:551060 return true;
1061}
1062
[email protected]73b718f2014-01-27 02:59:461063// These are treated as WebUI schemes but do not get WebUI bindings. Also,
1064// view-source is allowed for these schemes.
[email protected]8f89dd412013-04-17 02:35:411065void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1066 std::vector<std::string>* additional_schemes) {
1067 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]73b718f2014-01-27 02:59:461068 additional_schemes->push_back(chrome::kDomDistillerScheme);
[email protected]672c8c12013-03-07 12:30:061069}
1070
[email protected]70b89cd2014-03-18 00:33:241071void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck(
1072 std::vector<std::string>* hosts) {
1073 hosts->push_back(chrome::kChromeUIExtensionIconHost);
1074 hosts->push_back(chrome::kChromeUIFaviconHost);
1075 hosts->push_back(chrome::kChromeUIThemeHost);
1076 hosts->push_back(chrome::kChromeUIThumbnailHost);
1077 hosts->push_back(chrome::kChromeUIThumbnailHost2);
1078 hosts->push_back(chrome::kChromeUIThumbnailListHost);
1079}
1080
1081net::URLRequestContextGetter*
1082ChromeContentBrowserClient::CreateRequestContext(
[email protected]6bd30072013-02-08 18:17:111083 content::BrowserContext* browser_context,
[email protected]7571263c2014-03-10 22:57:091084 content::ProtocolHandlerMap* protocol_handlers,
1085 content::ProtocolHandlerScopedVector protocol_interceptors) {
[email protected]6bd30072013-02-08 18:17:111086 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]7571263c2014-03-10 22:57:091087 return profile->CreateRequestContext(protocol_handlers,
1088 protocol_interceptors.Pass());
[email protected]6bd30072013-02-08 18:17:111089}
1090
1091net::URLRequestContextGetter*
1092ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
1093 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:401094 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:111095 bool in_memory,
[email protected]7571263c2014-03-10 22:57:091096 content::ProtocolHandlerMap* protocol_handlers,
1097 content::ProtocolHandlerScopedVector protocol_interceptors) {
[email protected]6bd30072013-02-08 18:17:111098 Profile* profile = Profile::FromBrowserContext(browser_context);
1099 return profile->CreateRequestContextForStoragePartition(
[email protected]7571263c2014-03-10 22:57:091100 partition_path,
1101 in_memory,
1102 protocol_handlers,
1103 protocol_interceptors.Pass());
[email protected]6bd30072013-02-08 18:17:111104}
1105
[email protected]46fb9442011-12-09 17:57:471106bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1107 return ProfileIOData::IsHandledURL(url);
1108}
1109
[email protected]c4365fa42013-05-14 01:08:241110bool ChromeContentBrowserClient::CanCommitURL(
1111 content::RenderProcessHost* process_host,
1112 const GURL& url) {
1113 // We need to let most extension URLs commit in any process, since this can
1114 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1115 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1116 // cannot be loaded in iframes and should never be requested outside its
1117 // process.
1118 Profile* profile =
1119 Profile::FromBrowserContext(process_host->GetBrowserContext());
1120 ExtensionService* service =
1121 extensions::ExtensionSystem::Get(profile)->extension_service();
1122 if (!service)
1123 return true;
1124 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551125 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]c4365fa42013-05-14 01:08:241126 if (new_extension &&
1127 new_extension->is_hosted_app() &&
1128 new_extension->id() == extension_misc::kWebStoreAppId &&
[email protected]fafdc842014-01-17 18:09:081129 !extensions::ProcessMap::Get(profile)->
1130 Contains(new_extension->id(), process_host->GetID())) {
[email protected]c4365fa42013-05-14 01:08:241131 return false;
1132 }
1133
1134 return true;
1135}
1136
[email protected]9a60d1602013-09-11 04:09:121137bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1138 content::SiteInstance* site_instance, const GURL& url) {
1139 GURL from_url = site_instance->GetSiteURL();
1140 // Do not allow pages from the web or other extensions navigate to
1141 // non-web-accessible extension resources.
1142 if (url.SchemeIs(extensions::kExtensionScheme) &&
1143 (from_url.SchemeIsHTTPOrHTTPS() ||
1144 from_url.SchemeIs(extensions::kExtensionScheme))) {
1145 Profile* profile = Profile::FromBrowserContext(
1146 site_instance->GetProcess()->GetBrowserContext());
1147 ExtensionService* service =
1148 extensions::ExtensionSystem::Get(profile)->extension_service();
1149 if (!service)
1150 return true;
1151 const Extension* extension =
1152 service->extensions()->GetExtensionOrAppByURL(url);
1153 if (!extension)
1154 return true;
1155 const Extension* from_extension =
1156 service->extensions()->GetExtensionOrAppByURL(
1157 site_instance->GetSiteURL());
1158 if (from_extension && from_extension->id() == extension->id())
1159 return true;
1160
1161 if (!extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
1162 extension, url.path()))
1163 return false;
1164 }
1165 return true;
1166}
1167
[email protected]2a5221b2011-09-27 23:07:311168bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301169 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311170 const GURL& site_url) {
1171 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301172 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521173 // This may be NULL during tests. In that case, just assume any site can
1174 // share any host.
1175 if (!profile)
1176 return true;
1177
[email protected]d43f99fe2013-04-03 00:20:141178 // Instant URLs should only be in the instant process and instant process
1179 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521180 InstantService* instant_service =
1181 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141182 if (instant_service) {
1183 bool is_instant_process = instant_service->IsInstantProcess(
1184 process_host->GetID());
1185 bool should_be_in_instant_process =
1186 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1187 if (is_instant_process || should_be_in_instant_process)
1188 return is_instant_process && should_be_in_instant_process;
1189 }
[email protected]c5dec6292013-01-25 04:54:521190
[email protected]d5bcd06f2013-04-21 08:07:241191#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301192 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1193 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1194 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241195#endif
[email protected]970c63e2013-03-07 00:25:301196
[email protected]06bdd2b2012-11-30 18:47:131197 ExtensionService* service =
1198 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]fafdc842014-01-17 18:09:081199 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile);
[email protected]2a5221b2011-09-27 23:07:311200
[email protected]ffa97602011-11-17 17:55:521201 // Don't allow the Task Manager to share a process with anything else.
1202 // Otherwise it can affect the renderers it is observing.
1203 // Note: we could create another RenderProcessHostPrivilege bucket for
1204 // this to allow multiple chrome://tasks instances to share, but that's
1205 // a very unlikely case without serious consequences.
1206 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1207 return false;
1208
[email protected]8d3132f62011-10-12 07:13:421209 // These may be NULL during tests. In that case, just assume any site can
1210 // share any host.
[email protected]6f371442011-11-09 06:45:461211 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311212 return true;
1213
[email protected]eec0b33c2011-12-05 22:09:451214 // Otherwise, just make sure the process privilege matches the privilege
1215 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571216 RenderProcessHostPrivilege privilege_required =
1217 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451218 return GetProcessPrivilege(process_host, process_map, service) ==
1219 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311220}
1221
[email protected]76411f412012-02-22 18:56:061222// This function is trying to limit the amount of processes used by extensions
1223// with background pages. It uses a globally set percentage of processes to
1224// run such extensions and if the limit is exceeded, it returns true, to
1225// indicate to the content module to group extensions together.
1226bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1227 content::BrowserContext* browser_context, const GURL& url) {
1228 // It has to be a valid URL for us to check for an extension.
1229 if (!url.is_valid())
1230 return false;
1231
1232 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191233 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131234 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061235 if (!service)
1236 return false;
1237
1238 // We have to have a valid extension with background page to proceed.
1239 const Extension* extension =
[email protected]be9915fb2013-07-18 09:28:551240 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]76411f412012-02-22 18:56:061241 if (!extension)
1242 return false;
[email protected]9367eabc2013-03-01 01:29:291243 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061244 return false;
1245
1246 std::set<int> process_ids;
1247 size_t max_process_count =
1248 content::RenderProcessHost::GetMaxRendererProcessCount();
1249
1250 // Go through all profiles to ensure we have total count of extension
1251 // processes containing background pages, otherwise one profile can
1252 // starve the other.
1253 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1254 GetLoadedProfiles();
1255 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]98b6d942013-11-10 00:34:071256 extensions::ProcessManager* epm =
[email protected]be93bba02012-10-24 16:44:031257 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]98b6d942013-11-10 00:34:071258 for (extensions::ProcessManager::const_iterator iter =
[email protected]d1fe1352012-04-26 00:47:321259 epm->background_hosts().begin();
1260 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131261 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321262 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061263 }
1264 }
1265
1266 if (process_ids.size() >
1267 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1268 return true;
1269 }
1270
1271 return false;
1272}
1273
[email protected]6f371442011-11-09 06:45:461274void ChromeContentBrowserClient::SiteInstanceGotProcess(
1275 SiteInstance* site_instance) {
1276 CHECK(site_instance->HasProcess());
1277
1278 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021279 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521280 if (!profile)
1281 return;
1282
1283 // Remember the ID of the Instant process to signal the renderer process
1284 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031285 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321286 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521287 InstantService* instant_service =
1288 InstantServiceFactory::GetForProfile(profile);
1289 if (instant_service)
1290 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1291 }
1292
[email protected]d5bcd06f2013-04-21 08:07:241293#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301294 // We only expect there to be one signin process as we use process-per-site
1295 // for signin URLs. The signin process will be cleared from SigninManager
1296 // when the renderer is destroyed.
1297 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1298 SigninManager* signin_manager =
1299 SigninManagerFactory::GetForProfile(profile);
1300 if (signin_manager)
1301 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461302 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:201303 BrowserThread::IO,
1304 FROM_HERE,
1305 base::Bind(&InfoMap::SetSigninProcess,
[email protected]1deace22013-05-22 06:14:461306 extensions::ExtensionSystem::Get(profile)->info_map(),
1307 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301308 }
[email protected]d5bcd06f2013-04-21 08:07:241309#endif
[email protected]970c63e2013-03-07 00:25:301310
[email protected]06bdd2b2012-11-30 18:47:131311 ExtensionService* service =
1312 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461313 if (!service)
1314 return;
1315
[email protected]be9915fb2013-07-18 09:28:551316 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1317 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461318 if (!extension)
1319 return;
1320
[email protected]fafdc842014-01-17 18:09:081321 extensions::ProcessMap::Get(profile)
1322 ->Insert(extension->id(),
1323 site_instance->GetProcess()->GetID(),
1324 site_instance->GetId());
1325
[email protected]6f371442011-11-09 06:45:461326 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:201327 BrowserThread::IO,
1328 FROM_HERE,
1329 base::Bind(&InfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591330 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461331 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351332 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331333 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461334}
1335
1336void ChromeContentBrowserClient::SiteInstanceDeleting(
1337 SiteInstance* site_instance) {
1338 if (!site_instance->HasProcess())
1339 return;
1340
1341 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021342 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131343 ExtensionService* service =
1344 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461345 if (!service)
1346 return;
1347
[email protected]be9915fb2013-07-18 09:28:551348 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1349 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461350 if (!extension)
1351 return;
1352
[email protected]fafdc842014-01-17 18:09:081353 extensions::ProcessMap::Get(profile)
1354 ->Remove(extension->id(),
1355 site_instance->GetProcess()->GetID(),
1356 site_instance->GetId());
1357
[email protected]6f371442011-11-09 06:45:461358 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:201359 BrowserThread::IO,
1360 FROM_HERE,
1361 base::Bind(&InfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591362 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461363 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351364 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331365 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461366}
1367
[email protected]896c6d52014-01-28 21:40:211368void ChromeContentBrowserClient::WorkerProcessCreated(
1369 SiteInstance* site_instance,
1370 int worker_process_id) {
1371 extensions::ExtensionRegistry* extension_registry =
1372 extensions::ExtensionRegistry::Get(site_instance->GetBrowserContext());
1373 if (!extension_registry)
1374 return;
1375 const Extension* extension =
1376 extension_registry->enabled_extensions().GetExtensionOrAppByURL(
1377 site_instance->GetSiteURL());
1378 if (!extension)
1379 return;
1380 extensions::ExtensionSystem* extension_system =
[email protected]59b0e602014-01-30 00:41:241381 extensions::ExtensionSystem::Get(site_instance->GetBrowserContext());
[email protected]896c6d52014-01-28 21:40:211382 extension_system->info_map()->RegisterExtensionWorkerProcess(
1383 extension->id(),
1384 worker_process_id,
1385 site_instance->GetId());
1386}
1387
1388void ChromeContentBrowserClient::WorkerProcessTerminated(
1389 SiteInstance* site_instance,
1390 int worker_process_id) {
1391 extensions::ExtensionSystem* extension_system =
[email protected]59b0e602014-01-30 00:41:241392 extensions::ExtensionSystem::Get(site_instance->GetBrowserContext());
[email protected]896c6d52014-01-28 21:40:211393 extension_system->info_map()->UnregisterExtensionWorkerProcess(
1394 worker_process_id);
1395}
1396
[email protected]453f5432013-11-26 19:43:001397bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141398 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081399 const GURL& current_url,
1400 const GURL& new_url) {
[email protected]2aca9a92013-12-03 05:16:071401 // If we don't have an ExtensionService, then rely on the SiteInstance logic
[email protected]a5a59482013-12-03 22:52:061402 // in RenderFrameHostManager to decide when to swap.
[email protected]e9841fbd2013-02-22 23:12:141403 Profile* profile =
1404 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1405 ExtensionService* service =
1406 extensions::ExtensionSystem::Get(profile)->extension_service();
1407 if (!service)
1408 return false;
1409
[email protected]2aca9a92013-12-03 05:16:071410 // We must use a new BrowsingInstance (forcing a process swap and disabling
1411 // scripting by existing tabs) if one of the URLs is an extension and the
1412 // other is not the exact same extension.
1413 //
1414 // We ignore hosted apps here so that other tabs in their BrowsingInstance can
1415 // use postMessage with them. (The exception is the Chrome Web Store, which
1416 // is a hosted app that requires its own BrowsingInstance.) Navigations
1417 // to/from a hosted app will still trigger a SiteInstance swap in
[email protected]a5a59482013-12-03 22:52:061418 // RenderFrameHostManager.
[email protected]2aca9a92013-12-03 05:16:071419 const Extension* current_extension =
1420 service->extensions()->GetExtensionOrAppByURL(current_url);
1421 if (current_extension &&
1422 current_extension->is_hosted_app() &&
1423 current_extension->id() != extension_misc::kWebStoreAppId)
1424 current_extension = NULL;
1425
[email protected]e9841fbd2013-02-22 23:12:141426 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551427 service->extensions()->GetExtensionOrAppByURL(new_url);
[email protected]e9841fbd2013-02-22 23:12:141428 if (new_extension &&
1429 new_extension->is_hosted_app() &&
1430 new_extension->id() != extension_misc::kWebStoreAppId)
1431 new_extension = NULL;
[email protected]2aca9a92013-12-03 05:16:071432
1433 // First do a process check. We should force a BrowsingInstance swap if the
1434 // current process doesn't know about new_extension, even if current_extension
1435 // is somehow the same as new_extension.
[email protected]fafdc842014-01-17 18:09:081436 extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile);
[email protected]e9841fbd2013-02-22 23:12:141437 if (new_extension &&
1438 site_instance->HasProcess() &&
[email protected]fafdc842014-01-17 18:09:081439 !process_map->Contains(
1440 new_extension->id(), site_instance->GetProcess()->GetID()))
[email protected]e9841fbd2013-02-22 23:12:141441 return true;
1442
[email protected]2aca9a92013-12-03 05:16:071443 // Otherwise, swap BrowsingInstances if current_extension and new_extension
1444 // differ.
1445 return current_extension != new_extension;
[email protected]e3daf3c2011-10-05 21:17:081446}
1447
[email protected]395045c2012-05-22 15:04:381448bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1449 content::ResourceContext* resource_context, const GURL& current_url,
1450 const GURL& new_url) {
1451 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1452 return extensions::CrossesExtensionProcessBoundary(
1453 io_data->GetExtensionInfoMap()->extensions(),
[email protected]be9915fb2013-07-18 09:28:551454 current_url, new_url, false);
[email protected]395045c2012-05-22 15:04:381455}
1456
[email protected]3d831992013-07-04 01:13:291457bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1458 return !url.SchemeIs(chrome::kChromeNativeScheme);
1459}
1460
[email protected]763ec4ca2011-04-29 15:48:121461std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1462 const std::string& alias_name) {
1463 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1464}
1465
[email protected]b80f68432011-05-02 17:22:301466void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1467 CommandLine* command_line, int child_process_id) {
[email protected]264c0acac2013-10-01 13:33:301468#if defined(OS_POSIX)
[email protected]0b818f72013-10-22 00:11:031469 if (breakpad::IsCrashReporterEnabled()) {
[email protected]264c0acac2013-10-01 13:33:301470 std::string enable_crash_reporter;
1471 GoogleUpdateSettings::GetMetricsId(&enable_crash_reporter);
1472#if !defined(OS_MACOSX)
1473 enable_crash_reporter += "," + base::GetLinuxDistro();
1474#endif
[email protected]b80f68432011-05-02 17:22:301475 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
[email protected]264c0acac2013-10-01 13:33:301476 enable_crash_reporter);
[email protected]b80f68432011-05-02 17:22:301477 }
[email protected]264c0acac2013-10-01 13:33:301478#endif // OS_POSIX
[email protected]b80f68432011-05-02 17:22:301479
[email protected]f1933792011-06-14 00:49:341480 if (logging::DialogsAreSuppressed())
1481 command_line->AppendSwitch(switches::kNoErrorDialogs);
1482
[email protected]b80f68432011-05-02 17:22:301483 std::string process_type =
1484 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171485 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321486
[email protected]7c9b6f92013-09-10 18:11:351487 static const char* const kCommonSwitchNames[] = {
[email protected]aa051272014-03-10 05:56:561488 switches::kUserAgent,
[email protected]7c9b6f92013-09-10 18:11:351489 switches::kUserDataDir, // Make logs go to the right file.
1490 };
1491 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
1492 arraysize(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:321493
[email protected]8c64e282013-11-28 16:05:141494#if defined(ENABLE_IPC_FUZZER)
1495 static const char* const kIpcFuzzerSwitches[] = {
1496 switches::kIpcFuzzerTestcase,
1497 };
1498 command_line->CopySwitchesFrom(browser_command_line, kIpcFuzzerSwitches,
1499 arraysize(kIpcFuzzerSwitches));
1500#endif
1501
[email protected]718eab62011-10-05 21:16:521502 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:301503#if defined(OS_CHROMEOS)
1504 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441505 browser_command_line.GetSwitchValueASCII(
1506 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301507 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441508 command_line->AppendSwitchASCII(
1509 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301510#endif
1511
[email protected]50fa4d5f2013-11-05 00:53:231512#if defined(ENABLE_WEBRTC)
[email protected]30335fdf02014-02-26 19:51:271513 MaybeCopyDisableWebRtcEncryptionSwitch(command_line,
1514 browser_command_line,
1515 VersionInfo::GetChannel());
[email protected]50fa4d5f2013-11-05 00:53:231516#endif
1517
[email protected]f3b1a082011-11-18 00:34:301518 content::RenderProcessHost* process =
1519 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371520 if (process) {
1521 Profile* profile = Profile::FromBrowserContext(
1522 process->GetBrowserContext());
[email protected]fafdc842014-01-17 18:09:081523
1524 if (extensions::ProcessMap::Get(profile)->Contains(process->GetID()))
1525 command_line->AppendSwitch(extensions::switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:301526
[email protected]a8d851f82011-12-21 00:32:371527 PrefService* prefs = profile->GetPrefs();
1528 // Currently this pref is only registered if applied via a policy.
1529 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1530 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1531 // Turn this policy into a command line switch.
1532 command_line->AppendSwitch(switches::kDisable3DAPIs);
1533 }
[email protected]718eab62011-10-05 21:16:521534
[email protected]a8d851f82011-12-21 00:32:371535 // Disable client-side phishing detection in the renderer if it is
1536 // disabled in the Profile preferences or the browser process.
1537 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1538 !g_browser_process->safe_browsing_detection_service()) {
1539 command_line->AppendSwitch(
1540 switches::kDisableClientSidePhishingDetection);
1541 }
[email protected]0045b0f42012-07-26 11:52:081542
1543 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211544 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521545
1546 InstantService* instant_service =
1547 InstantServiceFactory::GetForProfile(profile);
1548 if (instant_service &&
1549 instant_service->IsInstantProcess(process->GetID()))
1550 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301551
[email protected]d5bcd06f2013-04-21 08:07:241552#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301553 SigninManager* signin_manager =
1554 SigninManagerFactory::GetForProfile(profile);
1555 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1556 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241557#endif
[email protected]47c7ec82012-01-18 03:29:211558 }
[email protected]4287a3d2011-06-13 23:56:511559
[email protected]47c7ec82012-01-18 03:29:211560 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511561 static const char* const kSwitchNames[] = {
[email protected]b785898a2014-02-05 06:54:431562 autofill::switches::kDisableIgnoreAutocompleteOff,
[email protected]000f3ad2013-05-16 02:19:171563 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]c3cc0632013-10-03 21:54:431564 autofill::switches::kDisablePasswordGeneration,
[email protected]000f3ad2013-05-16 02:19:171565 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]c3cc0632013-10-03 21:54:431566 autofill::switches::kEnablePasswordGeneration,
[email protected]3cbdf9362014-01-31 23:12:231567 autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration,
[email protected]558878cc82013-11-09 01:25:511568 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:271569 extensions::switches::kAllowLegacyExtensionManifests,
1570 extensions::switches::kAllowScriptingGallery,
[email protected]c8d02992013-07-31 22:16:511571 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271572 extensions::switches::kExtensionsOnChromeURLs,
[email protected]9d450492013-06-13 23:08:371573 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1574 // to browser.
1575 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511576 switches::kAppsCheckoutURL,
1577 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311578 switches::kCloudPrintServiceURL,
[email protected]382fb0d2012-02-25 00:19:501579 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531580 switches::kDisableExtensionsResourceWhitelist,
[email protected]83c85262013-08-22 21:13:461581 switches::kDisablePnacl,
[email protected]b0553c7e2012-09-19 21:36:111582 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531583 switches::kEnableAdview,
[email protected]1f4da9e2013-06-27 05:23:441584 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211585 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511586 switches::kEnableNaCl,
[email protected]1b4ec382014-03-07 02:32:241587 switches::kEnableNaClDebug,
[email protected]b2c73f42014-03-07 15:44:481588 switches::kEnableNaClNonSfiMode,
[email protected]ce304ce2013-02-22 21:54:451589 switches::kEnableNetBenchmarking,
[email protected]9fe9760a2014-03-15 00:11:591590 switches::kEnableOfflineAutoReload,
[email protected]c10b25f2014-01-14 14:57:001591 switches::kEnableStreamlinedHostedApps,
[email protected]4287a3d2011-06-13 23:56:511592 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511593 switches::kMemoryProfiling,
1594 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371595 switches::kNoJsRandomness,
[email protected]8f06e4d2013-11-25 23:20:181596 switches::kOutOfProcessPdf,
[email protected]f45c5f32012-04-18 19:26:371597 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511598 switches::kPpapiFlashArgs,
[email protected]4287a3d2011-06-13 23:56:511599 switches::kPpapiFlashPath,
1600 switches::kPpapiFlashVersion,
1601 switches::kProfilingAtStart,
1602 switches::kProfilingFile,
1603 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371604 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511605 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:381606 switches::kWhitelistedExtensionID,
[email protected]499e7c52013-10-04 16:03:091607 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:511608 };
1609
1610 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1611 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171612 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381613 static const char* const kSwitchNames[] = {
[email protected]558878cc82013-11-09 01:25:511614 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]c8d02992013-07-31 22:16:511615 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271616 extensions::switches::kExtensionsOnChromeURLs,
[email protected]a446534d2012-02-09 00:07:381617 switches::kWhitelistedExtensionID,
1618 };
1619
1620 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1621 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511622 } else if (process_type == switches::kPluginProcess) {
1623 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441624#if defined(OS_CHROMEOS)
1625 chromeos::switches::kLoginProfile,
1626#endif
[email protected]4287a3d2011-06-13 23:56:511627 switches::kMemoryProfiling,
1628 switches::kSilentDumpOnDCHECK,
[email protected]4287a3d2011-06-13 23:56:511629 };
1630
1631 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1632 arraysize(kSwitchNames));
1633 } else if (process_type == switches::kZygoteProcess) {
1634 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511635 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501636 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511637 switches::kPpapiFlashPath,
1638 switches::kPpapiFlashVersion,
1639 };
1640
1641 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1642 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111643 } else if (process_type == switches::kGpuProcess) {
1644 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1645 // because GPU is expected to be unreliable.
1646 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1647 !command_line->HasSwitch(switches::kDisableBreakpad))
1648 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301649 }
[email protected]6f08af82011-09-15 01:19:031650
1651 // The command line switch kEnableBenchmarking needs to be specified along
1652 // with the kEnableStatsTable switch to ensure that the stats table global
1653 // is initialized correctly.
1654 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1655 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301656}
1657
1658std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431659 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351660 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301661 return g_browser_process->GetApplicationLocale();
1662}
1663
[email protected]597a867b2011-11-18 18:31:201664std::string ChromeContentBrowserClient::GetAcceptLangs(
1665 content::BrowserContext* context) {
1666 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371667 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081668}
1669
[email protected]9ec0f452012-05-31 15:58:531670gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221671 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531672 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081673}
1674
[email protected]a2176792011-05-08 19:30:491675bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091676 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191677 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201678 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321679 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201680 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051681 return io_data->GetCookieSettings()->
1682 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491683}
1684
[email protected]ed24fad2011-05-10 22:44:011685bool ChromeContentBrowserClient::AllowGetCookie(
1686 const GURL& url,
1687 const GURL& first_party,
1688 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201689 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011690 int render_process_id,
[email protected]f3add922013-12-20 23:17:161691 int render_frame_id) {
[email protected]ed24fad2011-05-10 22:44:011692 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201693 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051694 bool allow = io_data->GetCookieSettings()->
1695 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011696
[email protected]8093a542011-05-13 07:29:321697 BrowserThread::PostTask(
1698 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031699 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]f7fa5b62014-03-19 15:20:061700 render_frame_id, url, first_party, cookie_list, !allow, true));
[email protected]ed24fad2011-05-10 22:44:011701 return allow;
1702}
1703
1704bool ChromeContentBrowserClient::AllowSetCookie(
1705 const GURL& url,
1706 const GURL& first_party,
1707 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201708 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011709 int render_process_id,
[email protected]f3add922013-12-20 23:17:161710 int render_frame_id,
[email protected]ed24fad2011-05-10 22:44:011711 net::CookieOptions* options) {
1712 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201713 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051714 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1715 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1716
[email protected]8093a542011-05-13 07:29:321717 BrowserThread::PostTask(
1718 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031719 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]f3add922013-12-20 23:17:161720 render_frame_id, url, first_party, cookie_line, *options,
[email protected]fd473d12012-04-05 11:38:431721 !allow));
[email protected]ed24fad2011-05-10 22:44:011722 return allow;
1723}
1724
[email protected]d5a19162011-06-30 18:51:541725bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201726 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541727 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201728 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431729 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1730 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261731
[email protected]bf510ed2012-06-05 08:31:431732 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1733 // Could we even support per-origin settings?
1734 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541735}
1736
[email protected]5c5a88e2011-11-12 00:45:351737bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351738 const GURL& url,
[email protected]96920152013-12-04 21:00:161739 const base::string16& name,
1740 const base::string16& display_name,
[email protected]5c5a88e2011-11-12 00:45:351741 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201742 content::ResourceContext* context,
[email protected]b765deb2013-12-18 06:43:301743 const std::vector<std::pair<int, int> >& render_frames) {
[email protected]5c5a88e2011-11-12 00:45:351744 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201745 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351746 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1747 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1748
[email protected]62151052012-02-01 18:40:481749 // Record access to database for potential display in UI.
1750 std::vector<std::pair<int, int> >::const_iterator i;
[email protected]b765deb2013-12-18 06:43:301751 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
[email protected]62151052012-02-01 18:40:481752 BrowserThread::PostTask(
1753 BrowserThread::UI, FROM_HERE,
1754 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1755 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351756 }
1757
1758 return allow;
1759}
1760
1761bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351762 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201763 content::ResourceContext* context,
[email protected]b765deb2013-12-18 06:43:301764 const std::vector<std::pair<int, int> >& render_frames) {
[email protected]5c5a88e2011-11-12 00:45:351765 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201766 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351767 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1768 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1769
[email protected]62151052012-02-01 18:40:481770 // Record access to file system for potential display in UI.
1771 std::vector<std::pair<int, int> >::const_iterator i;
[email protected]b765deb2013-12-18 06:43:301772 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
[email protected]62151052012-02-01 18:40:481773 BrowserThread::PostTask(
1774 BrowserThread::UI, FROM_HERE,
1775 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1776 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351777 }
1778
1779 return allow;
1780}
1781
[email protected]7c5ff9a2012-03-02 07:42:491782bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1783 const GURL& url,
[email protected]96920152013-12-04 21:00:161784 const base::string16& name,
[email protected]7c5ff9a2012-03-02 07:42:491785 content::ResourceContext* context,
[email protected]b765deb2013-12-18 06:43:301786 const std::vector<std::pair<int, int> >& render_frames) {
[email protected]7c5ff9a2012-03-02 07:42:491787 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1788 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1789 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1790 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1791
1792 // Record access to IndexedDB for potential display in UI.
1793 std::vector<std::pair<int, int> >::const_iterator i;
[email protected]b765deb2013-12-18 06:43:301794 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
[email protected]7c5ff9a2012-03-02 07:42:491795 BrowserThread::PostTask(
1796 BrowserThread::UI, FROM_HERE,
1797 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1798 i->first, i->second, url, name, !allow));
1799 }
1800
1801 return allow;
1802}
1803
[email protected]33ad6ce92013-08-27 14:39:081804net::URLRequestContext*
1805ChromeContentBrowserClient::OverrideRequestContextForURL(
1806 const GURL& url, content::ResourceContext* context) {
1807 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1808 if (url.SchemeIs(extensions::kExtensionScheme)) {
1809 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1810 return io_data->extensions_request_context();
1811 }
1812
1813 return NULL;
1814}
1815
[email protected]317f96c92011-05-31 06:53:411816QuotaPermissionContext*
1817ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1818 return new ChromeQuotaPermissionContext();
1819}
1820
[email protected]848dd042011-06-04 18:24:031821void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171822 int render_process_id,
[email protected]1a4e9752013-12-31 20:10:581823 int render_frame_id,
[email protected]4cf611e32012-02-13 16:06:171824 int cert_error,
1825 const net::SSLInfo& ssl_info,
1826 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021827 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031828 bool overridable,
[email protected]d9be47702012-05-16 03:41:221829 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171830 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001831 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021832 if (resource_type != ResourceType::MAIN_FRAME) {
1833 // A sub-resource has a certificate error. The user doesn't really
1834 // have a context for making the right decision, so block the
1835 // request hard, without an info bar to allow showing the insecure
1836 // content.
[email protected]8c965c22013-05-23 19:28:001837 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021838 return;
1839 }
1840
[email protected]f9034cf2011-07-21 12:43:411841 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]1a4e9752013-12-31 20:10:581842 content::RenderFrameHost* render_frame_host =
1843 content::RenderFrameHost::FromID(render_process_id, render_frame_id);
[email protected]1a4e9752013-12-31 20:10:581844 WebContents* tab = WebContents::FromRenderFrameHost(render_frame_host);
[email protected]f9034cf2011-07-21 12:43:411845 if (!tab) {
1846 NOTREACHED();
1847 return;
1848 }
[email protected]09667f02014-01-06 15:37:571849
1850 prerender::PrerenderContents* prerender_contents =
[email protected]294084d2014-01-06 22:22:021851 prerender::PrerenderContents::FromWebContents(tab);
[email protected]09667f02014-01-06 15:37:571852 if (prerender_contents) {
1853 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
1854 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
1855 return;
[email protected]f9034cf2011-07-21 12:43:411856 }
1857
[email protected]1e87df32012-09-12 04:53:191858#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231859 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1860 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1861 if (captive_portal_tab_helper)
1862 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191863#endif
1864
[email protected]f9034cf2011-07-21 12:43:411865 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221866 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1867 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031868}
1869
[email protected]c99c442e2011-08-24 11:37:301870void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451871 int render_process_id,
[email protected]094c8772013-12-21 17:54:501872 int render_frame_id,
[email protected]7a593db2012-02-13 21:19:401873 const net::HttpNetworkSession* network_session,
1874 net::SSLCertRequestInfo* cert_request_info,
1875 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]094c8772013-12-21 17:54:501876 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID(
1877 render_process_id, render_frame_id);
[email protected]294084d2014-01-06 22:22:021878 WebContents* tab = WebContents::FromRenderFrameHost(rfh);
1879 if (!tab) {
[email protected]094c8772013-12-21 17:54:501880 NOTREACHED();
1881 return;
1882 }
1883
[email protected]294084d2014-01-06 22:22:021884 prerender::PrerenderContents* prerender_contents =
1885 prerender::PrerenderContents::FromWebContents(tab);
1886 if (prerender_contents) {
1887 prerender_contents->Destroy(
1888 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
[email protected]8ec26472011-06-06 16:52:451889 return;
1890 }
1891
[email protected]791879c2013-12-17 07:22:411892 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
1893 DCHECK(requesting_url.is_valid())
1894 << "Invalid URL string: https://"
1895 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:451896
[email protected]627e0512011-12-21 22:55:301897 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]5bcdd99d2013-12-23 18:28:301898 scoped_ptr<base::Value> filter(
[email protected]6786bf402011-12-03 15:19:451899 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1900 requesting_url,
1901 requesting_url,
1902 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1903 std::string(), NULL));
1904
1905 if (filter.get()) {
1906 // Try to automatically select a client certificate.
[email protected]5bcdd99d2013-12-23 18:28:301907 if (filter->IsType(base::Value::TYPE_DICTIONARY)) {
1908 base::DictionaryValue* filter_dict =
1909 static_cast<base::DictionaryValue*>(filter.get());
[email protected]6786bf402011-12-03 15:19:451910
1911 const std::vector<scoped_refptr<net::X509Certificate> >&
1912 all_client_certs = cert_request_info->client_certs;
1913 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091914 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451915 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091916 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451917 return;
1918 }
1919 }
1920 } else {
1921 NOTREACHED();
1922 }
1923 }
1924
[email protected]11feec322012-09-18 03:58:521925 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1926 if (!ssl_tab_helper) {
1927 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451928 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141929 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401930 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451931 return;
1932 }
[email protected]11feec322012-09-18 03:58:521933 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401934 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451935}
1936
[email protected]3b455502012-12-11 18:22:581937void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451938 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581939 net::CertificateMimeType cert_type,
1940 const void* cert_data,
1941 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451942 int render_process_id,
1943 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581944 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1945 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451946}
1947
[email protected]dc73a7b2012-03-25 15:27:181948content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561949 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181950}
1951
[email protected]941623e2011-06-07 23:06:041952void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1953 const GURL& source_origin,
1954 int callback_context,
1955 int render_process_id,
1956 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111957#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021958 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1959 WebContents* contents =
1960 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1961 if (!contents) {
[email protected]941623e2011-06-07 23:06:041962 NOTREACHED();
1963 return;
1964 }
1965
[email protected]d0d9c3ee2012-06-19 03:07:021966 // Skip showing the infobar if the request comes from an extension, and that
1967 // extension has the 'notify' permission. (If the extension does not have the
1968 // permission, the user will still be prompted.)
1969 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]38427a12013-11-09 17:34:201970 InfoMap* extension_info_map =
[email protected]c7cd5942013-04-30 03:31:011971 extensions::ExtensionSystem::Get(profile)->info_map();
1972 DesktopNotificationService* notification_service =
1973 DesktopNotificationServiceFactory::GetForProfile(profile);
1974 const Extension* extension = NULL;
1975 if (extension_info_map) {
[email protected]289c44b2013-12-17 03:26:571976 extensions::ExtensionSet extensions;
[email protected]c7cd5942013-04-30 03:31:011977 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1978 source_origin, render_process_id,
1979 extensions::APIPermission::kNotification, &extensions);
[email protected]289c44b2013-12-17 03:26:571980 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
[email protected]c7cd5942013-04-30 03:31:011981 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381982 if (notification_service->IsNotifierEnabled(NotifierId(
1983 NotifierId::APPLICATION, (*iter)->id()))) {
[email protected]cadac622013-06-11 16:46:361984 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011985 break;
1986 }
1987 }
1988 }
[email protected]eb4832a2012-12-08 01:57:521989 RenderViewHost* rvh =
1990 RenderViewHost::FromID(render_process_id, render_view_id);
1991 if (IsExtensionWithPermissionOrSuggestInConsole(
1992 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021993 if (rvh)
1994 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1995 return;
1996 }
1997
[email protected]c7cd5942013-04-30 03:31:011998 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021999 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:112000#else
2001 NOTIMPLEMENTED();
2002#endif
[email protected]941623e2011-06-07 23:06:042003}
2004
[email protected]a1221aea2013-11-07 01:31:302005blink::WebNotificationPresenter::Permission
[email protected]941623e2011-06-07 23:06:042006 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:022007 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:202008 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:022009 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:112010#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:042011 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]5c129792013-07-10 02:08:482012
[email protected]df02aca2012-02-09 21:03:202013 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9afacd22013-11-13 20:23:312014 InfoMap* extension_info_map = io_data->GetExtensionInfoMap();
[email protected]941623e2011-06-07 23:06:042015
[email protected]9afacd22013-11-13 20:23:312016 // We want to see if there is an extension that hasn't been manually disabled
2017 // that has the notifications permission and applies to this security origin.
2018 // First, get the list of extensions with permission for the origin.
[email protected]289c44b2013-12-17 03:26:572019 extensions::ExtensionSet extensions;
[email protected]9afacd22013-11-13 20:23:312020 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
2021 source_origin, render_process_id,
2022 extensions::APIPermission::kNotification, &extensions);
[email protected]289c44b2013-12-17 03:26:572023 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
[email protected]9afacd22013-11-13 20:23:312024 iter != extensions.end(); ++iter) {
2025 // Then, check to see if it's been disabled by the user.
2026 if (!extension_info_map->AreNotificationsDisabled((*iter)->id()))
2027 return blink::WebNotificationPresenter::PermissionAllowed;
[email protected]c7cd5942013-04-30 03:31:012028 }
2029
[email protected]9afacd22013-11-13 20:23:312030 // No enabled extensions exist, so check the normal host content settings.
2031 HostContentSettingsMap* host_content_settings_map =
2032 io_data->GetHostContentSettingsMap();
2033 ContentSetting setting = host_content_settings_map->GetContentSetting(
2034 source_origin,
2035 source_origin,
2036 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
2037 NO_RESOURCE_IDENTIFIER);
2038
2039 if (setting == CONTENT_SETTING_ALLOW)
2040 return blink::WebNotificationPresenter::PermissionAllowed;
2041 if (setting == CONTENT_SETTING_BLOCK)
2042 return blink::WebNotificationPresenter::PermissionDenied;
[email protected]a1221aea2013-11-07 01:31:302043 return blink::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:112044#else
[email protected]a1221aea2013-11-07 01:31:302045 return blink::WebNotificationPresenter::PermissionAllowed;
[email protected]5fd2e842012-03-01 00:29:112046#endif
[email protected]941623e2011-06-07 23:06:042047}
2048
2049void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:172050 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:042051 int render_process_id,
2052 int render_view_id,
2053 bool worker) {
[email protected]5fd2e842012-03-01 00:29:112054#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:042055 RenderViewHost* rvh = RenderViewHost::FromID(
2056 render_process_id, render_view_id);
2057 if (!rvh) {
2058 NOTREACHED();
2059 return;
2060 }
2061
[email protected]9f76c1e2012-03-05 15:15:582062 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:302063 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:042064 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:372065 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042066 service->ShowDesktopNotification(
2067 params, render_process_id, render_view_id,
2068 worker ? DesktopNotificationService::WorkerNotification :
2069 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:112070#else
2071 NOTIMPLEMENTED();
2072#endif
[email protected]941623e2011-06-07 23:06:042073}
2074
2075void ChromeContentBrowserClient::CancelDesktopNotification(
2076 int render_process_id,
2077 int render_view_id,
2078 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:112079#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:042080 RenderViewHost* rvh = RenderViewHost::FromID(
2081 render_process_id, render_view_id);
2082 if (!rvh) {
2083 NOTREACHED();
2084 return;
2085 }
2086
[email protected]9f76c1e2012-03-05 15:15:582087 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:302088 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:042089 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:372090 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042091 service->CancelDesktopNotification(
2092 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:112093#else
2094 NOTIMPLEMENTED();
2095#endif
[email protected]941623e2011-06-07 23:06:042096}
2097
[email protected]9f3fba52011-06-08 20:37:192098bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:352099 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:572100 const GURL& opener_top_level_frame_url,
[email protected]34eec7ffe32011-11-02 23:49:022101 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:192102 WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:232103 const GURL& target_url,
2104 const content::Referrer& referrer,
2105 WindowOpenDisposition disposition,
2106 const WebWindowFeatures& features,
2107 bool user_gesture,
2108 bool opener_suppressed,
[email protected]df02aca2012-02-09 21:03:202109 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:012110 int render_process_id,
[email protected]190e5e22013-07-27 05:59:232111 bool is_guest,
2112 int opener_id,
[email protected]03b6d552012-03-29 04:03:012113 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:192114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:012115
2116 *no_javascript_access = false;
2117
[email protected]5e5f55e262c52013-09-12 00:27:192118 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]38427a12013-11-09 17:34:202119 InfoMap* map = io_data->GetExtensionInfoMap();
[email protected]5e5f55e262c52013-09-12 00:27:192120
[email protected]9f3fba52011-06-08 20:37:192121 // If the opener is trying to create a background window but doesn't have
2122 // the appropriate permission, fail the attempt.
[email protected]6940eef82013-09-11 11:58:412123 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]03b6d552012-03-29 04:03:012124 if (!map->SecurityOriginHasAPIPermission(
2125 source_origin,
2126 render_process_id,
[email protected]c2e66e12012-06-27 06:27:062127 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:012128 return false;
2129 }
2130
[email protected]7b54ca02012-03-02 18:06:532131 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2132 // return a recently installed Extension even if this CanCreateWindow call
2133 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:012134 // because the permission check above would have caused an early return
2135 // already. We must use the full URL to find hosted apps, though, and not
2136 // just the origin.
[email protected]be9915fb2013-07-18 09:28:552137 const Extension* extension =
2138 map->extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:292139 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:012140 *no_javascript_access = true;
[email protected]190e5e22013-07-27 05:59:232141
2142 return true;
[email protected]9f3fba52011-06-08 20:37:192143 }
[email protected]056efdc2013-04-06 00:14:532144
2145 // No new browser window (popup or tab) in app mode.
2146 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
2147 chrome::IsRunningInForcedAppMode()) {
2148 return false;
2149 }
2150
[email protected]190e5e22013-07-27 05:59:232151 if (is_guest)
2152 return true;
2153
[email protected]190e5e22013-07-27 05:59:232154 HostContentSettingsMap* content_settings =
2155 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap();
[email protected]916615b2013-09-11 18:19:442156 BlockedWindowParams blocked_params(target_url,
2157 referrer,
2158 disposition,
2159 features,
2160 user_gesture,
2161 opener_suppressed,
2162 render_process_id,
2163 opener_id);
[email protected]190e5e22013-07-27 05:59:232164
[email protected]7f53dff2013-08-05 10:45:502165 if (!user_gesture && !CommandLine::ForCurrentProcess()->HasSwitch(
2166 switches::kDisablePopupBlocking)) {
[email protected]931bc922013-09-11 21:42:572167 if (content_settings->GetContentSetting(opener_top_level_frame_url,
2168 opener_top_level_frame_url,
[email protected]190e5e22013-07-27 05:59:232169 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]916615b2013-09-11 18:19:442170 std::string()) !=
[email protected]190e5e22013-07-27 05:59:232171 CONTENT_SETTING_ALLOW) {
[email protected]916615b2013-09-11 18:19:442172 BrowserThread::PostTask(BrowserThread::UI,
2173 FROM_HERE,
2174 base::Bind(&HandleBlockedPopupOnUIThread,
2175 blocked_params));
2176 return false;
[email protected]190e5e22013-07-27 05:59:232177 }
[email protected]916615b2013-09-11 18:19:442178 }
[email protected]190e5e22013-07-27 05:59:232179
[email protected]916615b2013-09-11 18:19:442180#if defined(OS_ANDROID)
2181 if (SingleTabModeTabHelper::IsRegistered(render_process_id, opener_id)) {
[email protected]190e5e22013-07-27 05:59:232182 BrowserThread::PostTask(BrowserThread::UI,
2183 FROM_HERE,
[email protected]916615b2013-09-11 18:19:442184 base::Bind(&HandleSingleTabModeBlockOnUIThread,
2185 blocked_params));
[email protected]190e5e22013-07-27 05:59:232186 return false;
2187 }
[email protected]916615b2013-09-11 18:19:442188#endif
[email protected]190e5e22013-07-27 05:59:232189
[email protected]9f3fba52011-06-08 20:37:192190 return true;
2191}
2192
2193std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:202194 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:192195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2196 // Check if it's an extension-created worker, in which case we want to use
2197 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:202198 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:192199 const Extension* extension =
2200 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
2201 return extension ? extension->name() : std::string();
2202}
2203
[email protected]99907362012-01-11 05:41:402204void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2205 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:172206}
2207
[email protected]7a06d282013-05-03 04:39:332208// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:022209content::SpeechRecognitionManagerDelegate*
2210 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002211#if defined(ENABLE_INPUT_SPEECH)
2212 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
[email protected]a03f2d32012-03-14 00:26:322213#else
[email protected]855e18b2013-07-08 21:02:002214 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
2215 // need the base delegate without the bubble UI.
2216 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:322217#endif
[email protected]66cfec62012-02-24 17:57:512218}
2219
[email protected]ae6e9912011-07-27 01:18:282220net::NetLog* ChromeContentBrowserClient::GetNetLog() {
2221 return g_browser_process->net_log();
2222}
2223
[email protected]32538d92011-08-25 00:09:232224AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
2225 return new ChromeAccessTokenStore();
2226}
2227
[email protected]dbae6b02011-06-29 23:51:412228bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:012229 return true;
[email protected]dbae6b02011-06-29 23:51:412230}
2231
[email protected]64d69de42012-02-06 00:19:542232void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:322233 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:062234 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582235 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:062236 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062237
[email protected]33b79542013-10-18 11:18:452238 // Fill per-script font preferences. These are not registered on Android
2239 // - http://crbug.com/308033.
2240#if !defined(OS_ANDROID)
[email protected]f3986f82012-01-03 20:00:062241 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542242 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:062243 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542244 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:062245 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542246 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062247 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542248 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062249 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542250 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:062251 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542252 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:032253 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
2254 &web_prefs->pictograph_font_family_map);
[email protected]33b79542013-10-18 11:18:452255#endif
[email protected]f3986f82012-01-03 20:00:062256
[email protected]64d69de42012-02-06 00:19:542257 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:402258 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:542259 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:402260 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:542261 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:402262 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:542263 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:402264 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:062265
[email protected]ddf72142012-05-22 04:52:402266 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062267
[email protected]64d69de42012-02-06 00:19:542268 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:402269 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:542270 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:062271 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:542272 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:062273 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
[email protected]5bcdd99d2013-12-23 18:28:302274 const base::DictionaryValue* inspector_settings =
[email protected]f3986f82012-01-03 20:00:062275 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2276 if (inspector_settings) {
[email protected]5bcdd99d2013-12-23 18:28:302277 for (base::DictionaryValue::Iterator iter(*inspector_settings);
2278 !iter.IsAtEnd();
[email protected]c40ef1c2013-02-25 18:42:182279 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062280 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182281 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542282 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182283 std::make_pair(iter.key(), value));
2284 }
[email protected]f3986f82012-01-03 20:00:062285 }
2286 }
[email protected]64d69de42012-02-06 00:19:542287 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062288
[email protected]ddf72142012-05-22 04:52:402289 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542290 web_prefs->javascript_enabled = false;
2291 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2292 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402293 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542294 web_prefs->plugins_enabled = false;
2295 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2296 web_prefs->java_enabled = false;
2297 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402298 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062299
[email protected]64d69de42012-02-06 00:19:542300 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2301 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062302
[email protected]64d69de42012-02-06 00:19:542303 web_prefs->allow_displaying_insecure_content =
2304 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2305 web_prefs->allow_running_insecure_content =
2306 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322307#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:052308 web_prefs->font_scale_factor =
2309 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2310 web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment();
[email protected]d3b935f2012-10-19 23:14:322311 web_prefs->force_enable_zoom =
2312 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
2313#endif
[email protected]5c915252013-05-07 13:15:392314
[email protected]af4256d52013-06-04 20:39:072315#if defined(OS_ANDROID)
2316 web_prefs->password_echo_enabled =
2317 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2318#else
[email protected]9d06d88d2012-02-23 22:37:082319 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072320#endif
2321
[email protected]cfadadd2013-04-03 04:43:022322 web_prefs->asynchronous_spell_checking_enabled = true;
2323 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572324
[email protected]64d69de42012-02-06 00:19:542325 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062326 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542327 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062328 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542329 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062330 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2331
2332 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542333 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062334 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542335 web_prefs->default_encoding);
2336 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402337 prefs->ClearPref(prefs::kDefaultCharset);
2338 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062339 }
[email protected]64d69de42012-02-06 00:19:542340 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062341
[email protected]299d7f12012-05-23 05:31:152342 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232343 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132344 ExtensionService* service =
2345 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062346 if (service) {
[email protected]1e6e2ea2014-01-04 02:01:402347 const GURL& site_url = rvh->GetSiteInstance()->GetSiteURL();
2348 const Extension* extension =
2349 service->extensions()->GetByID(site_url.host());
[email protected]1bc28312012-11-08 08:31:532350 // Ensure that we are only granting extension preferences to URLs with
2351 // the correct scheme. Without this check, chrome-guest:// schemes used by
2352 // webview tags as well as hosts that happen to match the id of an
2353 // installed extension would get the wrong preferences.
[email protected]1e6e2ea2014-01-04 02:01:402354 if (site_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532355 extension_webkit_preferences::SetPreferences(
2356 extension, view_type, web_prefs);
2357 }
[email protected]f3986f82012-01-03 20:00:062358 }
2359
[email protected]cb2edf22013-04-01 20:25:232360 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542361 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232362 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062363 // Disable all kinds of acceleration for background pages.
2364 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542365 web_prefs->force_compositing_mode = false;
2366 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062367 }
[email protected]2e21fe292012-03-02 22:52:322368
[email protected]ff9300872014-01-22 11:09:322369#if defined(OS_CHROMEOS)
[email protected]2e21fe292012-03-02 22:52:322370 // Override the default of suppressing HW compositing for WebUI pages for the
2371 // file manager, which is implemented using WebUI but wants HW acceleration
2372 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532373 if (url.SchemeIs(extensions::kExtensionScheme) &&
[email protected]2de96a52013-08-14 01:18:092374 url.host() == file_manager::kFileManagerAppId) {
[email protected]2e21fe292012-03-02 22:52:322375 web_prefs->accelerated_compositing_enabled = true;
2376 web_prefs->accelerated_2d_canvas_enabled = true;
2377 }
2378#endif
[email protected]181a95ee2011-07-12 19:26:362379}
2380
2381void ChromeContentBrowserClient::UpdateInspectorSetting(
2382 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062383 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582384 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062385 DictionaryPrefUpdate update(
2386 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2387 prefs::kWebKitInspectorSettings);
[email protected]5bcdd99d2013-12-23 18:28:302388 base::DictionaryValue* inspector_settings = update.Get();
2389 inspector_settings->SetWithoutPathExpansion(
2390 key, base::Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362391}
2392
[email protected]b8148ac2011-07-13 22:03:252393void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2394 BrowserURLHandler* handler) {
2395 // Add the default URL handlers.
2396 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2397 BrowserURLHandler::null_handler());
2398 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2399 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2400
[email protected]b3adbd02011-11-30 22:23:272401 // about: handler. Must come before chrome: handler, since it will
2402 // rewrite about: urls to chrome: URLs and then expect chrome: to
2403 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252404 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2405 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:032406
2407 // Handler to rewrite chrome://newtab for InstantExtended.
2408 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2409 &chrome::HandleNewTabURLReverseRewrite);
2410
[email protected]b8148ac2011-07-13 22:03:252411 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242412 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252413}
2414
2415void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372416 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582417 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472418 BrowsingDataRemover* remover =
2419 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552420 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2421 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252422 // BrowsingDataRemover takes care of deleting itself when done.
2423}
2424
2425void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372426 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582427 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472428 BrowsingDataRemover* remover =
2429 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232430 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552431 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252432 // BrowsingDataRemover takes care of deleting itself when done.
2433}
2434
[email protected]650b2d52013-02-10 03:41:452435base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:492436 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:322437}
2438
[email protected]c9b6eb62011-10-18 20:49:392439std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2440 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2441}
2442
[email protected]b7631cc2012-09-15 05:08:382443void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2444 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542445#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382446 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2447 scoped_ptr<ppapi::host::HostFactory>(
2448 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542449#endif
[email protected]b7631cc2012-09-15 05:08:382450}
2451
[email protected]0c7193742012-11-07 19:05:032452content::BrowserPpapiHost*
2453 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2454 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132455 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032456 while (!iter.Done()) {
[email protected]7c766e92013-11-22 20:44:022457 nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>(
2458 iter.GetDelegate());
[email protected]0c7193742012-11-07 19:05:032459 if (host->process() &&
2460 host->process()->GetData().id == plugin_process_id) {
2461 // Found the plugin.
2462 return host->browser_ppapi_host();
2463 }
2464 ++iter;
2465 }
2466 return NULL;
2467}
2468
[email protected]7b38b192013-03-23 18:39:312469bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2470 content::BrowserContext* browser_context, const GURL& site_url) {
2471 if (CommandLine::ForCurrentProcess()->HasSwitch(
2472 switches::kEnableBrowserPluginForAllViewTypes))
2473 return true;
2474
[email protected]22aa4f82013-09-24 17:01:442475 if (content::HasWebUIScheme(site_url))
2476 return true;
2477
[email protected]7b38b192013-03-23 18:39:312478 Profile* profile = Profile::FromBrowserContext(browser_context);
2479 ExtensionService* service =
2480 extensions::ExtensionSystem::Get(profile)->extension_service();
2481 if (!service)
2482 return false;
2483
[email protected]be9915fb2013-07-18 09:28:552484 const Extension* extension =
2485 service->extensions()->GetExtensionOrAppByURL(site_url);
[email protected]7b38b192013-03-23 18:39:312486 if (!extension)
2487 return false;
2488
[email protected]c2d2f102013-04-29 16:42:582489 return extension->HasAPIPermission(APIPermission::kWebView) ||
2490 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312491}
2492
[email protected]38cd8f7f2012-06-15 22:06:072493bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582494 content::BrowserContext* browser_context,
2495 const GURL& url,
[email protected]dda54822013-06-15 01:26:392496 bool private_api,
[email protected]8b92ed182013-09-21 04:47:122497 const content::SocketPermissionRequest* params) {
[email protected]93f72062013-05-29 20:29:402498#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372499 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]289c44b2013-12-17 03:26:572500 const extensions::ExtensionSet* extension_set = NULL;
[email protected]9d450492013-06-13 23:08:372501 if (profile) {
2502 extension_set = extensions::ExtensionSystem::Get(profile)->
2503 extension_service()->extensions();
2504 }
[email protected]dda54822013-06-15 01:26:392505
2506 if (private_api) {
2507 // Access to private socket APIs is controlled by the whitelist.
2508 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2509 allowed_socket_origins_)) {
2510 return true;
2511 }
2512 } else {
2513 // Access to public socket APIs is controlled by extension permissions.
2514 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2515 extension_set) {
2516 const Extension* extension = extension_set->GetByID(url.host());
2517 if (extension) {
[email protected]8b92ed182013-09-21 04:47:122518 if (params) {
2519 extensions::SocketPermission::CheckParam check_params(
2520 params->type, params->host, params->port);
2521 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2522 extension, extensions::APIPermission::kSocket,
2523 &check_params)) {
2524 return true;
2525 }
2526 } else {
2527 if (extensions::PermissionsData::HasAPIPermission(
2528 extension, extensions::APIPermission::kSocket)) {
2529 return true;
2530 }
[email protected]dda54822013-06-15 01:26:392531 }
2532 }
2533 }
2534 }
2535
2536 // Allow both public and private APIs if the command line says so.
2537 return IsHostAllowedByCommandLine(url, extension_set,
2538 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402539#else
[email protected]a658d452012-03-02 12:45:292540 return false;
[email protected]93f72062013-05-29 20:29:402541#endif
[email protected]e461da2f2012-02-16 19:06:402542}
2543
[email protected]a28e3302013-02-03 03:50:432544ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2545 WebContents* web_contents) {
2546 return new ChromeSelectFilePolicy(web_contents);
2547}
2548
[email protected]7d9424702013-04-14 13:14:162549void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2550 std::vector<std::string>* additional_allowed_schemes) {
2551 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2552 additional_allowed_schemes);
[email protected]b3690f72014-02-17 00:32:482553 additional_allowed_schemes->push_back(content::kChromeDevToolsScheme);
[email protected]2d9748b22014-02-11 00:17:292554 additional_allowed_schemes->push_back(content::kChromeUIScheme);
[email protected]7d9424702013-04-14 13:14:162555 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2556}
2557
[email protected]c79859b82014-03-20 22:43:552558void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers(
2559 std::vector<fileapi::URLRequestAutoMountHandler>* handlers) {
2560}
2561
[email protected]f19bbf62013-07-09 01:22:322562void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:312563 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:532564 const base::FilePath& storage_partition_path,
[email protected]f19bbf62013-07-09 01:22:322565 ScopedVector<fileapi::FileSystemBackend>* additional_backends) {
[email protected]02250952013-04-24 23:52:532566#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032567 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]f19bbf62013-07-09 01:22:322568 additional_backends->push_back(new MediaFileSystemBackend(
[email protected]30a306f42013-06-10 03:09:032569 storage_partition_path,
2570 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]f19bbf62013-07-09 01:22:322571 MediaFileSystemBackend::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532572#endif
[email protected]b40015c2013-06-26 08:13:312573#if defined(OS_CHROMEOS)
[email protected]0ff5eb52013-07-10 20:35:312574 fileapi::ExternalMountPoints* external_mount_points =
2575 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:312576 DCHECK(external_mount_points);
[email protected]f19bbf62013-07-09 01:22:322577 chromeos::FileSystemBackend* backend =
2578 new chromeos::FileSystemBackend(
[email protected]6b154b3c2014-02-05 08:27:292579 new drive::FileSystemBackendDelegate,
[email protected]0ff5eb52013-07-10 20:35:312580 browser_context->GetSpecialStoragePolicy(),
[email protected]b40015c2013-06-26 08:13:312581 external_mount_points,
2582 fileapi::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:322583 backend->AddSystemMountPoints();
2584 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal));
2585 additional_backends->push_back(backend);
[email protected]b40015c2013-06-26 08:13:312586#endif
[email protected]445b7db2013-08-02 04:58:272587
[email protected]e86e2be2013-08-30 11:20:392588 additional_backends->push_back(
2589 new sync_file_system::SyncFileSystemBackend(
2590 Profile::FromBrowserContext(browser_context)));
[email protected]eab6105d2014-01-17 20:55:102591
[email protected]2188c8d2014-03-21 00:58:562592#if defined(ENABLE_SERVICE_DISCOVERY)
[email protected]eab6105d2014-01-17 20:55:102593 if (CommandLine::ForCurrentProcess()->HasSwitch(
2594 switches::kEnablePrivetStorage)) {
2595 additional_backends->push_back(
2596 new local_discovery::PrivetFileSystemBackend(
[email protected]7e503f92014-02-19 02:35:512597 fileapi::ExternalMountPoints::GetSystemInstance(),
2598 browser_context));
[email protected]eab6105d2014-01-17 20:55:102599 }
[email protected]7e503f92014-02-19 02:35:512600#endif
[email protected]02250952013-04-24 23:52:532601}
2602
[email protected]e60c0232011-11-11 19:56:352603#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182604void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2605 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382606 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082607 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392608#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452609 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392610 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2611 DCHECK(!data_path.empty());
2612
[email protected]0daaebfe2014-03-15 00:09:052613 int flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
[email protected]650b2d52013-02-10 03:41:452614 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392615 data_path.AppendASCII("chrome_100_percent.pak");
[email protected]0daaebfe2014-03-15 00:09:052616 base::File file(chrome_resources_pak, flags);
2617 DCHECK(file.IsValid());
[email protected]73592382013-01-18 19:22:372618 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]0daaebfe2014-03-15 00:09:052619 FileDescriptor(file.Pass())));
[email protected]29699c22012-10-03 23:57:392620
2621 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452622 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392623 GetLocaleFilePath(locale, false);
[email protected]0daaebfe2014-03-15 00:09:052624 file.Initialize(locale_pak, flags);
2625 DCHECK(file.IsValid());
[email protected]29699c22012-10-03 23:57:392626 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
[email protected]0daaebfe2014-03-15 00:09:052627 FileDescriptor(file.Pass())));
[email protected]40da3e0c2012-10-24 22:03:382628
[email protected]650b2d52013-02-10 03:41:452629 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372630 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
[email protected]0daaebfe2014-03-15 00:09:052631 file.Initialize(resources_pack_path, flags);
2632 DCHECK(file.IsValid());
[email protected]73592382013-01-18 19:22:372633 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
[email protected]0daaebfe2014-03-15 00:09:052634 FileDescriptor(file.Pass())));
[email protected]73592382013-01-18 19:22:372635
[email protected]0b818f72013-10-22 00:11:032636 if (breakpad::IsCrashReporterEnabled()) {
[email protected]0daaebfe2014-03-15 00:09:052637 file = breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2638 child_process_id);
2639 if (file.IsValid()) {
2640 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2641 FileDescriptor(file.Pass())));
2642 } else {
[email protected]82174aa2013-01-22 21:53:432643 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2644 "be disabled for this process.";
[email protected]82174aa2013-01-22 21:53:432645 }
[email protected]40da3e0c2012-10-24 22:03:382646 }
[email protected]40da3e0c2012-10-24 22:03:382647
2648#else
2649 int crash_signal_fd = GetCrashSignalFD(command_line);
2650 if (crash_signal_fd >= 0) {
2651 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2652 FileDescriptor(crash_signal_fd,
2653 false)));
2654 }
[email protected]29699c22012-10-03 23:57:392655#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302656}
[email protected]e60c0232011-11-11 19:56:352657#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302658
[email protected]4a65826d2011-08-25 16:04:012659#if defined(OS_WIN)
2660const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2661 return chrome::kBrowserResourcesDll;
2662}
[email protected]34f48682013-03-20 00:30:182663
2664void ChromeContentBrowserClient::PreSpawnRenderer(
2665 sandbox::TargetPolicy* policy,
2666 bool* success) {
2667 // This code is duplicated in nacl_exe_win_64.cc.
2668 // Allow the server side of a pipe restricted to the "chrome.nacl."
2669 // namespace so that it cannot impersonate other system or other chrome
2670 // service pipes.
2671 sandbox::ResultCode result = policy->AddRule(
2672 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2673 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2674 L"\\\\.\\pipe\\chrome.nacl.*");
2675 if (result != sandbox::SBOX_ALL_OK) {
2676 *success = false;
2677 return;
2678 }
2679
2680 // Renderers need to send named pipe handles and shared memory
2681 // segment handles to NaCl loader processes.
2682 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2683 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2684 L"File");
2685 if (result != sandbox::SBOX_ALL_OK) {
2686 *success = false;
2687 return;
2688 }
2689}
[email protected]4a65826d2011-08-25 16:04:012690#endif
2691
[email protected]a6868c22013-10-09 02:50:292692bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2693 content::BrowserContext* browser_context,
2694 const GURL& url) {
2695#if defined(ENABLE_PLUGINS)
2696 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]289c44b2013-12-17 03:26:572697 const extensions::ExtensionSet* extension_set = NULL;
[email protected]a6868c22013-10-09 02:50:292698 if (profile) {
2699 extension_set = extensions::ExtensionSystem::Get(profile)->
2700 extension_service()->extensions();
2701 }
2702 // TODO(teravest): Populate allowed_file_handle_origins_ when FileIO is moved
2703 // from the renderer to the browser.
2704 return IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2705 allowed_file_handle_origins_) ||
2706 IsHostAllowedByCommandLine(url, extension_set,
2707 switches::kAllowNaClFileHandleAPI);
2708#else
2709 return false;
2710#endif
2711}
2712
[email protected]8ddc6b7c2013-12-12 20:42:062713bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs() {
2714#if defined(ENABLE_PLUGINS)
2715 // Allow access for tests.
2716 if (CommandLine::ForCurrentProcess()->HasSwitch(
2717 switches::kEnablePepperTesting)) {
2718 return true;
2719 }
2720
2721 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
[email protected]5abe3e72013-12-19 18:58:542722 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown"
2723 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on
2724 // Chromium builds as well.
[email protected]8ddc6b7c2013-12-12 20:42:062725 return channel <= chrome::VersionInfo::CHANNEL_DEV;
2726#else
2727 return false;
2728#endif
2729}
2730
[email protected]30335fdf02014-02-26 19:51:272731#if defined(ENABLE_WEBRTC)
2732void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch(
2733 CommandLine* to_command_line,
2734 const CommandLine& from_command_line,
2735 VersionInfo::Channel channel) {
2736#if defined(OS_ANDROID)
2737 const VersionInfo::Channel kMaxDisableEncryptionChannel =
2738 VersionInfo::CHANNEL_BETA;
2739#else
2740 const VersionInfo::Channel kMaxDisableEncryptionChannel =
2741 VersionInfo::CHANNEL_DEV;
2742#endif
2743 if (channel <= kMaxDisableEncryptionChannel) {
2744 static const char* const kWebRtcDevSwitchNames[] = {
2745 switches::kDisableWebRtcEncryption,
2746 };
2747 to_command_line->CopySwitchesFrom(from_command_line,
2748 kWebRtcDevSwitchNames,
2749 arraysize(kWebRtcDevSwitchNames));
2750 }
2751}
2752#endif // defined(ENABLE_WEBRTC)
[email protected]8ddc6b7c2013-12-12 20:42:062753
[email protected]d977f9c2011-03-14 16:10:262754} // namespace chrome