OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ |
6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ | 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ |
7 | 7 |
8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
9 #include "base/id_map.h" | 9 #include "base/id_map.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" |
11 #include "components/content_settings/core/browser/content_settings_observer.h" | 12 #include "components/content_settings/core/browser/content_settings_observer.h" |
| 13 #include "components/content_settings/core/common/content_settings.h" |
12 #include "components/keyed_service/core/keyed_service.h" | 14 #include "components/keyed_service/core/keyed_service.h" |
13 #include "content/public/browser/permission_manager.h" | 15 #include "content/public/browser/permission_manager.h" |
14 | 16 |
15 | 17 |
16 class Profile; | 18 class Profile; |
17 | 19 |
18 namespace content { | 20 namespace content { |
19 enum class PermissionType; | 21 enum class PermissionType; |
20 class WebContents; | 22 class WebContents; |
21 }; // namespace content | 23 }; // namespace content |
22 | 24 |
23 class PermissionManager : public KeyedService, | 25 class PermissionManager : public KeyedService, |
24 public content::PermissionManager, | 26 public content::PermissionManager, |
25 public content_settings::Observer { | 27 public content_settings::Observer { |
26 public: | 28 public: |
27 explicit PermissionManager(Profile* profile); | 29 explicit PermissionManager(Profile* profile); |
28 ~PermissionManager() override; | 30 ~PermissionManager() override; |
29 | 31 |
30 // content::PermissionManager implementation. | 32 // content::PermissionManager implementation. |
31 void RequestPermission( | 33 int RequestPermission( |
32 content::PermissionType permission, | 34 content::PermissionType permission, |
33 content::RenderFrameHost* render_frame_host, | 35 content::RenderFrameHost* render_frame_host, |
34 int request_id, | |
35 const GURL& requesting_origin, | 36 const GURL& requesting_origin, |
36 bool user_gesture, | 37 bool user_gesture, |
37 const base::Callback<void(content::PermissionStatus)>& callback) override; | 38 const base::Callback<void(content::PermissionStatus)>& callback) override; |
38 void CancelPermissionRequest(content::PermissionType permission, | 39 void CancelPermissionRequest(int request_id) override; |
39 content::RenderFrameHost* render_frame_host, | |
40 int request_id, | |
41 const GURL& requesting_origin) override; | |
42 void ResetPermission(content::PermissionType permission, | 40 void ResetPermission(content::PermissionType permission, |
43 const GURL& requesting_origin, | 41 const GURL& requesting_origin, |
44 const GURL& embedding_origin) override; | 42 const GURL& embedding_origin) override; |
45 content::PermissionStatus GetPermissionStatus( | 43 content::PermissionStatus GetPermissionStatus( |
46 content::PermissionType permission, | 44 content::PermissionType permission, |
47 const GURL& requesting_origin, | 45 const GURL& requesting_origin, |
48 const GURL& embedding_origin) override; | 46 const GURL& embedding_origin) override; |
49 void RegisterPermissionUsage(content::PermissionType permission, | 47 void RegisterPermissionUsage(content::PermissionType permission, |
50 const GURL& requesting_origin, | 48 const GURL& requesting_origin, |
51 const GURL& embedding_origin) override; | 49 const GURL& embedding_origin) override; |
52 int SubscribePermissionStatusChange( | 50 int SubscribePermissionStatusChange( |
53 content::PermissionType permission, | 51 content::PermissionType permission, |
54 const GURL& requesting_origin, | 52 const GURL& requesting_origin, |
55 const GURL& embedding_origin, | 53 const GURL& embedding_origin, |
56 const base::Callback<void(content::PermissionStatus)>& callback) override; | 54 const base::Callback<void(content::PermissionStatus)>& callback) override; |
57 void UnsubscribePermissionStatusChange(int subscription_id) override; | 55 void UnsubscribePermissionStatusChange(int subscription_id) override; |
58 | 56 |
59 private: | 57 private: |
| 58 struct PendingRequest; |
| 59 using PendingRequestsMap = IDMap<PendingRequest, IDMapOwnPointer>; |
| 60 |
60 struct Subscription; | 61 struct Subscription; |
61 using SubscriptionsMap = IDMap<Subscription, IDMapOwnPointer>; | 62 using SubscriptionsMap = IDMap<Subscription, IDMapOwnPointer>; |
62 | 63 |
| 64 void OnPermissionRequestResponse( |
| 65 int request_id, |
| 66 const base::Callback<void(content::PermissionStatus)>& callback, |
| 67 ContentSetting content_setting); |
| 68 |
63 // Not all WebContents are able to display permission requests. If the PBM | 69 // Not all WebContents are able to display permission requests. If the PBM |
64 // is required but missing for |web_contents|, don't pass along the request. | 70 // is required but missing for |web_contents|, don't pass along the request. |
65 bool IsPermissionBubbleManagerMissing(content::WebContents* web_contents); | 71 bool IsPermissionBubbleManagerMissing(content::WebContents* web_contents); |
66 | 72 |
67 // content_settings::Observer implementation. | 73 // content_settings::Observer implementation. |
68 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, | 74 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, |
69 const ContentSettingsPattern& secondary_pattern, | 75 const ContentSettingsPattern& secondary_pattern, |
70 ContentSettingsType content_type, | 76 ContentSettingsType content_type, |
71 std::string resource_identifier) override; | 77 std::string resource_identifier) override; |
72 | 78 |
73 Profile* profile_; | 79 Profile* profile_; |
| 80 PendingRequestsMap pending_requests_; |
74 SubscriptionsMap subscriptions_; | 81 SubscriptionsMap subscriptions_; |
75 | 82 |
| 83 base::WeakPtrFactory<PermissionManager> weak_ptr_factory_; |
| 84 |
76 DISALLOW_COPY_AND_ASSIGN(PermissionManager); | 85 DISALLOW_COPY_AND_ASSIGN(PermissionManager); |
77 }; | 86 }; |
78 | 87 |
79 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ | 88 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ |
OLD | NEW |