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