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