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