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_MANAGER_H_ | |
6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_MANAGER_H_ | |
7 | |
8 #include "base/callback_forward.h" | |
9 #include "base/containers/scoped_ptr_hash_map.h" | |
10 #include "base/memory/weak_ptr.h" | |
11 #include "chrome/browser/permissions/permission_request_id.h" | |
12 #include "components/content_settings/core/common/content_settings.h" | |
13 #include "components/content_settings/core/common/content_settings_types.h" | |
14 #include "content/public/browser/web_contents_observer.h" | |
15 #include "content/public/browser/web_contents_user_data.h" | |
16 | |
17 class GURL; | |
18 class PermissionInfoBarRequest; | |
19 | |
20 // Manages permsision requests using InfoBars. Requests are coalesced by | |
21 // request_id. If multiple requests occur with overlapping permissions, both | |
22 // will be shown and the last to have a response will be persisted. | |
23 class PermissionInfoBarManager | |
24 : public content::WebContentsObserver, | |
25 public content::WebContentsUserData<PermissionInfoBarManager> { | |
26 public: | |
27 ~PermissionInfoBarManager() override; | |
28 | |
29 // Queues an infobar request to be shown at some point. Requests with | |
30 // the same |request_id| are coalesced. | |
31 void CreateRequest( | |
32 const ContentSettingsType type, | |
33 const PermissionRequestID& request, | |
34 const GURL& requesting_origin, | |
35 const GURL& embedding_origin, | |
36 const base::Callback<void(bool, ContentSetting)>& response_callback); | |
37 | |
38 // Cancels a specific infobar request. | |
39 void CancelRequest(const PermissionRequestID& request); | |
40 | |
41 private: | |
42 friend class GeolocationPermissionContextTests; | |
43 friend class PermissionContextBaseTests; | |
44 friend class content::WebContentsUserData<PermissionInfoBarManager>; | |
45 using PermissionDecidedCallback = base::Callback<void(bool, ContentSetting)>; | |
46 | |
47 explicit PermissionInfoBarManager(content::WebContents* web_contents); | |
48 | |
49 // Used by tests to accept or ignore the current request. | |
50 void Accept(); | |
51 void Closing(); | |
mlamouri (slow - plz ping)
2015/10/02 11:49:39
If these are for tests only, please add "ForTests"
Lalit Maganti
2015/10/02 13:37:45
Done.
| |
52 | |
53 // Posts a call to |ShowNextQueuedRequest| if there is no current request | |
54 // and |queued_requests_| is not empty. | |
55 void TriggerShowNextQueuedRequest(); | |
56 | |
57 // Shows the next request in |queued_requests_| if there is no current | |
58 // request and if |queued_requests_| is not empty | |
59 void ShowNextQueuedRequest(); | |
60 | |
61 // Callback function used when the infobar is dismissed, accepted or denied. | |
62 void OnInfoBarClosed(); | |
63 | |
64 // Remoes the current request and shows a next queued request if available. | |
mlamouri (slow - plz ping)
2015/10/02 11:49:39
nit: typo
Lalit Maganti
2015/10/02 13:37:45
Done.
| |
65 void ClearCurrentRequest(); | |
66 | |
67 // Returns whether the queue should be ignored when considering to show | |
68 // a new request. | |
69 bool ShouldIgnoreQueuedRequests(); | |
70 | |
71 scoped_ptr<PermissionInfoBarRequest> current_request_; | |
mlamouri (slow - plz ping)
2015/10/02 11:49:39
nit: add comment
Lalit Maganti
2015/10/02 13:37:45
Done.
| |
72 | |
73 bool is_show_pending_; | |
mlamouri (slow - plz ping)
2015/10/02 11:49:39
nit: add comment
Lalit Maganti
2015/10/02 13:37:45
Done.
| |
74 | |
75 base::ScopedPtrHashMap<int, | |
76 scoped_ptr<PermissionInfoBarRequest>> queued_requests_; | |
mlamouri (slow - plz ping)
2015/10/02 11:49:39
What about using IDMap here instead? It would guar
Lalit Maganti
2015/10/02 13:37:45
That would be good except I can't extract the poin
| |
77 | |
78 base::WeakPtrFactory<PermissionInfoBarManager> weak_factory_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(PermissionInfoBarManager); | |
81 }; | |
82 | |
83 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_MANAGER_H_ | |
OLD | NEW |