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