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