blob: d059d5f79c19dffbdb2b918179f1ee7b5097d4b4 [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]9a60d1602013-09-11 04:09:1295#include "chrome/common/extensions/web_accessible_resources_handler.h"
[email protected]f1933792011-06-14 00:49:3496#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:3797#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:1298#include "chrome/common/pref_names.h"
[email protected]4de75262013-12-18 23:16:1299#include "chrome/common/profile_management_switches.h"
[email protected]3e69bc82011-05-26 23:22:38100#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09101#include "chrome/common/url_constants.h"
[email protected]264c0acac2013-10-01 13:33:30102#include "chrome/installer/util/google_update_settings.h"
[email protected]e8f3f9982013-05-10 20:59:53103#include "chromeos/chromeos_constants.h"
[email protected]ef42ee82013-11-01 05:26:13104#include "components/nacl/browser/nacl_browser.h"
[email protected]7c766e92013-11-22 20:44:02105#include "components/nacl/browser/nacl_host_message_filter.h"
106#include "components/nacl/browser/nacl_process_host.h"
[email protected]d5d383252013-07-04 14:44:32107#include "components/nacl/common/nacl_process_type.h"
[email protected]499e7c52013-10-04 16:03:09108#include "components/translate/common/translate_switches.h"
[email protected]75fee372013-03-06 00:42:44109#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43110#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30111#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38112#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03113#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31114#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03115#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59116#include "content/public/browser/child_process_security_policy.h"
[email protected]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]e4452d32013-11-15 23:07:41134#include "extensions/common/permissions/permissions_data.h"
[email protected]49d9b142013-07-19 08:50:27135#include "extensions/common/switches.h"
[email protected]c9b6eb62011-10-18 20:49:39136#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23137#include "grit/ui_resources.h"
[email protected]3b455502012-12-11 18:22:58138#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34139#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06140#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57141#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38142#include "ppapi/host/ppapi_host.h"
[email protected]8ddc6b7c2013-12-12 20:42:06143#include "ppapi/shared_impl/ppapi_switches.h"
[email protected]c9b6eb62011-10-18 20:49:39144#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08145#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24146#include "ui/message_center/message_center_util.h"
[email protected]b40015c2013-06-26 08:13:31147#include "webkit/browser/fileapi/external_mount_points.h"
[email protected]fab55e72013-05-31 07:06:18148#include "webkit/common/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:26149
[email protected]b48c9182011-10-26 18:03:30150#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38151#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18152#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38153#elif defined(OS_MACOSX)
154#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56155#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]0b818f72013-10-22 00:11:03156#include "components/breakpad/app/breakpad_mac.h"
[email protected]b48c9182011-10-26 18:03:30157#elif defined(OS_CHROMEOS)
158#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]f19bbf62013-07-09 01:22:32159#include "chrome/browser/chromeos/drive/file_system_backend_delegate.h"
160#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]5c915252013-05-07 13:15:39161#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49162#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]c94ac692013-07-27 00:50:10163#include "chrome/browser/chromeos/system/input_device_settings.h"
[email protected]931d1042013-04-05 17:50:44164#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26165#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30166#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09167#elif defined(OS_ANDROID)
[email protected]916615b2013-09-11 18:19:44168#include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
[email protected]81054f812012-08-30 00:47:09169#include "chrome/browser/chrome_browser_main_android.h"
[email protected]2b12c322013-09-19 06:53:56170#include "chrome/browser/media/encrypted_media_message_filter_android.h"
[email protected]29699c22012-10-03 23:57:39171#include "chrome/common/descriptors_android.h"
[email protected]0b818f72013-10-22 00:11:03172#include "components/breakpad/browser/crash_dump_manager_android.h"
[email protected]b48c9182011-10-26 18:03:30173#elif defined(OS_POSIX)
174#include "chrome/browser/chrome_browser_main_posix.h"
175#endif
176
[email protected]a220b5932013-09-21 03:47:44177#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]779dd282013-10-19 15:57:02178#include "base/debug/leak_annotations.h"
[email protected]b80f68432011-05-02 17:22:30179#include "base/linux_util.h"
[email protected]0b818f72013-10-22 00:11:03180#include "components/breakpad/app/breakpad_linux.h"
181#include "components/breakpad/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43182#endif
[email protected]b80f68432011-05-02 17:22:30183
[email protected]1e87df32012-09-12 04:53:19184#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
185#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
186#endif
187
[email protected]29699c22012-10-03 23:57:39188#if defined(OS_ANDROID)
189#include "ui/base/ui_base_paths.h"
[email protected]b255a8e0e82013-10-22 04:03:59190#include "ui/gfx/android/device_display_info.h"
[email protected]29699c22012-10-03 23:57:39191#endif
192
[email protected]d5bcd06f2013-04-21 08:07:24193#if !defined(OS_CHROMEOS)
194#include "chrome/browser/signin/signin_manager.h"
195#include "chrome/browser/signin/signin_manager_factory.h"
196#endif
197
[email protected]02250952013-04-24 23:52:53198#if !defined(OS_ANDROID)
[email protected]f19bbf62013-07-09 01:22:32199#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
[email protected]02250952013-04-24 23:52:53200#endif
201
[email protected]6ef98b5a2013-05-31 23:58:31202#if defined(ENABLE_WEBRTC)
203#include "chrome/browser/media/webrtc_logging_handler_host.h"
204#endif
205
[email protected]855e18b2013-07-08 21:02:00206#if defined(ENABLE_INPUT_SPEECH)
207#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h"
208#endif
209
[email protected]02a3dc122013-06-13 15:07:53210#if defined(FILE_MANAGER_EXTENSION)
[email protected]473c9a4f2013-09-05 03:09:46211#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]02a3dc122013-06-13 15:07:53212#endif
213
[email protected]e8b6ca02013-07-10 18:00:51214#if defined(TOOLKIT_GTK)
215#include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h"
216#endif
217
218#if defined(TOOLKIT_VIEWS)
219#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
220#endif
221
222#if defined(USE_ASH)
223#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
224#endif
225
226#if defined(USE_AURA)
227#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
228#endif
229
230#if defined(USE_X11)
231#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
232#endif
233
[email protected]c6ce08072013-07-31 07:48:53234#if defined(ENABLE_SPELLCHECK)
235#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
236#endif
237
[email protected]a1221aea2013-11-07 01:31:30238using blink::WebWindowFeatures;
[email protected]c7abd422012-09-25 00:20:08239using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47240using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03241using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39242using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31243using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59244using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08245using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00246using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11247using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33248using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13249using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06250using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34251using extensions::Extension;
[email protected]38427a12013-11-09 17:34:20252using extensions::InfoMap;
[email protected]1d5e58b2013-01-31 08:41:40253using extensions::Manifest;
[email protected]593d2a72013-07-26 08:48:38254using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39255
[email protected]c5dbef02011-05-13 05:06:09256namespace {
257
[email protected]eabbfb12013-04-05 23:28:35258// Cached version of the locale so we can return the locale on the I/O
259// thread.
260base::LazyInstance<std::string> g_io_thread_application_locale;
261
[email protected]93f72062013-05-29 20:29:40262#if defined(ENABLE_PLUGINS)
[email protected]10c39222013-11-13 20:09:25263const char* kPredefinedAllowedFileHandleOrigins[] = {
264 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
265 "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789
266};
267
[email protected]e461da2f2012-02-16 19:06:40268const char* kPredefinedAllowedSocketOrigins[] = {
269 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18270 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45271 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
272 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
273 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
274 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35275 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54276 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
277 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
278 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
279 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
280 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
281 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38282 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58283 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29284 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]3f6fca22013-08-12 23:13:42285 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
286 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
287 "4EB74897CB187C7633357C2FE832E0AD6A44883A", // see crbug.com/234789
288 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
289 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
290 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40291};
[email protected]93f72062013-05-29 20:29:40292#endif
[email protected]e461da2f2012-02-16 19:06:40293
[email protected]f8f93eb2012-09-25 03:06:24294// Returns a copy of the given url with its host set to given host and path set
295// to given path. Other parts of the url will be the same.
296GURL ReplaceURLHostAndPath(const GURL& url,
297 const std::string& host,
298 const std::string& path) {
299 url_canon::Replacements<char> replacements;
300 replacements.SetHost(host.c_str(),
301 url_parse::Component(0, host.length()));
302 replacements.SetPath(path.c_str(),
303 url_parse::Component(0, path.length()));
304 return url.ReplaceComponents(replacements);
305}
306
307// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
308GURL AddUberHost(const GURL& url) {
309 const std::string uber_host = chrome::kChromeUIUberHost;
310 const std::string new_path = url.host() + url.path();
311
312 return ReplaceURLHostAndPath(url, uber_host, new_path);
313}
314
[email protected]045bf7c2012-09-28 20:27:36315// If url->host() is "chrome" and url->path() has characters other than the
316// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
317// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24318bool RemoveUberHost(GURL* url) {
319 if (url->host() != chrome::kChromeUIUberHost)
320 return false;
321
[email protected]045bf7c2012-09-28 20:27:36322 if (url->path().empty() || url->path() == "/")
323 return false;
324
[email protected]f8f93eb2012-09-25 03:06:24325 const std::string old_path = url->path();
326
327 const std::string::size_type separator = old_path.find('/', 1);
328 std::string new_host;
329 std::string new_path;
330 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36331 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24332 } else {
333 new_host = old_path.substr(1, separator - 1);
334 new_path = old_path.substr(separator);
335 }
336
[email protected]44e8add2013-06-13 17:29:15337 // Do not allow URLs with paths empty before the first slash since we can't
338 // have an empty host. (e.g "foo://chrome//")
339 if (new_host.empty())
340 return false;
341
[email protected]f8f93eb2012-09-25 03:06:24342 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
343
[email protected]44e8add2013-06-13 17:29:15344 DCHECK(url->is_valid());
345
[email protected]f8f93eb2012-09-25 03:06:24346 return true;
347}
348
[email protected]b8148ac2011-07-13 22:03:25349// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42350bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24351 // Do not handle special URLs such as "about:foo"
352 if (!url->host().empty()) {
353 const GURL chrome_url = AddUberHost(*url);
354
355 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
356 // be called.
357 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
358 browser_context, chrome_url))
359 return true;
360 }
361
[email protected]863f70a2012-01-27 02:05:50362 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
363 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25364 return false;
365
[email protected]fe69558d2012-03-12 11:34:49366#if defined(OS_CHROMEOS)
367 // Special case : in ChromeOS in Guest mode bookmarks and history are
368 // disabled for security reasons. New tab page explains the reasons, so
369 // we redirect user to new tab page.
370 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
371 if (url->SchemeIs(chrome::kChromeUIScheme) &&
372 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
[email protected]b9171622013-10-01 22:05:23373#if defined(ENABLE_ENHANCED_BOOKMARKS)
374 url->DomainIs(chrome::kChromeUIEnhancedBookmarksHost) ||
375#endif
[email protected]fe69558d2012-03-12 11:34:49376 url->DomainIs(chrome::kChromeUIHistoryHost))) {
377 // Rewrite with new tab URL
378 *url = GURL(chrome::kChromeUINewTabURL);
379 }
380 }
381#endif
382
[email protected]b8148ac2011-07-13 22:03:25383 return true;
384}
385
[email protected]f8f93eb2012-09-25 03:06:24386// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
387// "chrome://foo/".
388bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
389 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
390 return false;
391
392 return RemoveUberHost(url);
393}
394
[email protected]8d3132f62011-10-12 07:13:42395// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
396// below. Extension, and isolated apps require different privileges to be
397// granted to their RenderProcessHosts. This classification allows us to make
398// sure URLs are served by hosts with the right set of privileges.
399enum RenderProcessHostPrivilege {
400 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45401 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42402 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45403 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42404};
405
406RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
407 const GURL& url,
408 ExtensionService* service) {
409 // Default to a normal renderer cause it is lower privileged. This should only
410 // occur if the URL on a site instance is either malformed, or uninitialized.
411 // If it is malformed, then there is no need for better privileges anyways.
412 // If it is uninitialized, but eventually settles on being an a scheme other
413 // than normal webrenderer, the navigation logic will correct us out of band
414 // anyways.
415 if (!url.is_valid())
416 return PRIV_NORMAL;
417
[email protected]885c0e92012-11-13 20:27:42418 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44419 const Extension* extension =
420 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43421 if (extension &&
422 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42423 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45424 if (extension && extension->is_hosted_app())
425 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42426
427 return PRIV_EXTENSION;
428 }
429
430 return PRIV_NORMAL;
431}
432
433RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30434 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46435 extensions::ProcessMap* process_map,
436 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46437 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30438 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46439 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21440 return PRIV_NORMAL;
441
[email protected]6f371442011-11-09 06:45:46442 for (std::set<std::string>::iterator iter = extension_ids.begin();
443 iter != extension_ids.end(); ++iter) {
444 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43445 if (extension &&
446 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42447 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45448 if (extension && extension->is_hosted_app())
449 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42450 }
451
[email protected]676f6ab2011-10-19 20:23:21452 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42453}
454
[email protected]6786bf402011-12-03 15:19:45455bool CertMatchesFilter(const net::X509Certificate& cert,
456 const base::DictionaryValue& filter) {
457 // TODO(markusheintz): This is the minimal required filter implementation.
458 // Implement a better matcher.
459
460 // An empty filter matches any client certificate since no requirements are
461 // specified at all.
462 if (filter.empty())
463 return true;
464
465 std::string common_name;
466 if (filter.GetString("ISSUER.CN", &common_name) &&
467 (cert.issuer().common_name == common_name)) {
468 return true;
469 }
470 return false;
471}
472
[email protected]1d51882f2013-11-12 01:59:02473#if !defined(OS_ANDROID)
[email protected]f3986f82012-01-03 20:00:06474// Fills |map| with the per-script font prefs under path |map_name|.
475void FillFontFamilyMap(const PrefService* prefs,
476 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53477 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]33b79542013-10-18 11:18:45478 // TODO: Get rid of the brute-force scan over possible (font family / script)
479 // combinations - see http://crbug.com/308095.
[email protected]f3986f82012-01-03 20:00:06480 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
481 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
482 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
483 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23484 if (!font_family.empty())
485 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06486 }
487}
488
[email protected]a1733df2012-06-22 11:24:18489#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]0b818f72013-10-22 00:11:03490breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost(
491 const std::string& process_type) {
[email protected]779dd282013-10-19 15:57:02492 base::FilePath dumps_path;
493 PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
494 {
495 ANNOTATE_SCOPED_MEMORY_LEAK;
[email protected]0b818f72013-10-22 00:11:03496 breakpad::CrashHandlerHostLinux* crash_handler =
497 new breakpad::CrashHandlerHostLinux(
498 process_type, dumps_path, getenv(env_vars::kHeadless) == NULL);
[email protected]779dd282013-10-19 15:57:02499 crash_handler->StartUploaderThread();
500 return crash_handler;
501 }
502}
503
[email protected]a1733df2012-06-22 11:24:18504int GetCrashSignalFD(const CommandLine& command_line) {
505 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]0b818f72013-10-22 00:11:03506 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02507 if (!crash_handler)
508 crash_handler = CreateCrashHandlerHost("extension");
[email protected]a1733df2012-06-22 11:24:18509 return crash_handler->GetDeathSignalSocket();
510 }
511
512 std::string process_type =
513 command_line.GetSwitchValueASCII(switches::kProcessType);
514
[email protected]779dd282013-10-19 15:57:02515 if (process_type == switches::kRendererProcess) {
[email protected]0b818f72013-10-22 00:11:03516 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02517 if (!crash_handler)
518 crash_handler = CreateCrashHandlerHost(process_type);
519 return crash_handler->GetDeathSignalSocket();
520 }
[email protected]a1733df2012-06-22 11:24:18521
[email protected]779dd282013-10-19 15:57:02522 if (process_type == switches::kPluginProcess) {
[email protected]0b818f72013-10-22 00:11:03523 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02524 if (!crash_handler)
525 crash_handler = CreateCrashHandlerHost(process_type);
526 return crash_handler->GetDeathSignalSocket();
527 }
[email protected]a1733df2012-06-22 11:24:18528
[email protected]779dd282013-10-19 15:57:02529 if (process_type == switches::kPpapiPluginProcess) {
[email protected]0b818f72013-10-22 00:11:03530 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02531 if (!crash_handler)
532 crash_handler = CreateCrashHandlerHost(process_type);
533 return crash_handler->GetDeathSignalSocket();
534 }
[email protected]a1733df2012-06-22 11:24:18535
[email protected]779dd282013-10-19 15:57:02536 if (process_type == switches::kGpuProcess) {
[email protected]0b818f72013-10-22 00:11:03537 static breakpad::CrashHandlerHostLinux* crash_handler = NULL;
[email protected]779dd282013-10-19 15:57:02538 if (!crash_handler)
539 crash_handler = CreateCrashHandlerHost(process_type);
540 return crash_handler->GetDeathSignalSocket();
541 }
[email protected]a1733df2012-06-22 11:24:18542
543 return -1;
544}
545#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]1d51882f2013-11-12 01:59:02546#endif // !defined(OS_ANDROID)
[email protected]a1733df2012-06-22 11:24:18547
[email protected]d5bcd06f2013-04-21 08:07:24548#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30549GURL GetEffectiveURLForSignin(const GURL& url) {
550 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
551
552 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03553 // Copy the path because the argument to SetPathStr must outlive
554 // the Replacements object.
555 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30556 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03557 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30558 effective_url = effective_url.ReplaceComponents(replacements);
559 return effective_url;
560}
[email protected]d5bcd06f2013-04-21 08:07:24561#endif
[email protected]970c63e2013-03-07 00:25:30562
[email protected]eabbfb12013-04-05 23:28:35563void SetApplicationLocaleOnIOThread(const std::string& locale) {
564 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
565 g_io_thread_application_locale.Get() = locale;
566}
567
[email protected]916615b2013-09-11 18:19:44568void HandleBlockedPopupOnUIThread(const BlockedWindowParams& params) {
569 WebContents* tab = tab_util::GetWebContentsByID(params.render_process_id(),
570 params.opener_id());
[email protected]190e5e22013-07-27 05:59:23571 if (!tab)
572 return;
573
[email protected]190e5e22013-07-27 05:59:23574 PopupBlockerTabHelper* popup_helper =
575 PopupBlockerTabHelper::FromWebContents(tab);
576 if (!popup_helper)
577 return;
[email protected]916615b2013-09-11 18:19:44578 popup_helper->AddBlockedPopup(params);
[email protected]190e5e22013-07-27 05:59:23579}
[email protected]190e5e22013-07-27 05:59:23580
[email protected]916615b2013-09-11 18:19:44581#if defined(OS_ANDROID)
[email protected]b255a8e0e82013-10-22 04:03:59582
[email protected]916615b2013-09-11 18:19:44583void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams& params) {
584 WebContents* web_contents =
585 tab_util::GetWebContentsByID(params.render_process_id(),
586 params.opener_id());
587 if (!web_contents)
588 return;
589
590 SingleTabModeTabHelper::FromWebContents(web_contents)->HandleOpenUrl(params);
591}
[email protected]b255a8e0e82013-10-22 04:03:59592
[email protected]ded00dc2013-11-01 00:37:05593float GetDeviceScaleAdjustment() {
[email protected]b255a8e0e82013-10-22 04:03:59594 static const float kMinFSM = 1.05f;
595 static const int kWidthForMinFSM = 320;
596 static const float kMaxFSM = 1.3f;
597 static const int kWidthForMaxFSM = 800;
598
599 gfx::DeviceDisplayInfo info;
600 int minWidth = info.GetSmallestDIPWidth();
601
602 if (minWidth <= kWidthForMinFSM)
603 return kMinFSM;
604 if (minWidth >= kWidthForMaxFSM)
605 return kMaxFSM;
606
607 // The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
608 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) /
609 (kWidthForMaxFSM - kWidthForMinFSM);
610 return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
611}
612
[email protected]916615b2013-09-11 18:19:44613#endif // defined(OS_ANDROID)
614
[email protected]9dbfff12011-07-01 19:37:07615} // namespace
[email protected]c5dbef02011-05-13 05:06:09616
[email protected]d977f9c2011-03-14 16:10:26617namespace chrome {
618
[email protected]e461da2f2012-02-16 19:06:40619ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40620#if defined(ENABLE_PLUGINS)
[email protected]10c39222013-11-13 20:09:25621 for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i)
622 allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40623 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
624 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40625#endif
[email protected]1deace22013-05-22 06:14:46626
627 permissions_policy_delegate_.reset(
628 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40629}
630
631ChromeContentBrowserClient::~ChromeContentBrowserClient() {
632}
633
[email protected]bca18382012-06-25 19:15:23634// static
[email protected]37ca3fe02013-07-05 15:32:44635void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34636 user_prefs::PrefRegistrySyncable* registry) {
637 registry->RegisterBooleanPref(
638 prefs::kDisable3DAPIs,
639 false,
640 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
641 registry->RegisterBooleanPref(
642 prefs::kEnableHyperlinkAuditing,
643 true,
644 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
645 registry->RegisterBooleanPref(
646 prefs::kEnableMemoryInfo,
647 false,
648 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23649}
650
[email protected]eabbfb12013-04-05 23:28:35651// static
652void ChromeContentBrowserClient::SetApplicationLocale(
653 const std::string& locale) {
654 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
655
656 // This object is guaranteed to outlive all threads so we don't have to
657 // worry about the lack of refcounting and can just post as Unretained.
658 //
659 // The common case is that this function is called early in Chrome startup
660 // before any threads are created (it will also be called later if the user
661 // changes the pref). In this case, there will be no threads created and
662 // posting will fail. When there are no threads, we can just set the string
663 // without worrying about threadsafety.
664 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
665 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
666 g_io_thread_application_locale.Get() = locale;
667 }
668}
669
[email protected]50462bf02011-11-21 19:13:31670content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
671 const content::MainFunctionParams& parameters) {
672 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30673 // Construct the Main browser parts based on the OS type.
674#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31675 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04676#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31677 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30678#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22679 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26680#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31681 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14682#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09683 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30684#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31685 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04686#else
[email protected]b48c9182011-10-26 18:03:30687 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31688 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30689#endif
690
[email protected]7e75e4a2013-05-17 17:20:03691 chrome::AddProfilesExtraParts(main_parts);
692
[email protected]c7480942011-11-08 19:18:27693 // Construct additional browser parts. Stages are called in the order in
694 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22695#if defined(TOOLKIT_GTK)
[email protected]e8b6ca02013-07-10 18:00:51696 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04697#endif
[email protected]c7480942011-11-08 19:18:27698
699#if defined(TOOLKIT_VIEWS)
[email protected]e8b6ca02013-07-10 18:00:51700 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27701#endif
702
[email protected]dc04be7c2012-03-15 23:57:49703#if defined(USE_ASH)
[email protected]e8b6ca02013-07-10 18:00:51704 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
[email protected]dc04be7c2012-03-15 23:57:49705#endif
706
[email protected]e050ef142012-03-21 01:04:24707#if defined(USE_AURA)
[email protected]e8b6ca02013-07-10 18:00:51708 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
709#endif
710
711#if defined(USE_X11)
712 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:24713#endif
714
[email protected]95132f52013-04-12 02:19:04715 chrome::AddMetricsExtraParts(main_parts);
716
[email protected]50462bf02011-11-21 19:13:31717 return main_parts;
[email protected]f967b722011-09-07 00:58:04718}
719
[email protected]e94bbcb2012-09-07 05:33:57720std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19721 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57722 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53723 std::string partition_id;
724
725 // The partition ID for webview guest processes is the string value of its
726 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
[email protected]6eb1a11e2013-10-09 00:54:37727 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:53728 partition_id = site.spec();
729
[email protected]056efdc2013-04-06 00:14:53730 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53731 return partition_id;
732}
733
734bool ChromeContentBrowserClient::IsValidStoragePartitionId(
735 content::BrowserContext* browser_context,
736 const std::string& partition_id) {
737 // The default ID is empty and is always valid.
738 if (partition_id.empty())
739 return true;
740
741 return GURL(partition_id).is_valid();
742}
743
744void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
745 content::BrowserContext* browser_context,
746 const GURL& site,
[email protected]14acc642012-11-17 12:20:10747 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53748 std::string* partition_domain,
749 std::string* partition_name,
750 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10751 // Default to the browser-wide storage partition and override based on |site|
752 // below.
753 partition_domain->clear();
754 partition_name->clear();
755 *in_memory = false;
756
[email protected]3f24f97c2013-11-17 21:53:33757 bool success = GuestView::GetGuestPartitionConfigForSite(
758 site, partition_domain, partition_name, in_memory);
759
760 if (!success && site.SchemeIs(extensions::kExtensionScheme)) {
[email protected]14acc642012-11-17 12:20:10761 // If |can_be_default| is false, the caller is stating that the |site|
762 // should be parsed as if it had isolated storage. In particular it is
763 // important to NOT check ExtensionService for the is_storage_isolated()
764 // attribute because this code path is run during Extension uninstall
765 // to do cleanup after the Extension has already been unloaded from the
766 // ExtensionService.
767 bool is_isolated = !can_be_default;
768 if (can_be_default) {
769 const Extension* extension = NULL;
770 Profile* profile = Profile::FromBrowserContext(browser_context);
771 ExtensionService* extension_service =
772 extensions::ExtensionSystem::Get(profile)->extension_service();
773 if (extension_service) {
[email protected]be9915fb2013-07-18 09:28:55774 extension =
775 extension_service->extensions()->GetExtensionOrAppByURL(site);
[email protected]561e33d52013-04-03 06:58:43776 if (extension &&
777 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10778 is_isolated = true;
779 }
780 }
781 }
[email protected]1bc28312012-11-08 08:31:53782
[email protected]14acc642012-11-17 12:20:10783 if (is_isolated) {
784 CHECK(site.has_host());
785 // For extensions with isolated storage, the the host of the |site| is
786 // the |partition_domain|. The |in_memory| and |partition_name| are only
787 // used in guest schemes so they are cleared here.
788 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53789 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10790 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53791 }
[email protected]d1198fd2012-08-13 22:50:19792 }
793
[email protected]14acc642012-11-17 12:20:10794 // Assert that if |can_be_default| is false, the code above must have found a
795 // non-default partition. If this fails, the caller has a serious logic
796 // error about which StoragePartition they expect to be in and it is not
797 // safe to continue.
798 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44799}
800
[email protected]38b098f2012-03-14 21:11:57801content::WebContentsViewDelegate*
802 ChromeContentBrowserClient::GetWebContentsViewDelegate(
803 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27804 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32805}
806
[email protected]738f57a2013-06-29 21:06:54807void ChromeContentBrowserClient::GuestWebContentsCreated(
[email protected]dbbce92c2013-10-31 16:51:19808 SiteInstance* guest_site_instance,
[email protected]738f57a2013-06-29 21:06:54809 WebContents* guest_web_contents,
810 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22811 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54812 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]dbbce92c2013-10-31 16:51:19813 if (!guest_site_instance) {
814 NOTREACHED();
815 return;
816 }
817 GURL guest_site_url = guest_site_instance->GetSiteURL();
818 const std::string& extension_id = guest_site_url.host();
819
820 Profile* profile = Profile::FromBrowserContext(
821 guest_web_contents->GetBrowserContext());
822 ExtensionService* service =
823 extensions::ExtensionSystem::Get(profile)->extension_service();
824 if (!service) {
825 NOTREACHED();
826 return;
827 }
828
829 /// TODO(fsamuel): In the future, certain types of GuestViews won't require
830 // extension bindings. At that point, we should clear |extension_id| instead
831 // of exiting early.
832 if (!service->GetExtensionById(extension_id, false) &&
833 !CommandLine::ForCurrentProcess()->HasSwitch(
834 switches::kEnableBrowserPluginForAllViewTypes)) {
835 NOTREACHED();
836 return;
837 }
838
[email protected]738f57a2013-06-29 21:06:54839 if (opener_web_contents) {
840 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
841 if (!guest) {
842 NOTREACHED();
843 return;
844 }
845
[email protected]50c827d2013-09-13 21:36:09846 // Create a new GuestView of the same type as the opener.
847 *guest_delegate =
[email protected]dbbce92c2013-10-31 16:51:19848 GuestView::Create(guest_web_contents,
849 extension_id,
850 guest->GetViewType());
[email protected]738f57a2013-06-29 21:06:54851 return;
852 }
853
854 if (!extra_params) {
855 NOTREACHED();
856 return;
857 }
858 std::string api_type;
[email protected]90547d72013-08-06 05:57:27859 extra_params->GetString(guestview::kParameterApi, &api_type);
[email protected]738f57a2013-06-29 21:06:54860
[email protected]dbbce92c2013-10-31 16:51:19861 if (api_type.empty())
862 return;
863
[email protected]50c827d2013-09-13 21:36:09864 *guest_delegate =
865 GuestView::Create(guest_web_contents,
[email protected]dbbce92c2013-10-31 16:51:19866 extension_id,
[email protected]50c827d2013-09-13 21:36:09867 GuestView::GetViewTypeFromString(api_type));
[email protected]738f57a2013-06-29 21:06:54868}
869
[email protected]44295a12013-06-05 08:45:46870void ChromeContentBrowserClient::GuestWebContentsAttached(
871 WebContents* guest_web_contents,
872 WebContents* embedder_web_contents,
[email protected]5715566a2013-06-25 00:04:53873 const base::DictionaryValue& extra_params) {
[email protected]22aa4f82013-09-24 17:01:44874
[email protected]dbbce92c2013-10-31 16:51:19875 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
876 if (!guest) {
[email protected]efd6fb02013-08-05 04:44:06877 // It's ok to return here, since we could be running a browser plugin
878 // outside an extension, and don't need to attach a
879 // BrowserPluginGuestDelegate in that case;
880 // e.g. running with flag --enable-browser-plugin-for-all-view-types.
[email protected]738f57a2013-06-29 21:06:54881 return;
[email protected]18699372013-06-25 20:42:55882 }
[email protected]dbbce92c2013-10-31 16:51:19883 guest->Attach(embedder_web_contents, extra_params);
[email protected]44703cc72013-01-24 04:56:06884}
885
[email protected]f3b1a082011-11-18 00:34:30886void ChromeContentBrowserClient::RenderProcessHostCreated(
887 content::RenderProcessHost* host) {
888 int id = host->GetID();
889 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41890 net::URLRequestContextGetter* context =
891 profile->GetRequestContextForRenderProcess(id);
892
[email protected]ba780c12013-10-01 17:07:06893 host->AddFilter(new ChromeRenderMessageFilter(id, profile, context));
[email protected]ebd71962012-12-20 02:56:55894#if defined(ENABLE_PLUGINS)
[email protected]ba780c12013-10-01 17:07:06895 host->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55896#endif
[email protected]658677f2012-06-09 06:04:02897#if defined(ENABLE_PRINTING)
[email protected]ba780c12013-10-01 17:07:06898 host->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03899#endif
[email protected]ba780c12013-10-01 17:07:06900 host->AddFilter(new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]c6ce08072013-07-31 07:48:53901#if defined(ENABLE_SPELLCHECK)
[email protected]ba780c12013-10-01 17:07:06902 host->AddFilter(new SpellCheckMessageFilter(id));
[email protected]c6ce08072013-07-31 07:48:53903#endif
[email protected]7ceb99012011-12-21 08:05:56904#if defined(OS_MACOSX)
[email protected]ba780c12013-10-01 17:07:06905 host->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56906#endif
[email protected]ba780c12013-10-01 17:07:06907 host->AddFilter(new ChromeNetBenchmarkingMessageFilter(
[email protected]43535512013-02-20 20:41:41908 id, profile, context));
[email protected]ba780c12013-10-01 17:07:06909 host->AddFilter(new prerender::PrerenderMessageFilter(id, profile));
[email protected]ba780c12013-10-01 17:07:06910 host->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31911#if defined(ENABLE_WEBRTC)
[email protected]10e5c5e52013-10-03 18:44:06912 WebRtcLoggingHandlerHost* webrtc_logging_handler_host =
[email protected]135bc1d2013-10-21 09:11:37913 new WebRtcLoggingHandlerHost(profile);
[email protected]10e5c5e52013-10-03 18:44:06914 host->AddFilter(webrtc_logging_handler_host);
915 host->SetUserData(host, new base::UserDataAdapter<WebRtcLoggingHandlerHost>(
916 webrtc_logging_handler_host));
[email protected]6ef98b5a2013-05-31 23:58:31917#endif
[email protected]01e59752013-06-18 00:17:35918#if !defined(DISABLE_NACL)
[email protected]7c766e92013-11-22 20:44:02919 host->AddFilter(new nacl::NaClHostMessageFilter(
[email protected]14230ca2013-06-26 23:33:03920 id, profile->IsOffTheRecord(),
[email protected]a2b4c5c2013-10-18 02:06:07921 profile->GetPath(),
[email protected]14230ca2013-06-26 23:33:03922 context));
[email protected]01e59752013-06-18 00:17:35923#endif
[email protected]2b12c322013-09-19 06:53:56924#if defined(OS_ANDROID)
[email protected]ba780c12013-10-01 17:07:06925 host->AddFilter(new EncryptedMediaMessageFilterAndroid());
[email protected]2b12c322013-09-19 06:53:56926#endif
[email protected]4de75262013-12-18 23:16:12927 if (switches::IsNewProfileManagement())
[email protected]914cf6712013-12-05 01:14:06928 host->AddFilter(new PrincipalsMessageFilter(id));
[email protected]3e69bc82011-05-26 23:22:38929
[email protected]2ccf45c2011-08-19 23:35:50930 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
931 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07932
933 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56934
935 RendererContentSettingRules rules;
[email protected]06153f02013-12-04 03:01:28936 if (host->IsGuest()) {
937 GuestView::GetDefaultContentSettingRules(&rules, profile->IsOffTheRecord());
938 } else {
939 GetRendererContentSettingRules(
940 profile->GetHostContentSettingsMap(), &rules);
941 }
[email protected]edece212011-11-16 11:56:56942 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14943}
944
[email protected]3d7474ff2011-07-27 17:47:37945GURL ChromeContentBrowserClient::GetEffectiveURL(
946 content::BrowserContext* browser_context, const GURL& url) {
947 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52948 if (!profile)
949 return url;
950
[email protected]b3cb3a32013-07-31 01:32:29951 // If the input |url| should be assigned to the Instant renderer, make its
952 // effective URL distinct from other URLs on the search provider's domain.
953 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
954 return chrome::GetEffectiveURLForInstant(url, profile);
955
[email protected]d5bcd06f2013-04-21 08:07:24956#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30957 // If the input |url| should be assigned to the Signin renderer, make its
958 // effective URL distinct from other URLs on the signin service's domain.
959 // Note that the signin renderer will be allowed to sign the user in to
960 // Chrome.
961 if (SigninManager::IsWebBasedSigninFlowURL(url))
962 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24963#endif
[email protected]970c63e2013-03-07 00:25:30964
[email protected]c5dec6292013-01-25 04:54:52965 // If the input |url| is part of an installed app, the effective URL is an
966 // extension URL with the ID of that extension as the host. This has the
967 // effect of grouping apps together in a common SiteInstance.
968 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13969 extensions::ExtensionSystem::Get(profile)->extension_service();
970 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08971 return url;
972
[email protected]06bdd2b2012-11-30 18:47:13973 const Extension* extension = extension_service->extensions()->
[email protected]be9915fb2013-07-18 09:28:55974 GetHostedAppByURL(url);
[email protected]36fb2c7c2011-04-04 15:49:08975 if (!extension)
976 return url;
977
[email protected]15877ca2011-11-18 22:40:52978 // Bookmark apps do not use the hosted app process model, and should be
979 // treated as normal URLs.
980 if (extension->from_bookmark())
981 return url;
982
[email protected]36fb2c7c2011-04-04 15:49:08983 // If the URL is part of an extension's web extent, convert it to an
984 // extension URL.
985 return extension->GetResourceURL(url.path());
986}
987
[email protected]056ad2a2011-07-12 02:13:55988bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37989 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52990 // Non-extension, non-Instant URLs should generally use
991 // process-per-site-instance. Because we expect to use the effective URL,
992 // URLs for hosted apps (apart from bookmark apps) should have an extension
993 // scheme by now.
994
995 Profile* profile = Profile::FromBrowserContext(browser_context);
996 if (!profile)
997 return false;
998
[email protected]df113a12013-07-24 04:56:08999 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:521000 return true;
1001
[email protected]d5bcd06f2013-04-21 08:07:241002#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301003 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
1004 return true;
[email protected]d5bcd06f2013-04-21 08:07:241005#endif
[email protected]970c63e2013-03-07 00:25:301006
[email protected]885c0e92012-11-13 20:27:421007 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:551008 return false;
1009
[email protected]c5dec6292013-01-25 04:54:521010 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:131011 extensions::ExtensionSystem::Get(profile)->extension_service();
1012 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:551013 return false;
1014
[email protected]be9915fb2013-07-18 09:28:551015 const Extension* extension =
1016 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
[email protected]056ad2a2011-07-12 02:13:551017 if (!extension)
1018 return false;
1019
1020 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:531021 // permission, or that does not allow JavaScript access to the background
1022 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:551023 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:401024 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:061025 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:291026 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:531027 return false;
1028 }
1029 }
[email protected]056ad2a2011-07-12 02:13:551030
[email protected]7b54ca02012-03-02 18:06:531031 // Hosted apps that have script access to their background page must use
1032 // process per site, since all instances can make synchronous calls to the
1033 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:551034 return true;
1035}
1036
[email protected]672c8c12013-03-07 12:30:061037// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:411038void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1039 std::vector<std::string>* additional_schemes) {
1040 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:061041}
1042
[email protected]6bd30072013-02-08 18:17:111043net::URLRequestContextGetter*
1044ChromeContentBrowserClient::CreateRequestContext(
1045 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:061046 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:111047 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:061048 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111049}
1050
1051net::URLRequestContextGetter*
1052ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
1053 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:401054 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:111055 bool in_memory,
[email protected]672c8c12013-03-07 12:30:061056 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:111057 Profile* profile = Profile::FromBrowserContext(browser_context);
1058 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:061059 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111060}
1061
[email protected]46fb9442011-12-09 17:57:471062bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1063 return ProfileIOData::IsHandledURL(url);
1064}
1065
[email protected]c4365fa42013-05-14 01:08:241066bool ChromeContentBrowserClient::CanCommitURL(
1067 content::RenderProcessHost* process_host,
1068 const GURL& url) {
1069 // We need to let most extension URLs commit in any process, since this can
1070 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1071 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1072 // cannot be loaded in iframes and should never be requested outside its
1073 // process.
1074 Profile* profile =
1075 Profile::FromBrowserContext(process_host->GetBrowserContext());
1076 ExtensionService* service =
1077 extensions::ExtensionSystem::Get(profile)->extension_service();
1078 if (!service)
1079 return true;
1080 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551081 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]c4365fa42013-05-14 01:08:241082 if (new_extension &&
1083 new_extension->is_hosted_app() &&
1084 new_extension->id() == extension_misc::kWebStoreAppId &&
1085 !service->process_map()->Contains(new_extension->id(),
1086 process_host->GetID())) {
1087 return false;
1088 }
1089
1090 return true;
1091}
1092
[email protected]9a60d1602013-09-11 04:09:121093bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1094 content::SiteInstance* site_instance, const GURL& url) {
1095 GURL from_url = site_instance->GetSiteURL();
1096 // Do not allow pages from the web or other extensions navigate to
1097 // non-web-accessible extension resources.
1098 if (url.SchemeIs(extensions::kExtensionScheme) &&
1099 (from_url.SchemeIsHTTPOrHTTPS() ||
1100 from_url.SchemeIs(extensions::kExtensionScheme))) {
1101 Profile* profile = Profile::FromBrowserContext(
1102 site_instance->GetProcess()->GetBrowserContext());
1103 ExtensionService* service =
1104 extensions::ExtensionSystem::Get(profile)->extension_service();
1105 if (!service)
1106 return true;
1107 const Extension* extension =
1108 service->extensions()->GetExtensionOrAppByURL(url);
1109 if (!extension)
1110 return true;
1111 const Extension* from_extension =
1112 service->extensions()->GetExtensionOrAppByURL(
1113 site_instance->GetSiteURL());
1114 if (from_extension && from_extension->id() == extension->id())
1115 return true;
1116
1117 if (!extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
1118 extension, url.path()))
1119 return false;
1120 }
1121 return true;
1122}
1123
[email protected]2a5221b2011-09-27 23:07:311124bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301125 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311126 const GURL& site_url) {
1127 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301128 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521129 // This may be NULL during tests. In that case, just assume any site can
1130 // share any host.
1131 if (!profile)
1132 return true;
1133
[email protected]d43f99fe2013-04-03 00:20:141134 // Instant URLs should only be in the instant process and instant process
1135 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521136 InstantService* instant_service =
1137 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141138 if (instant_service) {
1139 bool is_instant_process = instant_service->IsInstantProcess(
1140 process_host->GetID());
1141 bool should_be_in_instant_process =
1142 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1143 if (is_instant_process || should_be_in_instant_process)
1144 return is_instant_process && should_be_in_instant_process;
1145 }
[email protected]c5dec6292013-01-25 04:54:521146
[email protected]d5bcd06f2013-04-21 08:07:241147#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301148 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1149 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1150 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241151#endif
[email protected]970c63e2013-03-07 00:25:301152
[email protected]06bdd2b2012-11-30 18:47:131153 ExtensionService* service =
1154 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461155 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:311156
[email protected]ffa97602011-11-17 17:55:521157 // Don't allow the Task Manager to share a process with anything else.
1158 // Otherwise it can affect the renderers it is observing.
1159 // Note: we could create another RenderProcessHostPrivilege bucket for
1160 // this to allow multiple chrome://tasks instances to share, but that's
1161 // a very unlikely case without serious consequences.
1162 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1163 return false;
1164
[email protected]8d3132f62011-10-12 07:13:421165 // These may be NULL during tests. In that case, just assume any site can
1166 // share any host.
[email protected]6f371442011-11-09 06:45:461167 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311168 return true;
1169
[email protected]eec0b33c2011-12-05 22:09:451170 // Otherwise, just make sure the process privilege matches the privilege
1171 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571172 RenderProcessHostPrivilege privilege_required =
1173 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451174 return GetProcessPrivilege(process_host, process_map, service) ==
1175 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311176}
1177
[email protected]76411f412012-02-22 18:56:061178// This function is trying to limit the amount of processes used by extensions
1179// with background pages. It uses a globally set percentage of processes to
1180// run such extensions and if the limit is exceeded, it returns true, to
1181// indicate to the content module to group extensions together.
1182bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1183 content::BrowserContext* browser_context, const GURL& url) {
1184 // It has to be a valid URL for us to check for an extension.
1185 if (!url.is_valid())
1186 return false;
1187
1188 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191189 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131190 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061191 if (!service)
1192 return false;
1193
1194 // We have to have a valid extension with background page to proceed.
1195 const Extension* extension =
[email protected]be9915fb2013-07-18 09:28:551196 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]76411f412012-02-22 18:56:061197 if (!extension)
1198 return false;
[email protected]9367eabc2013-03-01 01:29:291199 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061200 return false;
1201
1202 std::set<int> process_ids;
1203 size_t max_process_count =
1204 content::RenderProcessHost::GetMaxRendererProcessCount();
1205
1206 // Go through all profiles to ensure we have total count of extension
1207 // processes containing background pages, otherwise one profile can
1208 // starve the other.
1209 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1210 GetLoadedProfiles();
1211 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]98b6d942013-11-10 00:34:071212 extensions::ProcessManager* epm =
[email protected]be93bba02012-10-24 16:44:031213 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]98b6d942013-11-10 00:34:071214 for (extensions::ProcessManager::const_iterator iter =
[email protected]d1fe1352012-04-26 00:47:321215 epm->background_hosts().begin();
1216 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131217 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321218 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061219 }
1220 }
1221
1222 if (process_ids.size() >
1223 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1224 return true;
1225 }
1226
1227 return false;
1228}
1229
[email protected]6f371442011-11-09 06:45:461230void ChromeContentBrowserClient::SiteInstanceGotProcess(
1231 SiteInstance* site_instance) {
1232 CHECK(site_instance->HasProcess());
1233
1234 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021235 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521236 if (!profile)
1237 return;
1238
1239 // Remember the ID of the Instant process to signal the renderer process
1240 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031241 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321242 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521243 InstantService* instant_service =
1244 InstantServiceFactory::GetForProfile(profile);
1245 if (instant_service)
1246 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1247 }
1248
[email protected]d5bcd06f2013-04-21 08:07:241249#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301250 // We only expect there to be one signin process as we use process-per-site
1251 // for signin URLs. The signin process will be cleared from SigninManager
1252 // when the renderer is destroyed.
1253 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1254 SigninManager* signin_manager =
1255 SigninManagerFactory::GetForProfile(profile);
1256 if (signin_manager)
1257 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461258 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:201259 BrowserThread::IO,
1260 FROM_HERE,
1261 base::Bind(&InfoMap::SetSigninProcess,
[email protected]1deace22013-05-22 06:14:461262 extensions::ExtensionSystem::Get(profile)->info_map(),
1263 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301264 }
[email protected]d5bcd06f2013-04-21 08:07:241265#endif
[email protected]970c63e2013-03-07 00:25:301266
[email protected]06bdd2b2012-11-30 18:47:131267 ExtensionService* service =
1268 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461269 if (!service)
1270 return;
1271
[email protected]be9915fb2013-07-18 09:28:551272 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1273 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461274 if (!extension)
1275 return;
1276
[email protected]6bc04fd82011-12-04 02:29:351277 service->process_map()->Insert(extension->id(),
1278 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331279 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461280 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:201281 BrowserThread::IO,
1282 FROM_HERE,
1283 base::Bind(&InfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591284 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461285 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351286 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331287 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461288}
1289
1290void ChromeContentBrowserClient::SiteInstanceDeleting(
1291 SiteInstance* site_instance) {
1292 if (!site_instance->HasProcess())
1293 return;
1294
1295 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021296 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131297 ExtensionService* service =
1298 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461299 if (!service)
1300 return;
1301
[email protected]be9915fb2013-07-18 09:28:551302 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1303 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461304 if (!extension)
1305 return;
1306
[email protected]6bc04fd82011-12-04 02:29:351307 service->process_map()->Remove(extension->id(),
1308 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331309 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461310 BrowserThread::PostTask(
[email protected]38427a12013-11-09 17:34:201311 BrowserThread::IO,
1312 FROM_HERE,
1313 base::Bind(&InfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591314 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461315 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351316 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331317 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461318}
1319
[email protected]453f5432013-11-26 19:43:001320bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141321 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081322 const GURL& current_url,
1323 const GURL& new_url) {
[email protected]2aca9a92013-12-03 05:16:071324 // If we don't have an ExtensionService, then rely on the SiteInstance logic
[email protected]a5a59482013-12-03 22:52:061325 // in RenderFrameHostManager to decide when to swap.
[email protected]e9841fbd2013-02-22 23:12:141326 Profile* profile =
1327 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1328 ExtensionService* service =
1329 extensions::ExtensionSystem::Get(profile)->extension_service();
1330 if (!service)
1331 return false;
1332
[email protected]2aca9a92013-12-03 05:16:071333 // We must use a new BrowsingInstance (forcing a process swap and disabling
1334 // scripting by existing tabs) if one of the URLs is an extension and the
1335 // other is not the exact same extension.
1336 //
1337 // We ignore hosted apps here so that other tabs in their BrowsingInstance can
1338 // use postMessage with them. (The exception is the Chrome Web Store, which
1339 // is a hosted app that requires its own BrowsingInstance.) Navigations
1340 // to/from a hosted app will still trigger a SiteInstance swap in
[email protected]a5a59482013-12-03 22:52:061341 // RenderFrameHostManager.
[email protected]2aca9a92013-12-03 05:16:071342 const Extension* current_extension =
1343 service->extensions()->GetExtensionOrAppByURL(current_url);
1344 if (current_extension &&
1345 current_extension->is_hosted_app() &&
1346 current_extension->id() != extension_misc::kWebStoreAppId)
1347 current_extension = NULL;
1348
[email protected]e9841fbd2013-02-22 23:12:141349 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551350 service->extensions()->GetExtensionOrAppByURL(new_url);
[email protected]e9841fbd2013-02-22 23:12:141351 if (new_extension &&
1352 new_extension->is_hosted_app() &&
1353 new_extension->id() != extension_misc::kWebStoreAppId)
1354 new_extension = NULL;
[email protected]2aca9a92013-12-03 05:16:071355
1356 // First do a process check. We should force a BrowsingInstance swap if the
1357 // current process doesn't know about new_extension, even if current_extension
1358 // is somehow the same as new_extension.
[email protected]e9841fbd2013-02-22 23:12:141359 if (new_extension &&
1360 site_instance->HasProcess() &&
1361 !service->process_map()->Contains(new_extension->id(),
1362 site_instance->GetProcess()->GetID()))
1363 return true;
1364
[email protected]2aca9a92013-12-03 05:16:071365 // Otherwise, swap BrowsingInstances if current_extension and new_extension
1366 // differ.
1367 return current_extension != new_extension;
[email protected]e3daf3c2011-10-05 21:17:081368}
1369
[email protected]395045c2012-05-22 15:04:381370bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1371 content::ResourceContext* resource_context, const GURL& current_url,
1372 const GURL& new_url) {
1373 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1374 return extensions::CrossesExtensionProcessBoundary(
1375 io_data->GetExtensionInfoMap()->extensions(),
[email protected]be9915fb2013-07-18 09:28:551376 current_url, new_url, false);
[email protected]395045c2012-05-22 15:04:381377}
1378
[email protected]3d831992013-07-04 01:13:291379bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1380 return !url.SchemeIs(chrome::kChromeNativeScheme);
1381}
1382
[email protected]763ec4ca2011-04-29 15:48:121383std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1384 const std::string& alias_name) {
1385 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1386}
1387
[email protected]b80f68432011-05-02 17:22:301388void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1389 CommandLine* command_line, int child_process_id) {
[email protected]264c0acac2013-10-01 13:33:301390#if defined(OS_POSIX)
[email protected]0b818f72013-10-22 00:11:031391 if (breakpad::IsCrashReporterEnabled()) {
[email protected]264c0acac2013-10-01 13:33:301392 std::string enable_crash_reporter;
1393 GoogleUpdateSettings::GetMetricsId(&enable_crash_reporter);
1394#if !defined(OS_MACOSX)
1395 enable_crash_reporter += "," + base::GetLinuxDistro();
1396#endif
[email protected]b80f68432011-05-02 17:22:301397 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
[email protected]264c0acac2013-10-01 13:33:301398 enable_crash_reporter);
[email protected]b80f68432011-05-02 17:22:301399 }
[email protected]264c0acac2013-10-01 13:33:301400#endif // OS_POSIX
[email protected]b80f68432011-05-02 17:22:301401
[email protected]f1933792011-06-14 00:49:341402 if (logging::DialogsAreSuppressed())
1403 command_line->AppendSwitch(switches::kNoErrorDialogs);
1404
[email protected]b80f68432011-05-02 17:22:301405 std::string process_type =
1406 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171407 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321408
[email protected]7c9b6f92013-09-10 18:11:351409 static const char* const kCommonSwitchNames[] = {
1410 switches::kChromeFrame,
1411 switches::kUserDataDir, // Make logs go to the right file.
1412 };
1413 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
1414 arraysize(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:321415
[email protected]8c64e282013-11-28 16:05:141416#if defined(ENABLE_IPC_FUZZER)
1417 static const char* const kIpcFuzzerSwitches[] = {
1418 switches::kIpcFuzzerTestcase,
1419 };
1420 command_line->CopySwitchesFrom(browser_command_line, kIpcFuzzerSwitches,
1421 arraysize(kIpcFuzzerSwitches));
1422#endif
1423
[email protected]718eab62011-10-05 21:16:521424 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:301425#if defined(OS_CHROMEOS)
1426 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441427 browser_command_line.GetSwitchValueASCII(
1428 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301429 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441430 command_line->AppendSwitchASCII(
1431 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301432#endif
1433
[email protected]50fa4d5f2013-11-05 00:53:231434#if defined(ENABLE_WEBRTC)
1435 if (VersionInfo::GetChannel() <= VersionInfo::CHANNEL_DEV) {
1436 static const char* const kWebRtcDevSwitchNames[] = {
1437 switches::kDisableWebRtcEncryption,
1438 };
1439 command_line->CopySwitchesFrom(browser_command_line,
1440 kWebRtcDevSwitchNames,
1441 arraysize(kWebRtcDevSwitchNames));
1442 }
1443#endif
1444
[email protected]f3b1a082011-11-18 00:34:301445 content::RenderProcessHost* process =
1446 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371447 if (process) {
1448 Profile* profile = Profile::FromBrowserContext(
1449 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131450 ExtensionService* extension_service =
1451 extensions::ExtensionSystem::Get(profile)->extension_service();
1452 if (extension_service) {
1453 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]433669fd2013-10-31 22:07:101454 if (process_map && process_map->Contains(process->GetID()))
[email protected]c8598d42012-09-25 21:17:001455 command_line->AppendSwitch(switches::kExtensionProcess);
1456 }
[email protected]b80f68432011-05-02 17:22:301457
[email protected]a8d851f82011-12-21 00:32:371458 PrefService* prefs = profile->GetPrefs();
1459 // Currently this pref is only registered if applied via a policy.
1460 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1461 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1462 // Turn this policy into a command line switch.
1463 command_line->AppendSwitch(switches::kDisable3DAPIs);
1464 }
[email protected]718eab62011-10-05 21:16:521465
[email protected]a8d851f82011-12-21 00:32:371466 // Disable client-side phishing detection in the renderer if it is
1467 // disabled in the Profile preferences or the browser process.
1468 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1469 !g_browser_process->safe_browsing_detection_service()) {
1470 command_line->AppendSwitch(
1471 switches::kDisableClientSidePhishingDetection);
1472 }
[email protected]0045b0f42012-07-26 11:52:081473
1474 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211475 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521476
1477 InstantService* instant_service =
1478 InstantServiceFactory::GetForProfile(profile);
1479 if (instant_service &&
1480 instant_service->IsInstantProcess(process->GetID()))
1481 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301482
[email protected]d5bcd06f2013-04-21 08:07:241483#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301484 SigninManager* signin_manager =
1485 SigninManagerFactory::GetForProfile(profile);
1486 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1487 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241488#endif
[email protected]47c7ec82012-01-18 03:29:211489 }
[email protected]4287a3d2011-06-13 23:56:511490
[email protected]47c7ec82012-01-18 03:29:211491 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511492 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171493 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]c3cc0632013-10-03 21:54:431494 autofill::switches::kDisablePasswordGeneration,
[email protected]58bc1c32013-12-16 22:52:071495 autofill::switches::kEnableIgnoreAutocompleteOff,
[email protected]000f3ad2013-05-16 02:19:171496 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]c3cc0632013-10-03 21:54:431497 autofill::switches::kEnablePasswordGeneration,
[email protected]5c42c372013-10-17 15:06:101498 autofill::switches::kNoAutofillNecessaryForPasswordGeneration,
[email protected]558878cc82013-11-09 01:25:511499 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]49d9b142013-07-19 08:50:271500 extensions::switches::kAllowLegacyExtensionManifests,
1501 extensions::switches::kAllowScriptingGallery,
[email protected]c8d02992013-07-31 22:16:511502 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271503 extensions::switches::kExtensionsOnChromeURLs,
[email protected]9d450492013-06-13 23:08:371504 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1505 // to browser.
1506 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511507 switches::kAppsCheckoutURL,
1508 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311509 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511510 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501511 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531512 switches::kDisableExtensionsResourceWhitelist,
[email protected]83c85262013-08-22 21:13:461513 switches::kDisablePnacl,
[email protected]b0553c7e2012-09-19 21:36:111514 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531515 switches::kEnableAdview,
1516 switches::kEnableAdviewSrcAttribute,
[email protected]1f4da9e2013-06-27 05:23:441517 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211518 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511519 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451520 switches::kEnableNetBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511521 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511522 switches::kMemoryProfiling,
1523 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371524 switches::kNoJsRandomness,
[email protected]8f06e4d2013-11-25 23:20:181525 switches::kOutOfProcessPdf,
[email protected]f45c5f32012-04-18 19:26:371526 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511527 switches::kPpapiFlashArgs,
1528 switches::kPpapiFlashInProcess,
1529 switches::kPpapiFlashPath,
1530 switches::kPpapiFlashVersion,
1531 switches::kProfilingAtStart,
1532 switches::kProfilingFile,
1533 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371534 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511535 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:381536 switches::kWhitelistedExtensionID,
[email protected]499e7c52013-10-04 16:03:091537 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:511538 };
1539
1540 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1541 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171542 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381543 static const char* const kSwitchNames[] = {
[email protected]558878cc82013-11-09 01:25:511544 extensions::switches::kAllowHTTPBackgroundPage,
[email protected]c8d02992013-07-31 22:16:511545 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271546 extensions::switches::kExtensionsOnChromeURLs,
[email protected]a446534d2012-02-09 00:07:381547 switches::kWhitelistedExtensionID,
1548 };
1549
1550 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1551 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511552 } else if (process_type == switches::kPluginProcess) {
1553 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441554#if defined(OS_CHROMEOS)
1555 chromeos::switches::kLoginProfile,
1556#endif
[email protected]4287a3d2011-06-13 23:56:511557 switches::kMemoryProfiling,
1558 switches::kSilentDumpOnDCHECK,
[email protected]4287a3d2011-06-13 23:56:511559 };
1560
1561 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1562 arraysize(kSwitchNames));
1563 } else if (process_type == switches::kZygoteProcess) {
1564 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511565 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501566 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511567 switches::kPpapiFlashInProcess,
1568 switches::kPpapiFlashPath,
1569 switches::kPpapiFlashVersion,
1570 };
1571
1572 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1573 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111574 } else if (process_type == switches::kGpuProcess) {
1575 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1576 // because GPU is expected to be unreliable.
1577 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1578 !command_line->HasSwitch(switches::kDisableBreakpad))
1579 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301580 }
[email protected]6f08af82011-09-15 01:19:031581
1582 // The command line switch kEnableBenchmarking needs to be specified along
1583 // with the kEnableStatsTable switch to ensure that the stats table global
1584 // is initialized correctly.
1585 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1586 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301587}
1588
1589std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431590 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351591 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301592 return g_browser_process->GetApplicationLocale();
1593}
1594
[email protected]597a867b2011-11-18 18:31:201595std::string ChromeContentBrowserClient::GetAcceptLangs(
1596 content::BrowserContext* context) {
1597 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371598 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081599}
1600
[email protected]9ec0f452012-05-31 15:58:531601gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221602 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531603 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081604}
1605
[email protected]a2176792011-05-08 19:30:491606bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091607 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191608 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201609 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201611 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051612 return io_data->GetCookieSettings()->
1613 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491614}
1615
[email protected]ed24fad2011-05-10 22:44:011616bool ChromeContentBrowserClient::AllowGetCookie(
1617 const GURL& url,
1618 const GURL& first_party,
1619 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201620 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011621 int render_process_id,
1622 int render_view_id) {
1623 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201624 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051625 bool allow = io_data->GetCookieSettings()->
1626 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011627
[email protected]8093a542011-05-13 07:29:321628 BrowserThread::PostTask(
1629 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031630 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431631 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011632 return allow;
1633}
1634
1635bool ChromeContentBrowserClient::AllowSetCookie(
1636 const GURL& url,
1637 const GURL& first_party,
1638 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201639 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011640 int render_process_id,
1641 int render_view_id,
1642 net::CookieOptions* options) {
1643 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201644 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051645 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1646 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1647
[email protected]8093a542011-05-13 07:29:321648 BrowserThread::PostTask(
1649 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031650 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431651 render_view_id, url, first_party, cookie_line, *options,
1652 !allow));
[email protected]ed24fad2011-05-10 22:44:011653 return allow;
1654}
1655
[email protected]d5a19162011-06-30 18:51:541656bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201657 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541658 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201659 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431660 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1661 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261662
[email protected]bf510ed2012-06-05 08:31:431663 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1664 // Could we even support per-origin settings?
1665 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541666}
1667
[email protected]5c5a88e2011-11-12 00:45:351668bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351669 const GURL& url,
[email protected]96920152013-12-04 21:00:161670 const base::string16& name,
1671 const base::string16& display_name,
[email protected]5c5a88e2011-11-12 00:45:351672 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201673 content::ResourceContext* context,
[email protected]b765deb2013-12-18 06:43:301674 const std::vector<std::pair<int, int> >& render_frames) {
[email protected]5c5a88e2011-11-12 00:45:351675 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201676 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351677 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1678 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1679
[email protected]62151052012-02-01 18:40:481680 // Record access to database for potential display in UI.
1681 std::vector<std::pair<int, int> >::const_iterator i;
[email protected]b765deb2013-12-18 06:43:301682 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
[email protected]62151052012-02-01 18:40:481683 BrowserThread::PostTask(
1684 BrowserThread::UI, FROM_HERE,
1685 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1686 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351687 }
1688
1689 return allow;
1690}
1691
1692bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351693 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201694 content::ResourceContext* context,
[email protected]b765deb2013-12-18 06:43:301695 const std::vector<std::pair<int, int> >& render_frames) {
[email protected]5c5a88e2011-11-12 00:45:351696 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201697 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351698 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1699 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1700
[email protected]62151052012-02-01 18:40:481701 // Record access to file system for potential display in UI.
1702 std::vector<std::pair<int, int> >::const_iterator i;
[email protected]b765deb2013-12-18 06:43:301703 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
[email protected]62151052012-02-01 18:40:481704 BrowserThread::PostTask(
1705 BrowserThread::UI, FROM_HERE,
1706 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1707 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351708 }
1709
1710 return allow;
1711}
1712
[email protected]7c5ff9a2012-03-02 07:42:491713bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1714 const GURL& url,
[email protected]96920152013-12-04 21:00:161715 const base::string16& name,
[email protected]7c5ff9a2012-03-02 07:42:491716 content::ResourceContext* context,
[email protected]b765deb2013-12-18 06:43:301717 const std::vector<std::pair<int, int> >& render_frames) {
[email protected]7c5ff9a2012-03-02 07:42:491718 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1719 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1720 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1721 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1722
1723 // Record access to IndexedDB for potential display in UI.
1724 std::vector<std::pair<int, int> >::const_iterator i;
[email protected]b765deb2013-12-18 06:43:301725 for (i = render_frames.begin(); i != render_frames.end(); ++i) {
[email protected]7c5ff9a2012-03-02 07:42:491726 BrowserThread::PostTask(
1727 BrowserThread::UI, FROM_HERE,
1728 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1729 i->first, i->second, url, name, !allow));
1730 }
1731
1732 return allow;
1733}
1734
[email protected]33ad6ce92013-08-27 14:39:081735net::URLRequestContext*
1736ChromeContentBrowserClient::OverrideRequestContextForURL(
1737 const GURL& url, content::ResourceContext* context) {
1738 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1739 if (url.SchemeIs(extensions::kExtensionScheme)) {
1740 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1741 return io_data->extensions_request_context();
1742 }
1743
1744 return NULL;
1745}
1746
[email protected]317f96c92011-05-31 06:53:411747QuotaPermissionContext*
1748ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1749 return new ChromeQuotaPermissionContext();
1750}
1751
[email protected]848dd042011-06-04 18:24:031752void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171753 int render_process_id,
1754 int render_view_id,
1755 int cert_error,
1756 const net::SSLInfo& ssl_info,
1757 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021758 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031759 bool overridable,
[email protected]d9be47702012-05-16 03:41:221760 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171761 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001762 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021763 if (resource_type != ResourceType::MAIN_FRAME) {
1764 // A sub-resource has a certificate error. The user doesn't really
1765 // have a context for making the right decision, so block the
1766 // request hard, without an info bar to allow showing the insecure
1767 // content.
[email protected]8c965c22013-05-23 19:28:001768 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021769 return;
1770 }
1771
[email protected]f9034cf2011-07-21 12:43:411772 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131773 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171774 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411775 if (!tab) {
1776 NOTREACHED();
1777 return;
1778 }
1779 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501780 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301781 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011782 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1783 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411784 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171785 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411786 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001787 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411788 return;
1789 }
1790 }
1791
[email protected]1e87df32012-09-12 04:53:191792#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231793 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1794 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1795 if (captive_portal_tab_helper)
1796 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191797#endif
1798
[email protected]f9034cf2011-07-21 12:43:411799 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221800 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1801 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031802}
1803
[email protected]c99c442e2011-08-24 11:37:301804void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451805 int render_process_id,
1806 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401807 const net::HttpNetworkSession* network_session,
1808 net::SSLCertRequestInfo* cert_request_info,
1809 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131810 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451811 render_process_id, render_view_id);
1812 if (!tab) {
1813 NOTREACHED();
1814 return;
1815 }
1816
[email protected]791879c2013-12-17 07:22:411817 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
1818 DCHECK(requesting_url.is_valid())
1819 << "Invalid URL string: https://"
1820 << cert_request_info->host_and_port.ToString();
[email protected]6786bf402011-12-03 15:19:451821
[email protected]627e0512011-12-21 22:55:301822 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451823 scoped_ptr<Value> filter(
1824 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1825 requesting_url,
1826 requesting_url,
1827 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1828 std::string(), NULL));
1829
1830 if (filter.get()) {
1831 // Try to automatically select a client certificate.
1832 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1833 DictionaryValue* filter_dict =
1834 static_cast<DictionaryValue*>(filter.get());
1835
1836 const std::vector<scoped_refptr<net::X509Certificate> >&
1837 all_client_certs = cert_request_info->client_certs;
1838 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091839 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451840 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091841 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451842 return;
1843 }
1844 }
1845 } else {
1846 NOTREACHED();
1847 }
1848 }
1849
[email protected]11feec322012-09-18 03:58:521850 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1851 if (!ssl_tab_helper) {
1852 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451853 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141854 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401855 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451856 return;
1857 }
[email protected]11feec322012-09-18 03:58:521858 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401859 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451860}
1861
[email protected]3b455502012-12-11 18:22:581862void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451863 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581864 net::CertificateMimeType cert_type,
1865 const void* cert_data,
1866 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451867 int render_process_id,
1868 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581869 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1870 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451871}
1872
[email protected]dc73a7b2012-03-25 15:27:181873content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561874 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181875}
1876
[email protected]941623e2011-06-07 23:06:041877void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1878 const GURL& source_origin,
1879 int callback_context,
1880 int render_process_id,
1881 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111882#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021883 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1884 WebContents* contents =
1885 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1886 if (!contents) {
[email protected]941623e2011-06-07 23:06:041887 NOTREACHED();
1888 return;
1889 }
1890
[email protected]d0d9c3ee2012-06-19 03:07:021891 // Skip showing the infobar if the request comes from an extension, and that
1892 // extension has the 'notify' permission. (If the extension does not have the
1893 // permission, the user will still be prompted.)
1894 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]38427a12013-11-09 17:34:201895 InfoMap* extension_info_map =
[email protected]c7cd5942013-04-30 03:31:011896 extensions::ExtensionSystem::Get(profile)->info_map();
1897 DesktopNotificationService* notification_service =
1898 DesktopNotificationServiceFactory::GetForProfile(profile);
1899 const Extension* extension = NULL;
1900 if (extension_info_map) {
[email protected]289c44b2013-12-17 03:26:571901 extensions::ExtensionSet extensions;
[email protected]c7cd5942013-04-30 03:31:011902 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1903 source_origin, render_process_id,
1904 extensions::APIPermission::kNotification, &extensions);
[email protected]289c44b2013-12-17 03:26:571905 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
[email protected]c7cd5942013-04-30 03:31:011906 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381907 if (notification_service->IsNotifierEnabled(NotifierId(
1908 NotifierId::APPLICATION, (*iter)->id()))) {
[email protected]cadac622013-06-11 16:46:361909 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011910 break;
1911 }
1912 }
1913 }
[email protected]eb4832a2012-12-08 01:57:521914 RenderViewHost* rvh =
1915 RenderViewHost::FromID(render_process_id, render_view_id);
1916 if (IsExtensionWithPermissionOrSuggestInConsole(
1917 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021918 if (rvh)
1919 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1920 return;
1921 }
1922
[email protected]c7cd5942013-04-30 03:31:011923 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021924 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111925#else
1926 NOTIMPLEMENTED();
1927#endif
[email protected]941623e2011-06-07 23:06:041928}
1929
[email protected]a1221aea2013-11-07 01:31:301930blink::WebNotificationPresenter::Permission
[email protected]941623e2011-06-07 23:06:041931 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021932 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201933 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021934 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111935#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041936 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]5c129792013-07-10 02:08:481937
[email protected]df02aca2012-02-09 21:03:201938 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9afacd22013-11-13 20:23:311939 InfoMap* extension_info_map = io_data->GetExtensionInfoMap();
[email protected]941623e2011-06-07 23:06:041940
[email protected]9afacd22013-11-13 20:23:311941 // We want to see if there is an extension that hasn't been manually disabled
1942 // that has the notifications permission and applies to this security origin.
1943 // First, get the list of extensions with permission for the origin.
[email protected]289c44b2013-12-17 03:26:571944 extensions::ExtensionSet extensions;
[email protected]9afacd22013-11-13 20:23:311945 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1946 source_origin, render_process_id,
1947 extensions::APIPermission::kNotification, &extensions);
[email protected]289c44b2013-12-17 03:26:571948 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
[email protected]9afacd22013-11-13 20:23:311949 iter != extensions.end(); ++iter) {
1950 // Then, check to see if it's been disabled by the user.
1951 if (!extension_info_map->AreNotificationsDisabled((*iter)->id()))
1952 return blink::WebNotificationPresenter::PermissionAllowed;
[email protected]c7cd5942013-04-30 03:31:011953 }
1954
[email protected]9afacd22013-11-13 20:23:311955 // No enabled extensions exist, so check the normal host content settings.
1956 HostContentSettingsMap* host_content_settings_map =
1957 io_data->GetHostContentSettingsMap();
1958 ContentSetting setting = host_content_settings_map->GetContentSetting(
1959 source_origin,
1960 source_origin,
1961 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
1962 NO_RESOURCE_IDENTIFIER);
1963
1964 if (setting == CONTENT_SETTING_ALLOW)
1965 return blink::WebNotificationPresenter::PermissionAllowed;
1966 if (setting == CONTENT_SETTING_BLOCK)
1967 return blink::WebNotificationPresenter::PermissionDenied;
[email protected]a1221aea2013-11-07 01:31:301968 return blink::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111969#else
[email protected]a1221aea2013-11-07 01:31:301970 return blink::WebNotificationPresenter::PermissionAllowed;
[email protected]5fd2e842012-03-01 00:29:111971#endif
[email protected]941623e2011-06-07 23:06:041972}
1973
1974void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171975 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041976 int render_process_id,
1977 int render_view_id,
1978 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111979#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041980 RenderViewHost* rvh = RenderViewHost::FromID(
1981 render_process_id, render_view_id);
1982 if (!rvh) {
1983 NOTREACHED();
1984 return;
1985 }
1986
[email protected]9f76c1e2012-03-05 15:15:581987 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301988 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041989 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371990 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041991 service->ShowDesktopNotification(
1992 params, render_process_id, render_view_id,
1993 worker ? DesktopNotificationService::WorkerNotification :
1994 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111995#else
1996 NOTIMPLEMENTED();
1997#endif
[email protected]941623e2011-06-07 23:06:041998}
1999
2000void ChromeContentBrowserClient::CancelDesktopNotification(
2001 int render_process_id,
2002 int render_view_id,
2003 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:112004#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:042005 RenderViewHost* rvh = RenderViewHost::FromID(
2006 render_process_id, render_view_id);
2007 if (!rvh) {
2008 NOTREACHED();
2009 return;
2010 }
2011
[email protected]9f76c1e2012-03-05 15:15:582012 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:302013 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:042014 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:372015 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:042016 service->CancelDesktopNotification(
2017 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:112018#else
2019 NOTIMPLEMENTED();
2020#endif
[email protected]941623e2011-06-07 23:06:042021}
2022
[email protected]9f3fba52011-06-08 20:37:192023bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:352024 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:572025 const GURL& opener_top_level_frame_url,
[email protected]34eec7ffe32011-11-02 23:49:022026 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:192027 WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:232028 const GURL& target_url,
2029 const content::Referrer& referrer,
2030 WindowOpenDisposition disposition,
2031 const WebWindowFeatures& features,
2032 bool user_gesture,
2033 bool opener_suppressed,
[email protected]df02aca2012-02-09 21:03:202034 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:012035 int render_process_id,
[email protected]190e5e22013-07-27 05:59:232036 bool is_guest,
2037 int opener_id,
[email protected]03b6d552012-03-29 04:03:012038 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:192039 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:012040
2041 *no_javascript_access = false;
2042
[email protected]5e5f55e262c52013-09-12 00:27:192043 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]38427a12013-11-09 17:34:202044 InfoMap* map = io_data->GetExtensionInfoMap();
[email protected]5e5f55e262c52013-09-12 00:27:192045
[email protected]9f3fba52011-06-08 20:37:192046 // If the opener is trying to create a background window but doesn't have
2047 // the appropriate permission, fail the attempt.
[email protected]6940eef82013-09-11 11:58:412048 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]03b6d552012-03-29 04:03:012049 if (!map->SecurityOriginHasAPIPermission(
2050 source_origin,
2051 render_process_id,
[email protected]c2e66e12012-06-27 06:27:062052 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:012053 return false;
2054 }
2055
[email protected]7b54ca02012-03-02 18:06:532056 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2057 // return a recently installed Extension even if this CanCreateWindow call
2058 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:012059 // because the permission check above would have caused an early return
2060 // already. We must use the full URL to find hosted apps, though, and not
2061 // just the origin.
[email protected]be9915fb2013-07-18 09:28:552062 const Extension* extension =
2063 map->extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:292064 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:012065 *no_javascript_access = true;
[email protected]190e5e22013-07-27 05:59:232066
2067 return true;
[email protected]9f3fba52011-06-08 20:37:192068 }
[email protected]056efdc2013-04-06 00:14:532069
2070 // No new browser window (popup or tab) in app mode.
2071 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
2072 chrome::IsRunningInForcedAppMode()) {
2073 return false;
2074 }
2075
[email protected]d2bac6b2013-08-13 03:42:362076 if (g_browser_process->prerender_tracker() &&
2077 g_browser_process->prerender_tracker()->TryCancelOnIOThread(
2078 render_process_id,
2079 opener_id,
2080 prerender::FINAL_STATUS_CREATE_NEW_WINDOW)) {
2081 return false;
2082 }
2083
[email protected]190e5e22013-07-27 05:59:232084 if (is_guest)
2085 return true;
2086
[email protected]190e5e22013-07-27 05:59:232087 HostContentSettingsMap* content_settings =
2088 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap();
[email protected]916615b2013-09-11 18:19:442089 BlockedWindowParams blocked_params(target_url,
2090 referrer,
2091 disposition,
2092 features,
2093 user_gesture,
2094 opener_suppressed,
2095 render_process_id,
2096 opener_id);
[email protected]190e5e22013-07-27 05:59:232097
[email protected]7f53dff2013-08-05 10:45:502098 if (!user_gesture && !CommandLine::ForCurrentProcess()->HasSwitch(
2099 switches::kDisablePopupBlocking)) {
[email protected]931bc922013-09-11 21:42:572100 if (content_settings->GetContentSetting(opener_top_level_frame_url,
2101 opener_top_level_frame_url,
[email protected]190e5e22013-07-27 05:59:232102 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]916615b2013-09-11 18:19:442103 std::string()) !=
[email protected]190e5e22013-07-27 05:59:232104 CONTENT_SETTING_ALLOW) {
[email protected]916615b2013-09-11 18:19:442105 BrowserThread::PostTask(BrowserThread::UI,
2106 FROM_HERE,
2107 base::Bind(&HandleBlockedPopupOnUIThread,
2108 blocked_params));
2109 return false;
[email protected]190e5e22013-07-27 05:59:232110 }
[email protected]916615b2013-09-11 18:19:442111 }
[email protected]190e5e22013-07-27 05:59:232112
[email protected]916615b2013-09-11 18:19:442113#if defined(OS_ANDROID)
2114 if (SingleTabModeTabHelper::IsRegistered(render_process_id, opener_id)) {
[email protected]190e5e22013-07-27 05:59:232115 BrowserThread::PostTask(BrowserThread::UI,
2116 FROM_HERE,
[email protected]916615b2013-09-11 18:19:442117 base::Bind(&HandleSingleTabModeBlockOnUIThread,
2118 blocked_params));
[email protected]190e5e22013-07-27 05:59:232119 return false;
2120 }
[email protected]916615b2013-09-11 18:19:442121#endif
[email protected]190e5e22013-07-27 05:59:232122
[email protected]9f3fba52011-06-08 20:37:192123 return true;
2124}
2125
2126std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:202127 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:192128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2129 // Check if it's an extension-created worker, in which case we want to use
2130 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:202131 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:192132 const Extension* extension =
2133 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
2134 return extension ? extension->name() : std::string();
2135}
2136
[email protected]99907362012-01-11 05:41:402137void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2138 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:172139}
2140
[email protected]7a06d282013-05-03 04:39:332141// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:022142content::SpeechRecognitionManagerDelegate*
2143 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002144#if defined(ENABLE_INPUT_SPEECH)
2145 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
[email protected]a03f2d32012-03-14 00:26:322146#else
[email protected]855e18b2013-07-08 21:02:002147 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
2148 // need the base delegate without the bubble UI.
2149 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:322150#endif
[email protected]66cfec62012-02-24 17:57:512151}
2152
[email protected]ae6e9912011-07-27 01:18:282153net::NetLog* ChromeContentBrowserClient::GetNetLog() {
2154 return g_browser_process->net_log();
2155}
2156
[email protected]32538d92011-08-25 00:09:232157AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
2158 return new ChromeAccessTokenStore();
2159}
2160
[email protected]dbae6b02011-06-29 23:51:412161bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:012162 return true;
[email protected]dbae6b02011-06-29 23:51:412163}
2164
[email protected]64d69de42012-02-06 00:19:542165void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:322166 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:062167 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582168 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:062169 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062170
[email protected]33b79542013-10-18 11:18:452171 // Fill per-script font preferences. These are not registered on Android
2172 // - http://crbug.com/308033.
2173#if !defined(OS_ANDROID)
[email protected]f3986f82012-01-03 20:00:062174 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542175 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:062176 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542177 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:062178 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542179 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062180 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542181 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062182 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542183 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:062184 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542185 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:032186 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
2187 &web_prefs->pictograph_font_family_map);
[email protected]33b79542013-10-18 11:18:452188#endif
[email protected]f3986f82012-01-03 20:00:062189
[email protected]64d69de42012-02-06 00:19:542190 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:402191 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:542192 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:402193 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:542194 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:402195 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:542196 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:402197 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:062198
[email protected]ddf72142012-05-22 04:52:402199 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062200
[email protected]64d69de42012-02-06 00:19:542201 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:402202 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:542203 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:062204 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:542205 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:062206 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
2207 const DictionaryValue* inspector_settings =
2208 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2209 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:182210 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
2211 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062212 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182213 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542214 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182215 std::make_pair(iter.key(), value));
2216 }
[email protected]f3986f82012-01-03 20:00:062217 }
2218 }
[email protected]64d69de42012-02-06 00:19:542219 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062220
[email protected]ddf72142012-05-22 04:52:402221 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542222 web_prefs->javascript_enabled = false;
2223 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2224 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402225 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542226 web_prefs->plugins_enabled = false;
2227 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2228 web_prefs->java_enabled = false;
2229 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402230 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062231
[email protected]64d69de42012-02-06 00:19:542232 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2233 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062234
[email protected]64d69de42012-02-06 00:19:542235 web_prefs->memory_info_enabled =
2236 prefs->GetBoolean(prefs::kEnableMemoryInfo);
2237 web_prefs->allow_displaying_insecure_content =
2238 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2239 web_prefs->allow_running_insecure_content =
2240 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322241#if defined(OS_ANDROID)
[email protected]ded00dc2013-11-01 00:37:052242 web_prefs->font_scale_factor =
2243 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2244 web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment();
[email protected]d3b935f2012-10-19 23:14:322245 web_prefs->force_enable_zoom =
2246 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
2247#endif
[email protected]5c915252013-05-07 13:15:392248
[email protected]af4256d52013-06-04 20:39:072249#if defined(OS_ANDROID)
2250 web_prefs->password_echo_enabled =
2251 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2252#else
[email protected]9d06d88d2012-02-23 22:37:082253 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072254#endif
2255
[email protected]cfadadd2013-04-03 04:43:022256 web_prefs->asynchronous_spell_checking_enabled = true;
2257 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572258
[email protected]64d69de42012-02-06 00:19:542259 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062260 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542261 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062262 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542263 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062264 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2265
2266 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542267 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062268 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542269 web_prefs->default_encoding);
2270 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402271 prefs->ClearPref(prefs::kDefaultCharset);
2272 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062273 }
[email protected]64d69de42012-02-06 00:19:542274 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062275
[email protected]299d7f12012-05-23 05:31:152276 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232277 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132278 ExtensionService* service =
2279 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062280 if (service) {
[email protected]1bc28312012-11-08 08:31:532281 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2282 const Extension* extension = service->extensions()->GetByID(url.host());
2283 // Ensure that we are only granting extension preferences to URLs with
2284 // the correct scheme. Without this check, chrome-guest:// schemes used by
2285 // webview tags as well as hosts that happen to match the id of an
2286 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422287 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532288 extension_webkit_preferences::SetPreferences(
2289 extension, view_type, web_prefs);
2290 }
[email protected]f3986f82012-01-03 20:00:062291 }
2292
[email protected]cb2edf22013-04-01 20:25:232293 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542294 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232295 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062296 // Disable all kinds of acceleration for background pages.
2297 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542298 web_prefs->force_compositing_mode = false;
2299 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062300 }
[email protected]2e21fe292012-03-02 22:52:322301
2302#if defined(FILE_MANAGER_EXTENSION)
2303 // Override the default of suppressing HW compositing for WebUI pages for the
2304 // file manager, which is implemented using WebUI but wants HW acceleration
2305 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532306 if (url.SchemeIs(extensions::kExtensionScheme) &&
[email protected]2de96a52013-08-14 01:18:092307 url.host() == file_manager::kFileManagerAppId) {
[email protected]2e21fe292012-03-02 22:52:322308 web_prefs->accelerated_compositing_enabled = true;
2309 web_prefs->accelerated_2d_canvas_enabled = true;
2310 }
2311#endif
[email protected]181a95ee2011-07-12 19:26:362312}
2313
2314void ChromeContentBrowserClient::UpdateInspectorSetting(
2315 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062316 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582317 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062318 DictionaryPrefUpdate update(
2319 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2320 prefs::kWebKitInspectorSettings);
2321 DictionaryValue* inspector_settings = update.Get();
2322 inspector_settings->SetWithoutPathExpansion(key,
2323 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362324}
2325
[email protected]b8148ac2011-07-13 22:03:252326void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2327 BrowserURLHandler* handler) {
2328 // Add the default URL handlers.
2329 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2330 BrowserURLHandler::null_handler());
2331 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2332 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2333
[email protected]b3adbd02011-11-30 22:23:272334 // about: handler. Must come before chrome: handler, since it will
2335 // rewrite about: urls to chrome: URLs and then expect chrome: to
2336 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252337 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2338 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:032339
2340 // Handler to rewrite chrome://newtab for InstantExtended.
2341 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2342 &chrome::HandleNewTabURLReverseRewrite);
2343
[email protected]b8148ac2011-07-13 22:03:252344 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242345 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252346}
2347
2348void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372349 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582350 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472351 BrowsingDataRemover* remover =
2352 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552353 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2354 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252355 // BrowsingDataRemover takes care of deleting itself when done.
2356}
2357
2358void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372359 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582360 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472361 BrowsingDataRemover* remover =
2362 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232363 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552364 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252365 // BrowsingDataRemover takes care of deleting itself when done.
2366}
2367
[email protected]650b2d52013-02-10 03:41:452368base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:492369 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:322370}
2371
[email protected]c9b6eb62011-10-18 20:49:392372std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2373 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2374}
2375
[email protected]b7631cc2012-09-15 05:08:382376void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2377 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542378#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382379 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2380 scoped_ptr<ppapi::host::HostFactory>(
2381 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542382#endif
[email protected]b7631cc2012-09-15 05:08:382383}
2384
[email protected]0c7193742012-11-07 19:05:032385content::BrowserPpapiHost*
2386 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2387 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132388 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032389 while (!iter.Done()) {
[email protected]7c766e92013-11-22 20:44:022390 nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>(
2391 iter.GetDelegate());
[email protected]0c7193742012-11-07 19:05:032392 if (host->process() &&
2393 host->process()->GetData().id == plugin_process_id) {
2394 // Found the plugin.
2395 return host->browser_ppapi_host();
2396 }
2397 ++iter;
2398 }
2399 return NULL;
2400}
2401
[email protected]7b38b192013-03-23 18:39:312402bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2403 content::BrowserContext* browser_context, const GURL& site_url) {
2404 if (CommandLine::ForCurrentProcess()->HasSwitch(
2405 switches::kEnableBrowserPluginForAllViewTypes))
2406 return true;
2407
[email protected]22aa4f82013-09-24 17:01:442408 if (content::HasWebUIScheme(site_url))
2409 return true;
2410
[email protected]7b38b192013-03-23 18:39:312411 Profile* profile = Profile::FromBrowserContext(browser_context);
2412 ExtensionService* service =
2413 extensions::ExtensionSystem::Get(profile)->extension_service();
2414 if (!service)
2415 return false;
2416
[email protected]be9915fb2013-07-18 09:28:552417 const Extension* extension =
2418 service->extensions()->GetExtensionOrAppByURL(site_url);
[email protected]7b38b192013-03-23 18:39:312419 if (!extension)
2420 return false;
2421
[email protected]c2d2f102013-04-29 16:42:582422 return extension->HasAPIPermission(APIPermission::kWebView) ||
2423 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312424}
2425
[email protected]38cd8f7f2012-06-15 22:06:072426bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582427 content::BrowserContext* browser_context,
2428 const GURL& url,
[email protected]dda54822013-06-15 01:26:392429 bool private_api,
[email protected]8b92ed182013-09-21 04:47:122430 const content::SocketPermissionRequest* params) {
[email protected]93f72062013-05-29 20:29:402431#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372432 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]289c44b2013-12-17 03:26:572433 const extensions::ExtensionSet* extension_set = NULL;
[email protected]9d450492013-06-13 23:08:372434 if (profile) {
2435 extension_set = extensions::ExtensionSystem::Get(profile)->
2436 extension_service()->extensions();
2437 }
[email protected]dda54822013-06-15 01:26:392438
2439 if (private_api) {
2440 // Access to private socket APIs is controlled by the whitelist.
2441 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2442 allowed_socket_origins_)) {
2443 return true;
2444 }
2445 } else {
2446 // Access to public socket APIs is controlled by extension permissions.
2447 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2448 extension_set) {
2449 const Extension* extension = extension_set->GetByID(url.host());
2450 if (extension) {
[email protected]8b92ed182013-09-21 04:47:122451 if (params) {
2452 extensions::SocketPermission::CheckParam check_params(
2453 params->type, params->host, params->port);
2454 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2455 extension, extensions::APIPermission::kSocket,
2456 &check_params)) {
2457 return true;
2458 }
2459 } else {
2460 if (extensions::PermissionsData::HasAPIPermission(
2461 extension, extensions::APIPermission::kSocket)) {
2462 return true;
2463 }
[email protected]dda54822013-06-15 01:26:392464 }
2465 }
2466 }
2467 }
2468
2469 // Allow both public and private APIs if the command line says so.
2470 return IsHostAllowedByCommandLine(url, extension_set,
2471 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402472#else
[email protected]a658d452012-03-02 12:45:292473 return false;
[email protected]93f72062013-05-29 20:29:402474#endif
[email protected]e461da2f2012-02-16 19:06:402475}
2476
[email protected]a28e3302013-02-03 03:50:432477ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2478 WebContents* web_contents) {
2479 return new ChromeSelectFilePolicy(web_contents);
2480}
2481
[email protected]7d9424702013-04-14 13:14:162482void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2483 std::vector<std::string>* additional_allowed_schemes) {
2484 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2485 additional_allowed_schemes);
[email protected]98fa9dc2013-12-09 16:31:412486 additional_allowed_schemes->push_back(kChromeDevToolsScheme);
[email protected]7d9424702013-04-14 13:14:162487 additional_allowed_schemes->push_back(kChromeUIScheme);
2488 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2489}
2490
[email protected]f19bbf62013-07-09 01:22:322491void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:312492 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:532493 const base::FilePath& storage_partition_path,
[email protected]f19bbf62013-07-09 01:22:322494 ScopedVector<fileapi::FileSystemBackend>* additional_backends) {
[email protected]02250952013-04-24 23:52:532495#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032496 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]f19bbf62013-07-09 01:22:322497 additional_backends->push_back(new MediaFileSystemBackend(
[email protected]30a306f42013-06-10 03:09:032498 storage_partition_path,
2499 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]f19bbf62013-07-09 01:22:322500 MediaFileSystemBackend::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532501#endif
[email protected]b40015c2013-06-26 08:13:312502#if defined(OS_CHROMEOS)
[email protected]0ff5eb52013-07-10 20:35:312503 fileapi::ExternalMountPoints* external_mount_points =
2504 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:312505 DCHECK(external_mount_points);
[email protected]f19bbf62013-07-09 01:22:322506 chromeos::FileSystemBackend* backend =
2507 new chromeos::FileSystemBackend(
[email protected]0ff5eb52013-07-10 20:35:312508 new drive::FileSystemBackendDelegate(browser_context),
2509 browser_context->GetSpecialStoragePolicy(),
[email protected]b40015c2013-06-26 08:13:312510 external_mount_points,
2511 fileapi::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:322512 backend->AddSystemMountPoints();
2513 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal));
2514 additional_backends->push_back(backend);
[email protected]b40015c2013-06-26 08:13:312515#endif
[email protected]445b7db2013-08-02 04:58:272516
[email protected]e86e2be2013-08-30 11:20:392517 additional_backends->push_back(
2518 new sync_file_system::SyncFileSystemBackend(
2519 Profile::FromBrowserContext(browser_context)));
[email protected]02250952013-04-24 23:52:532520}
2521
[email protected]e60c0232011-11-11 19:56:352522#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182523void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2524 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382525 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082526 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392527#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452528 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392529 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2530 DCHECK(!data_path.empty());
2531
2532 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452533 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392534 data_path.AppendASCII("chrome_100_percent.pak");
[email protected]5db2b7492013-08-23 05:33:092535 base::PlatformFile f =
2536 base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
[email protected]29699c22012-10-03 23:57:392537 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372538 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392539 FileDescriptor(f, true)));
2540
2541 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452542 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392543 GetLocaleFilePath(locale, false);
2544 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2545 DCHECK(f != base::kInvalidPlatformFileValue);
2546 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2547 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382548
[email protected]650b2d52013-02-10 03:41:452549 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372550 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2551 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2552 DCHECK(f != base::kInvalidPlatformFileValue);
2553 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2554 FileDescriptor(f, true)));
2555
[email protected]0b818f72013-10-22 00:11:032556 if (breakpad::IsCrashReporterEnabled()) {
2557 f = breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile(
2558 child_process_id);
[email protected]82174aa2013-01-22 21:53:432559 if (f == base::kInvalidPlatformFileValue) {
2560 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2561 "be disabled for this process.";
2562 } else {
2563 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2564 FileDescriptor(f, true)));
2565 }
[email protected]40da3e0c2012-10-24 22:03:382566 }
[email protected]40da3e0c2012-10-24 22:03:382567
2568#else
2569 int crash_signal_fd = GetCrashSignalFD(command_line);
2570 if (crash_signal_fd >= 0) {
2571 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2572 FileDescriptor(crash_signal_fd,
2573 false)));
2574 }
[email protected]29699c22012-10-03 23:57:392575#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302576}
[email protected]e60c0232011-11-11 19:56:352577#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302578
[email protected]4a65826d2011-08-25 16:04:012579#if defined(OS_WIN)
2580const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2581 return chrome::kBrowserResourcesDll;
2582}
[email protected]34f48682013-03-20 00:30:182583
2584void ChromeContentBrowserClient::PreSpawnRenderer(
2585 sandbox::TargetPolicy* policy,
2586 bool* success) {
2587 // This code is duplicated in nacl_exe_win_64.cc.
2588 // Allow the server side of a pipe restricted to the "chrome.nacl."
2589 // namespace so that it cannot impersonate other system or other chrome
2590 // service pipes.
2591 sandbox::ResultCode result = policy->AddRule(
2592 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2593 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2594 L"\\\\.\\pipe\\chrome.nacl.*");
2595 if (result != sandbox::SBOX_ALL_OK) {
2596 *success = false;
2597 return;
2598 }
2599
2600 // Renderers need to send named pipe handles and shared memory
2601 // segment handles to NaCl loader processes.
2602 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2603 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2604 L"File");
2605 if (result != sandbox::SBOX_ALL_OK) {
2606 *success = false;
2607 return;
2608 }
2609}
[email protected]4a65826d2011-08-25 16:04:012610#endif
2611
[email protected]a6868c22013-10-09 02:50:292612bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2613 content::BrowserContext* browser_context,
2614 const GURL& url) {
2615#if defined(ENABLE_PLUGINS)
2616 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]289c44b2013-12-17 03:26:572617 const extensions::ExtensionSet* extension_set = NULL;
[email protected]a6868c22013-10-09 02:50:292618 if (profile) {
2619 extension_set = extensions::ExtensionSystem::Get(profile)->
2620 extension_service()->extensions();
2621 }
2622 // TODO(teravest): Populate allowed_file_handle_origins_ when FileIO is moved
2623 // from the renderer to the browser.
2624 return IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2625 allowed_file_handle_origins_) ||
2626 IsHostAllowedByCommandLine(url, extension_set,
2627 switches::kAllowNaClFileHandleAPI);
2628#else
2629 return false;
2630#endif
2631}
2632
[email protected]8ddc6b7c2013-12-12 20:42:062633bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs() {
2634#if defined(ENABLE_PLUGINS)
2635 // Allow access for tests.
2636 if (CommandLine::ForCurrentProcess()->HasSwitch(
2637 switches::kEnablePepperTesting)) {
2638 return true;
2639 }
2640
2641 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
2642 return channel <= chrome::VersionInfo::CHANNEL_DEV;
2643#else
2644 return false;
2645#endif
2646}
2647
2648
[email protected]d977f9c2011-03-14 16:10:262649} // namespace chrome