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