OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/app/shell_main_delegate.h" | 5 #include "content/shell/app/shell_main_delegate.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/cpu.h" | 9 #include "base/cpu.h" |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 #if defined(IPC_MESSAGE_LOG_ENABLED) | 43 #if defined(IPC_MESSAGE_LOG_ENABLED) |
44 #define IPC_MESSAGE_MACROS_LOG_ENABLED | 44 #define IPC_MESSAGE_MACROS_LOG_ENABLED |
45 #include "content/public/common/content_ipc_logging.h" | 45 #include "content/public/common/content_ipc_logging.h" |
46 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \ | 46 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \ |
47 content::RegisterIPCLogger(msg_id, logger) | 47 content::RegisterIPCLogger(msg_id, logger) |
48 #include "content/shell/common/shell_messages.h" | 48 #include "content/shell/common/shell_messages.h" |
49 #endif | 49 #endif |
50 | 50 |
51 #if defined(OS_ANDROID) | 51 #if defined(OS_ANDROID) |
| 52 #include "base/android/apk_assets.h" |
52 #include "base/posix/global_descriptors.h" | 53 #include "base/posix/global_descriptors.h" |
53 #include "content/shell/android/shell_descriptors.h" | 54 #include "content/shell/android/shell_descriptors.h" |
54 #endif | 55 #endif |
55 | 56 |
56 #if defined(OS_MACOSX) | 57 #if defined(OS_MACOSX) |
57 #include "base/mac/os_crash_dumps.h" | 58 #include "base/mac/os_crash_dumps.h" |
58 #include "components/crash/app/breakpad_mac.h" | 59 #include "components/crash/app/breakpad_mac.h" |
59 #include "content/shell/app/paths_mac.h" | 60 #include "content/shell/app/paths_mac.h" |
60 #include "content/shell/app/shell_main_delegate_mac.h" | 61 #include "content/shell/app/shell_main_delegate_mac.h" |
61 #endif // OS_MACOSX | 62 #endif // OS_MACOSX |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 breakpad::InitCrashReporter(process_type); | 288 breakpad::InitCrashReporter(process_type); |
288 } | 289 } |
289 } | 290 } |
290 #endif | 291 #endif |
291 | 292 |
292 void ShellMainDelegate::InitializeResourceBundle() { | 293 void ShellMainDelegate::InitializeResourceBundle() { |
293 #if defined(OS_ANDROID) | 294 #if defined(OS_ANDROID) |
294 // In the Android case, the renderer runs with a different UID and can never | 295 // In the Android case, the renderer runs with a different UID and can never |
295 // access the file system. So we are passed a file descriptor to the | 296 // access the file system. So we are passed a file descriptor to the |
296 // ResourceBundle pak at launch time. | 297 // ResourceBundle pak at launch time. |
297 int pak_fd = | 298 auto global_descriptors = base::GlobalDescriptors::GetInstance(); |
298 base::GlobalDescriptors::GetInstance()->MaybeGet(kShellPakDescriptor); | 299 int pak_fd = global_descriptors->MaybeGet(kShellPakDescriptor); |
| 300 base::MemoryMappedFile::Region pak_region; |
299 if (pak_fd >= 0) { | 301 if (pak_fd >= 0) { |
| 302 pak_region = global_descriptors->GetRegion(kShellPakDescriptor); |
300 // This is clearly wrong. See crbug.com/330930 | 303 // This is clearly wrong. See crbug.com/330930 |
301 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( | 304 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(base::File(pak_fd), |
302 base::File(pak_fd), base::MemoryMappedFile::Region::kWholeFile); | 305 pak_region); |
303 ResourceBundle::GetSharedInstance().AddDataPackFromFile( | 306 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFileRegion( |
304 base::File(pak_fd), ui::SCALE_FACTOR_100P); | 307 base::File(pak_fd), pak_region, ui::SCALE_FACTOR_100P); |
305 return; | 308 } else { |
| 309 pak_fd = |
| 310 base::android::OpenApkAsset("assets/content_shell.pak", &pak_region); |
| 311 DCHECK_GE(pak_fd, 0); |
| 312 global_descriptors->Set(kShellPakDescriptor, pak_fd, pak_region); |
| 313 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion(base::File(pak_fd), |
| 314 pak_region); |
306 } | 315 } |
307 #endif | 316 #else |
308 | |
309 base::FilePath pak_file; | 317 base::FilePath pak_file; |
310 #if defined(OS_MACOSX) | 318 #if defined(OS_MACOSX) |
311 pak_file = GetResourcesPakFilePath(); | 319 pak_file = GetResourcesPakFilePath(); |
312 #else | 320 #else |
313 base::FilePath pak_dir; | 321 base::FilePath pak_dir; |
314 | |
315 #if defined(OS_ANDROID) | |
316 bool got_path = PathService::Get(base::DIR_ANDROID_APP_DATA, &pak_dir); | |
317 DCHECK(got_path); | |
318 pak_dir = pak_dir.Append(FILE_PATH_LITERAL("paks")); | |
319 #else | |
320 PathService::Get(base::DIR_MODULE, &pak_dir); | 322 PathService::Get(base::DIR_MODULE, &pak_dir); |
321 #endif | |
322 | |
323 pak_file = pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak")); | 323 pak_file = pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak")); |
324 #endif | 324 #endif // defined(OS_MACOSX) |
325 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); | 325 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); |
| 326 #endif // defined(OS_ANDROID) |
326 } | 327 } |
327 | 328 |
328 ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() { | 329 ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() { |
329 browser_client_.reset(base::CommandLine::ForCurrentProcess()->HasSwitch( | 330 browser_client_.reset(base::CommandLine::ForCurrentProcess()->HasSwitch( |
330 switches::kRunLayoutTest) | 331 switches::kRunLayoutTest) |
331 ? new LayoutTestContentBrowserClient | 332 ? new LayoutTestContentBrowserClient |
332 : new ShellContentBrowserClient); | 333 : new ShellContentBrowserClient); |
333 | 334 |
334 return browser_client_.get(); | 335 return browser_client_.get(); |
335 } | 336 } |
336 | 337 |
337 ContentRendererClient* ShellMainDelegate::CreateContentRendererClient() { | 338 ContentRendererClient* ShellMainDelegate::CreateContentRendererClient() { |
338 renderer_client_.reset(base::CommandLine::ForCurrentProcess()->HasSwitch( | 339 renderer_client_.reset(base::CommandLine::ForCurrentProcess()->HasSwitch( |
339 switches::kRunLayoutTest) | 340 switches::kRunLayoutTest) |
340 ? new LayoutTestContentRendererClient | 341 ? new LayoutTestContentRendererClient |
341 : new ShellContentRendererClient); | 342 : new ShellContentRendererClient); |
342 | 343 |
343 return renderer_client_.get(); | 344 return renderer_client_.get(); |
344 } | 345 } |
345 | 346 |
346 ContentUtilityClient* ShellMainDelegate::CreateContentUtilityClient() { | 347 ContentUtilityClient* ShellMainDelegate::CreateContentUtilityClient() { |
347 utility_client_.reset(new ShellContentUtilityClient); | 348 utility_client_.reset(new ShellContentUtilityClient); |
348 return utility_client_.get(); | 349 return utility_client_.get(); |
349 } | 350 } |
350 | 351 |
351 } // namespace content | 352 } // namespace content |
OLD | NEW |