Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROID_H _ | 5 #ifndef CHROME_BROWSER_PERMISSIONS_GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROID_H _ |
| 6 #define CHROME_BROWSER_PERMISSIONS_GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROID_H _ | 6 #define CHROME_BROWSER_PERMISSIONS_GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROID_H _ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "components/content_settings/core/common/content_settings_types.h" | 11 #include "components/content_settings/core/common/content_settings_types.h" |
| 12 #include "components/infobars/core/confirm_infobar_delegate.h" | 12 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 13 | 13 |
| 14 class GURL; | 14 class GURL; |
| 15 class InfoBarService; | 15 class InfoBarService; |
| 16 class PermissionPromptAndroid; | |
| 16 class PermissionRequest; | 17 class PermissionRequest; |
| 17 | 18 |
| 18 // An InfoBar that displays a group of permission requests, each of which can be | 19 // An InfoBar that displays a group of permission requests, each of which can be |
| 19 // allowed or blocked independently. | 20 // allowed or blocked independently. |
| 20 // TODO(tsergeant): Expand this class so it can be used without subclassing. | 21 // TODO(tsergeant): Expand this class so it can be used without subclassing. |
| 21 class GroupedPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { | 22 class GroupedPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 22 public: | 23 public: |
| 23 // Public so we can have std::unique_ptr<GroupedPermissionInfoBarDelegate>. | 24 // Public so we can have std::unique_ptr<GroupedPermissionInfoBarDelegate>. |
| 24 ~GroupedPermissionInfoBarDelegate() override; | 25 ~GroupedPermissionInfoBarDelegate() override; |
| 25 | 26 |
| 26 static infobars::InfoBar* Create( | 27 static infobars::InfoBar* Create( |
| 28 PermissionPromptAndroid* permission_prompt, | |
| 27 InfoBarService* infobar_service, | 29 InfoBarService* infobar_service, |
| 28 const GURL& requesting_origin, | 30 const GURL& requesting_origin, |
| 29 const std::vector<PermissionRequest*>& requests); | 31 const std::vector<PermissionRequest*>& requests); |
| 30 | 32 |
| 31 bool persist() const { return persist_; } | 33 bool persist() const { return persist_; } |
| 32 void set_persist(bool persist) { persist_ = persist; } | 34 void set_persist(bool persist) { persist_ = persist; } |
| 33 size_t permission_count() const { return requests_.size(); } | 35 size_t permission_count() const { return requests_.size(); } |
| 34 | 36 |
| 35 // Returns true if the infobar should display a toggle to allow users to | 37 // Returns true if the infobar should display a toggle to allow users to |
| 36 // opt-out of persisting their accept/deny decision. | 38 // opt-out of persisting their accept/deny decision. |
| 37 bool ShouldShowPersistenceToggle() const; | 39 bool ShouldShowPersistenceToggle() const; |
| 38 | 40 |
| 39 ContentSettingsType GetContentSettingType(size_t position) const; | 41 ContentSettingsType GetContentSettingType(size_t position) const; |
| 40 int GetIconIdForPermission(size_t position) const; | 42 int GetIconIdForPermission(size_t position) const; |
| 41 | 43 |
| 42 // Message text to display for an individual permission at |position|. | 44 // Message text to display for an individual permission at |position|. |
| 43 base::string16 GetMessageTextFragment(size_t position) const; | 45 base::string16 GetMessageTextFragment(size_t position) const; |
| 44 | 46 |
| 45 // Toggle accept value for an individual permission at |position|. | 47 // Toggle accept value for an individual permission at |position|. |
| 46 void ToggleAccept(size_t position, bool new_value); | 48 void ToggleAccept(size_t position, bool new_value); |
| 47 | 49 |
| 48 // ConfirmInfoBarDelegate: | 50 // ConfirmInfoBarDelegate: |
| 49 base::string16 GetMessageText() const override; | 51 base::string16 GetMessageText() const override; |
| 52 bool Accept() override; | |
| 53 bool Cancel() override; | |
| 50 | 54 |
| 51 protected: | 55 protected: |
| 52 bool GetAcceptState(size_t position); | 56 bool GetAcceptState(size_t position); |
| 53 | 57 |
| 54 private: | 58 private: |
| 55 GroupedPermissionInfoBarDelegate( | 59 GroupedPermissionInfoBarDelegate( |
| 56 const GURL& requesting_origin, | 60 const GURL& requesting_origin, |
| 57 const std::vector<PermissionRequest*>& requests); | 61 const std::vector<PermissionRequest*>& requests, |
| 62 PermissionPromptAndroid* permission_prompt); | |
| 58 | 63 |
| 59 // ConfirmInfoBarDelegate: | 64 // ConfirmInfoBarDelegate: |
| 60 InfoBarIdentifier GetIdentifier() const override; | 65 InfoBarIdentifier GetIdentifier() const override; |
| 61 Type GetInfoBarType() const override; | 66 Type GetInfoBarType() const override; |
| 62 int GetButtons() const override; | 67 int GetButtons() const override; |
| 63 base::string16 GetButtonLabel(InfoBarButton button) const override; | 68 base::string16 GetButtonLabel(InfoBarButton button) const override; |
| 64 | 69 |
| 65 const GURL requesting_origin_; | 70 const GURL requesting_origin_; |
| 66 const std::vector<PermissionRequest*> requests_; | 71 const std::vector<PermissionRequest*> requests_; |
| 67 std::vector<bool> accept_states_; | 72 std::vector<bool> accept_states_; |
| 68 // Whether the accept/deny decision is persisted. | 73 // Whether the accept/deny decision is persisted. |
| 69 bool persist_; | 74 bool persist_; |
| 75 // PermissionPromptAndroid's lifetime matches that of this object as it | |
| 76 // controls the lifetime of the infobar which we are a delegate to. | |
|
raymes
2016/10/27 01:32:33
Hmm - it's not immediately clear to me that the Pe
lshang
2016/10/28 03:18:48
I think your point makes sense, that's a tricky on
| |
| 77 PermissionPromptAndroid* permission_prompt_; | |
| 70 | 78 |
| 71 DISALLOW_COPY_AND_ASSIGN(GroupedPermissionInfoBarDelegate); | 79 DISALLOW_COPY_AND_ASSIGN(GroupedPermissionInfoBarDelegate); |
| 72 }; | 80 }; |
| 73 | 81 |
| 74 #endif // CHROME_BROWSER_PERMISSIONS_GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROI D_H_ | 82 #endif // CHROME_BROWSER_PERMISSIONS_GROUPED_PERMISSION_INFOBAR_DELEGATE_ANDROI D_H_ |
| OLD | NEW |