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 CreateInfoBarRequest( | |
32 const ContentSettingsType type, | |
33 const PermissionRequestID& request, | |
34 const GURL& requesting_frame, | |
35 const GURL& embedder, | |
36 const base::Callback<void(bool, ContentSetting)>& user_callback, | |
37 const base::Callback<void(bool, ContentSetting)>& non_user_callback); | |
mlamouri (slow - plz ping)
2015/09/16 16:21:01
Why having these two callbacks? It makes things a
Lalit Maganti
2015/09/16 17:28:38
It's necessary to correctly bypass the UMA and con
| |
38 | |
39 // Cancels a specific infobar request. | |
40 void CancelInfoBarRequest(const PermissionRequestID& request); | |
41 | |
42 private: | |
43 friend class content::WebContentsUserData<PermissionInfoBarManager>; | |
44 using PermissionDecidedCallback = base::Callback<void(bool, ContentSetting)>; | |
45 | |
46 explicit PermissionInfoBarManager(content::WebContents* web_contents); | |
47 | |
48 void TriggerShowQueuedInfoBars(); | |
49 void ShowQueuedInfoBars(); | |
50 void OnInfoBarRequestCompleted(); | |
51 | |
52 void ClearCurrentRequest(); | |
53 bool ShouldIgnoreQueuedRequests(); | |
54 | |
55 scoped_ptr<PermissionInfoBarRequest> current_request_; | |
56 int current_request_id_; | |
57 | |
58 bool is_show_queued_pending_; | |
59 | |
60 base::ScopedPtrHashMap<int, | |
61 scoped_ptr<PermissionInfoBarRequest>> queued_requests_; | |
62 | |
63 base::WeakPtrFactory<PermissionInfoBarManager> weak_factory_; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(PermissionInfoBarManager); | |
66 }; | |
67 | |
68 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_INFOBAR_MANAGER_H_ | |
OLD | NEW |