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_util.h" |
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 set_persist(bool persist) { persist_ = persist; } |
| 39 |
| 40 // ConfirmInfoBarDelegate: |
| 41 base::string16 GetMessageText() const override; |
| 42 |
28 protected: | 43 protected: |
29 PermissionInfobarDelegate(const GURL& requesting_origin, | 44 PermissionInfobarDelegate(const GURL& requesting_origin, |
30 content::PermissionType permission_type, | 45 content::PermissionType permission_type, |
31 ContentSettingsType content_settings_type, | 46 ContentSettingsType content_settings_type, |
32 bool user_gesture, | 47 bool user_gesture, |
33 Profile* profile, | 48 Profile* profile, |
34 const PermissionSetCallback& callback); | 49 const PermissionSetCallback& callback); |
35 ~PermissionInfobarDelegate() override; | |
36 | 50 |
37 virtual int GetMessageResourceId() const = 0; | 51 virtual int GetMessageResourceId() const = 0; |
38 | 52 |
39 private: | 53 private: |
40 // ConfirmInfoBarDelegate: | 54 // ConfirmInfoBarDelegate: |
41 Type GetInfoBarType() const override; | 55 Type GetInfoBarType() const override; |
42 void InfoBarDismissed() override; | 56 void InfoBarDismissed() override; |
43 PermissionInfobarDelegate* AsPermissionInfobarDelegate() override; | 57 PermissionInfobarDelegate* AsPermissionInfobarDelegate() override; |
44 base::string16 GetButtonLabel(InfoBarButton button) const override; | 58 base::string16 GetButtonLabel(InfoBarButton button) const override; |
45 base::string16 GetMessageText() const override; | |
46 bool Accept() override; | 59 bool Accept() override; |
47 bool Cancel() override; | 60 bool Cancel() override; |
48 | 61 |
49 void SetPermission(bool update_content_setting, bool allowed); | 62 void SetPermission(bool update_content_setting, PermissionAction decision); |
50 | 63 |
51 GURL requesting_origin_; | 64 GURL requesting_origin_; |
52 bool action_taken_; | |
53 content::PermissionType permission_type_; | 65 content::PermissionType permission_type_; |
54 ContentSettingsType content_settings_type_; | 66 ContentSettingsType content_settings_type_; |
55 bool user_gesture_; | |
56 Profile* const profile_; | 67 Profile* const profile_; |
57 const PermissionSetCallback callback_; | 68 const PermissionSetCallback callback_; |
| 69 bool action_taken_; |
| 70 bool user_gesture_; |
| 71 bool persist_; |
58 | 72 |
59 DISALLOW_COPY_AND_ASSIGN(PermissionInfobarDelegate); | 73 DISALLOW_COPY_AND_ASSIGN(PermissionInfobarDelegate); |
60 }; | 74 }; |
61 | 75 |
| 76 // Implemented in platform-specific code. |
| 77 std::unique_ptr<infobars::InfoBar> CreatePermissionInfoBar( |
| 78 std::unique_ptr<PermissionInfobarDelegate> delegate); |
| 79 |
62 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_DELEGATE_H_ | 80 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_DELEGATE_H_ |
OLD | NEW |