diff --git a/build/BUILD.gn b/build/BUILD.gn index 7d7e08bb..664e4982 100644 --- a/build/BUILD.gn +++ b/build/BUILD.gn @@ -72,4 +72,17 @@ if (crashpad_is_ios) { ] } } + + if (crashpad_is_in_chromium) { + import("//build/config/ios/ios_sdk.gni") + crashpad_is_ios_app_extension = ios_is_app_extension + } else { + crashpad_is_ios_app_extension = false + } + + config("crashpad_is_ios_app_extension") { + if (crashpad_is_ios_app_extension) { + defines = [ "CRASHPAD_IS_IOS_APP_EXTENSION" ] + } + } } diff --git a/util/BUILD.gn b/util/BUILD.gn index 93b9d544..e7ff4a8a 100644 --- a/util/BUILD.gn +++ b/util/BUILD.gn @@ -597,6 +597,10 @@ crashpad_static_library("util") { ] } + if (crashpad_is_ios) { + configs += [ "../build:crashpad_is_ios_app_extension" ] + } + if (crashpad_is_win) { libs = [ "user32.lib", diff --git a/util/ios/ios_system_data_collector.mm b/util/ios/ios_system_data_collector.mm index 2ec6de59..bcadba6e 100644 --- a/util/ios/ios_system_data_collector.mm +++ b/util/ios/ios_system_data_collector.mm @@ -22,6 +22,7 @@ #import #include "base/apple/mach_logging.h" +#include "base/notreached.h" #include "base/numerics/safe_conversions.h" #include "base/strings/stringprintf.h" #include "base/strings/sys_string_conversions.h" @@ -99,7 +100,14 @@ IOSSystemDataCollector::IOSSystemDataCollector() build_ = ReadStringSysctlByName("kern.osversion"); bundle_identifier_ = base::SysNSStringToUTF8([[NSBundle mainBundle] bundleIdentifier]); +// If CRASHPAD_IS_IOS_APP_EXTENSION is defined, then the code is compiled with +// -fapplication-extension and can only be used in an app extension. Otherwise +// check at runtime whether the code is executing in an app extension or not. +#if defined(CRASHPAD_IS_IOS_APP_EXTENSION) + is_extension_ = true; +#else is_extension_ = [[NSBundle mainBundle].bundlePath hasSuffix:@"appex"]; +#endif #if defined(ARCH_CPU_X86_64) cpu_vendor_ = ReadStringSysctlByName("machdep.cpu.vendor"); @@ -172,6 +180,7 @@ void IOSSystemDataCollector::InstallHandlers() { (__bridge CFStringRef)UIDeviceOrientationDidChangeNotification, this); OrientationDidChangeNotification(); +#if !defined(CRASHPAD_IS_IOS_APP_EXTENSION) // Foreground/Background. Extensions shouldn't use UIApplication*. if (!is_extension_) { AddObserver< @@ -185,6 +194,7 @@ void IOSSystemDataCollector::InstallHandlers() { this); ApplicationDidChangeActiveNotification(); } +#endif } void IOSSystemDataCollector::SystemTimeZoneDidChangeNotification() { @@ -228,6 +238,9 @@ void IOSSystemDataCollector::OrientationDidChangeNotification() { } void IOSSystemDataCollector::ApplicationDidChangeActiveNotification() { +#if defined(CRASHPAD_IS_IOS_APP_EXTENSION) + NOTREACHED_NORETURN(); +#else dispatch_assert_queue_debug(dispatch_get_main_queue()); bool old_active = active_; active_ = [UIApplication sharedApplication].applicationState == @@ -235,6 +248,7 @@ void IOSSystemDataCollector::ApplicationDidChangeActiveNotification() { if (active_ != old_active && active_application_callback_) { active_application_callback_(active_); } +#endif } } // namespace internal