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