OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_REQUEST_H_ | |
6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_REQUEST_H_ | |
7 | |
8 #include "base/callback.h" | |
9 #include "base/memory/weak_ptr.h" | |
10 #include "components/content_settings/core/common/content_settings.h" | |
11 #include "url/gurl.h" | |
12 | |
13 class InfoBarService; | |
14 class Profile; | |
15 | |
16 namespace content { | |
17 class WebContents; | |
18 } // namespace content | |
19 | |
20 namespace infobars { | |
21 class InfoBar; | |
22 } // namespace infobars | |
23 | |
24 // Represents a permission request which will be displayed using an InfoBar. | |
25 class PermissionInfoBarRequest { | |
26 public: | |
27 PermissionInfoBarRequest( | |
28 int request_id, | |
29 const GURL& requesting_origin, | |
30 const GURL& embedding_origin, | |
31 const base::Closure& callback); | |
32 ~PermissionInfoBarRequest(); | |
33 | |
34 // Adds a permisison type which should be associated with this request. | |
35 /// This function can be called as many times as the caller wants until | |
36 // |ShowInfobar| is called. After this point this function should NOT be | |
37 // called. | |
38 void AddPermission( | |
39 const ContentSettingsType type, | |
40 const base::Callback<void(bool, ContentSetting)>& callback); | |
41 | |
42 // Shows the relavent infobar for this request in the specified web contents. | |
43 // Called after all permissions have been added to the request with | |
44 // |AddPermission|. | |
45 bool ShowInfobar(content::WebContents* web_contents); | |
46 | |
47 // Used to cancel the request without user action. | |
48 void Cancel(); | |
49 | |
50 int request_id() const { return request_id_; } | |
51 | |
52 private: | |
53 friend class PermissionContextBaseTests; | |
54 using PermissionDecidedCallback = base::Callback<void(bool, ContentSetting)>; | |
55 class PermissionRequest { | |
56 public: | |
57 PermissionRequest(ContentSettingsType type, | |
58 const PermissionDecidedCallback& callback); | |
59 ~PermissionRequest(); | |
60 | |
61 ContentSettingsType type() const { return type_; } | |
62 const PermissionDecidedCallback& callback() const { | |
63 return callback_; | |
64 } | |
65 | |
66 private: | |
67 ContentSettingsType type_; | |
68 PermissionDecidedCallback callback_; | |
69 }; | |
70 | |
71 // Used to accept or dismiss the request in tests. | |
72 void AcceptForTests(); | |
73 void ClosingForTests(); | |
74 | |
75 // Called when this request is dismissed without user action. | |
76 void OnManualClose(); | |
mlamouri (slow - plz ping)
2015/10/02 15:51:07
OnCancel?
Lalit Maganti
2015/10/02 16:06:43
Done.
| |
77 | |
78 // Callback function which is called when the user responds to a single | |
79 // permission infobar. | |
80 void OnPermissionSet(bool update_content_setting, | |
81 bool allowed); | |
82 | |
83 // Callback function which is called when the user responds to a coalesced | |
84 // permission infobar. | |
85 void OnPermissionsSet(bool update_content_setting, | |
86 const std::vector<ContentSetting>& allowed); | |
87 | |
88 // Removes any permissions from this request for which there is no need to | |
89 // prompt the user. | |
90 void PruneAnsweredPermissions(Profile* profile); | |
91 | |
92 // Creates the single permission infobar for the PermissionRequest | |
93 // specified. | |
94 void CreateInfoBar(InfoBarService* infobar_service, | |
95 const PermissionRequest& request, | |
96 const std::string& display_languages, | |
97 const base::Callback<void(bool, bool)>& callback); | |
98 | |
99 // Owned by InfoBarService. | |
100 infobars::InfoBar* infobar_; | |
101 | |
102 int request_id_; | |
103 GURL requesting_origin_; | |
104 GURL embedding_origin_; | |
105 base::Closure callback_; | |
106 std::vector<PermissionRequest> requests_; | |
107 | |
108 base::WeakPtrFactory<PermissionInfoBarRequest> weak_factory_; | |
109 | |
110 DISALLOW_COPY_AND_ASSIGN(PermissionInfoBarRequest); | |
111 }; | |
112 | |
113 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_REQUEST_H_ | |
OLD | NEW |