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