OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_DELEGATE_H_ |
6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_DELEGATE_H_ | 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_DELEGATE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "chrome/browser/permissions/permission_util.h" | 13 #include "chrome/browser/permissions/permission_util.h" |
14 #include "components/content_settings/core/common/content_settings_types.h" | 14 #include "components/content_settings/core/common/content_settings_types.h" |
15 #include "components/infobars/core/confirm_infobar_delegate.h" | 15 #include "components/infobars/core/confirm_infobar_delegate.h" |
16 #include "content/public/browser/permission_type.h" | |
17 #include "url/gurl.h" | 16 #include "url/gurl.h" |
18 | 17 |
19 namespace infobars { | 18 namespace infobars { |
20 class InfoBar; | 19 class InfoBar; |
21 } | 20 } |
22 | 21 |
23 class InfoBarService; | 22 class InfoBarService; |
24 class Profile; | 23 class Profile; |
25 | 24 |
26 // Base delegate class for permission prompts on Android. The default behavior | 25 // Base delegate class for permission prompts on Android. The default behavior |
27 // is that the accept/deny buttons grant/deny the relevant permission | 26 // is that the accept/deny buttons grant/deny the relevant permission |
28 // respectively. A basic implementor only needs to implement the methods that | 27 // respectively. A basic implementor only needs to implement the methods that |
29 // provide an icon and a message text to the infobar. | 28 // provide an icon and a message text to the infobar. |
30 // | 29 // |
31 // By default, the user is presented with an infobar to make their choice. If | 30 // By default, the user is presented with an infobar to make their choice. If |
32 // the experimental ModalPermissionPrompts feature is active, they will instead | 31 // the experimental ModalPermissionPrompts feature is active, they will instead |
33 // see a modal dialog. Currently, this class is used for both; future | 32 // see a modal dialog. Currently, this class is used for both; future |
34 // refactoring will be undertaken based on whether support for infobars is | 33 // refactoring will be undertaken based on whether support for infobars is |
35 // retained following the modal prompt experiment. | 34 // retained following the modal prompt experiment. |
36 class PermissionInfoBarDelegate : public ConfirmInfoBarDelegate { | 35 class PermissionInfoBarDelegate : public ConfirmInfoBarDelegate { |
37 public: | 36 public: |
38 using PermissionSetCallback = base::Callback<void(bool, PermissionAction)>; | 37 using PermissionSetCallback = base::Callback<void(bool, PermissionAction)>; |
39 | 38 |
40 // Creates an infobar for |type|. The returned pointer is owned by | 39 // Creates an infobar for |type|. The returned pointer is owned by |
41 // |infobar_service| and manages its own lifetime; callers must only use it | 40 // |infobar_service| and manages its own lifetime; callers must only use it |
42 // for calls to |infobar_service|. | 41 // for calls to |infobar_service|. |
43 static infobars::InfoBar* Create(InfoBarService* infobar_service, | 42 static infobars::InfoBar* Create(InfoBarService* infobar_service, |
44 content::PermissionType type, | 43 ContentSettingsType type, |
45 const GURL& requesting_frame, | 44 const GURL& requesting_frame, |
46 bool user_gesture, | 45 bool user_gesture, |
47 Profile* profile, | 46 Profile* profile, |
48 const PermissionSetCallback& callback); | 47 const PermissionSetCallback& callback); |
49 | 48 |
50 static std::unique_ptr<PermissionInfoBarDelegate> CreateDelegate( | 49 static std::unique_ptr<PermissionInfoBarDelegate> CreateDelegate( |
51 content::PermissionType type, | 50 ContentSettingsType type, |
52 const GURL& requesting_frame, | 51 const GURL& requesting_frame, |
53 bool user_gesture, | 52 bool user_gesture, |
54 Profile* profile, | 53 Profile* profile, |
55 const PermissionSetCallback& callback); | 54 const PermissionSetCallback& callback); |
56 | 55 |
57 ~PermissionInfoBarDelegate() override; | 56 ~PermissionInfoBarDelegate() override; |
58 virtual std::vector<int> content_settings_types() const; | 57 virtual std::vector<int> content_settings_types() const; |
59 | 58 |
60 // Returns true if the infobar should display a toggle to allow users to | 59 // Returns true if the infobar should display a toggle to allow users to |
61 // opt-out of persisting their accept/deny decision. | 60 // opt-out of persisting their accept/deny decision. |
62 bool ShouldShowPersistenceToggle() const; | 61 bool ShouldShowPersistenceToggle() const; |
63 | 62 |
64 // Sets whether or not a decided permission should be persisted to content | 63 // Sets whether or not a decided permission should be persisted to content |
65 // settings. | 64 // settings. |
66 void set_persist(bool persist) { persist_ = persist; } | 65 void set_persist(bool persist) { persist_ = persist; } |
67 bool persist() const { return persist_; } | 66 bool persist() const { return persist_; } |
68 | 67 |
69 bool user_gesture() const { return user_gesture_; } | 68 bool user_gesture() const { return user_gesture_; } |
70 | 69 |
71 // ConfirmInfoBarDelegate: | 70 // ConfirmInfoBarDelegate: |
72 bool Accept() override; | 71 bool Accept() override; |
73 bool Cancel() override; | 72 bool Cancel() override; |
74 void InfoBarDismissed() override; | 73 void InfoBarDismissed() override; |
75 base::string16 GetButtonLabel(InfoBarButton button) const override; | 74 base::string16 GetButtonLabel(InfoBarButton button) const override; |
76 base::string16 GetMessageText() const override; | 75 base::string16 GetMessageText() const override; |
77 | 76 |
78 protected: | 77 protected: |
79 PermissionInfoBarDelegate(const GURL& requesting_origin, | 78 PermissionInfoBarDelegate(const GURL& requesting_origin, |
80 content::PermissionType permission_type, | |
81 ContentSettingsType content_settings_type, | 79 ContentSettingsType content_settings_type, |
82 bool user_gesture, | 80 bool user_gesture, |
83 Profile* profile, | 81 Profile* profile, |
84 const PermissionSetCallback& callback); | 82 const PermissionSetCallback& callback); |
85 | 83 |
86 private: | 84 private: |
87 // ConfirmInfoBarDelegate: | 85 // ConfirmInfoBarDelegate: |
88 Type GetInfoBarType() const override; | 86 Type GetInfoBarType() const override; |
89 PermissionInfoBarDelegate* AsPermissionInfoBarDelegate() override; | 87 PermissionInfoBarDelegate* AsPermissionInfoBarDelegate() override; |
90 | 88 |
91 virtual int GetMessageResourceId() const = 0; | 89 virtual int GetMessageResourceId() const = 0; |
92 void SetPermission(bool update_content_setting, PermissionAction decision); | 90 void SetPermission(bool update_content_setting, PermissionAction decision); |
93 | 91 |
94 GURL requesting_origin_; | 92 GURL requesting_origin_; |
95 content::PermissionType permission_type_; | |
96 ContentSettingsType content_settings_type_; | 93 ContentSettingsType content_settings_type_; |
97 Profile* const profile_; | 94 Profile* const profile_; |
98 const PermissionSetCallback callback_; | 95 const PermissionSetCallback callback_; |
99 bool action_taken_; | 96 bool action_taken_; |
100 bool user_gesture_; | 97 bool user_gesture_; |
101 bool persist_; | 98 bool persist_; |
102 | 99 |
103 DISALLOW_COPY_AND_ASSIGN(PermissionInfoBarDelegate); | 100 DISALLOW_COPY_AND_ASSIGN(PermissionInfoBarDelegate); |
104 }; | 101 }; |
105 | 102 |
106 // Implemented in platform-specific code. | 103 // Implemented in platform-specific code. |
107 std::unique_ptr<infobars::InfoBar> CreatePermissionInfoBar( | 104 std::unique_ptr<infobars::InfoBar> CreatePermissionInfoBar( |
108 std::unique_ptr<PermissionInfoBarDelegate> delegate); | 105 std::unique_ptr<PermissionInfoBarDelegate> delegate); |
109 | 106 |
110 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_DELEGATE_H_ | 107 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_DELEGATE_H_ |
OLD | NEW |