blob: d97d2de5a1f23c05302d6364bf12633f1c62ce4e [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
[email protected]7c3228a2011-11-11 21:35:227#include <set>
[email protected]1033acd2012-02-08 08:46:278#include <utility>
[email protected]7c3228a2011-11-11 21:35:229#include <vector>
10
[email protected]317c58f02011-11-09 02:15:0311#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3012#include "base/command_line.h"
[email protected]eabbfb12013-04-05 23:28:3513#include "base/lazy_instance.h"
[email protected]29699c22012-10-03 23:57:3914#include "base/path_service.h"
[email protected]3853a4c2013-02-11 17:15:5715#include "base/prefs/pref_service.h"
[email protected]9eec53fe2013-10-30 20:21:1716#include "base/prefs/scoped_user_pref_update.h"
[email protected]e7463412013-06-10 22:53:4617#include "base/strings/string_number_conversions.h"
[email protected]135cb802013-06-09 16:44:2018#include "base/strings/utf_string_conversions.h"
[email protected]30a306f42013-06-10 03:09:0319#include "base/threading/sequenced_worker_pool.h"
[email protected]056efdc2013-04-06 00:14:5320#include "chrome/browser/app_mode/app_mode_utils.h"
[email protected]b8148ac2011-07-13 22:03:2521#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3022#include "chrome/browser/browser_process.h"
[email protected]5c129792013-07-10 02:08:4823#include "chrome/browser/browser_shutdown.h"
[email protected]b0cb5e82012-07-19 19:22:4724#include "chrome/browser/browsing_data/browsing_data_helper.h"
25#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1226#include "chrome/browser/character_encoding.h"
[email protected]43535512013-02-20 20:41:4127#include "chrome/browser/chrome_net_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4128#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5629#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0530#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4531#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3232#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0833#include "chrome/browser/defaults.h"
[email protected]b1d97272013-08-17 13:38:4934#include "chrome/browser/download/download_prefs.h"
[email protected]2b33dcd02012-03-18 01:34:1635#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]1deace22013-05-22 06:14:4636#include "chrome/browser/extensions/browser_permissions_policy_delegate.h"
[email protected]76411f412012-02-22 18:56:0637#include "chrome/browser/extensions/extension_host.h"
[email protected]d977f9c2011-03-14 16:10:2638#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0839#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2540#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0641#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]eb4832a2012-12-08 01:57:5242#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2343#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1244#include "chrome/browser/google/google_util.h"
[email protected]0533cc6d2013-06-27 22:44:0545#include "chrome/browser/guestview/adview/adview_guest.h"
[email protected]3f24f97c2013-11-17 21:53:3346#include "chrome/browser/guestview/guestview.h"
[email protected]0533cc6d2013-06-27 22:44:0547#include "chrome/browser/guestview/guestview_constants.h"
48#include "chrome/browser/guestview/webview/webview_guest.h"
[email protected]11158e2d2013-02-01 02:31:5649#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]95132f52013-04-12 02:19:0450#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
[email protected]a2b4c5c2013-10-18 02:06:0751#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
[email protected]ae6e9912011-07-27 01:18:2852#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0453#include "chrome/browser/notifications/desktop_notification_service.h"
54#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4255#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5656#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]190e5e22013-07-27 05:59:2357#include "chrome/browser/prerender/prerender_final_status.h"
[email protected]f9034cf2011-07-21 12:43:4158#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5059#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0760#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4161#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1462#include "chrome/browser/printing/printing_message_filter.h"
[email protected]7e75e4a2013-05-17 17:20:0363#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:1464#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3265#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0666#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1467#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3868#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4369#include "chrome/browser/search/instant_service.h"
70#include "chrome/browser/search/instant_service_factory.h"
71#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1472#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]914cf6712013-12-05 01:14:0673#include "chrome/browser/signin/principals_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0274#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3375#include "chrome/browser/speech/tts_message_filter.h"
[email protected]3b455502012-12-11 18:22:5876#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0377#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5278#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]180c66a62013-08-05 12:01:3679#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:4580#include "chrome/browser/tab_contents/tab_util.h"
[email protected]916615b2013-09-11 18:19:4481#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
[email protected]40aa8bb2013-08-23 20:28:2382#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
[email protected]a28e3302013-02-03 03:50:4383#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]329ac972013-06-21 15:24:2584#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:4485#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5086#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]4a65826d2011-08-25 16:04:0187#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1488#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3089#include "chrome/common/chrome_switches.h"
[email protected]50fa4d5f2013-11-05 00:53:2390#include "chrome/common/chrome_version_info.h"
[email protected]779dd282013-10-19 15:57:0291#include "chrome/common/env_vars.h"
[email protected]395045c2012-05-22 15:04:3892#include "chrome/common/extensions/extension_process_policy.h"
[email protected]561e33d52013-04-03 06:58:4393#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]157cc902012-11-02 06:31:5894#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:3495#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:3796#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:1297#include "chrome/common/pref_names.h"
[email protected]4de75262013-12-18 23:16:1298#include "chrome/common/profile_management_switches.h"
[email protected]3e69bc82011-05-26 23:22:3899#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09100#include "chrome/common/url_constants.h"
[email protected]264c0acac2013-10-01 13:33:30101#include "chrome/installer/util/google_update_settings.h"
[email protected]e8f3f9982013-05-10 20:59:53102#include "chromeos/chromeos_constants.h"
[email protected]ef42ee82013-11-01 05:26:13103#include "components/nacl/browser/nacl_browser.h"
[email protected]7c766e92013-11-22 20:44:02104#include "components/nacl/browser/nacl_host_message_filter.h"
105#include "components/nacl/browser/nacl_process_host.h"
[email protected]d5d383252013-07-04 14:44:32106#include "components/nacl/common/nacl_process_type.h"
[email protected]eba93c92014-01-07 17:34:17107#include "components/translate/core/common/translate_switches.h"
[email protected]75fee372013-03-06 00:42:44108#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43109#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30110#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38111#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03112#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31113#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03114#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59115#include "content/public/browser/child_process_security_policy.h"
[email protected]094c8772013-12-21 17:54:50116#include "content/public/browser/render_frame_host.h"
[email protected]f3b1a082011-11-18 00:34:30117#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33118#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05119#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33120#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19121#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10122#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43123#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18124#include "content/public/common/content_descriptors.h"
[email protected]22aa4f82013-09-24 17:01:44125#include "content/public/common/url_utils.h"
[email protected]38427a12013-11-09 17:34:20126#include "extensions/browser/info_map.h"
[email protected]98b6d942013-11-10 00:34:07127#include "extensions/browser/process_manager.h"
[email protected]cb2edf22013-04-01 20:25:23128#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42129#include "extensions/common/constants.h"
[email protected]e4452d32013-11-15 23:07:41130#include "extensions/common/extension.h"
[email protected]289c44b2013-12-17 03:26:57131#include "extensions/common/extension_set.h"
[email protected]558878cc82013-11-09 01:25:51132#include "extensions/common/manifest_handlers/background_info.h"
[email protected]301116c62013-11-26 10:37:45133#include "extensions/common/manifest_handlers/shared_module_info.h"
[email protected]474b1f72014-01-16 02:38:07134#include "extensions/common/manifest_handlers/web_accessible_resources_info.h"
[email protected]e4452d32013-11-15 23:07:41135#include "extensions/common/permissions/permissions_data.h"
[email protected]49d9b142013-07-19 08:50:27136#include "extensions/common/switches.h"
[email protected]c9b6eb62011-10-18 20:49:39137#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23138#include "grit/ui_resources.h"
[email protected]3b455502012-12-11 18:22:58139#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34140#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06141#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57142#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38143#include "ppapi/host/ppapi_host.h"
[email protected]8ddc6b7c2013-12-12 20:42:06144#include "ppapi/shared_impl/ppapi_switches.h"
[email protected]c9b6eb62011-10-18 20:49:39145#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08146#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24147#include "ui/message_center/message_center_util.h"
[email protected]b40015c2013-06-26 08:13:31148#include "webkit/browser/fileapi/external_mount_points.h"
[email protected]fab55e72013-05-31 07:06:18149#include "webkit/common/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:26150
[email protected]b48c9182011-10-26 18:03:30151#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38152#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18153#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38154#elif defined(OS_MACOSX)
155#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56156#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]0b818f72013-10-22 00:11:03157#include "components/breakpad/app/breakpad_mac.h"
[email protected]b48c9182011-10-26 18:03:30158#elif defined(OS_CHROMEOS)
159#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]f19bbf62013-07-09 01:22:32160#include "chrome/browser/chromeos/drive/file_system_backend_delegate.h"
161#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]5c915252013-05-07 13:15:39162#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49163#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]c94ac692013-07-27 00:50:10164#include "chrome/browser/chromeos/system/input_device_settings.h"
[email protected]931d1042013-04-05 17:50:44165#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26166#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30167#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09168#elif defined(OS_ANDROID)
[email protected]916615b2013-09-11 18:19:44169#include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
[email protected]81054f812012-08-30 00:47:09170#include "chrome/browser/chrome_browser_main_android.h"
[email protected]2b12c322013-09-19 06:53:56171#include "chrome/browser/media/encrypted_media_message_filter_android.h"
[email protected]29699c22012-10-03 23:57:39172#include "chrome/common/descriptors_android.h"
[email protected]0b818f72013-10-22 00:11:03173#include "components/breakpad/browser/crash_dump_manager_android.h"
[email protected]b48c9182011-10-26 18:03:30174#elif defined(OS_POSIX)
175#include "chrome/browser/chrome_browser_main_posix.h"
176#endif
177
[email protected]a220b5932013-09-21 03:47:44178#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]779dd282013-10-19 15:57:02179#include "base/debug/leak_annotations.h"
[email protected]b80f68432011-05-02 17:22:30180#include "base/linux_util.h"
[email protected]0b818f72013-10-22 00:11:03181#include "components/breakpad/app/breakpad_linux.h"
182#include "components/breakpad/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43183#endif
[email protected]b80f68432011-05-02 17:22:30184
[email protected]1e87df32012-09-12 04:53:19185#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
186#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
187#endif
188
[email protected]29699c22012-10-03 23:57:39189#if defined(OS_ANDROID)
190#include "ui/base/ui_base_paths.h"
[email protected]b255a8e0e82013-10-22 04:03:59191#include "ui/gfx/android/device_display_info.h"
[email protected]29699c22012-10-03 23:57:39192#endif
193
[email protected]d5bcd06f2013-04-21 08:07:24194#if !defined(OS_CHROMEOS)
195#include "chrome/browser/signin/signin_manager.h"
196#include "chrome/browser/signin/signin_manager_factory.h"
197#endif
198
[email protected]02250952013-04-24 23:52:53199#if !defined(OS_ANDROID)
[email protected]f19bbf62013-07-09 01:22:32200#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
[email protected]02250952013-04-24 23:52:53201#endif
202
[email protected]6ef98b5a2013-05-31 23:58:31203#if defined(ENABLE_WEBRTC)
204#include "chrome/browser/media/webrtc_logging_handler_host.h"
205#endif
206
[email protected]855e18b2013-07-08 21:02:00207#if defined(ENABLE_INPUT_SPEECH)
208#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h"
209#endif
210
[email protected]02a3dc122013-06-13 15:07:53211#if defined(FILE_MANAGER_EXTENSION)
[email protected]473c9a4f2013-09-05 03:09:46212#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]02a3dc122013-06-13 15:07:53213#endif
214
[email protected]e8b6ca02013-07-10 18:00:51215#if defined(TOOLKIT_GTK)
216#include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h"
217#endif
218
219#if defined(TOOLKIT_VIEWS)
220#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
221#endif
222
223#if defined(USE_ASH)
224#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
225#endif
226
227#if defined(USE_AURA)
228#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
229#endif
230
231#if defined(USE_X11)
232#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
233#endif
234
[email protected]c6ce08072013-07-31 07:48:53235#if defined(ENABLE_SPELLCHECK)
236#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
237#endif
238
[email protected]a1221aea2013-11-07 01:31:30239using blink::WebWindowFeatures;
[email protected]c7abd422012-09-25 00:20:08240using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47241using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03242using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39243using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31244using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59245using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08246using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00247using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11248using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33249using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13250using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06251using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34252using extensions::Extension;
[email protected]38427a12013-11-09 17:34:20253using extensions::InfoMap;
[email protected]1d5e58b2013-01-31 08:41:40254using extensions::Manifest;
[email protected]593d2a72013-07-26 08:48:38255using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39256
[email protected]c5dbef02011-05-13 05:06:09257namespace {
258
[email protected]eabbfb12013-04-05 23:28:35259// Cached version of the locale so we can return the locale on the I/O
260// thread.
261base::LazyInstance<std::string> g_io_thread_application_locale;
262
[email protected]93f72062013-05-29 20:29:40263#if defined(ENABLE_PLUGINS)
[email protected]10c39222013-11-13 20:09:25264const char* kPredefinedAllowedFileHandleOrigins[] = {
265 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
266 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
267};
268
[email protected]e461da2f2012-02-16 19:06:40269const char* kPredefinedAllowedSocketOrigins[] = {
270 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18271 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45272 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
273 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
274 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
275 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35276 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54277 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
278 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
279 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
280 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
281 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
282 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38283 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58284 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29285 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]3f6fca22013-08-12 23:13:42286 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
287 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
288 "4EB74897CB187C7633357C2FE832E0AD6A44883A", // see crbug.com/234789
289 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
290 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
291 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40292};
[email protected]93f72062013-05-29 20:29:40293#endif
[email protected]e461da2f2012-02-16 19:06:40294
[email protected]f8f93eb2012-09-25 03:06:24295// Returns a copy of the given url with its host set to given host and path set
296// to given path. Other parts of the url will be the same.
297GURL ReplaceURLHostAndPath(const GURL& url,
298 const std::string& host,
299 const std::string& path) {
300 url_canon::Replacements<char> replacements;
301 replacements.SetHost(host.c_str(),
302 url_parse::Component(0, host.length()));
303 replacements.SetPath(path.c_str(),
304 url_parse::Component(0, path.length()));
305 return url.ReplaceComponents(replacements);
306}
307
308// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
309GURL AddUberHost(const GURL& url) {
310 const std::string uber_host = chrome::kChromeUIUberHost;
311 const std::string new_path = url.host() + url.path();
312
313 return ReplaceURLHostAndPath(url, uber_host, new_path);
314}
315
[email protected]045bf7c2012-09-28 20:27:36316// If url->host() is "chrome" and url->path() has characters other than the
317// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
318// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24319bool RemoveUberHost(GURL* url) {
320 if (url->host() != chrome::kChromeUIUberHost)
321 return false;
322
[email protected]045bf7c2012-09-28 20:27:36323 if (url->path().empty() || url->path() == "/")
324 return false;
325
[email protected]f8f93eb2012-09-25 03:06:24326 const std::string old_path = url->path();
327
328 const std::string::size_type separator = old_path.find('/', 1);
329 std::string new_host;
330 std::string new_path;
331 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36332 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24333 } else {
334 new_host = old_path.substr(1, separator - 1);
335 new_path = old_path.substr(separator);
336 }
337
[email protected]44e8add2013-06-13 17:29:15338 // Do not allow URLs with paths empty before the first slash since we can't
339 // have an empty host. (e.g "foo://chrome//")
340 if (new_host.empty())
341 return false;
342
[email protected]f8f93eb2012-09-25 03:06:24343 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
344
[email protected]44e8add2013-06-13 17:29:15345 DCHECK(url->is_valid());
346
[email protected]f8f93eb2012-09-25 03:06:24347 return true;
348}
349
[email protected]b8148ac2011-07-13 22:03:25350// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42351bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24352 // Do not handle special URLs such as "about:foo"
353 if (!url->host().empty()) {
354 const GURL chrome_url = AddUberHost(*url);
355
356 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
357 // be called.
358 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
359 browser_context, chrome_url))
360 return true;
361 }
362
[email protected]863f70a2012-01-27 02:05:50363 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
364 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25365 return false;
366
[email protected]fe69558d2012-03-12 11:34:49367#if defined(OS_CHROMEOS)
368 // Special case : in ChromeOS in Guest mode bookmarks and history are
369 // disabled for security reasons. New tab page explains the reasons, so
370 // we redirect user to new tab page.
371 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
372 if (url->SchemeIs(chrome::kChromeUIScheme) &&
373 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
[email protected]b9171622013-10-01 22:05:23374#if defined(ENABLE_ENHANCED_BOOKMARKS)
375 url->DomainIs(chrome::kChromeUIEnhancedBookmarksHost) ||
376#endif
[email protected]fe69558d2012-03-12 11:34:49377 url->DomainIs(chrome::kChromeUIHistoryHost))) {
378 // Rewrite with new tab URL
379 *url = GURL(chrome::kChromeUINewTabURL);
380 }
381 }
382#endif
383
[email protected]b8148ac2011-07-13 22:03:25384 return true;
385}
386
[email protected]f8f93eb2012-09-25 03:06:24387// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
388// "chrome://foo/".
389bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
390 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
391 return false;
392
393 return RemoveUberHost(url);
394}
395
[email protected]8d3132f62011-10-12 07:13:42396// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
397// below. Extension, and isolated apps require different privileges to be
398// granted to their RenderProcessHosts. This classification allows us to make
399// sure URLs are served by hosts with the right set of privileges.
400enum RenderProcessHostPrivilege {
401 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45402 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42403 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45404 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42405};
406
407RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
408 const GURL& url,
409 ExtensionService* service) {
410 // Default to a normal renderer cause it is lower privileged. This should only
411 // occur if the URL on a site instance is either malformed, or uninitialized.
412 // If it is malformed, then there is no need for better privileges anyways.
413 // If it is uninitialized, but eventually settles on being an a scheme other
414 // than normal webrenderer, the navigation logic will correct us out of band
415 // anyways.
416 if (!url.is_valid())
417 return PRIV_NORMAL;
418
[email protected]885c0e92012-11-13 20:27:42419 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44420 const Extension* extension =
421 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43422 if (extension &&
423 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42424 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45425 if (extension && extension->is_hosted_app())
426 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42427
428 return PRIV_EXTENSION;
429 }
430
431 return PRIV_NORMAL;
432}
433
434RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30435 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46436 extensions::ProcessMap* process_map,
437 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46438 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30439 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46440 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21441 return PRIV_NORMAL;
442
[email protected]6f371442011-11-09 06:45:46443 for (std::set<std::string>::iterator iter = extension_ids.begin();
444 iter != extension_ids.end(); ++iter) {
445 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43446 if (extension &&
447 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42448 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45449 if (extension && extension->is_hosted_app())
450 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42451 }
452
[email protected]676f6ab2011-10-19 20:23:21453 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42454}
455
[email protected]6786bf402011-12-03 15:19:45456bool CertMatchesFilter(const net::X509Certificate& cert,
457 const base::DictionaryValue& filter) {
458 // TODO(markusheintz): This is the minimal required filter implementation.
459 // Implement a better matcher.
460
461 // An empty filter matches any client certificate since no requirements are
462 // specified at all.
463 if (filter.empty())
464 return true;
465
466 std::string common_name;
467 if (filter.GetString("ISSUER.CN", &common_name) &&
468 (cert.issuer().common_name == common_name)) {
469 return true;
470 }
471 return false;
472}
473
[email protected]1d51882f2013-11-12 01:59:02474#if !defined(OS_ANDROID)
[email protected]f3986f82012-01-03 20:00:06475// Fills |map| with the per-script font prefs under path |map_name|.
476void FillFontFamilyMap(const PrefService* prefs,
477 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53478 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]33b79542013-10-18 11:18:45479 // TODO: Get rid of the brute-force scan over possible (font family / script)
480 // combinations - see http://crbug.com/308095.
[email protected]f3986f82012-01-03 20:00:06481 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
482 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
483 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
484 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23485 if (!font_family.empty())
[email protected]cc2a2a22013-12-24 23:12:15486 (*map)[script] = base::UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06487 }
488}
489
[email protected]a1733df2012-06-22 11:24:18490#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]0b818f72013-10-22 00:11:03491breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
492 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02493 base::FilePath dumps_path;
494 PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
495 {
496 ANNOTATE_SCOPED_MEMORY_LEAK;
[email protected]0b818f72013-10-22 00:11:03497 breakpad::CrashHandlerHostLinux* crash_handler =
498 new breakpad::CrashHandlerHostLinux(
499 process_type, dumps_path, getenv(env_vars::kHeadless) == NULL);
[email protected]779dd282013-10-19 15:57:02500 crash_handler->StartUploaderThread();
501 return crash_handler;
502 }
503}
504
[email protected]a1733df2012-06-22 11:24:18505int GetCrashSignalFD(const CommandLine& command_line) {
[email protected]cd0f7af2014-01-16 23:50:39506 if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) {
[email protected]0b818f72013-10-22 00:11:03507 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02508 if (!crash_handler)
509 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18510 return crash_handler->GetDeathSignalSocket();
511 }
512
513 std::string process_type =
514 command_line.GetSwitchValueASCII(switches::kProcessType);
515
[email protected]779dd282013-10-19 15:57:02516 if (process_type == switches::kRendererProcess) {
[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(process_type);
520 return crash_handler->GetDeathSignalSocket();
521 }
[email protected]a1733df2012-06-22 11:24:18522
[email protected]779dd282013-10-19 15:57:02523 if (process_type == switches::kPluginProcess) {
[email protected]0b818f72013-10-22 00:11:03524 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02525 if (!crash_handler)
526 crash_handler = CreateCrashHandlerHost(process_type);
527 return crash_handler->GetDeathSignalSocket();
528 }
[email protected]a1733df2012-06-22 11:24:18529
[email protected]779dd282013-10-19 15:57:02530 if (process_type == switches::kPpapiPluginProcess) {
[email protected]0b818f72013-10-22 00:11:03531 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02532 if (!crash_handler)
533 crash_handler = CreateCrashHandlerHost(process_type);
534 return crash_handler->GetDeathSignalSocket();
535 }
[email protected]a1733df2012-06-22 11:24:18536
[email protected]779dd282013-10-19 15:57:02537 if (process_type == switches::kGpuProcess) {
[email protected]0b818f72013-10-22 00:11:03538 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02539 if (!crash_handler)
540 crash_handler = CreateCrashHandlerHost(process_type);
541 return crash_handler->GetDeathSignalSocket();
542 }
[email protected]a1733df2012-06-22 11:24:18543
544 return -1;
545}
546#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]1d51882f2013-11-12 01:59:02547#endif // !defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18548
[email protected]d5bcd06f2013-04-21 08:07:24549#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30550GURL GetEffectiveURLForSignin(const GURL& url) {
551 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
552
553 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03554 // Copy the path because the argument to SetPathStr must outlive
555 // the Replacements object.
556 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30557 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03558 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30559 effective_url = effective_url.ReplaceComponents(replacements);
560 return effective_url;
561}
[email protected]d5bcd06f2013-04-21 08:07:24562#endif
[email protected]970c63e2013-03-07 00:25:30563
[email protected]eabbfb12013-04-05 23:28:35564void SetApplicationLocaleOnIOThread(const std::string& locale) {
565 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
566 g_io_thread_application_locale.Get() = locale;
567}
568
[email protected]916615b2013-09-11 18:19:44569void HandleBlockedPopupOnUIThread(const BlockedWindowParams& params) {
570 WebContents* tab = tab_util::GetWebContentsByID(params.render_process_id(),
571 params.opener_id());
[email protected]190e5e22013-07-27 05:59:23572 if (!tab)
573 return;
574
[email protected]f1cd3362014-01-07 20:43:01575 prerender::PrerenderContents* prerender_contents =
576 prerender::PrerenderContents::FromWebContents(tab);
577 if (prerender_contents) {
578 prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW);
579 return;
580 }
581
[email protected]190e5e22013-07-27 05:59:23582 PopupBlockerTabHelper* popup_helper =
583 PopupBlockerTabHelper::FromWebContents(tab);
584 if (!popup_helper)
585 return;
[email protected]916615b2013-09-11 18:19:44586 popup_helper->AddBlockedPopup(params);
[email protected]190e5e22013-07-27 05:59:23587}
[email protected]190e5e22013-07-27 05:59:23588
[email protected]916615b2013-09-11 18:19:44589#if defined(OS_ANDROID)
[email protected]b255a8e0e82013-10-22 04:03:59590
[email protected]916615b2013-09-11 18:19:44591void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams& params) {
592 WebContents* web_contents =
593 tab_util::GetWebContentsByID(params.render_process_id(),
594 params.opener_id());
595 if (!web_contents)
596 return;
597
598 SingleTabModeTabHelper::FromWebContents(web_contents)->HandleOpenUrl(params);
599}
[email protected]b255a8e0e82013-10-22 04:03:59600
[email protected]ded00dc2013-11-01 00:37:05601float GetDeviceScaleAdjustment() {
[email protected]b255a8e0e82013-10-22 04:03:59602 static const float kMinFSM = 1.05f;
603 static const int kWidthForMinFSM = 320;
604 static const float kMaxFSM = 1.3f;
605 static const int kWidthForMaxFSM = 800;
606
607 gfx::DeviceDisplayInfo info;
608 int minWidth = info.GetSmallestDIPWidth();
609
610 if (minWidth <= kWidthForMinFSM)
611 return kMinFSM;
612 if (minWidth >= kWidthForMaxFSM)
613 return kMaxFSM;
614
615 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
616 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) /
617 (kWidthForMaxFSM - kWidthForMinFSM);
618 return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
619}
620
[email protected]916615b2013-09-11 18:19:44621#endif // defined(OS_ANDROID)
622
[email protected]9dbfff12011-07-01 19:37:07623} // namespace
[email protected]c5dbef02011-05-13 05:06:09624
[email protected]d977f9c2011-03-14 16:10:26625namespace chrome {
626
[email protected]e461da2f2012-02-16 19:06:40627ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40628#if defined(ENABLE_PLUGINS)
[email protected]10c39222013-11-13 20:09:25629 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i)
630 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40631 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
632 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40633#endif
[email protected]1deace22013-05-22 06:14:46634
635 permissions_policy_delegate_.reset(
636 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40637}
638
639ChromeContentBrowserClient::~ChromeContentBrowserClient() {
640}
641
[email protected]bca18382012-06-25 19:15:23642// static
[email protected]37ca3fe02013-07-05 15:32:44643void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34644 user_prefs::PrefRegistrySyncable* registry) {
645 registry->RegisterBooleanPref(
646 prefs::kDisable3DAPIs,
647 false,
648 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
649 registry->RegisterBooleanPref(
650 prefs::kEnableHyperlinkAuditing,
651 true,
652 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
653 registry->RegisterBooleanPref(
654 prefs::kEnableMemoryInfo,
655 false,
656 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23657}
658
[email protected]eabbfb12013-04-05 23:28:35659// static
660void ChromeContentBrowserClient::SetApplicationLocale(
661 const std::string& locale) {
662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
663
664 // This object is guaranteed to outlive all threads so we don't have to
665 // worry about the lack of refcounting and can just post as Unretained.
666 //
667 // The common case is that this function is called early in Chrome startup
668 // before any threads are created (it will also be called later if the user
669 // changes the pref). In this case, there will be no threads created and
670 // posting will fail. When there are no threads, we can just set the string
671 // without worrying about threadsafety.
672 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
673 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
674 g_io_thread_application_locale.Get() = locale;
675 }
676}
677
[email protected]50462bf02011-11-21 19:13:31678content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
679 const content::MainFunctionParams& parameters) {
680 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30681 // Construct the Main browser parts based on the OS type.
682#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31683 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04684#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31685 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30686#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22687 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26688#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31689 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14690#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09691 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30692#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31693 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04694#else
[email protected]b48c9182011-10-26 18:03:30695 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31696 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30697#endif
698
[email protected]7e75e4a2013-05-17 17:20:03699 chrome::AddProfilesExtraParts(main_parts);
700
[email protected]c7480942011-11-08 19:18:27701 // Construct additional browser parts. Stages are called in the order in
702 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22703#if defined(TOOLKIT_GTK)
[email protected]e8b6ca02013-07-10 18:00:51704 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04705#endif
[email protected]c7480942011-11-08 19:18:27706
707#if defined(TOOLKIT_VIEWS)
[email protected]e8b6ca02013-07-10 18:00:51708 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27709#endif
710
[email protected]dc04be7c2012-03-15 23:57:49711#if defined(USE_ASH)
[email protected]e8b6ca02013-07-10 18:00:51712 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
[email protected]dc04be7c2012-03-15 23:57:49713#endif
714
[email protected]e050ef142012-03-21 01:04:24715#if defined(USE_AURA)
[email protected]e8b6ca02013-07-10 18:00:51716 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
717#endif
718
719#if defined(USE_X11)
720 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:24721#endif
722
[email protected]95132f52013-04-12 02:19:04723 chrome::AddMetricsExtraParts(main_parts);
724
[email protected]50462bf02011-11-21 19:13:31725 return main_parts;
[email protected]f967b722011-09-07 00:58:04726}
727
[email protected]e94bbcb2012-09-07 05:33:57728std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19729 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57730 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53731 std::string partition_id;
732
733 // The partition ID for webview guest processes is the string value of its
734 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
[email protected]6eb1a11e2013-10-09 00:54:37735 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:53736 partition_id = site.spec();
737
[email protected]056efdc2013-04-06 00:14:53738 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53739 return partition_id;
740}
741
742bool ChromeContentBrowserClient::IsValidStoragePartitionId(
743 content::BrowserContext* browser_context,
744 const std::string& partition_id) {
745 // The default ID is empty and is always valid.
746 if (partition_id.empty())
747 return true;
748
749 return GURL(partition_id).is_valid();
750}
751
752void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
753 content::BrowserContext* browser_context,
754 const GURL& site,
[email protected]14acc642012-11-17 12:20:10755 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53756 std::string* partition_domain,
757 std::string* partition_name,
758 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10759 // Default to the browser-wide storage partition and override based on |site|
760 // below.
761 partition_domain->clear();
762 partition_name->clear();
763 *in_memory = false;
764
[email protected]3f24f97c2013-11-17 21:53:33765 bool success = GuestView::GetGuestPartitionConfigForSite(
766 site, partition_domain, partition_name, in_memory);
767
768 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
[email protected]14acc642012-11-17 12:20:10769 // If |can_be_default| is false, the caller is stating that the |site|
770 // should be parsed as if it had isolated storage. In particular it is
771 // important to NOT check ExtensionService for the is_storage_isolated()
772 // attribute because this code path is run during Extension uninstall
773 // to do cleanup after the Extension has already been unloaded from the
774 // ExtensionService.
775 bool is_isolated = !can_be_default;
776 if (can_be_default) {
777 const Extension* extension = NULL;
778 Profile* profile = Profile::FromBrowserContext(browser_context);
779 ExtensionService* extension_service =
780 extensions::ExtensionSystem::Get(profile)->extension_service();
781 if (extension_service) {
[email protected]be9915fb2013-07-18 09:28:55782 extension =
783 extension_service->extensions()->GetExtensionOrAppByURL(site);
[email protected]561e33d52013-04-03 06:58:43784 if (extension &&
785 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10786 is_isolated = true;
787 }
788 }
789 }
[email protected]1bc28312012-11-08 08:31:53790
[email protected]14acc642012-11-17 12:20:10791 if (is_isolated) {
792 CHECK(site.has_host());
793 // For extensions with isolated storage, the the host of the |site| is
794 // the |partition_domain|. The |in_memory| and |partition_name| are only
795 // used in guest schemes so they are cleared here.
796 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53797 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10798 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53799 }
[email protected]d1198fd2012-08-13 22:50:19800 }
801
[email protected]14acc642012-11-17 12:20:10802 // Assert that if |can_be_default| is false, the code above must have found a
803 // non-default partition. If this fails, the caller has a serious logic
804 // error about which StoragePartition they expect to be in and it is not
805 // safe to continue.
806 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44807}
808
[email protected]38b098f2012-03-14 21:11:57809content::WebContentsViewDelegate*
810 ChromeContentBrowserClient::GetWebContentsViewDelegate(
811 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27812 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32813}
814
[email protected]738f57a2013-06-29 21:06:54815void ChromeContentBrowserClient::GuestWebContentsCreated(
[email protected]dbbce92c2013-10-31 16:51:19816 SiteInstance* guest_site_instance,
[email protected]738f57a2013-06-29 21:06:54817 WebContents* guest_web_contents,
818 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22819 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54820 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]dbbce92c2013-10-31 16:51:19821 if (!guest_site_instance) {
822 NOTREACHED();
823 return;
824 }
825 GURL guest_site_url = guest_site_instance->GetSiteURL();
826 const std::string& extension_id = guest_site_url.host();
827
828 Profile* profile = Profile::FromBrowserContext(
829 guest_web_contents->GetBrowserContext());
830 ExtensionService* service =
831 extensions::ExtensionSystem::Get(profile)->extension_service();
832 if (!service) {
833 NOTREACHED();
834 return;
835 }
836
837 /// TODO(fsamuel): In the future, certain types of GuestViews won't require
838 // extension bindings. At that point, we should clear |extension_id| instead
839 // of exiting early.
840 if (!service->GetExtensionById(extension_id, false) &&
841 !CommandLine::ForCurrentProcess()->HasSwitch(
842 switches::kEnableBrowserPluginForAllViewTypes)) {
843 NOTREACHED();
844 return;
845 }
846
[email protected]738f57a2013-06-29 21:06:54847 if (opener_web_contents) {
848 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
849 if (!guest) {
850 NOTREACHED();
851 return;
852 }
853
[email protected]50c827d2013-09-13 21:36:09854 // Create a new GuestView of the same type as the opener.
855 *guest_delegate =
[email protected]dbbce92c2013-10-31 16:51:19856 GuestView::Create(guest_web_contents,
857 extension_id,
858 guest->GetViewType());
[email protected]738f57a2013-06-29 21:06:54859 return;
860 }
861
862 if (!extra_params) {
863 NOTREACHED();
864 return;
865 }
866 std::string api_type;
[email protected]90547d72013-08-06 05:57:27867 extra_params->GetString(guestview::kParameterApi, &api_type);
[email protected]738f57a2013-06-29 21:06:54868
[email protected]dbbce92c2013-10-31 16:51:19869 if (api_type.empty())
870 return;
871
[email protected]50c827d2013-09-13 21:36:09872 *guest_delegate =
873 GuestView::Create(guest_web_contents,
[email protected]dbbce92c2013-10-31 16:51:19874 extension_id,
[email protected]50c827d2013-09-13 21:36:09875 GuestView::GetViewTypeFromString(api_type));
[email protected]738f57a2013-06-29 21:06:54876}
877
[email protected]44295a12013-06-05 08:45:46878void ChromeContentBrowserClient::GuestWebContentsAttached(
879 WebContents* guest_web_contents,
880 WebContents* embedder_web_contents,
[email protected]5715566a2013-06-25 00:04:53881 const base::DictionaryValue& extra_params) {
[email protected]22aa4f82013-09-24 17:01:44882
[email protected]dbbce92c2013-10-31 16:51:19883 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
884 if (!guest) {
[email protected]efd6fb02013-08-05 04:44:06885 // It's ok to return here, since we could be running a browser plugin
886 // outside an extension, and don't need to attach a
887 // BrowserPluginGuestDelegate in that case;
888 // e.g. running with flag --enable-browser-plugin-for-all-view-types.
[email protected]738f57a2013-06-29 21:06:54889 return;
[email protected]18699372013-06-25 20:42:55890 }
[email protected]dbbce92c2013-10-31 16:51:19891 guest->Attach(embedder_web_contents, extra_params);
[email protected]44703cc72013-01-24 04:56:06892}
893
[email protected]6f2862742013-12-20 07:53:19894void ChromeContentBrowserClient::RenderProcessWillLaunch(
[email protected]f3b1a082011-11-18 00:34:30895 content::RenderProcessHost* host) {
896 int id = host->GetID();
897 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41898 net::URLRequestContextGetter* context =
899 profile->GetRequestContextForRenderProcess(id);
900
[email protected]ba780c12013-10-01 17:07:06901 host->AddFilter(new ChromeRenderMessageFilter(id, profile, context));
[email protected]ebd71962012-12-20 02:56:55902#if defined(ENABLE_PLUGINS)
[email protected]ba780c12013-10-01 17:07:06903 host->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55904#endif
[email protected]658677f2012-06-09 06:04:02905#if defined(ENABLE_PRINTING)
[email protected]ba780c12013-10-01 17:07:06906 host->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03907#endif
[email protected]ba780c12013-10-01 17:07:06908 host->AddFilter(new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]c6ce08072013-07-31 07:48:53909#if defined(ENABLE_SPELLCHECK)
[email protected]ba780c12013-10-01 17:07:06910 host->AddFilter(new SpellCheckMessageFilter(id));
[email protected]c6ce08072013-07-31 07:48:53911#endif
[email protected]7ceb99012011-12-21 08:05:56912#if defined(OS_MACOSX)
[email protected]ba780c12013-10-01 17:07:06913 host->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56914#endif
[email protected]ba780c12013-10-01 17:07:06915 host->AddFilter(new ChromeNetBenchmarkingMessageFilter(
[email protected]43535512013-02-20 20:41:41916 id, profile, context));
[email protected]ba780c12013-10-01 17:07:06917 host->AddFilter(new prerender::PrerenderMessageFilter(id, profile));
[email protected]ba780c12013-10-01 17:07:06918 host->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31919#if defined(ENABLE_WEBRTC)
[email protected]10e5c5e52013-10-03 18:44:06920 WebRtcLoggingHandlerHost* webrtc_logging_handler_host =
[email protected]135bc1d2013-10-21 09:11:37921 new WebRtcLoggingHandlerHost(profile);
[email protected]10e5c5e52013-10-03 18:44:06922 host->AddFilter(webrtc_logging_handler_host);
923 host->SetUserData(host, new base::UserDataAdapter<WebRtcLoggingHandlerHost>(
924 webrtc_logging_handler_host));
[email protected]6ef98b5a2013-05-31 23:58:31925#endif
[email protected]01e59752013-06-18 00:17:35926#if !defined(DISABLE_NACL)
[email protected]7c766e92013-11-22 20:44:02927 host->AddFilter(new nacl::NaClHostMessageFilter(
[email protected]14230ca2013-06-26 23:33:03928 id, profile->IsOffTheRecord(),
[email protected]a2b4c5c2013-10-18 02:06:07929 profile->GetPath(),
[email protected]14230ca2013-06-26 23:33:03930 context));
[email protected]01e59752013-06-18 00:17:35931#endif
[email protected]2b12c322013-09-19 06:53:56932#if defined(OS_ANDROID)
[email protected]ba780c12013-10-01 17:07:06933 host->AddFilter(new EncryptedMediaMessageFilterAndroid());
[email protected]2b12c322013-09-19 06:53:56934#endif
[email protected]4de75262013-12-18 23:16:12935 if (switches::IsNewProfileManagement())
[email protected]914cf6712013-12-05 01:14:06936 host->AddFilter(new PrincipalsMessageFilter(id));
[email protected]3e69bc82011-05-26 23:22:38937
[email protected]2ccf45c2011-08-19 23:35:50938 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
939 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07940
941 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56942
943 RendererContentSettingRules rules;
[email protected]06153f02013-12-04 03:01:28944 if (host->IsGuest()) {
945 GuestView::GetDefaultContentSettingRules(&rules, profile->IsOffTheRecord());
946 } else {
947 GetRendererContentSettingRules(
948 profile->GetHostContentSettingsMap(), &rules);
949 }
[email protected]edece212011-11-16 11:56:56950 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14951}
952
[email protected]3d7474ff2011-07-27 17:47:37953GURL ChromeContentBrowserClient::GetEffectiveURL(
954 content::BrowserContext* browser_context, const GURL& url) {
955 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52956 if (!profile)
957 return url;
958
[email protected]b3cb3a32013-07-31 01:32:29959 // If the input |url| should be assigned to the Instant renderer, make its
960 // effective URL distinct from other URLs on the search provider's domain.
961 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
962 return chrome::GetEffectiveURLForInstant(url, profile);
963
[email protected]d5bcd06f2013-04-21 08:07:24964#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30965 // If the input |url| should be assigned to the Signin renderer, make its
966 // effective URL distinct from other URLs on the signin service's domain.
967 // Note that the signin renderer will be allowed to sign the user in to
968 // Chrome.
969 if (SigninManager::IsWebBasedSigninFlowURL(url))
970 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24971#endif
[email protected]970c63e2013-03-07 00:25:30972
[email protected]c5dec6292013-01-25 04:54:52973 // If the input |url| is part of an installed app, the effective URL is an
974 // extension URL with the ID of that extension as the host. This has the
975 // effect of grouping apps together in a common SiteInstance.
976 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13977 extensions::ExtensionSystem::Get(profile)->extension_service();
978 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08979 return url;
980
[email protected]06bdd2b2012-11-30 18:47:13981 const Extension* extension = extension_service->extensions()->
[email protected]be9915fb2013-07-18 09:28:55982 GetHostedAppByURL(url);
[email protected]36fb2c7c2011-04-04 15:49:08983 if (!extension)
984 return url;
985
[email protected]15877ca2011-11-18 22:40:52986 // Bookmark apps do not use the hosted app process model, and should be
987 // treated as normal URLs.
988 if (extension->from_bookmark())
989 return url;
990
[email protected]36fb2c7c2011-04-04 15:49:08991 // If the URL is part of an extension's web extent, convert it to an
992 // extension URL.
993 return extension->GetResourceURL(url.path());
994}
995
[email protected]056ad2a2011-07-12 02:13:55996bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37997 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52998 // Non-extension, non-Instant URLs should generally use
999 // process-per-site-instance. Because we expect to use the effective URL,
1000 // URLs for hosted apps (apart from bookmark apps) should have an extension
1001 // scheme by now.
1002
1003 Profile* profile = Profile::FromBrowserContext(browser_context);
1004 if (!profile)
1005 return false;
1006
[email protected]df113a12013-07-24 04:56:081007 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:521008 return true;
1009
[email protected]d5bcd06f2013-04-21 08:07:241010#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301011 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
1012 return true;
[email protected]d5bcd06f2013-04-21 08:07:241013#endif
[email protected]970c63e2013-03-07 00:25:301014
[email protected]885c0e92012-11-13 20:27:421015 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:551016 return false;
1017
[email protected]c5dec6292013-01-25 04:54:521018 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:131019 extensions::ExtensionSystem::Get(profile)->extension_service();
1020 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:551021 return false;
1022
[email protected]be9915fb2013-07-18 09:28:551023 const Extension* extension =
1024 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
[email protected]056ad2a2011-07-12 02:13:551025 if (!extension)
1026 return false;
1027
1028 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:531029 // permission, or that does not allow JavaScript access to the background
1030 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:551031 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:401032 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:061033 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:291034 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:531035 return false;
1036 }
1037 }
[email protected]056ad2a2011-07-12 02:13:551038
[email protected]7b54ca02012-03-02 18:06:531039 // Hosted apps that have script access to their background page must use
1040 // process per site, since all instances can make synchronous calls to the
1041 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:551042 return true;
1043}
1044
[email protected]672c8c12013-03-07 12:30:061045// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:411046void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1047 std::vector<std::string>* additional_schemes) {
1048 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:061049}
1050
[email protected]6bd30072013-02-08 18:17:111051net::URLRequestContextGetter*
1052ChromeContentBrowserClient::CreateRequestContext(
1053 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:061054 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:111055 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:061056 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111057}
1058
1059net::URLRequestContextGetter*
1060ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
1061 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:401062 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:111063 bool in_memory,
[email protected]672c8c12013-03-07 12:30:061064 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:111065 Profile* profile = Profile::FromBrowserContext(browser_context);
1066 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:061067 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111068}
1069
[email protected]46fb9442011-12-09 17:57:471070bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1071 return ProfileIOData::IsHandledURL(url);
1072}
1073
[email protected]c4365fa42013-05-14 01:08:241074bool ChromeContentBrowserClient::CanCommitURL(
1075 content::RenderProcessHost* process_host,
1076 const GURL& url) {
1077 // We need to let most extension URLs commit in any process, since this can
1078 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1079 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1080 // cannot be loaded in iframes and should never be requested outside its
1081 // process.
1082 Profile* profile =
1083 Profile::FromBrowserContext(process_host->GetBrowserContext());
1084 ExtensionService* service =
1085 extensions::ExtensionSystem::Get(profile)->extension_service();
1086 if (!service)
1087 return true;
1088 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551089 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]c4365fa42013-05-14 01:08:241090 if (new_extension &&
1091 new_extension->is_hosted_app() &&
1092 new_extension->id() == extension_misc::kWebStoreAppId &&
1093 !service->process_map()->Contains(new_extension->id(),
1094 process_host->GetID())) {
1095 return false;
1096 }
1097
1098 return true;
1099}
1100
[email protected]9a60d1602013-09-11 04:09:121101bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1102 content::SiteInstance* site_instance, const GURL& url) {
1103 GURL from_url = site_instance->GetSiteURL();
1104 // Do not allow pages from the web or other extensions navigate to
1105 // non-web-accessible extension resources.
1106 if (url.SchemeIs(extensions::kExtensionScheme) &&
1107 (from_url.SchemeIsHTTPOrHTTPS() ||
1108 from_url.SchemeIs(extensions::kExtensionScheme))) {
1109 Profile* profile = Profile::FromBrowserContext(
1110 site_instance->GetProcess()->GetBrowserContext());
1111 ExtensionService* service =
1112 extensions::ExtensionSystem::Get(profile)->extension_service();
1113 if (!service)
1114 return true;
1115 const Extension* extension =
1116 service->extensions()->GetExtensionOrAppByURL(url);
1117 if (!extension)
1118 return true;
1119 const Extension* from_extension =
1120 service->extensions()->GetExtensionOrAppByURL(
1121 site_instance->GetSiteURL());
1122 if (from_extension && from_extension->id() == extension->id())
1123 return true;
1124
1125 if (!extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
1126 extension, url.path()))
1127 return false;
1128 }
1129 return true;
1130}
1131
[email protected]2a5221b2011-09-27 23:07:311132bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301133 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311134 const GURL& site_url) {
1135 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301136 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521137 // This may be NULL during tests. In that case, just assume any site can
1138 // share any host.
1139 if (!profile)
1140 return true;
1141
[email protected]d43f99fe2013-04-03 00:20:141142 // Instant URLs should only be in the instant process and instant process
1143 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521144 InstantService* instant_service =
1145 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141146 if (instant_service) {
1147 bool is_instant_process = instant_service->IsInstantProcess(
1148 process_host->GetID());
1149 bool should_be_in_instant_process =
1150 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1151 if (is_instant_process || should_be_in_instant_process)
1152 return is_instant_process && should_be_in_instant_process;
1153 }
[email protected]c5dec6292013-01-25 04:54:521154
[email protected]d5bcd06f2013-04-21 08:07:241155#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301156 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1157 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1158 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241159#endif
[email protected]970c63e2013-03-07 00:25:301160
[email protected]06bdd2b2012-11-30 18:47:131161 ExtensionService* service =
1162 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461163 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:311164
[email protected]ffa97602011-11-17 17:55:521165 // Don't allow the Task Manager to share a process with anything else.
1166 // Otherwise it can affect the renderers it is observing.
1167 // Note: we could create another RenderProcessHostPrivilege bucket for
1168 // this to allow multiple chrome://tasks instances to share, but that's
1169 // a very unlikely case without serious consequences.
1170 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1171 return false;
1172
[email protected]8d3132f62011-10-12 07:13:421173 // These may be NULL during tests. In that case, just assume any site can
1174 // share any host.
[email protected]6f371442011-11-09 06:45:461175 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311176 return true;
1177
[email protected]eec0b33c2011-12-05 22:09:451178 // Otherwise, just make sure the process privilege matches the privilege
1179 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571180 RenderProcessHostPrivilege privilege_required =
1181 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451182 return GetProcessPrivilege(process_host, process_map, service) ==
1183 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311184}
1185
[email protected]76411f412012-02-22 18:56:061186// This function is trying to limit the amount of processes used by extensions
1187// with background pages. It uses a globally set percentage of processes to
1188// run such extensions and if the limit is exceeded, it returns true, to
1189// indicate to the content module to group extensions together.
1190bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1191 content::BrowserContext* browser_context, const GURL& url) {
1192 // It has to be a valid URL for us to check for an extension.
1193 if (!url.is_valid())
1194 return false;
1195
1196 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191197 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131198 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061199 if (!service)
1200 return false;
1201
1202 // We have to have a valid extension with background page to proceed.
1203 const Extension* extension =
[email protected]be9915fb2013-07-18 09:28:551204 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]76411f412012-02-22 18:56:061205 if (!extension)
1206 return false;
[email protected]9367eabc2013-03-01 01:29:291207 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061208 return false;
1209
1210 std::set<int> process_ids;
1211 size_t max_process_count =
1212 content::RenderProcessHost::GetMaxRendererProcessCount();
1213
1214 // Go through all profiles to ensure we have total count of extension
1215 // processes containing background pages, otherwise one profile can
1216 // starve the other.
1217 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1218 GetLoadedProfiles();
1219 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]98b6d942013-11-10 00:34:071220 extensions::ProcessManager* epm =
[email protected]be93bba02012-10-24 16:44:031221 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]98b6d942013-11-10 00:34:071222 for (extensions::ProcessManager::const_iterator iter =
[email protected]d1fe1352012-04-26 00:47:321223 epm->background_hosts().begin();
1224 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131225 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321226 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061227 }
1228 }
1229
1230 if (process_ids.size() >
1231 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1232 return true;
1233 }
1234
1235 return false;
1236}
1237
[email protected]6f371442011-11-09 06:45:461238void ChromeContentBrowserClient::SiteInstanceGotProcess(
1239 SiteInstance* site_instance) {
1240 CHECK(site_instance->HasProcess());
1241
1242 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021243 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521244 if (!profile)
1245 return;
1246
1247 // Remember the ID of the Instant process to signal the renderer process
1248 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031249 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321250 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521251 InstantService* instant_service =
1252 InstantServiceFactory::GetForProfile(profile);
1253 if (instant_service)
1254 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1255 }
1256
[email protected]d5bcd06f2013-04-21 08:07:241257#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301258 // We only expect there to be one signin process as we use process-per-site
1259 // for signin URLs. The signin process will be cleared from SigninManager
1260 // when the renderer is destroyed.
1261 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1262 SigninManager* signin_manager =
1263 SigninManagerFactory::GetForProfile(profile);
1264 if (signin_manager)
1265 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461266 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:201267 BrowserThread::IO,
1268 FROM_HERE,
1269 base::Bind(&InfoMap::SetSigninProcess,
[email protected]1deace22013-05-22 06:14:461270 extensions::ExtensionSystem::Get(profile)->info_map(),
1271 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301272 }
[email protected]d5bcd06f2013-04-21 08:07:241273#endif
[email protected]970c63e2013-03-07 00:25:301274
[email protected]06bdd2b2012-11-30 18:47:131275 ExtensionService* service =
1276 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461277 if (!service)
1278 return;
1279
[email protected]be9915fb2013-07-18 09:28:551280 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1281 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461282 if (!extension)
1283 return;
1284
[email protected]6bc04fd82011-12-04 02:29:351285 service->process_map()->Insert(extension->id(),
1286 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331287 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461288 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:201289 BrowserThread::IO,
1290 FROM_HERE,
1291 base::Bind(&InfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591292 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461293 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351294 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331295 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461296}
1297
1298void ChromeContentBrowserClient::SiteInstanceDeleting(
1299 SiteInstance* site_instance) {
1300 if (!site_instance->HasProcess())
1301 return;
1302
1303 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021304 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131305 ExtensionService* service =
1306 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461307 if (!service)
1308 return;
1309
[email protected]be9915fb2013-07-18 09:28:551310 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1311 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461312 if (!extension)
1313 return;
1314
[email protected]6bc04fd82011-12-04 02:29:351315 service->process_map()->Remove(extension->id(),
1316 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331317 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461318 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:201319 BrowserThread::IO,
1320 FROM_HERE,
1321 base::Bind(&InfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591322 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461323 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351324 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331325 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461326}
1327
[email protected]453f5432013-11-26 19:43:001328bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141329 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081330 const GURL& current_url,
1331 const GURL& new_url) {
[email protected]2aca9a92013-12-03 05:16:071332 // If we don't have an ExtensionService, then rely on the SiteInstance logic
[email protected]a5a59482013-12-03 22:52:061333 // in RenderFrameHostManager to decide when to swap.
[email protected]e9841fbd2013-02-22 23:12:141334 Profile* profile =
1335 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1336 ExtensionService* service =
1337 extensions::ExtensionSystem::Get(profile)->extension_service();
1338 if (!service)
1339 return false;
1340
[email protected]2aca9a92013-12-03 05:16:071341 // We must use a new BrowsingInstance (forcing a process swap and disabling
1342 // scripting by existing tabs) if one of the URLs is an extension and the
1343 // other is not the exact same extension.
1344 //
1345 // We ignore hosted apps here so that other tabs in their BrowsingInstance can
1346 // use postMessage with them. (The exception is the Chrome Web Store, which
1347 // is a hosted app that requires its own BrowsingInstance.) Navigations
1348 // to/from a hosted app will still trigger a SiteInstance swap in
[email protected]a5a59482013-12-03 22:52:061349 // RenderFrameHostManager.
[email protected]2aca9a92013-12-03 05:16:071350 const Extension* current_extension =
1351 service->extensions()->GetExtensionOrAppByURL(current_url);
1352 if (current_extension &&
1353 current_extension->is_hosted_app() &&
1354 current_extension->id() != extension_misc::kWebStoreAppId)
1355 current_extension = NULL;
1356
[email protected]e9841fbd2013-02-22 23:12:141357 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551358 service->extensions()->GetExtensionOrAppByURL(new_url);
[email protected]e9841fbd2013-02-22 23:12:141359 if (new_extension &&
1360 new_extension->is_hosted_app() &&
1361 new_extension->id() != extension_misc::kWebStoreAppId)
1362 new_extension = NULL;
[email protected]2aca9a92013-12-03 05:16:071363
1364 // First do a process check. We should force a BrowsingInstance swap if the
1365 // current process doesn't know about new_extension, even if current_extension
1366 // is somehow the same as new_extension.
[email protected]e9841fbd2013-02-22 23:12:141367 if (new_extension &&
1368 site_instance->HasProcess() &&
1369 !service->process_map()->Contains(new_extension->id(),
1370 site_instance->GetProcess()->GetID()))
1371 return true;
1372
[email protected]2aca9a92013-12-03 05:16:071373 // Otherwise, swap BrowsingInstances if current_extension and new_extension
1374 // differ.
1375 return current_extension != new_extension;
[email protected]e3daf3c2011-10-05 21:17:081376}
1377
[email protected]395045c2012-05-22 15:04:381378bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1379 content::ResourceContext* resource_context, const GURL& current_url,
1380 const GURL& new_url) {
1381 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1382 return extensions::CrossesExtensionProcessBoundary(
1383 io_data->GetExtensionInfoMap()->extensions(),
[email protected]be9915fb2013-07-18 09:28:551384 current_url, new_url, false);
[email protected]395045c2012-05-22 15:04:381385}
1386
[email protected]3d831992013-07-04 01:13:291387bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1388 return !url.SchemeIs(chrome::kChromeNativeScheme);
1389}
1390
[email protected]763ec4ca2011-04-29 15:48:121391std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1392 const std::string& alias_name) {
1393 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1394}
1395
[email protected]b80f68432011-05-02 17:22:301396void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1397 CommandLine* command_line, int child_process_id) {
[email protected]264c0acac2013-10-01 13:33:301398#if defined(OS_POSIX)
[email protected]0b818f72013-10-22 00:11:031399 if (breakpad::IsCrashReporterEnabled()) {
[email protected]264c0acac2013-10-01 13:33:301400 std::string enable_crash_reporter;
1401 GoogleUpdateSettings::GetMetricsId(&enable_crash_reporter);
1402#if !defined(OS_MACOSX)
1403 enable_crash_reporter += "," + base::GetLinuxDistro();
1404#endif
[email protected]b80f68432011-05-02 17:22:301405 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
[email protected]264c0acac2013-10-01 13:33:301406 enable_crash_reporter);
[email protected]b80f68432011-05-02 17:22:301407 }
[email protected]264c0acac2013-10-01 13:33:301408#endif // OS_POSIX
[email protected]b80f68432011-05-02 17:22:301409
[email protected]f1933792011-06-14 00:49:341410 if (logging::DialogsAreSuppressed())
1411 command_line->AppendSwitch(switches::kNoErrorDialogs);
1412
[email protected]b80f68432011-05-02 17:22:301413 std::string process_type =
1414 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171415 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321416
[email protected]7c9b6f92013-09-10 18:11:351417 static const char* const kCommonSwitchNames[] = {
[email protected]7c9b6f92013-09-10 18:11:351418 switches::kUserDataDir, // Make logs go to the right file.
1419 };
1420 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
1421 arraysize(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:321422
[email protected]8c64e282013-11-28 16:05:141423#if defined(ENABLE_IPC_FUZZER)
1424 static const char* const kIpcFuzzerSwitches[] = {
1425 switches::kIpcFuzzerTestcase,
1426 };
1427 command_line->CopySwitchesFrom(browser_command_line, kIpcFuzzerSwitches,
1428 arraysize(kIpcFuzzerSwitches));
1429#endif
1430
[email protected]718eab62011-10-05 21:16:521431 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:301432#if defined(OS_CHROMEOS)
1433 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441434 browser_command_line.GetSwitchValueASCII(
1435 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301436 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441437 command_line->AppendSwitchASCII(
1438 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301439#endif
1440
[email protected]50fa4d5f2013-11-05 00:53:231441#if defined(ENABLE_WEBRTC)
1442 if (VersionInfo::GetChannel() <= VersionInfo::CHANNEL_DEV) {
1443 static const char* const kWebRtcDevSwitchNames[] = {
1444 switches::kDisableWebRtcEncryption,
1445 };
1446 command_line->CopySwitchesFrom(browser_command_line,
1447 kWebRtcDevSwitchNames,
1448 arraysize(kWebRtcDevSwitchNames));
1449 }
1450#endif
1451
[email protected]f3b1a082011-11-18 00:34:301452 content::RenderProcessHost* process =
1453 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371454 if (process) {
1455 Profile* profile = Profile::FromBrowserContext(
1456 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131457 ExtensionService* extension_service =
1458 extensions::ExtensionSystem::Get(profile)->extension_service();
1459 if (extension_service) {
1460 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]433669fd2013-10-31 22:07:101461 if (process_map && process_map->Contains(process->GetID()))
[email protected]cd0f7af2014-01-16 23:50:391462 command_line->AppendSwitch(extensions::switches::kExtensionProcess);
[email protected]c8598d42012-09-25 21:17:001463 }
[email protected]b80f68432011-05-02 17:22:301464
[email protected]a8d851f82011-12-21 00:32:371465 PrefService* prefs = profile->GetPrefs();
1466 // Currently this pref is only registered if applied via a policy.
1467 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1468 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1469 // Turn this policy into a command line switch.
1470 command_line->AppendSwitch(switches::kDisable3DAPIs);
1471 }
[email protected]718eab62011-10-05 21:16:521472
[email protected]a8d851f82011-12-21 00:32:371473 // Disable client-side phishing detection in the renderer if it is
1474 // disabled in the Profile preferences or the browser process.
1475 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1476 !g_browser_process->safe_browsing_detection_service()) {
1477 command_line->AppendSwitch(
1478 switches::kDisableClientSidePhishingDetection);
1479 }
[email protected]0045b0f42012-07-26 11:52:081480
1481 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211482 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521483
1484 InstantService* instant_service =
1485 InstantServiceFactory::GetForProfile(profile);
1486 if (instant_service &&
1487 instant_service->IsInstantProcess(process->GetID()))
1488 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301489
[email protected]d5bcd06f2013-04-21 08:07:241490#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301491 SigninManager* signin_manager =
1492 SigninManagerFactory::GetForProfile(profile);
1493 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1494 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241495#endif
[email protected]47c7ec82012-01-18 03:29:211496 }
[email protected]4287a3d2011-06-13 23:56:511497
[email protected]47c7ec82012-01-18 03:29:211498 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511499 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171500 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]c3cc0632013-10-03 21:54:431501 autofill::switches::kDisablePasswordGeneration,
[email protected]58bc1c32013-12-16 22:52:071502 autofill::switches::kEnableIgnoreAutocompleteOff,
[email protected]000f3ad2013-05-16 02:19:171503 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]c3cc0632013-10-03 21:54:431504 autofill::switches::kEnablePasswordGeneration,
[email protected]5c42c372013-10-17 15:06:101505 autofill::switches::kNoAutofillNecessaryForPasswordGeneration,
[email protected]558878cc82013-11-09 01:25:511506 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:271507 extensions::switches::kAllowLegacyExtensionManifests,
1508 extensions::switches::kAllowScriptingGallery,
[email protected]c8d02992013-07-31 22:16:511509 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271510 extensions::switches::kExtensionsOnChromeURLs,
[email protected]9d450492013-06-13 23:08:371511 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1512 // to browser.
1513 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511514 switches::kAppsCheckoutURL,
1515 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311516 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511517 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501518 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531519 switches::kDisableExtensionsResourceWhitelist,
[email protected]83c85262013-08-22 21:13:461520 switches::kDisablePnacl,
[email protected]b0553c7e2012-09-19 21:36:111521 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531522 switches::kEnableAdview,
1523 switches::kEnableAdviewSrcAttribute,
[email protected]1f4da9e2013-06-27 05:23:441524 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211525 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511526 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451527 switches::kEnableNetBenchmarking,
[email protected]c10b25f2014-01-14 14:57:001528 switches::kEnableStreamlinedHostedApps,
[email protected]4287a3d2011-06-13 23:56:511529 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511530 switches::kMemoryProfiling,
1531 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371532 switches::kNoJsRandomness,
[email protected]8f06e4d2013-11-25 23:20:181533 switches::kOutOfProcessPdf,
[email protected]f45c5f32012-04-18 19:26:371534 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511535 switches::kPpapiFlashArgs,
1536 switches::kPpapiFlashInProcess,
1537 switches::kPpapiFlashPath,
1538 switches::kPpapiFlashVersion,
1539 switches::kProfilingAtStart,
1540 switches::kProfilingFile,
1541 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371542 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511543 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:381544 switches::kWhitelistedExtensionID,
[email protected]499e7c52013-10-04 16:03:091545 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:511546 };
1547
1548 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1549 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171550 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381551 static const char* const kSwitchNames[] = {
[email protected]558878cc82013-11-09 01:25:511552 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]c8d02992013-07-31 22:16:511553 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271554 extensions::switches::kExtensionsOnChromeURLs,
[email protected]a446534d2012-02-09 00:07:381555 switches::kWhitelistedExtensionID,
1556 };
1557
1558 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1559 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511560 } else if (process_type == switches::kPluginProcess) {
1561 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441562#if defined(OS_CHROMEOS)
1563 chromeos::switches::kLoginProfile,
1564#endif
[email protected]4287a3d2011-06-13 23:56:511565 switches::kMemoryProfiling,
1566 switches::kSilentDumpOnDCHECK,
[email protected]4287a3d2011-06-13 23:56:511567 };
1568
1569 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1570 arraysize(kSwitchNames));
1571 } else if (process_type == switches::kZygoteProcess) {
1572 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511573 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501574 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511575 switches::kPpapiFlashInProcess,
1576 switches::kPpapiFlashPath,
1577 switches::kPpapiFlashVersion,
1578 };
1579
1580 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1581 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111582 } else if (process_type == switches::kGpuProcess) {
1583 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1584 // because GPU is expected to be unreliable.
1585 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1586 !command_line->HasSwitch(switches::kDisableBreakpad))
1587 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301588 }
[email protected]6f08af82011-09-15 01:19:031589
1590 // The command line switch kEnableBenchmarking needs to be specified along
1591 // with the kEnableStatsTable switch to ensure that the stats table global
1592 // is initialized correctly.
1593 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1594 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301595}
1596
1597std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431598 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351599 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301600 return g_browser_process->GetApplicationLocale();
1601}
1602
[email protected]597a867b2011-11-18 18:31:201603std::string ChromeContentBrowserClient::GetAcceptLangs(
1604 content::BrowserContext* context) {
1605 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371606 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081607}
1608
[email protected]9ec0f452012-05-31 15:58:531609gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221610 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531611 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081612}
1613
[email protected]a2176792011-05-08 19:30:491614bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091615 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191616 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201617 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321618 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201619 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051620 return io_data->GetCookieSettings()->
1621 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491622}
1623
[email protected]ed24fad2011-05-10 22:44:011624bool ChromeContentBrowserClient::AllowGetCookie(
1625 const GURL& url,
1626 const GURL& first_party,
1627 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201628 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011629 int render_process_id,
[email protected]f3add922013-12-20 23:17:161630 int render_frame_id) {
[email protected]ed24fad2011-05-10 22:44:011631 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201632 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051633 bool allow = io_data->GetCookieSettings()->
1634 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011635
[email protected]8093a542011-05-13 07:29:321636 BrowserThread::PostTask(
1637 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031638 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]f3add922013-12-20 23:17:161639 render_frame_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011640 return allow;
1641}
1642
1643bool ChromeContentBrowserClient::AllowSetCookie(
1644 const GURL& url,
1645 const GURL& first_party,
1646 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201647 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011648 int render_process_id,
[email protected]f3add922013-12-20 23:17:161649 int render_frame_id,
[email protected]ed24fad2011-05-10 22:44:011650 net::CookieOptions* options) {
1651 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201652 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051653 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1654 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1655
[email protected]8093a542011-05-13 07:29:321656 BrowserThread::PostTask(
1657 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031658 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]f3add922013-12-20 23:17:161659 render_frame_id, url, first_party, cookie_line, *options,
[email protected]fd473d12012-04-05 11:38:431660 !allow));
[email protected]ed24fad2011-05-10 22:44:011661 return allow;
1662}
1663
[email protected]d5a19162011-06-30 18:51:541664bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201665 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541666 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201667 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431668 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1669 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261670
[email protected]bf510ed2012-06-05 08:31:431671 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1672 // Could we even support per-origin settings?
1673 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541674}
1675
[email protected]5c5a88e2011-11-12 00:45:351676bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351677 const GURL& url,
[email protected]96920152013-12-04 21:00:161678 const base::string16& name,
1679 const base::string16& display_name,
[email protected]5c5a88e2011-11-12 00:45:351680 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201681 content::ResourceContext* context,
[email protected]b765deb2013-12-18 06:43:301682 const std::vector<std::pair<int, int> >& render_frames) {
[email protected]5c5a88e2011-11-12 00:45:351683 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201684 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351685 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1686 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1687
[email protected]62151052012-02-01 18:40:481688 // Record access to database for potential display in UI.
1689 std::vector<std::pair<int, int> >::const_iterator i;
[email protected]b765deb2013-12-18 06:43:301690 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
[email protected]62151052012-02-01 18:40:481691 BrowserThread::PostTask(
1692 BrowserThread::UI, FROM_HERE,
1693 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1694 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351695 }
1696
1697 return allow;
1698}
1699
1700bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351701 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201702 content::ResourceContext* context,
[email protected]b765deb2013-12-18 06:43:301703 const std::vector<std::pair<int, int> >& render_frames) {
[email protected]5c5a88e2011-11-12 00:45:351704 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201705 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351706 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1707 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1708
[email protected]62151052012-02-01 18:40:481709 // Record access to file system for potential display in UI.
1710 std::vector<std::pair<int, int> >::const_iterator i;
[email protected]b765deb2013-12-18 06:43:301711 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
[email protected]62151052012-02-01 18:40:481712 BrowserThread::PostTask(
1713 BrowserThread::UI, FROM_HERE,
1714 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1715 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351716 }
1717
1718 return allow;
1719}
1720
[email protected]7c5ff9a2012-03-02 07:42:491721bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1722 const GURL& url,
[email protected]96920152013-12-04 21:00:161723 const base::string16& name,
[email protected]7c5ff9a2012-03-02 07:42:491724 content::ResourceContext* context,
[email protected]b765deb2013-12-18 06:43:301725 const std::vector<std::pair<int, int> >& render_frames) {
[email protected]7c5ff9a2012-03-02 07:42:491726 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1727 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1728 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1729 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1730
1731 // Record access to IndexedDB for potential display in UI.
1732 std::vector<std::pair<int, int> >::const_iterator i;
[email protected]b765deb2013-12-18 06:43:301733 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
[email protected]7c5ff9a2012-03-02 07:42:491734 BrowserThread::PostTask(
1735 BrowserThread::UI, FROM_HERE,
1736 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1737 i->first, i->second, url, name, !allow));
1738 }
1739
1740 return allow;
1741}
1742
[email protected]33ad6ce92013-08-27 14:39:081743net::URLRequestContext*
1744ChromeContentBrowserClient::OverrideRequestContextForURL(
1745 const GURL& url, content::ResourceContext* context) {
1746 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1747 if (url.SchemeIs(extensions::kExtensionScheme)) {
1748 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1749 return io_data->extensions_request_context();
1750 }
1751
1752 return NULL;
1753}
1754
[email protected]317f96c92011-05-31 06:53:411755QuotaPermissionContext*
1756ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1757 return new ChromeQuotaPermissionContext();
1758}
1759
[email protected]848dd042011-06-04 18:24:031760void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171761 int render_process_id,
[email protected]1a4e9752013-12-31 20:10:581762 int render_frame_id,
[email protected]4cf611e32012-02-13 16:06:171763 int cert_error,
1764 const net::SSLInfo& ssl_info,
1765 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021766 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031767 bool overridable,
[email protected]d9be47702012-05-16 03:41:221768 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171769 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001770 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021771 if (resource_type != ResourceType::MAIN_FRAME) {
1772 // A sub-resource has a certificate error. The user doesn't really
1773 // have a context for making the right decision, so block the
1774 // request hard, without an info bar to allow showing the insecure
1775 // content.
[email protected]8c965c22013-05-23 19:28:001776 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021777 return;
1778 }
1779
[email protected]f9034cf2011-07-21 12:43:411780 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]1a4e9752013-12-31 20:10:581781 content::RenderFrameHost* render_frame_host =
1782 content::RenderFrameHost::FromID(render_process_id, render_frame_id);
1783 if (!render_frame_host) {
1784 NOTREACHED();
1785 return;
1786 }
1787 WebContents* tab = WebContents::FromRenderFrameHost(render_frame_host);
[email protected]f9034cf2011-07-21 12:43:411788 if (!tab) {
1789 NOTREACHED();
1790 return;
1791 }
[email protected]09667f02014-01-06 15:37:571792
1793 prerender::PrerenderContents* prerender_contents =
[email protected]294084d2014-01-06 22:22:021794 prerender::PrerenderContents::FromWebContents(tab);
[email protected]09667f02014-01-06 15:37:571795 if (prerender_contents) {
1796 prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR);
1797 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
1798 return;
[email protected]f9034cf2011-07-21 12:43:411799 }
1800
[email protected]1e87df32012-09-12 04:53:191801#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231802 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1803 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1804 if (captive_portal_tab_helper)
1805 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191806#endif
1807
[email protected]f9034cf2011-07-21 12:43:411808 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221809 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1810 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031811}
1812
[email protected]c99c442e2011-08-24 11:37:301813void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451814 int render_process_id,
[email protected]094c8772013-12-21 17:54:501815 int render_frame_id,
[email protected]7a593db2012-02-13 21:19:401816 const net::HttpNetworkSession* network_session,
1817 net::SSLCertRequestInfo* cert_request_info,
1818 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]094c8772013-12-21 17:54:501819 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID(
1820 render_process_id, render_frame_id);
[email protected]294084d2014-01-06 22:22:021821 WebContents* tab = WebContents::FromRenderFrameHost(rfh);
1822 if (!tab) {
[email protected]094c8772013-12-21 17:54:501823 NOTREACHED();
1824 return;
1825 }
1826
[email protected]294084d2014-01-06 22:22:021827 prerender::PrerenderContents* prerender_contents =
1828 prerender::PrerenderContents::FromWebContents(tab);
1829 if (prerender_contents) {
1830 prerender_contents->Destroy(
1831 prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED);
[email protected]8ec26472011-06-06 16:52:451832 return;
1833 }
1834
[email protected]791879c2013-12-17 07:22:411835 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
1836 DCHECK(requesting_url.is_valid())
1837 << "Invalid URL string: https://"
1838 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:451839
[email protected]627e0512011-12-21 22:55:301840 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]5bcdd99d2013-12-23 18:28:301841 scoped_ptr<base::Value> filter(
[email protected]6786bf402011-12-03 15:19:451842 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1843 requesting_url,
1844 requesting_url,
1845 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1846 std::string(), NULL));
1847
1848 if (filter.get()) {
1849 // Try to automatically select a client certificate.
[email protected]5bcdd99d2013-12-23 18:28:301850 if (filter->IsType(base::Value::TYPE_DICTIONARY)) {
1851 base::DictionaryValue* filter_dict =
1852 static_cast<base::DictionaryValue*>(filter.get());
[email protected]6786bf402011-12-03 15:19:451853
1854 const std::vector<scoped_refptr<net::X509Certificate> >&
1855 all_client_certs = cert_request_info->client_certs;
1856 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091857 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451858 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091859 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451860 return;
1861 }
1862 }
1863 } else {
1864 NOTREACHED();
1865 }
1866 }
1867
[email protected]11feec322012-09-18 03:58:521868 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1869 if (!ssl_tab_helper) {
1870 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451871 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141872 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401873 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451874 return;
1875 }
[email protected]11feec322012-09-18 03:58:521876 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401877 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451878}
1879
[email protected]3b455502012-12-11 18:22:581880void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451881 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581882 net::CertificateMimeType cert_type,
1883 const void* cert_data,
1884 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451885 int render_process_id,
1886 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581887 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1888 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451889}
1890
[email protected]dc73a7b2012-03-25 15:27:181891content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561892 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181893}
1894
[email protected]941623e2011-06-07 23:06:041895void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1896 const GURL& source_origin,
1897 int callback_context,
1898 int render_process_id,
1899 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111900#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021901 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1902 WebContents* contents =
1903 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1904 if (!contents) {
[email protected]941623e2011-06-07 23:06:041905 NOTREACHED();
1906 return;
1907 }
1908
[email protected]d0d9c3ee2012-06-19 03:07:021909 // Skip showing the infobar if the request comes from an extension, and that
1910 // extension has the 'notify' permission. (If the extension does not have the
1911 // permission, the user will still be prompted.)
1912 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]38427a12013-11-09 17:34:201913 InfoMap* extension_info_map =
[email protected]c7cd5942013-04-30 03:31:011914 extensions::ExtensionSystem::Get(profile)->info_map();
1915 DesktopNotificationService* notification_service =
1916 DesktopNotificationServiceFactory::GetForProfile(profile);
1917 const Extension* extension = NULL;
1918 if (extension_info_map) {
[email protected]289c44b2013-12-17 03:26:571919 extensions::ExtensionSet extensions;
[email protected]c7cd5942013-04-30 03:31:011920 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1921 source_origin, render_process_id,
1922 extensions::APIPermission::kNotification, &extensions);
[email protected]289c44b2013-12-17 03:26:571923 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
[email protected]c7cd5942013-04-30 03:31:011924 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381925 if (notification_service->IsNotifierEnabled(NotifierId(
1926 NotifierId::APPLICATION, (*iter)->id()))) {
[email protected]cadac622013-06-11 16:46:361927 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011928 break;
1929 }
1930 }
1931 }
[email protected]eb4832a2012-12-08 01:57:521932 RenderViewHost* rvh =
1933 RenderViewHost::FromID(render_process_id, render_view_id);
1934 if (IsExtensionWithPermissionOrSuggestInConsole(
1935 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021936 if (rvh)
1937 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1938 return;
1939 }
1940
[email protected]c7cd5942013-04-30 03:31:011941 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021942 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111943#else
1944 NOTIMPLEMENTED();
1945#endif
[email protected]941623e2011-06-07 23:06:041946}
1947
[email protected]a1221aea2013-11-07 01:31:301948blink::WebNotificationPresenter::Permission
[email protected]941623e2011-06-07 23:06:041949 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021950 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201951 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021952 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111953#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041954 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]5c129792013-07-10 02:08:481955
[email protected]df02aca2012-02-09 21:03:201956 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9afacd22013-11-13 20:23:311957 InfoMap* extension_info_map = io_data->GetExtensionInfoMap();
[email protected]941623e2011-06-07 23:06:041958
[email protected]9afacd22013-11-13 20:23:311959 // We want to see if there is an extension that hasn't been manually disabled
1960 // that has the notifications permission and applies to this security origin.
1961 // First, get the list of extensions with permission for the origin.
[email protected]289c44b2013-12-17 03:26:571962 extensions::ExtensionSet extensions;
[email protected]9afacd22013-11-13 20:23:311963 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1964 source_origin, render_process_id,
1965 extensions::APIPermission::kNotification, &extensions);
[email protected]289c44b2013-12-17 03:26:571966 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
[email protected]9afacd22013-11-13 20:23:311967 iter != extensions.end(); ++iter) {
1968 // Then, check to see if it's been disabled by the user.
1969 if (!extension_info_map->AreNotificationsDisabled((*iter)->id()))
1970 return blink::WebNotificationPresenter::PermissionAllowed;
[email protected]c7cd5942013-04-30 03:31:011971 }
1972
[email protected]9afacd22013-11-13 20:23:311973 // No enabled extensions exist, so check the normal host content settings.
1974 HostContentSettingsMap* host_content_settings_map =
1975 io_data->GetHostContentSettingsMap();
1976 ContentSetting setting = host_content_settings_map->GetContentSetting(
1977 source_origin,
1978 source_origin,
1979 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
1980 NO_RESOURCE_IDENTIFIER);
1981
1982 if (setting == CONTENT_SETTING_ALLOW)
1983 return blink::WebNotificationPresenter::PermissionAllowed;
1984 if (setting == CONTENT_SETTING_BLOCK)
1985 return blink::WebNotificationPresenter::PermissionDenied;
[email protected]a1221aea2013-11-07 01:31:301986 return blink::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111987#else
[email protected]a1221aea2013-11-07 01:31:301988 return blink::WebNotificationPresenter::PermissionAllowed;
[email protected]5fd2e842012-03-01 00:29:111989#endif
[email protected]941623e2011-06-07 23:06:041990}
1991
1992void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171993 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041994 int render_process_id,
1995 int render_view_id,
1996 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111997#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041998 RenderViewHost* rvh = RenderViewHost::FromID(
1999 render_process_id, render_view_id);
2000 if (!rvh) {
2001 NOTREACHED();
2002 return;
2003 }
2004
[email protected]9f76c1e2012-03-05 15:15:582005 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:302006 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:042007 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:372008 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042009 service->ShowDesktopNotification(
2010 params, render_process_id, render_view_id,
2011 worker ? DesktopNotificationService::WorkerNotification :
2012 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:112013#else
2014 NOTIMPLEMENTED();
2015#endif
[email protected]941623e2011-06-07 23:06:042016}
2017
2018void ChromeContentBrowserClient::CancelDesktopNotification(
2019 int render_process_id,
2020 int render_view_id,
2021 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:112022#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:042023 RenderViewHost* rvh = RenderViewHost::FromID(
2024 render_process_id, render_view_id);
2025 if (!rvh) {
2026 NOTREACHED();
2027 return;
2028 }
2029
[email protected]9f76c1e2012-03-05 15:15:582030 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:302031 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:042032 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:372033 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042034 service->CancelDesktopNotification(
2035 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:112036#else
2037 NOTIMPLEMENTED();
2038#endif
[email protected]941623e2011-06-07 23:06:042039}
2040
[email protected]9f3fba52011-06-08 20:37:192041bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:352042 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:572043 const GURL& opener_top_level_frame_url,
[email protected]34eec7ffe32011-11-02 23:49:022044 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:192045 WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:232046 const GURL& target_url,
2047 const content::Referrer& referrer,
2048 WindowOpenDisposition disposition,
2049 const WebWindowFeatures& features,
2050 bool user_gesture,
2051 bool opener_suppressed,
[email protected]df02aca2012-02-09 21:03:202052 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:012053 int render_process_id,
[email protected]190e5e22013-07-27 05:59:232054 bool is_guest,
2055 int opener_id,
[email protected]03b6d552012-03-29 04:03:012056 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:192057 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:012058
2059 *no_javascript_access = false;
2060
[email protected]5e5f55e262c52013-09-12 00:27:192061 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]38427a12013-11-09 17:34:202062 InfoMap* map = io_data->GetExtensionInfoMap();
[email protected]5e5f55e262c52013-09-12 00:27:192063
[email protected]9f3fba52011-06-08 20:37:192064 // If the opener is trying to create a background window but doesn't have
2065 // the appropriate permission, fail the attempt.
[email protected]6940eef82013-09-11 11:58:412066 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]03b6d552012-03-29 04:03:012067 if (!map->SecurityOriginHasAPIPermission(
2068 source_origin,
2069 render_process_id,
[email protected]c2e66e12012-06-27 06:27:062070 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:012071 return false;
2072 }
2073
[email protected]7b54ca02012-03-02 18:06:532074 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2075 // return a recently installed Extension even if this CanCreateWindow call
2076 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:012077 // because the permission check above would have caused an early return
2078 // already. We must use the full URL to find hosted apps, though, and not
2079 // just the origin.
[email protected]be9915fb2013-07-18 09:28:552080 const Extension* extension =
2081 map->extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:292082 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:012083 *no_javascript_access = true;
[email protected]190e5e22013-07-27 05:59:232084
2085 return true;
[email protected]9f3fba52011-06-08 20:37:192086 }
[email protected]056efdc2013-04-06 00:14:532087
2088 // No new browser window (popup or tab) in app mode.
2089 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
2090 chrome::IsRunningInForcedAppMode()) {
2091 return false;
2092 }
2093
[email protected]190e5e22013-07-27 05:59:232094 if (is_guest)
2095 return true;
2096
[email protected]190e5e22013-07-27 05:59:232097 HostContentSettingsMap* content_settings =
2098 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap();
[email protected]916615b2013-09-11 18:19:442099 BlockedWindowParams blocked_params(target_url,
2100 referrer,
2101 disposition,
2102 features,
2103 user_gesture,
2104 opener_suppressed,
2105 render_process_id,
2106 opener_id);
[email protected]190e5e22013-07-27 05:59:232107
[email protected]7f53dff2013-08-05 10:45:502108 if (!user_gesture && !CommandLine::ForCurrentProcess()->HasSwitch(
2109 switches::kDisablePopupBlocking)) {
[email protected]931bc922013-09-11 21:42:572110 if (content_settings->GetContentSetting(opener_top_level_frame_url,
2111 opener_top_level_frame_url,
[email protected]190e5e22013-07-27 05:59:232112 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]916615b2013-09-11 18:19:442113 std::string()) !=
[email protected]190e5e22013-07-27 05:59:232114 CONTENT_SETTING_ALLOW) {
[email protected]916615b2013-09-11 18:19:442115 BrowserThread::PostTask(BrowserThread::UI,
2116 FROM_HERE,
2117 base::Bind(&HandleBlockedPopupOnUIThread,
2118 blocked_params));
2119 return false;
[email protected]190e5e22013-07-27 05:59:232120 }
[email protected]916615b2013-09-11 18:19:442121 }
[email protected]190e5e22013-07-27 05:59:232122
[email protected]916615b2013-09-11 18:19:442123#if defined(OS_ANDROID)
2124 if (SingleTabModeTabHelper::IsRegistered(render_process_id, opener_id)) {
[email protected]190e5e22013-07-27 05:59:232125 BrowserThread::PostTask(BrowserThread::UI,
2126 FROM_HERE,
[email protected]916615b2013-09-11 18:19:442127 base::Bind(&HandleSingleTabModeBlockOnUIThread,
2128 blocked_params));
[email protected]190e5e22013-07-27 05:59:232129 return false;
2130 }
[email protected]916615b2013-09-11 18:19:442131#endif
[email protected]190e5e22013-07-27 05:59:232132
[email protected]9f3fba52011-06-08 20:37:192133 return true;
2134}
2135
2136std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:202137 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:192138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2139 // Check if it's an extension-created worker, in which case we want to use
2140 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:202141 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:192142 const Extension* extension =
2143 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
2144 return extension ? extension->name() : std::string();
2145}
2146
[email protected]99907362012-01-11 05:41:402147void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2148 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:172149}
2150
[email protected]7a06d282013-05-03 04:39:332151// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:022152content::SpeechRecognitionManagerDelegate*
2153 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002154#if defined(ENABLE_INPUT_SPEECH)
2155 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
[email protected]a03f2d32012-03-14 00:26:322156#else
[email protected]855e18b2013-07-08 21:02:002157 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
2158 // need the base delegate without the bubble UI.
2159 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:322160#endif
[email protected]66cfec62012-02-24 17:57:512161}
2162
[email protected]ae6e9912011-07-27 01:18:282163net::NetLog* ChromeContentBrowserClient::GetNetLog() {
2164 return g_browser_process->net_log();
2165}
2166
[email protected]32538d92011-08-25 00:09:232167AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
2168 return new ChromeAccessTokenStore();
2169}
2170
[email protected]dbae6b02011-06-29 23:51:412171bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:012172 return true;
[email protected]dbae6b02011-06-29 23:51:412173}
2174
[email protected]64d69de42012-02-06 00:19:542175void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:322176 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:062177 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582178 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:062179 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062180
[email protected]33b79542013-10-18 11:18:452181 // Fill per-script font preferences. These are not registered on Android
2182 // - http://crbug.com/308033.
2183#if !defined(OS_ANDROID)
[email protected]f3986f82012-01-03 20:00:062184 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542185 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:062186 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542187 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:062188 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542189 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062190 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542191 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062192 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542193 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:062194 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542195 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:032196 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
2197 &web_prefs->pictograph_font_family_map);
[email protected]33b79542013-10-18 11:18:452198#endif
[email protected]f3986f82012-01-03 20:00:062199
[email protected]64d69de42012-02-06 00:19:542200 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:402201 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:542202 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:402203 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:542204 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:402205 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:542206 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:402207 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:062208
[email protected]ddf72142012-05-22 04:52:402209 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062210
[email protected]64d69de42012-02-06 00:19:542211 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:402212 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:542213 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:062214 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:542215 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:062216 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
[email protected]5bcdd99d2013-12-23 18:28:302217 const base::DictionaryValue* inspector_settings =
[email protected]f3986f82012-01-03 20:00:062218 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2219 if (inspector_settings) {
[email protected]5bcdd99d2013-12-23 18:28:302220 for (base::DictionaryValue::Iterator iter(*inspector_settings);
2221 !iter.IsAtEnd();
[email protected]c40ef1c2013-02-25 18:42:182222 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062223 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182224 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542225 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182226 std::make_pair(iter.key(), value));
2227 }
[email protected]f3986f82012-01-03 20:00:062228 }
2229 }
[email protected]64d69de42012-02-06 00:19:542230 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062231
[email protected]ddf72142012-05-22 04:52:402232 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542233 web_prefs->javascript_enabled = false;
2234 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2235 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402236 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542237 web_prefs->plugins_enabled = false;
2238 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2239 web_prefs->java_enabled = false;
2240 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402241 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062242
[email protected]64d69de42012-02-06 00:19:542243 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2244 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062245
[email protected]64d69de42012-02-06 00:19:542246 web_prefs->memory_info_enabled =
2247 prefs->GetBoolean(prefs::kEnableMemoryInfo);
2248 web_prefs->allow_displaying_insecure_content =
2249 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2250 web_prefs->allow_running_insecure_content =
2251 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322252#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:052253 web_prefs->font_scale_factor =
2254 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2255 web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment();
[email protected]d3b935f2012-10-19 23:14:322256 web_prefs->force_enable_zoom =
2257 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
2258#endif
[email protected]5c915252013-05-07 13:15:392259
[email protected]af4256d52013-06-04 20:39:072260#if defined(OS_ANDROID)
2261 web_prefs->password_echo_enabled =
2262 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2263#else
[email protected]9d06d88d2012-02-23 22:37:082264 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072265#endif
2266
[email protected]cfadadd2013-04-03 04:43:022267 web_prefs->asynchronous_spell_checking_enabled = true;
2268 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572269
[email protected]64d69de42012-02-06 00:19:542270 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062271 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542272 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062273 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542274 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062275 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2276
2277 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542278 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062279 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542280 web_prefs->default_encoding);
2281 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402282 prefs->ClearPref(prefs::kDefaultCharset);
2283 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062284 }
[email protected]64d69de42012-02-06 00:19:542285 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062286
[email protected]299d7f12012-05-23 05:31:152287 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232288 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132289 ExtensionService* service =
2290 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062291 if (service) {
[email protected]1e6e2ea2014-01-04 02:01:402292 const GURL& site_url = rvh->GetSiteInstance()->GetSiteURL();
2293 const Extension* extension =
2294 service->extensions()->GetByID(site_url.host());
[email protected]1bc28312012-11-08 08:31:532295 // Ensure that we are only granting extension preferences to URLs with
2296 // the correct scheme. Without this check, chrome-guest:// schemes used by
2297 // webview tags as well as hosts that happen to match the id of an
2298 // installed extension would get the wrong preferences.
[email protected]1e6e2ea2014-01-04 02:01:402299 if (site_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532300 extension_webkit_preferences::SetPreferences(
2301 extension, view_type, web_prefs);
2302 }
[email protected]f3986f82012-01-03 20:00:062303 }
2304
[email protected]cb2edf22013-04-01 20:25:232305 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542306 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232307 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062308 // Disable all kinds of acceleration for background pages.
2309 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542310 web_prefs->force_compositing_mode = false;
2311 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062312 }
[email protected]2e21fe292012-03-02 22:52:322313
2314#if defined(FILE_MANAGER_EXTENSION)
2315 // Override the default of suppressing HW compositing for WebUI pages for the
2316 // file manager, which is implemented using WebUI but wants HW acceleration
2317 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532318 if (url.SchemeIs(extensions::kExtensionScheme) &&
[email protected]2de96a52013-08-14 01:18:092319 url.host() == file_manager::kFileManagerAppId) {
[email protected]2e21fe292012-03-02 22:52:322320 web_prefs->accelerated_compositing_enabled = true;
2321 web_prefs->accelerated_2d_canvas_enabled = true;
2322 }
2323#endif
[email protected]181a95ee2011-07-12 19:26:362324}
2325
2326void ChromeContentBrowserClient::UpdateInspectorSetting(
2327 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062328 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582329 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062330 DictionaryPrefUpdate update(
2331 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2332 prefs::kWebKitInspectorSettings);
[email protected]5bcdd99d2013-12-23 18:28:302333 base::DictionaryValue* inspector_settings = update.Get();
2334 inspector_settings->SetWithoutPathExpansion(
2335 key, base::Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362336}
2337
[email protected]b8148ac2011-07-13 22:03:252338void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2339 BrowserURLHandler* handler) {
2340 // Add the default URL handlers.
2341 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2342 BrowserURLHandler::null_handler());
2343 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2344 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2345
[email protected]b3adbd02011-11-30 22:23:272346 // about: handler. Must come before chrome: handler, since it will
2347 // rewrite about: urls to chrome: URLs and then expect chrome: to
2348 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252349 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2350 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:032351
2352 // Handler to rewrite chrome://newtab for InstantExtended.
2353 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2354 &chrome::HandleNewTabURLReverseRewrite);
2355
[email protected]b8148ac2011-07-13 22:03:252356 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242357 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252358}
2359
2360void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372361 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582362 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472363 BrowsingDataRemover* remover =
2364 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552365 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2366 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252367 // BrowsingDataRemover takes care of deleting itself when done.
2368}
2369
2370void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372371 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582372 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472373 BrowsingDataRemover* remover =
2374 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232375 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552376 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252377 // BrowsingDataRemover takes care of deleting itself when done.
2378}
2379
[email protected]650b2d52013-02-10 03:41:452380base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:492381 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:322382}
2383
[email protected]c9b6eb62011-10-18 20:49:392384std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2385 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2386}
2387
[email protected]b7631cc2012-09-15 05:08:382388void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2389 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542390#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382391 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2392 scoped_ptr<ppapi::host::HostFactory>(
2393 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542394#endif
[email protected]b7631cc2012-09-15 05:08:382395}
2396
[email protected]0c7193742012-11-07 19:05:032397content::BrowserPpapiHost*
2398 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2399 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132400 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032401 while (!iter.Done()) {
[email protected]7c766e92013-11-22 20:44:022402 nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>(
2403 iter.GetDelegate());
[email protected]0c7193742012-11-07 19:05:032404 if (host->process() &&
2405 host->process()->GetData().id == plugin_process_id) {
2406 // Found the plugin.
2407 return host->browser_ppapi_host();
2408 }
2409 ++iter;
2410 }
2411 return NULL;
2412}
2413
[email protected]7b38b192013-03-23 18:39:312414bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2415 content::BrowserContext* browser_context, const GURL& site_url) {
2416 if (CommandLine::ForCurrentProcess()->HasSwitch(
2417 switches::kEnableBrowserPluginForAllViewTypes))
2418 return true;
2419
[email protected]22aa4f82013-09-24 17:01:442420 if (content::HasWebUIScheme(site_url))
2421 return true;
2422
[email protected]7b38b192013-03-23 18:39:312423 Profile* profile = Profile::FromBrowserContext(browser_context);
2424 ExtensionService* service =
2425 extensions::ExtensionSystem::Get(profile)->extension_service();
2426 if (!service)
2427 return false;
2428
[email protected]be9915fb2013-07-18 09:28:552429 const Extension* extension =
2430 service->extensions()->GetExtensionOrAppByURL(site_url);
[email protected]7b38b192013-03-23 18:39:312431 if (!extension)
2432 return false;
2433
[email protected]c2d2f102013-04-29 16:42:582434 return extension->HasAPIPermission(APIPermission::kWebView) ||
2435 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312436}
2437
[email protected]38cd8f7f2012-06-15 22:06:072438bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582439 content::BrowserContext* browser_context,
2440 const GURL& url,
[email protected]dda54822013-06-15 01:26:392441 bool private_api,
[email protected]8b92ed182013-09-21 04:47:122442 const content::SocketPermissionRequest* params) {
[email protected]93f72062013-05-29 20:29:402443#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372444 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]289c44b2013-12-17 03:26:572445 const extensions::ExtensionSet* extension_set = NULL;
[email protected]9d450492013-06-13 23:08:372446 if (profile) {
2447 extension_set = extensions::ExtensionSystem::Get(profile)->
2448 extension_service()->extensions();
2449 }
[email protected]dda54822013-06-15 01:26:392450
2451 if (private_api) {
2452 // Access to private socket APIs is controlled by the whitelist.
2453 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2454 allowed_socket_origins_)) {
2455 return true;
2456 }
2457 } else {
2458 // Access to public socket APIs is controlled by extension permissions.
2459 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2460 extension_set) {
2461 const Extension* extension = extension_set->GetByID(url.host());
2462 if (extension) {
[email protected]8b92ed182013-09-21 04:47:122463 if (params) {
2464 extensions::SocketPermission::CheckParam check_params(
2465 params->type, params->host, params->port);
2466 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2467 extension, extensions::APIPermission::kSocket,
2468 &check_params)) {
2469 return true;
2470 }
2471 } else {
2472 if (extensions::PermissionsData::HasAPIPermission(
2473 extension, extensions::APIPermission::kSocket)) {
2474 return true;
2475 }
[email protected]dda54822013-06-15 01:26:392476 }
2477 }
2478 }
2479 }
2480
2481 // Allow both public and private APIs if the command line says so.
2482 return IsHostAllowedByCommandLine(url, extension_set,
2483 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402484#else
[email protected]a658d452012-03-02 12:45:292485 return false;
[email protected]93f72062013-05-29 20:29:402486#endif
[email protected]e461da2f2012-02-16 19:06:402487}
2488
[email protected]a28e3302013-02-03 03:50:432489ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2490 WebContents* web_contents) {
2491 return new ChromeSelectFilePolicy(web_contents);
2492}
2493
[email protected]7d9424702013-04-14 13:14:162494void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2495 std::vector<std::string>* additional_allowed_schemes) {
2496 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2497 additional_allowed_schemes);
[email protected]98fa9dc2013-12-09 16:31:412498 additional_allowed_schemes->push_back(kChromeDevToolsScheme);
[email protected]7d9424702013-04-14 13:14:162499 additional_allowed_schemes->push_back(kChromeUIScheme);
2500 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2501}
2502
[email protected]f19bbf62013-07-09 01:22:322503void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:312504 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:532505 const base::FilePath& storage_partition_path,
[email protected]f19bbf62013-07-09 01:22:322506 ScopedVector<fileapi::FileSystemBackend>* additional_backends) {
[email protected]02250952013-04-24 23:52:532507#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032508 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]f19bbf62013-07-09 01:22:322509 additional_backends->push_back(new MediaFileSystemBackend(
[email protected]30a306f42013-06-10 03:09:032510 storage_partition_path,
2511 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]f19bbf62013-07-09 01:22:322512 MediaFileSystemBackend::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532513#endif
[email protected]b40015c2013-06-26 08:13:312514#if defined(OS_CHROMEOS)
[email protected]0ff5eb52013-07-10 20:35:312515 fileapi::ExternalMountPoints* external_mount_points =
2516 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:312517 DCHECK(external_mount_points);
[email protected]f19bbf62013-07-09 01:22:322518 chromeos::FileSystemBackend* backend =
2519 new chromeos::FileSystemBackend(
[email protected]0ff5eb52013-07-10 20:35:312520 new drive::FileSystemBackendDelegate(browser_context),
2521 browser_context->GetSpecialStoragePolicy(),
[email protected]b40015c2013-06-26 08:13:312522 external_mount_points,
2523 fileapi::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:322524 backend->AddSystemMountPoints();
2525 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal));
2526 additional_backends->push_back(backend);
[email protected]b40015c2013-06-26 08:13:312527#endif
[email protected]445b7db2013-08-02 04:58:272528
[email protected]e86e2be2013-08-30 11:20:392529 additional_backends->push_back(
2530 new sync_file_system::SyncFileSystemBackend(
2531 Profile::FromBrowserContext(browser_context)));
[email protected]02250952013-04-24 23:52:532532}
2533
[email protected]e60c0232011-11-11 19:56:352534#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182535void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2536 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382537 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082538 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392539#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452540 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392541 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2542 DCHECK(!data_path.empty());
2543
2544 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452545 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392546 data_path.AppendASCII("chrome_100_percent.pak");
[email protected]5db2b7492013-08-23 05:33:092547 base::PlatformFile f =
2548 base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
[email protected]29699c22012-10-03 23:57:392549 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372550 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392551 FileDescriptor(f, true)));
2552
2553 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452554 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392555 GetLocaleFilePath(locale, false);
2556 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2557 DCHECK(f != base::kInvalidPlatformFileValue);
2558 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2559 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382560
[email protected]650b2d52013-02-10 03:41:452561 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372562 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2563 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2564 DCHECK(f != base::kInvalidPlatformFileValue);
2565 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2566 FileDescriptor(f, true)));
2567
[email protected]0b818f72013-10-22 00:11:032568 if (breakpad::IsCrashReporterEnabled()) {
2569 f = breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2570 child_process_id);
[email protected]82174aa2013-01-22 21:53:432571 if (f == base::kInvalidPlatformFileValue) {
2572 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2573 "be disabled for this process.";
2574 } else {
2575 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2576 FileDescriptor(f, true)));
2577 }
[email protected]40da3e0c2012-10-24 22:03:382578 }
[email protected]40da3e0c2012-10-24 22:03:382579
2580#else
2581 int crash_signal_fd = GetCrashSignalFD(command_line);
2582 if (crash_signal_fd >= 0) {
2583 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2584 FileDescriptor(crash_signal_fd,
2585 false)));
2586 }
[email protected]29699c22012-10-03 23:57:392587#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302588}
[email protected]e60c0232011-11-11 19:56:352589#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302590
[email protected]4a65826d2011-08-25 16:04:012591#if defined(OS_WIN)
2592const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2593 return chrome::kBrowserResourcesDll;
2594}
[email protected]34f48682013-03-20 00:30:182595
2596void ChromeContentBrowserClient::PreSpawnRenderer(
2597 sandbox::TargetPolicy* policy,
2598 bool* success) {
2599 // This code is duplicated in nacl_exe_win_64.cc.
2600 // Allow the server side of a pipe restricted to the "chrome.nacl."
2601 // namespace so that it cannot impersonate other system or other chrome
2602 // service pipes.
2603 sandbox::ResultCode result = policy->AddRule(
2604 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2605 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2606 L"\\\\.\\pipe\\chrome.nacl.*");
2607 if (result != sandbox::SBOX_ALL_OK) {
2608 *success = false;
2609 return;
2610 }
2611
2612 // Renderers need to send named pipe handles and shared memory
2613 // segment handles to NaCl loader processes.
2614 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2615 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2616 L"File");
2617 if (result != sandbox::SBOX_ALL_OK) {
2618 *success = false;
2619 return;
2620 }
2621}
[email protected]4a65826d2011-08-25 16:04:012622#endif
2623
[email protected]a6868c22013-10-09 02:50:292624bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2625 content::BrowserContext* browser_context,
2626 const GURL& url) {
2627#if defined(ENABLE_PLUGINS)
2628 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]289c44b2013-12-17 03:26:572629 const extensions::ExtensionSet* extension_set = NULL;
[email protected]a6868c22013-10-09 02:50:292630 if (profile) {
2631 extension_set = extensions::ExtensionSystem::Get(profile)->
2632 extension_service()->extensions();
2633 }
2634 // TODO(teravest): Populate allowed_file_handle_origins_ when FileIO is moved
2635 // from the renderer to the browser.
2636 return IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2637 allowed_file_handle_origins_) ||
2638 IsHostAllowedByCommandLine(url, extension_set,
2639 switches::kAllowNaClFileHandleAPI);
2640#else
2641 return false;
2642#endif
2643}
2644
[email protected]8ddc6b7c2013-12-12 20:42:062645bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs() {
2646#if defined(ENABLE_PLUGINS)
2647 // Allow access for tests.
2648 if (CommandLine::ForCurrentProcess()->HasSwitch(
2649 switches::kEnablePepperTesting)) {
2650 return true;
2651 }
2652
2653 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
[email protected]5abe3e72013-12-19 18:58:542654 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown"
2655 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on
2656 // Chromium builds as well.
[email protected]8ddc6b7c2013-12-12 20:42:062657 return channel <= chrome::VersionInfo::CHANNEL_DEV;
2658#else
2659 return false;
2660#endif
2661}
2662
2663
[email protected]d977f9c2011-03-14 16:10:262664} // namespace chrome