| 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 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "chrome/browser/permissions/permission_util.h" | 13 #include "chrome/browser/permissions/permission_util.h" |
| 14 #include "components/content_settings/core/common/content_settings_types.h" | 14 #include "components/content_settings/core/common/content_settings_types.h" |
| 15 #include "components/infobars/core/confirm_infobar_delegate.h" | 15 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 16 #include "content/public/browser/permission_type.h" | 16 #include "content/public/browser/permission_type.h" |
| 17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 18 | 18 |
| 19 namespace infobars { | 19 namespace infobars { |
| 20 class InfoBar; | 20 class InfoBar; |
| 21 } | 21 } |
| 22 | 22 |
| 23 class InfoBarService; | 23 class InfoBarService; |
| 24 class Profile; | 24 class Profile; |
| 25 | 25 |
| 26 // Base class for permission infobars, it implements the default behavior | 26 // Base delegate class for permission prompts on Android. The default behavior |
| 27 // so that the accept/deny buttons grant/deny the relevant permission. | 27 // is that the accept/deny buttons grant/deny the relevant permission |
| 28 // A basic implementor only needs to implement the methods that | 28 // respectively. A basic implementor only needs to implement the methods that |
| 29 // provide an icon and a message text to the infobar. | 29 // provide an icon and a message text to the infobar. |
| 30 // |
| 31 // By default, the user is presented with an infobar to make their choice. If |
| 32 // the experimental ModalPermissionPrompts feature is active, they will instead |
| 33 // see a modal dialog. Currently, this class is used for both; future |
| 34 // refactoring will be undertaken based on whether support for infobars is |
| 35 // retained following the modal prompt experiment. |
| 30 class PermissionInfoBarDelegate : public ConfirmInfoBarDelegate { | 36 class PermissionInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 31 | |
| 32 public: | 37 public: |
| 33 using PermissionSetCallback = base::Callback<void(bool, PermissionAction)>; | 38 using PermissionSetCallback = base::Callback<void(bool, PermissionAction)>; |
| 34 | 39 |
| 35 // Creates an infobar for |type|. The returned pointer is owned by | 40 // Creates an infobar for |type|. The returned pointer is owned by |
| 36 // |infobar_service| and manages its own lifetime; callers must only use it | 41 // |infobar_service| and manages its own lifetime; callers must only use it |
| 37 // for calls to |infobar_service|. | 42 // for calls to |infobar_service|. |
| 38 static infobars::InfoBar* Create(content::PermissionType type, | 43 static infobars::InfoBar* Create(InfoBarService* infobar_service, |
| 39 InfoBarService* infobar_service, | 44 content::PermissionType type, |
| 40 const GURL& requesting_frame, | 45 const GURL& requesting_frame, |
| 41 bool user_gesture, | 46 bool user_gesture, |
| 42 Profile* profile, | 47 Profile* profile, |
| 43 const PermissionSetCallback& callback); | 48 const PermissionSetCallback& callback); |
| 44 | 49 |
| 50 static std::unique_ptr<PermissionInfoBarDelegate> CreateDelegate( |
| 51 content::PermissionType type, |
| 52 const GURL& requesting_frame, |
| 53 bool user_gesture, |
| 54 Profile* profile, |
| 55 const PermissionSetCallback& callback); |
| 56 |
| 45 ~PermissionInfoBarDelegate() override; | 57 ~PermissionInfoBarDelegate() override; |
| 46 virtual std::vector<int> content_settings() const; | 58 virtual std::vector<int> content_settings() const; |
| 47 | 59 |
| 48 // Returns true if the infobar should display a toggle to allow users to | 60 // Returns true if the infobar should display a toggle to allow users to |
| 49 // opt-out of persisting their accept/deny decision. | 61 // opt-out of persisting their accept/deny decision. |
| 50 bool ShouldShowPersistenceToggle() const; | 62 bool ShouldShowPersistenceToggle() const; |
| 51 | 63 |
| 52 // Sets whether or not a decided permission should be persisted to content | 64 // Sets whether or not a decided permission should be persisted to content |
| 53 // settings. | 65 // settings. |
| 54 void set_persist(bool persist) { persist_ = persist; } | 66 void set_persist(bool persist) { persist_ = persist; } |
| 55 bool persist() const { return persist_; } | 67 bool persist() const { return persist_; } |
| 56 | 68 |
| 57 // ConfirmInfoBarDelegate: | 69 // ConfirmInfoBarDelegate: |
| 70 bool Accept() override; |
| 71 bool Cancel() override; |
| 72 void InfoBarDismissed() override; |
| 73 base::string16 GetButtonLabel(InfoBarButton button) const override; |
| 58 base::string16 GetMessageText() const override; | 74 base::string16 GetMessageText() const override; |
| 59 | 75 |
| 60 protected: | 76 protected: |
| 61 PermissionInfoBarDelegate(const GURL& requesting_origin, | 77 PermissionInfoBarDelegate(const GURL& requesting_origin, |
| 62 content::PermissionType permission_type, | 78 content::PermissionType permission_type, |
| 63 ContentSettingsType content_settings_type, | 79 ContentSettingsType content_settings_type, |
| 64 bool user_gesture, | 80 bool user_gesture, |
| 65 Profile* profile, | 81 Profile* profile, |
| 66 const PermissionSetCallback& callback); | 82 const PermissionSetCallback& callback); |
| 67 | 83 |
| 68 private: | 84 private: |
| 69 // ConfirmInfoBarDelegate: | 85 // ConfirmInfoBarDelegate: |
| 70 Type GetInfoBarType() const override; | 86 Type GetInfoBarType() const override; |
| 71 void InfoBarDismissed() override; | |
| 72 PermissionInfoBarDelegate* AsPermissionInfoBarDelegate() override; | 87 PermissionInfoBarDelegate* AsPermissionInfoBarDelegate() override; |
| 73 base::string16 GetButtonLabel(InfoBarButton button) const override; | |
| 74 bool Accept() override; | |
| 75 bool Cancel() override; | |
| 76 | 88 |
| 77 virtual int GetMessageResourceId() const = 0; | 89 virtual int GetMessageResourceId() const = 0; |
| 78 void SetPermission(bool update_content_setting, PermissionAction decision); | 90 void SetPermission(bool update_content_setting, PermissionAction decision); |
| 79 | 91 |
| 80 GURL requesting_origin_; | 92 GURL requesting_origin_; |
| 81 content::PermissionType permission_type_; | 93 content::PermissionType permission_type_; |
| 82 ContentSettingsType content_settings_type_; | 94 ContentSettingsType content_settings_type_; |
| 83 Profile* const profile_; | 95 Profile* const profile_; |
| 84 const PermissionSetCallback callback_; | 96 const PermissionSetCallback callback_; |
| 85 bool action_taken_; | 97 bool action_taken_; |
| 86 bool user_gesture_; | 98 bool user_gesture_; |
| 87 bool persist_; | 99 bool persist_; |
| 88 | 100 |
| 89 DISALLOW_COPY_AND_ASSIGN(PermissionInfoBarDelegate); | 101 DISALLOW_COPY_AND_ASSIGN(PermissionInfoBarDelegate); |
| 90 }; | 102 }; |
| 91 | 103 |
| 92 // Implemented in platform-specific code. | 104 // Implemented in platform-specific code. |
| 93 std::unique_ptr<infobars::InfoBar> CreatePermissionInfoBar( | 105 std::unique_ptr<infobars::InfoBar> CreatePermissionInfoBar( |
| 94 std::unique_ptr<PermissionInfoBarDelegate> delegate); | 106 std::unique_ptr<PermissionInfoBarDelegate> delegate); |
| 95 | 107 |
| 96 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_DELEGATE_H_ | 108 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_DELEGATE_H_ |
| OLD | NEW |