0

[ios] Toggle on feature notification setting upon notification open

This change turns on the feature notification setting in response to its
notification being opened.

Bug: 370956441
Change-Id: I297cc6de48d0456df25561bbb70565303aac0dee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5996612
Reviewed-by: Sergio Collazos <sczs@chromium.org>
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Reviewed-by: Scott Yoder <scottyoder@google.com>
Cr-Commit-Position: refs/heads/main@{#1380495}
This commit is contained in:
Chris Lu
2024-11-08 18:33:34 +00:00
committed by Chromium LUCI CQ
parent b746d0b84e
commit 2e03996998
10 changed files with 97 additions and 7 deletions

@ -18,6 +18,8 @@ source_set("notification_client") {
"//components/prefs",
"//ios/chrome/browser/push_notification/model:constants",
"//ios/chrome/browser/push_notification/model:push_notification_client_id",
"//ios/chrome/browser/push_notification/model:push_notification_service_header",
"//ios/chrome/browser/push_notification/model:push_notification_settings_util_header",
"//ios/chrome/browser/push_notification/model:push_notification_util",
"//ios/chrome/browser/safety_check/model",
"//ios/chrome/browser/safety_check/model:factory",
@ -29,6 +31,8 @@ source_set("notification_client") {
"//ios/chrome/browser/shared/model/profile",
"//ios/chrome/browser/shared/public/commands",
"//ios/chrome/browser/shared/public/features",
"//ios/chrome/browser/signin/model:authentication_service",
"//ios/chrome/browser/signin/model:authentication_service_factory",
"//ios/chrome/browser/ui/content_suggestions/safety_check",
]
frameworks = [

@ -4,4 +4,5 @@ include_rules = [
"+ios/chrome/browser/push_notification/model",
"+ios/chrome/browser/safety_check/model",
"+ios/chrome/browser/upgrade/model",
"+ios/chrome/browser/signin/model",
]

@ -9,10 +9,14 @@
#import "base/functional/callback_helpers.h"
#import "base/location.h"
#import "base/metrics/histogram_functions.h"
#import "base/strings/sys_string_conversions.h"
#import "base/task/bind_post_task.h"
#import "components/prefs/pref_service.h"
#import "ios/chrome/browser/push_notification/model/constants.h"
#import "ios/chrome/browser/push_notification/model/push_notification_client.h"
#import "ios/chrome/browser/push_notification/model/push_notification_client_id.h"
#import "ios/chrome/browser/push_notification/model/push_notification_service.h"
#import "ios/chrome/browser/push_notification/model/push_notification_settings_util.h"
#import "ios/chrome/browser/push_notification/model/push_notification_util.h"
#import "ios/chrome/browser/safety_check/model/ios_chrome_safety_check_manager.h"
#import "ios/chrome/browser/safety_check/model/ios_chrome_safety_check_manager_factory.h"
@ -26,6 +30,8 @@
#import "ios/chrome/browser/shared/public/commands/command_dispatcher.h"
#import "ios/chrome/browser/shared/public/commands/settings_commands.h"
#import "ios/chrome/browser/shared/public/features/features.h"
#import "ios/chrome/browser/signin/model/authentication_service.h"
#import "ios/chrome/browser/signin/model/authentication_service_factory.h"
#import "ios/chrome/browser/ui/content_suggestions/safety_check/utils.h"
namespace {
@ -470,6 +476,23 @@ void SafetyCheckNotificationClient::ShowUIForNotificationMetadata(
NOTREACHED();
}
if (IsProvisionalNotificationAlertEnabled()) {
AuthenticationService* authService =
AuthenticationServiceFactory::GetForProfile(
GetSceneLevelForegroundActiveBrowser()->GetProfile());
id<SystemIdentity> identity =
authService->GetPrimaryIdentity(signin::ConsentLevel::kSignin);
const std::string& gaiaID = base::SysNSStringToUTF8(identity.gaiaID);
if (!push_notification_settings::
GetMobileNotificationPermissionStatusForClient(
PushNotificationClientId::kSafetyCheck, gaiaID)) {
PushNotificationService* service =
GetApplicationContext()->GetPushNotificationService();
service->SetPreference(base::SysUTF8ToNSString(gaiaID),
PushNotificationClientId::kSafetyCheck, true);
}
}
id<ApplicationCommands> applicationHandler =
HandlerForProtocol(browser->GetCommandDispatcher(), ApplicationCommands);

@ -26,13 +26,18 @@ source_set("model") {
"//ios/chrome/browser/push_notification/model:constants",
"//ios/chrome/browser/push_notification/model:push_notification_client",
"//ios/chrome/browser/push_notification/model:push_notification_client_id",
"//ios/chrome/browser/push_notification/model:push_notification_service_header",
"//ios/chrome/browser/push_notification/model:push_notification_settings_util_header",
"//ios/chrome/browser/push_notification/model:push_notification_util",
"//ios/chrome/browser/shared/model/application_context",
"//ios/chrome/browser/shared/model/browser",
"//ios/chrome/browser/shared/model/prefs:pref_names",
"//ios/chrome/browser/shared/model/web_state_list",
"//ios/chrome/browser/shared/public/commands",
"//ios/chrome/browser/shared/public/features",
"//ios/chrome/browser/shared/ui/util",
"//ios/chrome/browser/signin/model:authentication_service",
"//ios/chrome/browser/signin/model:authentication_service_factory",
"//ios/chrome/browser/sync/model",
"//ios/chrome/browser/tabs/model",
"//ios/components/webui:url_constants",

@ -2,4 +2,5 @@ include_rules = [
"+ios/chrome/browser/infobars/model",
"+ios/chrome/browser/push_notification/model",
"+ios/chrome/browser/sync/model",
"+ios/chrome/browser/signin/model",
]

@ -8,8 +8,11 @@
#import <Foundation/Foundation.h>
#import <UserNotifications/UserNotifications.h>
#import "base/memory/raw_ptr.h"
#import "ios/chrome/browser/push_notification/model/push_notification_client.h"
class Browser;
// Client for handling send tab notifications.
class SendTabPushNotificationClient : public PushNotificationClient {
public:
@ -21,6 +24,13 @@ class SendTabPushNotificationClient : public PushNotificationClient {
std::optional<UIBackgroundFetchResult> HandleNotificationReception(
NSDictionary<NSString*, id>* notification) override;
NSArray<UNNotificationCategory*>* RegisterActionableNotifications() override;
private:
// Handles the completion of URL loads.
void OnURLLoadedInNewTab(std::string guid, Browser* browser);
// Weak pointer factory.
base::WeakPtrFactory<SendTabPushNotificationClient> weak_ptr_factory_{this};
};
#endif // IOS_CHROME_BROWSER_SEND_TAB_TO_SELF_MODEL_SEND_TAB_PUSH_NOTIFICATION_CLIENT_H_

@ -12,10 +12,17 @@
#import "components/send_tab_to_self/send_tab_to_self_model.h"
#import "components/send_tab_to_self/send_tab_to_self_sync_service.h"
#import "ios/chrome/browser/push_notification/model/constants.h"
#import "ios/chrome/browser/push_notification/model/push_notification_client.h"
#import "ios/chrome/browser/push_notification/model/push_notification_client_id.h"
#import "ios/chrome/browser/push_notification/model/push_notification_service.h"
#import "ios/chrome/browser/push_notification/model/push_notification_settings_util.h"
#import "ios/chrome/browser/push_notification/model/push_notification_util.h"
#import "ios/chrome/browser/send_tab_to_self/model/send_tab_to_self_browser_agent.h"
#import "ios/chrome/browser/shared/model/application_context/application_context.h"
#import "ios/chrome/browser/shared/model/browser/browser.h"
#import "ios/chrome/browser/shared/public/features/features.h"
#import "ios/chrome/browser/signin/model/authentication_service.h"
#import "ios/chrome/browser/signin/model/authentication_service_factory.h"
#import "ios/chrome/browser/sync/model/send_tab_to_self_sync_service_factory.h"
#import "url/gurl.h"
@ -50,13 +57,10 @@ bool SendTabPushNotificationClient::HandleNotificationInteraction(
// opened.
std::string guid = base::SysNSStringToUTF8(
response.notification.request.content.userInfo[kGuidKey]);
LoadUrlInNewTab(GURL(url), base::BindOnce(^(Browser* browser) {
send_tab_to_self::SendTabToSelfModel* send_tab_model =
SendTabToSelfSyncServiceFactory::GetForProfile(
browser->GetProfile())
->GetSendTabToSelfModel();
send_tab_model->MarkEntryOpened(guid);
}));
LoadUrlInNewTab(
GURL(url),
base::BindOnce(&SendTabPushNotificationClient::OnURLLoadedInNewTab,
weak_ptr_factory_.GetWeakPtr(), std::move(guid)));
base::RecordAction(
base::UserMetricsAction("IOS.Notifications.SendTab.Interaction"));
@ -80,3 +84,27 @@ NSArray<UNNotificationCategory*>*
SendTabPushNotificationClient::RegisterActionableNotifications() {
return @[];
}
void SendTabPushNotificationClient::OnURLLoadedInNewTab(std::string guid,
Browser* browser) {
send_tab_to_self::SendTabToSelfModel* send_tab_model =
SendTabToSelfSyncServiceFactory::GetForProfile(browser->GetProfile())
->GetSendTabToSelfModel();
send_tab_model->MarkEntryOpened(guid);
if (IsProvisionalNotificationAlertEnabled()) {
AuthenticationService* authService =
AuthenticationServiceFactory::GetForProfile(browser->GetProfile());
id<SystemIdentity> identity =
authService->GetPrimaryIdentity(signin::ConsentLevel::kSignin);
const std::string& gaiaID = base::SysNSStringToUTF8(identity.gaiaID);
if (!push_notification_settings::
GetMobileNotificationPermissionStatusForClient(
PushNotificationClientId::kSendTab, gaiaID)) {
PushNotificationService* service =
GetApplicationContext()->GetPushNotificationService();
service->SetPreference(base::SysUTF8ToNSString(gaiaID),
PushNotificationClientId::kSendTab, true);
}
}
}

@ -19,6 +19,7 @@ source_set("client") {
"//ios/chrome/browser/ntp/model:set_up_list_prefs",
"//ios/chrome/browser/push_notification/model:constants",
"//ios/chrome/browser/push_notification/model:push_notification_client",
"//ios/chrome/browser/push_notification/model:push_notification_service_header",
"//ios/chrome/browser/push_notification/model:push_notification_util",
"//ios/chrome/browser/search_engines/model:template_url_service_factory",
"//ios/chrome/browser/shared/coordinator/scene:scene_state_header",

@ -8,4 +8,5 @@ include_rules = [
"+ios/chrome/browser/ui/authentication",
"+ios/chrome/browser/ui/content_suggestions",
"+ios/chrome/browser/ui/lens",
"+ios/chrome/browser/signin/model",
]

@ -7,6 +7,7 @@
#import "base/metrics/histogram_functions.h"
#import "base/metrics/user_metrics.h"
#import "base/metrics/user_metrics_action.h"
#import "base/strings/sys_string_conversions.h"
#import "base/task/bind_post_task.h"
#import "base/time/time.h"
#import "components/feature_engagement/public/tracker.h"
@ -19,6 +20,8 @@
#import "ios/chrome/browser/feature_engagement/model/tracker_factory.h"
#import "ios/chrome/browser/ntp/model/set_up_list_prefs.h"
#import "ios/chrome/browser/push_notification/model/constants.h"
#import "ios/chrome/browser/push_notification/model/push_notification_client.h"
#import "ios/chrome/browser/push_notification/model/push_notification_service.h"
#import "ios/chrome/browser/push_notification/model/push_notification_util.h"
#import "ios/chrome/browser/search_engines/model/template_url_service_factory.h"
#import "ios/chrome/browser/shared/coordinator/scene/scene_state.h"
@ -175,6 +178,19 @@ void TipsNotificationClient::HandleNotificationInteraction(
base::CallbackToBlock(
base::BindOnce(&TipsNotificationClient::ShowUIForNotificationType,
weak_ptr_factory_.GetWeakPtr(), type, browser))];
if (IsProvisionalNotificationAlertEnabled() && !permitted_) {
AuthenticationService* authService =
AuthenticationServiceFactory::GetForProfile(
GetSceneLevelForegroundActiveBrowser()->GetProfile());
id<SystemIdentity> identity =
authService->GetPrimaryIdentity(signin::ConsentLevel::kSignin);
const std::string& gaiaID = base::SysNSStringToUTF8(identity.gaiaID);
PushNotificationService* service =
GetApplicationContext()->GetPushNotificationService();
service->SetPreference(base::SysUTF8ToNSString(gaiaID),
PushNotificationClientId::kTips, true);
}
}
std::optional<UIBackgroundFetchResult>