summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-06-08 07:46:35 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2018-06-08 07:46:35 +0000
commit49c93774212904291bc2df008b265323ec55e62e (patch)
treefc777e42097d13618e291a9f35b1cb453b7bd16d /src/corelib/kernel
parent92e472302a0ef8390f60fd91cac7f360b199a1e4 (diff)
parent096e37910d93f9c52976600e985c615ea36fe291 (diff)
Merge "Merge remote-tracking branch 'origin/5.11' into dev" into refs/staging/dev
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qcore_mac_objc.mm28
-rw-r--r--src/corelib/kernel/qcore_mac_p.h14
-rw-r--r--src/corelib/kernel/qeventdispatcher_cf.mm17
3 files changed, 48 insertions, 11 deletions
diff --git a/src/corelib/kernel/qcore_mac_objc.mm b/src/corelib/kernel/qcore_mac_objc.mm
index c1062e98b8..97a3acacd2 100644
--- a/src/corelib/kernel/qcore_mac_objc.mm
+++ b/src/corelib/kernel/qcore_mac_objc.mm
@@ -162,6 +162,34 @@ QDebug operator<<(QDebug debug, const QMacAutoReleasePool *pool)
}
#endif // !QT_NO_DEBUG_STREAM
+bool qt_apple_isApplicationExtension()
+{
+ static bool isExtension = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSExtension"];
+ return isExtension;
+}
+
+#if !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_WATCHOS)
+AppleApplication *qt_apple_sharedApplication()
+{
+ // Application extensions are not allowed to access the shared application
+ if (qt_apple_isApplicationExtension()) {
+ qWarning() << "accessing the shared" << [AppleApplication class]
+ << "is not allowed in application extensions";
+
+ // In practice the application is actually available, but the the App
+ // review process will likely catch uses of it, so we return nil just
+ // in case, unless we don't care about being App Store compliant.
+#if QT_CONFIG(appstore_compliant)
+ return nil;
+#endif
+ }
+
+ // We use performSelector so that building with -fapplication-extension will
+ // not mistakenly think we're using the shared application in extensions.
+ return [[AppleApplication class] performSelector:@selector(sharedApplication)];
+}
+#endif
+
#ifdef Q_OS_MACOS
/*
Ensure that Objective-C objects auto-released in main(), directly or indirectly,
diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h
index e8aa24b944..84978bbbc3 100644
--- a/src/corelib/kernel/qcore_mac_p.h
+++ b/src/corelib/kernel/qcore_mac_p.h
@@ -190,6 +190,20 @@ QDebug operator<<(QDebug debug, const QMacAutoReleasePool *pool);
#endif
Q_CORE_EXPORT void qt_apple_check_os_version();
+Q_CORE_EXPORT bool qt_apple_isApplicationExtension();
+
+#if !defined(QT_BOOTSTRAPPED) && !defined(Q_OS_WATCHOS)
+QT_END_NAMESPACE
+# if defined(Q_OS_MACOS)
+Q_FORWARD_DECLARE_OBJC_CLASS(NSApplication);
+using AppleApplication = NSApplication;
+# else
+Q_FORWARD_DECLARE_OBJC_CLASS(UIApplication);
+using AppleApplication = UIApplication;
+# endif
+QT_BEGIN_NAMESPACE
+Q_CORE_EXPORT AppleApplication *qt_apple_sharedApplication();
+#endif
// --------------------------------------------------------------------------
diff --git a/src/corelib/kernel/qeventdispatcher_cf.mm b/src/corelib/kernel/qeventdispatcher_cf.mm
index a6c5ccd7a8..73eeaba03f 100644
--- a/src/corelib/kernel/qeventdispatcher_cf.mm
+++ b/src/corelib/kernel/qeventdispatcher_cf.mm
@@ -90,17 +90,12 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(RunLoopModeTracker);
if ((self = [super init])) {
m_runLoopModes.push(kCFRunLoopDefaultMode);
- [[NSNotificationCenter defaultCenter]
- addObserver:self
- selector:@selector(receivedNotification:)
- name:nil
-#ifdef Q_OS_OSX
- object:NSApplication.sharedApplication];
-#elif defined(Q_OS_WATCHOS)
- object:WKExtension.sharedExtension];
-#else
- // Use performSelector so this can work in an App Extension
- object:[UIApplication.class performSelector:@selector(sharedApplication)]];
+#if !defined(Q_OS_WATCHOS)
+ if (!qt_apple_isApplicationExtension()) {
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self selector:@selector(receivedNotification:)
+ name:nil object:qt_apple_sharedApplication()];
+ }
#endif
}