Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: chrome/browser/permissions/permission_infobar_delegate.h

Issue 2446063002: Implement a modal permission dialog on Android gated by a feature. (Closed)
Patch Set: Allow user gesture requirement to be overridden by variations Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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(content::PermissionType type,
39 InfoBarService* infobar_service, 44 InfoBarService* infobar_service,
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
45 ~PermissionInfoBarDelegate() override; 50 ~PermissionInfoBarDelegate() override;
46 virtual std::vector<int> content_settings() const; 51 virtual std::vector<int> content_settings() const;
47 52
48 // Returns true if the infobar should display a toggle to allow users to 53 // Returns true if the infobar should display a toggle to allow users to
49 // opt-out of persisting their accept/deny decision. 54 // opt-out of persisting their accept/deny decision.
50 bool ShouldShowPersistenceToggle() const; 55 bool ShouldShowPersistenceToggle() const;
51 56
52 // Sets whether or not a decided permission should be persisted to content 57 // Sets whether or not a decided permission should be persisted to content
53 // settings. 58 // settings.
54 void set_persist(bool persist) { persist_ = persist; } 59 void set_persist(bool persist) { persist_ = persist; }
55 bool persist() const { return persist_; } 60 bool persist() const { return persist_; }
56 61
57 // ConfirmInfoBarDelegate: 62 // ConfirmInfoBarDelegate:
63 bool Accept() override;
64 bool Cancel() override;
65 void InfoBarDismissed() override;
66 base::string16 GetButtonLabel(InfoBarButton button) const override;
58 base::string16 GetMessageText() const override; 67 base::string16 GetMessageText() const override;
59 68
60 protected: 69 protected:
61 PermissionInfoBarDelegate(const GURL& requesting_origin, 70 PermissionInfoBarDelegate(const GURL& requesting_origin,
62 content::PermissionType permission_type, 71 content::PermissionType permission_type,
63 ContentSettingsType content_settings_type, 72 ContentSettingsType content_settings_type,
64 bool user_gesture, 73 bool user_gesture,
65 Profile* profile, 74 Profile* profile,
66 const PermissionSetCallback& callback); 75 const PermissionSetCallback& callback);
67 76
68 private: 77 private:
69 // ConfirmInfoBarDelegate: 78 // ConfirmInfoBarDelegate:
70 Type GetInfoBarType() const override; 79 Type GetInfoBarType() const override;
71 void InfoBarDismissed() override;
72 PermissionInfoBarDelegate* AsPermissionInfoBarDelegate() override; 80 PermissionInfoBarDelegate* AsPermissionInfoBarDelegate() override;
73 base::string16 GetButtonLabel(InfoBarButton button) const override;
74 bool Accept() override;
75 bool Cancel() override;
76 81
77 virtual int GetMessageResourceId() const = 0; 82 virtual int GetMessageResourceId() const = 0;
78 void SetPermission(bool update_content_setting, PermissionAction decision); 83 void SetPermission(bool update_content_setting, PermissionAction decision);
79 84
80 GURL requesting_origin_; 85 GURL requesting_origin_;
81 content::PermissionType permission_type_; 86 content::PermissionType permission_type_;
82 ContentSettingsType content_settings_type_; 87 ContentSettingsType content_settings_type_;
83 Profile* const profile_; 88 Profile* const profile_;
84 const PermissionSetCallback callback_; 89 const PermissionSetCallback callback_;
85 bool action_taken_; 90 bool action_taken_;
86 bool user_gesture_; 91 bool user_gesture_;
87 bool persist_; 92 bool persist_;
88 93
89 DISALLOW_COPY_AND_ASSIGN(PermissionInfoBarDelegate); 94 DISALLOW_COPY_AND_ASSIGN(PermissionInfoBarDelegate);
90 }; 95 };
91 96
92 // Implemented in platform-specific code. 97 // Implemented in platform-specific code.
93 std::unique_ptr<infobars::InfoBar> CreatePermissionInfoBar( 98 std::unique_ptr<infobars::InfoBar> CreatePermissionInfoBar(
94 std::unique_ptr<PermissionInfoBarDelegate> delegate); 99 std::unique_ptr<PermissionInfoBarDelegate> delegate);
95 100
96 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_DELEGATE_H_ 101 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698