Avi Drissman | ea1be23 | 2022-09-14 23:29:06 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
sdefresne | 34e9bd4 | 2016-12-19 12:45:40 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #import <UIKit/UIKit.h> |
| 6 | |
Justin Cohen | 28f8f9c | 2024-03-04 20:17:39 | [diff] [blame] | 7 | #import "base/allocator/partition_alloc_support.h" |
Gauthier Ambard | 999088c | 2022-09-13 08:36:57 | [diff] [blame] | 8 | #import "base/at_exit.h" |
| 9 | #import "base/debug/crash_logging.h" |
| 10 | #import "base/strings/sys_string_conversions.h" |
Dave Tapuska | c625d8b | 2023-08-14 20:26:11 | [diff] [blame] | 11 | #import "build/blink_buildflags.h" |
ginnnnnnny | b88db3e2 | 2022-11-04 17:15:33 | [diff] [blame] | 12 | #import "components/component_updater/component_updater_paths.h" |
Gauthier Ambard | 999088c | 2022-09-13 08:36:57 | [diff] [blame] | 13 | #import "ios/chrome/app/startup/ios_chrome_main.h" |
| 14 | #import "ios/chrome/app/startup/ios_enable_sandbox_dump_buildflags.h" |
Justin Cohen | 7b1e0df | 2024-10-17 22:25:07 | [diff] [blame] | 15 | #import "ios/chrome/app/tests_hook.h" |
Aman Verma | b6f5557 | 2023-09-28 11:40:53 | [diff] [blame] | 16 | #import "ios/chrome/browser/crash_report/model/crash_helper.h" |
Gauthier Ambard | c417747 | 2023-06-16 16:03:08 | [diff] [blame] | 17 | #import "ios/chrome/browser/shared/model/paths/paths.h" |
Max Li | d2deea41 | 2022-10-12 21:56:42 | [diff] [blame] | 18 | #import "ios/public/provider/chrome/browser/primes/primes_api.h" |
sdefresne | 34e9bd4 | 2016-12-19 12:45:40 | [diff] [blame] | 19 | |
Olivier Robin | d6dd04d | 2020-07-30 06:21:52 | [diff] [blame] | 20 | #if BUILDFLAG(IOS_ENABLE_SANDBOX_DUMP) |
Gauthier Ambard | 999088c | 2022-09-13 08:36:57 | [diff] [blame] | 21 | #import "ios/chrome/app/startup/sandbox_dump.h" // nogncheck |
Olivier Robin | d6dd04d | 2020-07-30 06:21:52 | [diff] [blame] | 22 | #endif // BUILDFLAG(IOS_ENABLE_SANDBOX_DUMP) |
| 23 | |
Dave Tapuska | 8cda9b4 | 2024-05-15 14:30:48 | [diff] [blame] | 24 | #if BUILDFLAG(USE_BLINK) |
| 25 | extern "C" { |
| 26 | // This function must be marked with NO_STACK_PROTECTOR or it may crash on |
| 27 | // return, see the --change-stack-guard-on-fork command line flag. |
Peter Kasting | 7bf5e3f9 | 2024-09-05 17:25:19 | [diff] [blame] | 28 | NO_STACK_PROTECTOR __attribute__((visibility("default"))) int ChromeMain( |
| 29 | int argc, |
| 30 | char* argv[]); |
Dave Tapuska | 8cda9b4 | 2024-05-15 14:30:48 | [diff] [blame] | 31 | } |
| 32 | #endif |
| 33 | |
sdefresne | 34e9bd4 | 2016-12-19 12:45:40 | [diff] [blame] | 34 | namespace { |
| 35 | |
| 36 | NSString* const kUIApplicationDelegateInfoKey = @"UIApplicationDelegate"; |
| 37 | |
| 38 | void StartCrashController() { |
Yuke Liao | d795cd03 | 2017-06-22 20:57:32 | [diff] [blame] | 39 | @autoreleasepool { |
Justin Cohen | b08ae48 | 2021-02-05 20:19:18 | [diff] [blame] | 40 | crash_helper::Start(); |
Yuke Liao | d795cd03 | 2017-06-22 20:57:32 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | |
| 44 | void SetTextDirectionIfPseudoRTLEnabled() { |
| 45 | @autoreleasepool { |
| 46 | NSUserDefaults* standard_defaults = [NSUserDefaults standardUserDefaults]; |
| 47 | if ([standard_defaults boolForKey:@"EnablePseudoRTL"]) { |
Mark Cogan | f31b0da | 2017-09-01 14:23:50 | [diff] [blame] | 48 | NSDictionary* pseudoDict = @{ |
| 49 | @"AppleTextDirection" : @"YES", |
| 50 | @"NSForceRightToLeftWritingDirection" : @"YES" |
| 51 | }; |
Yuke Liao | d795cd03 | 2017-06-22 20:57:32 | [diff] [blame] | 52 | [standard_defaults registerDefaults:pseudoDict]; |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | int RunUIApplicationMain(int argc, char* argv[]) { |
| 58 | @autoreleasepool { |
| 59 | // Fetch the name of the UIApplication delegate stored in the application |
| 60 | // Info.plist under the "UIApplicationDelegate" key. |
| 61 | NSString* delegate_class_name = [[NSBundle mainBundle] |
| 62 | objectForInfoDictionaryKey:kUIApplicationDelegateInfoKey]; |
| 63 | CHECK(delegate_class_name); |
| 64 | |
| 65 | return UIApplicationMain(argc, argv, nil, delegate_class_name); |
| 66 | } |
sdefresne | 34e9bd4 | 2016-12-19 12:45:40 | [diff] [blame] | 67 | } |
| 68 | |
ginnnnnnny | b88db3e2 | 2022-11-04 17:15:33 | [diff] [blame] | 69 | void RegisterPathProviders() { |
| 70 | @autoreleasepool { |
| 71 | ios::RegisterPathProvider(); |
| 72 | |
| 73 | // Bundled components are not supported on ios, so DIR_USER_DATA is passed |
| 74 | // for all three arguments. |
| 75 | component_updater::RegisterPathProvider( |
| 76 | ios::DIR_USER_DATA, ios::DIR_USER_DATA, ios::DIR_USER_DATA); |
| 77 | } |
| 78 | } |
| 79 | |
sdefresne | 34e9bd4 | 2016-12-19 12:45:40 | [diff] [blame] | 80 | } // namespace |
| 81 | |
Dave Tapuska | 8cda9b4 | 2024-05-15 14:30:48 | [diff] [blame] | 82 | int ChromeMain(int argc, char* argv[]) { |
sdefresne | 34e9bd4 | 2016-12-19 12:45:40 | [diff] [blame] | 83 | IOSChromeMain::InitStartTime(); |
sdefresne | 34e9bd4 | 2016-12-19 12:45:40 | [diff] [blame] | 84 | |
Olivier Robin | d6dd04d | 2020-07-30 06:21:52 | [diff] [blame] | 85 | #if BUILDFLAG(IOS_ENABLE_SANDBOX_DUMP) |
| 86 | // Dumps the sandbox if needed. This must be called as soon as possible, |
| 87 | // before actions are done on the sandbox. |
| 88 | // This is a blocking call. |
| 89 | DumpSandboxIfRequested(); |
| 90 | #endif // BUILDFLAG(IOS_ENABLE_SANDBOX_DUMP) |
| 91 | |
Justin Cohen | 7b1e0df | 2024-10-17 22:25:07 | [diff] [blame] | 92 | tests_hook::WipeProfileIfRequested(argc, argv); |
| 93 | |
Yuke Liao | 1764ee1 | 2017-06-15 19:36:10 | [diff] [blame] | 94 | // Set NSUserDefaults keys to force pseudo-RTL if needed. |
Yuke Liao | d795cd03 | 2017-06-22 20:57:32 | [diff] [blame] | 95 | SetTextDirectionIfPseudoRTLEnabled(); |
sdefresne | 34e9bd4 | 2016-12-19 12:45:40 | [diff] [blame] | 96 | |
Yuke Liao | 1764ee1 | 2017-06-15 19:36:10 | [diff] [blame] | 97 | // Create this here since it's needed to start the crash handler. |
| 98 | base::AtExitManager at_exit; |
sdefresne | 34e9bd4 | 2016-12-19 12:45:40 | [diff] [blame] | 99 | |
Max Li | d2deea41 | 2022-10-12 21:56:42 | [diff] [blame] | 100 | // Start Primes logging if it's supported. |
| 101 | if (ios::provider::IsPrimesSupported()) { |
| 102 | ios::provider::PrimesStartLogging(); |
| 103 | } |
| 104 | |
Yuke Liao | 1764ee1 | 2017-06-15 19:36:10 | [diff] [blame] | 105 | // The Crash Controller is started here even if the user opted out since we |
| 106 | // don't have yet preferences. Later on it is stopped if the user opted out. |
| 107 | // In any case reports are not sent if the user opted out. |
| 108 | StartCrashController(); |
| 109 | |
| 110 | // Always ignore SIGPIPE. We check the return value of write(). |
| 111 | CHECK_NE(SIG_ERR, signal(SIGPIPE, SIG_IGN)); |
| 112 | |
ginnnnnnny | b88db3e2 | 2022-11-04 17:15:33 | [diff] [blame] | 113 | // Register Chrome path providers. |
| 114 | RegisterPathProviders(); |
| 115 | |
Arthur Sonzogni | 62e877a | 2024-04-30 16:09:43 | [diff] [blame] | 116 | #if PA_BUILDFLAG(USE_PARTITION_ALLOC) && !BUILDFLAG(USE_BLINK) |
Justin | b4d2907 | 2024-03-19 17:41:00 | [diff] [blame] | 117 | // ContentMainRunnerImpl::Initialize calls this when USE_BLINK is true. |
Justin Cohen | 28f8f9c | 2024-03-04 20:17:39 | [diff] [blame] | 118 | base::allocator::PartitionAllocSupport::Get()->ReconfigureEarlyish(""); |
Arthur Sonzogni | 62e877a | 2024-04-30 16:09:43 | [diff] [blame] | 119 | #endif // PA_BUILDFLAG(USE_PARTITION_ALLOC) && !BUILDFLAG(USE_BLINK) |
Justin Cohen | 28f8f9c | 2024-03-04 20:17:39 | [diff] [blame] | 120 | |
Yuke Liao | d795cd03 | 2017-06-22 20:57:32 | [diff] [blame] | 121 | return RunUIApplicationMain(argc, argv); |
sdefresne | 34e9bd4 | 2016-12-19 12:45:40 | [diff] [blame] | 122 | } |
Dave Tapuska | 8cda9b4 | 2024-05-15 14:30:48 | [diff] [blame] | 123 | |
| 124 | #if !BUILDFLAG(USE_BLINK) |
| 125 | int main(int argc, char* argv[]) { |
| 126 | return ChromeMain(argc, argv); |
| 127 | } |
| 128 | #endif |