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 <map> | |
9 | |
8 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
9 #include "base/id_map.h" | 11 #include "base/id_map.h" |
10 #include "base/macros.h" | 12 #include "base/macros.h" |
11 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
12 #include "components/content_settings/core/browser/content_settings_observer.h" | 14 #include "components/content_settings/core/browser/content_settings_observer.h" |
13 #include "components/content_settings/core/common/content_settings.h" | 15 #include "components/content_settings/core/common/content_settings.h" |
14 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
15 #include "content/public/browser/permission_manager.h" | 17 #include "content/public/browser/permission_manager.h" |
16 | 18 |
19 class PermissionContextBase; | |
17 class Profile; | 20 class Profile; |
18 | 21 |
19 namespace content { | 22 namespace content { |
20 enum class PermissionType; | 23 enum class PermissionType; |
21 class WebContents; | 24 class WebContents; |
22 }; // namespace content | 25 }; // namespace content |
23 | 26 |
24 class PermissionManager : public KeyedService, | 27 class PermissionManager : public KeyedService, |
25 public content::PermissionManager, | 28 public content::PermissionManager, |
26 public content_settings::Observer { | 29 public content_settings::Observer { |
27 public: | 30 public: |
31 static PermissionManager* Get(Profile* profile); | |
32 | |
28 explicit PermissionManager(Profile* profile); | 33 explicit PermissionManager(Profile* profile); |
29 ~PermissionManager() override; | 34 ~PermissionManager() override; |
30 | 35 |
31 // content::PermissionManager implementation. | 36 // content::PermissionManager implementation. |
32 int RequestPermission( | 37 int RequestPermission( |
33 content::PermissionType permission, | 38 content::PermissionType permission, |
34 content::RenderFrameHost* render_frame_host, | 39 content::RenderFrameHost* render_frame_host, |
35 const GURL& requesting_origin, | 40 const GURL& requesting_origin, |
36 const base::Callback<void(blink::mojom::PermissionStatus)>& callback) | 41 const base::Callback<void(blink::mojom::PermissionStatus)>& callback) |
37 override; | 42 override; |
(...skipping 17 matching lines...) Expand all Loading... | |
55 const GURL& embedding_origin) override; | 60 const GURL& embedding_origin) override; |
56 int SubscribePermissionStatusChange( | 61 int SubscribePermissionStatusChange( |
57 content::PermissionType permission, | 62 content::PermissionType permission, |
58 const GURL& requesting_origin, | 63 const GURL& requesting_origin, |
59 const GURL& embedding_origin, | 64 const GURL& embedding_origin, |
60 const base::Callback<void(blink::mojom::PermissionStatus)>& callback) | 65 const base::Callback<void(blink::mojom::PermissionStatus)>& callback) |
61 override; | 66 override; |
62 void UnsubscribePermissionStatusChange(int subscription_id) override; | 67 void UnsubscribePermissionStatusChange(int subscription_id) override; |
63 | 68 |
64 private: | 69 private: |
70 friend class GeolocationPermissionContextTests; | |
71 // TODO(raymes): Delete this after refactoring MediaPermission! | |
mlamouri (slow - plz ping)
2016/04/12 11:36:39
Link to a bug number?
raymes
2016/04/13 00:35:07
Done.
| |
72 friend class MediaPermission; | |
73 | |
65 class PendingRequest; | 74 class PendingRequest; |
66 using PendingRequestsMap = IDMap<PendingRequest, IDMapOwnPointer>; | 75 using PendingRequestsMap = IDMap<PendingRequest, IDMapOwnPointer>; |
67 | 76 |
68 struct Subscription; | 77 struct Subscription; |
69 using SubscriptionsMap = IDMap<Subscription, IDMapOwnPointer>; | 78 using SubscriptionsMap = IDMap<Subscription, IDMapOwnPointer>; |
70 | 79 |
80 PermissionContextBase* GetPermissionContext(content::PermissionType type); | |
81 | |
71 // Called when a permission was decided for a given PendingRequest. The | 82 // Called when a permission was decided for a given PendingRequest. The |
72 // PendingRequest is identified by its |request_id| and the permission is | 83 // PendingRequest is identified by its |request_id| and the permission is |
73 // identified by its |permission_id|. If the PendingRequest contains more than | 84 // identified by its |permission_id|. If the PendingRequest contains more than |
74 // one permission, it will wait for the remaining permissions to be resolved. | 85 // one permission, it will wait for the remaining permissions to be resolved. |
75 // When all the permissions have been resolved, the PendingRequest's callback | 86 // When all the permissions have been resolved, the PendingRequest's callback |
76 // is run. | 87 // is run. |
77 void OnPermissionsRequestResponseStatus( | 88 void OnPermissionsRequestResponseStatus( |
78 int request_id, | 89 int request_id, |
79 int permission_id, | 90 int permission_id, |
80 blink::mojom::PermissionStatus status); | 91 blink::mojom::PermissionStatus status); |
81 | 92 |
82 // Not all WebContents are able to display permission requests. If the PBM | 93 // Not all WebContents are able to display permission requests. If the PBM |
83 // is required but missing for |web_contents|, don't pass along the request. | 94 // is required but missing for |web_contents|, don't pass along the request. |
84 bool IsPermissionBubbleManagerMissing(content::WebContents* web_contents); | 95 bool IsPermissionBubbleManagerMissing(content::WebContents* web_contents); |
85 | 96 |
86 // content_settings::Observer implementation. | 97 // content_settings::Observer implementation. |
87 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, | 98 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, |
88 const ContentSettingsPattern& secondary_pattern, | 99 const ContentSettingsPattern& secondary_pattern, |
89 ContentSettingsType content_type, | 100 ContentSettingsType content_type, |
90 std::string resource_identifier) override; | 101 std::string resource_identifier) override; |
91 | 102 |
92 Profile* profile_; | 103 Profile* profile_; |
93 PendingRequestsMap pending_requests_; | 104 PendingRequestsMap pending_requests_; |
94 SubscriptionsMap subscriptions_; | 105 SubscriptionsMap subscriptions_; |
95 | 106 |
107 std::map<content::PermissionType, scoped_ptr<PermissionContextBase>> | |
108 permission_contexts_; | |
109 | |
96 base::WeakPtrFactory<PermissionManager> weak_ptr_factory_; | 110 base::WeakPtrFactory<PermissionManager> weak_ptr_factory_; |
97 | 111 |
98 DISALLOW_COPY_AND_ASSIGN(PermissionManager); | 112 DISALLOW_COPY_AND_ASSIGN(PermissionManager); |
99 }; | 113 }; |
100 | 114 |
101 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ | 115 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ |
OLD | NEW |