chrome_content_browser_client.cc revision 558790d6acca3451cf3a6b497803a5f07d0bec58
1809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com// Use of this source code is governed by a BSD-style license that can be 3809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com// found in the LICENSE file. 4809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com 5809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/chrome_content_browser_client.h" 6809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com 7f168b86d7fafc5c20c87bebc6fd393cb17e120catfarina#include <set> 8809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include <utility> 9809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include <vector> 10809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com 11809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "base/bind.h" 12770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com#include "base/command_line.h" 13809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "base/lazy_instance.h" 14809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "base/path_service.h" 15809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "base/prefs/pref_service.h" 16809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "base/strings/string_number_conversions.h" 17809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "base/strings/utf_string_conversions.h" 18809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "base/threading/sequenced_worker_pool.h" 19809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/app/breakpad_mac.h" 20f168b86d7fafc5c20c87bebc6fd393cb17e120catfarina#include "chrome/browser/app_mode/app_mode_utils.h" 21809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/browser_about_handler.h" 22410e6e80f00a6c660675c80904807a041c7b7d2amtklein@google.com#include "chrome/browser/browser_process.h" 23809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/browser_shutdown.h" 24809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/browsing_data/browsing_data_helper.h" 25809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/browsing_data/browsing_data_remover.h" 26809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/character_encoding.h" 27809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/chrome_net_benchmarking_message_filter.h" 28809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/chrome_quota_permission_context.h" 29809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/content_settings/content_settings_utils.h" 30809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/content_settings/cookie_settings.h" 31809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/content_settings/host_content_settings_map.h" 32809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/content_settings/tab_specific_content_settings.h" 33809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/defaults.h" 34809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/download/download_util.h" 35809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/extensions/activity_log/activity_log.h" 36809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/extensions/api/web_request/web_request_api.h" 37809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/extensions/browser_permissions_policy_delegate.h" 38809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/extensions/extension_host.h" 393361471a3504ecd0351ff70f4c42d8d6fee963d4commit-bot@chromium.org#include "chrome/browser/extensions/extension_info_map.h" 40809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/extensions/extension_process_manager.h" 4184b18c7e3e042bf206e1ace3d1b6ea5bb929fe51robertphillips@google.com#include "chrome/browser/extensions/extension_service.h" 425fb2ce38b3dcb8e60e9e112df23c9d42456d7069commit-bot@chromium.org#include "chrome/browser/extensions/extension_system.h" 4384b18c7e3e042bf206e1ace3d1b6ea5bb929fe51robertphillips@google.com#include "chrome/browser/extensions/extension_web_ui.h" 4484b18c7e3e042bf206e1ace3d1b6ea5bb929fe51robertphillips@google.com#include "chrome/browser/extensions/extension_webkit_preferences.h" 45809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/extensions/suggest_permission_util.h" 463361471a3504ecd0351ff70f4c42d8d6fee963d4commit-bot@chromium.org#include "chrome/browser/geolocation/chrome_access_token_store.h" 47809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/google/google_util.h" 483361471a3504ecd0351ff70f4c42d8d6fee963d4commit-bot@chromium.org#include "chrome/browser/guestview/adview/adview_guest.h" 49c5ba71d2e5cd426def66fa49dcf003e5b2c98dc7robertphillips#include "chrome/browser/guestview/guestview_constants.h" 50809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/guestview/webview/webview_guest.h" 51809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/media/media_capture_devices_dispatcher.h" 52809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h" 53809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/nacl_host/nacl_host_message_filter.h" 54809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/nacl_host/nacl_process_host.h" 55c289743864e2ab926a95e617a5cd1d29b26d1825mtklein@google.com#include "chrome/browser/net/chrome_net_log.h" 56809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/notifications/desktop_notification_service.h" 57809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/notifications/desktop_notification_service_factory.h" 58809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/platform_util.h" 59809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/plugins/plugin_info_message_filter.h" 60809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/prefs/scoped_user_pref_update.h" 61809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/prerender/prerender_final_status.h" 62809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/prerender/prerender_manager.h" 63809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/prerender/prerender_manager_factory.h" 64809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/prerender/prerender_message_filter.h" 65809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/prerender/prerender_tracker.h" 66f168b86d7fafc5c20c87bebc6fd393cb17e120catfarina#include "chrome/browser/printing/printing_message_filter.h" 67809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" 68809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/profiles/profile.h" 69809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/profiles/profile_io_data.h" 70809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/profiles/profile_manager.h" 71809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/renderer_host/chrome_render_message_filter.h" 72410e6e80f00a6c660675c80904807a041c7b7d2amtklein@google.com#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h" 73809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/search/instant_service.h" 7484b18c7e3e042bf206e1ace3d1b6ea5bb929fe51robertphillips@google.com#include "chrome/browser/search/instant_service_factory.h" 75809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/search/search.h" 76809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h" 77809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h" 78809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/speech/tts_message_filter.h" 79809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/spellchecker/spellcheck_message_filter.h" 80809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/ssl/ssl_add_certificate.h" 81809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/ssl/ssl_blocking_page.h" 82809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/ssl/ssl_tab_helper.h" 83809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/tab_contents/tab_util.h" 84809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/ui/chrome_select_file_policy.h" 85809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/ui/sync/sync_promo_ui.h" 86809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h" 87809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" 88809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/user_style_sheet_watcher.h" 89809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/user_style_sheet_watcher_factory.h" 90809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/browser/validation_message_message_filter.h" 91809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/common/child_process_logging.h" 92809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/common/chrome_constants.h" 93809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/common/chrome_paths.h" 94809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/common/chrome_switches.h" 95410e6e80f00a6c660675c80904807a041c7b7d2amtklein@google.com#include "chrome/common/extensions/background_info.h" 96410e6e80f00a6c660675c80904807a041c7b7d2amtklein@google.com#include "chrome/common/extensions/extension.h" 97710c269dc1e503a60265d54109d827c730cd7bc0djsollen@google.com#include "chrome/common/extensions/extension_process_policy.h" 98809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/common/extensions/extension_set.h" 9984b18c7e3e042bf206e1ace3d1b6ea5bb929fe51robertphillips@google.com#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" 100809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/common/extensions/manifest_handlers/shared_module_info.h" 101809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/common/extensions/permissions/permissions_data.h" 102809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/common/extensions/permissions/socket_permission.h" 103809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/common/logging_chrome.h" 104809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/common/pepper_permission_util.h" 105809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/common/pref_names.h" 106809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/common/render_messages.h" 107809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chrome/common/url_constants.h" 108809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "chromeos/chromeos_constants.h" 109809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "components/nacl/common/nacl_process_type.h" 110809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "components/user_prefs/pref_registry_syncable.h" 111809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "content/public/browser/browser_child_process_host.h" 112809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "content/public/browser/browser_main_parts.h" 113809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "content/public/browser/browser_ppapi_host.h" 114809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "content/public/browser/browser_thread.h" 115809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "content/public/browser/browser_url_handler.h" 116809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "content/public/browser/child_process_data.h" 117809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "content/public/browser/child_process_security_policy.h" 118809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "content/public/browser/compositor_util.h" 119809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "content/public/browser/render_process_host.h" 120809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "content/public/browser/render_view_host.h" 121b7961193a3ecca44cf2650d9e446ebaa10b1583dborenet@google.com#include "content/public/browser/resource_context.h" 122809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "content/public/browser/site_instance.h" 123809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "content/public/browser/web_contents.h" 124809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "content/public/browser/web_contents_view.h" 125809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "content/public/common/child_process_host.h" 126809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "content/public/common/content_descriptors.h" 127809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "extensions/browser/view_type_utils.h" 128809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "extensions/common/constants.h" 129809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "extensions/common/switches.h" 130809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "grit/generated_resources.h" 131809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "grit/ui_resources.h" 132809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "net/base/escape.h" 133809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "net/base/mime_util.h" 134809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "net/cookies/canonical_cookie.h" 135809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "net/cookies/cookie_options.h" 136809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "net/ssl/ssl_cert_request_info.h" 137809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "ppapi/host/ppapi_host.h" 138809a2a9fb7deffacd9d2d37ba06a5202d90ee649djsollen@google.com#include "ui/base/l10n/l10n_util.h" 139410e6e80f00a6c660675c80904807a041c7b7d2amtklein@google.com#include "ui/base/resource/resource_bundle.h" 140410e6e80f00a6c660675c80904807a041c7b7d2amtklein@google.com#include "ui/message_center/message_center_util.h" 141410e6e80f00a6c660675c80904807a041c7b7d2amtklein@google.com#include "webkit/browser/fileapi/external_mount_points.h" 142#include "webkit/common/webpreferences.h" 143#include "webkit/plugins/plugin_switches.h" 144 145#if defined(OS_WIN) 146#include "chrome/browser/chrome_browser_main_win.h" 147#include "sandbox/win/src/sandbox_policy.h" 148#elif defined(OS_MACOSX) 149#include "chrome/browser/chrome_browser_main_mac.h" 150#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h" 151#elif defined(OS_CHROMEOS) 152#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h" 153#include "chrome/browser/chromeos/drive/file_system_backend_delegate.h" 154#include "chrome/browser/chromeos/fileapi/file_system_backend.h" 155#include "chrome/browser/chromeos/login/startup_utils.h" 156#include "chrome/browser/chromeos/login/user_manager.h" 157#include "chrome/browser/chromeos/system/input_device_settings.h" 158#include "chromeos/chromeos_switches.h" 159#elif defined(OS_LINUX) 160#include "chrome/browser/chrome_browser_main_linux.h" 161#elif defined(OS_ANDROID) 162#include "chrome/browser/android/crash_dump_manager.h" 163#include "chrome/browser/chrome_browser_main_android.h" 164#include "chrome/common/descriptors_android.h" 165#elif defined(OS_POSIX) 166#include "chrome/browser/chrome_browser_main_posix.h" 167#endif 168 169#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID) 170#include "base/linux_util.h" 171#include "chrome/browser/crash_handler_host_linux.h" 172#endif 173 174#if !defined(OS_ANDROID) 175#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" 176#endif 177 178#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) 179#include "chrome/browser/captive_portal/captive_portal_tab_helper.h" 180#endif 181 182#if defined(OS_ANDROID) 183#include "ui/base/ui_base_paths.h" 184#endif 185 186#if defined(USE_NSS) 187#include "chrome/browser/ui/crypto_module_password_dialog.h" 188#endif 189 190#if !defined(OS_CHROMEOS) 191#include "chrome/browser/signin/signin_manager.h" 192#include "chrome/browser/signin/signin_manager_factory.h" 193#endif 194 195#if !defined(OS_ANDROID) 196#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h" 197#endif 198 199#if defined(ENABLE_WEBRTC) 200#include "chrome/browser/media/webrtc_logging_handler_host.h" 201#endif 202 203#if defined(ENABLE_INPUT_SPEECH) 204#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h" 205#endif 206 207#if defined(FILE_MANAGER_EXTENSION) 208#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h" 209#endif 210 211#if defined(TOOLKIT_GTK) 212#include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h" 213#endif 214 215#if defined(TOOLKIT_VIEWS) 216#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h" 217#endif 218 219#if defined(USE_ASH) 220#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h" 221#endif 222 223#if defined(USE_AURA) 224#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h" 225#endif 226 227#if defined(USE_X11) 228#include "chrome/browser/chrome_browser_main_extra_parts_x11.h" 229#endif 230 231using WebKit::WebWindowFeatures; 232using base::FileDescriptor; 233using content::AccessTokenStore; 234using content::BrowserChildProcessHostIterator; 235using content::BrowserThread; 236using content::BrowserURLHandler; 237using content::ChildProcessSecurityPolicy; 238using content::FileDescriptorInfo; 239using content::QuotaPermissionContext; 240using content::RenderViewHost; 241using content::SiteInstance; 242using content::WebContents; 243using extensions::APIPermission; 244using extensions::Extension; 245using extensions::Manifest; 246using message_center::NotifierId; 247 248namespace { 249 250// Cached version of the locale so we can return the locale on the I/O 251// thread. 252base::LazyInstance<std::string> g_io_thread_application_locale; 253 254#if defined(ENABLE_PLUGINS) 255const char* kPredefinedAllowedSocketOrigins[] = { 256 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client 257 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client) 258 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126 259 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop 260 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop 261 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop 262 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary 263 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089 264 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099 265 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099 266 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099 267 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099 268 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099 269 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099 270 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514 271 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080 272 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080 273 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789 274 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084 275 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084 276 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084 277}; 278#endif 279 280// Returns a copy of the given url with its host set to given host and path set 281// to given path. Other parts of the url will be the same. 282GURL ReplaceURLHostAndPath(const GURL& url, 283 const std::string& host, 284 const std::string& path) { 285 url_canon::Replacements<char> replacements; 286 replacements.SetHost(host.c_str(), 287 url_parse::Component(0, host.length())); 288 replacements.SetPath(path.c_str(), 289 url_parse::Component(0, path.length())); 290 return url.ReplaceComponents(replacements); 291} 292 293// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/". 294GURL AddUberHost(const GURL& url) { 295 const std::string uber_host = chrome::kChromeUIUberHost; 296 const std::string new_path = url.host() + url.path(); 297 298 return ReplaceURLHostAndPath(url, uber_host, new_path); 299} 300 301// If url->host() is "chrome" and url->path() has characters other than the 302// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and 303// returns true. Otherwise returns false. 304bool RemoveUberHost(GURL* url) { 305 if (url->host() != chrome::kChromeUIUberHost) 306 return false; 307 308 if (url->path().empty() || url->path() == "/") 309 return false; 310 311 const std::string old_path = url->path(); 312 313 const std::string::size_type separator = old_path.find('/', 1); 314 std::string new_host; 315 std::string new_path; 316 if (separator == std::string::npos) { 317 new_host = old_path.substr(1); 318 } else { 319 new_host = old_path.substr(1, separator - 1); 320 new_path = old_path.substr(separator); 321 } 322 323 // Do not allow URLs with paths empty before the first slash since we can't 324 // have an empty host. (e.g "foo://chrome//") 325 if (new_host.empty()) 326 return false; 327 328 *url = ReplaceURLHostAndPath(*url, new_host, new_path); 329 330 DCHECK(url->is_valid()); 331 332 return true; 333} 334 335// Handles rewriting Web UI URLs. 336bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { 337 // Do not handle special URLs such as "about:foo" 338 if (!url->host().empty()) { 339 const GURL chrome_url = AddUberHost(*url); 340 341 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will 342 // be called. 343 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( 344 browser_context, chrome_url)) 345 return true; 346 } 347 348 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( 349 browser_context, *url)) 350 return false; 351 352#if defined(OS_CHROMEOS) 353 // Special case : in ChromeOS in Guest mode bookmarks and history are 354 // disabled for security reasons. New tab page explains the reasons, so 355 // we redirect user to new tab page. 356 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) { 357 if (url->SchemeIs(chrome::kChromeUIScheme) && 358 (url->DomainIs(chrome::kChromeUIBookmarksHost) || 359 url->DomainIs(chrome::kChromeUIHistoryHost))) { 360 // Rewrite with new tab URL 361 *url = GURL(chrome::kChromeUINewTabURL); 362 } 363 } 364#endif 365 366 // Special case the new tab page. In older versions of Chrome, the new tab 367 // page was hosted at chrome-internal:<blah>. This might be in people's saved 368 // sessions or bookmarks, so we say any URL with that scheme triggers the new 369 // tab page. 370 if (url->SchemeIs(chrome::kChromeInternalScheme)) { 371 // Rewrite it with the proper new tab URL. 372 *url = GURL(chrome::kChromeUINewTabURL); 373 } 374 375 return true; 376} 377 378// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to 379// "chrome://foo/". 380bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) { 381 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme)) 382 return false; 383 384 return RemoveUberHost(url); 385} 386 387// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions 388// below. Extension, and isolated apps require different privileges to be 389// granted to their RenderProcessHosts. This classification allows us to make 390// sure URLs are served by hosts with the right set of privileges. 391enum RenderProcessHostPrivilege { 392 PRIV_NORMAL, 393 PRIV_HOSTED, 394 PRIV_ISOLATED, 395 PRIV_EXTENSION, 396}; 397 398RenderProcessHostPrivilege GetPrivilegeRequiredByUrl( 399 const GURL& url, 400 ExtensionService* service) { 401 // Default to a normal renderer cause it is lower privileged. This should only 402 // occur if the URL on a site instance is either malformed, or uninitialized. 403 // If it is malformed, then there is no need for better privileges anyways. 404 // If it is uninitialized, but eventually settles on being an a scheme other 405 // than normal webrenderer, the navigation logic will correct us out of band 406 // anyways. 407 if (!url.is_valid()) 408 return PRIV_NORMAL; 409 410 if (url.SchemeIs(extensions::kExtensionScheme)) { 411 const Extension* extension = 412 service->extensions()->GetByID(url.host()); 413 if (extension && 414 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) 415 return PRIV_ISOLATED; 416 if (extension && extension->is_hosted_app()) 417 return PRIV_HOSTED; 418 419 return PRIV_EXTENSION; 420 } 421 422 return PRIV_NORMAL; 423} 424 425RenderProcessHostPrivilege GetProcessPrivilege( 426 content::RenderProcessHost* process_host, 427 extensions::ProcessMap* process_map, 428 ExtensionService* service) { 429 std::set<std::string> extension_ids = 430 process_map->GetExtensionsInProcess(process_host->GetID()); 431 if (extension_ids.empty()) 432 return PRIV_NORMAL; 433 434 for (std::set<std::string>::iterator iter = extension_ids.begin(); 435 iter != extension_ids.end(); ++iter) { 436 const Extension* extension = service->GetExtensionById(*iter, false); 437 if (extension && 438 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) 439 return PRIV_ISOLATED; 440 if (extension && extension->is_hosted_app()) 441 return PRIV_HOSTED; 442 } 443 444 return PRIV_EXTENSION; 445} 446 447bool CertMatchesFilter(const net::X509Certificate& cert, 448 const base::DictionaryValue& filter) { 449 // TODO(markusheintz): This is the minimal required filter implementation. 450 // Implement a better matcher. 451 452 // An empty filter matches any client certificate since no requirements are 453 // specified at all. 454 if (filter.empty()) 455 return true; 456 457 std::string common_name; 458 if (filter.GetString("ISSUER.CN", &common_name) && 459 (cert.issuer().common_name == common_name)) { 460 return true; 461 } 462 return false; 463} 464 465// Fills |map| with the per-script font prefs under path |map_name|. 466void FillFontFamilyMap(const PrefService* prefs, 467 const char* map_name, 468 webkit_glue::ScriptFontFamilyMap* map) { 469 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { 470 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; 471 std::string pref_name = base::StringPrintf("%s.%s", map_name, script); 472 std::string font_family = prefs->GetString(pref_name.c_str()); 473 if (!font_family.empty()) 474 (*map)[script] = UTF8ToUTF16(font_family); 475 } 476} 477 478#if defined(OS_POSIX) && !defined(OS_MACOSX) 479int GetCrashSignalFD(const CommandLine& command_line) { 480 if (command_line.HasSwitch(switches::kExtensionProcess)) { 481 ExtensionCrashHandlerHostLinux* crash_handler = 482 ExtensionCrashHandlerHostLinux::GetInstance(); 483 return crash_handler->GetDeathSignalSocket(); 484 } 485 486 std::string process_type = 487 command_line.GetSwitchValueASCII(switches::kProcessType); 488 489 if (process_type == switches::kRendererProcess) 490 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); 491 492 if (process_type == switches::kPluginProcess) 493 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); 494 495 if (process_type == switches::kPpapiPluginProcess) 496 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); 497 498 if (process_type == switches::kGpuProcess) 499 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); 500 501 return -1; 502} 503#endif // defined(OS_POSIX) && !defined(OS_MACOSX) 504 505#if !defined(OS_CHROMEOS) 506GURL GetEffectiveURLForSignin(const GURL& url) { 507 CHECK(SigninManager::IsWebBasedSigninFlowURL(url)); 508 509 GURL effective_url(SigninManager::kChromeSigninEffectiveSite); 510 // Copy the path because the argument to SetPathStr must outlive 511 // the Replacements object. 512 const std::string path_copy(url.path()); 513 GURL::Replacements replacements; 514 replacements.SetPathStr(path_copy); 515 effective_url = effective_url.ReplaceComponents(replacements); 516 return effective_url; 517} 518#endif 519 520void SetApplicationLocaleOnIOThread(const std::string& locale) { 521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 522 g_io_thread_application_locale.Get() = locale; 523} 524 525#if !defined(OS_ANDROID) 526struct BlockedPopupParams { 527 BlockedPopupParams(const GURL& target_url, 528 const content::Referrer& referrer, 529 WindowOpenDisposition disposition, 530 const WebWindowFeatures& features, 531 bool user_gesture, 532 bool opener_suppressed, 533 int render_process_id, 534 int opener_id) 535 : target_url(target_url), 536 referrer(referrer), 537 disposition(disposition), 538 features(features), 539 user_gesture(user_gesture), 540 opener_suppressed(opener_suppressed), 541 render_process_id(render_process_id), 542 opener_id(opener_id) 543 {} 544 545 GURL target_url; 546 content::Referrer referrer; 547 WindowOpenDisposition disposition; 548 WebWindowFeatures features; 549 bool user_gesture; 550 bool opener_suppressed; 551 int render_process_id; 552 int opener_id; 553}; 554 555void HandleBlockedPopupOnUIThread(const BlockedPopupParams& params) { 556 WebContents* tab = 557 tab_util::GetWebContentsByID(params.render_process_id, params.opener_id); 558 if (!tab) 559 return; 560 561 prerender::PrerenderManager* prerender_manager = 562 prerender::PrerenderManagerFactory::GetForProfile( 563 Profile::FromBrowserContext(tab->GetBrowserContext())); 564 if (prerender_manager) { 565 prerender_manager->DestroyPrerenderForRenderView( 566 params.render_process_id, 567 params.opener_id, 568 prerender::FINAL_STATUS_CREATE_NEW_WINDOW); 569 } 570 571 PopupBlockerTabHelper* popup_helper = 572 PopupBlockerTabHelper::FromWebContents(tab); 573 if (!popup_helper) 574 return; 575 popup_helper->AddBlockedPopup(params.target_url, 576 params.referrer, 577 params.disposition, 578 params.features, 579 params.user_gesture, 580 params.opener_suppressed); 581} 582#endif 583 584} // namespace 585 586namespace chrome { 587 588ChromeContentBrowserClient::ChromeContentBrowserClient() { 589#if defined(ENABLE_PLUGINS) 590 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) 591 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); 592#endif 593 594 permissions_policy_delegate_.reset( 595 new extensions::BrowserPermissionsPolicyDelegate()); 596} 597 598ChromeContentBrowserClient::~ChromeContentBrowserClient() { 599} 600 601// static 602void ChromeContentBrowserClient::RegisterProfilePrefs( 603 user_prefs::PrefRegistrySyncable* registry) { 604 registry->RegisterBooleanPref( 605 prefs::kDisable3DAPIs, 606 false, 607 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 608 registry->RegisterBooleanPref( 609 prefs::kEnableHyperlinkAuditing, 610 true, 611 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 612 registry->RegisterBooleanPref( 613 prefs::kEnableMemoryInfo, 614 false, 615 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 616} 617 618// static 619void ChromeContentBrowserClient::SetApplicationLocale( 620 const std::string& locale) { 621 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 622 623 // This object is guaranteed to outlive all threads so we don't have to 624 // worry about the lack of refcounting and can just post as Unretained. 625 // 626 // The common case is that this function is called early in Chrome startup 627 // before any threads are created (it will also be called later if the user 628 // changes the pref). In this case, there will be no threads created and 629 // posting will fail. When there are no threads, we can just set the string 630 // without worrying about threadsafety. 631 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 632 base::Bind(&SetApplicationLocaleOnIOThread, locale))) { 633 g_io_thread_application_locale.Get() = locale; 634 } 635} 636 637content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( 638 const content::MainFunctionParams& parameters) { 639 ChromeBrowserMainParts* main_parts; 640 // Construct the Main browser parts based on the OS type. 641#if defined(OS_WIN) 642 main_parts = new ChromeBrowserMainPartsWin(parameters); 643#elif defined(OS_MACOSX) 644 main_parts = new ChromeBrowserMainPartsMac(parameters); 645#elif defined(OS_CHROMEOS) 646 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters); 647#elif defined(OS_LINUX) 648 main_parts = new ChromeBrowserMainPartsLinux(parameters); 649#elif defined(OS_ANDROID) 650 main_parts = new ChromeBrowserMainPartsAndroid(parameters); 651#elif defined(OS_POSIX) 652 main_parts = new ChromeBrowserMainPartsPosix(parameters); 653#else 654 NOTREACHED(); 655 main_parts = new ChromeBrowserMainParts(parameters); 656#endif 657 658 chrome::AddProfilesExtraParts(main_parts); 659 660 // Construct additional browser parts. Stages are called in the order in 661 // which they are added. 662#if defined(TOOLKIT_GTK) 663 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk()); 664#endif 665 666#if defined(TOOLKIT_VIEWS) 667 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews()); 668#endif 669 670#if defined(USE_ASH) 671 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh()); 672#endif 673 674#if defined(USE_AURA) 675 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura()); 676#endif 677 678#if defined(USE_X11) 679 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11()); 680#endif 681 682 chrome::AddMetricsExtraParts(main_parts); 683 684 return main_parts; 685} 686 687std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite( 688 content::BrowserContext* browser_context, 689 const GURL& site) { 690 std::string partition_id; 691 692 // The partition ID for webview guest processes is the string value of its 693 // SiteInstance URL - "chrome-guest://app_id/persist?partition". 694 if (site.SchemeIs(chrome::kGuestScheme)) 695 partition_id = site.spec(); 696 697 DCHECK(IsValidStoragePartitionId(browser_context, partition_id)); 698 return partition_id; 699} 700 701bool ChromeContentBrowserClient::IsValidStoragePartitionId( 702 content::BrowserContext* browser_context, 703 const std::string& partition_id) { 704 // The default ID is empty and is always valid. 705 if (partition_id.empty()) 706 return true; 707 708 return GURL(partition_id).is_valid(); 709} 710 711void ChromeContentBrowserClient::GetStoragePartitionConfigForSite( 712 content::BrowserContext* browser_context, 713 const GURL& site, 714 bool can_be_default, 715 std::string* partition_domain, 716 std::string* partition_name, 717 bool* in_memory) { 718 // Default to the browser-wide storage partition and override based on |site| 719 // below. 720 partition_domain->clear(); 721 partition_name->clear(); 722 *in_memory = false; 723 724 // For the webview tag, we create special guest processes, which host the 725 // tag content separately from the main application that embeds the tag. 726 // A webview tag can specify both the partition name and whether the storage 727 // for that partition should be persisted. Each tag gets a SiteInstance with 728 // a specially formatted URL, based on the application it is hosted by and 729 // the partition requested by it. The format for that URL is: 730 // chrome-guest://partition_domain/persist?partition_name 731 if (site.SchemeIs(chrome::kGuestScheme)) { 732 // Since guest URLs are only used for packaged apps, there must be an app 733 // id in the URL. 734 CHECK(site.has_host()); 735 *partition_domain = site.host(); 736 // Since persistence is optional, the path must either be empty or the 737 // literal string. 738 *in_memory = (site.path() != "/persist"); 739 // The partition name is user supplied value, which we have encoded when the 740 // URL was created, so it needs to be decoded. 741 *partition_name = net::UnescapeURLComponent(site.query(), 742 net::UnescapeRule::NORMAL); 743 } else if (site.SchemeIs(extensions::kExtensionScheme)) { 744 // If |can_be_default| is false, the caller is stating that the |site| 745 // should be parsed as if it had isolated storage. In particular it is 746 // important to NOT check ExtensionService for the is_storage_isolated() 747 // attribute because this code path is run during Extension uninstall 748 // to do cleanup after the Extension has already been unloaded from the 749 // ExtensionService. 750 bool is_isolated = !can_be_default; 751 if (can_be_default) { 752 const Extension* extension = NULL; 753 Profile* profile = Profile::FromBrowserContext(browser_context); 754 ExtensionService* extension_service = 755 extensions::ExtensionSystem::Get(profile)->extension_service(); 756 if (extension_service) { 757 extension = 758 extension_service->extensions()->GetExtensionOrAppByURL(site); 759 if (extension && 760 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) { 761 is_isolated = true; 762 } 763 } 764 } 765 766 if (is_isolated) { 767 CHECK(site.has_host()); 768 // For extensions with isolated storage, the the host of the |site| is 769 // the |partition_domain|. The |in_memory| and |partition_name| are only 770 // used in guest schemes so they are cleared here. 771 *partition_domain = site.host(); 772 *in_memory = false; 773 partition_name->clear(); 774 } 775 } 776 777 // Assert that if |can_be_default| is false, the code above must have found a 778 // non-default partition. If this fails, the caller has a serious logic 779 // error about which StoragePartition they expect to be in and it is not 780 // safe to continue. 781 CHECK(can_be_default || !partition_domain->empty()); 782} 783 784content::WebContentsViewDelegate* 785 ChromeContentBrowserClient::GetWebContentsViewDelegate( 786 content::WebContents* web_contents) { 787 return chrome::CreateWebContentsViewDelegate(web_contents); 788} 789 790// Check if the extension activity log is enabled for the profile. 791static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) { 792 // crbug.com/247908 - This should be IsLogEnabled except for an issue 793 // in chrome_frame_net_tests 794 return extensions::ActivityLog::IsLogEnabledOnAnyProfile(); 795} 796 797void ChromeContentBrowserClient::GuestWebContentsCreated( 798 WebContents* guest_web_contents, 799 WebContents* opener_web_contents, 800 content::BrowserPluginGuestDelegate** guest_delegate, 801 scoped_ptr<base::DictionaryValue> extra_params) { 802 if (opener_web_contents) { 803 GuestView* guest = GuestView::FromWebContents(opener_web_contents); 804 if (!guest) { 805 NOTREACHED(); 806 return; 807 } 808 809 switch (guest->GetViewType()) { 810 case GuestView::WEBVIEW: { 811 *guest_delegate = new WebViewGuest(guest_web_contents); 812 break; 813 } 814 case GuestView::ADVIEW: { 815 *guest_delegate = new AdViewGuest(guest_web_contents); 816 break; 817 } 818 default: 819 NOTREACHED(); 820 break; 821 } 822 return; 823 } 824 825 if (!extra_params) { 826 NOTREACHED(); 827 return; 828 } 829 std::string api_type; 830 extra_params->GetString(guestview::kAttributeApi, &api_type); 831 832 if (api_type == "adview") { 833 *guest_delegate = new AdViewGuest(guest_web_contents); 834 } else if (api_type == "webview") { 835 *guest_delegate = new WebViewGuest(guest_web_contents); 836 } else { 837 NOTREACHED(); 838 } 839} 840 841void ChromeContentBrowserClient::GuestWebContentsAttached( 842 WebContents* guest_web_contents, 843 WebContents* embedder_web_contents, 844 int browser_plugin_instance_id, 845 const base::DictionaryValue& extra_params) { 846 Profile* profile = Profile::FromBrowserContext( 847 embedder_web_contents->GetBrowserContext()); 848 ExtensionService* service = 849 extensions::ExtensionSystem::Get(profile)->extension_service(); 850 if (!service) { 851 NOTREACHED(); 852 return; 853 } 854 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL(); 855 const Extension* extension = 856 service->extensions()->GetExtensionOrAppByURL(url); 857 if (!extension) { 858 NOTREACHED(); 859 return; 860 } 861 862 GuestView* guest = GuestView::FromWebContents(guest_web_contents); 863 if (!guest) { 864 NOTREACHED(); 865 return; 866 } 867 guest->Attach(embedder_web_contents, 868 extension->id(), 869 browser_plugin_instance_id, 870 extra_params); 871} 872 873void ChromeContentBrowserClient::RenderProcessHostCreated( 874 content::RenderProcessHost* host) { 875 int id = host->GetID(); 876 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); 877 net::URLRequestContextGetter* context = 878 profile->GetRequestContextForRenderProcess(id); 879 880 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter( 881 id, profile, context)); 882#if defined(ENABLE_PLUGINS) 883 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile)); 884#endif 885#if defined(ENABLE_PRINTING) 886 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile)); 887#endif 888 host->GetChannel()->AddFilter( 889 new SearchProviderInstallStateMessageFilter(id, profile)); 890 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id)); 891#if defined(OS_MACOSX) 892 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id)); 893#endif 894 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter( 895 id, profile, context)); 896 host->GetChannel()->AddFilter( 897 new prerender::PrerenderMessageFilter(id, profile)); 898 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id)); 899 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile)); 900#if defined(ENABLE_WEBRTC) 901 host->GetChannel()->AddFilter(new WebRtcLoggingHandlerHost()); 902#endif 903#if !defined(DISABLE_NACL) 904 ExtensionInfoMap* extension_info_map = 905 extensions::ExtensionSystem::Get(profile)->info_map(); 906 host->GetChannel()->AddFilter(new NaClHostMessageFilter( 907 id, profile->IsOffTheRecord(), 908 profile->GetPath(), extension_info_map, 909 context)); 910#endif 911 912 host->Send(new ChromeViewMsg_SetIsIncognitoProcess( 913 profile->IsOffTheRecord())); 914 915 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled( 916 IsExtensionActivityLogEnabledForProfile(profile))); 917 918 SendExtensionWebRequestStatusToHost(host); 919 920 RendererContentSettingRules rules; 921 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules); 922 host->Send(new ChromeViewMsg_SetContentSettingRules(rules)); 923} 924 925GURL ChromeContentBrowserClient::GetPossiblyPrivilegedURL( 926 content::BrowserContext* browser_context, 927 const GURL& url, 928 bool is_renderer_initiated, 929 content::SiteInstance* current_instance) { 930 Profile* profile = Profile::FromBrowserContext(browser_context); 931 if (!profile) 932 return url; 933 934 // Only return the privileged instant URL if we are entering from a browser- 935 // initiated navigation or if we are already in the instant process. 936 bool is_instant_process = false; 937 int process_id = current_instance->GetProcess()->GetID(); 938 InstantService* instant_service = 939 InstantServiceFactory::GetForProfile(profile); 940 if (instant_service) 941 is_instant_process = instant_service->IsInstantProcess(process_id); 942 943 DCHECK_EQ(is_instant_process, 944 chrome::IsPrivilegedURLForInstant(current_instance->GetSiteURL())); 945 if (!is_renderer_initiated || is_instant_process) { 946 // If the input |url| should be assigned to the Instant renderer, make its 947 // privileged URL distinct from other URLs on the search provider's domain. 948 if (chrome::ShouldAssignURLToInstantRenderer(url, profile)) 949 return chrome::GetPrivilegedURLForInstant(url, profile); 950 } 951 952 return url; 953} 954 955GURL ChromeContentBrowserClient::GetEffectiveURL( 956 content::BrowserContext* browser_context, const GURL& url) { 957 Profile* profile = Profile::FromBrowserContext(browser_context); 958 if (!profile) 959 return url; 960 961#if !defined(OS_CHROMEOS) 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); 968#endif 969 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 = 974 extensions::ExtensionSystem::Get(profile)->extension_service(); 975 if (!extension_service) 976 return url; 977 978 const Extension* extension = extension_service->extensions()-> 979 GetHostedAppByURL(url); 980 if (!extension) 981 return url; 982 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 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 993bool ChromeContentBrowserClient::ShouldUseProcessPerSite( 994 content::BrowserContext* browser_context, const GURL& effective_url) { 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 1004 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile)) 1005 return true; 1006 1007#if !defined(OS_CHROMEOS) 1008 if (SigninManager::IsWebBasedSigninFlowURL(effective_url)) 1009 return true; 1010#endif 1011 1012 if (!effective_url.SchemeIs(extensions::kExtensionScheme)) 1013 return false; 1014 1015 ExtensionService* extension_service = 1016 extensions::ExtensionSystem::Get(profile)->extension_service(); 1017 if (!extension_service) 1018 return false; 1019 1020 const Extension* extension = 1021 extension_service->extensions()->GetExtensionOrAppByURL(effective_url); 1022 if (!extension) 1023 return false; 1024 1025 // If the URL is part of a hosted app that does not have the background 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 1028 // responsiveness. 1029 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) { 1030 if (!extension->HasAPIPermission(APIPermission::kBackground) || 1031 !extensions::BackgroundInfo::AllowJSAccess(extension)) { 1032 return false; 1033 } 1034 } 1035 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. 1039 return true; 1040} 1041 1042// These are treated as WebUI schemes but do not get WebUI bindings. 1043void ChromeContentBrowserClient::GetAdditionalWebUISchemes( 1044 std::vector<std::string>* additional_schemes) { 1045 additional_schemes->push_back(chrome::kChromeSearchScheme); 1046} 1047 1048net::URLRequestContextGetter* 1049ChromeContentBrowserClient::CreateRequestContext( 1050 content::BrowserContext* browser_context, 1051 content::ProtocolHandlerMap* protocol_handlers) { 1052 Profile* profile = Profile::FromBrowserContext(browser_context); 1053 return profile->CreateRequestContext(protocol_handlers); 1054} 1055 1056net::URLRequestContextGetter* 1057ChromeContentBrowserClient::CreateRequestContextForStoragePartition( 1058 content::BrowserContext* browser_context, 1059 const base::FilePath& partition_path, 1060 bool in_memory, 1061 content::ProtocolHandlerMap* protocol_handlers) { 1062 Profile* profile = Profile::FromBrowserContext(browser_context); 1063 return profile->CreateRequestContextForStoragePartition( 1064 partition_path, in_memory, protocol_handlers); 1065} 1066 1067bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) { 1068 return ProfileIOData::IsHandledURL(url); 1069} 1070 1071bool 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 = 1086 service->extensions()->GetExtensionOrAppByURL(url); 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 1098bool ChromeContentBrowserClient::IsSuitableHost( 1099 content::RenderProcessHost* process_host, 1100 const GURL& site_url) { 1101 Profile* profile = 1102 Profile::FromBrowserContext(process_host->GetBrowserContext()); 1103 // This may be NULL during tests. In that case, just assume any site can 1104 // share any host. 1105 if (!profile) 1106 return true; 1107 1108 // Instant URLs should only be in the instant process and instant process 1109 // should only have Instant URLs. 1110 InstantService* instant_service = 1111 InstantServiceFactory::GetForProfile(profile); 1112 if (instant_service) { 1113 bool is_instant_process = instant_service->IsInstantProcess( 1114 process_host->GetID()); 1115 bool should_be_in_instant_process = 1116 chrome::ShouldAssignURLToInstantRenderer(site_url, profile); 1117 if (is_instant_process || should_be_in_instant_process) 1118 return is_instant_process && should_be_in_instant_process; 1119 } 1120 1121#if !defined(OS_CHROMEOS) 1122 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile); 1123 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID())) 1124 return SigninManager::IsWebBasedSigninFlowURL(site_url); 1125#endif 1126 1127 ExtensionService* service = 1128 extensions::ExtensionSystem::Get(profile)->extension_service(); 1129 extensions::ProcessMap* process_map = service->process_map(); 1130 1131 // Don't allow the Task Manager to share a process with anything else. 1132 // Otherwise it can affect the renderers it is observing. 1133 // Note: we could create another RenderProcessHostPrivilege bucket for 1134 // this to allow multiple chrome://tasks instances to share, but that's 1135 // a very unlikely case without serious consequences. 1136 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin()) 1137 return false; 1138 1139 // These may be NULL during tests. In that case, just assume any site can 1140 // share any host. 1141 if (!service || !process_map) 1142 return true; 1143 1144 // Otherwise, just make sure the process privilege matches the privilege 1145 // required by the site. 1146 RenderProcessHostPrivilege privilege_required = 1147 GetPrivilegeRequiredByUrl(site_url, service); 1148 return GetProcessPrivilege(process_host, process_map, service) == 1149 privilege_required; 1150} 1151 1152// This function is trying to limit the amount of processes used by extensions 1153// with background pages. It uses a globally set percentage of processes to 1154// run such extensions and if the limit is exceeded, it returns true, to 1155// indicate to the content module to group extensions together. 1156bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost( 1157 content::BrowserContext* browser_context, const GURL& url) { 1158 // It has to be a valid URL for us to check for an extension. 1159 if (!url.is_valid()) 1160 return false; 1161 1162 Profile* profile = Profile::FromBrowserContext(browser_context); 1163 ExtensionService* service = !profile ? NULL : 1164 extensions::ExtensionSystem::Get(profile)->extension_service(); 1165 if (!service) 1166 return false; 1167 1168 // We have to have a valid extension with background page to proceed. 1169 const Extension* extension = 1170 service->extensions()->GetExtensionOrAppByURL(url); 1171 if (!extension) 1172 return false; 1173 if (!extensions::BackgroundInfo::HasBackgroundPage(extension)) 1174 return false; 1175 1176 std::set<int> process_ids; 1177 size_t max_process_count = 1178 content::RenderProcessHost::GetMaxRendererProcessCount(); 1179 1180 // Go through all profiles to ensure we have total count of extension 1181 // processes containing background pages, otherwise one profile can 1182 // starve the other. 1183 std::vector<Profile*> profiles = g_browser_process->profile_manager()-> 1184 GetLoadedProfiles(); 1185 for (size_t i = 0; i < profiles.size(); ++i) { 1186 ExtensionProcessManager* epm = 1187 extensions::ExtensionSystem::Get(profiles[i])->process_manager(); 1188 for (ExtensionProcessManager::const_iterator iter = 1189 epm->background_hosts().begin(); 1190 iter != epm->background_hosts().end(); ++iter) { 1191 const extensions::ExtensionHost* host = *iter; 1192 process_ids.insert(host->render_process_host()->GetID()); 1193 } 1194 } 1195 1196 if (process_ids.size() > 1197 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) { 1198 return true; 1199 } 1200 1201 return false; 1202} 1203 1204void ChromeContentBrowserClient::SiteInstanceGotProcess( 1205 SiteInstance* site_instance) { 1206 CHECK(site_instance->HasProcess()); 1207 1208 Profile* profile = Profile::FromBrowserContext( 1209 site_instance->GetBrowserContext()); 1210 if (!profile) 1211 return; 1212 1213 // Remember the ID of the Instant process to signal the renderer process 1214 // on startup in |AppendExtraCommandLineSwitches| below. 1215 if (chrome::ShouldAssignURLToInstantRenderer( 1216 site_instance->GetSiteURL(), profile)) { 1217 InstantService* instant_service = 1218 InstantServiceFactory::GetForProfile(profile); 1219 if (instant_service) 1220 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID()); 1221 } 1222 1223#if !defined(OS_CHROMEOS) 1224 // We only expect there to be one signin process as we use process-per-site 1225 // for signin URLs. The signin process will be cleared from SigninManager 1226 // when the renderer is destroyed. 1227 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) { 1228 SigninManager* signin_manager = 1229 SigninManagerFactory::GetForProfile(profile); 1230 if (signin_manager) 1231 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID()); 1232 BrowserThread::PostTask( 1233 BrowserThread::IO, FROM_HERE, 1234 base::Bind(&ExtensionInfoMap::SetSigninProcess, 1235 extensions::ExtensionSystem::Get(profile)->info_map(), 1236 site_instance->GetProcess()->GetID())); 1237 } 1238#endif 1239 1240 ExtensionService* service = 1241 extensions::ExtensionSystem::Get(profile)->extension_service(); 1242 if (!service) 1243 return; 1244 1245 const Extension* extension = service->extensions()->GetExtensionOrAppByURL( 1246 site_instance->GetSiteURL()); 1247 if (!extension) 1248 return; 1249 1250 service->process_map()->Insert(extension->id(), 1251 site_instance->GetProcess()->GetID(), 1252 site_instance->GetId()); 1253 BrowserThread::PostTask( 1254 BrowserThread::IO, FROM_HERE, 1255 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess, 1256 extensions::ExtensionSystem::Get(profile)->info_map(), 1257 extension->id(), 1258 site_instance->GetProcess()->GetID(), 1259 site_instance->GetId())); 1260} 1261 1262void ChromeContentBrowserClient::SiteInstanceDeleting( 1263 SiteInstance* site_instance) { 1264 if (!site_instance->HasProcess()) 1265 return; 1266 1267 Profile* profile = Profile::FromBrowserContext( 1268 site_instance->GetBrowserContext()); 1269 ExtensionService* service = 1270 extensions::ExtensionSystem::Get(profile)->extension_service(); 1271 if (!service) 1272 return; 1273 1274 const Extension* extension = service->extensions()->GetExtensionOrAppByURL( 1275 site_instance->GetSiteURL()); 1276 if (!extension) 1277 return; 1278 1279 service->process_map()->Remove(extension->id(), 1280 site_instance->GetProcess()->GetID(), 1281 site_instance->GetId()); 1282 BrowserThread::PostTask( 1283 BrowserThread::IO, FROM_HERE, 1284 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess, 1285 extensions::ExtensionSystem::Get(profile)->info_map(), 1286 extension->id(), 1287 site_instance->GetProcess()->GetID(), 1288 site_instance->GetId())); 1289} 1290 1291bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation( 1292 SiteInstance* site_instance, 1293 const GURL& current_url, 1294 const GURL& new_url) { 1295 if (current_url.is_empty()) { 1296 // Always choose a new process when navigating to extension URLs. The 1297 // process grouping logic will combine all of a given extension's pages 1298 // into the same process. 1299 if (new_url.SchemeIs(extensions::kExtensionScheme)) 1300 return true; 1301 1302 return false; 1303 } 1304 1305 // Also, we must switch if one is an extension and the other is not the exact 1306 // same extension. 1307 if (current_url.SchemeIs(extensions::kExtensionScheme) || 1308 new_url.SchemeIs(extensions::kExtensionScheme)) { 1309 if (current_url.GetOrigin() != new_url.GetOrigin()) 1310 return true; 1311 } 1312 1313 // The checks below only matter if we can retrieve which extensions are 1314 // installed. 1315 Profile* profile = 1316 Profile::FromBrowserContext(site_instance->GetBrowserContext()); 1317 ExtensionService* service = 1318 extensions::ExtensionSystem::Get(profile)->extension_service(); 1319 if (!service) 1320 return false; 1321 1322 // We must swap if the URL is for an extension and we are not using an 1323 // extension process. 1324 const Extension* new_extension = 1325 service->extensions()->GetExtensionOrAppByURL(new_url); 1326 // Ignore all hosted apps except the Chrome Web Store, since they do not 1327 // require their own BrowsingInstance (e.g., postMessage is ok). 1328 if (new_extension && 1329 new_extension->is_hosted_app() && 1330 new_extension->id() != extension_misc::kWebStoreAppId) 1331 new_extension = NULL; 1332 if (new_extension && 1333 site_instance->HasProcess() && 1334 !service->process_map()->Contains(new_extension->id(), 1335 site_instance->GetProcess()->GetID())) 1336 return true; 1337 1338 return false; 1339} 1340 1341bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect( 1342 content::ResourceContext* resource_context, const GURL& current_url, 1343 const GURL& new_url) { 1344 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); 1345 return extensions::CrossesExtensionProcessBoundary( 1346 io_data->GetExtensionInfoMap()->extensions(), 1347 current_url, new_url, false); 1348} 1349 1350bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) { 1351 return !url.SchemeIs(chrome::kChromeNativeScheme); 1352} 1353 1354std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName( 1355 const std::string& alias_name) { 1356 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name); 1357} 1358 1359void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( 1360 CommandLine* command_line, int child_process_id) { 1361#if defined(OS_MACOSX) 1362 if (IsCrashReporterEnabled()) { 1363 command_line->AppendSwitchASCII(switches::kEnableCrashReporter, 1364 child_process_logging::GetClientId()); 1365 } 1366#elif defined(OS_POSIX) 1367 if (IsCrashReporterEnabled()) { 1368 command_line->AppendSwitchASCII(switches::kEnableCrashReporter, 1369 child_process_logging::GetClientId() + "," + base::GetLinuxDistro()); 1370 } 1371 1372#endif // OS_MACOSX 1373 1374 if (logging::DialogsAreSuppressed()) 1375 command_line->AppendSwitch(switches::kNoErrorDialogs); 1376 1377 std::string process_type = 1378 command_line->GetSwitchValueASCII(switches::kProcessType); 1379 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); 1380 1381 if (browser_command_line.HasSwitch(switches::kChromeFrame)) 1382 command_line->AppendSwitch(switches::kChromeFrame); 1383 1384 if (process_type == switches::kRendererProcess) { 1385 base::FilePath user_data_dir = 1386 browser_command_line.GetSwitchValuePath(switches::kUserDataDir); 1387 if (!user_data_dir.empty()) 1388 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); 1389#if defined(OS_CHROMEOS) 1390 const std::string& login_profile = 1391 browser_command_line.GetSwitchValueASCII( 1392 chromeos::switches::kLoginProfile); 1393 if (!login_profile.empty()) 1394 command_line->AppendSwitchASCII( 1395 chromeos::switches::kLoginProfile, login_profile); 1396#endif 1397 1398 content::RenderProcessHost* process = 1399 content::RenderProcessHost::FromID(child_process_id); 1400 if (process) { 1401 Profile* profile = Profile::FromBrowserContext( 1402 process->GetBrowserContext()); 1403 ExtensionService* extension_service = 1404 extensions::ExtensionSystem::Get(profile)->extension_service(); 1405 if (extension_service) { 1406 extensions::ProcessMap* process_map = extension_service->process_map(); 1407 if (process_map && process_map->Contains(process->GetID())) 1408 command_line->AppendSwitch(switches::kExtensionProcess); 1409 } 1410 1411 PrefService* prefs = profile->GetPrefs(); 1412 // Currently this pref is only registered if applied via a policy. 1413 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) && 1414 prefs->GetBoolean(prefs::kDisable3DAPIs)) { 1415 // Turn this policy into a command line switch. 1416 command_line->AppendSwitch(switches::kDisable3DAPIs); 1417 } 1418 1419 // Disable client-side phishing detection in the renderer if it is 1420 // disabled in the Profile preferences or the browser process. 1421 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) || 1422 !g_browser_process->safe_browsing_detection_service()) { 1423 command_line->AppendSwitch( 1424 switches::kDisableClientSidePhishingDetection); 1425 } 1426 1427 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled)) 1428 command_line->AppendSwitch(switches::kRendererPrintPreview); 1429 1430 InstantService* instant_service = 1431 InstantServiceFactory::GetForProfile(profile); 1432 if (instant_service && 1433 instant_service->IsInstantProcess(process->GetID())) 1434 command_line->AppendSwitch(switches::kInstantProcess); 1435 1436#if !defined(OS_CHROMEOS) 1437 SigninManager* signin_manager = 1438 SigninManagerFactory::GetForProfile(profile); 1439 if (signin_manager && signin_manager->IsSigninProcess(process->GetID())) 1440 command_line->AppendSwitch(switches::kSigninProcess); 1441#endif 1442 } 1443 1444 if (content::IsThreadedCompositingEnabled()) 1445 command_line->AppendSwitch(switches::kEnableThreadedCompositing); 1446 1447 if (message_center::IsRichNotificationEnabled()) 1448 command_line->AppendSwitch(switches::kDisableHTMLNotifications); 1449 1450 // Please keep this in alphabetical order. 1451 static const char* const kSwitchNames[] = { 1452 autofill::switches::kDisableInteractiveAutocomplete, 1453 autofill::switches::kEnableExperimentalFormFilling, 1454 autofill::switches::kEnableInteractiveAutocomplete, 1455 extensions::switches::kAllowLegacyExtensionManifests, 1456 extensions::switches::kAllowScriptingGallery, 1457 extensions::switches::kExtensionsOnChromeURLs, 1458 switches::kAllowHTTPBackgroundPage, 1459 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO 1460 // to browser. 1461 switches::kAllowNaClFileHandleAPI, 1462 switches::kAppsCheckoutURL, 1463 switches::kAppsGalleryURL, 1464 switches::kCloudPrintServiceURL, 1465 switches::kDebugPrint, 1466 switches::kDisableBundledPpapiFlash, 1467 switches::kDisableExtensionsResourceWhitelist, 1468 switches::kDisablePnacl, 1469 switches::kDisableScriptedPrintThrottling, 1470 switches::kEnableAdview, 1471 switches::kEnableAdviewSrcAttribute, 1472 switches::kEnableAppWindowControls, 1473 switches::kEnableBenchmarking, 1474 switches::kEnableExperimentalExtensionApis, 1475 switches::kEnableIPCFuzzing, 1476 switches::kEnableNaCl, 1477 switches::kEnableNetBenchmarking, 1478 switches::kEnablePasswordGeneration, 1479 switches::kEnableWatchdog, 1480 switches::kMemoryProfiling, 1481 switches::kMessageLoopHistogrammer, 1482 switches::kNoJsRandomness, 1483 switches::kPlaybackMode, 1484 switches::kPpapiFlashArgs, 1485 switches::kPpapiFlashInProcess, 1486 switches::kPpapiFlashPath, 1487 switches::kPpapiFlashVersion, 1488 switches::kProfilingAtStart, 1489 switches::kProfilingFile, 1490 switches::kProfilingFlush, 1491 switches::kRecordMode, 1492 switches::kSilentDumpOnDCHECK, 1493 switches::kSpdyProxyAuthOrigin, 1494 switches::kWhitelistedExtensionID, 1495 }; 1496 1497 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, 1498 arraysize(kSwitchNames)); 1499 } else if (process_type == switches::kUtilityProcess) { 1500 static const char* const kSwitchNames[] = { 1501 extensions::switches::kExtensionsOnChromeURLs, 1502 switches::kAllowHTTPBackgroundPage, 1503 switches::kEnableExperimentalExtensionApis, 1504 switches::kWhitelistedExtensionID, 1505 }; 1506 1507 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, 1508 arraysize(kSwitchNames)); 1509 } else if (process_type == switches::kPluginProcess) { 1510 static const char* const kSwitchNames[] = { 1511#if defined(OS_CHROMEOS) 1512 chromeos::switches::kLoginProfile, 1513#endif 1514 switches::kMemoryProfiling, 1515 switches::kSilentDumpOnDCHECK, 1516 switches::kUserDataDir, 1517 }; 1518 1519 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, 1520 arraysize(kSwitchNames)); 1521 } else if (process_type == switches::kZygoteProcess) { 1522 static const char* const kSwitchNames[] = { 1523 switches::kUserDataDir, // Make logs go to the right file. 1524 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox. 1525 switches::kDisableBundledPpapiFlash, 1526 switches::kPpapiFlashInProcess, 1527 switches::kPpapiFlashPath, 1528 switches::kPpapiFlashVersion, 1529 }; 1530 1531 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, 1532 arraysize(kSwitchNames)); 1533 } else if (process_type == switches::kGpuProcess) { 1534 base::FilePath user_data_dir = 1535 browser_command_line.GetSwitchValuePath(switches::kUserDataDir); 1536 if (!user_data_dir.empty()) 1537 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); 1538 // If --ignore-gpu-blacklist is passed in, don't send in crash reports 1539 // because GPU is expected to be unreliable. 1540 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) && 1541 !command_line->HasSwitch(switches::kDisableBreakpad)) 1542 command_line->AppendSwitch(switches::kDisableBreakpad); 1543 } 1544 1545 // The command line switch kEnableBenchmarking needs to be specified along 1546 // with the kEnableStatsTable switch to ensure that the stats table global 1547 // is initialized correctly. 1548 if (command_line->HasSwitch(switches::kEnableBenchmarking)) 1549 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable)); 1550} 1551 1552std::string ChromeContentBrowserClient::GetApplicationLocale() { 1553 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) 1554 return g_io_thread_application_locale.Get(); 1555 return g_browser_process->GetApplicationLocale(); 1556} 1557 1558std::string ChromeContentBrowserClient::GetAcceptLangs( 1559 content::BrowserContext* context) { 1560 Profile* profile = Profile::FromBrowserContext(context); 1561 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages); 1562} 1563 1564gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() { 1565 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1566 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON); 1567} 1568 1569bool ChromeContentBrowserClient::AllowAppCache( 1570 const GURL& manifest_url, 1571 const GURL& first_party, 1572 content::ResourceContext* context) { 1573 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1574 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1575 return io_data->GetCookieSettings()-> 1576 IsSettingCookieAllowed(manifest_url, first_party); 1577} 1578 1579bool ChromeContentBrowserClient::AllowGetCookie( 1580 const GURL& url, 1581 const GURL& first_party, 1582 const net::CookieList& cookie_list, 1583 content::ResourceContext* context, 1584 int render_process_id, 1585 int render_view_id) { 1586 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1587 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1588 bool allow = io_data->GetCookieSettings()-> 1589 IsReadingCookieAllowed(url, first_party); 1590 1591 BrowserThread::PostTask( 1592 BrowserThread::UI, FROM_HERE, 1593 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id, 1594 render_view_id, url, first_party, cookie_list, !allow)); 1595 return allow; 1596} 1597 1598bool ChromeContentBrowserClient::AllowSetCookie( 1599 const GURL& url, 1600 const GURL& first_party, 1601 const std::string& cookie_line, 1602 content::ResourceContext* context, 1603 int render_process_id, 1604 int render_view_id, 1605 net::CookieOptions* options) { 1606 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1607 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1608 CookieSettings* cookie_settings = io_data->GetCookieSettings(); 1609 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party); 1610 1611 BrowserThread::PostTask( 1612 BrowserThread::UI, FROM_HERE, 1613 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id, 1614 render_view_id, url, first_party, cookie_line, *options, 1615 !allow)); 1616 return allow; 1617} 1618 1619bool ChromeContentBrowserClient::AllowSaveLocalState( 1620 content::ResourceContext* context) { 1621 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1622 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1623 CookieSettings* cookie_settings = io_data->GetCookieSettings(); 1624 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL); 1625 1626 // TODO(bauerb): Should we also disallow local state if the default is BLOCK? 1627 // Could we even support per-origin settings? 1628 return setting != CONTENT_SETTING_SESSION_ONLY; 1629} 1630 1631bool ChromeContentBrowserClient::AllowWorkerDatabase( 1632 const GURL& url, 1633 const string16& name, 1634 const string16& display_name, 1635 unsigned long estimated_size, 1636 content::ResourceContext* context, 1637 const std::vector<std::pair<int, int> >& render_views) { 1638 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1639 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1640 CookieSettings* cookie_settings = io_data->GetCookieSettings(); 1641 bool allow = cookie_settings->IsSettingCookieAllowed(url, url); 1642 1643 // Record access to database for potential display in UI. 1644 std::vector<std::pair<int, int> >::const_iterator i; 1645 for (i = render_views.begin(); i != render_views.end(); ++i) { 1646 BrowserThread::PostTask( 1647 BrowserThread::UI, FROM_HERE, 1648 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed, 1649 i->first, i->second, url, name, display_name, !allow)); 1650 } 1651 1652 return allow; 1653} 1654 1655bool ChromeContentBrowserClient::AllowWorkerFileSystem( 1656 const GURL& url, 1657 content::ResourceContext* context, 1658 const std::vector<std::pair<int, int> >& render_views) { 1659 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1660 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1661 CookieSettings* cookie_settings = io_data->GetCookieSettings(); 1662 bool allow = cookie_settings->IsSettingCookieAllowed(url, url); 1663 1664 // Record access to file system for potential display in UI. 1665 std::vector<std::pair<int, int> >::const_iterator i; 1666 for (i = render_views.begin(); i != render_views.end(); ++i) { 1667 BrowserThread::PostTask( 1668 BrowserThread::UI, FROM_HERE, 1669 base::Bind(&TabSpecificContentSettings::FileSystemAccessed, 1670 i->first, i->second, url, !allow)); 1671 } 1672 1673 return allow; 1674} 1675 1676bool ChromeContentBrowserClient::AllowWorkerIndexedDB( 1677 const GURL& url, 1678 const string16& name, 1679 content::ResourceContext* context, 1680 const std::vector<std::pair<int, int> >& render_views) { 1681 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1682 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1683 CookieSettings* cookie_settings = io_data->GetCookieSettings(); 1684 bool allow = cookie_settings->IsSettingCookieAllowed(url, url); 1685 1686 // Record access to IndexedDB for potential display in UI. 1687 std::vector<std::pair<int, int> >::const_iterator i; 1688 for (i = render_views.begin(); i != render_views.end(); ++i) { 1689 BrowserThread::PostTask( 1690 BrowserThread::UI, FROM_HERE, 1691 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed, 1692 i->first, i->second, url, name, !allow)); 1693 } 1694 1695 return allow; 1696} 1697 1698net::URLRequestContext* 1699ChromeContentBrowserClient::OverrideRequestContextForURL( 1700 const GURL& url, content::ResourceContext* context) { 1701 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1702 if (url.SchemeIs(extensions::kExtensionScheme)) { 1703 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1704 return io_data->extensions_request_context(); 1705 } 1706 1707 return NULL; 1708} 1709 1710QuotaPermissionContext* 1711ChromeContentBrowserClient::CreateQuotaPermissionContext() { 1712 return new ChromeQuotaPermissionContext(); 1713} 1714 1715void ChromeContentBrowserClient::AllowCertificateError( 1716 int render_process_id, 1717 int render_view_id, 1718 int cert_error, 1719 const net::SSLInfo& ssl_info, 1720 const GURL& request_url, 1721 ResourceType::Type resource_type, 1722 bool overridable, 1723 bool strict_enforcement, 1724 const base::Callback<void(bool)>& callback, 1725 content::CertificateRequestResultType* result) { 1726 if (resource_type != ResourceType::MAIN_FRAME) { 1727 // A sub-resource has a certificate error. The user doesn't really 1728 // have a context for making the right decision, so block the 1729 // request hard, without an info bar to allow showing the insecure 1730 // content. 1731 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY; 1732 return; 1733 } 1734 1735 // If the tab is being prerendered, cancel the prerender and the request. 1736 WebContents* tab = tab_util::GetWebContentsByID( 1737 render_process_id, render_view_id); 1738 if (!tab) { 1739 NOTREACHED(); 1740 return; 1741 } 1742 prerender::PrerenderManager* prerender_manager = 1743 prerender::PrerenderManagerFactory::GetForProfile( 1744 Profile::FromBrowserContext(tab->GetBrowserContext())); 1745 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab, 1746 NULL)) { 1747 if (prerender_manager->prerender_tracker()->TryCancel( 1748 render_process_id, render_view_id, 1749 prerender::FINAL_STATUS_SSL_ERROR)) { 1750 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL; 1751 return; 1752 } 1753 } 1754 1755#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) 1756 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper = 1757 captive_portal::CaptivePortalTabHelper::FromWebContents(tab); 1758 if (captive_portal_tab_helper) 1759 captive_portal_tab_helper->OnSSLCertError(ssl_info); 1760#endif 1761 1762 // Otherwise, display an SSL blocking page. 1763 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable, 1764 strict_enforcement, callback); 1765} 1766 1767void ChromeContentBrowserClient::SelectClientCertificate( 1768 int render_process_id, 1769 int render_view_id, 1770 const net::HttpNetworkSession* network_session, 1771 net::SSLCertRequestInfo* cert_request_info, 1772 const base::Callback<void(net::X509Certificate*)>& callback) { 1773 WebContents* tab = tab_util::GetWebContentsByID( 1774 render_process_id, render_view_id); 1775 if (!tab) { 1776 NOTREACHED(); 1777 return; 1778 } 1779 1780 GURL requesting_url("https://" + cert_request_info->host_and_port); 1781 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://" 1782 << cert_request_info->host_and_port; 1783 1784 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); 1785 scoped_ptr<Value> filter( 1786 profile->GetHostContentSettingsMap()->GetWebsiteSetting( 1787 requesting_url, 1788 requesting_url, 1789 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, 1790 std::string(), NULL)); 1791 1792 if (filter.get()) { 1793 // Try to automatically select a client certificate. 1794 if (filter->IsType(Value::TYPE_DICTIONARY)) { 1795 DictionaryValue* filter_dict = 1796 static_cast<DictionaryValue*>(filter.get()); 1797 1798 const std::vector<scoped_refptr<net::X509Certificate> >& 1799 all_client_certs = cert_request_info->client_certs; 1800 for (size_t i = 0; i < all_client_certs.size(); ++i) { 1801 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) { 1802 // Use the first certificate that is matched by the filter. 1803 callback.Run(all_client_certs[i].get()); 1804 return; 1805 } 1806 } 1807 } else { 1808 NOTREACHED(); 1809 } 1810 } 1811 1812 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab); 1813 if (!ssl_tab_helper) { 1814 // If there is no SSLTabHelper for the given WebContents then we can't 1815 // show the user a dialog to select a client certificate. So we simply 1816 // proceed with no client certificate. 1817 callback.Run(NULL); 1818 return; 1819 } 1820 ssl_tab_helper->ShowClientCertificateRequestDialog( 1821 network_session, cert_request_info, callback); 1822} 1823 1824void ChromeContentBrowserClient::AddCertificate( 1825 net::URLRequest* request, 1826 net::CertificateMimeType cert_type, 1827 const void* cert_data, 1828 size_t cert_size, 1829 int render_process_id, 1830 int render_view_id) { 1831 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size, 1832 render_process_id, render_view_id); 1833} 1834 1835content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() { 1836 return MediaCaptureDevicesDispatcher::GetInstance(); 1837} 1838 1839void ChromeContentBrowserClient::RequestDesktopNotificationPermission( 1840 const GURL& source_origin, 1841 int callback_context, 1842 int render_process_id, 1843 int render_view_id) { 1844#if defined(ENABLE_NOTIFICATIONS) 1845 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1846 WebContents* contents = 1847 tab_util::GetWebContentsByID(render_process_id, render_view_id); 1848 if (!contents) { 1849 NOTREACHED(); 1850 return; 1851 } 1852 1853 // Skip showing the infobar if the request comes from an extension, and that 1854 // extension has the 'notify' permission. (If the extension does not have the 1855 // permission, the user will still be prompted.) 1856 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 1857 ExtensionInfoMap* extension_info_map = 1858 extensions::ExtensionSystem::Get(profile)->info_map(); 1859 DesktopNotificationService* notification_service = 1860 DesktopNotificationServiceFactory::GetForProfile(profile); 1861 const Extension* extension = NULL; 1862 if (extension_info_map) { 1863 ExtensionSet extensions; 1864 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin( 1865 source_origin, render_process_id, 1866 extensions::APIPermission::kNotification, &extensions); 1867 for (ExtensionSet::const_iterator iter = extensions.begin(); 1868 iter != extensions.end(); ++iter) { 1869 if (notification_service->IsNotifierEnabled(NotifierId( 1870 NotifierId::APPLICATION, (*iter)->id()))) { 1871 extension = iter->get(); 1872 break; 1873 } 1874 } 1875 } 1876 RenderViewHost* rvh = 1877 RenderViewHost::FromID(render_process_id, render_view_id); 1878 if (IsExtensionWithPermissionOrSuggestInConsole( 1879 APIPermission::kNotification, extension, rvh)) { 1880 if (rvh) 1881 rvh->DesktopNotificationPermissionRequestDone(callback_context); 1882 return; 1883 } 1884 1885 notification_service->RequestPermission(source_origin, render_process_id, 1886 render_view_id, callback_context, contents); 1887#else 1888 NOTIMPLEMENTED(); 1889#endif 1890} 1891 1892WebKit::WebNotificationPresenter::Permission 1893 ChromeContentBrowserClient::CheckDesktopNotificationPermission( 1894 const GURL& source_origin, 1895 content::ResourceContext* context, 1896 int render_process_id) { 1897#if defined(ENABLE_NOTIFICATIONS) 1898 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1899 // Sometimes a notification may be invoked during the shutdown. 1900 // See http://crbug.com/256638 1901 if (browser_shutdown::IsTryingToQuit()) 1902 return WebKit::WebNotificationPresenter::PermissionNotAllowed; 1903 1904 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 1905 1906 DesktopNotificationService* notification_service = 1907 io_data->GetNotificationService(); 1908 if (notification_service) { 1909 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap(); 1910 ExtensionSet extensions; 1911 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin( 1912 source_origin, render_process_id, 1913 extensions::APIPermission::kNotification, &extensions); 1914 for (ExtensionSet::const_iterator iter = extensions.begin(); 1915 iter != extensions.end(); ++iter) { 1916 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id()); 1917 if (notification_service->IsNotifierEnabled(notifier_id)) 1918 return WebKit::WebNotificationPresenter::PermissionAllowed; 1919 } 1920 1921 return notification_service->HasPermission(source_origin); 1922 } 1923 1924 return WebKit::WebNotificationPresenter::PermissionNotAllowed; 1925#else 1926 return WebKit::WebNotificationPresenter::PermissionAllowed; 1927#endif 1928} 1929 1930void ChromeContentBrowserClient::ShowDesktopNotification( 1931 const content::ShowDesktopNotificationHostMsgParams& params, 1932 int render_process_id, 1933 int render_view_id, 1934 bool worker) { 1935#if defined(ENABLE_NOTIFICATIONS) 1936 RenderViewHost* rvh = RenderViewHost::FromID( 1937 render_process_id, render_view_id); 1938 if (!rvh) { 1939 NOTREACHED(); 1940 return; 1941 } 1942 1943 content::RenderProcessHost* process = rvh->GetProcess(); 1944 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); 1945 DesktopNotificationService* service = 1946 DesktopNotificationServiceFactory::GetForProfile(profile); 1947 service->ShowDesktopNotification( 1948 params, render_process_id, render_view_id, 1949 worker ? DesktopNotificationService::WorkerNotification : 1950 DesktopNotificationService::PageNotification); 1951#else 1952 NOTIMPLEMENTED(); 1953#endif 1954} 1955 1956void ChromeContentBrowserClient::CancelDesktopNotification( 1957 int render_process_id, 1958 int render_view_id, 1959 int notification_id) { 1960#if defined(ENABLE_NOTIFICATIONS) 1961 RenderViewHost* rvh = RenderViewHost::FromID( 1962 render_process_id, render_view_id); 1963 if (!rvh) { 1964 NOTREACHED(); 1965 return; 1966 } 1967 1968 content::RenderProcessHost* process = rvh->GetProcess(); 1969 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); 1970 DesktopNotificationService* service = 1971 DesktopNotificationServiceFactory::GetForProfile(profile); 1972 service->CancelDesktopNotification( 1973 render_process_id, render_view_id, notification_id); 1974#else 1975 NOTIMPLEMENTED(); 1976#endif 1977} 1978 1979bool ChromeContentBrowserClient::CanCreateWindow( 1980 const GURL& opener_url, 1981 const GURL& source_origin, 1982 WindowContainerType container_type, 1983 const GURL& target_url, 1984 const content::Referrer& referrer, 1985 WindowOpenDisposition disposition, 1986 const WebWindowFeatures& features, 1987 bool user_gesture, 1988 bool opener_suppressed, 1989 content::ResourceContext* context, 1990 int render_process_id, 1991 bool is_guest, 1992 int opener_id, 1993 bool* no_javascript_access) { 1994 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1995 1996 *no_javascript_access = false; 1997 1998 // If the opener is trying to create a background window but doesn't have 1999 // the appropriate permission, fail the attempt. 2000 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { 2001 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 2002 ExtensionInfoMap* map = io_data->GetExtensionInfoMap(); 2003 2004 if (!map->SecurityOriginHasAPIPermission( 2005 source_origin, 2006 render_process_id, 2007 APIPermission::kBackground)) { 2008 return false; 2009 } 2010 2011 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may 2012 // return a recently installed Extension even if this CanCreateWindow call 2013 // was made by an old copy of the page in a normal web process. That's ok, 2014 // because the permission check above would have caused an early return 2015 // already. We must use the full URL to find hosted apps, though, and not 2016 // just the origin. 2017 const Extension* extension = 2018 map->extensions().GetExtensionOrAppByURL(opener_url); 2019 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension)) 2020 *no_javascript_access = true; 2021 2022 return true; 2023 } 2024 2025 // No new browser window (popup or tab) in app mode. 2026 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL && 2027 chrome::IsRunningInForcedAppMode()) { 2028 return false; 2029 } 2030 2031#if !defined(OS_ANDROID) 2032 if (CommandLine::ForCurrentProcess()->HasSwitch( 2033 switches::kDisableBetterPopupBlocking)) { 2034 return true; 2035 } 2036 2037 if (is_guest) 2038 return true; 2039 2040 HostContentSettingsMap* content_settings = 2041 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap(); 2042 2043 if ((disposition == NEW_POPUP || disposition == NEW_FOREGROUND_TAB || 2044 disposition == NEW_BACKGROUND_TAB) && !user_gesture && 2045 !CommandLine::ForCurrentProcess()->HasSwitch( 2046 switches::kDisablePopupBlocking)) { 2047 if (content_settings->GetContentSetting(opener_url, 2048 opener_url, 2049 CONTENT_SETTINGS_TYPE_POPUPS, 2050 std::string()) == 2051 CONTENT_SETTING_ALLOW) { 2052 return true; 2053 } 2054 2055 BrowserThread::PostTask(BrowserThread::UI, 2056 FROM_HERE, 2057 base::Bind(&HandleBlockedPopupOnUIThread, 2058 BlockedPopupParams(target_url, 2059 referrer, 2060 disposition, 2061 features, 2062 user_gesture, 2063 opener_suppressed, 2064 render_process_id, 2065 opener_id))); 2066 return false; 2067 } 2068#endif 2069 2070 return true; 2071} 2072 2073std::string ChromeContentBrowserClient::GetWorkerProcessTitle( 2074 const GURL& url, content::ResourceContext* context) { 2075 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 2076 // Check if it's an extension-created worker, in which case we want to use 2077 // the name of the extension. 2078 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); 2079 const Extension* extension = 2080 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host()); 2081 return extension ? extension->name() : std::string(); 2082} 2083 2084void ChromeContentBrowserClient::ResourceDispatcherHostCreated() { 2085 return g_browser_process->ResourceDispatcherHostCreated(); 2086} 2087 2088// TODO(tommi): Rename from Get to Create. 2089content::SpeechRecognitionManagerDelegate* 2090 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() { 2091#if defined(ENABLE_INPUT_SPEECH) 2092 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI(); 2093#else 2094 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just 2095 // need the base delegate without the bubble UI. 2096 return new speech::ChromeSpeechRecognitionManagerDelegate(); 2097#endif 2098} 2099 2100net::NetLog* ChromeContentBrowserClient::GetNetLog() { 2101 return g_browser_process->net_log(); 2102} 2103 2104AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() { 2105 return new ChromeAccessTokenStore(); 2106} 2107 2108bool ChromeContentBrowserClient::IsFastShutdownPossible() { 2109 return true; 2110} 2111 2112void ChromeContentBrowserClient::OverrideWebkitPrefs( 2113 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) { 2114 Profile* profile = Profile::FromBrowserContext( 2115 rvh->GetProcess()->GetBrowserContext()); 2116 PrefService* prefs = profile->GetPrefs(); 2117 2118 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap, 2119 &web_prefs->standard_font_family_map); 2120 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap, 2121 &web_prefs->fixed_font_family_map); 2122 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap, 2123 &web_prefs->serif_font_family_map); 2124 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap, 2125 &web_prefs->sans_serif_font_family_map); 2126 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap, 2127 &web_prefs->cursive_font_family_map); 2128 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap, 2129 &web_prefs->fantasy_font_family_map); 2130 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap, 2131 &web_prefs->pictograph_font_family_map); 2132 2133 web_prefs->default_font_size = 2134 prefs->GetInteger(prefs::kWebKitDefaultFontSize); 2135 web_prefs->default_fixed_font_size = 2136 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize); 2137 web_prefs->minimum_font_size = 2138 prefs->GetInteger(prefs::kWebKitMinimumFontSize); 2139 web_prefs->minimum_logical_font_size = 2140 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize); 2141 2142 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); 2143 2144 web_prefs->javascript_can_open_windows_automatically = 2145 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically); 2146 web_prefs->dom_paste_enabled = 2147 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled); 2148 web_prefs->shrinks_standalone_images_to_fit = 2149 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit); 2150 const DictionaryValue* inspector_settings = 2151 prefs->GetDictionary(prefs::kWebKitInspectorSettings); 2152 if (inspector_settings) { 2153 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd(); 2154 iter.Advance()) { 2155 std::string value; 2156 if (iter.value().GetAsString(&value)) { 2157 web_prefs->inspector_settings.push_back( 2158 std::make_pair(iter.key(), value)); 2159 } 2160 } 2161 } 2162 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks); 2163 2164 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled)) 2165 web_prefs->javascript_enabled = false; 2166 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled)) 2167 web_prefs->web_security_enabled = false; 2168 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled)) 2169 web_prefs->plugins_enabled = false; 2170 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled)) 2171 web_prefs->java_enabled = false; 2172 web_prefs->loads_images_automatically = 2173 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically); 2174 2175 if (prefs->GetBoolean(prefs::kDisable3DAPIs)) 2176 web_prefs->experimental_webgl_enabled = false; 2177 2178 web_prefs->memory_info_enabled = 2179 prefs->GetBoolean(prefs::kEnableMemoryInfo); 2180 web_prefs->allow_displaying_insecure_content = 2181 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent); 2182 web_prefs->allow_running_insecure_content = 2183 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent); 2184#if defined(OS_ANDROID) 2185 web_prefs->font_scale_factor = 2186 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor)); 2187 web_prefs->force_enable_zoom = 2188 prefs->GetBoolean(prefs::kWebKitForceEnableZoom); 2189#if defined(GOOGLE_TV) 2190 web_prefs->user_gesture_required_for_media_playback = false; 2191#endif 2192#endif 2193 2194#if defined(OS_ANDROID) 2195 web_prefs->password_echo_enabled = 2196 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled); 2197#else 2198 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled; 2199#endif 2200 2201#if defined(OS_CHROMEOS) 2202 // Enable password echo during OOBE when keyboard driven flag is set. 2203 if (chromeos::UserManager::IsInitialized() && 2204 !chromeos::UserManager::Get()->IsUserLoggedIn() && 2205 !chromeos::StartupUtils::IsOobeCompleted() && 2206 chromeos::system::keyboard_settings::ForceKeyboardDrivenUINavigation()) { 2207 web_prefs->password_echo_enabled = true; 2208 } 2209#endif 2210 2211#if defined(OS_ANDROID) 2212 web_prefs->user_style_sheet_enabled = false; 2213#else 2214 // The user stylesheet watcher may not exist in a testing profile. 2215 UserStyleSheetWatcher* user_style_sheet_watcher = 2216 UserStyleSheetWatcherFactory::GetForProfile(profile).get(); 2217 if (user_style_sheet_watcher) { 2218 web_prefs->user_style_sheet_enabled = true; 2219 web_prefs->user_style_sheet_location = 2220 user_style_sheet_watcher->user_style_sheet(); 2221 } else { 2222 web_prefs->user_style_sheet_enabled = false; 2223 } 2224#endif 2225 2226 web_prefs->asynchronous_spell_checking_enabled = true; 2227 web_prefs->unified_textchecker_enabled = true; 2228 2229 web_prefs->uses_universal_detector = 2230 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector); 2231 web_prefs->text_areas_are_resizable = 2232 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable); 2233 web_prefs->hyperlink_auditing_enabled = 2234 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing); 2235 2236 // Make sure we will set the default_encoding with canonical encoding name. 2237 web_prefs->default_encoding = 2238 CharacterEncoding::GetCanonicalEncodingNameByAliasName( 2239 web_prefs->default_encoding); 2240 if (web_prefs->default_encoding.empty()) { 2241 prefs->ClearPref(prefs::kDefaultCharset); 2242 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); 2243 } 2244 DCHECK(!web_prefs->default_encoding.empty()); 2245 2246 if (content::IsForceCompositingModeEnabled()) 2247 web_prefs->force_compositing_mode = true; 2248 2249 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); 2250 extensions::ViewType view_type = extensions::GetViewType(web_contents); 2251 ExtensionService* service = 2252 extensions::ExtensionSystem::Get(profile)->extension_service(); 2253 if (service) { 2254 const GURL& url = rvh->GetSiteInstance()->GetSiteURL(); 2255 const Extension* extension = service->extensions()->GetByID(url.host()); 2256 // Ensure that we are only granting extension preferences to URLs with 2257 // the correct scheme. Without this check, chrome-guest:// schemes used by 2258 // webview tags as well as hosts that happen to match the id of an 2259 // installed extension would get the wrong preferences. 2260 if (url.SchemeIs(extensions::kExtensionScheme)) { 2261 extension_webkit_preferences::SetPreferences( 2262 extension, view_type, web_prefs); 2263 } 2264 } 2265 2266 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) { 2267 web_prefs->allow_scripts_to_close_windows = true; 2268 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) { 2269 // Disable all kinds of acceleration for background pages. 2270 // See http://crbug.com/96005 and http://crbug.com/96006 2271 web_prefs->force_compositing_mode = false; 2272 web_prefs->accelerated_compositing_enabled = false; 2273 } 2274 2275#if defined(FILE_MANAGER_EXTENSION) 2276 // Override the default of suppressing HW compositing for WebUI pages for the 2277 // file manager, which is implemented using WebUI but wants HW acceleration 2278 // for video decode & render. 2279 if (url.SchemeIs(extensions::kExtensionScheme) && 2280 url.host() == kFileBrowserDomain) { 2281 web_prefs->accelerated_compositing_enabled = true; 2282 web_prefs->accelerated_2d_canvas_enabled = true; 2283 } 2284#endif 2285} 2286 2287void ChromeContentBrowserClient::UpdateInspectorSetting( 2288 RenderViewHost* rvh, const std::string& key, const std::string& value) { 2289 content::BrowserContext* browser_context = 2290 rvh->GetProcess()->GetBrowserContext(); 2291 DictionaryPrefUpdate update( 2292 Profile::FromBrowserContext(browser_context)->GetPrefs(), 2293 prefs::kWebKitInspectorSettings); 2294 DictionaryValue* inspector_settings = update.Get(); 2295 inspector_settings->SetWithoutPathExpansion(key, 2296 Value::CreateStringValue(value)); 2297} 2298 2299void ChromeContentBrowserClient::BrowserURLHandlerCreated( 2300 BrowserURLHandler* handler) { 2301 // Add the default URL handlers. 2302 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride, 2303 BrowserURLHandler::null_handler()); 2304 handler->AddHandlerPair(BrowserURLHandler::null_handler(), 2305 &ExtensionWebUI::HandleChromeURLOverrideReverse); 2306 2307 // about: handler. Must come before chrome: handler, since it will 2308 // rewrite about: urls to chrome: URLs and then expect chrome: to 2309 // actually handle them. 2310 handler->AddHandlerPair(&WillHandleBrowserAboutURL, 2311 BrowserURLHandler::null_handler()); 2312 2313 // Handler to rewrite chrome://newtab for InstantExtended. 2314 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite, 2315 &chrome::HandleNewTabURLReverseRewrite); 2316 2317 // chrome: & friends. 2318 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse); 2319} 2320 2321void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { 2322 Profile* profile = Profile::FromBrowserContext( 2323 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext()); 2324 BrowsingDataRemover* remover = 2325 BrowsingDataRemover::CreateForUnboundedRange(profile); 2326 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, 2327 BrowsingDataHelper::UNPROTECTED_WEB); 2328 // BrowsingDataRemover takes care of deleting itself when done. 2329} 2330 2331void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) { 2332 Profile* profile = Profile::FromBrowserContext( 2333 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext()); 2334 BrowsingDataRemover* remover = 2335 BrowsingDataRemover::CreateForUnboundedRange(profile); 2336 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA; 2337 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB); 2338 // BrowsingDataRemover takes care of deleting itself when done. 2339} 2340 2341base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { 2342 return download_util::GetDefaultDownloadDirectory(); 2343} 2344 2345std::string ChromeContentBrowserClient::GetDefaultDownloadName() { 2346 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); 2347} 2348 2349void ChromeContentBrowserClient::DidCreatePpapiPlugin( 2350 content::BrowserPpapiHost* browser_host) { 2351#if defined(ENABLE_PLUGINS) 2352 browser_host->GetPpapiHost()->AddHostFactoryFilter( 2353 scoped_ptr<ppapi::host::HostFactory>( 2354 new ChromeBrowserPepperHostFactory(browser_host))); 2355#endif 2356} 2357 2358content::BrowserPpapiHost* 2359 ChromeContentBrowserClient::GetExternalBrowserPpapiHost( 2360 int plugin_process_id) { 2361 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER); 2362 while (!iter.Done()) { 2363 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate()); 2364 if (host->process() && 2365 host->process()->GetData().id == plugin_process_id) { 2366 // Found the plugin. 2367 return host->browser_ppapi_host(); 2368 } 2369 ++iter; 2370 } 2371 return NULL; 2372} 2373 2374bool ChromeContentBrowserClient::SupportsBrowserPlugin( 2375 content::BrowserContext* browser_context, const GURL& site_url) { 2376 if (CommandLine::ForCurrentProcess()->HasSwitch( 2377 switches::kEnableBrowserPluginForAllViewTypes)) 2378 return true; 2379 2380 Profile* profile = Profile::FromBrowserContext(browser_context); 2381 ExtensionService* service = 2382 extensions::ExtensionSystem::Get(profile)->extension_service(); 2383 if (!service) 2384 return false; 2385 2386 const Extension* extension = 2387 service->extensions()->GetExtensionOrAppByURL(site_url); 2388 if (!extension) 2389 return false; 2390 2391 return extension->HasAPIPermission(APIPermission::kWebView) || 2392 extension->HasAPIPermission(APIPermission::kAdView); 2393} 2394 2395bool ChromeContentBrowserClient::AllowPepperSocketAPI( 2396 content::BrowserContext* browser_context, 2397 const GURL& url, 2398 bool private_api, 2399 const content::SocketPermissionRequest& params) { 2400#if defined(ENABLE_PLUGINS) 2401 Profile* profile = Profile::FromBrowserContext(browser_context); 2402 const ExtensionSet* extension_set = NULL; 2403 if (profile) { 2404 extension_set = extensions::ExtensionSystem::Get(profile)-> 2405 extension_service()->extensions(); 2406 } 2407 2408 if (private_api) { 2409 // Access to private socket APIs is controlled by the whitelist. 2410 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set, 2411 allowed_socket_origins_)) { 2412 return true; 2413 } 2414 } else { 2415 // Access to public socket APIs is controlled by extension permissions. 2416 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) && 2417 extension_set) { 2418 const Extension* extension = extension_set->GetByID(url.host()); 2419 if (extension) { 2420 extensions::SocketPermission::CheckParam check_params( 2421 params.type, params.host, params.port); 2422 if (extensions::PermissionsData::CheckAPIPermissionWithParam( 2423 extension, extensions::APIPermission::kSocket, &check_params)) { 2424 return true; 2425 } 2426 } 2427 } 2428 } 2429 2430 // Allow both public and private APIs if the command line says so. 2431 return IsHostAllowedByCommandLine(url, extension_set, 2432 switches::kAllowNaClSocketAPI); 2433#else 2434 return false; 2435#endif 2436} 2437 2438base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() { 2439 base::FilePath directory; 2440 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory); 2441 return directory.Append(FILE_PATH_LITERAL("Hyphen")); 2442} 2443 2444ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy( 2445 WebContents* web_contents) { 2446 return new ChromeSelectFilePolicy(web_contents); 2447} 2448 2449void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( 2450 std::vector<std::string>* additional_allowed_schemes) { 2451 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( 2452 additional_allowed_schemes); 2453 additional_allowed_schemes->push_back(kChromeUIScheme); 2454 additional_allowed_schemes->push_back(extensions::kExtensionScheme); 2455} 2456 2457void ChromeContentBrowserClient::GetAdditionalFileSystemBackends( 2458 content::BrowserContext* browser_context, 2459 const base::FilePath& storage_partition_path, 2460 ScopedVector<fileapi::FileSystemBackend>* additional_backends) { 2461#if !defined(OS_ANDROID) 2462 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool(); 2463 additional_backends->push_back(new MediaFileSystemBackend( 2464 storage_partition_path, 2465 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken( 2466 MediaFileSystemBackend::kMediaTaskRunnerName)).get())); 2467#endif 2468#if defined(OS_CHROMEOS) 2469 fileapi::ExternalMountPoints* external_mount_points = 2470 content::BrowserContext::GetMountPoints(browser_context); 2471 DCHECK(external_mount_points); 2472 chromeos::FileSystemBackend* backend = 2473 new chromeos::FileSystemBackend( 2474 new drive::FileSystemBackendDelegate(browser_context), 2475 browser_context->GetSpecialStoragePolicy(), 2476 external_mount_points, 2477 fileapi::ExternalMountPoints::GetSystemInstance()); 2478 backend->AddSystemMountPoints(); 2479 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal)); 2480 additional_backends->push_back(backend); 2481#endif 2482} 2483 2484#if defined(OS_POSIX) && !defined(OS_MACOSX) 2485void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess( 2486 const CommandLine& command_line, 2487 int child_process_id, 2488 std::vector<FileDescriptorInfo>* mappings) { 2489#if defined(OS_ANDROID) 2490 base::FilePath data_path; 2491 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path); 2492 DCHECK(!data_path.empty()); 2493 2494 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ; 2495 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak"); 2496 base::PlatformFile f = 2497 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL); 2498 DCHECK(f != base::kInvalidPlatformFileValue); 2499 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor, 2500 FileDescriptor(f, true))); 2501 2502 base::FilePath chrome_resources_pak = 2503 data_path.AppendASCII("chrome_100_percent.pak"); 2504 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL); 2505 DCHECK(f != base::kInvalidPlatformFileValue); 2506 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor, 2507 FileDescriptor(f, true))); 2508 2509 const std::string locale = GetApplicationLocale(); 2510 base::FilePath locale_pak = ResourceBundle::GetSharedInstance(). 2511 GetLocaleFilePath(locale, false); 2512 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL); 2513 DCHECK(f != base::kInvalidPlatformFileValue); 2514 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor, 2515 FileDescriptor(f, true))); 2516 2517 base::FilePath resources_pack_path; 2518 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); 2519 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL); 2520 DCHECK(f != base::kInvalidPlatformFileValue); 2521 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor, 2522 FileDescriptor(f, true))); 2523 2524 if (IsCrashReporterEnabled()) { 2525 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id); 2526 if (f == base::kInvalidPlatformFileValue) { 2527 LOG(ERROR) << "Failed to create file for minidump, crash reporting will " 2528 "be disabled for this process."; 2529 } else { 2530 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor, 2531 FileDescriptor(f, true))); 2532 } 2533 } 2534 2535#else 2536 int crash_signal_fd = GetCrashSignalFD(command_line); 2537 if (crash_signal_fd >= 0) { 2538 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal, 2539 FileDescriptor(crash_signal_fd, 2540 false))); 2541 } 2542#endif // defined(OS_ANDROID) 2543} 2544#endif // defined(OS_POSIX) && !defined(OS_MACOSX) 2545 2546#if defined(OS_WIN) 2547const wchar_t* ChromeContentBrowserClient::GetResourceDllName() { 2548 return chrome::kBrowserResourcesDll; 2549} 2550 2551void ChromeContentBrowserClient::PreSpawnRenderer( 2552 sandbox::TargetPolicy* policy, 2553 bool* success) { 2554 // This code is duplicated in nacl_exe_win_64.cc. 2555 // Allow the server side of a pipe restricted to the "chrome.nacl." 2556 // namespace so that it cannot impersonate other system or other chrome 2557 // service pipes. 2558 sandbox::ResultCode result = policy->AddRule( 2559 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES, 2560 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY, 2561 L"\\\\.\\pipe\\chrome.nacl.*"); 2562 if (result != sandbox::SBOX_ALL_OK) { 2563 *success = false; 2564 return; 2565 } 2566 2567 // Renderers need to send named pipe handles and shared memory 2568 // segment handles to NaCl loader processes. 2569 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES, 2570 sandbox::TargetPolicy::HANDLES_DUP_ANY, 2571 L"File"); 2572 if (result != sandbox::SBOX_ALL_OK) { 2573 *success = false; 2574 return; 2575 } 2576} 2577#endif 2578 2579#if defined(USE_NSS) 2580crypto::CryptoModuleBlockingPasswordDelegate* 2581 ChromeContentBrowserClient::GetCryptoPasswordDelegate( 2582 const GURL& url) { 2583 return chrome::NewCryptoModuleBlockingDialogDelegate( 2584 chrome::kCryptoModulePasswordKeygen, url.host()); 2585} 2586#endif 2587 2588} // namespace chrome 2589