[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] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 13 | #include "base/lazy_instance.h" |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 14 | #include "base/path_service.h" |
[email protected] | 3853a4c | 2013-02-11 17:15:57 | [diff] [blame] | 15 | #include "base/prefs/pref_service.h" |
[email protected] | 9eec53fe | 2013-10-30 20:21:17 | [diff] [blame] | 16 | #include "base/prefs/scoped_user_pref_update.h" |
[email protected] | e746341 | 2013-06-10 22:53:46 | [diff] [blame] | 17 | #include "base/strings/string_number_conversions.h" |
[email protected] | 135cb80 | 2013-06-09 16:44:20 | [diff] [blame] | 18 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 30a306f4 | 2013-06-10 03:09:03 | [diff] [blame] | 19 | #include "base/threading/sequenced_worker_pool.h" |
[email protected] | 056efdc | 2013-04-06 00:14:53 | [diff] [blame] | 20 | #include "chrome/browser/app_mode/app_mode_utils.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 21 | #include "chrome/browser/browser_about_handler.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 22 | #include "chrome/browser/browser_process.h" |
[email protected] | 5c12979 | 2013-07-10 02:08:48 | [diff] [blame] | 23 | #include "chrome/browser/browser_shutdown.h" |
[email protected] | b0cb5e8 | 2012-07-19 19:22:47 | [diff] [blame] | 24 | #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 25 | #include "chrome/browser/browsing_data/browsing_data_remover.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 26 | #include "chrome/browser/character_encoding.h" |
[email protected] | 4353551 | 2013-02-20 20:41:41 | [diff] [blame] | 27 | #include "chrome/browser/chrome_net_benchmarking_message_filter.h" |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 28 | #include "chrome/browser/chrome_quota_permission_context.h" |
[email protected] | edece21 | 2011-11-16 11:56:56 | [diff] [blame] | 29 | #include "chrome/browser/content_settings/content_settings_utils.h" |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 30 | #include "chrome/browser/content_settings/cookie_settings.h" |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 31 | #include "chrome/browser/content_settings/host_content_settings_map.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 32 | #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
[email protected] | 9d06d88d | 2012-02-23 22:37:08 | [diff] [blame] | 33 | #include "chrome/browser/defaults.h" |
[email protected] | b1d9727 | 2013-08-17 13:38:49 | [diff] [blame] | 34 | #include "chrome/browser/download/download_prefs.h" |
[email protected] | 2b33dcd0 | 2012-03-18 01:34:16 | [diff] [blame] | 35 | #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
[email protected] | 1deace2 | 2013-05-22 06:14:46 | [diff] [blame] | 36 | #include "chrome/browser/extensions/browser_permissions_policy_delegate.h" |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 37 | #include "chrome/browser/extensions/extension_host.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 38 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 39 | #include "chrome/browser/extensions/extension_system.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 40 | #include "chrome/browser/extensions/extension_web_ui.h" |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 41 | #include "chrome/browser/extensions/extension_webkit_preferences.h" |
[email protected] | eb4832a | 2012-12-08 01:57:52 | [diff] [blame] | 42 | #include "chrome/browser/extensions/suggest_permission_util.h" |
[email protected] | 32538d9 | 2011-08-25 00:09:23 | [diff] [blame] | 43 | #include "chrome/browser/geolocation/chrome_access_token_store.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 44 | #include "chrome/browser/google/google_util.h" |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 45 | #include "chrome/browser/guestview/adview/adview_guest.h" |
[email protected] | 3f24f97c | 2013-11-17 21:53:33 | [diff] [blame] | 46 | #include "chrome/browser/guestview/guestview.h" |
[email protected] | 0533cc6d | 2013-06-27 22:44:05 | [diff] [blame] | 47 | #include "chrome/browser/guestview/guestview_constants.h" |
| 48 | #include "chrome/browser/guestview/webview/webview_guest.h" |
[email protected] | 11158e2d | 2013-02-01 02:31:56 | [diff] [blame] | 49 | #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
[email protected] | 95132f5 | 2013-04-12 02:19:04 | [diff] [blame] | 50 | #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h" |
[email protected] | a2b4c5c | 2013-10-18 02:06:07 | [diff] [blame] | 51 | #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h" |
[email protected] | ae6e991 | 2011-07-27 01:18:28 | [diff] [blame] | 52 | #include "chrome/browser/net/chrome_net_log.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 53 | #include "chrome/browser/notifications/desktop_notification_service.h" |
| 54 | #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 55 | #include "chrome/browser/platform_util.h" |
[email protected] | c2295f7 | 2013-01-03 22:18:56 | [diff] [blame] | 56 | #include "chrome/browser/plugins/plugin_info_message_filter.h" |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 57 | #include "chrome/browser/prerender/prerender_final_status.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 58 | #include "chrome/browser/prerender/prerender_manager.h" |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 59 | #include "chrome/browser/prerender/prerender_manager_factory.h" |
[email protected] | 2736c03 | 2012-05-11 18:06:07 | [diff] [blame] | 60 | #include "chrome/browser/prerender/prerender_message_filter.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 61 | #include "chrome/browser/prerender/prerender_tracker.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 62 | #include "chrome/browser/printing/printing_message_filter.h" |
[email protected] | 7e75e4a | 2013-05-17 17:20:03 | [diff] [blame] | 63 | #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 64 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 65 | #include "chrome/browser/profiles/profile_io_data.h" |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 66 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 67 | #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 68 | #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h" |
[email protected] | a7b8e43d | 2013-03-18 18:52:43 | [diff] [blame] | 69 | #include "chrome/browser/search/instant_service.h" |
| 70 | #include "chrome/browser/search/instant_service_factory.h" |
| 71 | #include "chrome/browser/search/search.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 72 | #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h" |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 73 | #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h" |
[email protected] | 7a06d28 | 2013-05-03 04:39:33 | [diff] [blame] | 74 | #include "chrome/browser/speech/tts_message_filter.h" |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 75 | #include "chrome/browser/ssl/ssl_add_certificate.h" |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 76 | #include "chrome/browser/ssl/ssl_blocking_page.h" |
[email protected] | 11feec32 | 2012-09-18 03:58:52 | [diff] [blame] | 77 | #include "chrome/browser/ssl/ssl_tab_helper.h" |
[email protected] | 180c66a6 | 2013-08-05 12:01:36 | [diff] [blame] | 78 | #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 79 | #include "chrome/browser/tab_contents/tab_util.h" |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 80 | #include "chrome/browser/ui/blocked_content/blocked_window_params.h" |
[email protected] | 40aa8bb | 2013-08-23 20:28:23 | [diff] [blame] | 81 | #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" |
[email protected] | a28e330 | 2013-02-03 03:50:43 | [diff] [blame] | 82 | #include "chrome/browser/ui/chrome_select_file_policy.h" |
[email protected] | 329ac97 | 2013-06-21 15:24:25 | [diff] [blame] | 83 | #include "chrome/browser/ui/sync/sync_promo_ui.h" |
[email protected] | b5d7342 | 2012-06-02 23:46:44 | [diff] [blame] | 84 | #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h" |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 85 | #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
[email protected] | 1352ca9 | 2013-04-30 02:30:27 | [diff] [blame] | 86 | #include "chrome/browser/validation_message_message_filter.h" |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 87 | #include "chrome/common/chrome_constants.h" |
[email protected] | a7944aa | 2012-10-15 10:12:14 | [diff] [blame] | 88 | #include "chrome/common/chrome_paths.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 89 | #include "chrome/common/chrome_switches.h" |
[email protected] | 50fa4d5f | 2013-11-05 00:53:23 | [diff] [blame] | 90 | #include "chrome/common/chrome_version_info.h" |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 91 | #include "chrome/common/env_vars.h" |
[email protected] | 395045c | 2012-05-22 15:04:38 | [diff] [blame] | 92 | #include "chrome/common/extensions/extension_process_policy.h" |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 93 | #include "chrome/common/extensions/extension_set.h" |
[email protected] | 561e33d5 | 2013-04-03 06:58:43 | [diff] [blame] | 94 | #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" |
[email protected] | 157cc90 | 2012-11-02 06:31:58 | [diff] [blame] | 95 | #include "chrome/common/extensions/permissions/socket_permission.h" |
[email protected] | 9a60d160 | 2013-09-11 04:09:12 | [diff] [blame] | 96 | #include "chrome/common/extensions/web_accessible_resources_handler.h" |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 97 | #include "chrome/common/logging_chrome.h" |
[email protected] | 9d45049 | 2013-06-13 23:08:37 | [diff] [blame] | 98 | #include "chrome/common/pepper_permission_util.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 99 | #include "chrome/common/pref_names.h" |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 100 | #include "chrome/common/render_messages.h" |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 101 | #include "chrome/common/url_constants.h" |
[email protected] | 264c0acac | 2013-10-01 13:33:30 | [diff] [blame] | 102 | #include "chrome/installer/util/google_update_settings.h" |
[email protected] | e8f3f998 | 2013-05-10 20:59:53 | [diff] [blame] | 103 | #include "chromeos/chromeos_constants.h" |
[email protected] | ef42ee8 | 2013-11-01 05:26:13 | [diff] [blame] | 104 | #include "components/nacl/browser/nacl_browser.h" |
[email protected] | 7c766e9 | 2013-11-22 20:44:02 | [diff] [blame] | 105 | #include "components/nacl/browser/nacl_host_message_filter.h" |
| 106 | #include "components/nacl/browser/nacl_process_host.h" |
[email protected] | d5d38325 | 2013-07-04 14:44:32 | [diff] [blame] | 107 | #include "components/nacl/common/nacl_process_type.h" |
[email protected] | 499e7c5 | 2013-10-04 16:03:09 | [diff] [blame] | 108 | #include "components/translate/common/translate_switches.h" |
[email protected] | 75fee37 | 2013-03-06 00:42:44 | [diff] [blame] | 109 | #include "components/user_prefs/pref_registry_syncable.h" |
[email protected] | e0ada9c | 2012-03-20 03:54:43 | [diff] [blame] | 110 | #include "content/public/browser/browser_child_process_host.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 111 | #include "content/public/browser/browser_main_parts.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 112 | #include "content/public/browser/browser_ppapi_host.h" |
[email protected] | 30a306f4 | 2013-06-10 03:09:03 | [diff] [blame] | 113 | #include "content/public/browser/browser_thread.h" |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 114 | #include "content/public/browser/browser_url_handler.h" |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 115 | #include "content/public/browser/child_process_data.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 116 | #include "content/public/browser/child_process_security_policy.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 117 | #include "content/public/browser/render_process_host.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 118 | #include "content/public/browser/render_view_host.h" |
[email protected] | ce96786 | 2012-02-09 22:47:05 | [diff] [blame] | 119 | #include "content/public/browser/resource_context.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 120 | #include "content/public/browser/site_instance.h" |
[email protected] | 91ee368 | 2012-01-19 15:02:19 | [diff] [blame] | 121 | #include "content/public/browser/web_contents.h" |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 122 | #include "content/public/browser/web_contents_view.h" |
[email protected] | e0ada9c | 2012-03-20 03:54:43 | [diff] [blame] | 123 | #include "content/public/common/child_process_host.h" |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 124 | #include "content/public/common/content_descriptors.h" |
[email protected] | 22aa4f8 | 2013-09-24 17:01:44 | [diff] [blame] | 125 | #include "content/public/common/url_utils.h" |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 126 | #include "extensions/browser/info_map.h" |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 127 | #include "extensions/browser/process_manager.h" |
[email protected] | cb2edf2 | 2013-04-01 20:25:23 | [diff] [blame] | 128 | #include "extensions/browser/view_type_utils.h" |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 129 | #include "extensions/common/constants.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 130 | #include "extensions/common/extension.h" |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 131 | #include "extensions/common/manifest_handlers/background_info.h" |
[email protected] | 301116c6 | 2013-11-26 10:37:45 | [diff] [blame] | 132 | #include "extensions/common/manifest_handlers/shared_module_info.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 133 | #include "extensions/common/permissions/permissions_data.h" |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 134 | #include "extensions/common/switches.h" |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 135 | #include "grit/generated_resources.h" |
[email protected] | 2a28133 | 2012-07-11 22:20:23 | [diff] [blame] | 136 | #include "grit/ui_resources.h" |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 137 | #include "net/base/mime_util.h" |
[email protected] | 5b9bc35 | 2012-07-18 13:13:34 | [diff] [blame] | 138 | #include "net/cookies/canonical_cookie.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 139 | #include "net/cookies/cookie_options.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 140 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 141 | #include "ppapi/host/ppapi_host.h" |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 142 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 143 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | fb1aac1 | 2013-05-14 05:30:24 | [diff] [blame] | 144 | #include "ui/message_center/message_center_util.h" |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 145 | #include "webkit/browser/fileapi/external_mount_points.h" |
[email protected] | fab55e7 | 2013-05-31 07:06:18 | [diff] [blame] | 146 | #include "webkit/common/webpreferences.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 147 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 148 | #if defined(OS_WIN) |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 149 | #include "chrome/browser/chrome_browser_main_win.h" |
[email protected] | 34f4868 | 2013-03-20 00:30:18 | [diff] [blame] | 150 | #include "sandbox/win/src/sandbox_policy.h" |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 151 | #elif defined(OS_MACOSX) |
| 152 | #include "chrome/browser/chrome_browser_main_mac.h" |
[email protected] | 7ceb9901 | 2011-12-21 08:05:56 | [diff] [blame] | 153 | #include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h" |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 154 | #include "components/breakpad/app/breakpad_mac.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 155 | #elif defined(OS_CHROMEOS) |
| 156 | #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h" |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 157 | #include "chrome/browser/chromeos/drive/file_system_backend_delegate.h" |
| 158 | #include "chrome/browser/chromeos/fileapi/file_system_backend.h" |
[email protected] | 5c91525 | 2013-05-07 13:15:39 | [diff] [blame] | 159 | #include "chrome/browser/chromeos/login/startup_utils.h" |
[email protected] | fe69558d | 2012-03-12 11:34:49 | [diff] [blame] | 160 | #include "chrome/browser/chromeos/login/user_manager.h" |
[email protected] | c94ac69 | 2013-07-27 00:50:10 | [diff] [blame] | 161 | #include "chrome/browser/chromeos/system/input_device_settings.h" |
[email protected] | 931d104 | 2013-04-05 17:50:44 | [diff] [blame] | 162 | #include "chromeos/chromeos_switches.h" |
[email protected] | 81ce2c4 | 2012-03-24 01:43:26 | [diff] [blame] | 163 | #elif defined(OS_LINUX) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 164 | #include "chrome/browser/chrome_browser_main_linux.h" |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 165 | #elif defined(OS_ANDROID) |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 166 | #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h" |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 167 | #include "chrome/browser/chrome_browser_main_android.h" |
[email protected] | 2b12c32 | 2013-09-19 06:53:56 | [diff] [blame] | 168 | #include "chrome/browser/media/encrypted_media_message_filter_android.h" |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 169 | #include "chrome/common/descriptors_android.h" |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 170 | #include "components/breakpad/browser/crash_dump_manager_android.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 171 | #elif defined(OS_POSIX) |
| 172 | #include "chrome/browser/chrome_browser_main_posix.h" |
| 173 | #endif |
| 174 | |
[email protected] | a220b593 | 2013-09-21 03:47:44 | [diff] [blame] | 175 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 176 | #include "base/debug/leak_annotations.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 177 | #include "base/linux_util.h" |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 178 | #include "components/breakpad/app/breakpad_linux.h" |
| 179 | #include "components/breakpad/browser/crash_handler_host_linux.h" |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 180 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 181 | |
[email protected] | 1e87df3 | 2012-09-12 04:53:19 | [diff] [blame] | 182 | #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 183 | #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
| 184 | #endif |
| 185 | |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 186 | #if defined(OS_ANDROID) |
| 187 | #include "ui/base/ui_base_paths.h" |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 188 | #include "ui/gfx/android/device_display_info.h" |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 189 | #endif |
| 190 | |
[email protected] | 37a72af | 2011-06-13 05:42:01 | [diff] [blame] | 191 | #if defined(USE_NSS) |
| 192 | #include "chrome/browser/ui/crypto_module_password_dialog.h" |
| 193 | #endif |
| 194 | |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 195 | #if !defined(OS_CHROMEOS) |
| 196 | #include "chrome/browser/signin/signin_manager.h" |
| 197 | #include "chrome/browser/signin/signin_manager_factory.h" |
| 198 | #endif |
| 199 | |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 200 | #if !defined(OS_ANDROID) |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 201 | #include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 202 | #endif |
| 203 | |
[email protected] | 6ef98b5a | 2013-05-31 23:58:31 | [diff] [blame] | 204 | #if defined(ENABLE_WEBRTC) |
| 205 | #include "chrome/browser/media/webrtc_logging_handler_host.h" |
| 206 | #endif |
| 207 | |
[email protected] | 855e18b | 2013-07-08 21:02:00 | [diff] [blame] | 208 | #if defined(ENABLE_INPUT_SPEECH) |
| 209 | #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h" |
| 210 | #endif |
| 211 | |
[email protected] | 02a3dc12 | 2013-06-13 15:07:53 | [diff] [blame] | 212 | #if defined(FILE_MANAGER_EXTENSION) |
[email protected] | 473c9a4f | 2013-09-05 03:09:46 | [diff] [blame] | 213 | #include "chrome/browser/chromeos/file_manager/app_id.h" |
[email protected] | 02a3dc12 | 2013-06-13 15:07:53 | [diff] [blame] | 214 | #endif |
| 215 | |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 216 | #if defined(TOOLKIT_GTK) |
| 217 | #include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h" |
| 218 | #endif |
| 219 | |
| 220 | #if defined(TOOLKIT_VIEWS) |
| 221 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h" |
| 222 | #endif |
| 223 | |
| 224 | #if defined(USE_ASH) |
| 225 | #include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h" |
| 226 | #endif |
| 227 | |
| 228 | #if defined(USE_AURA) |
| 229 | #include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h" |
| 230 | #endif |
| 231 | |
| 232 | #if defined(USE_X11) |
| 233 | #include "chrome/browser/chrome_browser_main_extra_parts_x11.h" |
| 234 | #endif |
| 235 | |
[email protected] | c6ce0807 | 2013-07-31 07:48:53 | [diff] [blame] | 236 | #if defined(ENABLE_SPELLCHECK) |
| 237 | #include "chrome/browser/spellchecker/spellcheck_message_filter.h" |
| 238 | #endif |
| 239 | |
[email protected] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 240 | using blink::WebWindowFeatures; |
[email protected] | c7abd42 | 2012-09-25 00:20:08 | [diff] [blame] | 241 | using base::FileDescriptor; |
[email protected] | c8c7718 | 2011-12-21 15:04:47 | [diff] [blame] | 242 | using content::AccessTokenStore; |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 243 | using content::BrowserChildProcessHostIterator; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 244 | using content::BrowserThread; |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 245 | using content::BrowserURLHandler; |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 246 | using content::ChildProcessSecurityPolicy; |
[email protected] | c7abd42 | 2012-09-25 00:20:08 | [diff] [blame] | 247 | using content::FileDescriptorInfo; |
[email protected] | 9f9749a | 2012-03-02 19:37:00 | [diff] [blame] | 248 | using content::QuotaPermissionContext; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 249 | using content::RenderViewHost; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 250 | using content::SiteInstance; |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 251 | using content::WebContents; |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 252 | using extensions::APIPermission; |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 253 | using extensions::Extension; |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 254 | using extensions::InfoMap; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 255 | using extensions::Manifest; |
[email protected] | 593d2a7 | 2013-07-26 08:48:38 | [diff] [blame] | 256 | using message_center::NotifierId; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 257 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 258 | namespace { |
| 259 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 260 | // Cached version of the locale so we can return the locale on the I/O |
| 261 | // thread. |
| 262 | base::LazyInstance<std::string> g_io_thread_application_locale; |
| 263 | |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 264 | #if defined(ENABLE_PLUGINS) |
[email protected] | 10c3922 | 2013-11-13 20:09:25 | [diff] [blame] | 265 | const char* kPredefinedAllowedFileHandleOrigins[] = { |
| 266 | "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789 |
| 267 | "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789 |
| 268 | }; |
| 269 | |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 270 | const char* kPredefinedAllowedSocketOrigins[] = { |
| 271 | "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client |
[email protected] | b95bf50 | 2012-04-06 07:41:18 | [diff] [blame] | 272 | "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client) |
[email protected] | 9913268 | 2012-04-24 19:00:45 | [diff] [blame] | 273 | "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126 |
| 274 | "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop |
| 275 | "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop |
| 276 | "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop |
[email protected] | a450b6be | 2012-05-22 19:30:35 | [diff] [blame] | 277 | "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary |
[email protected] | 9040a0c2 | 2012-06-22 19:06:54 | [diff] [blame] | 278 | "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089 |
| 279 | "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099 |
| 280 | "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099 |
| 281 | "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099 |
| 282 | "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099 |
| 283 | "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099 |
[email protected] | 4dc30b8 | 2012-08-15 00:24:38 | [diff] [blame] | 284 | "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099 |
[email protected] | 45db05f | 2012-12-10 21:52:58 | [diff] [blame] | 285 | "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514 |
[email protected] | b7131323 | 2013-05-06 06:16:29 | [diff] [blame] | 286 | "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080 |
[email protected] | 3f6fca2 | 2013-08-12 23:13:42 | [diff] [blame] | 287 | "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080 |
| 288 | "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789 |
| 289 | "4EB74897CB187C7633357C2FE832E0AD6A44883A", // see crbug.com/234789 |
| 290 | "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084 |
| 291 | "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084 |
| 292 | "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084 |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 293 | }; |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 294 | #endif |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 295 | |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 296 | // Returns a copy of the given url with its host set to given host and path set |
| 297 | // to given path. Other parts of the url will be the same. |
| 298 | GURL ReplaceURLHostAndPath(const GURL& url, |
| 299 | const std::string& host, |
| 300 | const std::string& path) { |
| 301 | url_canon::Replacements<char> replacements; |
| 302 | replacements.SetHost(host.c_str(), |
| 303 | url_parse::Component(0, host.length())); |
| 304 | replacements.SetPath(path.c_str(), |
| 305 | url_parse::Component(0, path.length())); |
| 306 | return url.ReplaceComponents(replacements); |
| 307 | } |
| 308 | |
| 309 | // Maps "foo://bar/baz/" to "foo://chrome/bar/baz/". |
| 310 | GURL AddUberHost(const GURL& url) { |
| 311 | const std::string uber_host = chrome::kChromeUIUberHost; |
| 312 | const std::string new_path = url.host() + url.path(); |
| 313 | |
| 314 | return ReplaceURLHostAndPath(url, uber_host, new_path); |
| 315 | } |
| 316 | |
[email protected] | 045bf7c | 2012-09-28 20:27:36 | [diff] [blame] | 317 | // If url->host() is "chrome" and url->path() has characters other than the |
| 318 | // first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and |
| 319 | // returns true. Otherwise returns false. |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 320 | bool RemoveUberHost(GURL* url) { |
| 321 | if (url->host() != chrome::kChromeUIUberHost) |
| 322 | return false; |
| 323 | |
[email protected] | 045bf7c | 2012-09-28 20:27:36 | [diff] [blame] | 324 | if (url->path().empty() || url->path() == "/") |
| 325 | return false; |
| 326 | |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 327 | const std::string old_path = url->path(); |
| 328 | |
| 329 | const std::string::size_type separator = old_path.find('/', 1); |
| 330 | std::string new_host; |
| 331 | std::string new_path; |
| 332 | if (separator == std::string::npos) { |
[email protected] | 045bf7c | 2012-09-28 20:27:36 | [diff] [blame] | 333 | new_host = old_path.substr(1); |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 334 | } else { |
| 335 | new_host = old_path.substr(1, separator - 1); |
| 336 | new_path = old_path.substr(separator); |
| 337 | } |
| 338 | |
[email protected] | 44e8add | 2013-06-13 17:29:15 | [diff] [blame] | 339 | // Do not allow URLs with paths empty before the first slash since we can't |
| 340 | // have an empty host. (e.g "foo://chrome//") |
| 341 | if (new_host.empty()) |
| 342 | return false; |
| 343 | |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 344 | *url = ReplaceURLHostAndPath(*url, new_host, new_path); |
| 345 | |
[email protected] | 44e8add | 2013-06-13 17:29:15 | [diff] [blame] | 346 | DCHECK(url->is_valid()); |
| 347 | |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 348 | return true; |
| 349 | } |
| 350 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 351 | // Handles rewriting Web UI URLs. |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 352 | bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 353 | // Do not handle special URLs such as "about:foo" |
| 354 | if (!url->host().empty()) { |
| 355 | const GURL chrome_url = AddUberHost(*url); |
| 356 | |
| 357 | // Handle valid "chrome://chrome/foo" URLs so the reverse handler will |
| 358 | // be called. |
| 359 | if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 360 | browser_context, chrome_url)) |
| 361 | return true; |
| 362 | } |
| 363 | |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 364 | if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 365 | browser_context, *url)) |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 366 | return false; |
| 367 | |
[email protected] | fe69558d | 2012-03-12 11:34:49 | [diff] [blame] | 368 | #if defined(OS_CHROMEOS) |
| 369 | // Special case : in ChromeOS in Guest mode bookmarks and history are |
| 370 | // disabled for security reasons. New tab page explains the reasons, so |
| 371 | // we redirect user to new tab page. |
| 372 | if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) { |
| 373 | if (url->SchemeIs(chrome::kChromeUIScheme) && |
| 374 | (url->DomainIs(chrome::kChromeUIBookmarksHost) || |
[email protected] | b917162 | 2013-10-01 22:05:23 | [diff] [blame] | 375 | #if defined(ENABLE_ENHANCED_BOOKMARKS) |
| 376 | url->DomainIs(chrome::kChromeUIEnhancedBookmarksHost) || |
| 377 | #endif |
[email protected] | fe69558d | 2012-03-12 11:34:49 | [diff] [blame] | 378 | url->DomainIs(chrome::kChromeUIHistoryHost))) { |
| 379 | // Rewrite with new tab URL |
| 380 | *url = GURL(chrome::kChromeUINewTabURL); |
| 381 | } |
| 382 | } |
| 383 | #endif |
| 384 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 385 | // Special case the new tab page. In older versions of Chrome, the new tab |
| 386 | // page was hosted at chrome-internal:<blah>. This might be in people's saved |
| 387 | // sessions or bookmarks, so we say any URL with that scheme triggers the new |
| 388 | // tab page. |
| 389 | if (url->SchemeIs(chrome::kChromeInternalScheme)) { |
| 390 | // Rewrite it with the proper new tab URL. |
| 391 | *url = GURL(chrome::kChromeUINewTabURL); |
| 392 | } |
| 393 | |
| 394 | return true; |
| 395 | } |
| 396 | |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 397 | // Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to |
| 398 | // "chrome://foo/". |
| 399 | bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) { |
| 400 | if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme)) |
| 401 | return false; |
| 402 | |
| 403 | return RemoveUberHost(url); |
| 404 | } |
| 405 | |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 406 | // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions |
| 407 | // below. Extension, and isolated apps require different privileges to be |
| 408 | // granted to their RenderProcessHosts. This classification allows us to make |
| 409 | // sure URLs are served by hosts with the right set of privileges. |
| 410 | enum RenderProcessHostPrivilege { |
| 411 | PRIV_NORMAL, |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 412 | PRIV_HOSTED, |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 413 | PRIV_ISOLATED, |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 414 | PRIV_EXTENSION, |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 415 | }; |
| 416 | |
| 417 | RenderProcessHostPrivilege GetPrivilegeRequiredByUrl( |
| 418 | const GURL& url, |
| 419 | ExtensionService* service) { |
| 420 | // Default to a normal renderer cause it is lower privileged. This should only |
| 421 | // occur if the URL on a site instance is either malformed, or uninitialized. |
| 422 | // If it is malformed, then there is no need for better privileges anyways. |
| 423 | // If it is uninitialized, but eventually settles on being an a scheme other |
| 424 | // than normal webrenderer, the navigation logic will correct us out of band |
| 425 | // anyways. |
| 426 | if (!url.is_valid()) |
| 427 | return PRIV_NORMAL; |
| 428 | |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 429 | if (url.SchemeIs(extensions::kExtensionScheme)) { |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 430 | const Extension* extension = |
| 431 | service->extensions()->GetByID(url.host()); |
[email protected] | 561e33d5 | 2013-04-03 06:58:43 | [diff] [blame] | 432 | if (extension && |
| 433 | extensions::AppIsolationInfo::HasIsolatedStorage(extension)) |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 434 | return PRIV_ISOLATED; |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 435 | if (extension && extension->is_hosted_app()) |
| 436 | return PRIV_HOSTED; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 437 | |
| 438 | return PRIV_EXTENSION; |
| 439 | } |
| 440 | |
| 441 | return PRIV_NORMAL; |
| 442 | } |
| 443 | |
| 444 | RenderProcessHostPrivilege GetProcessPrivilege( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 445 | content::RenderProcessHost* process_host, |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 446 | extensions::ProcessMap* process_map, |
| 447 | ExtensionService* service) { |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 448 | std::set<std::string> extension_ids = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 449 | process_map->GetExtensionsInProcess(process_host->GetID()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 450 | if (extension_ids.empty()) |
[email protected] | 676f6ab | 2011-10-19 20:23:21 | [diff] [blame] | 451 | return PRIV_NORMAL; |
| 452 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 453 | for (std::set<std::string>::iterator iter = extension_ids.begin(); |
| 454 | iter != extension_ids.end(); ++iter) { |
| 455 | const Extension* extension = service->GetExtensionById(*iter, false); |
[email protected] | 561e33d5 | 2013-04-03 06:58:43 | [diff] [blame] | 456 | if (extension && |
| 457 | extensions::AppIsolationInfo::HasIsolatedStorage(extension)) |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 458 | return PRIV_ISOLATED; |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 459 | if (extension && extension->is_hosted_app()) |
| 460 | return PRIV_HOSTED; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 461 | } |
| 462 | |
[email protected] | 676f6ab | 2011-10-19 20:23:21 | [diff] [blame] | 463 | return PRIV_EXTENSION; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 464 | } |
| 465 | |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 466 | bool CertMatchesFilter(const net::X509Certificate& cert, |
| 467 | const base::DictionaryValue& filter) { |
| 468 | // TODO(markusheintz): This is the minimal required filter implementation. |
| 469 | // Implement a better matcher. |
| 470 | |
| 471 | // An empty filter matches any client certificate since no requirements are |
| 472 | // specified at all. |
| 473 | if (filter.empty()) |
| 474 | return true; |
| 475 | |
| 476 | std::string common_name; |
| 477 | if (filter.GetString("ISSUER.CN", &common_name) && |
| 478 | (cert.issuer().common_name == common_name)) { |
| 479 | return true; |
| 480 | } |
| 481 | return false; |
| 482 | } |
| 483 | |
[email protected] | 1d51882f | 2013-11-12 01:59:02 | [diff] [blame] | 484 | #if !defined(OS_ANDROID) |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 485 | // Fills |map| with the per-script font prefs under path |map_name|. |
| 486 | void FillFontFamilyMap(const PrefService* prefs, |
| 487 | const char* map_name, |
[email protected] | 3184f90b | 2013-05-01 18:17:53 | [diff] [blame] | 488 | webkit_glue::ScriptFontFamilyMap* map) { |
[email protected] | 33b7954 | 2013-10-18 11:18:45 | [diff] [blame] | 489 | // TODO: Get rid of the brute-force scan over possible (font family / script) |
| 490 | // combinations - see http://crbug.com/308095. |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 491 | for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { |
| 492 | const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; |
| 493 | std::string pref_name = base::StringPrintf("%s.%s", map_name, script); |
| 494 | std::string font_family = prefs->GetString(pref_name.c_str()); |
[email protected] | d047106 | 2012-10-26 09:00:23 | [diff] [blame] | 495 | if (!font_family.empty()) |
| 496 | (*map)[script] = UTF8ToUTF16(font_family); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 500 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 501 | breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost( |
| 502 | const std::string& process_type) { |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 503 | base::FilePath dumps_path; |
| 504 | PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path); |
| 505 | { |
| 506 | ANNOTATE_SCOPED_MEMORY_LEAK; |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 507 | breakpad::CrashHandlerHostLinux* crash_handler = |
| 508 | new breakpad::CrashHandlerHostLinux( |
| 509 | process_type, dumps_path, getenv(env_vars::kHeadless) == NULL); |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 510 | crash_handler->StartUploaderThread(); |
| 511 | return crash_handler; |
| 512 | } |
| 513 | } |
| 514 | |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 515 | int GetCrashSignalFD(const CommandLine& command_line) { |
| 516 | if (command_line.HasSwitch(switches::kExtensionProcess)) { |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 517 | static breakpad::CrashHandlerHostLinux* crash_handler = NULL; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 518 | if (!crash_handler) |
| 519 | crash_handler = CreateCrashHandlerHost("extension"); |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 520 | return crash_handler->GetDeathSignalSocket(); |
| 521 | } |
| 522 | |
| 523 | std::string process_type = |
| 524 | command_line.GetSwitchValueASCII(switches::kProcessType); |
| 525 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 526 | if (process_type == switches::kRendererProcess) { |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 527 | static breakpad::CrashHandlerHostLinux* crash_handler = NULL; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 528 | if (!crash_handler) |
| 529 | crash_handler = CreateCrashHandlerHost(process_type); |
| 530 | return crash_handler->GetDeathSignalSocket(); |
| 531 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 532 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 533 | if (process_type == switches::kPluginProcess) { |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 534 | static breakpad::CrashHandlerHostLinux* crash_handler = NULL; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 535 | if (!crash_handler) |
| 536 | crash_handler = CreateCrashHandlerHost(process_type); |
| 537 | return crash_handler->GetDeathSignalSocket(); |
| 538 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 539 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 540 | if (process_type == switches::kPpapiPluginProcess) { |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 541 | static breakpad::CrashHandlerHostLinux* crash_handler = NULL; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 542 | if (!crash_handler) |
| 543 | crash_handler = CreateCrashHandlerHost(process_type); |
| 544 | return crash_handler->GetDeathSignalSocket(); |
| 545 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 546 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 547 | if (process_type == switches::kGpuProcess) { |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 548 | static breakpad::CrashHandlerHostLinux* crash_handler = NULL; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 549 | if (!crash_handler) |
| 550 | crash_handler = CreateCrashHandlerHost(process_type); |
| 551 | return crash_handler->GetDeathSignalSocket(); |
| 552 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 553 | |
| 554 | return -1; |
| 555 | } |
| 556 | #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 1d51882f | 2013-11-12 01:59:02 | [diff] [blame] | 557 | #endif // !defined(OS_ANDROID) |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 558 | |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 559 | #if !defined(OS_CHROMEOS) |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 560 | GURL GetEffectiveURLForSignin(const GURL& url) { |
| 561 | CHECK(SigninManager::IsWebBasedSigninFlowURL(url)); |
| 562 | |
| 563 | GURL effective_url(SigninManager::kChromeSigninEffectiveSite); |
[email protected] | fab8bbed4 | 2013-03-07 01:13:03 | [diff] [blame] | 564 | // Copy the path because the argument to SetPathStr must outlive |
| 565 | // the Replacements object. |
| 566 | const std::string path_copy(url.path()); |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 567 | GURL::Replacements replacements; |
[email protected] | fab8bbed4 | 2013-03-07 01:13:03 | [diff] [blame] | 568 | replacements.SetPathStr(path_copy); |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 569 | effective_url = effective_url.ReplaceComponents(replacements); |
| 570 | return effective_url; |
| 571 | } |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 572 | #endif |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 573 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 574 | void SetApplicationLocaleOnIOThread(const std::string& locale) { |
| 575 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 576 | g_io_thread_application_locale.Get() = locale; |
| 577 | } |
| 578 | |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 579 | void HandleBlockedPopupOnUIThread(const BlockedWindowParams& params) { |
| 580 | WebContents* tab = tab_util::GetWebContentsByID(params.render_process_id(), |
| 581 | params.opener_id()); |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 582 | if (!tab) |
| 583 | return; |
| 584 | |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 585 | PopupBlockerTabHelper* popup_helper = |
| 586 | PopupBlockerTabHelper::FromWebContents(tab); |
| 587 | if (!popup_helper) |
| 588 | return; |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 589 | popup_helper->AddBlockedPopup(params); |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 590 | } |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 591 | |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 592 | #if defined(OS_ANDROID) |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 593 | |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 594 | void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams& params) { |
| 595 | WebContents* web_contents = |
| 596 | tab_util::GetWebContentsByID(params.render_process_id(), |
| 597 | params.opener_id()); |
| 598 | if (!web_contents) |
| 599 | return; |
| 600 | |
| 601 | SingleTabModeTabHelper::FromWebContents(web_contents)->HandleOpenUrl(params); |
| 602 | } |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 603 | |
[email protected] | ded00dc | 2013-11-01 00:37:05 | [diff] [blame] | 604 | float GetDeviceScaleAdjustment() { |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 605 | static const float kMinFSM = 1.05f; |
| 606 | static const int kWidthForMinFSM = 320; |
| 607 | static const float kMaxFSM = 1.3f; |
| 608 | static const int kWidthForMaxFSM = 800; |
| 609 | |
| 610 | gfx::DeviceDisplayInfo info; |
| 611 | int minWidth = info.GetSmallestDIPWidth(); |
| 612 | |
| 613 | if (minWidth <= kWidthForMinFSM) |
| 614 | return kMinFSM; |
| 615 | if (minWidth >= kWidthForMaxFSM) |
| 616 | return kMaxFSM; |
| 617 | |
| 618 | // The font scale multiplier varies linearly between kMinFSM and kMaxFSM. |
| 619 | float ratio = static_cast<float>(minWidth - kWidthForMinFSM) / |
| 620 | (kWidthForMaxFSM - kWidthForMinFSM); |
| 621 | return ratio * (kMaxFSM - kMinFSM) + kMinFSM; |
| 622 | } |
| 623 | |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 624 | #endif // defined(OS_ANDROID) |
| 625 | |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 626 | } // namespace |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 627 | |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 628 | namespace chrome { |
| 629 | |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 630 | ChromeContentBrowserClient::ChromeContentBrowserClient() { |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 631 | #if defined(ENABLE_PLUGINS) |
[email protected] | 10c3922 | 2013-11-13 20:09:25 | [diff] [blame] | 632 | for (size_t i = 0; i < arraysize(kPredefinedAllowedFileHandleOrigins); ++i) |
| 633 | allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]); |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 634 | for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) |
| 635 | allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 636 | #endif |
[email protected] | 1deace2 | 2013-05-22 06:14:46 | [diff] [blame] | 637 | |
| 638 | permissions_policy_delegate_.reset( |
| 639 | new extensions::BrowserPermissionsPolicyDelegate()); |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | ChromeContentBrowserClient::~ChromeContentBrowserClient() { |
| 643 | } |
| 644 | |
[email protected] | bca1838 | 2012-06-25 19:15:23 | [diff] [blame] | 645 | // static |
[email protected] | 37ca3fe0 | 2013-07-05 15:32:44 | [diff] [blame] | 646 | void ChromeContentBrowserClient::RegisterProfilePrefs( |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 647 | user_prefs::PrefRegistrySyncable* registry) { |
| 648 | registry->RegisterBooleanPref( |
| 649 | prefs::kDisable3DAPIs, |
| 650 | false, |
| 651 | user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 652 | registry->RegisterBooleanPref( |
| 653 | prefs::kEnableHyperlinkAuditing, |
| 654 | true, |
| 655 | user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 656 | registry->RegisterBooleanPref( |
| 657 | prefs::kEnableMemoryInfo, |
| 658 | false, |
| 659 | user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
[email protected] | bca1838 | 2012-06-25 19:15:23 | [diff] [blame] | 660 | } |
| 661 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 662 | // static |
| 663 | void ChromeContentBrowserClient::SetApplicationLocale( |
| 664 | const std::string& locale) { |
| 665 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 666 | |
| 667 | // This object is guaranteed to outlive all threads so we don't have to |
| 668 | // worry about the lack of refcounting and can just post as Unretained. |
| 669 | // |
| 670 | // The common case is that this function is called early in Chrome startup |
| 671 | // before any threads are created (it will also be called later if the user |
| 672 | // changes the pref). In this case, there will be no threads created and |
| 673 | // posting will fail. When there are no threads, we can just set the string |
| 674 | // without worrying about threadsafety. |
| 675 | if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 676 | base::Bind(&SetApplicationLocaleOnIOThread, locale))) { |
| 677 | g_io_thread_application_locale.Get() = locale; |
| 678 | } |
| 679 | } |
| 680 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 681 | content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( |
| 682 | const content::MainFunctionParams& parameters) { |
| 683 | ChromeBrowserMainParts* main_parts; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 684 | // Construct the Main browser parts based on the OS type. |
| 685 | #if defined(OS_WIN) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 686 | main_parts = new ChromeBrowserMainPartsWin(parameters); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 687 | #elif defined(OS_MACOSX) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 688 | main_parts = new ChromeBrowserMainPartsMac(parameters); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 689 | #elif defined(OS_CHROMEOS) |
[email protected] | 2c624d0 | 2012-11-15 19:37:22 | [diff] [blame] | 690 | main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters); |
[email protected] | 81ce2c4 | 2012-03-24 01:43:26 | [diff] [blame] | 691 | #elif defined(OS_LINUX) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 692 | main_parts = new ChromeBrowserMainPartsLinux(parameters); |
[email protected] | 6e677a34 | 2012-02-11 01:21:14 | [diff] [blame] | 693 | #elif defined(OS_ANDROID) |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 694 | main_parts = new ChromeBrowserMainPartsAndroid(parameters); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 695 | #elif defined(OS_POSIX) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 696 | main_parts = new ChromeBrowserMainPartsPosix(parameters); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 697 | #else |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 698 | NOTREACHED(); |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 699 | main_parts = new ChromeBrowserMainParts(parameters); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 700 | #endif |
| 701 | |
[email protected] | 7e75e4a | 2013-05-17 17:20:03 | [diff] [blame] | 702 | chrome::AddProfilesExtraParts(main_parts); |
| 703 | |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 704 | // Construct additional browser parts. Stages are called in the order in |
| 705 | // which they are added. |
[email protected] | a13283cc | 2012-04-05 00:21:22 | [diff] [blame] | 706 | #if defined(TOOLKIT_GTK) |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 707 | main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk()); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 708 | #endif |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 709 | |
| 710 | #if defined(TOOLKIT_VIEWS) |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 711 | main_parts->AddParts(new ChromeBrowserMainExtraPartsViews()); |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 712 | #endif |
| 713 | |
[email protected] | dc04be7c | 2012-03-15 23:57:49 | [diff] [blame] | 714 | #if defined(USE_ASH) |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 715 | main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh()); |
[email protected] | dc04be7c | 2012-03-15 23:57:49 | [diff] [blame] | 716 | #endif |
| 717 | |
[email protected] | e050ef14 | 2012-03-21 01:04:24 | [diff] [blame] | 718 | #if defined(USE_AURA) |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 719 | main_parts->AddParts(new ChromeBrowserMainExtraPartsAura()); |
| 720 | #endif |
| 721 | |
| 722 | #if defined(USE_X11) |
| 723 | main_parts->AddParts(new ChromeBrowserMainExtraPartsX11()); |
[email protected] | e050ef14 | 2012-03-21 01:04:24 | [diff] [blame] | 724 | #endif |
| 725 | |
[email protected] | 95132f5 | 2013-04-12 02:19:04 | [diff] [blame] | 726 | chrome::AddMetricsExtraParts(main_parts); |
| 727 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 728 | return main_parts; |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 729 | } |
| 730 | |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 731 | std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite( |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 732 | content::BrowserContext* browser_context, |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 733 | const GURL& site) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 734 | std::string partition_id; |
| 735 | |
| 736 | // The partition ID for webview guest processes is the string value of its |
| 737 | // SiteInstance URL - "chrome-guest://app_id/persist?partition". |
[email protected] | 6eb1a11e | 2013-10-09 00:54:37 | [diff] [blame] | 738 | if (site.SchemeIs(content::kGuestScheme)) |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 739 | partition_id = site.spec(); |
| 740 | |
[email protected] | 056efdc | 2013-04-06 00:14:53 | [diff] [blame] | 741 | DCHECK(IsValidStoragePartitionId(browser_context, partition_id)); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 742 | return partition_id; |
| 743 | } |
| 744 | |
| 745 | bool ChromeContentBrowserClient::IsValidStoragePartitionId( |
| 746 | content::BrowserContext* browser_context, |
| 747 | const std::string& partition_id) { |
| 748 | // The default ID is empty and is always valid. |
| 749 | if (partition_id.empty()) |
| 750 | return true; |
| 751 | |
| 752 | return GURL(partition_id).is_valid(); |
| 753 | } |
| 754 | |
| 755 | void ChromeContentBrowserClient::GetStoragePartitionConfigForSite( |
| 756 | content::BrowserContext* browser_context, |
| 757 | const GURL& site, |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 758 | bool can_be_default, |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 759 | std::string* partition_domain, |
| 760 | std::string* partition_name, |
| 761 | bool* in_memory) { |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 762 | // Default to the browser-wide storage partition and override based on |site| |
| 763 | // below. |
| 764 | partition_domain->clear(); |
| 765 | partition_name->clear(); |
| 766 | *in_memory = false; |
| 767 | |
[email protected] | 3f24f97c | 2013-11-17 21:53:33 | [diff] [blame] | 768 | bool success = GuestView::GetGuestPartitionConfigForSite( |
| 769 | site, partition_domain, partition_name, in_memory); |
| 770 | |
| 771 | if (!success && site.SchemeIs(extensions::kExtensionScheme)) { |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 772 | // If |can_be_default| is false, the caller is stating that the |site| |
| 773 | // should be parsed as if it had isolated storage. In particular it is |
| 774 | // important to NOT check ExtensionService for the is_storage_isolated() |
| 775 | // attribute because this code path is run during Extension uninstall |
| 776 | // to do cleanup after the Extension has already been unloaded from the |
| 777 | // ExtensionService. |
| 778 | bool is_isolated = !can_be_default; |
| 779 | if (can_be_default) { |
| 780 | const Extension* extension = NULL; |
| 781 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 782 | ExtensionService* extension_service = |
| 783 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 784 | if (extension_service) { |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 785 | extension = |
| 786 | extension_service->extensions()->GetExtensionOrAppByURL(site); |
[email protected] | 561e33d5 | 2013-04-03 06:58:43 | [diff] [blame] | 787 | if (extension && |
| 788 | extensions::AppIsolationInfo::HasIsolatedStorage(extension)) { |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 789 | is_isolated = true; |
| 790 | } |
| 791 | } |
| 792 | } |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 793 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 794 | if (is_isolated) { |
| 795 | CHECK(site.has_host()); |
| 796 | // For extensions with isolated storage, the the host of the |site| is |
| 797 | // the |partition_domain|. The |in_memory| and |partition_name| are only |
| 798 | // used in guest schemes so they are cleared here. |
| 799 | *partition_domain = site.host(); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 800 | *in_memory = false; |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 801 | partition_name->clear(); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 802 | } |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 803 | } |
| 804 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 805 | // Assert that if |can_be_default| is false, the code above must have found a |
| 806 | // non-default partition. If this fails, the caller has a serious logic |
| 807 | // error about which StoragePartition they expect to be in and it is not |
| 808 | // safe to continue. |
| 809 | CHECK(can_be_default || !partition_domain->empty()); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 810 | } |
| 811 | |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 812 | content::WebContentsViewDelegate* |
| 813 | ChromeContentBrowserClient::GetWebContentsViewDelegate( |
| 814 | content::WebContents* web_contents) { |
[email protected] | d3322029 | 2012-07-04 01:41:27 | [diff] [blame] | 815 | return chrome::CreateWebContentsViewDelegate(web_contents); |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 816 | } |
| 817 | |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 818 | void ChromeContentBrowserClient::GuestWebContentsCreated( |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 819 | SiteInstance* guest_site_instance, |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 820 | WebContents* guest_web_contents, |
| 821 | WebContents* opener_web_contents, |
[email protected] | 4c0e827 | 2013-07-03 23:39:22 | [diff] [blame] | 822 | content::BrowserPluginGuestDelegate** guest_delegate, |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 823 | scoped_ptr<base::DictionaryValue> extra_params) { |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 824 | if (!guest_site_instance) { |
| 825 | NOTREACHED(); |
| 826 | return; |
| 827 | } |
| 828 | GURL guest_site_url = guest_site_instance->GetSiteURL(); |
| 829 | const std::string& extension_id = guest_site_url.host(); |
| 830 | |
| 831 | Profile* profile = Profile::FromBrowserContext( |
| 832 | guest_web_contents->GetBrowserContext()); |
| 833 | ExtensionService* service = |
| 834 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 835 | if (!service) { |
| 836 | NOTREACHED(); |
| 837 | return; |
| 838 | } |
| 839 | |
| 840 | /// TODO(fsamuel): In the future, certain types of GuestViews won't require |
| 841 | // extension bindings. At that point, we should clear |extension_id| instead |
| 842 | // of exiting early. |
| 843 | if (!service->GetExtensionById(extension_id, false) && |
| 844 | !CommandLine::ForCurrentProcess()->HasSwitch( |
| 845 | switches::kEnableBrowserPluginForAllViewTypes)) { |
| 846 | NOTREACHED(); |
| 847 | return; |
| 848 | } |
| 849 | |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 850 | if (opener_web_contents) { |
| 851 | GuestView* guest = GuestView::FromWebContents(opener_web_contents); |
| 852 | if (!guest) { |
| 853 | NOTREACHED(); |
| 854 | return; |
| 855 | } |
| 856 | |
[email protected] | 50c827d | 2013-09-13 21:36:09 | [diff] [blame] | 857 | // Create a new GuestView of the same type as the opener. |
| 858 | *guest_delegate = |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 859 | GuestView::Create(guest_web_contents, |
| 860 | extension_id, |
| 861 | guest->GetViewType()); |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 862 | return; |
| 863 | } |
| 864 | |
| 865 | if (!extra_params) { |
| 866 | NOTREACHED(); |
| 867 | return; |
| 868 | } |
| 869 | std::string api_type; |
[email protected] | 90547d7 | 2013-08-06 05:57:27 | [diff] [blame] | 870 | extra_params->GetString(guestview::kParameterApi, &api_type); |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 871 | |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 872 | if (api_type.empty()) |
| 873 | return; |
| 874 | |
[email protected] | 50c827d | 2013-09-13 21:36:09 | [diff] [blame] | 875 | *guest_delegate = |
| 876 | GuestView::Create(guest_web_contents, |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 877 | extension_id, |
[email protected] | 50c827d | 2013-09-13 21:36:09 | [diff] [blame] | 878 | GuestView::GetViewTypeFromString(api_type)); |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 879 | } |
| 880 | |
[email protected] | 44295a1 | 2013-06-05 08:45:46 | [diff] [blame] | 881 | void ChromeContentBrowserClient::GuestWebContentsAttached( |
| 882 | WebContents* guest_web_contents, |
| 883 | WebContents* embedder_web_contents, |
[email protected] | 5715566a | 2013-06-25 00:04:53 | [diff] [blame] | 884 | const base::DictionaryValue& extra_params) { |
[email protected] | 22aa4f8 | 2013-09-24 17:01:44 | [diff] [blame] | 885 | |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 886 | GuestView* guest = GuestView::FromWebContents(guest_web_contents); |
| 887 | if (!guest) { |
[email protected] | efd6fb0 | 2013-08-05 04:44:06 | [diff] [blame] | 888 | // It's ok to return here, since we could be running a browser plugin |
| 889 | // outside an extension, and don't need to attach a |
| 890 | // BrowserPluginGuestDelegate in that case; |
| 891 | // e.g. running with flag --enable-browser-plugin-for-all-view-types. |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 892 | return; |
[email protected] | 1869937 | 2013-06-25 20:42:55 | [diff] [blame] | 893 | } |
[email protected] | dbbce92c | 2013-10-31 16:51:19 | [diff] [blame] | 894 | guest->Attach(embedder_web_contents, extra_params); |
[email protected] | 44703cc7 | 2013-01-24 04:56:06 | [diff] [blame] | 895 | } |
| 896 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 897 | void ChromeContentBrowserClient::RenderProcessHostCreated( |
| 898 | content::RenderProcessHost* host) { |
| 899 | int id = host->GetID(); |
| 900 | Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
[email protected] | 4353551 | 2013-02-20 20:41:41 | [diff] [blame] | 901 | net::URLRequestContextGetter* context = |
| 902 | profile->GetRequestContextForRenderProcess(id); |
| 903 | |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 904 | host->AddFilter(new ChromeRenderMessageFilter(id, profile, context)); |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 905 | #if defined(ENABLE_PLUGINS) |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 906 | host->AddFilter(new PluginInfoMessageFilter(id, profile)); |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 907 | #endif |
[email protected] | 658677f | 2012-06-09 06:04:02 | [diff] [blame] | 908 | #if defined(ENABLE_PRINTING) |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 909 | host->AddFilter(new PrintingMessageFilter(id, profile)); |
[email protected] | 058e573 | 2012-03-01 22:48:03 | [diff] [blame] | 910 | #endif |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 911 | host->AddFilter(new SearchProviderInstallStateMessageFilter(id, profile)); |
[email protected] | c6ce0807 | 2013-07-31 07:48:53 | [diff] [blame] | 912 | #if defined(ENABLE_SPELLCHECK) |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 913 | host->AddFilter(new SpellCheckMessageFilter(id)); |
[email protected] | c6ce0807 | 2013-07-31 07:48:53 | [diff] [blame] | 914 | #endif |
[email protected] | 7ceb9901 | 2011-12-21 08:05:56 | [diff] [blame] | 915 | #if defined(OS_MACOSX) |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 916 | host->AddFilter(new SpellCheckMessageFilterMac(id)); |
[email protected] | 7ceb9901 | 2011-12-21 08:05:56 | [diff] [blame] | 917 | #endif |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 918 | host->AddFilter(new ChromeNetBenchmarkingMessageFilter( |
[email protected] | 4353551 | 2013-02-20 20:41:41 | [diff] [blame] | 919 | id, profile, context)); |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 920 | host->AddFilter(new prerender::PrerenderMessageFilter(id, profile)); |
| 921 | host->AddFilter(new ValidationMessageMessageFilter(id)); |
| 922 | host->AddFilter(new TtsMessageFilter(id, profile)); |
[email protected] | 6ef98b5a | 2013-05-31 23:58:31 | [diff] [blame] | 923 | #if defined(ENABLE_WEBRTC) |
[email protected] | 10e5c5e5 | 2013-10-03 18:44:06 | [diff] [blame] | 924 | WebRtcLoggingHandlerHost* webrtc_logging_handler_host = |
[email protected] | 135bc1d | 2013-10-21 09:11:37 | [diff] [blame] | 925 | new WebRtcLoggingHandlerHost(profile); |
[email protected] | 10e5c5e5 | 2013-10-03 18:44:06 | [diff] [blame] | 926 | host->AddFilter(webrtc_logging_handler_host); |
| 927 | host->SetUserData(host, new base::UserDataAdapter<WebRtcLoggingHandlerHost>( |
| 928 | webrtc_logging_handler_host)); |
[email protected] | 6ef98b5a | 2013-05-31 23:58:31 | [diff] [blame] | 929 | #endif |
[email protected] | 01e5975 | 2013-06-18 00:17:35 | [diff] [blame] | 930 | #if !defined(DISABLE_NACL) |
[email protected] | 7c766e9 | 2013-11-22 20:44:02 | [diff] [blame] | 931 | host->AddFilter(new nacl::NaClHostMessageFilter( |
[email protected] | 14230ca | 2013-06-26 23:33:03 | [diff] [blame] | 932 | id, profile->IsOffTheRecord(), |
[email protected] | a2b4c5c | 2013-10-18 02:06:07 | [diff] [blame] | 933 | profile->GetPath(), |
[email protected] | 14230ca | 2013-06-26 23:33:03 | [diff] [blame] | 934 | context)); |
[email protected] | 01e5975 | 2013-06-18 00:17:35 | [diff] [blame] | 935 | #endif |
[email protected] | 2b12c32 | 2013-09-19 06:53:56 | [diff] [blame] | 936 | #if defined(OS_ANDROID) |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 937 | host->AddFilter(new EncryptedMediaMessageFilterAndroid()); |
[email protected] | 2b12c32 | 2013-09-19 06:53:56 | [diff] [blame] | 938 | #endif |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 939 | |
[email protected] | 2ccf45c | 2011-08-19 23:35:50 | [diff] [blame] | 940 | host->Send(new ChromeViewMsg_SetIsIncognitoProcess( |
| 941 | profile->IsOffTheRecord())); |
[email protected] | 39a5b53 | 2011-10-22 01:47:07 | [diff] [blame] | 942 | |
| 943 | SendExtensionWebRequestStatusToHost(host); |
[email protected] | edece21 | 2011-11-16 11:56:56 | [diff] [blame] | 944 | |
| 945 | RendererContentSettingRules rules; |
| 946 | GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules); |
| 947 | host->Send(new ChromeViewMsg_SetContentSettingRules(rules)); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 948 | } |
| 949 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 950 | GURL ChromeContentBrowserClient::GetEffectiveURL( |
| 951 | content::BrowserContext* browser_context, const GURL& url) { |
| 952 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 953 | if (!profile) |
| 954 | return url; |
| 955 | |
[email protected] | b3cb3a3 | 2013-07-31 01:32:29 | [diff] [blame] | 956 | // If the input |url| should be assigned to the Instant renderer, make its |
| 957 | // effective URL distinct from other URLs on the search provider's domain. |
| 958 | if (chrome::ShouldAssignURLToInstantRenderer(url, profile)) |
| 959 | return chrome::GetEffectiveURLForInstant(url, profile); |
| 960 | |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 961 | #if !defined(OS_CHROMEOS) |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 962 | // If the input |url| should be assigned to the Signin renderer, make its |
| 963 | // effective URL distinct from other URLs on the signin service's domain. |
| 964 | // Note that the signin renderer will be allowed to sign the user in to |
| 965 | // Chrome. |
| 966 | if (SigninManager::IsWebBasedSigninFlowURL(url)) |
| 967 | return GetEffectiveURLForSignin(url); |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 968 | #endif |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 969 | |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 970 | // If the input |url| is part of an installed app, the effective URL is an |
| 971 | // extension URL with the ID of that extension as the host. This has the |
| 972 | // effect of grouping apps together in a common SiteInstance. |
| 973 | ExtensionService* extension_service = |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 974 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 975 | if (!extension_service) |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 976 | return url; |
| 977 | |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 978 | const Extension* extension = extension_service->extensions()-> |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 979 | GetHostedAppByURL(url); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 980 | if (!extension) |
| 981 | return url; |
| 982 | |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 983 | // Bookmark apps do not use the hosted app process model, and should be |
| 984 | // treated as normal URLs. |
| 985 | if (extension->from_bookmark()) |
| 986 | return url; |
| 987 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 988 | // If the URL is part of an extension's web extent, convert it to an |
| 989 | // extension URL. |
| 990 | return extension->GetResourceURL(url.path()); |
| 991 | } |
| 992 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 993 | bool ChromeContentBrowserClient::ShouldUseProcessPerSite( |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 994 | content::BrowserContext* browser_context, const GURL& effective_url) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 995 | // Non-extension, non-Instant URLs should generally use |
| 996 | // process-per-site-instance. Because we expect to use the effective URL, |
| 997 | // URLs for hosted apps (apart from bookmark apps) should have an extension |
| 998 | // scheme by now. |
| 999 | |
| 1000 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1001 | if (!profile) |
| 1002 | return false; |
| 1003 | |
[email protected] | df113a1 | 2013-07-24 04:56:08 | [diff] [blame] | 1004 | if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile)) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1005 | return true; |
| 1006 | |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 1007 | #if !defined(OS_CHROMEOS) |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 1008 | if (SigninManager::IsWebBasedSigninFlowURL(effective_url)) |
| 1009 | return true; |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 1010 | #endif |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 1011 | |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 1012 | if (!effective_url.SchemeIs(extensions::kExtensionScheme)) |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1013 | return false; |
| 1014 | |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1015 | ExtensionService* extension_service = |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 1016 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 1017 | if (!extension_service) |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1018 | return false; |
| 1019 | |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 1020 | const Extension* extension = |
| 1021 | extension_service->extensions()->GetExtensionOrAppByURL(effective_url); |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1022 | if (!extension) |
| 1023 | return false; |
| 1024 | |
| 1025 | // 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] | 1026 | // permission, or that does not allow JavaScript access to the background |
| 1027 | // page, we want to give each instance its own process to improve |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1028 | // responsiveness. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1029 | if (extension->GetType() == Manifest::TYPE_HOSTED_APP) { |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1030 | if (!extension->HasAPIPermission(APIPermission::kBackground) || |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 1031 | !extensions::BackgroundInfo::AllowJSAccess(extension)) { |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 1032 | return false; |
| 1033 | } |
| 1034 | } |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1035 | |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 1036 | // Hosted apps that have script access to their background page must use |
| 1037 | // process per site, since all instances can make synchronous calls to the |
| 1038 | // background window. Other extensions should use process per site as well. |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1039 | return true; |
| 1040 | } |
| 1041 | |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 1042 | // These are treated as WebUI schemes but do not get WebUI bindings. |
[email protected] | 8f89dd41 | 2013-04-17 02:35:41 | [diff] [blame] | 1043 | void ChromeContentBrowserClient::GetAdditionalWebUISchemes( |
| 1044 | std::vector<std::string>* additional_schemes) { |
| 1045 | additional_schemes->push_back(chrome::kChromeSearchScheme); |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 1046 | } |
| 1047 | |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 1048 | net::URLRequestContextGetter* |
| 1049 | ChromeContentBrowserClient::CreateRequestContext( |
| 1050 | content::BrowserContext* browser_context, |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 1051 | content::ProtocolHandlerMap* protocol_handlers) { |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 1052 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 1053 | return profile->CreateRequestContext(protocol_handlers); |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | net::URLRequestContextGetter* |
| 1057 | ChromeContentBrowserClient::CreateRequestContextForStoragePartition( |
| 1058 | content::BrowserContext* browser_context, |
[email protected] | 152ea30 | 2013-02-11 04:08:40 | [diff] [blame] | 1059 | const base::FilePath& partition_path, |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 1060 | bool in_memory, |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 1061 | content::ProtocolHandlerMap* protocol_handlers) { |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 1062 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1063 | return profile->CreateRequestContextForStoragePartition( |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 1064 | partition_path, in_memory, protocol_handlers); |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 1065 | } |
| 1066 | |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 1067 | bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) { |
| 1068 | return ProfileIOData::IsHandledURL(url); |
| 1069 | } |
| 1070 | |
[email protected] | c4365fa4 | 2013-05-14 01:08:24 | [diff] [blame] | 1071 | bool ChromeContentBrowserClient::CanCommitURL( |
| 1072 | content::RenderProcessHost* process_host, |
| 1073 | const GURL& url) { |
| 1074 | // We need to let most extension URLs commit in any process, since this can |
| 1075 | // be allowed due to web_accessible_resources. Most hosted app URLs may also |
| 1076 | // load in any process (e.g., in an iframe). However, the Chrome Web Store |
| 1077 | // cannot be loaded in iframes and should never be requested outside its |
| 1078 | // process. |
| 1079 | Profile* profile = |
| 1080 | Profile::FromBrowserContext(process_host->GetBrowserContext()); |
| 1081 | ExtensionService* service = |
| 1082 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 1083 | if (!service) |
| 1084 | return true; |
| 1085 | const Extension* new_extension = |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 1086 | service->extensions()->GetExtensionOrAppByURL(url); |
[email protected] | c4365fa4 | 2013-05-14 01:08:24 | [diff] [blame] | 1087 | if (new_extension && |
| 1088 | new_extension->is_hosted_app() && |
| 1089 | new_extension->id() == extension_misc::kWebStoreAppId && |
| 1090 | !service->process_map()->Contains(new_extension->id(), |
| 1091 | process_host->GetID())) { |
| 1092 | return false; |
| 1093 | } |
| 1094 | |
| 1095 | return true; |
| 1096 | } |
| 1097 | |
[email protected] | 9a60d160 | 2013-09-11 04:09:12 | [diff] [blame] | 1098 | bool ChromeContentBrowserClient::ShouldAllowOpenURL( |
| 1099 | content::SiteInstance* site_instance, const GURL& url) { |
| 1100 | GURL from_url = site_instance->GetSiteURL(); |
| 1101 | // Do not allow pages from the web or other extensions navigate to |
| 1102 | // non-web-accessible extension resources. |
| 1103 | if (url.SchemeIs(extensions::kExtensionScheme) && |
| 1104 | (from_url.SchemeIsHTTPOrHTTPS() || |
| 1105 | from_url.SchemeIs(extensions::kExtensionScheme))) { |
| 1106 | Profile* profile = Profile::FromBrowserContext( |
| 1107 | site_instance->GetProcess()->GetBrowserContext()); |
| 1108 | ExtensionService* service = |
| 1109 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 1110 | if (!service) |
| 1111 | return true; |
| 1112 | const Extension* extension = |
| 1113 | service->extensions()->GetExtensionOrAppByURL(url); |
| 1114 | if (!extension) |
| 1115 | return true; |
| 1116 | const Extension* from_extension = |
| 1117 | service->extensions()->GetExtensionOrAppByURL( |
| 1118 | site_instance->GetSiteURL()); |
| 1119 | if (from_extension && from_extension->id() == extension->id()) |
| 1120 | return true; |
| 1121 | |
| 1122 | if (!extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible( |
| 1123 | extension, url.path())) |
| 1124 | return false; |
| 1125 | } |
| 1126 | return true; |
| 1127 | } |
| 1128 | |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1129 | bool ChromeContentBrowserClient::IsSuitableHost( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1130 | content::RenderProcessHost* process_host, |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1131 | const GURL& site_url) { |
| 1132 | Profile* profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1133 | Profile::FromBrowserContext(process_host->GetBrowserContext()); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1134 | // This may be NULL during tests. In that case, just assume any site can |
| 1135 | // share any host. |
| 1136 | if (!profile) |
| 1137 | return true; |
| 1138 | |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1139 | // Instant URLs should only be in the instant process and instant process |
| 1140 | // should only have Instant URLs. |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1141 | InstantService* instant_service = |
| 1142 | InstantServiceFactory::GetForProfile(profile); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1143 | if (instant_service) { |
| 1144 | bool is_instant_process = instant_service->IsInstantProcess( |
| 1145 | process_host->GetID()); |
| 1146 | bool should_be_in_instant_process = |
| 1147 | chrome::ShouldAssignURLToInstantRenderer(site_url, profile); |
| 1148 | if (is_instant_process || should_be_in_instant_process) |
| 1149 | return is_instant_process && should_be_in_instant_process; |
| 1150 | } |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1151 | |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 1152 | #if !defined(OS_CHROMEOS) |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 1153 | SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile); |
| 1154 | if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID())) |
| 1155 | return SigninManager::IsWebBasedSigninFlowURL(site_url); |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 1156 | #endif |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 1157 | |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 1158 | ExtensionService* service = |
| 1159 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1160 | extensions::ProcessMap* process_map = service->process_map(); |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1161 | |
[email protected] | ffa9760 | 2011-11-17 17:55:52 | [diff] [blame] | 1162 | // Don't allow the Task Manager to share a process with anything else. |
| 1163 | // Otherwise it can affect the renderers it is observing. |
| 1164 | // Note: we could create another RenderProcessHostPrivilege bucket for |
| 1165 | // this to allow multiple chrome://tasks instances to share, but that's |
| 1166 | // a very unlikely case without serious consequences. |
| 1167 | if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin()) |
| 1168 | return false; |
| 1169 | |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 1170 | // These may be NULL during tests. In that case, just assume any site can |
| 1171 | // share any host. |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1172 | if (!service || !process_map) |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1173 | return true; |
| 1174 | |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 1175 | // Otherwise, just make sure the process privilege matches the privilege |
| 1176 | // required by the site. |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 1177 | RenderProcessHostPrivilege privilege_required = |
| 1178 | GetPrivilegeRequiredByUrl(site_url, service); |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 1179 | return GetProcessPrivilege(process_host, process_map, service) == |
| 1180 | privilege_required; |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1181 | } |
| 1182 | |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1183 | // This function is trying to limit the amount of processes used by extensions |
| 1184 | // with background pages. It uses a globally set percentage of processes to |
| 1185 | // run such extensions and if the limit is exceeded, it returns true, to |
| 1186 | // indicate to the content module to group extensions together. |
| 1187 | bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost( |
| 1188 | content::BrowserContext* browser_context, const GURL& url) { |
| 1189 | // It has to be a valid URL for us to check for an extension. |
| 1190 | if (!url.is_valid()) |
| 1191 | return false; |
| 1192 | |
| 1193 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | 2ee3da9d6 | 2012-12-05 20:17:19 | [diff] [blame] | 1194 | ExtensionService* service = !profile ? NULL : |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 1195 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1196 | if (!service) |
| 1197 | return false; |
| 1198 | |
| 1199 | // We have to have a valid extension with background page to proceed. |
| 1200 | const Extension* extension = |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 1201 | service->extensions()->GetExtensionOrAppByURL(url); |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1202 | if (!extension) |
| 1203 | return false; |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 1204 | if (!extensions::BackgroundInfo::HasBackgroundPage(extension)) |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1205 | return false; |
| 1206 | |
| 1207 | std::set<int> process_ids; |
| 1208 | size_t max_process_count = |
| 1209 | content::RenderProcessHost::GetMaxRendererProcessCount(); |
| 1210 | |
| 1211 | // Go through all profiles to ensure we have total count of extension |
| 1212 | // processes containing background pages, otherwise one profile can |
| 1213 | // starve the other. |
| 1214 | std::vector<Profile*> profiles = g_browser_process->profile_manager()-> |
| 1215 | GetLoadedProfiles(); |
| 1216 | for (size_t i = 0; i < profiles.size(); ++i) { |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 1217 | extensions::ProcessManager* epm = |
[email protected] | be93bba0 | 2012-10-24 16:44:03 | [diff] [blame] | 1218 | extensions::ExtensionSystem::Get(profiles[i])->process_manager(); |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 1219 | for (extensions::ProcessManager::const_iterator iter = |
[email protected] | d1fe135 | 2012-04-26 00:47:32 | [diff] [blame] | 1220 | epm->background_hosts().begin(); |
| 1221 | iter != epm->background_hosts().end(); ++iter) { |
[email protected] | 3a1dc57 | 2012-07-31 22:25:13 | [diff] [blame] | 1222 | const extensions::ExtensionHost* host = *iter; |
[email protected] | d1fe135 | 2012-04-26 00:47:32 | [diff] [blame] | 1223 | process_ids.insert(host->render_process_host()->GetID()); |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | if (process_ids.size() > |
| 1228 | (max_process_count * chrome::kMaxShareOfExtensionProcesses)) { |
| 1229 | return true; |
| 1230 | } |
| 1231 | |
| 1232 | return false; |
| 1233 | } |
| 1234 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1235 | void ChromeContentBrowserClient::SiteInstanceGotProcess( |
| 1236 | SiteInstance* site_instance) { |
| 1237 | CHECK(site_instance->HasProcess()); |
| 1238 | |
| 1239 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 72daaa9 | 2012-01-18 13:39:02 | [diff] [blame] | 1240 | site_instance->GetBrowserContext()); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1241 | if (!profile) |
| 1242 | return; |
| 1243 | |
| 1244 | // Remember the ID of the Instant process to signal the renderer process |
| 1245 | // on startup in |AppendExtraCommandLineSwitches| below. |
[email protected] | 165fe42 | 2013-03-27 06:34:03 | [diff] [blame] | 1246 | if (chrome::ShouldAssignURLToInstantRenderer( |
[email protected] | 7c60f504 | 2013-02-14 03:39:32 | [diff] [blame] | 1247 | site_instance->GetSiteURL(), profile)) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1248 | InstantService* instant_service = |
| 1249 | InstantServiceFactory::GetForProfile(profile); |
| 1250 | if (instant_service) |
| 1251 | instant_service->AddInstantProcess(site_instance->GetProcess()->GetID()); |
| 1252 | } |
| 1253 | |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 1254 | #if !defined(OS_CHROMEOS) |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 1255 | // We only expect there to be one signin process as we use process-per-site |
| 1256 | // for signin URLs. The signin process will be cleared from SigninManager |
| 1257 | // when the renderer is destroyed. |
| 1258 | if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) { |
| 1259 | SigninManager* signin_manager = |
| 1260 | SigninManagerFactory::GetForProfile(profile); |
| 1261 | if (signin_manager) |
| 1262 | signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID()); |
[email protected] | 1deace2 | 2013-05-22 06:14:46 | [diff] [blame] | 1263 | BrowserThread::PostTask( |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 1264 | BrowserThread::IO, |
| 1265 | FROM_HERE, |
| 1266 | base::Bind(&InfoMap::SetSigninProcess, |
[email protected] | 1deace2 | 2013-05-22 06:14:46 | [diff] [blame] | 1267 | extensions::ExtensionSystem::Get(profile)->info_map(), |
| 1268 | site_instance->GetProcess()->GetID())); |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 1269 | } |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 1270 | #endif |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 1271 | |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 1272 | ExtensionService* service = |
| 1273 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1274 | if (!service) |
| 1275 | return; |
| 1276 | |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 1277 | const Extension* extension = service->extensions()->GetExtensionOrAppByURL( |
| 1278 | site_instance->GetSiteURL()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1279 | if (!extension) |
| 1280 | return; |
| 1281 | |
[email protected] | 6bc04fd8 | 2011-12-04 02:29:35 | [diff] [blame] | 1282 | service->process_map()->Insert(extension->id(), |
| 1283 | site_instance->GetProcess()->GetID(), |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 1284 | site_instance->GetId()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1285 | BrowserThread::PostTask( |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 1286 | BrowserThread::IO, |
| 1287 | FROM_HERE, |
| 1288 | base::Bind(&InfoMap::RegisterExtensionProcess, |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 1289 | extensions::ExtensionSystem::Get(profile)->info_map(), |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1290 | extension->id(), |
[email protected] | 6bc04fd8 | 2011-12-04 02:29:35 | [diff] [blame] | 1291 | site_instance->GetProcess()->GetID(), |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 1292 | site_instance->GetId())); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | void ChromeContentBrowserClient::SiteInstanceDeleting( |
| 1296 | SiteInstance* site_instance) { |
| 1297 | if (!site_instance->HasProcess()) |
| 1298 | return; |
| 1299 | |
| 1300 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 72daaa9 | 2012-01-18 13:39:02 | [diff] [blame] | 1301 | site_instance->GetBrowserContext()); |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 1302 | ExtensionService* service = |
| 1303 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1304 | if (!service) |
| 1305 | return; |
| 1306 | |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 1307 | const Extension* extension = service->extensions()->GetExtensionOrAppByURL( |
| 1308 | site_instance->GetSiteURL()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1309 | if (!extension) |
| 1310 | return; |
| 1311 | |
[email protected] | 6bc04fd8 | 2011-12-04 02:29:35 | [diff] [blame] | 1312 | service->process_map()->Remove(extension->id(), |
| 1313 | site_instance->GetProcess()->GetID(), |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 1314 | site_instance->GetId()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1315 | BrowserThread::PostTask( |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 1316 | BrowserThread::IO, |
| 1317 | FROM_HERE, |
| 1318 | base::Bind(&InfoMap::UnregisterExtensionProcess, |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 1319 | extensions::ExtensionSystem::Get(profile)->info_map(), |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1320 | extension->id(), |
[email protected] | 6bc04fd8 | 2011-12-04 02:29:35 | [diff] [blame] | 1321 | site_instance->GetProcess()->GetID(), |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 1322 | site_instance->GetId())); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1323 | } |
| 1324 | |
[email protected] | 453f543 | 2013-11-26 19:43:00 | [diff] [blame^] | 1325 | bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation( |
[email protected] | e9841fbd | 2013-02-22 23:12:14 | [diff] [blame] | 1326 | SiteInstance* site_instance, |
[email protected] | e3daf3c | 2011-10-05 21:17:08 | [diff] [blame] | 1327 | const GURL& current_url, |
| 1328 | const GURL& new_url) { |
[email protected] | f0576397 | 2012-06-06 18:17:26 | [diff] [blame] | 1329 | if (current_url.is_empty()) { |
| 1330 | // Always choose a new process when navigating to extension URLs. The |
| 1331 | // process grouping logic will combine all of a given extension's pages |
| 1332 | // into the same process. |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 1333 | if (new_url.SchemeIs(extensions::kExtensionScheme)) |
[email protected] | f0576397 | 2012-06-06 18:17:26 | [diff] [blame] | 1334 | return true; |
[email protected] | e3daf3c | 2011-10-05 21:17:08 | [diff] [blame] | 1335 | |
[email protected] | f0576397 | 2012-06-06 18:17:26 | [diff] [blame] | 1336 | return false; |
| 1337 | } |
| 1338 | |
| 1339 | // Also, we must switch if one is an extension and the other is not the exact |
| 1340 | // same extension. |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 1341 | if (current_url.SchemeIs(extensions::kExtensionScheme) || |
| 1342 | new_url.SchemeIs(extensions::kExtensionScheme)) { |
[email protected] | f0576397 | 2012-06-06 18:17:26 | [diff] [blame] | 1343 | if (current_url.GetOrigin() != new_url.GetOrigin()) |
| 1344 | return true; |
| 1345 | } |
| 1346 | |
[email protected] | e9841fbd | 2013-02-22 23:12:14 | [diff] [blame] | 1347 | // The checks below only matter if we can retrieve which extensions are |
| 1348 | // installed. |
| 1349 | Profile* profile = |
| 1350 | Profile::FromBrowserContext(site_instance->GetBrowserContext()); |
| 1351 | ExtensionService* service = |
| 1352 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 1353 | if (!service) |
| 1354 | return false; |
| 1355 | |
| 1356 | // We must swap if the URL is for an extension and we are not using an |
| 1357 | // extension process. |
| 1358 | const Extension* new_extension = |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 1359 | service->extensions()->GetExtensionOrAppByURL(new_url); |
[email protected] | e9841fbd | 2013-02-22 23:12:14 | [diff] [blame] | 1360 | // Ignore all hosted apps except the Chrome Web Store, since they do not |
| 1361 | // require their own BrowsingInstance (e.g., postMessage is ok). |
| 1362 | if (new_extension && |
| 1363 | new_extension->is_hosted_app() && |
| 1364 | new_extension->id() != extension_misc::kWebStoreAppId) |
| 1365 | new_extension = NULL; |
| 1366 | if (new_extension && |
| 1367 | site_instance->HasProcess() && |
| 1368 | !service->process_map()->Contains(new_extension->id(), |
| 1369 | site_instance->GetProcess()->GetID())) |
| 1370 | return true; |
| 1371 | |
[email protected] | f0576397 | 2012-06-06 18:17:26 | [diff] [blame] | 1372 | return false; |
[email protected] | e3daf3c | 2011-10-05 21:17:08 | [diff] [blame] | 1373 | } |
| 1374 | |
[email protected] | 395045c | 2012-05-22 15:04:38 | [diff] [blame] | 1375 | bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect( |
| 1376 | content::ResourceContext* resource_context, const GURL& current_url, |
| 1377 | const GURL& new_url) { |
| 1378 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
| 1379 | return extensions::CrossesExtensionProcessBoundary( |
| 1380 | io_data->GetExtensionInfoMap()->extensions(), |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 1381 | current_url, new_url, false); |
[email protected] | 395045c | 2012-05-22 15:04:38 | [diff] [blame] | 1382 | } |
| 1383 | |
[email protected] | 3d83199 | 2013-07-04 01:13:29 | [diff] [blame] | 1384 | bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) { |
| 1385 | return !url.SchemeIs(chrome::kChromeNativeScheme); |
| 1386 | } |
| 1387 | |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 1388 | std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName( |
| 1389 | const std::string& alias_name) { |
| 1390 | return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name); |
| 1391 | } |
| 1392 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1393 | void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( |
| 1394 | CommandLine* command_line, int child_process_id) { |
[email protected] | 264c0acac | 2013-10-01 13:33:30 | [diff] [blame] | 1395 | #if defined(OS_POSIX) |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 1396 | if (breakpad::IsCrashReporterEnabled()) { |
[email protected] | 264c0acac | 2013-10-01 13:33:30 | [diff] [blame] | 1397 | std::string enable_crash_reporter; |
| 1398 | GoogleUpdateSettings::GetMetricsId(&enable_crash_reporter); |
| 1399 | #if !defined(OS_MACOSX) |
| 1400 | enable_crash_reporter += "," + base::GetLinuxDistro(); |
| 1401 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1402 | command_line->AppendSwitchASCII(switches::kEnableCrashReporter, |
[email protected] | 264c0acac | 2013-10-01 13:33:30 | [diff] [blame] | 1403 | enable_crash_reporter); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1404 | } |
[email protected] | 264c0acac | 2013-10-01 13:33:30 | [diff] [blame] | 1405 | #endif // OS_POSIX |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1406 | |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 1407 | if (logging::DialogsAreSuppressed()) |
| 1408 | command_line->AppendSwitch(switches::kNoErrorDialogs); |
| 1409 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1410 | std::string process_type = |
| 1411 | command_line->GetSwitchValueASCII(switches::kProcessType); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 1412 | const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 9206f2a0 | 2013-03-20 01:10:32 | [diff] [blame] | 1413 | |
[email protected] | 7c9b6f9 | 2013-09-10 18:11:35 | [diff] [blame] | 1414 | static const char* const kCommonSwitchNames[] = { |
| 1415 | switches::kChromeFrame, |
| 1416 | switches::kUserDataDir, // Make logs go to the right file. |
| 1417 | }; |
| 1418 | command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames, |
| 1419 | arraysize(kCommonSwitchNames)); |
[email protected] | 9206f2a0 | 2013-03-20 01:10:32 | [diff] [blame] | 1420 | |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 1421 | if (process_type == switches::kRendererProcess) { |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1422 | #if defined(OS_CHROMEOS) |
| 1423 | const std::string& login_profile = |
[email protected] | 931d104 | 2013-04-05 17:50:44 | [diff] [blame] | 1424 | browser_command_line.GetSwitchValueASCII( |
| 1425 | chromeos::switches::kLoginProfile); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1426 | if (!login_profile.empty()) |
[email protected] | 931d104 | 2013-04-05 17:50:44 | [diff] [blame] | 1427 | command_line->AppendSwitchASCII( |
| 1428 | chromeos::switches::kLoginProfile, login_profile); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1429 | #endif |
| 1430 | |
[email protected] | 50fa4d5f | 2013-11-05 00:53:23 | [diff] [blame] | 1431 | #if defined(ENABLE_WEBRTC) |
| 1432 | if (VersionInfo::GetChannel() <= VersionInfo::CHANNEL_DEV) { |
| 1433 | static const char* const kWebRtcDevSwitchNames[] = { |
| 1434 | switches::kDisableWebRtcEncryption, |
| 1435 | }; |
| 1436 | command_line->CopySwitchesFrom(browser_command_line, |
| 1437 | kWebRtcDevSwitchNames, |
| 1438 | arraysize(kWebRtcDevSwitchNames)); |
| 1439 | } |
| 1440 | #endif |
| 1441 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1442 | content::RenderProcessHost* process = |
| 1443 | content::RenderProcessHost::FromID(child_process_id); |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 1444 | if (process) { |
| 1445 | Profile* profile = Profile::FromBrowserContext( |
| 1446 | process->GetBrowserContext()); |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 1447 | ExtensionService* extension_service = |
| 1448 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 1449 | if (extension_service) { |
| 1450 | extensions::ProcessMap* process_map = extension_service->process_map(); |
[email protected] | 433669fd | 2013-10-31 22:07:10 | [diff] [blame] | 1451 | if (process_map && process_map->Contains(process->GetID())) |
[email protected] | c8598d4 | 2012-09-25 21:17:00 | [diff] [blame] | 1452 | command_line->AppendSwitch(switches::kExtensionProcess); |
| 1453 | } |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1454 | |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 1455 | PrefService* prefs = profile->GetPrefs(); |
| 1456 | // Currently this pref is only registered if applied via a policy. |
| 1457 | if (prefs->HasPrefPath(prefs::kDisable3DAPIs) && |
| 1458 | prefs->GetBoolean(prefs::kDisable3DAPIs)) { |
| 1459 | // Turn this policy into a command line switch. |
| 1460 | command_line->AppendSwitch(switches::kDisable3DAPIs); |
| 1461 | } |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 1462 | |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 1463 | // Disable client-side phishing detection in the renderer if it is |
| 1464 | // disabled in the Profile preferences or the browser process. |
| 1465 | if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) || |
| 1466 | !g_browser_process->safe_browsing_detection_service()) { |
| 1467 | command_line->AppendSwitch( |
| 1468 | switches::kDisableClientSidePhishingDetection); |
| 1469 | } |
[email protected] | 0045b0f4 | 2012-07-26 11:52:08 | [diff] [blame] | 1470 | |
| 1471 | if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled)) |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 1472 | command_line->AppendSwitch(switches::kRendererPrintPreview); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1473 | |
| 1474 | InstantService* instant_service = |
| 1475 | InstantServiceFactory::GetForProfile(profile); |
| 1476 | if (instant_service && |
| 1477 | instant_service->IsInstantProcess(process->GetID())) |
| 1478 | command_line->AppendSwitch(switches::kInstantProcess); |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 1479 | |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 1480 | #if !defined(OS_CHROMEOS) |
[email protected] | 970c63e | 2013-03-07 00:25:30 | [diff] [blame] | 1481 | SigninManager* signin_manager = |
| 1482 | SigninManagerFactory::GetForProfile(profile); |
| 1483 | if (signin_manager && signin_manager->IsSigninProcess(process->GetID())) |
| 1484 | command_line->AppendSwitch(switches::kSigninProcess); |
[email protected] | d5bcd06f | 2013-04-21 08:07:24 | [diff] [blame] | 1485 | #endif |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 1486 | } |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1487 | |
[email protected] | 16dc4245 | 2013-04-09 04:37:19 | [diff] [blame] | 1488 | if (message_center::IsRichNotificationEnabled()) |
| 1489 | command_line->AppendSwitch(switches::kDisableHTMLNotifications); |
[email protected] | 16dc4245 | 2013-04-09 04:37:19 | [diff] [blame] | 1490 | |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 1491 | // Please keep this in alphabetical order. |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1492 | static const char* const kSwitchNames[] = { |
[email protected] | 000f3ad | 2013-05-16 02:19:17 | [diff] [blame] | 1493 | autofill::switches::kDisableInteractiveAutocomplete, |
[email protected] | c3cc063 | 2013-10-03 21:54:43 | [diff] [blame] | 1494 | autofill::switches::kDisablePasswordGeneration, |
[email protected] | 000f3ad | 2013-05-16 02:19:17 | [diff] [blame] | 1495 | autofill::switches::kEnableInteractiveAutocomplete, |
[email protected] | c3cc063 | 2013-10-03 21:54:43 | [diff] [blame] | 1496 | autofill::switches::kEnablePasswordGeneration, |
[email protected] | 5c42c37 | 2013-10-17 15:06:10 | [diff] [blame] | 1497 | autofill::switches::kNoAutofillNecessaryForPasswordGeneration, |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 1498 | extensions::switches::kAllowHTTPBackgroundPage, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 1499 | extensions::switches::kAllowLegacyExtensionManifests, |
| 1500 | extensions::switches::kAllowScriptingGallery, |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 1501 | extensions::switches::kEnableExperimentalExtensionApis, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 1502 | extensions::switches::kExtensionsOnChromeURLs, |
[email protected] | 9d45049 | 2013-06-13 23:08:37 | [diff] [blame] | 1503 | // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO |
| 1504 | // to browser. |
| 1505 | switches::kAllowNaClFileHandleAPI, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1506 | switches::kAppsCheckoutURL, |
| 1507 | switches::kAppsGalleryURL, |
[email protected] | be9d9c8 | 2011-07-13 04:17:31 | [diff] [blame] | 1508 | switches::kCloudPrintServiceURL, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1509 | switches::kDebugPrint, |
[email protected] | 382fb0d | 2012-02-25 00:19:50 | [diff] [blame] | 1510 | switches::kDisableBundledPpapiFlash, |
[email protected] | e9dfe22 | 2012-05-11 22:05:53 | [diff] [blame] | 1511 | switches::kDisableExtensionsResourceWhitelist, |
[email protected] | 83c8526 | 2013-08-22 21:13:46 | [diff] [blame] | 1512 | switches::kDisablePnacl, |
[email protected] | b0553c7e | 2012-09-19 21:36:11 | [diff] [blame] | 1513 | switches::kDisableScriptedPrintThrottling, |
[email protected] | e9cddd5 | 2013-03-23 17:37:53 | [diff] [blame] | 1514 | switches::kEnableAdview, |
| 1515 | switches::kEnableAdviewSrcAttribute, |
[email protected] | 1f4da9e | 2013-06-27 05:23:44 | [diff] [blame] | 1516 | switches::kEnableAppWindowControls, |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 1517 | switches::kEnableBenchmarking, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1518 | switches::kEnableNaCl, |
[email protected] | ce304ce | 2013-02-22 21:54:45 | [diff] [blame] | 1519 | switches::kEnableNetBenchmarking, |
[email protected] | c9043a88 | 2013-11-16 00:06:00 | [diff] [blame] | 1520 | switches::kEnableProxyPreconnectHints, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1521 | switches::kEnableWatchdog, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1522 | switches::kMemoryProfiling, |
| 1523 | switches::kMessageLoopHistogrammer, |
[email protected] | f45c5f3 | 2012-04-18 19:26:37 | [diff] [blame] | 1524 | switches::kNoJsRandomness, |
[email protected] | 8f06e4d | 2013-11-25 23:20:18 | [diff] [blame] | 1525 | switches::kOutOfProcessPdf, |
[email protected] | f45c5f3 | 2012-04-18 19:26:37 | [diff] [blame] | 1526 | switches::kPlaybackMode, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1527 | switches::kPpapiFlashArgs, |
| 1528 | switches::kPpapiFlashInProcess, |
| 1529 | switches::kPpapiFlashPath, |
| 1530 | switches::kPpapiFlashVersion, |
| 1531 | switches::kProfilingAtStart, |
| 1532 | switches::kProfilingFile, |
| 1533 | switches::kProfilingFlush, |
[email protected] | f45c5f3 | 2012-04-18 19:26:37 | [diff] [blame] | 1534 | switches::kRecordMode, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1535 | switches::kSilentDumpOnDCHECK, |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 1536 | switches::kWhitelistedExtensionID, |
[email protected] | 499e7c5 | 2013-10-04 16:03:09 | [diff] [blame] | 1537 | translate::switches::kTranslateSecurityOrigin, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1538 | }; |
| 1539 | |
| 1540 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 1541 | arraysize(kSwitchNames)); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 1542 | } else if (process_type == switches::kUtilityProcess) { |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 1543 | static const char* const kSwitchNames[] = { |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 1544 | extensions::switches::kAllowHTTPBackgroundPage, |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 1545 | extensions::switches::kEnableExperimentalExtensionApis, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 1546 | extensions::switches::kExtensionsOnChromeURLs, |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 1547 | switches::kWhitelistedExtensionID, |
| 1548 | }; |
| 1549 | |
| 1550 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 1551 | arraysize(kSwitchNames)); |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1552 | } else if (process_type == switches::kPluginProcess) { |
| 1553 | static const char* const kSwitchNames[] = { |
[email protected] | 931d104 | 2013-04-05 17:50:44 | [diff] [blame] | 1554 | #if defined(OS_CHROMEOS) |
| 1555 | chromeos::switches::kLoginProfile, |
| 1556 | #endif |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1557 | switches::kMemoryProfiling, |
| 1558 | switches::kSilentDumpOnDCHECK, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1559 | }; |
| 1560 | |
| 1561 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 1562 | arraysize(kSwitchNames)); |
| 1563 | } else if (process_type == switches::kZygoteProcess) { |
| 1564 | static const char* const kSwitchNames[] = { |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1565 | // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox. |
[email protected] | 382fb0d | 2012-02-25 00:19:50 | [diff] [blame] | 1566 | switches::kDisableBundledPpapiFlash, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 1567 | switches::kPpapiFlashInProcess, |
| 1568 | switches::kPpapiFlashPath, |
| 1569 | switches::kPpapiFlashVersion, |
| 1570 | }; |
| 1571 | |
| 1572 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 1573 | arraysize(kSwitchNames)); |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 1574 | } else if (process_type == switches::kGpuProcess) { |
| 1575 | // If --ignore-gpu-blacklist is passed in, don't send in crash reports |
| 1576 | // because GPU is expected to be unreliable. |
| 1577 | if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) && |
| 1578 | !command_line->HasSwitch(switches::kDisableBreakpad)) |
| 1579 | command_line->AppendSwitch(switches::kDisableBreakpad); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1580 | } |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 1581 | |
| 1582 | // The command line switch kEnableBenchmarking needs to be specified along |
| 1583 | // with the kEnableStatsTable switch to ensure that the stats table global |
| 1584 | // is initialized correctly. |
| 1585 | if (command_line->HasSwitch(switches::kEnableBenchmarking)) |
| 1586 | DCHECK(command_line->HasSwitch(switches::kEnableStatsTable)); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | std::string ChromeContentBrowserClient::GetApplicationLocale() { |
[email protected] | e9a32a5 | 2012-06-14 23:32:43 | [diff] [blame] | 1590 | if (BrowserThread::CurrentlyOn(BrowserThread::IO)) |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 1591 | return g_io_thread_application_locale.Get(); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1592 | return g_browser_process->GetApplicationLocale(); |
| 1593 | } |
| 1594 | |
[email protected] | 597a867b | 2011-11-18 18:31:20 | [diff] [blame] | 1595 | std::string ChromeContentBrowserClient::GetAcceptLangs( |
| 1596 | content::BrowserContext* context) { |
| 1597 | Profile* profile = Profile::FromBrowserContext(context); |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1598 | return profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 1599 | } |
| 1600 | |
[email protected] | 9ec0f45 | 2012-05-31 15:58:53 | [diff] [blame] | 1601 | gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() { |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 1602 | ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
[email protected] | 9ec0f45 | 2012-05-31 15:58:53 | [diff] [blame] | 1603 | return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON); |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 1604 | } |
| 1605 | |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 1606 | bool ChromeContentBrowserClient::AllowAppCache( |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 1607 | const GURL& manifest_url, |
[email protected] | 0a60884 | 2011-09-08 10:55:19 | [diff] [blame] | 1608 | const GURL& first_party, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1609 | content::ResourceContext* context) { |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 1610 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1611 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 1612 | return io_data->GetCookieSettings()-> |
| 1613 | IsSettingCookieAllowed(manifest_url, first_party); |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 1614 | } |
| 1615 | |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 1616 | bool ChromeContentBrowserClient::AllowGetCookie( |
| 1617 | const GURL& url, |
| 1618 | const GURL& first_party, |
| 1619 | const net::CookieList& cookie_list, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1620 | content::ResourceContext* context, |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 1621 | int render_process_id, |
| 1622 | int render_view_id) { |
| 1623 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1624 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 1625 | bool allow = io_data->GetCookieSettings()-> |
| 1626 | IsReadingCookieAllowed(url, first_party); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 1627 | |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 1628 | BrowserThread::PostTask( |
| 1629 | BrowserThread::UI, FROM_HERE, |
[email protected] | 317c58f0 | 2011-11-09 02:15:03 | [diff] [blame] | 1630 | base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id, |
[email protected] | fd473d1 | 2012-04-05 11:38:43 | [diff] [blame] | 1631 | render_view_id, url, first_party, cookie_list, !allow)); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 1632 | return allow; |
| 1633 | } |
| 1634 | |
| 1635 | bool ChromeContentBrowserClient::AllowSetCookie( |
| 1636 | const GURL& url, |
| 1637 | const GURL& first_party, |
| 1638 | const std::string& cookie_line, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1639 | content::ResourceContext* context, |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 1640 | int render_process_id, |
| 1641 | int render_view_id, |
| 1642 | net::CookieOptions* options) { |
| 1643 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1644 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 1645 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 1646 | bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party); |
| 1647 | |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 1648 | BrowserThread::PostTask( |
| 1649 | BrowserThread::UI, FROM_HERE, |
[email protected] | 317c58f0 | 2011-11-09 02:15:03 | [diff] [blame] | 1650 | base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id, |
[email protected] | fd473d1 | 2012-04-05 11:38:43 | [diff] [blame] | 1651 | render_view_id, url, first_party, cookie_line, *options, |
| 1652 | !allow)); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 1653 | return allow; |
| 1654 | } |
| 1655 | |
[email protected] | d5a1916 | 2011-06-30 18:51:54 | [diff] [blame] | 1656 | bool ChromeContentBrowserClient::AllowSaveLocalState( |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1657 | content::ResourceContext* context) { |
[email protected] | d5a1916 | 2011-06-30 18:51:54 | [diff] [blame] | 1658 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1659 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | bf510ed | 2012-06-05 08:31:43 | [diff] [blame] | 1660 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 1661 | ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL); |
[email protected] | 1848cdc | 2012-02-17 10:48:26 | [diff] [blame] | 1662 | |
[email protected] | bf510ed | 2012-06-05 08:31:43 | [diff] [blame] | 1663 | // TODO(bauerb): Should we also disallow local state if the default is BLOCK? |
| 1664 | // Could we even support per-origin settings? |
| 1665 | return setting != CONTENT_SETTING_SESSION_ONLY; |
[email protected] | d5a1916 | 2011-06-30 18:51:54 | [diff] [blame] | 1666 | } |
| 1667 | |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1668 | bool ChromeContentBrowserClient::AllowWorkerDatabase( |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1669 | const GURL& url, |
| 1670 | const string16& name, |
| 1671 | const string16& display_name, |
| 1672 | unsigned long estimated_size, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1673 | content::ResourceContext* context, |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 1674 | const std::vector<std::pair<int, int> >& render_views) { |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1675 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1676 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1677 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 1678 | bool allow = cookie_settings->IsSettingCookieAllowed(url, url); |
| 1679 | |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 1680 | // Record access to database for potential display in UI. |
| 1681 | std::vector<std::pair<int, int> >::const_iterator i; |
| 1682 | for (i = render_views.begin(); i != render_views.end(); ++i) { |
| 1683 | BrowserThread::PostTask( |
| 1684 | BrowserThread::UI, FROM_HERE, |
| 1685 | base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed, |
| 1686 | i->first, i->second, url, name, display_name, !allow)); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | return allow; |
| 1690 | } |
| 1691 | |
| 1692 | bool ChromeContentBrowserClient::AllowWorkerFileSystem( |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1693 | const GURL& url, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1694 | content::ResourceContext* context, |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 1695 | const std::vector<std::pair<int, int> >& render_views) { |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1696 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1697 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1698 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 1699 | bool allow = cookie_settings->IsSettingCookieAllowed(url, url); |
| 1700 | |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 1701 | // Record access to file system for potential display in UI. |
| 1702 | std::vector<std::pair<int, int> >::const_iterator i; |
| 1703 | for (i = render_views.begin(); i != render_views.end(); ++i) { |
| 1704 | BrowserThread::PostTask( |
| 1705 | BrowserThread::UI, FROM_HERE, |
| 1706 | base::Bind(&TabSpecificContentSettings::FileSystemAccessed, |
| 1707 | i->first, i->second, url, !allow)); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | return allow; |
| 1711 | } |
| 1712 | |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 1713 | bool ChromeContentBrowserClient::AllowWorkerIndexedDB( |
| 1714 | const GURL& url, |
| 1715 | const string16& name, |
| 1716 | content::ResourceContext* context, |
| 1717 | const std::vector<std::pair<int, int> >& render_views) { |
| 1718 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1719 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
| 1720 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 1721 | bool allow = cookie_settings->IsSettingCookieAllowed(url, url); |
| 1722 | |
| 1723 | // Record access to IndexedDB for potential display in UI. |
| 1724 | std::vector<std::pair<int, int> >::const_iterator i; |
| 1725 | for (i = render_views.begin(); i != render_views.end(); ++i) { |
| 1726 | BrowserThread::PostTask( |
| 1727 | BrowserThread::UI, FROM_HERE, |
| 1728 | base::Bind(&TabSpecificContentSettings::IndexedDBAccessed, |
| 1729 | i->first, i->second, url, name, !allow)); |
| 1730 | } |
| 1731 | |
| 1732 | return allow; |
| 1733 | } |
| 1734 | |
[email protected] | 33ad6ce9 | 2013-08-27 14:39:08 | [diff] [blame] | 1735 | net::URLRequestContext* |
| 1736 | ChromeContentBrowserClient::OverrideRequestContextForURL( |
| 1737 | const GURL& url, content::ResourceContext* context) { |
| 1738 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1739 | if (url.SchemeIs(extensions::kExtensionScheme)) { |
| 1740 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
| 1741 | return io_data->extensions_request_context(); |
| 1742 | } |
| 1743 | |
| 1744 | return NULL; |
| 1745 | } |
| 1746 | |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 1747 | QuotaPermissionContext* |
| 1748 | ChromeContentBrowserClient::CreateQuotaPermissionContext() { |
| 1749 | return new ChromeQuotaPermissionContext(); |
| 1750 | } |
| 1751 | |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 1752 | void ChromeContentBrowserClient::AllowCertificateError( |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 1753 | int render_process_id, |
| 1754 | int render_view_id, |
| 1755 | int cert_error, |
| 1756 | const net::SSLInfo& ssl_info, |
| 1757 | const GURL& request_url, |
[email protected] | a2f7688 | 2013-02-25 21:36:02 | [diff] [blame] | 1758 | ResourceType::Type resource_type, |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 1759 | bool overridable, |
[email protected] | d9be4770 | 2012-05-16 03:41:22 | [diff] [blame] | 1760 | bool strict_enforcement, |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 1761 | const base::Callback<void(bool)>& callback, |
[email protected] | 8c965c2 | 2013-05-23 19:28:00 | [diff] [blame] | 1762 | content::CertificateRequestResultType* result) { |
[email protected] | a2f7688 | 2013-02-25 21:36:02 | [diff] [blame] | 1763 | if (resource_type != ResourceType::MAIN_FRAME) { |
| 1764 | // A sub-resource has a certificate error. The user doesn't really |
| 1765 | // have a context for making the right decision, so block the |
| 1766 | // request hard, without an info bar to allow showing the insecure |
| 1767 | // content. |
[email protected] | 8c965c2 | 2013-05-23 19:28:00 | [diff] [blame] | 1768 | *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY; |
[email protected] | a2f7688 | 2013-02-25 21:36:02 | [diff] [blame] | 1769 | return; |
| 1770 | } |
| 1771 | |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 1772 | // If the tab is being prerendered, cancel the prerender and the request. |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 1773 | WebContents* tab = tab_util::GetWebContentsByID( |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 1774 | render_process_id, render_view_id); |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 1775 | if (!tab) { |
| 1776 | NOTREACHED(); |
| 1777 | return; |
| 1778 | } |
| 1779 | prerender::PrerenderManager* prerender_manager = |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 1780 | prerender::PrerenderManagerFactory::GetForProfile( |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 1781 | Profile::FromBrowserContext(tab->GetBrowserContext())); |
[email protected] | 3a6ec76 | 2012-10-17 16:01:01 | [diff] [blame] | 1782 | if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab, |
| 1783 | NULL)) { |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 1784 | if (prerender_manager->prerender_tracker()->TryCancel( |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 1785 | render_process_id, render_view_id, |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 1786 | prerender::FINAL_STATUS_SSL_ERROR)) { |
[email protected] | 8c965c2 | 2013-05-23 19:28:00 | [diff] [blame] | 1787 | *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL; |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 1788 | return; |
| 1789 | } |
| 1790 | } |
| 1791 | |
[email protected] | 1e87df3 | 2012-09-12 04:53:19 | [diff] [blame] | 1792 | #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
[email protected] | eb0b9dd | 2012-09-19 21:36:23 | [diff] [blame] | 1793 | captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper = |
| 1794 | captive_portal::CaptivePortalTabHelper::FromWebContents(tab); |
| 1795 | if (captive_portal_tab_helper) |
| 1796 | captive_portal_tab_helper->OnSSLCertError(ssl_info); |
[email protected] | 1e87df3 | 2012-09-12 04:53:19 | [diff] [blame] | 1797 | #endif |
| 1798 | |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 1799 | // Otherwise, display an SSL blocking page. |
[email protected] | d9be4770 | 2012-05-16 03:41:22 | [diff] [blame] | 1800 | new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable, |
| 1801 | strict_enforcement, callback); |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 1802 | } |
| 1803 | |
[email protected] | c99c442e | 2011-08-24 11:37:30 | [diff] [blame] | 1804 | void ChromeContentBrowserClient::SelectClientCertificate( |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 1805 | int render_process_id, |
| 1806 | int render_view_id, |
[email protected] | 7a593db | 2012-02-13 21:19:40 | [diff] [blame] | 1807 | const net::HttpNetworkSession* network_session, |
| 1808 | net::SSLCertRequestInfo* cert_request_info, |
| 1809 | const base::Callback<void(net::X509Certificate*)>& callback) { |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 1810 | WebContents* tab = tab_util::GetWebContentsByID( |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 1811 | render_process_id, render_view_id); |
| 1812 | if (!tab) { |
| 1813 | NOTREACHED(); |
| 1814 | return; |
| 1815 | } |
| 1816 | |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1817 | GURL requesting_url("https://" + cert_request_info->host_and_port); |
| 1818 | DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://" |
| 1819 | << cert_request_info->host_and_port; |
| 1820 | |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 1821 | Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1822 | scoped_ptr<Value> filter( |
| 1823 | profile->GetHostContentSettingsMap()->GetWebsiteSetting( |
| 1824 | requesting_url, |
| 1825 | requesting_url, |
| 1826 | CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
| 1827 | std::string(), NULL)); |
| 1828 | |
| 1829 | if (filter.get()) { |
| 1830 | // Try to automatically select a client certificate. |
| 1831 | if (filter->IsType(Value::TYPE_DICTIONARY)) { |
| 1832 | DictionaryValue* filter_dict = |
| 1833 | static_cast<DictionaryValue*>(filter.get()); |
| 1834 | |
| 1835 | const std::vector<scoped_refptr<net::X509Certificate> >& |
| 1836 | all_client_certs = cert_request_info->client_certs; |
| 1837 | for (size_t i = 0; i < all_client_certs.size(); ++i) { |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1838 | if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) { |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1839 | // Use the first certificate that is matched by the filter. |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1840 | callback.Run(all_client_certs[i].get()); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1841 | return; |
| 1842 | } |
| 1843 | } |
| 1844 | } else { |
| 1845 | NOTREACHED(); |
| 1846 | } |
| 1847 | } |
| 1848 | |
[email protected] | 11feec32 | 2012-09-18 03:58:52 | [diff] [blame] | 1849 | SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab); |
| 1850 | if (!ssl_tab_helper) { |
| 1851 | // If there is no SSLTabHelper for the given WebContents then we can't |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1852 | // show the user a dialog to select a client certificate. So we simply |
[email protected] | 2a349e9 | 2011-12-07 12:00:14 | [diff] [blame] | 1853 | // proceed with no client certificate. |
[email protected] | 7a593db | 2012-02-13 21:19:40 | [diff] [blame] | 1854 | callback.Run(NULL); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1855 | return; |
| 1856 | } |
[email protected] | 11feec32 | 2012-09-18 03:58:52 | [diff] [blame] | 1857 | ssl_tab_helper->ShowClientCertificateRequestDialog( |
[email protected] | 7a593db | 2012-02-13 21:19:40 | [diff] [blame] | 1858 | network_session, cert_request_info, callback); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 1859 | } |
| 1860 | |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 1861 | void ChromeContentBrowserClient::AddCertificate( |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 1862 | net::URLRequest* request, |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 1863 | net::CertificateMimeType cert_type, |
| 1864 | const void* cert_data, |
| 1865 | size_t cert_size, |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 1866 | int render_process_id, |
| 1867 | int render_view_id) { |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 1868 | chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size, |
| 1869 | render_process_id, render_view_id); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 1870 | } |
| 1871 | |
[email protected] | dc73a7b | 2012-03-25 15:27:18 | [diff] [blame] | 1872 | content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() { |
[email protected] | 11158e2d | 2013-02-01 02:31:56 | [diff] [blame] | 1873 | return MediaCaptureDevicesDispatcher::GetInstance(); |
[email protected] | dc73a7b | 2012-03-25 15:27:18 | [diff] [blame] | 1874 | } |
| 1875 | |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1876 | void ChromeContentBrowserClient::RequestDesktopNotificationPermission( |
| 1877 | const GURL& source_origin, |
| 1878 | int callback_context, |
| 1879 | int render_process_id, |
| 1880 | int render_view_id) { |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 1881 | #if defined(ENABLE_NOTIFICATIONS) |
[email protected] | d0d9c3ee | 2012-06-19 03:07:02 | [diff] [blame] | 1882 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1883 | WebContents* contents = |
| 1884 | tab_util::GetWebContentsByID(render_process_id, render_view_id); |
| 1885 | if (!contents) { |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1886 | NOTREACHED(); |
| 1887 | return; |
| 1888 | } |
| 1889 | |
[email protected] | d0d9c3ee | 2012-06-19 03:07:02 | [diff] [blame] | 1890 | // Skip showing the infobar if the request comes from an extension, and that |
| 1891 | // extension has the 'notify' permission. (If the extension does not have the |
| 1892 | // permission, the user will still be prompted.) |
| 1893 | Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 1894 | InfoMap* extension_info_map = |
[email protected] | c7cd594 | 2013-04-30 03:31:01 | [diff] [blame] | 1895 | extensions::ExtensionSystem::Get(profile)->info_map(); |
| 1896 | DesktopNotificationService* notification_service = |
| 1897 | DesktopNotificationServiceFactory::GetForProfile(profile); |
| 1898 | const Extension* extension = NULL; |
| 1899 | if (extension_info_map) { |
| 1900 | ExtensionSet extensions; |
| 1901 | extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin( |
| 1902 | source_origin, render_process_id, |
| 1903 | extensions::APIPermission::kNotification, &extensions); |
| 1904 | for (ExtensionSet::const_iterator iter = extensions.begin(); |
| 1905 | iter != extensions.end(); ++iter) { |
[email protected] | 593d2a7 | 2013-07-26 08:48:38 | [diff] [blame] | 1906 | if (notification_service->IsNotifierEnabled(NotifierId( |
| 1907 | NotifierId::APPLICATION, (*iter)->id()))) { |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 1908 | extension = iter->get(); |
[email protected] | c7cd594 | 2013-04-30 03:31:01 | [diff] [blame] | 1909 | break; |
| 1910 | } |
| 1911 | } |
| 1912 | } |
[email protected] | eb4832a | 2012-12-08 01:57:52 | [diff] [blame] | 1913 | RenderViewHost* rvh = |
| 1914 | RenderViewHost::FromID(render_process_id, render_view_id); |
| 1915 | if (IsExtensionWithPermissionOrSuggestInConsole( |
| 1916 | APIPermission::kNotification, extension, rvh)) { |
[email protected] | d0d9c3ee | 2012-06-19 03:07:02 | [diff] [blame] | 1917 | if (rvh) |
| 1918 | rvh->DesktopNotificationPermissionRequestDone(callback_context); |
| 1919 | return; |
| 1920 | } |
| 1921 | |
[email protected] | c7cd594 | 2013-04-30 03:31:01 | [diff] [blame] | 1922 | notification_service->RequestPermission(source_origin, render_process_id, |
[email protected] | d0d9c3ee | 2012-06-19 03:07:02 | [diff] [blame] | 1923 | render_view_id, callback_context, contents); |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 1924 | #else |
| 1925 | NOTIMPLEMENTED(); |
| 1926 | #endif |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1927 | } |
| 1928 | |
[email protected] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 1929 | blink::WebNotificationPresenter::Permission |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1930 | ChromeContentBrowserClient::CheckDesktopNotificationPermission( |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 1931 | const GURL& source_origin, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1932 | content::ResourceContext* context, |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 1933 | int render_process_id) { |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 1934 | #if defined(ENABLE_NOTIFICATIONS) |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1935 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 5c12979 | 2013-07-10 02:08:48 | [diff] [blame] | 1936 | |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1937 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 1938 | InfoMap* extension_info_map = io_data->GetExtensionInfoMap(); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1939 | |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 1940 | // We want to see if there is an extension that hasn't been manually disabled |
| 1941 | // that has the notifications permission and applies to this security origin. |
| 1942 | // First, get the list of extensions with permission for the origin. |
| 1943 | ExtensionSet extensions; |
| 1944 | extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin( |
| 1945 | source_origin, render_process_id, |
| 1946 | extensions::APIPermission::kNotification, &extensions); |
| 1947 | for (ExtensionSet::const_iterator iter = extensions.begin(); |
| 1948 | iter != extensions.end(); ++iter) { |
| 1949 | // Then, check to see if it's been disabled by the user. |
| 1950 | if (!extension_info_map->AreNotificationsDisabled((*iter)->id())) |
| 1951 | return blink::WebNotificationPresenter::PermissionAllowed; |
[email protected] | c7cd594 | 2013-04-30 03:31:01 | [diff] [blame] | 1952 | } |
| 1953 | |
[email protected] | 9afacd2 | 2013-11-13 20:23:31 | [diff] [blame] | 1954 | // No enabled extensions exist, so check the normal host content settings. |
| 1955 | HostContentSettingsMap* host_content_settings_map = |
| 1956 | io_data->GetHostContentSettingsMap(); |
| 1957 | ContentSetting setting = host_content_settings_map->GetContentSetting( |
| 1958 | source_origin, |
| 1959 | source_origin, |
| 1960 | CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 1961 | NO_RESOURCE_IDENTIFIER); |
| 1962 | |
| 1963 | if (setting == CONTENT_SETTING_ALLOW) |
| 1964 | return blink::WebNotificationPresenter::PermissionAllowed; |
| 1965 | if (setting == CONTENT_SETTING_BLOCK) |
| 1966 | return blink::WebNotificationPresenter::PermissionDenied; |
[email protected] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 1967 | return blink::WebNotificationPresenter::PermissionNotAllowed; |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 1968 | #else |
[email protected] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 1969 | return blink::WebNotificationPresenter::PermissionAllowed; |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 1970 | #endif |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | void ChromeContentBrowserClient::ShowDesktopNotification( |
[email protected] | 0ee57e2 | 2011-11-12 01:59:17 | [diff] [blame] | 1974 | const content::ShowDesktopNotificationHostMsgParams& params, |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1975 | int render_process_id, |
| 1976 | int render_view_id, |
| 1977 | bool worker) { |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 1978 | #if defined(ENABLE_NOTIFICATIONS) |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1979 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 1980 | render_process_id, render_view_id); |
| 1981 | if (!rvh) { |
| 1982 | NOTREACHED(); |
| 1983 | return; |
| 1984 | } |
| 1985 | |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1986 | content::RenderProcessHost* process = rvh->GetProcess(); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1987 | Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1988 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1989 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1990 | service->ShowDesktopNotification( |
| 1991 | params, render_process_id, render_view_id, |
| 1992 | worker ? DesktopNotificationService::WorkerNotification : |
| 1993 | DesktopNotificationService::PageNotification); |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 1994 | #else |
| 1995 | NOTIMPLEMENTED(); |
| 1996 | #endif |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1997 | } |
| 1998 | |
| 1999 | void ChromeContentBrowserClient::CancelDesktopNotification( |
| 2000 | int render_process_id, |
| 2001 | int render_view_id, |
| 2002 | int notification_id) { |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 2003 | #if defined(ENABLE_NOTIFICATIONS) |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2004 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 2005 | render_process_id, render_view_id); |
| 2006 | if (!rvh) { |
| 2007 | NOTREACHED(); |
| 2008 | return; |
| 2009 | } |
| 2010 | |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2011 | content::RenderProcessHost* process = rvh->GetProcess(); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2012 | Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2013 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 2014 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2015 | service->CancelDesktopNotification( |
| 2016 | render_process_id, render_view_id, notification_id); |
[email protected] | 5fd2e84 | 2012-03-01 00:29:11 | [diff] [blame] | 2017 | #else |
| 2018 | NOTIMPLEMENTED(); |
| 2019 | #endif |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2020 | } |
| 2021 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2022 | bool ChromeContentBrowserClient::CanCreateWindow( |
[email protected] | 2b751a1 | 2012-03-06 03:00:35 | [diff] [blame] | 2023 | const GURL& opener_url, |
[email protected] | 931bc92 | 2013-09-11 21:42:57 | [diff] [blame] | 2024 | const GURL& opener_top_level_frame_url, |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 2025 | const GURL& source_origin, |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2026 | WindowContainerType container_type, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2027 | const GURL& target_url, |
| 2028 | const content::Referrer& referrer, |
| 2029 | WindowOpenDisposition disposition, |
| 2030 | const WebWindowFeatures& features, |
| 2031 | bool user_gesture, |
| 2032 | bool opener_suppressed, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 2033 | content::ResourceContext* context, |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2034 | int render_process_id, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2035 | bool is_guest, |
| 2036 | int opener_id, |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2037 | bool* no_javascript_access) { |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2038 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2039 | |
| 2040 | *no_javascript_access = false; |
| 2041 | |
[email protected] | 5e5f55e262c5 | 2013-09-12 00:27:19 | [diff] [blame] | 2042 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 2043 | InfoMap* map = io_data->GetExtensionInfoMap(); |
[email protected] | 5e5f55e262c5 | 2013-09-12 00:27:19 | [diff] [blame] | 2044 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2045 | // If the opener is trying to create a background window but doesn't have |
| 2046 | // the appropriate permission, fail the attempt. |
[email protected] | 6940eef8 | 2013-09-11 11:58:41 | [diff] [blame] | 2047 | if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2048 | if (!map->SecurityOriginHasAPIPermission( |
| 2049 | source_origin, |
| 2050 | render_process_id, |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2051 | APIPermission::kBackground)) { |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2052 | return false; |
| 2053 | } |
| 2054 | |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 2055 | // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may |
| 2056 | // return a recently installed Extension even if this CanCreateWindow call |
| 2057 | // 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] | 2058 | // because the permission check above would have caused an early return |
| 2059 | // already. We must use the full URL to find hosted apps, though, and not |
| 2060 | // just the origin. |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 2061 | const Extension* extension = |
| 2062 | map->extensions().GetExtensionOrAppByURL(opener_url); |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 2063 | if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension)) |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2064 | *no_javascript_access = true; |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2065 | |
| 2066 | return true; |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2067 | } |
[email protected] | 056efdc | 2013-04-06 00:14:53 | [diff] [blame] | 2068 | |
| 2069 | // No new browser window (popup or tab) in app mode. |
| 2070 | if (container_type == WINDOW_CONTAINER_TYPE_NORMAL && |
| 2071 | chrome::IsRunningInForcedAppMode()) { |
| 2072 | return false; |
| 2073 | } |
| 2074 | |
[email protected] | d2bac6b | 2013-08-13 03:42:36 | [diff] [blame] | 2075 | if (g_browser_process->prerender_tracker() && |
| 2076 | g_browser_process->prerender_tracker()->TryCancelOnIOThread( |
| 2077 | render_process_id, |
| 2078 | opener_id, |
| 2079 | prerender::FINAL_STATUS_CREATE_NEW_WINDOW)) { |
| 2080 | return false; |
| 2081 | } |
| 2082 | |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2083 | if (is_guest) |
| 2084 | return true; |
| 2085 | |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2086 | HostContentSettingsMap* content_settings = |
| 2087 | ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap(); |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 2088 | BlockedWindowParams blocked_params(target_url, |
| 2089 | referrer, |
| 2090 | disposition, |
| 2091 | features, |
| 2092 | user_gesture, |
| 2093 | opener_suppressed, |
| 2094 | render_process_id, |
| 2095 | opener_id); |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2096 | |
[email protected] | 7f53dff | 2013-08-05 10:45:50 | [diff] [blame] | 2097 | if (!user_gesture && !CommandLine::ForCurrentProcess()->HasSwitch( |
| 2098 | switches::kDisablePopupBlocking)) { |
[email protected] | 931bc92 | 2013-09-11 21:42:57 | [diff] [blame] | 2099 | if (content_settings->GetContentSetting(opener_top_level_frame_url, |
| 2100 | opener_top_level_frame_url, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2101 | CONTENT_SETTINGS_TYPE_POPUPS, |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 2102 | std::string()) != |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2103 | CONTENT_SETTING_ALLOW) { |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 2104 | BrowserThread::PostTask(BrowserThread::UI, |
| 2105 | FROM_HERE, |
| 2106 | base::Bind(&HandleBlockedPopupOnUIThread, |
| 2107 | blocked_params)); |
| 2108 | return false; |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2109 | } |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 2110 | } |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2111 | |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 2112 | #if defined(OS_ANDROID) |
| 2113 | if (SingleTabModeTabHelper::IsRegistered(render_process_id, opener_id)) { |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2114 | BrowserThread::PostTask(BrowserThread::UI, |
| 2115 | FROM_HERE, |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 2116 | base::Bind(&HandleSingleTabModeBlockOnUIThread, |
| 2117 | blocked_params)); |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2118 | return false; |
| 2119 | } |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 2120 | #endif |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2121 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2122 | return true; |
| 2123 | } |
| 2124 | |
| 2125 | std::string ChromeContentBrowserClient::GetWorkerProcessTitle( |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 2126 | const GURL& url, content::ResourceContext* context) { |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2127 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2128 | // Check if it's an extension-created worker, in which case we want to use |
| 2129 | // the name of the extension. |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 2130 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2131 | const Extension* extension = |
| 2132 | io_data->GetExtensionInfoMap()->extensions().GetByID(url.host()); |
| 2133 | return extension ? extension->name() : std::string(); |
| 2134 | } |
| 2135 | |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 2136 | void ChromeContentBrowserClient::ResourceDispatcherHostCreated() { |
| 2137 | return g_browser_process->ResourceDispatcherHostCreated(); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 2138 | } |
| 2139 | |
[email protected] | 7a06d28 | 2013-05-03 04:39:33 | [diff] [blame] | 2140 | // TODO(tommi): Rename from Get to Create. |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 2141 | content::SpeechRecognitionManagerDelegate* |
| 2142 | ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() { |
[email protected] | 855e18b | 2013-07-08 21:02:00 | [diff] [blame] | 2143 | #if defined(ENABLE_INPUT_SPEECH) |
| 2144 | return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI(); |
[email protected] | a03f2d3 | 2012-03-14 00:26:32 | [diff] [blame] | 2145 | #else |
[email protected] | 855e18b | 2013-07-08 21:02:00 | [diff] [blame] | 2146 | // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just |
| 2147 | // need the base delegate without the bubble UI. |
| 2148 | return new speech::ChromeSpeechRecognitionManagerDelegate(); |
[email protected] | a03f2d3 | 2012-03-14 00:26:32 | [diff] [blame] | 2149 | #endif |
[email protected] | 66cfec6 | 2012-02-24 17:57:51 | [diff] [blame] | 2150 | } |
| 2151 | |
[email protected] | ae6e991 | 2011-07-27 01:18:28 | [diff] [blame] | 2152 | net::NetLog* ChromeContentBrowserClient::GetNetLog() { |
| 2153 | return g_browser_process->net_log(); |
| 2154 | } |
| 2155 | |
[email protected] | 32538d9 | 2011-08-25 00:09:23 | [diff] [blame] | 2156 | AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() { |
| 2157 | return new ChromeAccessTokenStore(); |
| 2158 | } |
| 2159 | |
[email protected] | dbae6b0 | 2011-06-29 23:51:41 | [diff] [blame] | 2160 | bool ChromeContentBrowserClient::IsFastShutdownPossible() { |
[email protected] | 263ff4f | 2013-01-04 20:23:01 | [diff] [blame] | 2161 | return true; |
[email protected] | dbae6b0 | 2011-06-29 23:51:41 | [diff] [blame] | 2162 | } |
| 2163 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2164 | void ChromeContentBrowserClient::OverrideWebkitPrefs( |
[email protected] | 2e21fe29 | 2012-03-02 22:52:32 | [diff] [blame] | 2165 | RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2166 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2167 | rvh->GetProcess()->GetBrowserContext()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2168 | PrefService* prefs = profile->GetPrefs(); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2169 | |
[email protected] | 33b7954 | 2013-10-18 11:18:45 | [diff] [blame] | 2170 | // Fill per-script font preferences. These are not registered on Android |
| 2171 | // - http://crbug.com/308033. |
| 2172 | #if !defined(OS_ANDROID) |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2173 | FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2174 | &web_prefs->standard_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2175 | FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2176 | &web_prefs->fixed_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2177 | FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2178 | &web_prefs->serif_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2179 | FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2180 | &web_prefs->sans_serif_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2181 | FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2182 | &web_prefs->cursive_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2183 | FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2184 | &web_prefs->fantasy_font_family_map); |
[email protected] | 85edc23 | 2012-10-05 08:56:03 | [diff] [blame] | 2185 | FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap, |
| 2186 | &web_prefs->pictograph_font_family_map); |
[email protected] | 33b7954 | 2013-10-18 11:18:45 | [diff] [blame] | 2187 | #endif |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2188 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2189 | web_prefs->default_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2190 | prefs->GetInteger(prefs::kWebKitDefaultFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2191 | web_prefs->default_fixed_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2192 | prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2193 | web_prefs->minimum_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2194 | prefs->GetInteger(prefs::kWebKitMinimumFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2195 | web_prefs->minimum_logical_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2196 | prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2197 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2198 | web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2199 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2200 | web_prefs->javascript_can_open_windows_automatically = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2201 | prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2202 | web_prefs->dom_paste_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2203 | prefs->GetBoolean(prefs::kWebKitDomPasteEnabled); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2204 | web_prefs->shrinks_standalone_images_to_fit = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2205 | prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit); |
| 2206 | const DictionaryValue* inspector_settings = |
| 2207 | prefs->GetDictionary(prefs::kWebKitInspectorSettings); |
| 2208 | if (inspector_settings) { |
[email protected] | c40ef1c | 2013-02-25 18:42:18 | [diff] [blame] | 2209 | for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd(); |
| 2210 | iter.Advance()) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2211 | std::string value; |
[email protected] | c40ef1c | 2013-02-25 18:42:18 | [diff] [blame] | 2212 | if (iter.value().GetAsString(&value)) { |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2213 | web_prefs->inspector_settings.push_back( |
[email protected] | c40ef1c | 2013-02-25 18:42:18 | [diff] [blame] | 2214 | std::make_pair(iter.key(), value)); |
| 2215 | } |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2216 | } |
| 2217 | } |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2218 | web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2219 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2220 | if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2221 | web_prefs->javascript_enabled = false; |
| 2222 | if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled)) |
| 2223 | web_prefs->web_security_enabled = false; |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2224 | if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2225 | web_prefs->plugins_enabled = false; |
| 2226 | if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled)) |
| 2227 | web_prefs->java_enabled = false; |
| 2228 | web_prefs->loads_images_automatically = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2229 | prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2230 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2231 | if (prefs->GetBoolean(prefs::kDisable3DAPIs)) |
| 2232 | web_prefs->experimental_webgl_enabled = false; |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2233 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2234 | web_prefs->memory_info_enabled = |
| 2235 | prefs->GetBoolean(prefs::kEnableMemoryInfo); |
| 2236 | web_prefs->allow_displaying_insecure_content = |
| 2237 | prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent); |
| 2238 | web_prefs->allow_running_insecure_content = |
| 2239 | prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent); |
[email protected] | d3b935f | 2012-10-19 23:14:32 | [diff] [blame] | 2240 | #if defined(OS_ANDROID) |
[email protected] | ded00dc | 2013-11-01 00:37:05 | [diff] [blame] | 2241 | web_prefs->font_scale_factor = |
| 2242 | static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor)); |
| 2243 | web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment(); |
[email protected] | d3b935f | 2012-10-19 23:14:32 | [diff] [blame] | 2244 | web_prefs->force_enable_zoom = |
| 2245 | prefs->GetBoolean(prefs::kWebKitForceEnableZoom); |
| 2246 | #endif |
[email protected] | 5c91525 | 2013-05-07 13:15:39 | [diff] [blame] | 2247 | |
[email protected] | af4256d5 | 2013-06-04 20:39:07 | [diff] [blame] | 2248 | #if defined(OS_ANDROID) |
| 2249 | web_prefs->password_echo_enabled = |
| 2250 | prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled); |
| 2251 | #else |
[email protected] | 9d06d88d | 2012-02-23 22:37:08 | [diff] [blame] | 2252 | web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled; |
[email protected] | af4256d5 | 2013-06-04 20:39:07 | [diff] [blame] | 2253 | #endif |
| 2254 | |
[email protected] | cfadadd | 2013-04-03 04:43:02 | [diff] [blame] | 2255 | web_prefs->asynchronous_spell_checking_enabled = true; |
| 2256 | web_prefs->unified_textchecker_enabled = true; |
[email protected] | dd5d0fb | 2012-01-18 03:37:57 | [diff] [blame] | 2257 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2258 | web_prefs->uses_universal_detector = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2259 | prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2260 | web_prefs->text_areas_are_resizable = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2261 | prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2262 | web_prefs->hyperlink_auditing_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2263 | prefs->GetBoolean(prefs::kEnableHyperlinkAuditing); |
| 2264 | |
| 2265 | // Make sure we will set the default_encoding with canonical encoding name. |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2266 | web_prefs->default_encoding = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2267 | CharacterEncoding::GetCanonicalEncodingNameByAliasName( |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2268 | web_prefs->default_encoding); |
| 2269 | if (web_prefs->default_encoding.empty()) { |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 2270 | prefs->ClearPref(prefs::kDefaultCharset); |
| 2271 | web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2272 | } |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2273 | DCHECK(!web_prefs->default_encoding.empty()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2274 | |
[email protected] | 299d7f1 | 2012-05-23 05:31:15 | [diff] [blame] | 2275 | WebContents* web_contents = WebContents::FromRenderViewHost(rvh); |
[email protected] | cb2edf2 | 2013-04-01 20:25:23 | [diff] [blame] | 2276 | extensions::ViewType view_type = extensions::GetViewType(web_contents); |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 2277 | ExtensionService* service = |
| 2278 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2279 | if (service) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 2280 | const GURL& url = rvh->GetSiteInstance()->GetSiteURL(); |
| 2281 | const Extension* extension = service->extensions()->GetByID(url.host()); |
| 2282 | // Ensure that we are only granting extension preferences to URLs with |
| 2283 | // the correct scheme. Without this check, chrome-guest:// schemes used by |
| 2284 | // webview tags as well as hosts that happen to match the id of an |
| 2285 | // installed extension would get the wrong preferences. |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 2286 | if (url.SchemeIs(extensions::kExtensionScheme)) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 2287 | extension_webkit_preferences::SetPreferences( |
| 2288 | extension, view_type, web_prefs); |
| 2289 | } |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2290 | } |
| 2291 | |
[email protected] | cb2edf2 | 2013-04-01 20:25:23 | [diff] [blame] | 2292 | if (view_type == extensions::VIEW_TYPE_NOTIFICATION) { |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2293 | web_prefs->allow_scripts_to_close_windows = true; |
[email protected] | cb2edf2 | 2013-04-01 20:25:23 | [diff] [blame] | 2294 | } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2295 | // Disable all kinds of acceleration for background pages. |
| 2296 | // See http://crbug.com/96005 and http://crbug.com/96006 |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2297 | web_prefs->force_compositing_mode = false; |
| 2298 | web_prefs->accelerated_compositing_enabled = false; |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2299 | } |
[email protected] | 2e21fe29 | 2012-03-02 22:52:32 | [diff] [blame] | 2300 | |
| 2301 | #if defined(FILE_MANAGER_EXTENSION) |
| 2302 | // Override the default of suppressing HW compositing for WebUI pages for the |
| 2303 | // file manager, which is implemented using WebUI but wants HW acceleration |
| 2304 | // for video decode & render. |
[email protected] | 02a3dc12 | 2013-06-13 15:07:53 | [diff] [blame] | 2305 | if (url.SchemeIs(extensions::kExtensionScheme) && |
[email protected] | 2de96a5 | 2013-08-14 01:18:09 | [diff] [blame] | 2306 | url.host() == file_manager::kFileManagerAppId) { |
[email protected] | 2e21fe29 | 2012-03-02 22:52:32 | [diff] [blame] | 2307 | web_prefs->accelerated_compositing_enabled = true; |
| 2308 | web_prefs->accelerated_2d_canvas_enabled = true; |
| 2309 | } |
| 2310 | #endif |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | void ChromeContentBrowserClient::UpdateInspectorSetting( |
| 2314 | RenderViewHost* rvh, const std::string& key, const std::string& value) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2315 | content::BrowserContext* browser_context = |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2316 | rvh->GetProcess()->GetBrowserContext(); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2317 | DictionaryPrefUpdate update( |
| 2318 | Profile::FromBrowserContext(browser_context)->GetPrefs(), |
| 2319 | prefs::kWebKitInspectorSettings); |
| 2320 | DictionaryValue* inspector_settings = update.Get(); |
| 2321 | inspector_settings->SetWithoutPathExpansion(key, |
| 2322 | Value::CreateStringValue(value)); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 2323 | } |
| 2324 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 2325 | void ChromeContentBrowserClient::BrowserURLHandlerCreated( |
| 2326 | BrowserURLHandler* handler) { |
| 2327 | // Add the default URL handlers. |
| 2328 | handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride, |
| 2329 | BrowserURLHandler::null_handler()); |
| 2330 | handler->AddHandlerPair(BrowserURLHandler::null_handler(), |
| 2331 | &ExtensionWebUI::HandleChromeURLOverrideReverse); |
| 2332 | |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 2333 | // about: handler. Must come before chrome: handler, since it will |
| 2334 | // rewrite about: urls to chrome: URLs and then expect chrome: to |
| 2335 | // actually handle them. |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 2336 | handler->AddHandlerPair(&WillHandleBrowserAboutURL, |
| 2337 | BrowserURLHandler::null_handler()); |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 2338 | |
| 2339 | // Handler to rewrite chrome://newtab for InstantExtended. |
| 2340 | handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite, |
| 2341 | &chrome::HandleNewTabURLReverseRewrite); |
| 2342 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 2343 | // chrome: & friends. |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 2344 | handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 2348 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2349 | rvh->GetSiteInstance()->GetProcess()->GetBrowserContext()); |
[email protected] | 38b892b4 | 2012-09-04 13:25:47 | [diff] [blame] | 2350 | BrowsingDataRemover* remover = |
| 2351 | BrowsingDataRemover::CreateForUnboundedRange(profile); |
[email protected] | 3d4d4cf | 2012-06-04 10:40:55 | [diff] [blame] | 2352 | remover->Remove(BrowsingDataRemover::REMOVE_CACHE, |
| 2353 | BrowsingDataHelper::UNPROTECTED_WEB); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 2354 | // BrowsingDataRemover takes care of deleting itself when done. |
| 2355 | } |
| 2356 | |
| 2357 | void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 2358 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2359 | rvh->GetSiteInstance()->GetProcess()->GetBrowserContext()); |
[email protected] | 38b892b4 | 2012-09-04 13:25:47 | [diff] [blame] | 2360 | BrowsingDataRemover* remover = |
| 2361 | BrowsingDataRemover::CreateForUnboundedRange(profile); |
[email protected] | dceaa91 | 2011-09-06 17:17:23 | [diff] [blame] | 2362 | int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA; |
[email protected] | 3d4d4cf | 2012-06-04 10:40:55 | [diff] [blame] | 2363 | remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 2364 | // BrowsingDataRemover takes care of deleting itself when done. |
| 2365 | } |
| 2366 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2367 | base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { |
[email protected] | b1d9727 | 2013-08-17 13:38:49 | [diff] [blame] | 2368 | return DownloadPrefs::GetDefaultDownloadDirectory(); |
[email protected] | e1d16eb9 | 2011-08-18 23:19:32 | [diff] [blame] | 2369 | } |
| 2370 | |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 2371 | std::string ChromeContentBrowserClient::GetDefaultDownloadName() { |
| 2372 | return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); |
| 2373 | } |
| 2374 | |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 2375 | void ChromeContentBrowserClient::DidCreatePpapiPlugin( |
| 2376 | content::BrowserPpapiHost* browser_host) { |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 2377 | #if defined(ENABLE_PLUGINS) |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 2378 | browser_host->GetPpapiHost()->AddHostFactoryFilter( |
| 2379 | scoped_ptr<ppapi::host::HostFactory>( |
| 2380 | new ChromeBrowserPepperHostFactory(browser_host))); |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 2381 | #endif |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 2382 | } |
| 2383 | |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 2384 | content::BrowserPpapiHost* |
| 2385 | ChromeContentBrowserClient::GetExternalBrowserPpapiHost( |
| 2386 | int plugin_process_id) { |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 2387 | BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER); |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 2388 | while (!iter.Done()) { |
[email protected] | 7c766e9 | 2013-11-22 20:44:02 | [diff] [blame] | 2389 | nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>( |
| 2390 | iter.GetDelegate()); |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 2391 | if (host->process() && |
| 2392 | host->process()->GetData().id == plugin_process_id) { |
| 2393 | // Found the plugin. |
| 2394 | return host->browser_ppapi_host(); |
| 2395 | } |
| 2396 | ++iter; |
| 2397 | } |
| 2398 | return NULL; |
| 2399 | } |
| 2400 | |
[email protected] | 7b38b19 | 2013-03-23 18:39:31 | [diff] [blame] | 2401 | bool ChromeContentBrowserClient::SupportsBrowserPlugin( |
| 2402 | content::BrowserContext* browser_context, const GURL& site_url) { |
| 2403 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2404 | switches::kEnableBrowserPluginForAllViewTypes)) |
| 2405 | return true; |
| 2406 | |
[email protected] | 22aa4f8 | 2013-09-24 17:01:44 | [diff] [blame] | 2407 | if (content::HasWebUIScheme(site_url)) |
| 2408 | return true; |
| 2409 | |
[email protected] | 7b38b19 | 2013-03-23 18:39:31 | [diff] [blame] | 2410 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2411 | ExtensionService* service = |
| 2412 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 2413 | if (!service) |
| 2414 | return false; |
| 2415 | |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 2416 | const Extension* extension = |
| 2417 | service->extensions()->GetExtensionOrAppByURL(site_url); |
[email protected] | 7b38b19 | 2013-03-23 18:39:31 | [diff] [blame] | 2418 | if (!extension) |
| 2419 | return false; |
| 2420 | |
[email protected] | c2d2f10 | 2013-04-29 16:42:58 | [diff] [blame] | 2421 | return extension->HasAPIPermission(APIPermission::kWebView) || |
| 2422 | extension->HasAPIPermission(APIPermission::kAdView); |
[email protected] | 7b38b19 | 2013-03-23 18:39:31 | [diff] [blame] | 2423 | } |
| 2424 | |
[email protected] | 38cd8f7f | 2012-06-15 22:06:07 | [diff] [blame] | 2425 | bool ChromeContentBrowserClient::AllowPepperSocketAPI( |
[email protected] | 157cc90 | 2012-11-02 06:31:58 | [diff] [blame] | 2426 | content::BrowserContext* browser_context, |
| 2427 | const GURL& url, |
[email protected] | dda5482 | 2013-06-15 01:26:39 | [diff] [blame] | 2428 | bool private_api, |
[email protected] | 8b92ed18 | 2013-09-21 04:47:12 | [diff] [blame] | 2429 | const content::SocketPermissionRequest* params) { |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 2430 | #if defined(ENABLE_PLUGINS) |
[email protected] | 9d45049 | 2013-06-13 23:08:37 | [diff] [blame] | 2431 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2432 | const ExtensionSet* extension_set = NULL; |
| 2433 | if (profile) { |
| 2434 | extension_set = extensions::ExtensionSystem::Get(profile)-> |
| 2435 | extension_service()->extensions(); |
| 2436 | } |
[email protected] | dda5482 | 2013-06-15 01:26:39 | [diff] [blame] | 2437 | |
| 2438 | if (private_api) { |
| 2439 | // Access to private socket APIs is controlled by the whitelist. |
| 2440 | if (IsExtensionOrSharedModuleWhitelisted(url, extension_set, |
| 2441 | allowed_socket_origins_)) { |
| 2442 | return true; |
| 2443 | } |
| 2444 | } else { |
| 2445 | // Access to public socket APIs is controlled by extension permissions. |
| 2446 | if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) && |
| 2447 | extension_set) { |
| 2448 | const Extension* extension = extension_set->GetByID(url.host()); |
| 2449 | if (extension) { |
[email protected] | 8b92ed18 | 2013-09-21 04:47:12 | [diff] [blame] | 2450 | if (params) { |
| 2451 | extensions::SocketPermission::CheckParam check_params( |
| 2452 | params->type, params->host, params->port); |
| 2453 | if (extensions::PermissionsData::CheckAPIPermissionWithParam( |
| 2454 | extension, extensions::APIPermission::kSocket, |
| 2455 | &check_params)) { |
| 2456 | return true; |
| 2457 | } |
| 2458 | } else { |
| 2459 | if (extensions::PermissionsData::HasAPIPermission( |
| 2460 | extension, extensions::APIPermission::kSocket)) { |
| 2461 | return true; |
| 2462 | } |
[email protected] | dda5482 | 2013-06-15 01:26:39 | [diff] [blame] | 2463 | } |
| 2464 | } |
| 2465 | } |
| 2466 | } |
| 2467 | |
| 2468 | // Allow both public and private APIs if the command line says so. |
| 2469 | return IsHostAllowedByCommandLine(url, extension_set, |
| 2470 | switches::kAllowNaClSocketAPI); |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 2471 | #else |
[email protected] | a658d45 | 2012-03-02 12:45:29 | [diff] [blame] | 2472 | return false; |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 2473 | #endif |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 2474 | } |
| 2475 | |
[email protected] | a28e330 | 2013-02-03 03:50:43 | [diff] [blame] | 2476 | ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy( |
| 2477 | WebContents* web_contents) { |
| 2478 | return new ChromeSelectFilePolicy(web_contents); |
| 2479 | } |
| 2480 | |
[email protected] | 7d942470 | 2013-04-14 13:14:16 | [diff] [blame] | 2481 | void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 2482 | std::vector<std::string>* additional_allowed_schemes) { |
| 2483 | ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 2484 | additional_allowed_schemes); |
| 2485 | additional_allowed_schemes->push_back(kChromeUIScheme); |
| 2486 | additional_allowed_schemes->push_back(extensions::kExtensionScheme); |
| 2487 | } |
| 2488 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 2489 | void ChromeContentBrowserClient::GetAdditionalFileSystemBackends( |
[email protected] | 0ff5eb5 | 2013-07-10 20:35:31 | [diff] [blame] | 2490 | content::BrowserContext* browser_context, |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 2491 | const base::FilePath& storage_partition_path, |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 2492 | ScopedVector<fileapi::FileSystemBackend>* additional_backends) { |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 2493 | #if !defined(OS_ANDROID) |
[email protected] | 30a306f4 | 2013-06-10 03:09:03 | [diff] [blame] | 2494 | base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 2495 | additional_backends->push_back(new MediaFileSystemBackend( |
[email protected] | 30a306f4 | 2013-06-10 03:09:03 | [diff] [blame] | 2496 | storage_partition_path, |
| 2497 | pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken( |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 2498 | MediaFileSystemBackend::kMediaTaskRunnerName)).get())); |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 2499 | #endif |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 2500 | #if defined(OS_CHROMEOS) |
[email protected] | 0ff5eb5 | 2013-07-10 20:35:31 | [diff] [blame] | 2501 | fileapi::ExternalMountPoints* external_mount_points = |
| 2502 | content::BrowserContext::GetMountPoints(browser_context); |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 2503 | DCHECK(external_mount_points); |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 2504 | chromeos::FileSystemBackend* backend = |
| 2505 | new chromeos::FileSystemBackend( |
[email protected] | 0ff5eb5 | 2013-07-10 20:35:31 | [diff] [blame] | 2506 | new drive::FileSystemBackendDelegate(browser_context), |
| 2507 | browser_context->GetSpecialStoragePolicy(), |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 2508 | external_mount_points, |
| 2509 | fileapi::ExternalMountPoints::GetSystemInstance()); |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 2510 | backend->AddSystemMountPoints(); |
| 2511 | DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal)); |
| 2512 | additional_backends->push_back(backend); |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 2513 | #endif |
[email protected] | 445b7db | 2013-08-02 04:58:27 | [diff] [blame] | 2514 | |
[email protected] | e86e2be | 2013-08-30 11:20:39 | [diff] [blame] | 2515 | additional_backends->push_back( |
| 2516 | new sync_file_system::SyncFileSystemBackend( |
| 2517 | Profile::FromBrowserContext(browser_context))); |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 2518 | } |
| 2519 | |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 2520 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 2521 | void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
| 2522 | const CommandLine& command_line, |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 2523 | int child_process_id, |
[email protected] | c7abd42 | 2012-09-25 00:20:08 | [diff] [blame] | 2524 | std::vector<FileDescriptorInfo>* mappings) { |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 2525 | #if defined(OS_ANDROID) |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2526 | base::FilePath data_path; |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 2527 | PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path); |
| 2528 | DCHECK(!data_path.empty()); |
| 2529 | |
| 2530 | int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2531 | base::FilePath chrome_resources_pak = |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 2532 | data_path.AppendASCII("chrome_100_percent.pak"); |
[email protected] | 5db2b749 | 2013-08-23 05:33:09 | [diff] [blame] | 2533 | base::PlatformFile f = |
| 2534 | base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL); |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 2535 | DCHECK(f != base::kInvalidPlatformFileValue); |
[email protected] | 7359238 | 2013-01-18 19:22:37 | [diff] [blame] | 2536 | mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor, |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 2537 | FileDescriptor(f, true))); |
| 2538 | |
| 2539 | const std::string locale = GetApplicationLocale(); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2540 | base::FilePath locale_pak = ResourceBundle::GetSharedInstance(). |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 2541 | GetLocaleFilePath(locale, false); |
| 2542 | f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL); |
| 2543 | DCHECK(f != base::kInvalidPlatformFileValue); |
| 2544 | mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor, |
| 2545 | FileDescriptor(f, true))); |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 2546 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2547 | base::FilePath resources_pack_path; |
[email protected] | 7359238 | 2013-01-18 19:22:37 | [diff] [blame] | 2548 | PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); |
| 2549 | f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL); |
| 2550 | DCHECK(f != base::kInvalidPlatformFileValue); |
| 2551 | mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor, |
| 2552 | FileDescriptor(f, true))); |
| 2553 | |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 2554 | if (breakpad::IsCrashReporterEnabled()) { |
| 2555 | f = breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile( |
| 2556 | child_process_id); |
[email protected] | 82174aa | 2013-01-22 21:53:43 | [diff] [blame] | 2557 | if (f == base::kInvalidPlatformFileValue) { |
| 2558 | LOG(ERROR) << "Failed to create file for minidump, crash reporting will " |
| 2559 | "be disabled for this process."; |
| 2560 | } else { |
| 2561 | mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor, |
| 2562 | FileDescriptor(f, true))); |
| 2563 | } |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 2564 | } |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 2565 | |
| 2566 | #else |
| 2567 | int crash_signal_fd = GetCrashSignalFD(command_line); |
| 2568 | if (crash_signal_fd >= 0) { |
| 2569 | mappings->push_back(FileDescriptorInfo(kCrashDumpSignal, |
| 2570 | FileDescriptor(crash_signal_fd, |
| 2571 | false))); |
| 2572 | } |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 2573 | #endif // defined(OS_ANDROID) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2574 | } |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 2575 | #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2576 | |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 2577 | #if defined(OS_WIN) |
| 2578 | const wchar_t* ChromeContentBrowserClient::GetResourceDllName() { |
| 2579 | return chrome::kBrowserResourcesDll; |
| 2580 | } |
[email protected] | 34f4868 | 2013-03-20 00:30:18 | [diff] [blame] | 2581 | |
| 2582 | void ChromeContentBrowserClient::PreSpawnRenderer( |
| 2583 | sandbox::TargetPolicy* policy, |
| 2584 | bool* success) { |
| 2585 | // This code is duplicated in nacl_exe_win_64.cc. |
| 2586 | // Allow the server side of a pipe restricted to the "chrome.nacl." |
| 2587 | // namespace so that it cannot impersonate other system or other chrome |
| 2588 | // service pipes. |
| 2589 | sandbox::ResultCode result = policy->AddRule( |
| 2590 | sandbox::TargetPolicy::SUBSYS_NAMED_PIPES, |
| 2591 | sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY, |
| 2592 | L"\\\\.\\pipe\\chrome.nacl.*"); |
| 2593 | if (result != sandbox::SBOX_ALL_OK) { |
| 2594 | *success = false; |
| 2595 | return; |
| 2596 | } |
| 2597 | |
| 2598 | // Renderers need to send named pipe handles and shared memory |
| 2599 | // segment handles to NaCl loader processes. |
| 2600 | result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES, |
| 2601 | sandbox::TargetPolicy::HANDLES_DUP_ANY, |
| 2602 | L"File"); |
| 2603 | if (result != sandbox::SBOX_ALL_OK) { |
| 2604 | *success = false; |
| 2605 | return; |
| 2606 | } |
| 2607 | } |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 2608 | #endif |
| 2609 | |
[email protected] | 37a72af | 2011-06-13 05:42:01 | [diff] [blame] | 2610 | #if defined(USE_NSS) |
| 2611 | crypto::CryptoModuleBlockingPasswordDelegate* |
| 2612 | ChromeContentBrowserClient::GetCryptoPasswordDelegate( |
| 2613 | const GURL& url) { |
[email protected] | 6246ac5 | 2012-09-24 01:55:29 | [diff] [blame] | 2614 | return chrome::NewCryptoModuleBlockingDialogDelegate( |
| 2615 | chrome::kCryptoModulePasswordKeygen, url.host()); |
[email protected] | 37a72af | 2011-06-13 05:42:01 | [diff] [blame] | 2616 | } |
| 2617 | #endif |
| 2618 | |
[email protected] | a6868c2 | 2013-10-09 02:50:29 | [diff] [blame] | 2619 | bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle( |
| 2620 | content::BrowserContext* browser_context, |
| 2621 | const GURL& url) { |
| 2622 | #if defined(ENABLE_PLUGINS) |
| 2623 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2624 | const ExtensionSet* extension_set = NULL; |
| 2625 | if (profile) { |
| 2626 | extension_set = extensions::ExtensionSystem::Get(profile)-> |
| 2627 | extension_service()->extensions(); |
| 2628 | } |
| 2629 | // TODO(teravest): Populate allowed_file_handle_origins_ when FileIO is moved |
| 2630 | // from the renderer to the browser. |
| 2631 | return IsExtensionOrSharedModuleWhitelisted(url, extension_set, |
| 2632 | allowed_file_handle_origins_) || |
| 2633 | IsHostAllowedByCommandLine(url, extension_set, |
| 2634 | switches::kAllowNaClFileHandleAPI); |
| 2635 | #else |
| 2636 | return false; |
| 2637 | #endif |
| 2638 | } |
| 2639 | |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 2640 | } // namespace chrome |