[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 5629e0c | 2011-09-12 22:07:36 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 5 | #include "content/shell/browser/shell_content_browser_client.h" |
[email protected] | 5629e0c | 2011-09-12 22:07:36 | [diff] [blame] | 6 | |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 7 | #include <stddef.h> |
dcheng | f63a125 | 2015-12-26 20:43:13 | [diff] [blame] | 8 | #include <utility> |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 9 | |
[email protected] | d6d06a35 | 2013-10-23 07:04:00 | [diff] [blame] | 10 | #include "base/base_switches.h" |
[email protected] | 74830f0 | 2012-01-30 22:27:04 | [diff] [blame] | 11 | #include "base/command_line.h" |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 12 | #include "base/files/file.h" |
thestig | b7aad54f | 2014-09-05 18:25:39 | [diff] [blame] | 13 | #include "base/files/file_util.h" |
ben | 6c7a8a7 | 2016-09-30 18:35:21 | [diff] [blame] | 14 | #include "base/json/json_reader.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 15 | #include "base/macros.h" |
[email protected] | 53d96fb | 2012-11-27 15:36:27 | [diff] [blame] | 16 | #include "base/path_service.h" |
nick | d410644 | 2015-12-08 21:53:11 | [diff] [blame] | 17 | #include "base/strings/pattern.h" |
[email protected] | a553b67 | 2014-04-16 05:40:41 | [diff] [blame] | 18 | #include "base/strings/utf_string_conversions.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 19 | #include "build/build_config.h" |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 20 | #include "content/public/browser/client_certificate_delegate.h" |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 21 | #include "content/public/browser/page_navigator.h" |
[email protected] | 53d96fb | 2012-11-27 15:36:27 | [diff] [blame] | 22 | #include "content/public/browser/render_process_host.h" |
[email protected] | e3503ac | 2012-04-05 15:01:36 | [diff] [blame] | 23 | #include "content/public/browser/resource_dispatcher_host.h" |
[email protected] | 833b700d | 2013-02-18 19:43:00 | [diff] [blame] | 24 | #include "content/public/browser/storage_partition.h" |
[email protected] | 7b38b19 | 2013-03-23 18:39:31 | [diff] [blame] | 25 | #include "content/public/common/content_switches.h" |
ben | 51bb6c6 | 2016-11-17 20:15:57 | [diff] [blame] | 26 | #include "content/public/common/service_names.mojom.h" |
[email protected] | e0f35c9 | 2013-05-08 16:04:34 | [diff] [blame] | 27 | #include "content/public/common/url_constants.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 28 | #include "content/public/common/web_preferences.h" |
ben | ff46163 | 2016-10-06 14:27:33 | [diff] [blame] | 29 | #include "content/public/test/test_service.h" |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 30 | #include "content/shell/browser/shell.h" |
| 31 | #include "content/shell/browser/shell_browser_context.h" |
| 32 | #include "content/shell/browser/shell_browser_main_parts.h" |
vkuzkokov | cbabd58 | 2014-11-06 13:53:54 | [diff] [blame] | 33 | #include "content/shell/browser/shell_devtools_manager_delegate.h" |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 34 | #include "content/shell/browser/shell_net_log.h" |
| 35 | #include "content/shell/browser/shell_quota_permission_context.h" |
| 36 | #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h" |
| 37 | #include "content/shell/browser/shell_web_contents_view_delegate_creator.h" |
[email protected] | b7c504c | 2013-05-07 14:42:12 | [diff] [blame] | 38 | #include "content/shell/common/shell_messages.h" |
| 39 | #include "content/shell/common/shell_switches.h" |
ben | 6c7a8a7 | 2016-09-30 18:35:21 | [diff] [blame] | 40 | #include "grit/shell_resources.h" |
[email protected] | e3c4d527 | 2013-07-17 11:14:01 | [diff] [blame] | 41 | #include "net/url_request/url_request_context_getter.h" |
ben | 6c7a8a7 | 2016-09-30 18:35:21 | [diff] [blame] | 42 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | 707e1c4 | 2013-07-09 21:18:58 | [diff] [blame] | 43 | #include "url/gurl.h" |
nick | d410644 | 2015-12-08 21:53:11 | [diff] [blame] | 44 | #include "url/origin.h" |
[email protected] | 5629e0c | 2011-09-12 22:07:36 | [diff] [blame] | 45 | |
[email protected] | f83a4739 | 2012-07-12 22:15:04 | [diff] [blame] | 46 | #if defined(OS_ANDROID) |
agrieve | 05398f5 | 2015-06-24 18:59:00 | [diff] [blame] | 47 | #include "base/android/apk_assets.h" |
[email protected] | f83a4739 | 2012-07-12 22:15:04 | [diff] [blame] | 48 | #include "base/android/path_utils.h" |
sdefresne | 8ba0b88c | 2015-09-18 10:33:13 | [diff] [blame] | 49 | #include "components/crash/content/browser/crash_dump_manager_android.h" |
[email protected] | f83a4739 | 2012-07-12 22:15:04 | [diff] [blame] | 50 | #include "content/shell/android/shell_descriptors.h" |
| 51 | #endif |
| 52 | |
[email protected] | a7aa8ab | 2013-10-24 07:21:48 | [diff] [blame] | 53 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 54 | #include "base/debug/leak_annotations.h" |
sdefresne | 8ba0b88c | 2015-09-18 10:33:13 | [diff] [blame] | 55 | #include "components/crash/content/app/breakpad_linux.h" |
| 56 | #include "components/crash/content/browser/crash_handler_host_linux.h" |
[email protected] | a7aa8ab | 2013-10-24 07:21:48 | [diff] [blame] | 57 | #include "content/public/common/content_descriptors.h" |
| 58 | #endif |
| 59 | |
[email protected] | a553b67 | 2014-04-16 05:40:41 | [diff] [blame] | 60 | #if defined(OS_WIN) |
| 61 | #include "content/common/sandbox_win.h" |
| 62 | #include "sandbox/win/src/sandbox.h" |
| 63 | #endif |
| 64 | |
alokp | aa2fdfb7 | 2016-02-03 22:55:54 | [diff] [blame] | 65 | #if defined(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS) |
xhwang | b1d65fd | 2016-10-19 20:55:52 | [diff] [blame] | 66 | #include "media/mojo/services/media_service_factory.h" // nogncheck |
alokp | aa2fdfb7 | 2016-02-03 22:55:54 | [diff] [blame] | 67 | #endif |
| 68 | |
ben | d906307 | 2016-11-12 01:32:51 | [diff] [blame] | 69 | #if defined(USE_AURA) |
| 70 | #include "services/navigation/navigation.h" |
| 71 | #endif |
| 72 | |
[email protected] | 5629e0c | 2011-09-12 22:07:36 | [diff] [blame] | 73 | namespace content { |
| 74 | |
[email protected] | 53d96fb | 2012-11-27 15:36:27 | [diff] [blame] | 75 | namespace { |
| 76 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 77 | ShellContentBrowserClient* g_browser_client; |
[email protected] | fbaccee | 2013-08-12 23:24:02 | [diff] [blame] | 78 | bool g_swap_processes_for_redirect = false; |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 79 | |
[email protected] | 1d51882f | 2013-11-12 01:59:02 | [diff] [blame] | 80 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
[email protected] | a7aa8ab | 2013-10-24 07:21:48 | [diff] [blame] | 81 | breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost( |
| 82 | const std::string& process_type) { |
| 83 | base::FilePath dumps_path = |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 84 | base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
[email protected] | a7aa8ab | 2013-10-24 07:21:48 | [diff] [blame] | 85 | switches::kCrashDumpsDir); |
| 86 | { |
| 87 | ANNOTATE_SCOPED_MEMORY_LEAK; |
| 88 | breakpad::CrashHandlerHostLinux* crash_handler = |
| 89 | new breakpad::CrashHandlerHostLinux( |
| 90 | process_type, dumps_path, false); |
| 91 | crash_handler->StartUploaderThread(); |
| 92 | return crash_handler; |
| 93 | } |
| 94 | } |
| 95 | |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 96 | int GetCrashSignalFD(const base::CommandLine& command_line) { |
[email protected] | a7aa8ab | 2013-10-24 07:21:48 | [diff] [blame] | 97 | if (!breakpad::IsCrashReporterEnabled()) |
| 98 | return -1; |
| 99 | |
| 100 | std::string process_type = |
| 101 | command_line.GetSwitchValueASCII(switches::kProcessType); |
| 102 | |
| 103 | if (process_type == switches::kRendererProcess) { |
| 104 | static breakpad::CrashHandlerHostLinux* crash_handler = NULL; |
| 105 | if (!crash_handler) |
| 106 | crash_handler = CreateCrashHandlerHost(process_type); |
| 107 | return crash_handler->GetDeathSignalSocket(); |
| 108 | } |
| 109 | |
[email protected] | a7aa8ab | 2013-10-24 07:21:48 | [diff] [blame] | 110 | if (process_type == switches::kPpapiPluginProcess) { |
| 111 | static breakpad::CrashHandlerHostLinux* crash_handler = NULL; |
| 112 | if (!crash_handler) |
| 113 | crash_handler = CreateCrashHandlerHost(process_type); |
| 114 | return crash_handler->GetDeathSignalSocket(); |
| 115 | } |
| 116 | |
| 117 | if (process_type == switches::kGpuProcess) { |
| 118 | static breakpad::CrashHandlerHostLinux* crash_handler = NULL; |
| 119 | if (!crash_handler) |
| 120 | crash_handler = CreateCrashHandlerHost(process_type); |
| 121 | return crash_handler->GetDeathSignalSocket(); |
| 122 | } |
| 123 | |
| 124 | return -1; |
| 125 | } |
[email protected] | 1d51882f | 2013-11-12 01:59:02 | [diff] [blame] | 126 | #endif // defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
[email protected] | a7aa8ab | 2013-10-24 07:21:48 | [diff] [blame] | 127 | |
[email protected] | 53d96fb | 2012-11-27 15:36:27 | [diff] [blame] | 128 | } // namespace |
| 129 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 130 | ShellContentBrowserClient* ShellContentBrowserClient::Get() { |
| 131 | return g_browser_client; |
| 132 | } |
| 133 | |
[email protected] | fbaccee | 2013-08-12 23:24:02 | [diff] [blame] | 134 | void ShellContentBrowserClient::SetSwapProcessesForRedirect(bool swap) { |
| 135 | g_swap_processes_for_redirect = swap; |
| 136 | } |
| 137 | |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 138 | ShellContentBrowserClient::ShellContentBrowserClient() |
agrieve | fd2d44ab | 2015-06-19 04:33:03 | [diff] [blame] | 139 | : shell_browser_main_parts_(NULL) { |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 140 | DCHECK(!g_browser_client); |
| 141 | g_browser_client = this; |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 142 | } |
| 143 | |
[email protected] | 5629e0c | 2011-09-12 22:07:36 | [diff] [blame] | 144 | ShellContentBrowserClient::~ShellContentBrowserClient() { |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 145 | g_browser_client = NULL; |
[email protected] | 5629e0c | 2011-09-12 22:07:36 | [diff] [blame] | 146 | } |
| 147 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 148 | BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts( |
[email protected] | bdcf915 | 2012-07-19 17:43:21 | [diff] [blame] | 149 | const MainFunctionParams& parameters) { |
jochen | 5ce1af9 | 2016-02-17 20:39:45 | [diff] [blame] | 150 | shell_browser_main_parts_ = new ShellBrowserMainParts(parameters); |
[email protected] | 078822c1b | 2012-04-07 23:16:12 | [diff] [blame] | 151 | return shell_browser_main_parts_; |
[email protected] | 5629e0c | 2011-09-12 22:07:36 | [diff] [blame] | 152 | } |
| 153 | |
nick | d410644 | 2015-12-08 21:53:11 | [diff] [blame] | 154 | bool ShellContentBrowserClient::DoesSiteRequireDedicatedProcess( |
| 155 | BrowserContext* browser_context, |
nick | db193a1 | 2016-09-09 23:09:23 | [diff] [blame] | 156 | const GURL& effective_site_url) { |
nick | d410644 | 2015-12-08 21:53:11 | [diff] [blame] | 157 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 158 | DCHECK(command_line->HasSwitch(switches::kIsolateSitesForTesting)); |
| 159 | std::string pattern = |
| 160 | command_line->GetSwitchValueASCII(switches::kIsolateSitesForTesting); |
nick | fd25e83 | 2016-11-08 22:18:27 | [diff] [blame] | 161 | |
nick | db193a1 | 2016-09-09 23:09:23 | [diff] [blame] | 162 | url::Origin origin(effective_site_url); |
| 163 | |
nick | fd25e83 | 2016-11-08 22:18:27 | [diff] [blame] | 164 | if (!origin.unique()) { |
| 165 | // Schemes like blob or filesystem, which have an embedded origin, should |
| 166 | // already have been canonicalized to the origin site. |
| 167 | CHECK_EQ(origin.scheme(), effective_site_url.scheme()) |
| 168 | << "a site url should have the same scheme as its origin."; |
| 169 | } |
nick | db193a1 | 2016-09-09 23:09:23 | [diff] [blame] | 170 | |
| 171 | // Practically |origin.Serialize()| is the same as |
| 172 | // |effective_site_url.spec()|, except Origin serialization strips the |
| 173 | // trailing "/", which makes for cleaner wildcard patterns. |
| 174 | return base::MatchPattern(origin.Serialize(), pattern); |
nick | d410644 | 2015-12-08 21:53:11 | [diff] [blame] | 175 | } |
| 176 | |
[email protected] | e0f35c9 | 2013-05-08 16:04:34 | [diff] [blame] | 177 | bool ShellContentBrowserClient::IsHandledURL(const GURL& url) { |
| 178 | if (!url.is_valid()) |
| 179 | return false; |
[email protected] | e0f35c9 | 2013-05-08 16:04:34 | [diff] [blame] | 180 | // Keep in sync with ProtocolHandlers added by |
| 181 | // ShellURLRequestContextGetter::GetURLRequestContext(). |
| 182 | static const char* const kProtocolList[] = { |
[email protected] | cca6f39 | 2014-05-28 21:32:26 | [diff] [blame] | 183 | url::kBlobScheme, |
| 184 | url::kFileSystemScheme, |
[email protected] | 2d9748b2 | 2014-02-11 00:17:29 | [diff] [blame] | 185 | kChromeUIScheme, |
[email protected] | b3690f7 | 2014-02-17 00:32:48 | [diff] [blame] | 186 | kChromeDevToolsScheme, |
[email protected] | cca6f39 | 2014-05-28 21:32:26 | [diff] [blame] | 187 | url::kDataScheme, |
| 188 | url::kFileScheme, |
[email protected] | e0f35c9 | 2013-05-08 16:04:34 | [diff] [blame] | 189 | }; |
| 190 | for (size_t i = 0; i < arraysize(kProtocolList); ++i) { |
| 191 | if (url.scheme() == kProtocolList[i]) |
| 192 | return true; |
| 193 | } |
| 194 | return false; |
| 195 | } |
| 196 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 197 | void ShellContentBrowserClient::RegisterInProcessServices( |
| 198 | StaticServiceMap* services) { |
alokp | 6ecb238 | 2016-01-27 00:40:00 | [diff] [blame] | 199 | #if (ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS) |
ben | d906307 | 2016-11-12 01:32:51 | [diff] [blame] | 200 | { |
| 201 | content::ServiceInfo info; |
| 202 | info.factory = base::Bind(&media::CreateMediaServiceForTesting); |
ben | 72b07763 | 2016-11-16 00:23:53 | [diff] [blame] | 203 | services->insert(std::make_pair("media", info)); |
ben | d906307 | 2016-11-12 01:32:51 | [diff] [blame] | 204 | } |
| 205 | #endif |
| 206 | #if defined(USE_AURA) |
| 207 | { |
| 208 | content::ServiceInfo info; |
| 209 | info.factory = base::Bind(&navigation::CreateNavigationService); |
ben | 72b07763 | 2016-11-16 00:23:53 | [diff] [blame] | 210 | services->insert(std::make_pair("navigation", info)); |
ben | d906307 | 2016-11-12 01:32:51 | [diff] [blame] | 211 | } |
alokp | 6ecb238 | 2016-01-27 00:40:00 | [diff] [blame] | 212 | #endif |
| 213 | } |
| 214 | |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 215 | void ShellContentBrowserClient::RegisterOutOfProcessServices( |
| 216 | OutOfProcessServiceMap* services) { |
| 217 | services->insert(std::make_pair(kTestServiceUrl, |
| 218 | base::UTF8ToUTF16("Test Service"))); |
rockot | 4252ddfd | 2015-09-01 19:44:55 | [diff] [blame] | 219 | } |
| 220 | |
ben | 6c7a8a7 | 2016-09-30 18:35:21 | [diff] [blame] | 221 | std::unique_ptr<base::Value> |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame^] | 222 | ShellContentBrowserClient::GetServiceManifestOverlay(base::StringPiece name) { |
ben | 6c7a8a7 | 2016-09-30 18:35:21 | [diff] [blame] | 223 | int id = -1; |
ben | 51bb6c6 | 2016-11-17 20:15:57 | [diff] [blame] | 224 | if (name == content::mojom::kBrowserServiceName) |
ben | 6c7a8a7 | 2016-09-30 18:35:21 | [diff] [blame] | 225 | id = IDR_CONTENT_SHELL_BROWSER_MANIFEST_OVERLAY; |
ben | 51bb6c6 | 2016-11-17 20:15:57 | [diff] [blame] | 226 | else if (name == content::mojom::kRendererServiceName) |
ben | 6c7a8a7 | 2016-09-30 18:35:21 | [diff] [blame] | 227 | id = IDR_CONTENT_SHELL_RENDERER_MANIFEST_OVERLAY; |
ben | 51bb6c6 | 2016-11-17 20:15:57 | [diff] [blame] | 228 | else if (name == content::mojom::kUtilityServiceName) |
ben | 6c7a8a7 | 2016-09-30 18:35:21 | [diff] [blame] | 229 | id = IDR_CONTENT_SHELL_UTILITY_MANIFEST_OVERLAY; |
| 230 | if (id == -1) |
| 231 | return nullptr; |
| 232 | |
| 233 | base::StringPiece manifest_contents = |
| 234 | ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale( |
| 235 | id, ui::ScaleFactor::SCALE_FACTOR_NONE); |
| 236 | return base::JSONReader::Read(manifest_contents); |
| 237 | } |
| 238 | |
erikcorry | c94eff1 | 2015-06-08 11:29:16 | [diff] [blame] | 239 | void ShellContentBrowserClient::AppendExtraCommandLineSwitches( |
| 240 | base::CommandLine* command_line, |
| 241 | int child_process_id) { |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 242 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
lukasza | 756abda | 2016-03-15 21:58:50 | [diff] [blame] | 243 | switches::kExposeInternalsForTesting)) { |
| 244 | command_line->AppendSwitch(switches::kExposeInternalsForTesting); |
| 245 | } |
| 246 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | d6d06a35 | 2013-10-23 07:04:00 | [diff] [blame] | 247 | switches::kEnableCrashReporter)) { |
| 248 | command_line->AppendSwitch(switches::kEnableCrashReporter); |
| 249 | } |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 250 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 251 | switches::kCrashDumpsDir)) { |
[email protected] | a7aa8ab | 2013-10-24 07:21:48 | [diff] [blame] | 252 | command_line->AppendSwitchPath( |
| 253 | switches::kCrashDumpsDir, |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 254 | base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
[email protected] | a7aa8ab | 2013-10-24 07:21:48 | [diff] [blame] | 255 | switches::kCrashDumpsDir)); |
| 256 | } |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 257 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
nick | d410644 | 2015-12-08 21:53:11 | [diff] [blame] | 258 | switches::kIsolateSitesForTesting)) { |
| 259 | command_line->AppendSwitchASCII( |
| 260 | switches::kIsolateSitesForTesting, |
| 261 | base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 262 | switches::kIsolateSitesForTesting)); |
| 263 | } |
| 264 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 265 | switches::kRegisterFontFiles)) { |
[email protected] | a553b67 | 2014-04-16 05:40:41 | [diff] [blame] | 266 | command_line->AppendSwitchASCII( |
| 267 | switches::kRegisterFontFiles, |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 268 | base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
[email protected] | a553b67 | 2014-04-16 05:40:41 | [diff] [blame] | 269 | switches::kRegisterFontFiles)); |
| 270 | } |
[email protected] | 5629e0c | 2011-09-12 22:07:36 | [diff] [blame] | 271 | } |
| 272 | |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 273 | void ShellContentBrowserClient::ResourceDispatcherHostCreated() { |
[email protected] | e3503ac | 2012-04-05 15:01:36 | [diff] [blame] | 274 | resource_dispatcher_host_delegate_.reset( |
jochen | 5ce1af9 | 2016-02-17 20:39:45 | [diff] [blame] | 275 | new ShellResourceDispatcherHostDelegate); |
[email protected] | e3503ac | 2012-04-05 15:01:36 | [diff] [blame] | 276 | ResourceDispatcherHost::Get()->SetDelegate( |
| 277 | resource_dispatcher_host_delegate_.get()); |
[email protected] | 5629e0c | 2011-09-12 22:07:36 | [diff] [blame] | 278 | } |
| 279 | |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 280 | std::string ShellContentBrowserClient::GetDefaultDownloadName() { |
| 281 | return "download"; |
| 282 | } |
| 283 | |
[email protected] | 4c2aa39 | 2012-09-03 01:29:42 | [diff] [blame] | 284 | WebContentsViewDelegate* ShellContentBrowserClient::GetWebContentsViewDelegate( |
| 285 | WebContents* web_contents) { |
[email protected] | 4c2aa39 | 2012-09-03 01:29:42 | [diff] [blame] | 286 | return CreateShellWebContentsViewDelegate(web_contents); |
[email protected] | 4c2aa39 | 2012-09-03 01:29:42 | [diff] [blame] | 287 | } |
| 288 | |
[email protected] | fc41b21 | 2013-03-25 16:04:23 | [diff] [blame] | 289 | QuotaPermissionContext* |
| 290 | ShellContentBrowserClient::CreateQuotaPermissionContext() { |
| 291 | return new ShellQuotaPermissionContext(); |
| 292 | } |
| 293 | |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 294 | void ShellContentBrowserClient::SelectClientCertificate( |
| 295 | WebContents* web_contents, |
| 296 | net::SSLCertRequestInfo* cert_request_info, |
dcheng | 6003e0b | 2016-04-09 18:42:34 | [diff] [blame] | 297 | std::unique_ptr<ClientCertificateDelegate> delegate) { |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 298 | if (!select_client_certificate_callback_.is_null()) |
| 299 | select_client_certificate_callback_.Run(); |
| 300 | } |
| 301 | |
[email protected] | 9896c55 | 2013-08-29 19:03:20 | [diff] [blame] | 302 | SpeechRecognitionManagerDelegate* |
zork | b548de08 | 2014-11-14 21:40:47 | [diff] [blame] | 303 | ShellContentBrowserClient::CreateSpeechRecognitionManagerDelegate() { |
[email protected] | 9896c55 | 2013-08-29 19:03:20 | [diff] [blame] | 304 | return new ShellSpeechRecognitionManagerDelegate(); |
| 305 | } |
| 306 | |
[email protected] | d5869bf | 2013-07-03 16:21:47 | [diff] [blame] | 307 | net::NetLog* ShellContentBrowserClient::GetNetLog() { |
| 308 | return shell_browser_main_parts_->net_log(); |
| 309 | } |
| 310 | |
[email protected] | fbaccee | 2013-08-12 23:24:02 | [diff] [blame] | 311 | bool ShellContentBrowserClient::ShouldSwapProcessesForRedirect( |
clamy | d69748c | 2016-10-07 22:09:44 | [diff] [blame] | 312 | BrowserContext* browser_context, |
[email protected] | fbaccee | 2013-08-12 23:24:02 | [diff] [blame] | 313 | const GURL& current_url, |
| 314 | const GURL& new_url) { |
| 315 | return g_swap_processes_for_redirect; |
| 316 | } |
| 317 | |
dgozman | 252e18d | 2014-09-22 12:40:06 | [diff] [blame] | 318 | DevToolsManagerDelegate* |
| 319 | ShellContentBrowserClient::GetDevToolsManagerDelegate() { |
Pavel Feldman | 43f56b7c | 2016-08-30 00:04:35 | [diff] [blame] | 320 | return new ShellDevToolsManagerDelegate(browser_context()); |
dgozman | 252e18d | 2014-09-22 12:40:06 | [diff] [blame] | 321 | } |
| 322 | |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 323 | void ShellContentBrowserClient::OpenURL( |
| 324 | BrowserContext* browser_context, |
| 325 | const OpenURLParams& params, |
| 326 | const base::Callback<void(WebContents*)>& callback) { |
| 327 | callback.Run(Shell::CreateNewWindow(browser_context, |
| 328 | params.url, |
| 329 | nullptr, |
| 330 | gfx::Size())->web_contents()); |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 331 | } |
| 332 | |
agrieve | 05398f5 | 2015-06-24 18:59:00 | [diff] [blame] | 333 | #if defined(OS_ANDROID) |
[email protected] | f83a4739 | 2012-07-12 22:15:04 | [diff] [blame] | 334 | void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 335 | const base::CommandLine& command_line, |
[email protected] | 12c779c | 2012-10-25 09:39:57 | [diff] [blame] | 336 | int child_process_id, |
agrieve | 05398f5 | 2015-06-24 18:59:00 | [diff] [blame] | 337 | content::FileDescriptorInfo* mappings, |
| 338 | std::map<int, base::MemoryMappedFile::Region>* regions) { |
| 339 | mappings->Share( |
| 340 | kShellPakDescriptor, |
| 341 | base::GlobalDescriptors::GetInstance()->Get(kShellPakDescriptor)); |
| 342 | regions->insert(std::make_pair( |
| 343 | kShellPakDescriptor, |
| 344 | base::GlobalDescriptors::GetInstance()->GetRegion(kShellPakDescriptor))); |
boliu | f4d9dc0 | 2016-09-02 03:24:04 | [diff] [blame] | 345 | |
| 346 | if (breakpad::IsCrashReporterEnabled()) { |
| 347 | base::File f(breakpad::CrashDumpManager::GetInstance()->CreateMinidumpFile( |
| 348 | child_process_id)); |
| 349 | if (!f.IsValid()) { |
| 350 | LOG(ERROR) << "Failed to create file for minidump, crash reporting will " |
| 351 | << "be disabled for this process."; |
| 352 | } else { |
| 353 | mappings->Transfer(kAndroidMinidumpDescriptor, |
| 354 | base::ScopedFD(f.TakePlatformFile())); |
| 355 | } |
| 356 | } |
agrieve | 05398f5 | 2015-06-24 18:59:00 | [diff] [blame] | 357 | } |
| 358 | #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
| 359 | void ShellContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
| 360 | const base::CommandLine& command_line, |
| 361 | int child_process_id, |
| 362 | content::FileDescriptorInfo* mappings) { |
[email protected] | a7aa8ab | 2013-10-24 07:21:48 | [diff] [blame] | 363 | int crash_signal_fd = GetCrashSignalFD(command_line); |
| 364 | if (crash_signal_fd >= 0) { |
morrita | d95714f | 2014-10-01 02:37:24 | [diff] [blame] | 365 | mappings->Share(kCrashDumpSignal, crash_signal_fd); |
[email protected] | a7aa8ab | 2013-10-24 07:21:48 | [diff] [blame] | 366 | } |
[email protected] | f83a4739 | 2012-07-12 22:15:04 | [diff] [blame] | 367 | } |
agrieve | 05398f5 | 2015-06-24 18:59:00 | [diff] [blame] | 368 | #endif // defined(OS_ANDROID) |
[email protected] | f83a4739 | 2012-07-12 22:15:04 | [diff] [blame] | 369 | |
[email protected] | a553b67 | 2014-04-16 05:40:41 | [diff] [blame] | 370 | #if defined(OS_WIN) |
rickyz | 5010931 | 2015-11-11 00:37:08 | [diff] [blame] | 371 | bool ShellContentBrowserClient::PreSpawnRenderer( |
| 372 | sandbox::TargetPolicy* policy) { |
[email protected] | a553b67 | 2014-04-16 05:40:41 | [diff] [blame] | 373 | // Add sideloaded font files for testing. See also DIR_WINDOWS_FONTS |
| 374 | // addition in |StartSandboxedProcess|. |
jam | daca82e | 2015-09-02 06:51:25 | [diff] [blame] | 375 | std::vector<std::string> font_files = switches::GetSideloadFontFiles(); |
[email protected] | a553b67 | 2014-04-16 05:40:41 | [diff] [blame] | 376 | for (std::vector<std::string>::const_iterator i(font_files.begin()); |
| 377 | i != font_files.end(); |
| 378 | ++i) { |
| 379 | policy->AddRule(sandbox::TargetPolicy::SUBSYS_FILES, |
| 380 | sandbox::TargetPolicy::FILES_ALLOW_READONLY, |
| 381 | base::UTF8ToWide(*i).c_str()); |
| 382 | } |
rickyz | 5010931 | 2015-11-11 00:37:08 | [diff] [blame] | 383 | return true; |
[email protected] | a553b67 | 2014-04-16 05:40:41 | [diff] [blame] | 384 | } |
| 385 | #endif // OS_WIN |
| 386 | |
[email protected] | 147f809 | 2012-03-21 11:47:45 | [diff] [blame] | 387 | ShellBrowserContext* ShellContentBrowserClient::browser_context() { |
[email protected] | 3560b57 | 2012-04-04 20:47:32 | [diff] [blame] | 388 | return shell_browser_main_parts_->browser_context(); |
[email protected] | 147f809 | 2012-03-21 11:47:45 | [diff] [blame] | 389 | } |
| 390 | |
[email protected] | 71d504f | 2012-07-25 17:15:28 | [diff] [blame] | 391 | ShellBrowserContext* |
| 392 | ShellContentBrowserClient::off_the_record_browser_context() { |
| 393 | return shell_browser_main_parts_->off_the_record_browser_context(); |
| 394 | } |
| 395 | |
[email protected] | 5629e0c | 2011-09-12 22:07:36 | [diff] [blame] | 396 | } // namespace content |