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 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "chrome/browser/permissions/permission_util.h" | 12 #include "chrome/browser/permissions/permission_util.h" |
13 #include "components/content_settings/core/common/content_settings_types.h" | 13 #include "components/content_settings/core/common/content_settings_types.h" |
14 #include "components/infobars/core/confirm_infobar_delegate.h" | 14 #include "components/infobars/core/confirm_infobar_delegate.h" |
15 #include "content/public/browser/permission_type.h" | 15 #include "url/gurl.h" |
16 | 16 |
17 class NavigationDetails; | 17 // Base class for permission infobars. |
raymes
2016/08/17 03:20:43
nit: fill 80chars or new paragraph
dominickn
2016/08/17 03:29:38
Done.
| |
18 class Profile; | 18 // Implementors should inherit from SinglePermissionInfoBarDelegate or |
19 | 19 // GroupedPermissionInfobarDelegate. |
20 // Base class for permission infobars, it implements the default behavior | 20 class PermissionInfoBarDelegate : public ConfirmInfoBarDelegate { |
21 // so that the accept/deny buttons grant/deny the relevant permission. | |
22 // A basic implementor only needs to implement the methods that | |
23 // provide an icon and a message text to the infobar. | |
24 class PermissionInfobarDelegate : public ConfirmInfoBarDelegate { | |
25 | |
26 public: | 21 public: |
27 using PermissionSetCallback = base::Callback<void(bool, PermissionAction)>; | 22 using PermissionSetCallback = base::Callback<void(bool, PermissionAction)>; |
28 | 23 ~PermissionInfoBarDelegate() override; |
29 ~PermissionInfobarDelegate() override; | 24 virtual ContentSettingsType GetContentSettingType(int index) const = 0; |
raymes
2016/08/17 03:20:43
It seems like we only ever need the first content
dominickn
2016/08/17 03:29:38
The GroupedPermissionInfobarDelegate uses the inde
raymes
2016/08/17 03:44:41
Hmm it's unclear whether the one callsite which cu
| |
30 ContentSettingsType content_setting() const { return content_settings_type_; } | |
31 | 25 |
32 // Returns true if the infobar should display a toggle to allow users to | 26 // Returns true if the infobar should display a toggle to allow users to |
33 // opt-out of persisting their accept/deny decision. | 27 // opt-out of persisting their accept/deny decision. |
34 bool ShouldShowPersistenceToggle() const; | 28 virtual bool ShouldShowPersistenceToggle() const; |
35 | 29 |
36 // Sets whether or not a decided permission should be persisted to content | 30 // Sets whether or not a decided permission should be persisted to content |
37 // settings. | 31 // settings. |
38 void set_persist(bool persist) { persist_ = persist; } | 32 void set_persist(bool persist) { persist_ = persist; } |
39 | 33 |
40 // ConfirmInfoBarDelegate: | 34 protected: |
41 base::string16 GetMessageText() const override; | 35 explicit PermissionInfoBarDelegate(const GURL& requesting_origin); |
42 | 36 |
43 protected: | 37 const GURL& requesting_origin() const { return requesting_origin_; } |
44 PermissionInfobarDelegate(const GURL& requesting_origin, | 38 bool persist() const { return persist_; } |
45 content::PermissionType permission_type, | |
46 ContentSettingsType content_settings_type, | |
47 bool user_gesture, | |
48 Profile* profile, | |
49 const PermissionSetCallback& callback); | |
50 | |
51 virtual int GetMessageResourceId() const = 0; | |
52 | 39 |
53 private: | 40 private: |
54 // ConfirmInfoBarDelegate: | 41 // ConfirmInfoBarDelegate: |
55 Type GetInfoBarType() const override; | 42 Type GetInfoBarType() const override; |
56 void InfoBarDismissed() override; | 43 PermissionInfoBarDelegate* AsPermissionInfoBarDelegate() override; |
57 PermissionInfobarDelegate* AsPermissionInfobarDelegate() override; | |
58 base::string16 GetButtonLabel(InfoBarButton button) const override; | |
59 bool Accept() override; | |
60 bool Cancel() override; | |
61 | |
62 void SetPermission(bool update_content_setting, PermissionAction decision); | |
63 | 44 |
64 GURL requesting_origin_; | 45 GURL requesting_origin_; |
65 content::PermissionType permission_type_; | |
66 ContentSettingsType content_settings_type_; | |
67 Profile* const profile_; | |
68 const PermissionSetCallback callback_; | |
69 bool action_taken_; | |
70 bool user_gesture_; | |
71 bool persist_; | 46 bool persist_; |
72 | 47 |
73 DISALLOW_COPY_AND_ASSIGN(PermissionInfobarDelegate); | 48 DISALLOW_COPY_AND_ASSIGN(PermissionInfoBarDelegate); |
74 }; | 49 }; |
75 | 50 |
76 // Implemented in platform-specific code. | 51 // Implemented in platform-specific code. |
77 std::unique_ptr<infobars::InfoBar> CreatePermissionInfoBar( | 52 std::unique_ptr<infobars::InfoBar> CreatePermissionInfoBar( |
78 std::unique_ptr<PermissionInfobarDelegate> delegate); | 53 std::unique_ptr<PermissionInfoBarDelegate> delegate); |
79 | 54 |
80 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_DELEGATE_H_ | 55 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_DELEGATE_H_ |
OLD | NEW |