Lijin Shen | 9cb57a22 | 2021-11-16 02:17:37 | [diff] [blame^] | 1 | // 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" |
| 11 | #include "components/content_settings/core/common/content_settings_types.h" |
| 12 | #include "components/messages/android/message_enums.h" |
| 13 | #include "components/messages/android/message_wrapper.h" |
| 14 | #include "content/public/browser/web_contents_user_data.h" |
| 15 | |
| 16 | namespace content { |
| 17 | class WebContents; |
| 18 | } |
| 19 | |
| 20 | namespace permissions { |
| 21 | class PermissionPromptAndroid; |
| 22 | } |
| 23 | |
| 24 | // A message ui that displays a notification permission request, which is an |
| 25 | // alternative ui to the mini infobar. |
| 26 | class NotificationBlockedMessageDelegate |
| 27 | : public content::WebContentsUserData<NotificationBlockedMessageDelegate> { |
| 28 | public: |
| 29 | // Delegate to mock out the |PermissionPromptAndroid| for testing. |
| 30 | class Delegate { |
| 31 | public: |
| 32 | Delegate(); |
| 33 | Delegate(const base::WeakPtr<permissions::PermissionPromptAndroid>& |
| 34 | permission_prompt); |
| 35 | virtual ~Delegate(); |
| 36 | virtual void Accept(); |
| 37 | virtual void Deny(); |
| 38 | virtual void Closing(); |
| 39 | virtual bool IsPromptDestroyed(); |
| 40 | virtual bool ShouldUseQuietUI(); |
| 41 | |
| 42 | private: |
| 43 | base::WeakPtr<permissions::PermissionPromptAndroid> permission_prompt_; |
| 44 | }; |
| 45 | |
| 46 | ~NotificationBlockedMessageDelegate() override; |
| 47 | |
| 48 | // Returns pointer to the message wrapper if a new message UIs has been |
| 49 | // created and will be shown. Returns nullptr if not created. |
| 50 | messages::MessageWrapper* ShowMessage(std::unique_ptr<Delegate> delegate); |
| 51 | |
| 52 | private: |
| 53 | friend class content::WebContentsUserData<NotificationBlockedMessageDelegate>; |
| 54 | friend class NotificationBlockedMessageDelegateAndroidTest; |
| 55 | |
| 56 | explicit NotificationBlockedMessageDelegate( |
| 57 | content::WebContents* web_contents); |
| 58 | |
| 59 | void HandlePrimaryActionClick(); |
| 60 | void HandleDismissCallback(messages::DismissReason reason); |
| 61 | void HandleManageClick(); |
| 62 | |
| 63 | void DismissInternal(); |
| 64 | |
| 65 | std::unique_ptr<messages::MessageWrapper> message_; |
| 66 | std::unique_ptr<Delegate> delegate_; |
| 67 | content::WebContents* web_contents_ = nullptr; |
| 68 | |
| 69 | WEB_CONTENTS_USER_DATA_KEY_DECL(); |
| 70 | }; |
| 71 | |
| 72 | #endif // CHROME_BROWSER_PERMISSIONS_NOTIFICATION_BLOCKED_MESSAGE_DELEGATE_ANDROID_H_ |