From a44238bcf8255c73589b33910af841ec9b7c001f Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Thu, 7 Nov 2019 13:34:00 +0000 Subject: [PATCH] Remove macOS changes for "Fix user earns while native Windows and macOS notifications are suppressed" Fixes https://github.com/brave/brave-browser/issues/6818 --- components/brave_ads/browser/BUILD.gn | 6 - .../browser/notification_helper_mac.mm | 194 ++++++++++-------- 2 files changed, 104 insertions(+), 96 deletions(-) diff --git a/components/brave_ads/browser/BUILD.gn b/components/brave_ads/browser/BUILD.gn index 43b8c6bb7a25..a8a2821f33bc 100644 --- a/components/brave_ads/browser/BUILD.gn +++ b/components/brave_ads/browser/BUILD.gn @@ -88,12 +88,6 @@ source_set("browser") { "//ui/message_center/public/cpp", ] - if (is_mac) { - libs = [ - "UserNotifications.framework", - ] - } - if (is_win) { deps += [ "//ui/views", diff --git a/components/brave_ads/browser/notification_helper_mac.mm b/components/brave_ads/browser/notification_helper_mac.mm index 767257dc93a5..6e37919a9625 100644 --- a/components/brave_ads/browser/notification_helper_mac.mm +++ b/components/brave_ads/browser/notification_helper_mac.mm @@ -4,7 +4,11 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #import -#import + +// TODO(https://github.com/brave/brave-browser/issues/5541): Uncomment below +// code when notification_platform_bridge_mac.mm has been updated to use +// UNUserNotificationCenter +// #import #include "base/mac/mac_util.h" #include "base/feature_list.h" @@ -70,111 +74,121 @@ /////////////////////////////////////////////////////////////////////////////// bool NotificationHelperMac::IsAuthorized() const { -#if !defined(OFFICIAL_BUILD) - LOG(WARNING) << "Unable to detect the status of native notifications on non" - " official builds as the app is not code signed"; + // TODO(https://github.com/brave/brave-browser/issues/5541): Uncomment below + // code when notification_platform_bridge_mac.mm has been updated to use + // UNUserNotificationCenter return true; -#else - // TODO(https://openradar.appspot.com/27768556): We must mock this function - // using NotificationHelperMock as a workaround to UNUserNotificationCenter - // throwing an exception during tests - if (@available(macOS 10.14, *)) { - __block bool is_authorized = false; +// #if !defined(OFFICIAL_BUILD) +// LOG(WARNING) << "Unable to detect the status of native notifications on non" +// " official builds as the app is not code signed"; +// return true; +// #else +// // TODO(https://openradar.appspot.com/27768556): We must mock this function +// // using NotificationHelperMock as a workaround to UNUserNotificationCenter +// // throwing an exception during tests - dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); +// if (@available(macOS 10.14, *)) { +// __block bool is_authorized = false; - UNUserNotificationCenter *notificationCenter = - [UNUserNotificationCenter currentNotificationCenter]; +// dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); - [notificationCenter requestAuthorizationWithOptions:UNAuthorizationOptionAlert - completionHandler:^(BOOL granted, NSError * _Nullable error) { - if (granted) { - LOG(INFO) << "User granted authorization to show notifications"; - } else { - LOG(WARNING) << "User denied authorization to show notifications"; - } +// UNUserNotificationCenter *notificationCenter = +// [UNUserNotificationCenter currentNotificationCenter]; - is_authorized = granted; +// [notificationCenter requestAuthorizationWithOptions:UNAuthorizationOptionAlert +// completionHandler:^(BOOL granted, NSError * _Nullable error) { +// if (granted) { +// LOG(INFO) << "User granted authorization to show notifications"; +// } else { +// LOG(WARNING) << "User denied authorization to show notifications"; +// } - dispatch_semaphore_signal(semaphore); - }]; +// is_authorized = granted; - dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - dispatch_release(semaphore); +// dispatch_semaphore_signal(semaphore); +// }]; - if (!is_authorized) { - LOG(WARNING) << "User is not authorized to show notifications"; - } +// dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); +// dispatch_release(semaphore); - return is_authorized; - } +// if (!is_authorized) { +// LOG(WARNING) << "User is not authorized to show notifications"; +// } - return true; -#endif +// return is_authorized; +// } + +// return true; +// #endif } bool NotificationHelperMac::IsEnabled() const { -#if !defined(OFFICIAL_BUILD) - LOG(WARNING) << "Unable to detect the status of native notifications on non" - " official builds as the app is not code signed"; + // TODO(https://github.com/brave/brave-browser/issues/5541): Uncomment below + // code when notification_platform_bridge_mac.mm has been updated to use + // UNUserNotificationCenter return true; -#else - // TODO(https://openradar.appspot.com/27768556): We must mock this function - // using NotificationHelperMock as a workaround to UNUserNotificationCenter - // throwing an exception during tests - - if (@available(macOS 10.14, *)) { - __block bool is_authorized = false; - - dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); - - UNUserNotificationCenter *notificationCenter = - [UNUserNotificationCenter currentNotificationCenter]; - - [notificationCenter getNotificationSettingsWithCompletionHandler: - ^(UNNotificationSettings * _Nonnull settings) { - switch (settings.authorizationStatus) { - case UNAuthorizationStatusDenied: { - LOG(WARNING) << "Notification authorization status denied"; - is_authorized = false; - break; - } - - case UNAuthorizationStatusNotDetermined: { - LOG(INFO) << "Notification authorization status not determined"; - is_authorized = true; - break; - } - - case UNAuthorizationStatusAuthorized: { - LOG(INFO) << "Notification authorization status authorized"; - is_authorized = true; - break; - } - - case UNAuthorizationStatusProvisional: { - LOG(INFO) << "Notification authorization status provisional"; - is_authorized = true; - break; - } - } - - dispatch_semaphore_signal(semaphore); - }]; - - dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - dispatch_release(semaphore); - - if (!is_authorized) { - LOG(WARNING) << "Notifications not authorized"; - } - - return is_authorized; - } - return true; -#endif +// #if !defined(OFFICIAL_BUILD) +// LOG(WARNING) << "Unable to detect the status of native notifications on non" +// " official builds as the app is not code signed"; +// return true; +// #else +// // TODO(https://openradar.appspot.com/27768556): We must mock this function +// // using NotificationHelperMock as a workaround to UNUserNotificationCenter +// // throwing an exception during tests + +// if (@available(macOS 10.14, *)) { +// __block bool is_authorized = false; + +// dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); + +// UNUserNotificationCenter *notificationCenter = +// [UNUserNotificationCenter currentNotificationCenter]; + +// [notificationCenter getNotificationSettingsWithCompletionHandler: +// ^(UNNotificationSettings * _Nonnull settings) { +// switch (settings.authorizationStatus) { +// case UNAuthorizationStatusDenied: { +// LOG(WARNING) << "Notification authorization status denied"; +// is_authorized = false; +// break; +// } + +// case UNAuthorizationStatusNotDetermined: { +// LOG(INFO) << "Notification authorization status not determined"; +// is_authorized = true; +// break; +// } + +// case UNAuthorizationStatusAuthorized: { +// LOG(INFO) << "Notification authorization status authorized"; +// is_authorized = true; +// break; +// } + +// case UNAuthorizationStatusProvisional: { +// LOG(INFO) << "Notification authorization status provisional"; +// is_authorized = true; +// break; +// } +// } + +// dispatch_semaphore_signal(semaphore); +// }]; + +// dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); +// dispatch_release(semaphore); + +// if (!is_authorized) { +// LOG(WARNING) << "Notifications not authorized"; +// } + +// return is_authorized; +// } + +// return true; +// #endif } } // namespace brave_ads