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