[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 2 | // 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] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 7 | #include <set> |
[email protected] | 1033acd | 2012-02-08 08:46:27 | [diff] [blame] | 8 | #include <utility> |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
[email protected] | 317c58f0 | 2011-11-09 02:15:03 | [diff] [blame] | 11 | #include "base/bind.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 13 | #include "base/lazy_instance.h" |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 14 | #include "base/path_service.h" |
[email protected] | 3853a4c | 2013-02-11 17:15:57 | [diff] [blame] | 15 | #include "base/prefs/pref_service.h" |
[email protected] | 9eec53fe | 2013-10-30 20:21:17 | [diff] [blame] | 16 | #include "base/prefs/scoped_user_pref_update.h" |
[email protected] | e746341 | 2013-06-10 22:53:46 | [diff] [blame] | 17 | #include "base/strings/string_number_conversions.h" |
[email protected] | 135cb80 | 2013-06-09 16:44:20 | [diff] [blame] | 18 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 30a306f4 | 2013-06-10 03:09:03 | [diff] [blame] | 19 | #include "base/threading/sequenced_worker_pool.h" |
[email protected] | 056efdc | 2013-04-06 00:14:53 | [diff] [blame] | 20 | #include "chrome/browser/app_mode/app_mode_utils.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 21 | #include "chrome/browser/browser_about_handler.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 22 | #include "chrome/browser/browser_process.h" |
[email protected] | 5c12979 | 2013-07-10 02:08:48 | [diff] [blame] | 23 | #include "chrome/browser/browser_shutdown.h" |
[email protected] | b0cb5e8 | 2012-07-19 19:22:47 | [diff] [blame] | 24 | #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 25 | #include "chrome/browser/browsing_data/browsing_data_remover.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 26 | #include "chrome/browser/character_encoding.h" |
[email protected] | 4353551 | 2013-02-20 20:41:41 | [diff] [blame] | 27 | #include "chrome/browser/chrome_net_benchmarking_message_filter.h" |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 28 | #include "chrome/browser/chrome_quota_permission_context.h" |
[email protected] | edece21 | 2011-11-16 11:56:56 | [diff] [blame] | 29 | #include "chrome/browser/content_settings/content_settings_utils.h" |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 30 | #include "chrome/browser/content_settings/cookie_settings.h" |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 31 | #include "chrome/browser/content_settings/host_content_settings_map.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 32 | #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
[email protected] | 9d06d88d | 2012-02-23 22:37:08 | [diff] [blame] | 33 | #include "chrome/browser/defaults.h" |
[email protected] | b1d9727 | 2013-08-17 13:38:49 | [diff] [blame] | 34 | #include "chrome/browser/download/download_prefs.h" |
[email protected] | 2b33dcd0 | 2012-03-18 01:34:16 | [diff] [blame] | 35 | #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
[email protected] | 1deace2 | 2013-05-22 06:14:46 | [diff] [blame] | 36 | #include "chrome/browser/extensions/browser_permissions_policy_delegate.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 37 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | ca033634 | 2014-03-21 12:58:34 | [diff] [blame] | 38 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 39 | #include "chrome/browser/extensions/extension_web_ui.h" |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 40 | #include "chrome/browser/extensions/extension_webkit_preferences.h" |
[email protected] | eb4832a | 2012-12-08 01:57:52 | [diff] [blame] | 41 | #include "chrome/browser/extensions/suggest_permission_util.h" |
[email protected] | 32538d9 | 2011-08-25 00:09:23 | [diff] [blame] | 42 | #include "chrome/browser/geolocation/chrome_access_token_store.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 43 | #include "chrome/browser/google/google_util.h" |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 44 | #include "chrome/browser/guestview/adview/adview_guest.h" |
[email protected] | 3f24f97c | 2013-11-17 21:53:33 | [diff] [blame] | 45 | #include "chrome/browser/guestview/guestview.h" |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 46 | #include "chrome/browser/guestview/guestview_constants.h" |
| 47 | #include "chrome/browser/guestview/webview/webview_guest.h" |
[email protected] | eab6105d | 2014-01-17 20:55:10 | [diff] [blame] | 48 | #include "chrome/browser/local_discovery/storage/privet_filesystem_backend.h" |
[email protected] | 1ea4c49 | 2014-02-15 19:45:17 | [diff] [blame] | 49 | #include "chrome/browser/media/cast_transport_host_filter.h" |
[email protected] | 11158e2d | 2013-02-01 02:31:56 | [diff] [blame] | 50 | #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
[email protected] | 95132f5 | 2013-04-12 02:19:04 | [diff] [blame] | 51 | #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h" |
[email protected] | a2b4c5c | 2013-10-18 02:06:07 | [diff] [blame] | 52 | #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h" |
[email protected] | ae6e991 | 2011-07-27 01:18:28 | [diff] [blame] | 53 | #include "chrome/browser/net/chrome_net_log.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 54 | #include "chrome/browser/notifications/desktop_notification_service.h" |
| 55 | #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 56 | #include "chrome/browser/platform_util.h" |
[email protected] | c2295f7 | 2013-01-03 22:18:56 | [diff] [blame] | 57 | #include "chrome/browser/plugins/plugin_info_message_filter.h" |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 58 | #include "chrome/browser/prerender/prerender_final_status.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 59 | #include "chrome/browser/prerender/prerender_manager.h" |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 60 | #include "chrome/browser/prerender/prerender_manager_factory.h" |
[email protected] | 2736c03 | 2012-05-11 18:06:07 | [diff] [blame] | 61 | #include "chrome/browser/prerender/prerender_message_filter.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 62 | #include "chrome/browser/prerender/prerender_tracker.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 63 | #include "chrome/browser/printing/printing_message_filter.h" |
[email protected] | 7e75e4a | 2013-05-17 17:20:03 | [diff] [blame] | 64 | #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 65 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 66 | #include "chrome/browser/profiles/profile_io_data.h" |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 67 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 68 | #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 69 | #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h" |
[email protected] | a7b8e43d | 2013-03-18 18:52:43 | [diff] [blame] | 70 | #include "chrome/browser/search/instant_service.h" |
| 71 | #include "chrome/browser/search/instant_service_factory.h" |
| 72 | #include "chrome/browser/search/search.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 73 | #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h" |
[email protected] | 914cf671 | 2013-12-05 01:14:06 | [diff] [blame] | 74 | #include "chrome/browser/signin/principals_message_filter.h" |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 75 | #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h" |
[email protected] | 7a06d28 | 2013-05-03 04:39:33 | [diff] [blame] | 76 | #include "chrome/browser/speech/tts_message_filter.h" |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 77 | #include "chrome/browser/ssl/ssl_add_certificate.h" |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 78 | #include "chrome/browser/ssl/ssl_blocking_page.h" |
[email protected] | 11feec32 | 2012-09-18 03:58:52 | [diff] [blame] | 79 | #include "chrome/browser/ssl/ssl_tab_helper.h" |
[email protected] | 180c66a6 | 2013-08-05 12:01:36 | [diff] [blame] | 80 | #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 81 | #include "chrome/browser/tab_contents/tab_util.h" |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 82 | #include "chrome/browser/ui/blocked_content/blocked_window_params.h" |
[email protected] | 40aa8bb | 2013-08-23 20:28:23 | [diff] [blame] | 83 | #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" |
[email protected] | a28e330 | 2013-02-03 03:50:43 | [diff] [blame] | 84 | #include "chrome/browser/ui/chrome_select_file_policy.h" |
[email protected] | 329ac97 | 2013-06-21 15:24:25 | [diff] [blame] | 85 | #include "chrome/browser/ui/sync/sync_promo_ui.h" |
[email protected] | b5d7342 | 2012-06-02 23:46:44 | [diff] [blame] | 86 | #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h" |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 87 | #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 88 | #include "chrome/common/chrome_constants.h" |
[email protected] | a7944aa | 2012-10-15 10:12:14 | [diff] [blame] | 89 | #include "chrome/common/chrome_paths.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 90 | #include "chrome/common/chrome_switches.h" |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 91 | #include "chrome/common/env_vars.h" |
[email protected] | 395045c | 2012-05-22 15:04:38 | [diff] [blame] | 92 | #include "chrome/common/extensions/extension_process_policy.h" |
[email protected] | 561e33d5 | 2013-04-03 06:58:43 | [diff] [blame] | 93 | #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 94 | #include "chrome/common/logging_chrome.h" |
[email protected] | 9d45049 | 2013-06-13 23:08:37 | [diff] [blame] | 95 | #include "chrome/common/pepper_permission_util.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 96 | #include "chrome/common/pref_names.h" |
[email protected] | 4de7526 | 2013-12-18 23:16:12 | [diff] [blame] | 97 | #include "chrome/common/profile_management_switches.h" |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 98 | #include "chrome/common/render_messages.h" |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 99 | #include "chrome/common/url_constants.h" |
[email protected] | 264c0acac | 2013-10-01 13:33:30 | [diff] [blame] | 100 | #include "chrome/installer/util/google_update_settings.h" |
[email protected] | e8f3f998 | 2013-05-10 20:59:53 | [diff] [blame] | 101 | #include "chromeos/chromeos_constants.h" |
[email protected] | ef42ee8 | 2013-11-01 05:26:13 | [diff] [blame] | 102 | #include "components/nacl/browser/nacl_browser.h" |
[email protected] | 7c766e9 | 2013-11-22 20:44:02 | [diff] [blame] | 103 | #include "components/nacl/browser/nacl_host_message_filter.h" |
| 104 | #include "components/nacl/browser/nacl_process_host.h" |
[email protected] | d5d38325 | 2013-07-04 14:44:32 | [diff] [blame] | 105 | #include "components/nacl/common/nacl_process_type.h" |
[email protected] | 1b4ec38 | 2014-03-07 02:32:24 | [diff] [blame] | 106 | #include "components/nacl/common/nacl_switches.h" |
[email protected] | eba93c9 | 2014-01-07 17:34:17 | [diff] [blame] | 107 | #include "components/translate/core/common/translate_switches.h" |
[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 108 | #include "components/user_prefs/pref_registry_syncable.h" |
[email protected] | e0ada9c | 2012-03-20 03:54:43 | [diff] [blame] | 109 | #include "content/public/browser/browser_child_process_host.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 110 | #include "content/public/browser/browser_main_parts.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 111 | #include "content/public/browser/browser_ppapi_host.h" |
[email protected] | 30a306f4 | 2013-06-10 03:09:03 | [diff] [blame] | 112 | #include "content/public/browser/browser_thread.h" |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 113 | #include "content/public/browser/browser_url_handler.h" |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 114 | #include "content/public/browser/child_process_data.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 115 | #include "content/public/browser/child_process_security_policy.h" |
[email protected] | 094c877 | 2013-12-21 17:54:50 | [diff] [blame] | 116 | #include "content/public/browser/render_frame_host.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 117 | #include "content/public/browser/render_process_host.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 118 | #include "content/public/browser/render_view_host.h" |
[email protected] | ce96786 | 2012-02-09 22:47:05 | [diff] [blame] | 119 | #include "content/public/browser/resource_context.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 120 | #include "content/public/browser/site_instance.h" |
[email protected] | 91ee368 | 2012-01-19 15:02:19 | [diff] [blame] | 121 | #include "content/public/browser/web_contents.h" |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 122 | #include "content/public/browser/web_contents_view.h" |
[email protected] | e0ada9c | 2012-03-20 03:54:43 | [diff] [blame] | 123 | #include "content/public/common/child_process_host.h" |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 124 | #include "content/public/common/content_descriptors.h" |
[email protected] | 22aa4f8 | 2013-09-24 17:01:44 | [diff] [blame] | 125 | #include "content/public/common/url_utils.h" |
[email protected] | 22401dc | 2014-03-21 01:38:57 | [diff] [blame] | 126 | #include "extensions/browser/extension_host.h" |
[email protected] | afed511 | 2014-02-02 06:01:53 | [diff] [blame] | 127 | #include "extensions/browser/extension_message_filter.h" |
[email protected] | 896c6d5 | 2014-01-28 21:40:21 | [diff] [blame] | 128 | #include "extensions/browser/extension_registry.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 129 | #include "extensions/browser/extension_system.h" |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 130 | #include "extensions/browser/info_map.h" |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 131 | #include "extensions/browser/process_manager.h" |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 132 | #include "extensions/browser/process_map.h" |
[email protected] | cb2edf2 | 2013-04-01 20:25:23 | [diff] [blame] | 133 | #include "extensions/browser/view_type_utils.h" |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 134 | #include "extensions/common/constants.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 135 | #include "extensions/common/extension.h" |
[email protected] | 289c44b | 2013-12-17 03:26:57 | [diff] [blame] | 136 | #include "extensions/common/extension_set.h" |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 137 | #include "extensions/common/manifest_handlers/background_info.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 138 | #include "extensions/common/manifest_handlers/shared_module_info.h" |
[email protected] | 474b1f7 | 2014-01-16 02:38:07 | [diff] [blame] | 139 | #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 140 | #include "extensions/common/permissions/permissions_data.h" |
[email protected] | 91add6a | 2014-03-21 11:48:22 | [diff] [blame] | 141 | #include "extensions/common/permissions/socket_permission.h" |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 142 | #include "extensions/common/switches.h" |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 143 | #include "grit/generated_resources.h" |
[email protected] | 2a28133 | 2012-07-11 22:20:23 | [diff] [blame] | 144 | #include "grit/ui_resources.h" |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 145 | #include "net/base/mime_util.h" |
[email protected] | 5b9bc35 | 2012-07-18 13:13:34 | [diff] [blame] | 146 | #include "net/cookies/canonical_cookie.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 147 | #include "net/cookies/cookie_options.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 148 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 149 | #include "ppapi/host/ppapi_host.h" |
[email protected] | 8ddc6b7c | 2013-12-12 20:42:06 | [diff] [blame] | 150 | #include "ppapi/shared_impl/ppapi_switches.h" |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 151 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 152 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | fb1aac1 | 2013-05-14 05:30:24 | [diff] [blame] | 153 | #include "ui/message_center/message_center_util.h" |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 154 | #include "webkit/browser/fileapi/external_mount_points.h" |
[email protected] | fab55e7 | 2013-05-31 07:06:18 | [diff] [blame] | 155 | #include "webkit/common/webpreferences.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 156 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 157 | #if defined(OS_WIN) |
[email protected] | 7fe75ce | 2014-01-28 02:12:24 | [diff] [blame] | 158 | #include "base/win/windows_version.h" |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 159 | #include "chrome/browser/chrome_browser_main_win.h" |
[email protected] | 34f4868 | 2013-03-20 00:30:18 | [diff] [blame] | 160 | #include "sandbox/win/src/sandbox_policy.h" |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 161 | #elif defined(OS_MACOSX) |
| 162 | #include "chrome/browser/chrome_browser_main_mac.h" |
[email protected] | 7ceb9901 | 2011-12-21 08:05:56 | [diff] [blame] | 163 | #include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h" |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 164 | #include "components/breakpad/app/breakpad_mac.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 165 | #elif defined(OS_CHROMEOS) |
| 166 | #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h" |
[email protected] | 07fe275 | 2014-01-29 11:21:55 | [diff] [blame] | 167 | #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h" |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 168 | #include "chrome/browser/chromeos/fileapi/file_system_backend.h" |
[email protected] | 5c91525 | 2013-05-07 13:15:39 | [diff] [blame] | 169 | #include "chrome/browser/chromeos/login/startup_utils.h" |
[email protected] | fe69558d | 2012-03-12 11:34:49 | [diff] [blame] | 170 | #include "chrome/browser/chromeos/login/user_manager.h" |
[email protected] | c94ac69 | 2013-07-27 00:50:10 | [diff] [blame] | 171 | #include "chrome/browser/chromeos/system/input_device_settings.h" |
[email protected] | 931d104 | 2013-04-05 17:50:44 | [diff] [blame] | 172 | #include "chromeos/chromeos_switches.h" |
[email protected] | 81ce2c4 | 2012-03-24 01:43:26 | [diff] [blame] | 173 | #elif defined(OS_LINUX) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 174 | #include "chrome/browser/chrome_browser_main_linux.h" |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 175 | #elif defined(OS_ANDROID) |
[email protected] | 4bd78e9 | 2014-03-28 18:54:03 | [diff] [blame] | 176 | #include "chrome/browser/android/new_tab_page_url_handler.h" |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 177 | #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h" |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 178 | #include "chrome/browser/chrome_browser_main_android.h" |
[email protected] | 2b12c32 | 2013-09-19 06:53:56 | [diff] [blame] | 179 | #include "chrome/browser/media/encrypted_media_message_filter_android.h" |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 180 | #include "chrome/common/descriptors_android.h" |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 181 | #include "components/breakpad/browser/crash_dump_manager_android.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 182 | #elif defined(OS_POSIX) |
| 183 | #include "chrome/browser/chrome_browser_main_posix.h" |
| 184 | #endif |
| 185 | |
[email protected] | a220b593 | 2013-09-21 03:47:44 | [diff] [blame] | 186 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 187 | #include "base/debug/leak_annotations.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 188 | #include "base/linux_util.h" |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 189 | #include "components/breakpad/app/breakpad_linux.h" |
| 190 | #include "components/breakpad/browser/crash_handler_host_linux.h" |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 191 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 192 | |
[email protected] | 1e87df3 | 2012-09-12 04:53:19 | [diff] [blame] | 193 | #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 194 | #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
| 195 | #endif |
| 196 | |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 197 | #if defined(OS_ANDROID) |
| 198 | #include "ui/base/ui_base_paths.h" |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 199 | #include "ui/gfx/android/device_display_info.h" |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 200 | #endif |
| 201 | |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 202 | #if !defined(OS_CHROMEOS) |
[email protected] | 5ac245e | 2014-03-28 16:44:56 | [diff] [blame] | 203 | #include "chrome/browser/signin/chrome_signin_client.h" |
| 204 | #include "chrome/browser/signin/chrome_signin_client_factory.h" |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 205 | #include "chrome/browser/signin/signin_manager_factory.h" |
[email protected] | 7fbd3b1 | 2014-04-01 11:19:16 | [diff] [blame] | 206 | #include "components/signin/core/browser/signin_manager.h" |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 207 | #endif |
| 208 | |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 209 | #if !defined(OS_ANDROID) |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 210 | #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 211 | #endif |
| 212 | |
[email protected] | 6ef98b5a | 2013-05-31 23:58:31 | [diff] [blame] | 213 | #if defined(ENABLE_WEBRTC) |
| 214 | #include "chrome/browser/media/webrtc_logging_handler_host.h" |
| 215 | #endif |
| 216 | |
[email protected] | 855e18b | 2013-07-08 21:02:00 | [diff] [blame] | 217 | #if defined(ENABLE_INPUT_SPEECH) |
| 218 | #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h" |
| 219 | #endif |
| 220 | |
[email protected] | ff930087 | 2014-01-22 11:09:32 | [diff] [blame] | 221 | #if defined(OS_CHROMEOS) |
[email protected] | 473c9a4f | 2013-09-05 03:09:46 | [diff] [blame] | 222 | #include "chrome/browser/chromeos/file_manager/app_id.h" |
[email protected] | 02a3dc12 | 2013-06-13 15:07:53 | [diff] [blame] | 223 | #endif |
| 224 | |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 225 | #if defined(TOOLKIT_GTK) |
| 226 | #include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h" |
| 227 | #endif |
| 228 | |
| 229 | #if defined(TOOLKIT_VIEWS) |
| 230 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h" |
| 231 | #endif |
| 232 | |
| 233 | #if defined(USE_ASH) |
| 234 | #include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h" |
| 235 | #endif |
| 236 | |
| 237 | #if defined(USE_AURA) |
| 238 | #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h" |
| 239 | #endif |
| 240 | |
| 241 | #if defined(USE_X11) |
| 242 | #include "chrome/browser/chrome_browser_main_extra_parts_x11.h" |
| 243 | #endif |
| 244 | |
[email protected] | c6ce0807 | 2013-07-31 07:48:53 | [diff] [blame] | 245 | #if defined(ENABLE_SPELLCHECK) |
| 246 | #include "chrome/browser/spellchecker/spellcheck_message_filter.h" |
| 247 | #endif |
| 248 | |
[email protected] | 2188c8d | 2014-03-21 00:58:56 | [diff] [blame] | 249 | #if defined(ENABLE_SERVICE_DISCOVERY) |
[email protected] | 7e503f9 | 2014-02-19 02:35:51 | [diff] [blame] | 250 | #include "chrome/browser/local_discovery/storage/privet_filesystem_backend.h" |
| 251 | #endif |
| 252 | |
[email protected] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 253 | using blink::WebWindowFeatures; |
[email protected] | c7abd42 | 2012-09-25 00:20:08 | [diff] [blame] | 254 | using base::FileDescriptor; |
[email protected] | c8c7718 | 2011-12-21 15:04:47 | [diff] [blame] | 255 | using content::AccessTokenStore; |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 256 | using content::BrowserChildProcessHostIterator; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 257 | using content::BrowserThread; |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 258 | using content::BrowserURLHandler; |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 259 | using content::ChildProcessSecurityPolicy; |
[email protected] | 9f9749a | 2012-03-02 19:37:00 | [diff] [blame] | 260 | using content::QuotaPermissionContext; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 261 | using content::RenderViewHost; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 262 | using content::SiteInstance; |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 263 | using content::WebContents; |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 264 | using extensions::APIPermission; |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 265 | using extensions::Extension; |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 266 | using extensions::InfoMap; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 267 | using extensions::Manifest; |
[email protected] | 593d2a7 | 2013-07-26 08:48:38 | [diff] [blame] | 268 | using message_center::NotifierId; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 269 | |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 270 | #if defined(OS_POSIX) |
| 271 | using content::FileDescriptorInfo; |
| 272 | #endif |
| 273 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 274 | namespace { |
| 275 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 276 | // Cached version of the locale so we can return the locale on the I/O |
| 277 | // thread. |
| 278 | base::LazyInstance<std::string> g_io_thread_application_locale; |
| 279 | |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 280 | #if defined(ENABLE_PLUGINS) |
[email protected] | 10c3922 | 2013-11-13 20:09:25 | [diff] [blame] | 281 | const char* kPredefinedAllowedFileHandleOrigins[] = { |
| 282 | "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789 |
| 283 | "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789 |
| 284 | }; |
| 285 | |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 286 | const char* kPredefinedAllowedSocketOrigins[] = { |
| 287 | "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client |
[email protected] | b95bf50 | 2012-04-06 07:41:18 | [diff] [blame] | 288 | "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client) |
[email protected] | 9913268 | 2012-04-24 19:00:45 | [diff] [blame] | 289 | "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126 |
| 290 | "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop |
| 291 | "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop |
| 292 | "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop |
[email protected] | a450b6be | 2012-05-22 19:30:35 | [diff] [blame] | 293 | "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary |
[email protected] | 9040a0c2 | 2012-06-22 19:06:54 | [diff] [blame] | 294 | "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089 |
| 295 | "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099 |
| 296 | "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099 |
| 297 | "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099 |
| 298 | "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099 |
| 299 | "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099 |
[email protected] | 4dc30b8 | 2012-08-15 00:24:38 | [diff] [blame] | 300 | "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099 |
[email protected] | 45db05f | 2012-12-10 21:52:58 | [diff] [blame] | 301 | "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514 |
[email protected] | b7131323 | 2013-05-06 06:16:29 | [diff] [blame] | 302 | "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080 |
[email protected] | 3f6fca2 | 2013-08-12 23:13:42 | [diff] [blame] | 303 | "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080 |
| 304 | "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789 |
| 305 | "4EB74897CB187C7633357C2FE832E0AD6A44883A", // see crbug.com/234789 |
| 306 | "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084 |
| 307 | "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084 |
| 308 | "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084 |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 309 | }; |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 310 | #endif |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 311 | |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 312 | // Returns a copy of the given url with its host set to given host and path set |
| 313 | // to given path. Other parts of the url will be the same. |
| 314 | GURL ReplaceURLHostAndPath(const GURL& url, |
| 315 | const std::string& host, |
| 316 | const std::string& path) { |
| 317 | url_canon::Replacements<char> replacements; |
| 318 | replacements.SetHost(host.c_str(), |
| 319 | url_parse::Component(0, host.length())); |
| 320 | replacements.SetPath(path.c_str(), |
| 321 | url_parse::Component(0, path.length())); |
| 322 | return url.ReplaceComponents(replacements); |
| 323 | } |
| 324 | |
| 325 | // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/". |
| 326 | GURL AddUberHost(const GURL& url) { |
| 327 | const std::string uber_host = chrome::kChromeUIUberHost; |
| 328 | const std::string new_path = url.host() + url.path(); |
| 329 | |
| 330 | return ReplaceURLHostAndPath(url, uber_host, new_path); |
| 331 | } |
| 332 | |
[email protected] | 045bf7c | 2012-09-28 20:27:36 | [diff] [blame] | 333 | // If url->host() is "chrome" and url->path() has characters other than the |
| 334 | // first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and |
| 335 | // returns true. Otherwise returns false. |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 336 | bool RemoveUberHost(GURL* url) { |
| 337 | if (url->host() != chrome::kChromeUIUberHost) |
| 338 | return false; |
| 339 | |
[email protected] | 045bf7c | 2012-09-28 20:27:36 | [diff] [blame] | 340 | if (url->path().empty() || url->path() == "/") |
| 341 | return false; |
| 342 | |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 343 | const std::string old_path = url->path(); |
| 344 | |
| 345 | const std::string::size_type separator = old_path.find('/', 1); |
| 346 | std::string new_host; |
| 347 | std::string new_path; |
| 348 | if (separator == std::string::npos) { |
[email protected] | 045bf7c | 2012-09-28 20:27:36 | [diff] [blame] | 349 | new_host = old_path.substr(1); |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 350 | } else { |
| 351 | new_host = old_path.substr(1, separator - 1); |
| 352 | new_path = old_path.substr(separator); |
| 353 | } |
| 354 | |
[email protected] | 44e8add | 2013-06-13 17:29:15 | [diff] [blame] | 355 | // Do not allow URLs with paths empty before the first slash since we can't |
| 356 | // have an empty host. (e.g "foo://chrome//") |
| 357 | if (new_host.empty()) |
| 358 | return false; |
| 359 | |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 360 | *url = ReplaceURLHostAndPath(*url, new_host, new_path); |
| 361 | |
[email protected] | 44e8add | 2013-06-13 17:29:15 | [diff] [blame] | 362 | DCHECK(url->is_valid()); |
| 363 | |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 364 | return true; |
| 365 | } |
| 366 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 367 | // Handles rewriting Web UI URLs. |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 368 | bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 369 | // Do not handle special URLs such as "about:foo" |
| 370 | if (!url->host().empty()) { |
| 371 | const GURL chrome_url = AddUberHost(*url); |
| 372 | |
| 373 | // Handle valid "chrome://chrome/foo" URLs so the reverse handler will |
| 374 | // be called. |
| 375 | if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 376 | browser_context, chrome_url)) |
| 377 | return true; |
| 378 | } |
| 379 | |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 380 | if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 381 | browser_context, *url)) |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 382 | return false; |
| 383 | |
[email protected] | fe69558d | 2012-03-12 11:34:49 | [diff] [blame] | 384 | #if defined(OS_CHROMEOS) |
| 385 | // Special case : in ChromeOS in Guest mode bookmarks and history are |
| 386 | // disabled for security reasons. New tab page explains the reasons, so |
| 387 | // we redirect user to new tab page. |
| 388 | if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) { |
[email protected] | 2d9748b2 | 2014-02-11 00:17:29 | [diff] [blame] | 389 | if (url->SchemeIs(content::kChromeUIScheme) && |
[email protected] | fe69558d | 2012-03-12 11:34:49 | [diff] [blame] | 390 | (url->DomainIs(chrome::kChromeUIBookmarksHost) || |
| 391 | url->DomainIs(chrome::kChromeUIHistoryHost))) { |
| 392 | // Rewrite with new tab URL |
| 393 | *url = GURL(chrome::kChromeUINewTabURL); |
| 394 | } |
| 395 | } |
| 396 | #endif |
| 397 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 398 | return true; |
| 399 | } |
| 400 | |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 401 | // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to |
| 402 | // "chrome://foo/". |
| 403 | bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) { |
[email protected] | 2d9748b2 | 2014-02-11 00:17:29 | [diff] [blame] | 404 | if (!url->is_valid() || !url->SchemeIs(content::kChromeUIScheme)) |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 405 | return false; |
| 406 | |
| 407 | return RemoveUberHost(url); |
| 408 | } |
| 409 | |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 410 | // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions |
| 411 | // below. Extension, and isolated apps require different privileges to be |
| 412 | // granted to their RenderProcessHosts. This classification allows us to make |
| 413 | // sure URLs are served by hosts with the right set of privileges. |
| 414 | enum RenderProcessHostPrivilege { |
| 415 | PRIV_NORMAL, |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 416 | PRIV_HOSTED, |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 417 | PRIV_ISOLATED, |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 418 | PRIV_EXTENSION, |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 419 | }; |
| 420 | |
| 421 | RenderProcessHostPrivilege GetPrivilegeRequiredByUrl( |
| 422 | const GURL& url, |
| 423 | ExtensionService* service) { |
| 424 | // Default to a normal renderer cause it is lower privileged. This should only |
| 425 | // occur if the URL on a site instance is either malformed, or uninitialized. |
| 426 | // If it is malformed, then there is no need for better privileges anyways. |
| 427 | // If it is uninitialized, but eventually settles on being an a scheme other |
| 428 | // than normal webrenderer, the navigation logic will correct us out of band |
| 429 | // anyways. |
| 430 | if (!url.is_valid()) |
| 431 | return PRIV_NORMAL; |
| 432 | |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 433 | if (url.SchemeIs(extensions::kExtensionScheme)) { |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 434 | const Extension* extension = |
| 435 | service->extensions()->GetByID(url.host()); |
[email protected] | 561e33d5 | 2013-04-03 06:58:43 | [diff] [blame] | 436 | if (extension && |
| 437 | extensions::AppIsolationInfo::HasIsolatedStorage(extension)) |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 438 | return PRIV_ISOLATED; |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 439 | if (extension && extension->is_hosted_app()) |
| 440 | return PRIV_HOSTED; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 441 | |
| 442 | return PRIV_EXTENSION; |
| 443 | } |
| 444 | |
| 445 | return PRIV_NORMAL; |
| 446 | } |
| 447 | |
| 448 | RenderProcessHostPrivilege GetProcessPrivilege( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 449 | content::RenderProcessHost* process_host, |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 450 | extensions::ProcessMap* process_map, |
| 451 | ExtensionService* service) { |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 452 | std::set<std::string> extension_ids = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 453 | process_map->GetExtensionsInProcess(process_host->GetID()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 454 | if (extension_ids.empty()) |
[email protected] | 676f6ab | 2011-10-19 20:23:21 | [diff] [blame] | 455 | return PRIV_NORMAL; |
| 456 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 457 | for (std::set<std::string>::iterator iter = extension_ids.begin(); |
| 458 | iter != extension_ids.end(); ++iter) { |
| 459 | const Extension* extension = service->GetExtensionById(*iter, false); |
[email protected] | 561e33d5 | 2013-04-03 06:58:43 | [diff] [blame] | 460 | if (extension && |
| 461 | extensions::AppIsolationInfo::HasIsolatedStorage(extension)) |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 462 | return PRIV_ISOLATED; |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 463 | if (extension && extension->is_hosted_app()) |
| 464 | return PRIV_HOSTED; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 465 | } |
| 466 | |
[email protected] | 676f6ab | 2011-10-19 20:23:21 | [diff] [blame] | 467 | return PRIV_EXTENSION; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 468 | } |
| 469 | |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 470 | bool CertMatchesFilter(const net::X509Certificate& cert, |
| 471 | const base::DictionaryValue& filter) { |
| 472 | // TODO(markusheintz): This is the minimal required filter implementation. |
| 473 | // Implement a better matcher. |
| 474 | |
| 475 | // An empty filter matches any client certificate since no requirements are |
| 476 | // specified at all. |
| 477 | if (filter.empty()) |
| 478 | return true; |
| 479 | |
| 480 | std::string common_name; |
| 481 | if (filter.GetString("ISSUER.CN", &common_name) && |
| 482 | (cert.issuer().common_name == common_name)) { |
| 483 | return true; |
| 484 | } |
| 485 | return false; |
| 486 | } |
| 487 | |
[email protected] | 1d51882f | 2013-11-12 01:59:02 | [diff] [blame] | 488 | #if !defined(OS_ANDROID) |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 489 | // Fills |map| with the per-script font prefs under path |map_name|. |
| 490 | void FillFontFamilyMap(const PrefService* prefs, |
| 491 | const char* map_name, |
[email protected] | 3184f90b | 2013-05-01 18:17:53 | [diff] [blame] | 492 | webkit_glue::ScriptFontFamilyMap* map) { |
[email protected] | 33b7954 | 2013-10-18 11:18:45 | [diff] [blame] | 493 | // TODO: Get rid of the brute-force scan over possible (font family / script) |
| 494 | // combinations - see http://crbug.com/308095. |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 495 | for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { |
| 496 | const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; |
| 497 | std::string pref_name = base::StringPrintf("%s.%s", map_name, script); |
| 498 | std::string font_family = prefs->GetString(pref_name.c_str()); |
[email protected] | d047106 | 2012-10-26 09:00:23 | [diff] [blame] | 499 | if (!font_family.empty()) |
[email protected] | cc2a2a2 | 2013-12-24 23:12:15 | [diff] [blame] | 500 | (*map)[script] = base::UTF8ToUTF16(font_family); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 501 | } |
| 502 | } |
| 503 | |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 504 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 505 | breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost( |
| 506 | const std::string& process_type) { |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 507 | base::FilePath dumps_path; |
| 508 | PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path); |
| 509 | { |
| 510 | ANNOTATE_SCOPED_MEMORY_LEAK; |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 511 | breakpad::CrashHandlerHostLinux* crash_handler = |
| 512 | new breakpad::CrashHandlerHostLinux( |
| 513 | process_type, dumps_path, getenv(env_vars::kHeadless) == NULL); |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 514 | crash_handler->StartUploaderThread(); |
| 515 | return crash_handler; |
| 516 | } |
| 517 | } |
| 518 | |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 519 | int GetCrashSignalFD(const CommandLine& command_line) { |
[email protected] | cd0f7af | 2014-01-16 23:50:39 | [diff] [blame] | 520 | if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) { |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 521 | static breakpad::CrashHandlerHostLinux* crash_handler = NULL; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 522 | if (!crash_handler) |
| 523 | crash_handler = CreateCrashHandlerHost("extension"); |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 524 | return crash_handler->GetDeathSignalSocket(); |
| 525 | } |
| 526 | |
| 527 | std::string process_type = |
| 528 | command_line.GetSwitchValueASCII(switches::kProcessType); |
| 529 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 530 | if (process_type == switches::kRendererProcess) { |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 531 | static breakpad::CrashHandlerHostLinux* crash_handler = NULL; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 532 | if (!crash_handler) |
| 533 | crash_handler = CreateCrashHandlerHost(process_type); |
| 534 | return crash_handler->GetDeathSignalSocket(); |
| 535 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 536 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 537 | if (process_type == switches::kPluginProcess) { |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 538 | static breakpad::CrashHandlerHostLinux* crash_handler = NULL; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 539 | if (!crash_handler) |
| 540 | crash_handler = CreateCrashHandlerHost(process_type); |
| 541 | return crash_handler->GetDeathSignalSocket(); |
| 542 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 543 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 544 | if (process_type == switches::kPpapiPluginProcess) { |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 545 | static breakpad::CrashHandlerHostLinux* crash_handler = NULL; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 546 | if (!crash_handler) |
| 547 | crash_handler = CreateCrashHandlerHost(process_type); |
| 548 | return crash_handler->GetDeathSignalSocket(); |
| 549 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 550 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 551 | if (process_type == switches::kGpuProcess) { |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 552 | static breakpad::CrashHandlerHostLinux* crash_handler = NULL; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 553 | if (!crash_handler) |
| 554 | crash_handler = CreateCrashHandlerHost(process_type); |
| 555 | return crash_handler->GetDeathSignalSocket(); |
| 556 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 557 | |
| 558 | return -1; |
| 559 | } |
| 560 | #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 1d51882f | 2013-11-12 01:59:02 | [diff] [blame] | 561 | #endif // !defined(OS_ANDROID) |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 562 | |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 563 | #if !defined(OS_CHROMEOS) |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 564 | GURL GetEffectiveURLForSignin(const GURL& url) { |
| 565 | CHECK(SigninManager::IsWebBasedSigninFlowURL(url)); |
| 566 | |
| 567 | GURL effective_url(SigninManager::kChromeSigninEffectiveSite); |
[email protected] | fab8bbed4 | 2013-03-07 01:13:03 | [diff] [blame] | 568 | // Copy the path because the argument to SetPathStr must outlive |
| 569 | // the Replacements object. |
| 570 | const std::string path_copy(url.path()); |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 571 | GURL::Replacements replacements; |
[email protected] | fab8bbed4 | 2013-03-07 01:13:03 | [diff] [blame] | 572 | replacements.SetPathStr(path_copy); |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 573 | effective_url = effective_url.ReplaceComponents(replacements); |
| 574 | return effective_url; |
| 575 | } |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 576 | #endif |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 577 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 578 | void SetApplicationLocaleOnIOThread(const std::string& locale) { |
| 579 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 580 | g_io_thread_application_locale.Get() = locale; |
| 581 | } |
| 582 | |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 583 | void HandleBlockedPopupOnUIThread(const BlockedWindowParams& params) { |
| 584 | WebContents* tab = tab_util::GetWebContentsByID(params.render_process_id(), |
| 585 | params.opener_id()); |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 586 | if (!tab) |
| 587 | return; |
| 588 | |
[email protected] | f1cd336 | 2014-01-07 20:43:01 | [diff] [blame] | 589 | prerender::PrerenderContents* prerender_contents = |
| 590 | prerender::PrerenderContents::FromWebContents(tab); |
| 591 | if (prerender_contents) { |
| 592 | prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW); |
| 593 | return; |
| 594 | } |
| 595 | |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 596 | PopupBlockerTabHelper* popup_helper = |
| 597 | PopupBlockerTabHelper::FromWebContents(tab); |
| 598 | if (!popup_helper) |
| 599 | return; |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 600 | popup_helper->AddBlockedPopup(params); |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 601 | } |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 602 | |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 603 | #if defined(OS_ANDROID) |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 604 | |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 605 | void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams& params) { |
| 606 | WebContents* web_contents = |
| 607 | tab_util::GetWebContentsByID(params.render_process_id(), |
| 608 | params.opener_id()); |
| 609 | if (!web_contents) |
| 610 | return; |
| 611 | |
| 612 | SingleTabModeTabHelper::FromWebContents(web_contents)->HandleOpenUrl(params); |
| 613 | } |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 614 | |
[email protected] | ded00dc | 2013-11-01 00:37:05 | [diff] [blame] | 615 | float GetDeviceScaleAdjustment() { |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 616 | static const float kMinFSM = 1.05f; |
| 617 | static const int kWidthForMinFSM = 320; |
| 618 | static const float kMaxFSM = 1.3f; |
| 619 | static const int kWidthForMaxFSM = 800; |
| 620 | |
| 621 | gfx::DeviceDisplayInfo info; |
| 622 | int minWidth = info.GetSmallestDIPWidth(); |
| 623 | |
| 624 | if (minWidth <= kWidthForMinFSM) |
| 625 | return kMinFSM; |
| 626 | if (minWidth >= kWidthForMaxFSM) |
| 627 | return kMaxFSM; |
| 628 | |
| 629 | // The font scale multiplier varies linearly between kMinFSM and kMaxFSM. |
| 630 | float ratio = static_cast<float>(minWidth - kWidthForMinFSM) / |
| 631 | (kWidthForMaxFSM - kWidthForMinFSM); |
| 632 | return ratio * (kMaxFSM - kMinFSM) + kMinFSM; |
| 633 | } |
| 634 | |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 635 | #endif // defined(OS_ANDROID) |
| 636 | |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 637 | } // namespace |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 638 | |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 639 | namespace chrome { |
| 640 | |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 641 | ChromeContentBrowserClient::ChromeContentBrowserClient() { |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 642 | #if defined(ENABLE_PLUGINS) |
[email protected] | 10c3922 | 2013-11-13 20:09:25 | [diff] [blame] | 643 | for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i) |
| 644 | allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]); |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 645 | for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) |
| 646 | allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 647 | #endif |
[email protected] | 1deace2 | 2013-05-22 06:14:46 | [diff] [blame] | 648 | |
| 649 | permissions_policy_delegate_.reset( |
| 650 | new extensions::BrowserPermissionsPolicyDelegate()); |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | ChromeContentBrowserClient::~ChromeContentBrowserClient() { |
| 654 | } |
| 655 | |
[email protected] | bca1838 | 2012-06-25 19:15:23 | [diff] [blame] | 656 | // static |
[email protected] | 37ca3fe0 | 2013-07-05 15:32:44 | [diff] [blame] | 657 | void ChromeContentBrowserClient::RegisterProfilePrefs( |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 658 | user_prefs::PrefRegistrySyncable* registry) { |
| 659 | registry->RegisterBooleanPref( |
| 660 | prefs::kDisable3DAPIs, |
| 661 | false, |
| 662 | user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 663 | registry->RegisterBooleanPref( |
| 664 | prefs::kEnableHyperlinkAuditing, |
| 665 | true, |
| 666 | user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
[email protected] | bca1838 | 2012-06-25 19:15:23 | [diff] [blame] | 667 | } |
| 668 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 669 | // static |
| 670 | void ChromeContentBrowserClient::SetApplicationLocale( |
| 671 | const std::string& locale) { |
| 672 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 673 | |
| 674 | // This object is guaranteed to outlive all threads so we don't have to |
| 675 | // worry about the lack of refcounting and can just post as Unretained. |
| 676 | // |
| 677 | // The common case is that this function is called early in Chrome startup |
| 678 | // before any threads are created (it will also be called later if the user |
| 679 | // changes the pref). In this case, there will be no threads created and |
| 680 | // posting will fail. When there are no threads, we can just set the string |
| 681 | // without worrying about threadsafety. |
| 682 | if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 683 | base::Bind(&SetApplicationLocaleOnIOThread, locale))) { |
| 684 | g_io_thread_application_locale.Get() = locale; |
| 685 | } |
| 686 | } |
| 687 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 688 | content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( |
| 689 | const content::MainFunctionParams& parameters) { |
| 690 | ChromeBrowserMainParts* main_parts; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 691 | // Construct the Main browser parts based on the OS type. |
| 692 | #if defined(OS_WIN) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 693 | main_parts = new ChromeBrowserMainPartsWin(parameters); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 694 | #elif defined(OS_MACOSX) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 695 | main_parts = new ChromeBrowserMainPartsMac(parameters); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 696 | #elif defined(OS_CHROMEOS) |
[email protected] | 2c624d0 | 2012-11-15 19:37:22 | [diff] [blame] | 697 | main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters); |
[email protected] | 81ce2c4 | 2012-03-24 01:43:26 | [diff] [blame] | 698 | #elif defined(OS_LINUX) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 699 | main_parts = new ChromeBrowserMainPartsLinux(parameters); |
[email protected] | 6e677a34 | 2012-02-11 01:21:14 | [diff] [blame] | 700 | #elif defined(OS_ANDROID) |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 701 | main_parts = new ChromeBrowserMainPartsAndroid(parameters); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 702 | #elif defined(OS_POSIX) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 703 | main_parts = new ChromeBrowserMainPartsPosix(parameters); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 704 | #else |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 705 | NOTREACHED(); |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 706 | main_parts = new ChromeBrowserMainParts(parameters); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 707 | #endif |
| 708 | |
[email protected] | 7e75e4a | 2013-05-17 17:20:03 | [diff] [blame] | 709 | chrome::AddProfilesExtraParts(main_parts); |
| 710 | |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 711 | // Construct additional browser parts. Stages are called in the order in |
| 712 | // which they are added. |
[email protected] | a13283cc | 2012-04-05 00:21:22 | [diff] [blame] | 713 | #if defined(TOOLKIT_GTK) |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 714 | main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk()); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 715 | #endif |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 716 | |
| 717 | #if defined(TOOLKIT_VIEWS) |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 718 | main_parts->AddParts(new ChromeBrowserMainExtraPartsViews()); |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 719 | #endif |
| 720 | |
[email protected] | dc04be7c | 2012-03-15 23:57:49 | [diff] [blame] | 721 | #if defined(USE_ASH) |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 722 | main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh()); |
[email protected] | dc04be7c | 2012-03-15 23:57:49 | [diff] [blame] | 723 | #endif |
| 724 | |
[email protected] | e050ef14 | 2012-03-21 01:04:24 | [diff] [blame] | 725 | #if defined(USE_AURA) |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 726 | main_parts->AddParts(new ChromeBrowserMainExtraPartsAura()); |
| 727 | #endif |
| 728 | |
| 729 | #if defined(USE_X11) |
| 730 | main_parts->AddParts(new ChromeBrowserMainExtraPartsX11()); |
[email protected] | e050ef14 | 2012-03-21 01:04:24 | [diff] [blame] | 731 | #endif |
| 732 | |
[email protected] | 95132f5 | 2013-04-12 02:19:04 | [diff] [blame] | 733 | chrome::AddMetricsExtraParts(main_parts); |
| 734 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 735 | return main_parts; |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 736 | } |
| 737 | |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 738 | std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite( |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 739 | content::BrowserContext* browser_context, |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 740 | const GURL& site) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 741 | std::string partition_id; |
| 742 | |
| 743 | // The partition ID for webview guest processes is the string value of its |
| 744 | // SiteInstance URL - "chrome-guest://app_id/persist?partition". |
[email protected] | 4413d87 | 2014-02-20 20:26:55 | [diff] [blame] | 745 | if (site.SchemeIs(content::kGuestScheme)) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 746 | partition_id = site.spec(); |
[email protected] | 4413d87 | 2014-02-20 20:26:55 | [diff] [blame] | 747 | } else if (site.GetOrigin().spec() == kChromeUIChromeSigninURL) { |
| 748 | // Chrome signin page has an embedded iframe of extension and web content, |
| 749 | // thus it must be isolated from other webUI pages. |
| 750 | partition_id = site.GetOrigin().spec(); |
| 751 | } |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 752 | |
[email protected] | 056efdc | 2013-04-06 00:14:53 | [diff] [blame] | 753 | DCHECK(IsValidStoragePartitionId(browser_context, partition_id)); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 754 | return partition_id; |
| 755 | } |
| 756 | |
| 757 | bool ChromeContentBrowserClient::IsValidStoragePartitionId( |
| 758 | content::BrowserContext* browser_context, |
| 759 | const std::string& partition_id) { |
| 760 | // The default ID is empty and is always valid. |
| 761 | if (partition_id.empty()) |
| 762 | return true; |
| 763 | |
| 764 | return GURL(partition_id).is_valid(); |
| 765 | } |
| 766 | |
| 767 | void ChromeContentBrowserClient::GetStoragePartitionConfigForSite( |
| 768 | content::BrowserContext* browser_context, |
| 769 | const GURL& site, |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 770 | bool can_be_default, |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 771 | std::string* partition_domain, |
| 772 | std::string* partition_name, |
| 773 | bool* in_memory) { |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 774 | // Default to the browser-wide storage partition and override based on |site| |
| 775 | // below. |
| 776 | partition_domain->clear(); |
| 777 | partition_name->clear(); |
| 778 | *in_memory = false; |
| 779 | |
[email protected] | 3f24f97c | 2013-11-17 21:53:33 | [diff] [blame] | 780 | bool success = GuestView::GetGuestPartitionConfigForSite( |
| 781 | site, partition_domain, partition_name, in_memory); |
| 782 | |
| 783 | if (!success && site.SchemeIs(extensions::kExtensionScheme)) { |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 784 | // If |can_be_default| is false, the caller is stating that the |site| |
| 785 | // should be parsed as if it had isolated storage. In particular it is |
| 786 | // important to NOT check ExtensionService for the is_storage_isolated() |
| 787 | // attribute because this code path is run during Extension uninstall |
| 788 | // to do cleanup after the Extension has already been unloaded from the |
| 789 | // ExtensionService. |
| 790 | bool is_isolated = !can_be_default; |
| 791 | if (can_be_default) { |
[email protected] | ca033634 | 2014-03-21 12:58:34 | [diff] [blame] | 792 | if (extensions::util::SiteHasIsolatedStorage(site, browser_context)) |
| 793 | is_isolated = true; |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 794 | } |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 795 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 796 | if (is_isolated) { |
| 797 | CHECK(site.has_host()); |
| 798 | // For extensions with isolated storage, the the host of the |site| is |
| 799 | // the |partition_domain|. The |in_memory| and |partition_name| are only |
| 800 | // used in guest schemes so they are cleared here. |
| 801 | *partition_domain = site.host(); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 802 | *in_memory = false; |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 803 | partition_name->clear(); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 804 | } |
[email protected] | 4413d87 | 2014-02-20 20:26:55 | [diff] [blame] | 805 | } else if (site.GetOrigin().spec() == kChromeUIChromeSigninURL) { |
| 806 | // Chrome signin page has an embedded iframe of extension and web content, |
| 807 | // thus it must be isolated from other webUI pages. |
| 808 | *partition_domain = chrome::kChromeUIChromeSigninHost; |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 809 | } |
| 810 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 811 | // Assert that if |can_be_default| is false, the code above must have found a |
| 812 | // non-default partition. If this fails, the caller has a serious logic |
| 813 | // error about which StoragePartition they expect to be in and it is not |
| 814 | // safe to continue. |
| 815 | CHECK(can_be_default || !partition_domain->empty()); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 816 | } |
| 817 | |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 818 | content::WebContentsViewDelegate* |
| 819 | ChromeContentBrowserClient::GetWebContentsViewDelegate( |
| 820 | content::WebContents* web_contents) { |
[email protected] | d3322029 | 2012-07-04 01:41:27 | [diff] [blame] | 821 | return chrome::CreateWebContentsViewDelegate(web_contents); |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 822 | } |
| 823 | |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 824 | void ChromeContentBrowserClient::GuestWebContentsCreated( |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 825 | SiteInstance* guest_site_instance, |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 826 | WebContents* guest_web_contents, |
| 827 | WebContents* opener_web_contents, |
[email protected] | 4c0e827 | 2013-07-03 23:39:22 | [diff] [blame] | 828 | content::BrowserPluginGuestDelegate** guest_delegate, |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 829 | scoped_ptr<base::DictionaryValue> extra_params) { |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 830 | if (!guest_site_instance) { |
| 831 | NOTREACHED(); |
| 832 | return; |
| 833 | } |
| 834 | GURL guest_site_url = guest_site_instance->GetSiteURL(); |
| 835 | const std::string& extension_id = guest_site_url.host(); |
| 836 | |
| 837 | Profile* profile = Profile::FromBrowserContext( |
| 838 | guest_web_contents->GetBrowserContext()); |
| 839 | ExtensionService* service = |
| 840 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 841 | if (!service) { |
| 842 | NOTREACHED(); |
| 843 | return; |
| 844 | } |
| 845 | |
| 846 | /// TODO(fsamuel): In the future, certain types of GuestViews won't require |
| 847 | // extension bindings. At that point, we should clear |extension_id| instead |
| 848 | // of exiting early. |
| 849 | if (!service->GetExtensionById(extension_id, false) && |
| 850 | !CommandLine::ForCurrentProcess()->HasSwitch( |
| 851 | switches::kEnableBrowserPluginForAllViewTypes)) { |
| 852 | NOTREACHED(); |
| 853 | return; |
| 854 | } |
| 855 | |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 856 | if (opener_web_contents) { |
| 857 | GuestView* guest = GuestView::FromWebContents(opener_web_contents); |
| 858 | if (!guest) { |
| 859 | NOTREACHED(); |
| 860 | return; |
| 861 | } |
| 862 | |
[email protected] | 50c827d | 2013-09-13 21:36:09 | [diff] [blame] | 863 | // Create a new GuestView of the same type as the opener. |
| 864 | *guest_delegate = |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 865 | GuestView::Create(guest_web_contents, |
| 866 | extension_id, |
| 867 | guest->GetViewType()); |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 868 | return; |
| 869 | } |
| 870 | |
| 871 | if (!extra_params) { |
| 872 | NOTREACHED(); |
| 873 | return; |
| 874 | } |
| 875 | std::string api_type; |
[email protected] | 90547d7 | 2013-08-06 05:57:27 | [diff] [blame] | 876 | extra_params->GetString(guestview::kParameterApi, &api_type); |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 877 | |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 878 | if (api_type.empty()) |
| 879 | return; |
| 880 | |
[email protected] | 50c827d | 2013-09-13 21:36:09 | [diff] [blame] | 881 | *guest_delegate = |
| 882 | GuestView::Create(guest_web_contents, |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 883 | extension_id, |
[email protected] | 50c827d | 2013-09-13 21:36:09 | [diff] [blame] | 884 | GuestView::GetViewTypeFromString(api_type)); |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 885 | } |
| 886 | |
[email protected] | 44295a1 | 2013-06-05 08:45:46 | [diff] [blame] | 887 | void ChromeContentBrowserClient::GuestWebContentsAttached( |
| 888 | WebContents* guest_web_contents, |
| 889 | WebContents* embedder_web_contents, |
[email protected] | 5715566a | 2013-06-25 00:04:53 | [diff] [blame] | 890 | const base::DictionaryValue& extra_params) { |
[email protected] | 22aa4f8 | 2013-09-24 17:01:44 | [diff] [blame] | 891 | |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 892 | GuestView* guest = GuestView::FromWebContents(guest_web_contents); |
| 893 | if (!guest) { |
[email protected] | efd6fb0 | 2013-08-05 04:44:06 | [diff] [blame] | 894 | // It's ok to return here, since we could be running a browser plugin |
| 895 | // outside an extension, and don't need to attach a |
| 896 | // BrowserPluginGuestDelegate in that case; |
| 897 | // e.g. running with flag --enable-browser-plugin-for-all-view-types. |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 898 | return; |
[email protected] | 1869937 | 2013-06-25 20:42:55 | [diff] [blame] | 899 | } |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 900 | guest->Attach(embedder_web_contents, extra_params); |
[email protected] | 44703cc7 | 2013-01-24 04:56:06 | [diff] [blame] | 901 | } |
| 902 | |
[email protected] | 6f286274 | 2013-12-20 07:53:19 | [diff] [blame] | 903 | void ChromeContentBrowserClient::RenderProcessWillLaunch( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 904 | content::RenderProcessHost* host) { |
| 905 | int id = host->GetID(); |
| 906 | Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
[email protected] | 4353551 | 2013-02-20 20:41:41 | [diff] [blame] | 907 | net::URLRequestContextGetter* context = |
| 908 | profile->GetRequestContextForRenderProcess(id); |
| 909 | |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 910 | host->AddFilter(new ChromeRenderMessageFilter(id, profile, context)); |
[email protected] | afed511 | 2014-02-02 06:01:53 | [diff] [blame] | 911 | host->AddFilter(new extensions::ExtensionMessageFilter(id, profile)); |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 912 | #if defined(ENABLE_PLUGINS) |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 913 | host->AddFilter(new PluginInfoMessageFilter(id, profile)); |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 914 | #endif |
[email protected] | 1ea4c49 | 2014-02-15 19:45:17 | [diff] [blame] | 915 | host->AddFilter(new cast::CastTransportHostFilter); |
[email protected] | 658677f | 2012-06-09 06:04:02 | [diff] [blame] | 916 | #if defined(ENABLE_PRINTING) |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 917 | host->AddFilter(new PrintingMessageFilter(id, profile)); |
[email protected] | 058e573 | 2012-03-01 22:48:03 | [diff] [blame] | 918 | #endif |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 919 | host->AddFilter(new SearchProviderInstallStateMessageFilter(id, profile)); |
[email protected] | c6ce0807 | 2013-07-31 07:48:53 | [diff] [blame] | 920 | #if defined(ENABLE_SPELLCHECK) |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 921 | host->AddFilter(new SpellCheckMessageFilter(id)); |
[email protected] | c6ce0807 | 2013-07-31 07:48:53 | [diff] [blame] | 922 | #endif |
[email protected] | 7ceb9901 | 2011-12-21 08:05:56 | [diff] [blame] | 923 | #if defined(OS_MACOSX) |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 924 | host->AddFilter(new SpellCheckMessageFilterMac(id)); |
[email protected] | 7ceb9901 | 2011-12-21 08:05:56 | [diff] [blame] | 925 | #endif |
[email protected] | 49aa5a3 | 2014-02-03 10:00:44 | [diff] [blame] | 926 | host->AddFilter(new ChromeNetBenchmarkingMessageFilter(profile, context)); |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 927 | host->AddFilter(new prerender::PrerenderMessageFilter(id, profile)); |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 928 | host->AddFilter(new TtsMessageFilter(id, profile)); |
[email protected] | 6ef98b5a | 2013-05-31 23:58:31 | [diff] [blame] | 929 | #if defined(ENABLE_WEBRTC) |
[email protected] | 10e5c5e5 | 2013-10-03 18:44:06 | [diff] [blame] | 930 | WebRtcLoggingHandlerHost* webrtc_logging_handler_host = |
[email protected] | 135bc1d | 2013-10-21 09:11:37 | [diff] [blame] | 931 | new WebRtcLoggingHandlerHost(profile); |
[email protected] | e7b9b35 | 2014-01-29 16:35:27 | [diff] [blame] | 932 | host->SetWebRtcLogMessageCallback(base::Bind( |
| 933 | &WebRtcLoggingHandlerHost::LogMessage, webrtc_logging_handler_host)); |
[email protected] | 10e5c5e5 | 2013-10-03 18:44:06 | [diff] [blame] | 934 | host->AddFilter(webrtc_logging_handler_host); |
| 935 | host->SetUserData(host, new base::UserDataAdapter<WebRtcLoggingHandlerHost>( |
| 936 | webrtc_logging_handler_host)); |
[email protected] | 6ef98b5a | 2013-05-31 23:58:31 | [diff] [blame] | 937 | #endif |
[email protected] | 01e5975 | 2013-06-18 00:17:35 | [diff] [blame] | 938 | #if !defined(DISABLE_NACL) |
[email protected] | 7c766e9 | 2013-11-22 20:44:02 | [diff] [blame] | 939 | host->AddFilter(new nacl::NaClHostMessageFilter( |
[email protected] | 14230ca | 2013-06-26 23:33:03 | [diff] [blame] | 940 | id, profile->IsOffTheRecord(), |
[email protected] | a2b4c5c | 2013-10-18 02:06:07 | [diff] [blame] | 941 | profile->GetPath(), |
[email protected] | 14230ca | 2013-06-26 23:33:03 | [diff] [blame] | 942 | context)); |
[email protected] | 01e5975 | 2013-06-18 00:17:35 | [diff] [blame] | 943 | #endif |
[email protected] | 2b12c32 | 2013-09-19 06:53:56 | [diff] [blame] | 944 | #if defined(OS_ANDROID) |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 945 | host->AddFilter(new EncryptedMediaMessageFilterAndroid()); |
[email protected] | 2b12c32 | 2013-09-19 06:53:56 | [diff] [blame] | 946 | #endif |
[email protected] | 4de7526 | 2013-12-18 23:16:12 | [diff] [blame] | 947 | if (switches::IsNewProfileManagement()) |
[email protected] | 914cf671 | 2013-12-05 01:14:06 | [diff] [blame] | 948 | host->AddFilter(new PrincipalsMessageFilter(id)); |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 949 | |
[email protected] | 2ccf45c | 2011-08-19 23:35:50 | [diff] [blame] | 950 | host->Send(new ChromeViewMsg_SetIsIncognitoProcess( |
| 951 | profile->IsOffTheRecord())); |
[email protected] | 39a5b53 | 2011-10-22 01:47:07 | [diff] [blame] | 952 | |
| 953 | SendExtensionWebRequestStatusToHost(host); |
[email protected] | edece21 | 2011-11-16 11:56:56 | [diff] [blame] | 954 | |
| 955 | RendererContentSettingRules rules; |
[email protected] | 06153f0 | 2013-12-04 03:01:28 | [diff] [blame] | 956 | if (host->IsGuest()) { |
| 957 | GuestView::GetDefaultContentSettingRules(&rules, profile->IsOffTheRecord()); |
| 958 | } else { |
| 959 | GetRendererContentSettingRules( |
| 960 | profile->GetHostContentSettingsMap(), &rules); |
| 961 | } |
[email protected] | edece21 | 2011-11-16 11:56:56 | [diff] [blame] | 962 | host->Send(new ChromeViewMsg_SetContentSettingRules(rules)); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 963 | } |
| 964 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 965 | GURL ChromeContentBrowserClient::GetEffectiveURL( |
| 966 | content::BrowserContext* browser_context, const GURL& url) { |
| 967 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 968 | if (!profile) |
| 969 | return url; |
| 970 | |
[email protected] | b3cb3a3 | 2013-07-31 01:32:29 | [diff] [blame] | 971 | // If the input |url| should be assigned to the Instant renderer, make its |
| 972 | // effective URL distinct from other URLs on the search provider's domain. |
| 973 | if (chrome::ShouldAssignURLToInstantRenderer(url, profile)) |
| 974 | return chrome::GetEffectiveURLForInstant(url, profile); |
| 975 | |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 976 | #if !defined(OS_CHROMEOS) |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 977 | // If the input |url| should be assigned to the Signin renderer, make its |
| 978 | // effective URL distinct from other URLs on the signin service's domain. |
| 979 | // Note that the signin renderer will be allowed to sign the user in to |
| 980 | // Chrome. |
| 981 | if (SigninManager::IsWebBasedSigninFlowURL(url)) |
| 982 | return GetEffectiveURLForSignin(url); |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 983 | #endif |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 984 | |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 985 | // If the input |url| is part of an installed app, the effective URL is an |
| 986 | // extension URL with the ID of that extension as the host. This has the |
| 987 | // effect of grouping apps together in a common SiteInstance. |
| 988 | ExtensionService* extension_service = |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 989 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 990 | if (!extension_service) |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 991 | return url; |
| 992 | |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 993 | const Extension* extension = extension_service->extensions()-> |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 994 | GetHostedAppByURL(url); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 995 | if (!extension) |
| 996 | return url; |
| 997 | |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 998 | // Bookmark apps do not use the hosted app process model, and should be |
| 999 | // treated as normal URLs. |
| 1000 | if (extension->from_bookmark()) |
| 1001 | return url; |
| 1002 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 1003 | // If the URL is part of an extension's web extent, convert it to an |
| 1004 | // extension URL. |
| 1005 | return extension->GetResourceURL(url.path()); |
| 1006 | } |
| 1007 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1008 | bool ChromeContentBrowserClient::ShouldUseProcessPerSite( |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1009 | content::BrowserContext* browser_context, const GURL& effective_url) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1010 | // Non-extension, non-Instant URLs should generally use |
| 1011 | // process-per-site-instance. Because we expect to use the effective URL, |
| 1012 | // URLs for hosted apps (apart from bookmark apps) should have an extension |
| 1013 | // scheme by now. |
| 1014 | |
| 1015 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1016 | if (!profile) |
| 1017 | return false; |
| 1018 | |
[email protected] | df113a1 | 2013-07-24 04:56:08 | [diff] [blame] | 1019 | if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile)) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1020 | return true; |
| 1021 | |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 1022 | #if !defined(OS_CHROMEOS) |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 1023 | if (SigninManager::IsWebBasedSigninFlowURL(effective_url)) |
| 1024 | return true; |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 1025 | #endif |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 1026 | |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 1027 | if (!effective_url.SchemeIs(extensions::kExtensionScheme)) |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1028 | return false; |
| 1029 | |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1030 | ExtensionService* extension_service = |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 1031 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 1032 | if (!extension_service) |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1033 | return false; |
| 1034 | |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 1035 | const Extension* extension = |
| 1036 | extension_service->extensions()->GetExtensionOrAppByURL(effective_url); |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1037 | if (!extension) |
| 1038 | return false; |
| 1039 | |
| 1040 | // If the URL is part of a hosted app that does not have the background |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 1041 | // permission, or that does not allow JavaScript access to the background |
| 1042 | // page, we want to give each instance its own process to improve |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1043 | // responsiveness. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1044 | if (extension->GetType() == Manifest::TYPE_HOSTED_APP) { |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1045 | if (!extension->HasAPIPermission(APIPermission::kBackground) || |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 1046 | !extensions::BackgroundInfo::AllowJSAccess(extension)) { |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 1047 | return false; |
| 1048 | } |
| 1049 | } |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1050 | |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 1051 | // Hosted apps that have script access to their background page must use |
| 1052 | // process per site, since all instances can make synchronous calls to the |
| 1053 | // background window. Other extensions should use process per site as well. |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1054 | return true; |
| 1055 | } |
| 1056 | |
[email protected] | 73b718f | 2014-01-27 02:59:46 | [diff] [blame] | 1057 | // These are treated as WebUI schemes but do not get WebUI bindings. Also, |
| 1058 | // view-source is allowed for these schemes. |
[email protected] | 8f89dd41 | 2013-04-17 02:35:41 | [diff] [blame] | 1059 | void ChromeContentBrowserClient::GetAdditionalWebUISchemes( |
| 1060 | std::vector<std::string>* additional_schemes) { |
| 1061 | additional_schemes->push_back(chrome::kChromeSearchScheme); |
[email protected] | 73b718f | 2014-01-27 02:59:46 | [diff] [blame] | 1062 | additional_schemes->push_back(chrome::kDomDistillerScheme); |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 1063 | } |
| 1064 | |
[email protected] | 70b89cd | 2014-03-18 00:33:24 | [diff] [blame] | 1065 | void ChromeContentBrowserClient::GetAdditionalWebUIHostsToIgnoreParititionCheck( |
| 1066 | std::vector<std::string>* hosts) { |
| 1067 | hosts->push_back(chrome::kChromeUIExtensionIconHost); |
| 1068 | hosts->push_back(chrome::kChromeUIFaviconHost); |
| 1069 | hosts->push_back(chrome::kChromeUIThemeHost); |
| 1070 | hosts->push_back(chrome::kChromeUIThumbnailHost); |
| 1071 | hosts->push_back(chrome::kChromeUIThumbnailHost2); |
| 1072 | hosts->push_back(chrome::kChromeUIThumbnailListHost); |
| 1073 | } |
| 1074 | |
| 1075 | net::URLRequestContextGetter* |
| 1076 | ChromeContentBrowserClient::CreateRequestContext( |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 1077 | content::BrowserContext* browser_context, |
[email protected] | 7571263c | 2014-03-10 22:57:09 | [diff] [blame] | 1078 | content::ProtocolHandlerMap* protocol_handlers, |
| 1079 | content::ProtocolHandlerScopedVector protocol_interceptors) { |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 1080 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | 7571263c | 2014-03-10 22:57:09 | [diff] [blame] | 1081 | return profile->CreateRequestContext(protocol_handlers, |
| 1082 | protocol_interceptors.Pass()); |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | net::URLRequestContextGetter* |
| 1086 | ChromeContentBrowserClient::CreateRequestContextForStoragePartition( |
| 1087 | content::BrowserContext* browser_context, |
[email protected] | 152ea30 | 2013-02-11 04:08:40 | [diff] [blame] | 1088 | const base::FilePath& partition_path, |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 1089 | bool in_memory, |
[email protected] | 7571263c | 2014-03-10 22:57:09 | [diff] [blame] | 1090 | content::ProtocolHandlerMap* protocol_handlers, |
| 1091 | content::ProtocolHandlerScopedVector protocol_interceptors) { |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 1092 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1093 | return profile->CreateRequestContextForStoragePartition( |
[email protected] | 7571263c | 2014-03-10 22:57:09 | [diff] [blame] | 1094 | partition_path, |
| 1095 | in_memory, |
| 1096 | protocol_handlers, |
| 1097 | protocol_interceptors.Pass()); |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 1098 | } |
| 1099 | |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 1100 | bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) { |
| 1101 | return ProfileIOData::IsHandledURL(url); |
| 1102 | } |
| 1103 | |
[email protected] | c4365fa4 | 2013-05-14 01:08:24 | [diff] [blame] | 1104 | bool ChromeContentBrowserClient::CanCommitURL( |
| 1105 | content::RenderProcessHost* process_host, |
| 1106 | const GURL& url) { |
| 1107 | // We need to let most extension URLs commit in any process, since this can |
| 1108 | // be allowed due to web_accessible_resources. Most hosted app URLs may also |
| 1109 | // load in any process (e.g., in an iframe). However, the Chrome Web Store |
| 1110 | // cannot be loaded in iframes and should never be requested outside its |
| 1111 | // process. |
| 1112 | Profile* profile = |
| 1113 | Profile::FromBrowserContext(process_host->GetBrowserContext()); |
| 1114 | ExtensionService* service = |
| 1115 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 1116 | if (!service) |
| 1117 | return true; |
| 1118 | const Extension* new_extension = |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 1119 | service->extensions()->GetExtensionOrAppByURL(url); |
[email protected] | c4365fa4 | 2013-05-14 01:08:24 | [diff] [blame] | 1120 | if (new_extension && |
| 1121 | new_extension->is_hosted_app() && |
| 1122 | new_extension->id() == extension_misc::kWebStoreAppId && |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 1123 | !extensions::ProcessMap::Get(profile)-> |
| 1124 | Contains(new_extension->id(), process_host->GetID())) { |
[email protected] | c4365fa4 | 2013-05-14 01:08:24 | [diff] [blame] | 1125 | return false; |
| 1126 | } |
| 1127 | |
| 1128 | return true; |
| 1129 | } |
| 1130 | |
[email protected] | 9a60d160 | 2013-09-11 04:09:12 | [diff] [blame] | 1131 | bool ChromeContentBrowserClient::ShouldAllowOpenURL( |
| 1132 | content::SiteInstance* site_instance, const GURL& url) { |
| 1133 | GURL from_url = site_instance->GetSiteURL(); |
| 1134 | // Do not allow pages from the web or other extensions navigate to |
| 1135 | // non-web-accessible extension resources. |
| 1136 | if (url.SchemeIs(extensions::kExtensionScheme) && |
| 1137 | (from_url.SchemeIsHTTPOrHTTPS() || |
| 1138 | from_url.SchemeIs(extensions::kExtensionScheme))) { |
| 1139 | Profile* profile = Profile::FromBrowserContext( |
| 1140 | site_instance->GetProcess()->GetBrowserContext()); |
| 1141 | ExtensionService* service = |
| 1142 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 1143 | if (!service) |
| 1144 | return true; |
| 1145 | const Extension* extension = |
| 1146 | service->extensions()->GetExtensionOrAppByURL(url); |
| 1147 | if (!extension) |
| 1148 | return true; |
| 1149 | const Extension* from_extension = |
| 1150 | service->extensions()->GetExtensionOrAppByURL( |
| 1151 | site_instance->GetSiteURL()); |
| 1152 | if (from_extension && from_extension->id() == extension->id()) |
| 1153 | return true; |
| 1154 | |
| 1155 | if (!extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible( |
| 1156 | extension, url.path())) |
| 1157 | return false; |
| 1158 | } |
| 1159 | return true; |
| 1160 | } |
| 1161 | |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1162 | bool ChromeContentBrowserClient::IsSuitableHost( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1163 | content::RenderProcessHost* process_host, |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1164 | const GURL& site_url) { |
| 1165 | Profile* profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1166 | Profile::FromBrowserContext(process_host->GetBrowserContext()); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1167 | // This may be NULL during tests. In that case, just assume any site can |
| 1168 | // share any host. |
| 1169 | if (!profile) |
| 1170 | return true; |
| 1171 | |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1172 | // Instant URLs should only be in the instant process and instant process |
| 1173 | // should only have Instant URLs. |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1174 | InstantService* instant_service = |
| 1175 | InstantServiceFactory::GetForProfile(profile); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1176 | if (instant_service) { |
| 1177 | bool is_instant_process = instant_service->IsInstantProcess( |
| 1178 | process_host->GetID()); |
| 1179 | bool should_be_in_instant_process = |
| 1180 | chrome::ShouldAssignURLToInstantRenderer(site_url, profile); |
| 1181 | if (is_instant_process || should_be_in_instant_process) |
| 1182 | return is_instant_process && should_be_in_instant_process; |
| 1183 | } |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1184 | |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 1185 | #if !defined(OS_CHROMEOS) |
[email protected] | 5ac245e | 2014-03-28 16:44:56 | [diff] [blame] | 1186 | ChromeSigninClient* signin_client = |
| 1187 | ChromeSigninClientFactory::GetForProfile(profile); |
| 1188 | if (signin_client && signin_client->IsSigninProcess(process_host->GetID())) |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 1189 | return SigninManager::IsWebBasedSigninFlowURL(site_url); |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 1190 | #endif |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 1191 | |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 1192 | ExtensionService* service = |
| 1193 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 1194 | extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile); |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1195 | |
[email protected] | ffa9760 | 2011-11-17 17:55:52 | [diff] [blame] | 1196 | // Don't allow the Task Manager to share a process with anything else. |
| 1197 | // Otherwise it can affect the renderers it is observing. |
| 1198 | // Note: we could create another RenderProcessHostPrivilege bucket for |
| 1199 | // this to allow multiple chrome://tasks instances to share, but that's |
| 1200 | // a very unlikely case without serious consequences. |
| 1201 | if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin()) |
| 1202 | return false; |
| 1203 | |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 1204 | // These may be NULL during tests. In that case, just assume any site can |
| 1205 | // share any host. |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1206 | if (!service || !process_map) |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1207 | return true; |
| 1208 | |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 1209 | // Otherwise, just make sure the process privilege matches the privilege |
| 1210 | // required by the site. |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 1211 | RenderProcessHostPrivilege privilege_required = |
| 1212 | GetPrivilegeRequiredByUrl(site_url, service); |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 1213 | return GetProcessPrivilege(process_host, process_map, service) == |
| 1214 | privilege_required; |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1215 | } |
| 1216 | |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1217 | // This function is trying to limit the amount of processes used by extensions |
| 1218 | // with background pages. It uses a globally set percentage of processes to |
| 1219 | // run such extensions and if the limit is exceeded, it returns true, to |
| 1220 | // indicate to the content module to group extensions together. |
| 1221 | bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost( |
| 1222 | content::BrowserContext* browser_context, const GURL& url) { |
| 1223 | // It has to be a valid URL for us to check for an extension. |
| 1224 | if (!url.is_valid()) |
| 1225 | return false; |
| 1226 | |
| 1227 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | 2ee3da9d6 | 2012-12-05 20:17:19 | [diff] [blame] | 1228 | ExtensionService* service = !profile ? NULL : |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 1229 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1230 | if (!service) |
| 1231 | return false; |
| 1232 | |
| 1233 | // We have to have a valid extension with background page to proceed. |
| 1234 | const Extension* extension = |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 1235 | service->extensions()->GetExtensionOrAppByURL(url); |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1236 | if (!extension) |
| 1237 | return false; |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 1238 | if (!extensions::BackgroundInfo::HasBackgroundPage(extension)) |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1239 | return false; |
| 1240 | |
| 1241 | std::set<int> process_ids; |
| 1242 | size_t max_process_count = |
| 1243 | content::RenderProcessHost::GetMaxRendererProcessCount(); |
| 1244 | |
| 1245 | // Go through all profiles to ensure we have total count of extension |
| 1246 | // processes containing background pages, otherwise one profile can |
| 1247 | // starve the other. |
| 1248 | std::vector<Profile*> profiles = g_browser_process->profile_manager()-> |
| 1249 | GetLoadedProfiles(); |
| 1250 | for (size_t i = 0; i < profiles.size(); ++i) { |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 1251 | extensions::ProcessManager* epm = |
[email protected] | be93bba0 | 2012-10-24 16:44:03 | [diff] [blame] | 1252 | extensions::ExtensionSystem::Get(profiles[i])->process_manager(); |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 1253 | for (extensions::ProcessManager::const_iterator iter = |
[email protected] | d1fe135 | 2012-04-26 00:47:32 | [diff] [blame] | 1254 | epm->background_hosts().begin(); |
| 1255 | iter != epm->background_hosts().end(); ++iter) { |
[email protected] | 3a1dc57 | 2012-07-31 22:25:13 | [diff] [blame] | 1256 | const extensions::ExtensionHost* host = *iter; |
[email protected] | d1fe135 | 2012-04-26 00:47:32 | [diff] [blame] | 1257 | process_ids.insert(host->render_process_host()->GetID()); |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | if (process_ids.size() > |
| 1262 | (max_process_count * chrome::kMaxShareOfExtensionProcesses)) { |
| 1263 | return true; |
| 1264 | } |
| 1265 | |
| 1266 | return false; |
| 1267 | } |
| 1268 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1269 | void ChromeContentBrowserClient::SiteInstanceGotProcess( |
| 1270 | SiteInstance* site_instance) { |
| 1271 | CHECK(site_instance->HasProcess()); |
| 1272 | |
| 1273 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 72daaa9 | 2012-01-18 13:39:02 | [diff] [blame] | 1274 | site_instance->GetBrowserContext()); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1275 | if (!profile) |
| 1276 | return; |
| 1277 | |
| 1278 | // Remember the ID of the Instant process to signal the renderer process |
| 1279 | // on startup in |AppendExtraCommandLineSwitches| below. |
[email protected] | 165fe42 | 2013-03-27 06:34:03 | [diff] [blame] | 1280 | if (chrome::ShouldAssignURLToInstantRenderer( |
[email protected] | 7c60f504 | 2013-02-14 03:39:32 | [diff] [blame] | 1281 | site_instance->GetSiteURL(), profile)) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1282 | InstantService* instant_service = |
| 1283 | InstantServiceFactory::GetForProfile(profile); |
| 1284 | if (instant_service) |
| 1285 | instant_service->AddInstantProcess(site_instance->GetProcess()->GetID()); |
| 1286 | } |
| 1287 | |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 1288 | #if !defined(OS_CHROMEOS) |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 1289 | // We only expect there to be one signin process as we use process-per-site |
| 1290 | // for signin URLs. The signin process will be cleared from SigninManager |
| 1291 | // when the renderer is destroyed. |
| 1292 | if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) { |
[email protected] | 5ac245e | 2014-03-28 16:44:56 | [diff] [blame] | 1293 | ChromeSigninClient* signin_client = |
| 1294 | ChromeSigninClientFactory::GetForProfile(profile); |
| 1295 | if (signin_client) |
| 1296 | signin_client->SetSigninProcess(site_instance->GetProcess()->GetID()); |
[email protected] | 1deace2 | 2013-05-22 06:14:46 | [diff] [blame] | 1297 | BrowserThread::PostTask( |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 1298 | BrowserThread::IO, |
| 1299 | FROM_HERE, |
| 1300 | base::Bind(&InfoMap::SetSigninProcess, |
[email protected] | 1deace2 | 2013-05-22 06:14:46 | [diff] [blame] | 1301 | extensions::ExtensionSystem::Get(profile)->info_map(), |
| 1302 | site_instance->GetProcess()->GetID())); |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 1303 | } |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 1304 | #endif |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 1305 | |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 1306 | ExtensionService* service = |
| 1307 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1308 | if (!service) |
| 1309 | return; |
| 1310 | |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 1311 | const Extension* extension = service->extensions()->GetExtensionOrAppByURL( |
| 1312 | site_instance->GetSiteURL()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1313 | if (!extension) |
| 1314 | return; |
| 1315 | |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 1316 | extensions::ProcessMap::Get(profile) |
| 1317 | ->Insert(extension->id(), |
| 1318 | site_instance->GetProcess()->GetID(), |
| 1319 | site_instance->GetId()); |
| 1320 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1321 | BrowserThread::PostTask( |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 1322 | BrowserThread::IO, |
| 1323 | FROM_HERE, |
| 1324 | base::Bind(&InfoMap::RegisterExtensionProcess, |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 1325 | extensions::ExtensionSystem::Get(profile)->info_map(), |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1326 | extension->id(), |
[email protected] | 6bc04fd8 | 2011-12-04 02:29:35 | [diff] [blame] | 1327 | site_instance->GetProcess()->GetID(), |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 1328 | site_instance->GetId())); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | void ChromeContentBrowserClient::SiteInstanceDeleting( |
| 1332 | SiteInstance* site_instance) { |
| 1333 | if (!site_instance->HasProcess()) |
| 1334 | return; |
| 1335 | |
| 1336 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 72daaa9 | 2012-01-18 13:39:02 | [diff] [blame] | 1337 | site_instance->GetBrowserContext()); |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 1338 | ExtensionService* service = |
| 1339 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1340 | if (!service) |
| 1341 | return; |
| 1342 | |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 1343 | const Extension* extension = service->extensions()->GetExtensionOrAppByURL( |
| 1344 | site_instance->GetSiteURL()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1345 | if (!extension) |
| 1346 | return; |
| 1347 | |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 1348 | extensions::ProcessMap::Get(profile) |
| 1349 | ->Remove(extension->id(), |
| 1350 | site_instance->GetProcess()->GetID(), |
| 1351 | site_instance->GetId()); |
| 1352 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1353 | BrowserThread::PostTask( |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 1354 | BrowserThread::IO, |
| 1355 | FROM_HERE, |
| 1356 | base::Bind(&InfoMap::UnregisterExtensionProcess, |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 1357 | extensions::ExtensionSystem::Get(profile)->info_map(), |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1358 | extension->id(), |
[email protected] | 6bc04fd8 | 2011-12-04 02:29:35 | [diff] [blame] | 1359 | site_instance->GetProcess()->GetID(), |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 1360 | site_instance->GetId())); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1361 | } |
| 1362 | |
[email protected] | 896c6d5 | 2014-01-28 21:40:21 | [diff] [blame] | 1363 | void ChromeContentBrowserClient::WorkerProcessCreated( |
| 1364 | SiteInstance* site_instance, |
| 1365 | int worker_process_id) { |
| 1366 | extensions::ExtensionRegistry* extension_registry = |
| 1367 | extensions::ExtensionRegistry::Get(site_instance->GetBrowserContext()); |
| 1368 | if (!extension_registry) |
| 1369 | return; |
| 1370 | const Extension* extension = |
| 1371 | extension_registry->enabled_extensions().GetExtensionOrAppByURL( |
| 1372 | site_instance->GetSiteURL()); |
| 1373 | if (!extension) |
| 1374 | return; |
| 1375 | extensions::ExtensionSystem* extension_system = |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 1376 | extensions::ExtensionSystem::Get(site_instance->GetBrowserContext()); |
[email protected] | 896c6d5 | 2014-01-28 21:40:21 | [diff] [blame] | 1377 | extension_system->info_map()->RegisterExtensionWorkerProcess( |
| 1378 | extension->id(), |
| 1379 | worker_process_id, |
| 1380 | site_instance->GetId()); |
| 1381 | } |
| 1382 | |
| 1383 | void ChromeContentBrowserClient::WorkerProcessTerminated( |
| 1384 | SiteInstance* site_instance, |
| 1385 | int worker_process_id) { |
| 1386 | extensions::ExtensionSystem* extension_system = |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 1387 | extensions::ExtensionSystem::Get(site_instance->GetBrowserContext()); |
[email protected] | 896c6d5 | 2014-01-28 21:40:21 | [diff] [blame] | 1388 | extension_system->info_map()->UnregisterExtensionWorkerProcess( |
| 1389 | worker_process_id); |
| 1390 | } |
| 1391 | |
[email protected] | 453f543 | 2013-11-26 19:43:00 | [diff] [blame] | 1392 | bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation( |
[email protected] | e9841fbd | 2013-02-22 23:12:14 | [diff] [blame] | 1393 | SiteInstance* site_instance, |
[email protected] | e3daf3c | 2011-10-05 21:17:08 | [diff] [blame] | 1394 | const GURL& current_url, |
| 1395 | const GURL& new_url) { |
[email protected] | 2aca9a9 | 2013-12-03 05:16:07 | [diff] [blame] | 1396 | // If we don't have an ExtensionService, then rely on the SiteInstance logic |
[email protected] | a5a5948 | 2013-12-03 22:52:06 | [diff] [blame] | 1397 | // in RenderFrameHostManager to decide when to swap. |
[email protected] | e9841fbd | 2013-02-22 23:12:14 | [diff] [blame] | 1398 | Profile* profile = |
| 1399 | Profile::FromBrowserContext(site_instance->GetBrowserContext()); |
| 1400 | ExtensionService* service = |
| 1401 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 1402 | if (!service) |
| 1403 | return false; |
| 1404 | |
[email protected] | 2aca9a9 | 2013-12-03 05:16:07 | [diff] [blame] | 1405 | // We must use a new BrowsingInstance (forcing a process swap and disabling |
| 1406 | // scripting by existing tabs) if one of the URLs is an extension and the |
| 1407 | // other is not the exact same extension. |
| 1408 | // |
| 1409 | // We ignore hosted apps here so that other tabs in their BrowsingInstance can |
| 1410 | // use postMessage with them. (The exception is the Chrome Web Store, which |
| 1411 | // is a hosted app that requires its own BrowsingInstance.) Navigations |
| 1412 | // to/from a hosted app will still trigger a SiteInstance swap in |
[email protected] | a5a5948 | 2013-12-03 22:52:06 | [diff] [blame] | 1413 | // RenderFrameHostManager. |
[email protected] | 2aca9a9 | 2013-12-03 05:16:07 | [diff] [blame] | 1414 | const Extension* current_extension = |
| 1415 | service->extensions()->GetExtensionOrAppByURL(current_url); |
| 1416 | if (current_extension && |
| 1417 | current_extension->is_hosted_app() && |
| 1418 | current_extension->id() != extension_misc::kWebStoreAppId) |
| 1419 | current_extension = NULL; |
| 1420 | |
[email protected] | e9841fbd | 2013-02-22 23:12:14 | [diff] [blame] | 1421 | const Extension* new_extension = |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 1422 | service->extensions()->GetExtensionOrAppByURL(new_url); |
[email protected] | e9841fbd | 2013-02-22 23:12:14 | [diff] [blame] | 1423 | if (new_extension && |
| 1424 | new_extension->is_hosted_app() && |
| 1425 | new_extension->id() != extension_misc::kWebStoreAppId) |
| 1426 | new_extension = NULL; |
[email protected] | 2aca9a9 | 2013-12-03 05:16:07 | [diff] [blame] | 1427 | |
| 1428 | // First do a process check. We should force a BrowsingInstance swap if the |
| 1429 | // current process doesn't know about new_extension, even if current_extension |
| 1430 | // is somehow the same as new_extension. |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 1431 | extensions::ProcessMap* process_map = extensions::ProcessMap::Get(profile); |
[email protected] | e9841fbd | 2013-02-22 23:12:14 | [diff] [blame] | 1432 | if (new_extension && |
| 1433 | site_instance->HasProcess() && |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 1434 | !process_map->Contains( |
| 1435 | new_extension->id(), site_instance->GetProcess()->GetID())) |
[email protected] | e9841fbd | 2013-02-22 23:12:14 | [diff] [blame] | 1436 | return true; |
| 1437 | |
[email protected] | 2aca9a9 | 2013-12-03 05:16:07 | [diff] [blame] | 1438 | // Otherwise, swap BrowsingInstances if current_extension and new_extension |
| 1439 | // differ. |
| 1440 | return current_extension != new_extension; |
[email protected] | e3daf3c | 2011-10-05 21:17:08 | [diff] [blame] | 1441 | } |
| 1442 | |
[email protected] | 395045c | 2012-05-22 15:04:38 | [diff] [blame] | 1443 | bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect( |
| 1444 | content::ResourceContext* resource_context, const GURL& current_url, |
| 1445 | const GURL& new_url) { |
| 1446 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
| 1447 | return extensions::CrossesExtensionProcessBoundary( |
| 1448 | io_data->GetExtensionInfoMap()->extensions(), |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 1449 | current_url, new_url, false); |
[email protected] | 395045c | 2012-05-22 15:04:38 | [diff] [blame] | 1450 | } |
| 1451 | |
[email protected] | 3d83199 | 2013-07-04 01:13:29 | [diff] [blame] | 1452 | bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) { |
| 1453 | return !url.SchemeIs(chrome::kChromeNativeScheme); |
| 1454 | } |
| 1455 | |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 1456 | std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName( |
| 1457 | const std::string& alias_name) { |
| 1458 | return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name); |
| 1459 | } |
| 1460 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1461 | void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( |
| 1462 | CommandLine* command_line, int child_process_id) { |
[email protected] | 264c0acac | 2013-10-01 13:33:30 | [diff] [blame] | 1463 | #if defined(OS_POSIX) |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 1464 | if (breakpad::IsCrashReporterEnabled()) { |
[email protected] | 264c0acac | 2013-10-01 13:33:30 | [diff] [blame] | 1465 | std::string enable_crash_reporter; |
| 1466 | GoogleUpdateSettings::GetMetricsId(&enable_crash_reporter); |
| 1467 | #if !defined(OS_MACOSX) |
| 1468 | enable_crash_reporter += "," + base::GetLinuxDistro(); |
| 1469 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1470 | command_line->AppendSwitchASCII(switches::kEnableCrashReporter, |
[email protected] | 264c0acac | 2013-10-01 13:33:30 | [diff] [blame] | 1471 | enable_crash_reporter); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1472 | } |
[email protected] | 264c0acac | 2013-10-01 13:33:30 | [diff] [blame] | 1473 | #endif // OS_POSIX |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1474 | |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 1475 | if (logging::DialogsAreSuppressed()) |
| 1476 | command_line->AppendSwitch(switches::kNoErrorDialogs); |
| 1477 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1478 | std::string process_type = |
| 1479 | command_line->GetSwitchValueASCII(switches::kProcessType); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 1480 | const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 9206f2a0 | 2013-03-20 01:10:32 | [diff] [blame] | 1481 | |
[email protected] | 7c9b6f9 | 2013-09-10 18:11:35 | [diff] [blame] | 1482 | static const char* const kCommonSwitchNames[] = { |
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 1483 | switches::kUserAgent, |
[email protected] | 7c9b6f9 | 2013-09-10 18:11:35 | [diff] [blame] | 1484 | switches::kUserDataDir, // Make logs go to the right file. |
| 1485 | }; |
| 1486 | command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames, |
| 1487 | arraysize(kCommonSwitchNames)); |
[email protected] | 9206f2a0 | 2013-03-20 01:10:32 | [diff] [blame] | 1488 | |
[email protected] | 8c64e28 | 2013-11-28 16:05:14 | [diff] [blame] | 1489 | #if defined(ENABLE_IPC_FUZZER) |
| 1490 | static const char* const kIpcFuzzerSwitches[] = { |
| 1491 | switches::kIpcFuzzerTestcase, |
| 1492 | }; |
| 1493 | command_line->CopySwitchesFrom(browser_command_line, kIpcFuzzerSwitches, |
| 1494 | arraysize(kIpcFuzzerSwitches)); |
| 1495 | #endif |
| 1496 | |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 1497 | if (process_type == switches::kRendererProcess) { |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1498 | #if defined(OS_CHROMEOS) |
| 1499 | const std::string& login_profile = |
[email protected] | 931d104 | 2013-04-05 17:50:44 | [diff] [blame] | 1500 | browser_command_line.GetSwitchValueASCII( |
| 1501 | chromeos::switches::kLoginProfile); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1502 | if (!login_profile.empty()) |
[email protected] | 931d104 | 2013-04-05 17:50:44 | [diff] [blame] | 1503 | command_line->AppendSwitchASCII( |
| 1504 | chromeos::switches::kLoginProfile, login_profile); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1505 | #endif |
| 1506 | |
[email protected] | 50fa4d5f | 2013-11-05 00:53:23 | [diff] [blame] | 1507 | #if defined(ENABLE_WEBRTC) |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 1508 | MaybeCopyDisableWebRtcEncryptionSwitch(command_line, |
| 1509 | browser_command_line, |
| 1510 | VersionInfo::GetChannel()); |
[email protected] | 50fa4d5f | 2013-11-05 00:53:23 | [diff] [blame] | 1511 | #endif |
| 1512 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1513 | content::RenderProcessHost* process = |
| 1514 | content::RenderProcessHost::FromID(child_process_id); |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 1515 | if (process) { |
| 1516 | Profile* profile = Profile::FromBrowserContext( |
| 1517 | process->GetBrowserContext()); |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 1518 | |
| 1519 | if (extensions::ProcessMap::Get(profile)->Contains(process->GetID())) |
| 1520 | command_line->AppendSwitch(extensions::switches::kExtensionProcess); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1521 | |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 1522 | PrefService* prefs = profile->GetPrefs(); |
| 1523 | // Currently this pref is only registered if applied via a policy. |
| 1524 | if (prefs->HasPrefPath(prefs::kDisable3DAPIs) && |
| 1525 | prefs->GetBoolean(prefs::kDisable3DAPIs)) { |
| 1526 | // Turn this policy into a command line switch. |
| 1527 | command_line->AppendSwitch(switches::kDisable3DAPIs); |
| 1528 | } |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 1529 | |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 1530 | // Disable client-side phishing detection in the renderer if it is |
| 1531 | // disabled in the Profile preferences or the browser process. |
| 1532 | if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) || |
| 1533 | !g_browser_process->safe_browsing_detection_service()) { |
| 1534 | command_line->AppendSwitch( |
| 1535 | switches::kDisableClientSidePhishingDetection); |
| 1536 | } |
[email protected] | 0045b0f4 | 2012-07-26 11:52:08 | [diff] [blame] | 1537 | |
| 1538 | if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled)) |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 1539 | command_line->AppendSwitch(switches::kRendererPrintPreview); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1540 | |
| 1541 | InstantService* instant_service = |
| 1542 | InstantServiceFactory::GetForProfile(profile); |
| 1543 | if (instant_service && |
| 1544 | instant_service->IsInstantProcess(process->GetID())) |
| 1545 | command_line->AppendSwitch(switches::kInstantProcess); |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 1546 | |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 1547 | #if !defined(OS_CHROMEOS) |
[email protected] | 5ac245e | 2014-03-28 16:44:56 | [diff] [blame] | 1548 | ChromeSigninClient* signin_client = |
| 1549 | ChromeSigninClientFactory::GetForProfile(profile); |
| 1550 | if (signin_client && signin_client->IsSigninProcess(process->GetID())) |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 1551 | command_line->AppendSwitch(switches::kSigninProcess); |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 1552 | #endif |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 1553 | } |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1554 | |
[email protected] | 28ee4e7 | 2014-03-28 19:29:04 | [diff] [blame] | 1555 | { |
| 1556 | // Enable auto-reload if this session is in the field trial or the user |
| 1557 | // explicitly enabled it. |
| 1558 | std::string group = |
| 1559 | base::FieldTrialList::FindFullName("AutoReloadExperiment"); |
| 1560 | if (group == "Enabled" || |
| 1561 | browser_command_line.HasSwitch(switches::kEnableOfflineAutoReload)) { |
| 1562 | command_line->AppendSwitch(switches::kEnableOfflineAutoReload); |
| 1563 | } |
| 1564 | } |
| 1565 | |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 1566 | // Please keep this in alphabetical order. |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1567 | static const char* const kSwitchNames[] = { |
[email protected] | b785898a | 2014-02-05 06:54:43 | [diff] [blame] | 1568 | autofill::switches::kDisableIgnoreAutocompleteOff, |
[email protected] | 000f3ad | 2013-05-16 02:19:17 | [diff] [blame] | 1569 | autofill::switches::kDisableInteractiveAutocomplete, |
[email protected] | c3cc063 | 2013-10-03 21:54:43 | [diff] [blame] | 1570 | autofill::switches::kDisablePasswordGeneration, |
[email protected] | 000f3ad | 2013-05-16 02:19:17 | [diff] [blame] | 1571 | autofill::switches::kEnableInteractiveAutocomplete, |
[email protected] | c3cc063 | 2013-10-03 21:54:43 | [diff] [blame] | 1572 | autofill::switches::kEnablePasswordGeneration, |
[email protected] | 3cbdf936 | 2014-01-31 23:12:23 | [diff] [blame] | 1573 | autofill::switches::kLocalHeuristicsOnlyForPasswordGeneration, |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 1574 | extensions::switches::kAllowHTTPBackgroundPage, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 1575 | extensions::switches::kAllowLegacyExtensionManifests, |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 1576 | extensions::switches::kEnableExperimentalExtensionApis, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 1577 | extensions::switches::kExtensionsOnChromeURLs, |
[email protected] | a612eb3 | 2014-03-31 22:09:17 | [diff] [blame] | 1578 | extensions::switches::kWhitelistedExtensionID, |
[email protected] | 9d45049 | 2013-06-13 23:08:37 | [diff] [blame] | 1579 | // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO |
| 1580 | // to browser. |
| 1581 | switches::kAllowNaClFileHandleAPI, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1582 | switches::kAppsCheckoutURL, |
| 1583 | switches::kAppsGalleryURL, |
[email protected] | be9d9c8 | 2011-07-13 04:17:31 | [diff] [blame] | 1584 | switches::kCloudPrintServiceURL, |
[email protected] | 382fb0d | 2012-02-25 00:19:50 | [diff] [blame] | 1585 | switches::kDisableBundledPpapiFlash, |
[email protected] | e9dfe22 | 2012-05-11 22:05:53 | [diff] [blame] | 1586 | switches::kDisableExtensionsResourceWhitelist, |
[email protected] | 83c8526 | 2013-08-22 21:13:46 | [diff] [blame] | 1587 | switches::kDisablePnacl, |
[email protected] | b0553c7e | 2012-09-19 21:36:11 | [diff] [blame] | 1588 | switches::kDisableScriptedPrintThrottling, |
[email protected] | e9cddd5 | 2013-03-23 17:37:53 | [diff] [blame] | 1589 | switches::kEnableAdview, |
[email protected] | 1f4da9e | 2013-06-27 05:23:44 | [diff] [blame] | 1590 | switches::kEnableAppWindowControls, |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 1591 | switches::kEnableBenchmarking, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1592 | switches::kEnableNaCl, |
[email protected] | 1b4ec38 | 2014-03-07 02:32:24 | [diff] [blame] | 1593 | switches::kEnableNaClDebug, |
[email protected] | b2c73f4 | 2014-03-07 15:44:48 | [diff] [blame] | 1594 | switches::kEnableNaClNonSfiMode, |
[email protected] | ce304ce | 2013-02-22 21:54:45 | [diff] [blame] | 1595 | switches::kEnableNetBenchmarking, |
[email protected] | c10b25f | 2014-01-14 14:57:00 | [diff] [blame] | 1596 | switches::kEnableStreamlinedHostedApps, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1597 | switches::kEnableWatchdog, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1598 | switches::kMemoryProfiling, |
| 1599 | switches::kMessageLoopHistogrammer, |
[email protected] | f45c5f3 | 2012-04-18 19:26:37 | [diff] [blame] | 1600 | switches::kNoJsRandomness, |
[email protected] | 8f06e4d | 2013-11-25 23:20:18 | [diff] [blame] | 1601 | switches::kOutOfProcessPdf, |
[email protected] | f45c5f3 | 2012-04-18 19:26:37 | [diff] [blame] | 1602 | switches::kPlaybackMode, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1603 | switches::kPpapiFlashArgs, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1604 | switches::kPpapiFlashPath, |
| 1605 | switches::kPpapiFlashVersion, |
| 1606 | switches::kProfilingAtStart, |
| 1607 | switches::kProfilingFile, |
| 1608 | switches::kProfilingFlush, |
[email protected] | f45c5f3 | 2012-04-18 19:26:37 | [diff] [blame] | 1609 | switches::kRecordMode, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1610 | switches::kSilentDumpOnDCHECK, |
[email protected] | 499e7c5 | 2013-10-04 16:03:09 | [diff] [blame] | 1611 | translate::switches::kTranslateSecurityOrigin, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1612 | }; |
| 1613 | |
| 1614 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 1615 | arraysize(kSwitchNames)); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 1616 | } else if (process_type == switches::kUtilityProcess) { |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 1617 | static const char* const kSwitchNames[] = { |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 1618 | extensions::switches::kAllowHTTPBackgroundPage, |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 1619 | extensions::switches::kEnableExperimentalExtensionApis, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 1620 | extensions::switches::kExtensionsOnChromeURLs, |
[email protected] | a612eb3 | 2014-03-31 22:09:17 | [diff] [blame] | 1621 | extensions::switches::kWhitelistedExtensionID, |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 1622 | }; |
| 1623 | |
| 1624 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 1625 | arraysize(kSwitchNames)); |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1626 | } else if (process_type == switches::kPluginProcess) { |
| 1627 | static const char* const kSwitchNames[] = { |
[email protected] | 931d104 | 2013-04-05 17:50:44 | [diff] [blame] | 1628 | #if defined(OS_CHROMEOS) |
| 1629 | chromeos::switches::kLoginProfile, |
| 1630 | #endif |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1631 | switches::kMemoryProfiling, |
| 1632 | switches::kSilentDumpOnDCHECK, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1633 | }; |
| 1634 | |
| 1635 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 1636 | arraysize(kSwitchNames)); |
| 1637 | } else if (process_type == switches::kZygoteProcess) { |
| 1638 | static const char* const kSwitchNames[] = { |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1639 | // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox. |
[email protected] | 382fb0d | 2012-02-25 00:19:50 | [diff] [blame] | 1640 | switches::kDisableBundledPpapiFlash, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1641 | switches::kPpapiFlashPath, |
| 1642 | switches::kPpapiFlashVersion, |
| 1643 | }; |
| 1644 | |
| 1645 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 1646 | arraysize(kSwitchNames)); |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 1647 | } else if (process_type == switches::kGpuProcess) { |
| 1648 | // If --ignore-gpu-blacklist is passed in, don't send in crash reports |
| 1649 | // because GPU is expected to be unreliable. |
| 1650 | if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) && |
| 1651 | !command_line->HasSwitch(switches::kDisableBreakpad)) |
| 1652 | command_line->AppendSwitch(switches::kDisableBreakpad); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1653 | } |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 1654 | |
| 1655 | // The command line switch kEnableBenchmarking needs to be specified along |
| 1656 | // with the kEnableStatsTable switch to ensure that the stats table global |
| 1657 | // is initialized correctly. |
| 1658 | if (command_line->HasSwitch(switches::kEnableBenchmarking)) |
| 1659 | DCHECK(command_line->HasSwitch(switches::kEnableStatsTable)); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | std::string ChromeContentBrowserClient::GetApplicationLocale() { |
[email protected] | e9a32a5 | 2012-06-14 23:32:43 | [diff] [blame] | 1663 | if (BrowserThread::CurrentlyOn(BrowserThread::IO)) |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 1664 | return g_io_thread_application_locale.Get(); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1665 | return g_browser_process->GetApplicationLocale(); |
| 1666 | } |
| 1667 | |
[email protected] | 597a867b | 2011-11-18 18:31:20 | [diff] [blame] | 1668 | std::string ChromeContentBrowserClient::GetAcceptLangs( |
| 1669 | content::BrowserContext* context) { |
| 1670 | Profile* profile = Profile::FromBrowserContext(context); |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1671 | return profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 1672 | } |
| 1673 | |
[email protected] | 9ec0f45 | 2012-05-31 15:58:53 | [diff] [blame] | 1674 | gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() { |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 1675 | ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
[email protected] | 9ec0f45 | 2012-05-31 15:58:53 | [diff] [blame] | 1676 | return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON); |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 1677 | } |
| 1678 | |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 1679 | bool ChromeContentBrowserClient::AllowAppCache( |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 1680 | const GURL& manifest_url, |
[email protected] | 0a60884 | 2011-09-08 10:55:19 | [diff] [blame] | 1681 | const GURL& first_party, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1682 | content::ResourceContext* context) { |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 1683 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1684 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 1685 | return io_data->GetCookieSettings()-> |
| 1686 | IsSettingCookieAllowed(manifest_url, first_party); |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 1687 | } |
| 1688 | |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 1689 | bool ChromeContentBrowserClient::AllowGetCookie( |
| 1690 | const GURL& url, |
| 1691 | const GURL& first_party, |
| 1692 | const net::CookieList& cookie_list, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1693 | content::ResourceContext* context, |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 1694 | int render_process_id, |
[email protected] | f3add92 | 2013-12-20 23:17:16 | [diff] [blame] | 1695 | int render_frame_id) { |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 1696 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1697 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 1698 | bool allow = io_data->GetCookieSettings()-> |
| 1699 | IsReadingCookieAllowed(url, first_party); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 1700 | |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 1701 | BrowserThread::PostTask( |
| 1702 | BrowserThread::UI, FROM_HERE, |
[email protected] | 317c58f0 | 2011-11-09 02:15:03 | [diff] [blame] | 1703 | base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id, |
[email protected] | f7fa5b6 | 2014-03-19 15:20:06 | [diff] [blame] | 1704 | render_frame_id, url, first_party, cookie_list, !allow, true)); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 1705 | return allow; |
| 1706 | } |
| 1707 | |
| 1708 | bool ChromeContentBrowserClient::AllowSetCookie( |
| 1709 | const GURL& url, |
| 1710 | const GURL& first_party, |
| 1711 | const std::string& cookie_line, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1712 | content::ResourceContext* context, |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 1713 | int render_process_id, |
[email protected] | f3add92 | 2013-12-20 23:17:16 | [diff] [blame] | 1714 | int render_frame_id, |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 1715 | net::CookieOptions* options) { |
| 1716 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1717 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 1718 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 1719 | bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party); |
| 1720 | |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 1721 | BrowserThread::PostTask( |
| 1722 | BrowserThread::UI, FROM_HERE, |
[email protected] | 317c58f0 | 2011-11-09 02:15:03 | [diff] [blame] | 1723 | base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id, |
[email protected] | f3add92 | 2013-12-20 23:17:16 | [diff] [blame] | 1724 | render_frame_id, url, first_party, cookie_line, *options, |
[email protected] | fd473d1 | 2012-04-05 11:38:43 | [diff] [blame] | 1725 | !allow)); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 1726 | return allow; |
| 1727 | } |
| 1728 | |
[email protected] | d5a1916 | 2011-06-30 18:51:54 | [diff] [blame] | 1729 | bool ChromeContentBrowserClient::AllowSaveLocalState( |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1730 | content::ResourceContext* context) { |
[email protected] | d5a1916 | 2011-06-30 18:51:54 | [diff] [blame] | 1731 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1732 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | bf510ed | 2012-06-05 08:31:43 | [diff] [blame] | 1733 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 1734 | ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL); |
[email protected] | 1848cdc | 2012-02-17 10:48:26 | [diff] [blame] | 1735 | |
[email protected] | bf510ed | 2012-06-05 08:31:43 | [diff] [blame] | 1736 | // TODO(bauerb): Should we also disallow local state if the default is BLOCK? |
| 1737 | // Could we even support per-origin settings? |
| 1738 | return setting != CONTENT_SETTING_SESSION_ONLY; |
[email protected] | d5a1916 | 2011-06-30 18:51:54 | [diff] [blame] | 1739 | } |
| 1740 | |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1741 | bool ChromeContentBrowserClient::AllowWorkerDatabase( |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1742 | const GURL& url, |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 1743 | const base::string16& name, |
| 1744 | const base::string16& display_name, |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1745 | unsigned long estimated_size, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1746 | content::ResourceContext* context, |
[email protected] | b765deb | 2013-12-18 06:43:30 | [diff] [blame] | 1747 | const std::vector<std::pair<int, int> >& render_frames) { |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1748 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1749 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1750 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 1751 | bool allow = cookie_settings->IsSettingCookieAllowed(url, url); |
| 1752 | |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 1753 | // Record access to database for potential display in UI. |
| 1754 | std::vector<std::pair<int, int> >::const_iterator i; |
[email protected] | b765deb | 2013-12-18 06:43:30 | [diff] [blame] | 1755 | for (i = render_frames.begin(); i != render_frames.end(); ++i) { |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 1756 | BrowserThread::PostTask( |
| 1757 | BrowserThread::UI, FROM_HERE, |
| 1758 | base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed, |
| 1759 | i->first, i->second, url, name, display_name, !allow)); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1760 | } |
| 1761 | |
| 1762 | return allow; |
| 1763 | } |
| 1764 | |
| 1765 | bool ChromeContentBrowserClient::AllowWorkerFileSystem( |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1766 | const GURL& url, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1767 | content::ResourceContext* context, |
[email protected] | b765deb | 2013-12-18 06:43:30 | [diff] [blame] | 1768 | const std::vector<std::pair<int, int> >& render_frames) { |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1769 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1770 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1771 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 1772 | bool allow = cookie_settings->IsSettingCookieAllowed(url, url); |
| 1773 | |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 1774 | // Record access to file system for potential display in UI. |
| 1775 | std::vector<std::pair<int, int> >::const_iterator i; |
[email protected] | b765deb | 2013-12-18 06:43:30 | [diff] [blame] | 1776 | for (i = render_frames.begin(); i != render_frames.end(); ++i) { |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 1777 | BrowserThread::PostTask( |
| 1778 | BrowserThread::UI, FROM_HERE, |
| 1779 | base::Bind(&TabSpecificContentSettings::FileSystemAccessed, |
| 1780 | i->first, i->second, url, !allow)); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | return allow; |
| 1784 | } |
| 1785 | |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 1786 | bool ChromeContentBrowserClient::AllowWorkerIndexedDB( |
| 1787 | const GURL& url, |
[email protected] | 9692015 | 2013-12-04 21:00:16 | [diff] [blame] | 1788 | const base::string16& name, |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 1789 | content::ResourceContext* context, |
[email protected] | b765deb | 2013-12-18 06:43:30 | [diff] [blame] | 1790 | const std::vector<std::pair<int, int> >& render_frames) { |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 1791 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1792 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
| 1793 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 1794 | bool allow = cookie_settings->IsSettingCookieAllowed(url, url); |
| 1795 | |
| 1796 | // Record access to IndexedDB for potential display in UI. |
| 1797 | std::vector<std::pair<int, int> >::const_iterator i; |
[email protected] | b765deb | 2013-12-18 06:43:30 | [diff] [blame] | 1798 | for (i = render_frames.begin(); i != render_frames.end(); ++i) { |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 1799 | BrowserThread::PostTask( |
| 1800 | BrowserThread::UI, FROM_HERE, |
| 1801 | base::Bind(&TabSpecificContentSettings::IndexedDBAccessed, |
| 1802 | i->first, i->second, url, name, !allow)); |
| 1803 | } |
| 1804 | |
| 1805 | return allow; |
| 1806 | } |
| 1807 | |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 1808 | net::URLRequestContext* |
| 1809 | ChromeContentBrowserClient::OverrideRequestContextForURL( |
| 1810 | const GURL& url, content::ResourceContext* context) { |
| 1811 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1812 | if (url.SchemeIs(extensions::kExtensionScheme)) { |
| 1813 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
| 1814 | return io_data->extensions_request_context(); |
| 1815 | } |
| 1816 | |
| 1817 | return NULL; |
| 1818 | } |
| 1819 | |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 1820 | QuotaPermissionContext* |
| 1821 | ChromeContentBrowserClient::CreateQuotaPermissionContext() { |
| 1822 | return new ChromeQuotaPermissionContext(); |
| 1823 | } |
| 1824 | |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 1825 | void ChromeContentBrowserClient::AllowCertificateError( |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 1826 | int render_process_id, |
[email protected] | 1a4e975 | 2013-12-31 20:10:58 | [diff] [blame] | 1827 | int render_frame_id, |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 1828 | int cert_error, |
| 1829 | const net::SSLInfo& ssl_info, |
| 1830 | const GURL& request_url, |
[email protected] | a2f7688 | 2013-02-25 21:36:02 | [diff] [blame] | 1831 | ResourceType::Type resource_type, |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 1832 | bool overridable, |
[email protected] | d9be4770 | 2012-05-16 03:41:22 | [diff] [blame] | 1833 | bool strict_enforcement, |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 1834 | const base::Callback<void(bool)>& callback, |
[email protected] | 8c965c2 | 2013-05-23 19:28:00 | [diff] [blame] | 1835 | content::CertificateRequestResultType* result) { |
[email protected] | a2f7688 | 2013-02-25 21:36:02 | [diff] [blame] | 1836 | if (resource_type != ResourceType::MAIN_FRAME) { |
| 1837 | // A sub-resource has a certificate error. The user doesn't really |
| 1838 | // have a context for making the right decision, so block the |
| 1839 | // request hard, without an info bar to allow showing the insecure |
| 1840 | // content. |
[email protected] | 8c965c2 | 2013-05-23 19:28:00 | [diff] [blame] | 1841 | *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY; |
[email protected] | a2f7688 | 2013-02-25 21:36:02 | [diff] [blame] | 1842 | return; |
| 1843 | } |
| 1844 | |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 1845 | // If the tab is being prerendered, cancel the prerender and the request. |
[email protected] | 1a4e975 | 2013-12-31 20:10:58 | [diff] [blame] | 1846 | content::RenderFrameHost* render_frame_host = |
| 1847 | content::RenderFrameHost::FromID(render_process_id, render_frame_id); |
[email protected] | 1a4e975 | 2013-12-31 20:10:58 | [diff] [blame] | 1848 | WebContents* tab = WebContents::FromRenderFrameHost(render_frame_host); |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 1849 | if (!tab) { |
| 1850 | NOTREACHED(); |
| 1851 | return; |
| 1852 | } |
[email protected] | 09667f0 | 2014-01-06 15:37:57 | [diff] [blame] | 1853 | |
| 1854 | prerender::PrerenderContents* prerender_contents = |
[email protected] | 294084d | 2014-01-06 22:22:02 | [diff] [blame] | 1855 | prerender::PrerenderContents::FromWebContents(tab); |
[email protected] | 09667f0 | 2014-01-06 15:37:57 | [diff] [blame] | 1856 | if (prerender_contents) { |
| 1857 | prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR); |
| 1858 | *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL; |
| 1859 | return; |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 1860 | } |
| 1861 | |
[email protected] | 1e87df3 | 2012-09-12 04:53:19 | [diff] [blame] | 1862 | #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
[email protected] | eb0b9dd | 2012-09-19 21:36:23 | [diff] [blame] | 1863 | captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper = |
| 1864 | captive_portal::CaptivePortalTabHelper::FromWebContents(tab); |
| 1865 | if (captive_portal_tab_helper) |
| 1866 | captive_portal_tab_helper->OnSSLCertError(ssl_info); |
[email protected] | 1e87df3 | 2012-09-12 04:53:19 | [diff] [blame] | 1867 | #endif |
| 1868 | |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 1869 | // Otherwise, display an SSL blocking page. |
[email protected] | d9be4770 | 2012-05-16 03:41:22 | [diff] [blame] | 1870 | new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable, |
| 1871 | strict_enforcement, callback); |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 1872 | } |
| 1873 | |
[email protected] | c99c442e | 2011-08-24 11:37:30 | [diff] [blame] | 1874 | void ChromeContentBrowserClient::SelectClientCertificate( |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 1875 | int render_process_id, |
[email protected] | 094c877 | 2013-12-21 17:54:50 | [diff] [blame] | 1876 | int render_frame_id, |
[email protected] | 7a593db | 2012-02-13 21:19:40 | [diff] [blame] | 1877 | const net::HttpNetworkSession* network_session, |
| 1878 | net::SSLCertRequestInfo* cert_request_info, |
| 1879 | const base::Callback<void(net::X509Certificate*)>& callback) { |
[email protected] | 094c877 | 2013-12-21 17:54:50 | [diff] [blame] | 1880 | content::RenderFrameHost* rfh = content::RenderFrameHost::FromID( |
| 1881 | render_process_id, render_frame_id); |
[email protected] | 294084d | 2014-01-06 22:22:02 | [diff] [blame] | 1882 | WebContents* tab = WebContents::FromRenderFrameHost(rfh); |
| 1883 | if (!tab) { |
[email protected] | 094c877 | 2013-12-21 17:54:50 | [diff] [blame] | 1884 | NOTREACHED(); |
| 1885 | return; |
| 1886 | } |
| 1887 | |
[email protected] | 294084d | 2014-01-06 22:22:02 | [diff] [blame] | 1888 | prerender::PrerenderContents* prerender_contents = |
| 1889 | prerender::PrerenderContents::FromWebContents(tab); |
| 1890 | if (prerender_contents) { |
| 1891 | prerender_contents->Destroy( |
| 1892 | prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 1893 | return; |
| 1894 | } |
| 1895 | |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 1896 | GURL requesting_url("https://" + cert_request_info->host_and_port.ToString()); |
| 1897 | DCHECK(requesting_url.is_valid()) |
| 1898 | << "Invalid URL string: https://" |
| 1899 | << cert_request_info->host_and_port.ToString(); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1900 | |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 1901 | Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
[email protected] | 5bcdd99d | 2013-12-23 18:28:30 | [diff] [blame] | 1902 | scoped_ptr<base::Value> filter( |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1903 | profile->GetHostContentSettingsMap()->GetWebsiteSetting( |
| 1904 | requesting_url, |
| 1905 | requesting_url, |
| 1906 | CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
| 1907 | std::string(), NULL)); |
| 1908 | |
| 1909 | if (filter.get()) { |
| 1910 | // Try to automatically select a client certificate. |
[email protected] | 5bcdd99d | 2013-12-23 18:28:30 | [diff] [blame] | 1911 | if (filter->IsType(base::Value::TYPE_DICTIONARY)) { |
| 1912 | base::DictionaryValue* filter_dict = |
| 1913 | static_cast<base::DictionaryValue*>(filter.get()); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1914 | |
| 1915 | const std::vector<scoped_refptr<net::X509Certificate> >& |
| 1916 | all_client_certs = cert_request_info->client_certs; |
| 1917 | for (size_t i = 0; i < all_client_certs.size(); ++i) { |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1918 | if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) { |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1919 | // Use the first certificate that is matched by the filter. |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1920 | callback.Run(all_client_certs[i].get()); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1921 | return; |
| 1922 | } |
| 1923 | } |
| 1924 | } else { |
| 1925 | NOTREACHED(); |
| 1926 | } |
| 1927 | } |
| 1928 | |
[email protected] | 11feec32 | 2012-09-18 03:58:52 | [diff] [blame] | 1929 | SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab); |
| 1930 | if (!ssl_tab_helper) { |
| 1931 | // If there is no SSLTabHelper for the given WebContents then we can't |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1932 | // show the user a dialog to select a client certificate. So we simply |
[email protected] | 2a349e9 | 2011-12-07 12:00:14 | [diff] [blame] | 1933 | // proceed with no client certificate. |
[email protected] | 7a593db | 2012-02-13 21:19:40 | [diff] [blame] | 1934 | callback.Run(NULL); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1935 | return; |
| 1936 | } |
[email protected] | 11feec32 | 2012-09-18 03:58:52 | [diff] [blame] | 1937 | ssl_tab_helper->ShowClientCertificateRequestDialog( |
[email protected] | 7a593db | 2012-02-13 21:19:40 | [diff] [blame] | 1938 | network_session, cert_request_info, callback); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 1939 | } |
| 1940 | |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 1941 | void ChromeContentBrowserClient::AddCertificate( |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 1942 | net::URLRequest* request, |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 1943 | net::CertificateMimeType cert_type, |
| 1944 | const void* cert_data, |
| 1945 | size_t cert_size, |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 1946 | int render_process_id, |
| 1947 | int render_view_id) { |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 1948 | chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size, |
| 1949 | render_process_id, render_view_id); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 1950 | } |
| 1951 | |
[email protected] | dc73a7b | 2012-03-25 15:27:18 | [diff] [blame] | 1952 | content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() { |
[email protected] | 11158e2d | 2013-02-01 02:31:56 | [diff] [blame] | 1953 | return MediaCaptureDevicesDispatcher::GetInstance(); |
[email protected] | dc73a7b | 2012-03-25 15:27:18 | [diff] [blame] | 1954 | } |
| 1955 | |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1956 | void ChromeContentBrowserClient::RequestDesktopNotificationPermission( |
| 1957 | const GURL& source_origin, |
| 1958 | int callback_context, |
| 1959 | int render_process_id, |
| 1960 | int render_view_id) { |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 1961 | #if defined(ENABLE_NOTIFICATIONS) |
[email protected] | d0d9c3ee | 2012-06-19 03:07:02 | [diff] [blame] | 1962 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1963 | WebContents* contents = |
| 1964 | tab_util::GetWebContentsByID(render_process_id, render_view_id); |
| 1965 | if (!contents) { |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1966 | NOTREACHED(); |
| 1967 | return; |
| 1968 | } |
| 1969 | |
[email protected] | d0d9c3ee | 2012-06-19 03:07:02 | [diff] [blame] | 1970 | // Skip showing the infobar if the request comes from an extension, and that |
| 1971 | // extension has the 'notify' permission. (If the extension does not have the |
| 1972 | // permission, the user will still be prompted.) |
| 1973 | Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 1974 | InfoMap* extension_info_map = |
[email protected] | c7cd594 | 2013-04-30 03:31:01 | [diff] [blame] | 1975 | extensions::ExtensionSystem::Get(profile)->info_map(); |
| 1976 | DesktopNotificationService* notification_service = |
| 1977 | DesktopNotificationServiceFactory::GetForProfile(profile); |
| 1978 | const Extension* extension = NULL; |
| 1979 | if (extension_info_map) { |
[email protected] | 289c44b | 2013-12-17 03:26:57 | [diff] [blame] | 1980 | extensions::ExtensionSet extensions; |
[email protected] | c7cd594 | 2013-04-30 03:31:01 | [diff] [blame] | 1981 | extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin( |
| 1982 | source_origin, render_process_id, |
| 1983 | extensions::APIPermission::kNotification, &extensions); |
[email protected] | 289c44b | 2013-12-17 03:26:57 | [diff] [blame] | 1984 | for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); |
[email protected] | c7cd594 | 2013-04-30 03:31:01 | [diff] [blame] | 1985 | iter != extensions.end(); ++iter) { |
[email protected] | 593d2a7 | 2013-07-26 08:48:38 | [diff] [blame] | 1986 | if (notification_service->IsNotifierEnabled(NotifierId( |
| 1987 | NotifierId::APPLICATION, (*iter)->id()))) { |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 1988 | extension = iter->get(); |
[email protected] | c7cd594 | 2013-04-30 03:31:01 | [diff] [blame] | 1989 | break; |
| 1990 | } |
| 1991 | } |
| 1992 | } |
[email protected] | eb4832a | 2012-12-08 01:57:52 | [diff] [blame] | 1993 | RenderViewHost* rvh = |
| 1994 | RenderViewHost::FromID(render_process_id, render_view_id); |
| 1995 | if (IsExtensionWithPermissionOrSuggestInConsole( |
| 1996 | APIPermission::kNotification, extension, rvh)) { |
[email protected] | d0d9c3ee | 2012-06-19 03:07:02 | [diff] [blame] | 1997 | if (rvh) |
| 1998 | rvh->DesktopNotificationPermissionRequestDone(callback_context); |
| 1999 | return; |
| 2000 | } |
| 2001 | |
[email protected] | c7cd594 | 2013-04-30 03:31:01 | [diff] [blame] | 2002 | notification_service->RequestPermission(source_origin, render_process_id, |
[email protected] | d0d9c3ee | 2012-06-19 03:07:02 | [diff] [blame] | 2003 | render_view_id, callback_context, contents); |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 2004 | #else |
| 2005 | NOTIMPLEMENTED(); |
| 2006 | #endif |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2007 | } |
| 2008 | |
[email protected] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 2009 | blink::WebNotificationPresenter::Permission |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2010 | ChromeContentBrowserClient::CheckDesktopNotificationPermission( |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 2011 | const GURL& source_origin, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 2012 | content::ResourceContext* context, |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 2013 | int render_process_id) { |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 2014 | #if defined(ENABLE_NOTIFICATIONS) |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2015 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 5c12979 | 2013-07-10 02:08:48 | [diff] [blame] | 2016 | |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 2017 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 2018 | InfoMap* extension_info_map = io_data->GetExtensionInfoMap(); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2019 | |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 2020 | // We want to see if there is an extension that hasn't been manually disabled |
| 2021 | // that has the notifications permission and applies to this security origin. |
| 2022 | // First, get the list of extensions with permission for the origin. |
[email protected] | 289c44b | 2013-12-17 03:26:57 | [diff] [blame] | 2023 | extensions::ExtensionSet extensions; |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 2024 | extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin( |
| 2025 | source_origin, render_process_id, |
| 2026 | extensions::APIPermission::kNotification, &extensions); |
[email protected] | 289c44b | 2013-12-17 03:26:57 | [diff] [blame] | 2027 | for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 2028 | iter != extensions.end(); ++iter) { |
| 2029 | // Then, check to see if it's been disabled by the user. |
| 2030 | if (!extension_info_map->AreNotificationsDisabled((*iter)->id())) |
| 2031 | return blink::WebNotificationPresenter::PermissionAllowed; |
[email protected] | c7cd594 | 2013-04-30 03:31:01 | [diff] [blame] | 2032 | } |
| 2033 | |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 2034 | // No enabled extensions exist, so check the normal host content settings. |
| 2035 | HostContentSettingsMap* host_content_settings_map = |
| 2036 | io_data->GetHostContentSettingsMap(); |
| 2037 | ContentSetting setting = host_content_settings_map->GetContentSetting( |
| 2038 | source_origin, |
| 2039 | source_origin, |
| 2040 | CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 2041 | NO_RESOURCE_IDENTIFIER); |
| 2042 | |
| 2043 | if (setting == CONTENT_SETTING_ALLOW) |
| 2044 | return blink::WebNotificationPresenter::PermissionAllowed; |
| 2045 | if (setting == CONTENT_SETTING_BLOCK) |
| 2046 | return blink::WebNotificationPresenter::PermissionDenied; |
[email protected] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 2047 | return blink::WebNotificationPresenter::PermissionNotAllowed; |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 2048 | #else |
[email protected] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 2049 | return blink::WebNotificationPresenter::PermissionAllowed; |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 2050 | #endif |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | void ChromeContentBrowserClient::ShowDesktopNotification( |
[email protected] | 0ee57e2 | 2011-11-12 01:59:17 | [diff] [blame] | 2054 | const content::ShowDesktopNotificationHostMsgParams& params, |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2055 | int render_process_id, |
| 2056 | int render_view_id, |
| 2057 | bool worker) { |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 2058 | #if defined(ENABLE_NOTIFICATIONS) |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2059 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 2060 | render_process_id, render_view_id); |
| 2061 | if (!rvh) { |
| 2062 | NOTREACHED(); |
| 2063 | return; |
| 2064 | } |
| 2065 | |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2066 | content::RenderProcessHost* process = rvh->GetProcess(); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2067 | Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2068 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 2069 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2070 | service->ShowDesktopNotification( |
| 2071 | params, render_process_id, render_view_id, |
| 2072 | worker ? DesktopNotificationService::WorkerNotification : |
| 2073 | DesktopNotificationService::PageNotification); |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 2074 | #else |
| 2075 | NOTIMPLEMENTED(); |
| 2076 | #endif |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | void ChromeContentBrowserClient::CancelDesktopNotification( |
| 2080 | int render_process_id, |
| 2081 | int render_view_id, |
| 2082 | int notification_id) { |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 2083 | #if defined(ENABLE_NOTIFICATIONS) |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2084 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 2085 | render_process_id, render_view_id); |
| 2086 | if (!rvh) { |
| 2087 | NOTREACHED(); |
| 2088 | return; |
| 2089 | } |
| 2090 | |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2091 | content::RenderProcessHost* process = rvh->GetProcess(); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2092 | Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2093 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 2094 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2095 | service->CancelDesktopNotification( |
| 2096 | render_process_id, render_view_id, notification_id); |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 2097 | #else |
| 2098 | NOTIMPLEMENTED(); |
| 2099 | #endif |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2100 | } |
| 2101 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2102 | bool ChromeContentBrowserClient::CanCreateWindow( |
[email protected] | 2b751a1 | 2012-03-06 03:00:35 | [diff] [blame] | 2103 | const GURL& opener_url, |
[email protected] | 931bc92 | 2013-09-11 21:42:57 | [diff] [blame] | 2104 | const GURL& opener_top_level_frame_url, |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 2105 | const GURL& source_origin, |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2106 | WindowContainerType container_type, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2107 | const GURL& target_url, |
| 2108 | const content::Referrer& referrer, |
| 2109 | WindowOpenDisposition disposition, |
| 2110 | const WebWindowFeatures& features, |
| 2111 | bool user_gesture, |
| 2112 | bool opener_suppressed, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 2113 | content::ResourceContext* context, |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2114 | int render_process_id, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2115 | bool is_guest, |
| 2116 | int opener_id, |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2117 | bool* no_javascript_access) { |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2118 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2119 | |
| 2120 | *no_javascript_access = false; |
| 2121 | |
[email protected] | 5e5f55e262c5 | 2013-09-12 00:27:19 | [diff] [blame] | 2122 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 2123 | InfoMap* map = io_data->GetExtensionInfoMap(); |
[email protected] | 5e5f55e262c5 | 2013-09-12 00:27:19 | [diff] [blame] | 2124 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2125 | // If the opener is trying to create a background window but doesn't have |
| 2126 | // the appropriate permission, fail the attempt. |
[email protected] | 6940eef8 | 2013-09-11 11:58:41 | [diff] [blame] | 2127 | if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2128 | if (!map->SecurityOriginHasAPIPermission( |
| 2129 | source_origin, |
| 2130 | render_process_id, |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2131 | APIPermission::kBackground)) { |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2132 | return false; |
| 2133 | } |
| 2134 | |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 2135 | // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may |
| 2136 | // return a recently installed Extension even if this CanCreateWindow call |
| 2137 | // was made by an old copy of the page in a normal web process. That's ok, |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2138 | // because the permission check above would have caused an early return |
| 2139 | // already. We must use the full URL to find hosted apps, though, and not |
| 2140 | // just the origin. |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 2141 | const Extension* extension = |
| 2142 | map->extensions().GetExtensionOrAppByURL(opener_url); |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 2143 | if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension)) |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2144 | *no_javascript_access = true; |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2145 | |
| 2146 | return true; |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2147 | } |
[email protected] | 056efdc | 2013-04-06 00:14:53 | [diff] [blame] | 2148 | |
| 2149 | // No new browser window (popup or tab) in app mode. |
| 2150 | if (container_type == WINDOW_CONTAINER_TYPE_NORMAL && |
| 2151 | chrome::IsRunningInForcedAppMode()) { |
| 2152 | return false; |
| 2153 | } |
| 2154 | |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2155 | if (is_guest) |
| 2156 | return true; |
| 2157 | |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2158 | HostContentSettingsMap* content_settings = |
| 2159 | ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap(); |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 2160 | BlockedWindowParams blocked_params(target_url, |
| 2161 | referrer, |
| 2162 | disposition, |
| 2163 | features, |
| 2164 | user_gesture, |
| 2165 | opener_suppressed, |
| 2166 | render_process_id, |
| 2167 | opener_id); |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2168 | |
[email protected] | 7f53dff | 2013-08-05 10:45:50 | [diff] [blame] | 2169 | if (!user_gesture && !CommandLine::ForCurrentProcess()->HasSwitch( |
| 2170 | switches::kDisablePopupBlocking)) { |
[email protected] | 931bc92 | 2013-09-11 21:42:57 | [diff] [blame] | 2171 | if (content_settings->GetContentSetting(opener_top_level_frame_url, |
| 2172 | opener_top_level_frame_url, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2173 | CONTENT_SETTINGS_TYPE_POPUPS, |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 2174 | std::string()) != |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2175 | CONTENT_SETTING_ALLOW) { |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 2176 | BrowserThread::PostTask(BrowserThread::UI, |
| 2177 | FROM_HERE, |
| 2178 | base::Bind(&HandleBlockedPopupOnUIThread, |
| 2179 | blocked_params)); |
| 2180 | return false; |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2181 | } |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 2182 | } |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2183 | |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 2184 | #if defined(OS_ANDROID) |
| 2185 | if (SingleTabModeTabHelper::IsRegistered(render_process_id, opener_id)) { |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2186 | BrowserThread::PostTask(BrowserThread::UI, |
| 2187 | FROM_HERE, |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 2188 | base::Bind(&HandleSingleTabModeBlockOnUIThread, |
| 2189 | blocked_params)); |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2190 | return false; |
| 2191 | } |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 2192 | #endif |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2193 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2194 | return true; |
| 2195 | } |
| 2196 | |
| 2197 | std::string ChromeContentBrowserClient::GetWorkerProcessTitle( |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 2198 | const GURL& url, content::ResourceContext* context) { |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2199 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2200 | // Check if it's an extension-created worker, in which case we want to use |
| 2201 | // the name of the extension. |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 2202 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2203 | const Extension* extension = |
| 2204 | io_data->GetExtensionInfoMap()->extensions().GetByID(url.host()); |
| 2205 | return extension ? extension->name() : std::string(); |
| 2206 | } |
| 2207 | |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 2208 | void ChromeContentBrowserClient::ResourceDispatcherHostCreated() { |
| 2209 | return g_browser_process->ResourceDispatcherHostCreated(); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 2210 | } |
| 2211 | |
[email protected] | 7a06d28 | 2013-05-03 04:39:33 | [diff] [blame] | 2212 | // TODO(tommi): Rename from Get to Create. |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 2213 | content::SpeechRecognitionManagerDelegate* |
| 2214 | ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() { |
[email protected] | 855e18b | 2013-07-08 21:02:00 | [diff] [blame] | 2215 | #if defined(ENABLE_INPUT_SPEECH) |
| 2216 | return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI(); |
[email protected] | a03f2d3 | 2012-03-14 00:26:32 | [diff] [blame] | 2217 | #else |
[email protected] | 855e18b | 2013-07-08 21:02:00 | [diff] [blame] | 2218 | // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just |
| 2219 | // need the base delegate without the bubble UI. |
| 2220 | return new speech::ChromeSpeechRecognitionManagerDelegate(); |
[email protected] | a03f2d3 | 2012-03-14 00:26:32 | [diff] [blame] | 2221 | #endif |
[email protected] | 66cfec6 | 2012-02-24 17:57:51 | [diff] [blame] | 2222 | } |
| 2223 | |
[email protected] | ae6e991 | 2011-07-27 01:18:28 | [diff] [blame] | 2224 | net::NetLog* ChromeContentBrowserClient::GetNetLog() { |
| 2225 | return g_browser_process->net_log(); |
| 2226 | } |
| 2227 | |
[email protected] | 32538d9 | 2011-08-25 00:09:23 | [diff] [blame] | 2228 | AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() { |
| 2229 | return new ChromeAccessTokenStore(); |
| 2230 | } |
| 2231 | |
[email protected] | dbae6b0 | 2011-06-29 23:51:41 | [diff] [blame] | 2232 | bool ChromeContentBrowserClient::IsFastShutdownPossible() { |
[email protected] | 263ff4f | 2013-01-04 20:23:01 | [diff] [blame] | 2233 | return true; |
[email protected] | dbae6b0 | 2011-06-29 23:51:41 | [diff] [blame] | 2234 | } |
| 2235 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2236 | void ChromeContentBrowserClient::OverrideWebkitPrefs( |
[email protected] | 2e21fe29 | 2012-03-02 22:52:32 | [diff] [blame] | 2237 | RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2238 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2239 | rvh->GetProcess()->GetBrowserContext()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2240 | PrefService* prefs = profile->GetPrefs(); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2241 | |
[email protected] | 33b7954 | 2013-10-18 11:18:45 | [diff] [blame] | 2242 | // Fill per-script font preferences. These are not registered on Android |
| 2243 | // - http://crbug.com/308033. |
| 2244 | #if !defined(OS_ANDROID) |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2245 | FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2246 | &web_prefs->standard_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2247 | FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2248 | &web_prefs->fixed_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2249 | FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2250 | &web_prefs->serif_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2251 | FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2252 | &web_prefs->sans_serif_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2253 | FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2254 | &web_prefs->cursive_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2255 | FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2256 | &web_prefs->fantasy_font_family_map); |
[email protected] | 85edc23 | 2012-10-05 08:56:03 | [diff] [blame] | 2257 | FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap, |
| 2258 | &web_prefs->pictograph_font_family_map); |
[email protected] | 33b7954 | 2013-10-18 11:18:45 | [diff] [blame] | 2259 | #endif |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2260 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2261 | web_prefs->default_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2262 | prefs->GetInteger(prefs::kWebKitDefaultFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2263 | web_prefs->default_fixed_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2264 | prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2265 | web_prefs->minimum_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2266 | prefs->GetInteger(prefs::kWebKitMinimumFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2267 | web_prefs->minimum_logical_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2268 | prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2269 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2270 | web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2271 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2272 | web_prefs->javascript_can_open_windows_automatically = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2273 | prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2274 | web_prefs->dom_paste_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2275 | prefs->GetBoolean(prefs::kWebKitDomPasteEnabled); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2276 | web_prefs->shrinks_standalone_images_to_fit = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2277 | prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit); |
[email protected] | 5bcdd99d | 2013-12-23 18:28:30 | [diff] [blame] | 2278 | const base::DictionaryValue* inspector_settings = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2279 | prefs->GetDictionary(prefs::kWebKitInspectorSettings); |
| 2280 | if (inspector_settings) { |
[email protected] | 5bcdd99d | 2013-12-23 18:28:30 | [diff] [blame] | 2281 | for (base::DictionaryValue::Iterator iter(*inspector_settings); |
| 2282 | !iter.IsAtEnd(); |
[email protected] | c40ef1c | 2013-02-25 18:42:18 | [diff] [blame] | 2283 | iter.Advance()) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2284 | std::string value; |
[email protected] | c40ef1c | 2013-02-25 18:42:18 | [diff] [blame] | 2285 | if (iter.value().GetAsString(&value)) { |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2286 | web_prefs->inspector_settings.push_back( |
[email protected] | c40ef1c | 2013-02-25 18:42:18 | [diff] [blame] | 2287 | std::make_pair(iter.key(), value)); |
| 2288 | } |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2289 | } |
| 2290 | } |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2291 | web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2292 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2293 | if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2294 | web_prefs->javascript_enabled = false; |
| 2295 | if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled)) |
| 2296 | web_prefs->web_security_enabled = false; |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2297 | if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2298 | web_prefs->plugins_enabled = false; |
| 2299 | if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled)) |
| 2300 | web_prefs->java_enabled = false; |
| 2301 | web_prefs->loads_images_automatically = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2302 | prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2303 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2304 | if (prefs->GetBoolean(prefs::kDisable3DAPIs)) |
| 2305 | web_prefs->experimental_webgl_enabled = false; |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2306 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2307 | web_prefs->allow_displaying_insecure_content = |
| 2308 | prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent); |
| 2309 | web_prefs->allow_running_insecure_content = |
| 2310 | prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent); |
[email protected] | d3b935f | 2012-10-19 23:14:32 | [diff] [blame] | 2311 | #if defined(OS_ANDROID) |
[email protected] | ded00dc | 2013-11-01 00:37:05 | [diff] [blame] | 2312 | web_prefs->font_scale_factor = |
| 2313 | static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor)); |
| 2314 | web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment(); |
[email protected] | d3b935f | 2012-10-19 23:14:32 | [diff] [blame] | 2315 | web_prefs->force_enable_zoom = |
| 2316 | prefs->GetBoolean(prefs::kWebKitForceEnableZoom); |
| 2317 | #endif |
[email protected] | 5c91525 | 2013-05-07 13:15:39 | [diff] [blame] | 2318 | |
[email protected] | af4256d5 | 2013-06-04 20:39:07 | [diff] [blame] | 2319 | #if defined(OS_ANDROID) |
| 2320 | web_prefs->password_echo_enabled = |
| 2321 | prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled); |
| 2322 | #else |
[email protected] | 9d06d88d | 2012-02-23 22:37:08 | [diff] [blame] | 2323 | web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled; |
[email protected] | af4256d5 | 2013-06-04 20:39:07 | [diff] [blame] | 2324 | #endif |
| 2325 | |
[email protected] | cfadadd | 2013-04-03 04:43:02 | [diff] [blame] | 2326 | web_prefs->asynchronous_spell_checking_enabled = true; |
| 2327 | web_prefs->unified_textchecker_enabled = true; |
[email protected] | dd5d0fb | 2012-01-18 03:37:57 | [diff] [blame] | 2328 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2329 | web_prefs->uses_universal_detector = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2330 | prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2331 | web_prefs->text_areas_are_resizable = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2332 | prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2333 | web_prefs->hyperlink_auditing_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2334 | prefs->GetBoolean(prefs::kEnableHyperlinkAuditing); |
| 2335 | |
| 2336 | // Make sure we will set the default_encoding with canonical encoding name. |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2337 | web_prefs->default_encoding = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2338 | CharacterEncoding::GetCanonicalEncodingNameByAliasName( |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2339 | web_prefs->default_encoding); |
| 2340 | if (web_prefs->default_encoding.empty()) { |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2341 | prefs->ClearPref(prefs::kDefaultCharset); |
| 2342 | web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2343 | } |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2344 | DCHECK(!web_prefs->default_encoding.empty()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2345 | |
[email protected] | 299d7f1 | 2012-05-23 05:31:15 | [diff] [blame] | 2346 | WebContents* web_contents = WebContents::FromRenderViewHost(rvh); |
[email protected] | cb2edf2 | 2013-04-01 20:25:23 | [diff] [blame] | 2347 | extensions::ViewType view_type = extensions::GetViewType(web_contents); |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 2348 | ExtensionService* service = |
| 2349 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2350 | if (service) { |
[email protected] | 1e6e2ea | 2014-01-04 02:01:40 | [diff] [blame] | 2351 | const GURL& site_url = rvh->GetSiteInstance()->GetSiteURL(); |
| 2352 | const Extension* extension = |
| 2353 | service->extensions()->GetByID(site_url.host()); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 2354 | // Ensure that we are only granting extension preferences to URLs with |
| 2355 | // the correct scheme. Without this check, chrome-guest:// schemes used by |
| 2356 | // webview tags as well as hosts that happen to match the id of an |
| 2357 | // installed extension would get the wrong preferences. |
[email protected] | 1e6e2ea | 2014-01-04 02:01:40 | [diff] [blame] | 2358 | if (site_url.SchemeIs(extensions::kExtensionScheme)) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 2359 | extension_webkit_preferences::SetPreferences( |
| 2360 | extension, view_type, web_prefs); |
| 2361 | } |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2362 | } |
| 2363 | |
[email protected] | cb2edf2 | 2013-04-01 20:25:23 | [diff] [blame] | 2364 | if (view_type == extensions::VIEW_TYPE_NOTIFICATION) { |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2365 | web_prefs->allow_scripts_to_close_windows = true; |
[email protected] | cb2edf2 | 2013-04-01 20:25:23 | [diff] [blame] | 2366 | } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2367 | // Disable all kinds of acceleration for background pages. |
| 2368 | // See http://crbug.com/96005 and http://crbug.com/96006 |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2369 | web_prefs->force_compositing_mode = false; |
| 2370 | web_prefs->accelerated_compositing_enabled = false; |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2371 | } |
[email protected] | 2e21fe29 | 2012-03-02 22:52:32 | [diff] [blame] | 2372 | |
[email protected] | ff930087 | 2014-01-22 11:09:32 | [diff] [blame] | 2373 | #if defined(OS_CHROMEOS) |
[email protected] | 2e21fe29 | 2012-03-02 22:52:32 | [diff] [blame] | 2374 | // Override the default of suppressing HW compositing for WebUI pages for the |
| 2375 | // file manager, which is implemented using WebUI but wants HW acceleration |
| 2376 | // for video decode & render. |
[email protected] | 02a3dc12 | 2013-06-13 15:07:53 | [diff] [blame] | 2377 | if (url.SchemeIs(extensions::kExtensionScheme) && |
[email protected] | 2de96a5 | 2013-08-14 01:18:09 | [diff] [blame] | 2378 | url.host() == file_manager::kFileManagerAppId) { |
[email protected] | 2e21fe29 | 2012-03-02 22:52:32 | [diff] [blame] | 2379 | web_prefs->accelerated_compositing_enabled = true; |
| 2380 | web_prefs->accelerated_2d_canvas_enabled = true; |
| 2381 | } |
| 2382 | #endif |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | void ChromeContentBrowserClient::UpdateInspectorSetting( |
| 2386 | RenderViewHost* rvh, const std::string& key, const std::string& value) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2387 | content::BrowserContext* browser_context = |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2388 | rvh->GetProcess()->GetBrowserContext(); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2389 | DictionaryPrefUpdate update( |
| 2390 | Profile::FromBrowserContext(browser_context)->GetPrefs(), |
| 2391 | prefs::kWebKitInspectorSettings); |
[email protected] | 5bcdd99d | 2013-12-23 18:28:30 | [diff] [blame] | 2392 | base::DictionaryValue* inspector_settings = update.Get(); |
| 2393 | inspector_settings->SetWithoutPathExpansion( |
| 2394 | key, base::Value::CreateStringValue(value)); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 2395 | } |
| 2396 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 2397 | void ChromeContentBrowserClient::BrowserURLHandlerCreated( |
| 2398 | BrowserURLHandler* handler) { |
| 2399 | // Add the default URL handlers. |
| 2400 | handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride, |
| 2401 | BrowserURLHandler::null_handler()); |
| 2402 | handler->AddHandlerPair(BrowserURLHandler::null_handler(), |
| 2403 | &ExtensionWebUI::HandleChromeURLOverrideReverse); |
| 2404 | |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 2405 | // about: handler. Must come before chrome: handler, since it will |
| 2406 | // rewrite about: urls to chrome: URLs and then expect chrome: to |
| 2407 | // actually handle them. |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 2408 | handler->AddHandlerPair(&WillHandleBrowserAboutURL, |
| 2409 | BrowserURLHandler::null_handler()); |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 2410 | |
[email protected] | 4bd78e9 | 2014-03-28 18:54:03 | [diff] [blame] | 2411 | #if defined(OS_ANDROID) |
| 2412 | // Handler to rewrite chrome://newtab on Android. |
| 2413 | handler->AddHandlerPair(&chrome::android::HandleAndroidNewTabURL, |
| 2414 | BrowserURLHandler::null_handler()); |
| 2415 | #else |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 2416 | // Handler to rewrite chrome://newtab for InstantExtended. |
| 2417 | handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite, |
| 2418 | &chrome::HandleNewTabURLReverseRewrite); |
[email protected] | 4bd78e9 | 2014-03-28 18:54:03 | [diff] [blame] | 2419 | #endif |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 2420 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 2421 | // chrome: & friends. |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 2422 | handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 2426 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2427 | rvh->GetSiteInstance()->GetProcess()->GetBrowserContext()); |
[email protected] | 38b892b4 | 2012-09-04 13:25:47 | [diff] [blame] | 2428 | BrowsingDataRemover* remover = |
| 2429 | BrowsingDataRemover::CreateForUnboundedRange(profile); |
[email protected] | 3d4d4cf | 2012-06-04 10:40:55 | [diff] [blame] | 2430 | remover->Remove(BrowsingDataRemover::REMOVE_CACHE, |
| 2431 | BrowsingDataHelper::UNPROTECTED_WEB); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 2432 | // BrowsingDataRemover takes care of deleting itself when done. |
| 2433 | } |
| 2434 | |
| 2435 | void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 2436 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2437 | rvh->GetSiteInstance()->GetProcess()->GetBrowserContext()); |
[email protected] | 38b892b4 | 2012-09-04 13:25:47 | [diff] [blame] | 2438 | BrowsingDataRemover* remover = |
| 2439 | BrowsingDataRemover::CreateForUnboundedRange(profile); |
[email protected] | dceaa91 | 2011-09-06 17:17:23 | [diff] [blame] | 2440 | int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA; |
[email protected] | 3d4d4cf | 2012-06-04 10:40:55 | [diff] [blame] | 2441 | remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 2442 | // BrowsingDataRemover takes care of deleting itself when done. |
| 2443 | } |
| 2444 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2445 | base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { |
[email protected] | b1d9727 | 2013-08-17 13:38:49 | [diff] [blame] | 2446 | return DownloadPrefs::GetDefaultDownloadDirectory(); |
[email protected] | e1d16eb9 | 2011-08-18 23:19:32 | [diff] [blame] | 2447 | } |
| 2448 | |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 2449 | std::string ChromeContentBrowserClient::GetDefaultDownloadName() { |
| 2450 | return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); |
| 2451 | } |
| 2452 | |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 2453 | void ChromeContentBrowserClient::DidCreatePpapiPlugin( |
| 2454 | content::BrowserPpapiHost* browser_host) { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 2455 | #if defined(ENABLE_PLUGINS) |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 2456 | browser_host->GetPpapiHost()->AddHostFactoryFilter( |
| 2457 | scoped_ptr<ppapi::host::HostFactory>( |
| 2458 | new ChromeBrowserPepperHostFactory(browser_host))); |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 2459 | #endif |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 2460 | } |
| 2461 | |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 2462 | content::BrowserPpapiHost* |
| 2463 | ChromeContentBrowserClient::GetExternalBrowserPpapiHost( |
| 2464 | int plugin_process_id) { |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 2465 | BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER); |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 2466 | while (!iter.Done()) { |
[email protected] | 7c766e9 | 2013-11-22 20:44:02 | [diff] [blame] | 2467 | nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>( |
| 2468 | iter.GetDelegate()); |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 2469 | if (host->process() && |
| 2470 | host->process()->GetData().id == plugin_process_id) { |
| 2471 | // Found the plugin. |
| 2472 | return host->browser_ppapi_host(); |
| 2473 | } |
| 2474 | ++iter; |
| 2475 | } |
| 2476 | return NULL; |
| 2477 | } |
| 2478 | |
[email protected] | 7b38b19 | 2013-03-23 18:39:31 | [diff] [blame] | 2479 | bool ChromeContentBrowserClient::SupportsBrowserPlugin( |
| 2480 | content::BrowserContext* browser_context, const GURL& site_url) { |
| 2481 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2482 | switches::kEnableBrowserPluginForAllViewTypes)) |
| 2483 | return true; |
| 2484 | |
[email protected] | 22aa4f8 | 2013-09-24 17:01:44 | [diff] [blame] | 2485 | if (content::HasWebUIScheme(site_url)) |
| 2486 | return true; |
| 2487 | |
[email protected] | 7b38b19 | 2013-03-23 18:39:31 | [diff] [blame] | 2488 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2489 | ExtensionService* service = |
| 2490 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 2491 | if (!service) |
| 2492 | return false; |
| 2493 | |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 2494 | const Extension* extension = |
| 2495 | service->extensions()->GetExtensionOrAppByURL(site_url); |
[email protected] | 7b38b19 | 2013-03-23 18:39:31 | [diff] [blame] | 2496 | if (!extension) |
| 2497 | return false; |
| 2498 | |
[email protected] | c2d2f10 | 2013-04-29 16:42:58 | [diff] [blame] | 2499 | return extension->HasAPIPermission(APIPermission::kWebView) || |
| 2500 | extension->HasAPIPermission(APIPermission::kAdView); |
[email protected] | 7b38b19 | 2013-03-23 18:39:31 | [diff] [blame] | 2501 | } |
| 2502 | |
[email protected] | 38cd8f7f | 2012-06-15 22:06:07 | [diff] [blame] | 2503 | bool ChromeContentBrowserClient::AllowPepperSocketAPI( |
[email protected] | 157cc90 | 2012-11-02 06:31:58 | [diff] [blame] | 2504 | content::BrowserContext* browser_context, |
| 2505 | const GURL& url, |
[email protected] | dda5482 | 2013-06-15 01:26:39 | [diff] [blame] | 2506 | bool private_api, |
[email protected] | 8b92ed18 | 2013-09-21 04:47:12 | [diff] [blame] | 2507 | const content::SocketPermissionRequest* params) { |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 2508 | #if defined(ENABLE_PLUGINS) |
[email protected] | 9d45049 | 2013-06-13 23:08:37 | [diff] [blame] | 2509 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | 289c44b | 2013-12-17 03:26:57 | [diff] [blame] | 2510 | const extensions::ExtensionSet* extension_set = NULL; |
[email protected] | 9d45049 | 2013-06-13 23:08:37 | [diff] [blame] | 2511 | if (profile) { |
| 2512 | extension_set = extensions::ExtensionSystem::Get(profile)-> |
| 2513 | extension_service()->extensions(); |
| 2514 | } |
[email protected] | dda5482 | 2013-06-15 01:26:39 | [diff] [blame] | 2515 | |
| 2516 | if (private_api) { |
| 2517 | // Access to private socket APIs is controlled by the whitelist. |
| 2518 | if (IsExtensionOrSharedModuleWhitelisted(url, extension_set, |
| 2519 | allowed_socket_origins_)) { |
| 2520 | return true; |
| 2521 | } |
| 2522 | } else { |
| 2523 | // Access to public socket APIs is controlled by extension permissions. |
| 2524 | if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) && |
| 2525 | extension_set) { |
| 2526 | const Extension* extension = extension_set->GetByID(url.host()); |
| 2527 | if (extension) { |
[email protected] | 8b92ed18 | 2013-09-21 04:47:12 | [diff] [blame] | 2528 | if (params) { |
| 2529 | extensions::SocketPermission::CheckParam check_params( |
| 2530 | params->type, params->host, params->port); |
| 2531 | if (extensions::PermissionsData::CheckAPIPermissionWithParam( |
| 2532 | extension, extensions::APIPermission::kSocket, |
| 2533 | &check_params)) { |
| 2534 | return true; |
| 2535 | } |
| 2536 | } else { |
| 2537 | if (extensions::PermissionsData::HasAPIPermission( |
| 2538 | extension, extensions::APIPermission::kSocket)) { |
| 2539 | return true; |
| 2540 | } |
[email protected] | dda5482 | 2013-06-15 01:26:39 | [diff] [blame] | 2541 | } |
| 2542 | } |
| 2543 | } |
| 2544 | } |
| 2545 | |
| 2546 | // Allow both public and private APIs if the command line says so. |
| 2547 | return IsHostAllowedByCommandLine(url, extension_set, |
| 2548 | switches::kAllowNaClSocketAPI); |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 2549 | #else |
[email protected] | a658d45 | 2012-03-02 12:45:29 | [diff] [blame] | 2550 | return false; |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 2551 | #endif |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 2552 | } |
| 2553 | |
[email protected] | a28e330 | 2013-02-03 03:50:43 | [diff] [blame] | 2554 | ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy( |
| 2555 | WebContents* web_contents) { |
| 2556 | return new ChromeSelectFilePolicy(web_contents); |
| 2557 | } |
| 2558 | |
[email protected] | 7d942470 | 2013-04-14 13:14:16 | [diff] [blame] | 2559 | void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 2560 | std::vector<std::string>* additional_allowed_schemes) { |
| 2561 | ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 2562 | additional_allowed_schemes); |
[email protected] | b3690f7 | 2014-02-17 00:32:48 | [diff] [blame] | 2563 | additional_allowed_schemes->push_back(content::kChromeDevToolsScheme); |
[email protected] | 2d9748b2 | 2014-02-11 00:17:29 | [diff] [blame] | 2564 | additional_allowed_schemes->push_back(content::kChromeUIScheme); |
[email protected] | 7d942470 | 2013-04-14 13:14:16 | [diff] [blame] | 2565 | additional_allowed_schemes->push_back(extensions::kExtensionScheme); |
| 2566 | } |
| 2567 | |
[email protected] | c79859b8 | 2014-03-20 22:43:55 | [diff] [blame] | 2568 | void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers( |
| 2569 | std::vector<fileapi::URLRequestAutoMountHandler>* handlers) { |
[email protected] | 65486ad | 2014-03-28 21:06:48 | [diff] [blame] | 2570 | #if !defined(OS_ANDROID) |
| 2571 | handlers->push_back( |
| 2572 | base::Bind(MediaFileSystemBackend::AttemptAutoMountForURLRequest)); |
| 2573 | #endif // OS_ANDROID |
[email protected] | c79859b8 | 2014-03-20 22:43:55 | [diff] [blame] | 2574 | } |
| 2575 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 2576 | void ChromeContentBrowserClient::GetAdditionalFileSystemBackends( |
[email protected] | 0ff5eb5 | 2013-07-10 20:35:31 | [diff] [blame] | 2577 | content::BrowserContext* browser_context, |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 2578 | const base::FilePath& storage_partition_path, |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 2579 | ScopedVector<fileapi::FileSystemBackend>* additional_backends) { |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 2580 | #if !defined(OS_ANDROID) |
[email protected] | 30a306f4 | 2013-06-10 03:09:03 | [diff] [blame] | 2581 | base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 2582 | additional_backends->push_back(new MediaFileSystemBackend( |
[email protected] | 30a306f4 | 2013-06-10 03:09:03 | [diff] [blame] | 2583 | storage_partition_path, |
| 2584 | pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken( |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 2585 | MediaFileSystemBackend::kMediaTaskRunnerName)).get())); |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 2586 | #endif |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 2587 | #if defined(OS_CHROMEOS) |
[email protected] | 0ff5eb5 | 2013-07-10 20:35:31 | [diff] [blame] | 2588 | fileapi::ExternalMountPoints* external_mount_points = |
| 2589 | content::BrowserContext::GetMountPoints(browser_context); |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 2590 | DCHECK(external_mount_points); |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 2591 | chromeos::FileSystemBackend* backend = |
| 2592 | new chromeos::FileSystemBackend( |
[email protected] | 6b154b3c | 2014-02-05 08:27:29 | [diff] [blame] | 2593 | new drive::FileSystemBackendDelegate, |
[email protected] | 0ff5eb5 | 2013-07-10 20:35:31 | [diff] [blame] | 2594 | browser_context->GetSpecialStoragePolicy(), |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 2595 | external_mount_points, |
| 2596 | fileapi::ExternalMountPoints::GetSystemInstance()); |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 2597 | backend->AddSystemMountPoints(); |
| 2598 | DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal)); |
| 2599 | additional_backends->push_back(backend); |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 2600 | #endif |
[email protected] | 445b7db | 2013-08-02 04:58:27 | [diff] [blame] | 2601 | |
[email protected] | e86e2be | 2013-08-30 11:20:39 | [diff] [blame] | 2602 | additional_backends->push_back( |
| 2603 | new sync_file_system::SyncFileSystemBackend( |
| 2604 | Profile::FromBrowserContext(browser_context))); |
[email protected] | eab6105d | 2014-01-17 20:55:10 | [diff] [blame] | 2605 | |
[email protected] | 2188c8d | 2014-03-21 00:58:56 | [diff] [blame] | 2606 | #if defined(ENABLE_SERVICE_DISCOVERY) |
[email protected] | eab6105d | 2014-01-17 20:55:10 | [diff] [blame] | 2607 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2608 | switches::kEnablePrivetStorage)) { |
| 2609 | additional_backends->push_back( |
| 2610 | new local_discovery::PrivetFileSystemBackend( |
[email protected] | 7e503f9 | 2014-02-19 02:35:51 | [diff] [blame] | 2611 | fileapi::ExternalMountPoints::GetSystemInstance(), |
| 2612 | browser_context)); |
[email protected] | eab6105d | 2014-01-17 20:55:10 | [diff] [blame] | 2613 | } |
[email protected] | 7e503f9 | 2014-02-19 02:35:51 | [diff] [blame] | 2614 | #endif |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 2615 | } |
| 2616 | |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 2617 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 2618 | void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
| 2619 | const CommandLine& command_line, |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 2620 | int child_process_id, |
[email protected] | c7abd42 | 2012-09-25 00:20:08 | [diff] [blame] | 2621 | std::vector<FileDescriptorInfo>* mappings) { |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 2622 | #if defined(OS_ANDROID) |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2623 | base::FilePath data_path; |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 2624 | PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path); |
| 2625 | DCHECK(!data_path.empty()); |
| 2626 | |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 2627 | int flags = base::File::FLAG_OPEN | base::File::FLAG_READ; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2628 | base::FilePath chrome_resources_pak = |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 2629 | data_path.AppendASCII("chrome_100_percent.pak"); |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 2630 | base::File file(chrome_resources_pak, flags); |
| 2631 | DCHECK(file.IsValid()); |
[email protected] | 7359238 | 2013-01-18 19:22:37 | [diff] [blame] | 2632 | mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor, |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 2633 | FileDescriptor(file.Pass()))); |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 2634 | |
| 2635 | const std::string locale = GetApplicationLocale(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2636 | base::FilePath locale_pak = ResourceBundle::GetSharedInstance(). |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 2637 | GetLocaleFilePath(locale, false); |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 2638 | file.Initialize(locale_pak, flags); |
| 2639 | DCHECK(file.IsValid()); |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 2640 | mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor, |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 2641 | FileDescriptor(file.Pass()))); |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 2642 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2643 | base::FilePath resources_pack_path; |
[email protected] | 7359238 | 2013-01-18 19:22:37 | [diff] [blame] | 2644 | PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 2645 | file.Initialize(resources_pack_path, flags); |
| 2646 | DCHECK(file.IsValid()); |
[email protected] | 7359238 | 2013-01-18 19:22:37 | [diff] [blame] | 2647 | mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor, |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 2648 | FileDescriptor(file.Pass()))); |
[email protected] | 7359238 | 2013-01-18 19:22:37 | [diff] [blame] | 2649 | |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 2650 | if (breakpad::IsCrashReporterEnabled()) { |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 2651 | file = breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile( |
| 2652 | child_process_id); |
| 2653 | if (file.IsValid()) { |
| 2654 | mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor, |
| 2655 | FileDescriptor(file.Pass()))); |
| 2656 | } else { |
[email protected] | 82174aa | 2013-01-22 21:53:43 | [diff] [blame] | 2657 | LOG(ERROR) << "Failed to create file for minidump, crash reporting will " |
| 2658 | "be disabled for this process."; |
[email protected] | 82174aa | 2013-01-22 21:53:43 | [diff] [blame] | 2659 | } |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 2660 | } |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 2661 | |
| 2662 | #else |
| 2663 | int crash_signal_fd = GetCrashSignalFD(command_line); |
| 2664 | if (crash_signal_fd >= 0) { |
| 2665 | mappings->push_back(FileDescriptorInfo(kCrashDumpSignal, |
| 2666 | FileDescriptor(crash_signal_fd, |
| 2667 | false))); |
| 2668 | } |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 2669 | #endif // defined(OS_ANDROID) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2670 | } |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 2671 | #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2672 | |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 2673 | #if defined(OS_WIN) |
| 2674 | const wchar_t* ChromeContentBrowserClient::GetResourceDllName() { |
| 2675 | return chrome::kBrowserResourcesDll; |
| 2676 | } |
[email protected] | 34f4868 | 2013-03-20 00:30:18 | [diff] [blame] | 2677 | |
| 2678 | void ChromeContentBrowserClient::PreSpawnRenderer( |
| 2679 | sandbox::TargetPolicy* policy, |
| 2680 | bool* success) { |
| 2681 | // This code is duplicated in nacl_exe_win_64.cc. |
| 2682 | // Allow the server side of a pipe restricted to the "chrome.nacl." |
| 2683 | // namespace so that it cannot impersonate other system or other chrome |
| 2684 | // service pipes. |
| 2685 | sandbox::ResultCode result = policy->AddRule( |
| 2686 | sandbox::TargetPolicy::SUBSYS_NAMED_PIPES, |
| 2687 | sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY, |
| 2688 | L"\\\\.\\pipe\\chrome.nacl.*"); |
| 2689 | if (result != sandbox::SBOX_ALL_OK) { |
| 2690 | *success = false; |
| 2691 | return; |
| 2692 | } |
| 2693 | |
| 2694 | // Renderers need to send named pipe handles and shared memory |
| 2695 | // segment handles to NaCl loader processes. |
| 2696 | result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES, |
| 2697 | sandbox::TargetPolicy::HANDLES_DUP_ANY, |
| 2698 | L"File"); |
| 2699 | if (result != sandbox::SBOX_ALL_OK) { |
| 2700 | *success = false; |
| 2701 | return; |
| 2702 | } |
| 2703 | } |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 2704 | #endif |
| 2705 | |
[email protected] | a6868c2 | 2013-10-09 02:50:29 | [diff] [blame] | 2706 | bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle( |
| 2707 | content::BrowserContext* browser_context, |
| 2708 | const GURL& url) { |
| 2709 | #if defined(ENABLE_PLUGINS) |
| 2710 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | 289c44b | 2013-12-17 03:26:57 | [diff] [blame] | 2711 | const extensions::ExtensionSet* extension_set = NULL; |
[email protected] | a6868c2 | 2013-10-09 02:50:29 | [diff] [blame] | 2712 | if (profile) { |
| 2713 | extension_set = extensions::ExtensionSystem::Get(profile)-> |
| 2714 | extension_service()->extensions(); |
| 2715 | } |
| 2716 | // TODO(teravest): Populate allowed_file_handle_origins_ when FileIO is moved |
| 2717 | // from the renderer to the browser. |
| 2718 | return IsExtensionOrSharedModuleWhitelisted(url, extension_set, |
| 2719 | allowed_file_handle_origins_) || |
| 2720 | IsHostAllowedByCommandLine(url, extension_set, |
| 2721 | switches::kAllowNaClFileHandleAPI); |
| 2722 | #else |
| 2723 | return false; |
| 2724 | #endif |
| 2725 | } |
| 2726 | |
[email protected] | 8ddc6b7c | 2013-12-12 20:42:06 | [diff] [blame] | 2727 | bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs() { |
| 2728 | #if defined(ENABLE_PLUGINS) |
| 2729 | // Allow access for tests. |
| 2730 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2731 | switches::kEnablePepperTesting)) { |
| 2732 | return true; |
| 2733 | } |
| 2734 | |
| 2735 | chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); |
[email protected] | 5abe3e7 | 2013-12-19 18:58:54 | [diff] [blame] | 2736 | // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown" |
| 2737 | // releases of Chrome. Permitting "Unknown" allows these APIs to be used on |
| 2738 | // Chromium builds as well. |
[email protected] | 8ddc6b7c | 2013-12-12 20:42:06 | [diff] [blame] | 2739 | return channel <= chrome::VersionInfo::CHANNEL_DEV; |
| 2740 | #else |
| 2741 | return false; |
| 2742 | #endif |
| 2743 | } |
| 2744 | |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 2745 | #if defined(ENABLE_WEBRTC) |
| 2746 | void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch( |
| 2747 | CommandLine* to_command_line, |
| 2748 | const CommandLine& from_command_line, |
| 2749 | VersionInfo::Channel channel) { |
| 2750 | #if defined(OS_ANDROID) |
| 2751 | const VersionInfo::Channel kMaxDisableEncryptionChannel = |
| 2752 | VersionInfo::CHANNEL_BETA; |
| 2753 | #else |
| 2754 | const VersionInfo::Channel kMaxDisableEncryptionChannel = |
| 2755 | VersionInfo::CHANNEL_DEV; |
| 2756 | #endif |
| 2757 | if (channel <= kMaxDisableEncryptionChannel) { |
| 2758 | static const char* const kWebRtcDevSwitchNames[] = { |
| 2759 | switches::kDisableWebRtcEncryption, |
| 2760 | }; |
| 2761 | to_command_line->CopySwitchesFrom(from_command_line, |
| 2762 | kWebRtcDevSwitchNames, |
| 2763 | arraysize(kWebRtcDevSwitchNames)); |
| 2764 | } |
| 2765 | } |
| 2766 | #endif // defined(ENABLE_WEBRTC) |
[email protected] | 8ddc6b7c | 2013-12-12 20:42:06 | [diff] [blame] | 2767 | |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 2768 | } // namespace chrome |