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 "content/public/browser/permission_type.h" |
16 | 16 |
17 class NavigationDetails; | |
18 class Profile; | 17 class Profile; |
19 | 18 |
20 // Base class for permission infobars, it implements the default behavior | 19 // Base class for permission infobars, it implements the default behavior |
21 // so that the accept/deny buttons grant/deny the relevant permission. | 20 // so that the accept/deny buttons grant/deny the relevant permission. |
22 // A basic implementor only needs to implement the methods that | 21 // A basic implementor only needs to implement the methods that |
23 // provide an icon and a message text to the infobar. | 22 // provide an icon and a message text to the infobar. |
24 class PermissionInfobarDelegate : public ConfirmInfoBarDelegate { | 23 class PermissionInfoBarDelegate : public ConfirmInfoBarDelegate { |
25 | 24 |
26 public: | 25 public: |
27 using PermissionSetCallback = base::Callback<void(bool, PermissionAction)>; | 26 using PermissionSetCallback = base::Callback<void(bool, PermissionAction)>; |
28 | 27 |
29 ~PermissionInfobarDelegate() override; | 28 ~PermissionInfoBarDelegate() override; |
30 ContentSettingsType content_setting() const { return content_settings_type_; } | 29 ContentSettingsType content_setting() const { return content_settings_type_; } |
31 | 30 |
32 // Returns true if the infobar should display a toggle to allow users to | 31 // Returns true if the infobar should display a toggle to allow users to |
33 // opt-out of persisting their accept/deny decision. | 32 // opt-out of persisting their accept/deny decision. |
34 bool ShouldShowPersistenceToggle() const; | 33 bool ShouldShowPersistenceToggle() const; |
35 | 34 |
36 // Sets whether or not a decided permission should be persisted to content | 35 // Sets whether or not a decided permission should be persisted to content |
37 // settings. | 36 // settings. |
38 void set_persist(bool persist) { persist_ = persist; } | 37 void set_persist(bool persist) { persist_ = persist; } |
39 | 38 |
40 // ConfirmInfoBarDelegate: | 39 // ConfirmInfoBarDelegate: |
41 base::string16 GetMessageText() const override; | 40 base::string16 GetMessageText() const override; |
42 | 41 |
43 protected: | 42 protected: |
44 PermissionInfobarDelegate(const GURL& requesting_origin, | 43 PermissionInfoBarDelegate(const GURL& requesting_origin, |
45 content::PermissionType permission_type, | 44 content::PermissionType permission_type, |
46 ContentSettingsType content_settings_type, | 45 ContentSettingsType content_settings_type, |
47 bool user_gesture, | 46 bool user_gesture, |
48 Profile* profile, | 47 Profile* profile, |
49 const PermissionSetCallback& callback); | 48 const PermissionSetCallback& callback); |
50 | 49 |
51 virtual int GetMessageResourceId() const = 0; | |
52 | |
53 private: | 50 private: |
54 // ConfirmInfoBarDelegate: | 51 // ConfirmInfoBarDelegate: |
55 Type GetInfoBarType() const override; | 52 Type GetInfoBarType() const override; |
56 void InfoBarDismissed() override; | 53 void InfoBarDismissed() override; |
57 PermissionInfobarDelegate* AsPermissionInfobarDelegate() override; | 54 PermissionInfoBarDelegate* AsPermissionInfoBarDelegate() override; |
58 base::string16 GetButtonLabel(InfoBarButton button) const override; | 55 base::string16 GetButtonLabel(InfoBarButton button) const override; |
56 virtual int GetMessageResourceId() const = 0; | |
Peter Kasting
2016/08/17 23:02:22
Nit: Don't place this in the middle of the Confirm
dominickn
2016/08/17 23:29:41
Done.
| |
59 bool Accept() override; | 57 bool Accept() override; |
60 bool Cancel() override; | 58 bool Cancel() override; |
61 | 59 |
62 void SetPermission(bool update_content_setting, PermissionAction decision); | 60 void SetPermission(bool update_content_setting, PermissionAction decision); |
63 | 61 |
64 GURL requesting_origin_; | 62 GURL requesting_origin_; |
65 content::PermissionType permission_type_; | 63 content::PermissionType permission_type_; |
66 ContentSettingsType content_settings_type_; | 64 ContentSettingsType content_settings_type_; |
67 Profile* const profile_; | 65 Profile* const profile_; |
68 const PermissionSetCallback callback_; | 66 const PermissionSetCallback callback_; |
69 bool action_taken_; | 67 bool action_taken_; |
70 bool user_gesture_; | 68 bool user_gesture_; |
71 bool persist_; | 69 bool persist_; |
72 | 70 |
73 DISALLOW_COPY_AND_ASSIGN(PermissionInfobarDelegate); | 71 DISALLOW_COPY_AND_ASSIGN(PermissionInfoBarDelegate); |
74 }; | 72 }; |
75 | 73 |
76 // Implemented in platform-specific code. | 74 // Implemented in platform-specific code. |
77 std::unique_ptr<infobars::InfoBar> CreatePermissionInfoBar( | 75 std::unique_ptr<infobars::InfoBar> CreatePermissionInfoBar( |
78 std::unique_ptr<PermissionInfobarDelegate> delegate); | 76 std::unique_ptr<PermissionInfoBarDelegate> delegate); |
79 | 77 |
80 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_DELEGATE_H_ | 78 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_DELEGATE_H_ |
OLD | NEW |