blob: 9ad7880a506985a00bf7c6ccc2001f4e4489b443 [file] [log] [blame]
Lijin Shen9cb57a222021-11-16 02:17:371// Copyright 2021 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_PERMISSIONS_NOTIFICATION_BLOCKED_MESSAGE_DELEGATE_ANDROID_H_
6#define CHROME_BROWSER_PERMISSIONS_NOTIFICATION_BLOCKED_MESSAGE_DELEGATE_ANDROID_H_
7
8#include <memory>
9
10#include "base/callback.h"
Keishi Hattori0e45c022021-11-27 09:25:5211#include "base/memory/raw_ptr.h"
Lijin Shen20a1b6e2022-01-15 00:52:5012#include "chrome/browser/permissions/notification_blocked_dialog_controller_android.h"
Lijin Shen9cb57a222021-11-16 02:17:3713#include "components/content_settings/core/common/content_settings_types.h"
14#include "components/messages/android/message_enums.h"
15#include "components/messages/android/message_wrapper.h"
Lijin Shen7628090a2021-11-16 16:34:1316#include "components/permissions/permissions_client.h"
Lijin Shenb05ef8942022-01-26 22:37:1717#include "content/public/browser/web_contents_observer.h"
Lijin Shen9cb57a222021-11-16 02:17:3718
19namespace content {
20class WebContents;
21}
22
23namespace permissions {
24class PermissionPromptAndroid;
25}
26
27// A message ui that displays a notification permission request, which is an
28// alternative ui to the mini infobar.
29class NotificationBlockedMessageDelegate
Lijin Shen20a1b6e2022-01-15 00:52:5030 : public NotificationBlockedDialogController::Delegate,
Lijin Shenb05ef8942022-01-26 22:37:1731 public permissions::PermissionsClient::PermissionMessageDelegate,
32 public content::WebContentsObserver {
Lijin Shen9cb57a222021-11-16 02:17:3733 public:
34 // Delegate to mock out the |PermissionPromptAndroid| for testing.
35 class Delegate {
36 public:
37 Delegate();
38 Delegate(const base::WeakPtr<permissions::PermissionPromptAndroid>&
39 permission_prompt);
40 virtual ~Delegate();
41 virtual void Accept();
42 virtual void Deny();
43 virtual void Closing();
Lijin Shen9cb57a222021-11-16 02:17:3744 virtual bool ShouldUseQuietUI();
Lijin Shen20a1b6e2022-01-15 00:52:5045 virtual absl::optional<permissions::PermissionUiSelector::QuietUiReason>
46 ReasonForUsingQuietUi();
Lijin Shen9cb57a222021-11-16 02:17:3747
48 private:
49 base::WeakPtr<permissions::PermissionPromptAndroid> permission_prompt_;
50 };
51
Lijin Shen7628090a2021-11-16 16:34:1352 NotificationBlockedMessageDelegate(content::WebContents* web_contents,
53 std::unique_ptr<Delegate> delegate);
Lijin Shen9cb57a222021-11-16 02:17:3754 ~NotificationBlockedMessageDelegate() override;
55
Lijin Shen20a1b6e2022-01-15 00:52:5056 protected:
57 // NotificationBlockedDialogController::Delegate:
58 void OnContinueBlocking() override;
59 void OnAllowForThisSite() override;
60 void OnLearnMoreClicked() override;
Lijin Shenb05ef8942022-01-26 22:37:1761 void OnOpenedSettings() override;
Lijin Shen20a1b6e2022-01-15 00:52:5062 void OnDialogDismissed() override;
63
Lijin Shenb05ef8942022-01-26 22:37:1764 // content::WebContentsObserver implementation.
65 void OnWebContentsFocused(
66 content::RenderWidgetHost* render_widget_host) override;
67
Lijin Shen9cb57a222021-11-16 02:17:3768 private:
Lijin Shen9cb57a222021-11-16 02:17:3769 friend class NotificationBlockedMessageDelegateAndroidTest;
70
Lijin Shen9cb57a222021-11-16 02:17:3771 void HandlePrimaryActionClick();
72 void HandleDismissCallback(messages::DismissReason reason);
73 void HandleManageClick();
74
75 void DismissInternal();
76
Lijin Shenb05ef8942022-01-26 22:37:1777 // `message_` and `dialog_controller_` can not be alive at the same moment,
78 // since message ui and dialog ui won't show together.
Lijin Shen9cb57a222021-11-16 02:17:3779 std::unique_ptr<messages::MessageWrapper> message_;
Lijin Shen20a1b6e2022-01-15 00:52:5080 std::unique_ptr<NotificationBlockedDialogController> dialog_controller_;
Keishi Hattori0e45c022021-11-27 09:25:5281 raw_ptr<content::WebContents> web_contents_ = nullptr;
Lijin Shen7628090a2021-11-16 16:34:1382 std::unique_ptr<Delegate> delegate_;
Lijin Shenb05ef8942022-01-26 22:37:1783
84 // Whether we should re-show the dialog to users when users return to the tab.
85 bool should_reshow_dialog_on_focus_ = false;
Lijin Shen9cb57a222021-11-16 02:17:3786};
87
88#endif // CHROME_BROWSER_PERMISSIONS_NOTIFICATION_BLOCKED_MESSAGE_DELEGATE_ANDROID_H_