| 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" | |
| 15 #include "components/infobars/core/confirm_infobar_delegate.h" | 14 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 16 #include "content/public/browser/permission_type.h" | 15 #include "content/public/browser/permission_type.h" |
| 17 | 16 |
| 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 virtual std::vector<int> content_settings() const; | 29 virtual std::vector<int> permission_types() const; |
| 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 bool persist() const { return persist_; } | 38 bool persist() const { return persist_; } |
| 40 | 39 |
| 41 // ConfirmInfoBarDelegate: | 40 // ConfirmInfoBarDelegate: |
| 42 base::string16 GetMessageText() const override; | 41 base::string16 GetMessageText() const override; |
| 43 | 42 |
| 44 protected: | 43 protected: |
| 45 PermissionInfoBarDelegate(const GURL& requesting_origin, | 44 PermissionInfoBarDelegate(const GURL& requesting_origin, |
| 46 content::PermissionType permission_type, | 45 content::PermissionType permission_type, |
| 47 ContentSettingsType content_settings_type, | |
| 48 bool user_gesture, | 46 bool user_gesture, |
| 49 Profile* profile, | 47 Profile* profile, |
| 50 const PermissionSetCallback& callback); | 48 const PermissionSetCallback& callback); |
| 51 | 49 |
| 52 private: | 50 private: |
| 53 // ConfirmInfoBarDelegate: | 51 // ConfirmInfoBarDelegate: |
| 54 Type GetInfoBarType() const override; | 52 Type GetInfoBarType() const override; |
| 55 void InfoBarDismissed() override; | 53 void InfoBarDismissed() override; |
| 56 PermissionInfoBarDelegate* AsPermissionInfoBarDelegate() override; | 54 PermissionInfoBarDelegate* AsPermissionInfoBarDelegate() override; |
| 57 base::string16 GetButtonLabel(InfoBarButton button) const override; | 55 base::string16 GetButtonLabel(InfoBarButton button) const override; |
| 58 bool Accept() override; | 56 bool Accept() override; |
| 59 bool Cancel() override; | 57 bool Cancel() override; |
| 60 | 58 |
| 61 virtual int GetMessageResourceId() const = 0; | 59 virtual int GetMessageResourceId() const = 0; |
| 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_; | |
| 67 Profile* const profile_; | 64 Profile* const profile_; |
| 68 const PermissionSetCallback callback_; | 65 const PermissionSetCallback callback_; |
| 69 bool action_taken_; | 66 bool action_taken_; |
| 70 bool user_gesture_; | 67 bool user_gesture_; |
| 71 bool persist_; | 68 bool persist_; |
| 72 | 69 |
| 73 DISALLOW_COPY_AND_ASSIGN(PermissionInfoBarDelegate); | 70 DISALLOW_COPY_AND_ASSIGN(PermissionInfoBarDelegate); |
| 74 }; | 71 }; |
| 75 | 72 |
| 76 // Implemented in platform-specific code. | 73 // Implemented in platform-specific code. |
| 77 std::unique_ptr<infobars::InfoBar> CreatePermissionInfoBar( | 74 std::unique_ptr<infobars::InfoBar> CreatePermissionInfoBar( |
| 78 std::unique_ptr<PermissionInfoBarDelegate> delegate); | 75 std::unique_ptr<PermissionInfoBarDelegate> delegate); |
| 79 | 76 |
| 80 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_DELEGATE_H_ | 77 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_DELEGATE_H_ |
| OLD | NEW |