| 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 <unordered_map> | 8 #include <unordered_map> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/id_map.h" | 11 #include "base/id_map.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "chrome/browser/permissions/permission_util.h" | 14 #include "chrome/browser/permissions/permission_util.h" |
| 15 #include "components/content_settings/core/browser/content_settings_observer.h" | 15 #include "components/content_settings/core/browser/content_settings_observer.h" |
| 16 #include "components/content_settings/core/common/content_settings.h" | 16 #include "components/content_settings/core/common/content_settings.h" |
| 17 #include "components/keyed_service/core/keyed_service.h" | 17 #include "components/keyed_service/core/keyed_service.h" |
| 18 #include "content/public/browser/permission_manager.h" | 18 #include "content/public/browser/permission_manager.h" |
| 19 | 19 |
| 20 class PermissionContextBase; | 20 class PermissionContextBase; |
| 21 struct PermissionResult; |
| 21 class Profile; | 22 class Profile; |
| 22 | 23 |
| 23 namespace content { | 24 namespace content { |
| 24 enum class PermissionType; | 25 enum class PermissionType; |
| 25 }; // namespace content | 26 }; // namespace content |
| 26 | 27 |
| 27 class PermissionManager : public KeyedService, | 28 class PermissionManager : public KeyedService, |
| 28 public content::PermissionManager, | 29 public content::PermissionManager, |
| 29 public content_settings::Observer { | 30 public content_settings::Observer { |
| 30 public: | 31 public: |
| 31 static PermissionManager* Get(Profile* profile); | 32 static PermissionManager* Get(Profile* profile); |
| 32 | 33 |
| 33 explicit PermissionManager(Profile* profile); | 34 explicit PermissionManager(Profile* profile); |
| 34 ~PermissionManager() override; | 35 ~PermissionManager() override; |
| 35 | 36 |
| 36 // Callers from within chrome/ should use the methods which take the | 37 // Callers from within chrome/ should use the methods which take the |
| 37 // ContentSettingsType enum. The methods which take PermissionType values | 38 // ContentSettingsType enum. The methods which take PermissionType values |
| 38 // are for the content::PermissionManager overrides and shouldn't be used | 39 // are for the content::PermissionManager overrides and shouldn't be used |
| 39 // from chrome/. | 40 // from chrome/. |
| 40 | 41 |
| 41 int RequestPermission( | 42 int RequestPermission(ContentSettingsType permission, |
| 42 ContentSettingsType permission, | 43 content::RenderFrameHost* render_frame_host, |
| 43 content::RenderFrameHost* render_frame_host, | 44 const GURL& requesting_origin, |
| 44 const GURL& requesting_origin, | 45 bool user_gesture, |
| 45 bool user_gesture, | 46 const base::Callback<void(ContentSetting)>& callback); |
| 46 const base::Callback<void(blink::mojom::PermissionStatus)>& callback); | |
| 47 int RequestPermissions( | 47 int RequestPermissions( |
| 48 const std::vector<ContentSettingsType>& permissions, | 48 const std::vector<ContentSettingsType>& permissions, |
| 49 content::RenderFrameHost* render_frame_host, | 49 content::RenderFrameHost* render_frame_host, |
| 50 const GURL& requesting_origin, | 50 const GURL& requesting_origin, |
| 51 bool user_gesture, | 51 bool user_gesture, |
| 52 const base::Callback< | 52 const base::Callback<void(const std::vector<ContentSetting>&)>& callback); |
| 53 void(const std::vector<blink::mojom::PermissionStatus>&)>& callback); | |
| 54 | 53 |
| 55 blink::mojom::PermissionStatus GetPermissionStatus( | 54 PermissionResult GetPermissionStatus(ContentSettingsType permission, |
| 56 ContentSettingsType permission, | 55 const GURL& requesting_origin, |
| 57 const GURL& requesting_origin, | 56 const GURL& embedding_origin); |
| 58 const GURL& embedding_origin); | |
| 59 | 57 |
| 60 // content::PermissionManager implementation. | 58 // content::PermissionManager implementation. |
| 61 int RequestPermission( | 59 int RequestPermission( |
| 62 content::PermissionType permission, | 60 content::PermissionType permission, |
| 63 content::RenderFrameHost* render_frame_host, | 61 content::RenderFrameHost* render_frame_host, |
| 64 const GURL& requesting_origin, | 62 const GURL& requesting_origin, |
| 65 bool user_gesture, | 63 bool user_gesture, |
| 66 const base::Callback<void(blink::mojom::PermissionStatus)>& callback) | 64 const base::Callback<void(blink::mojom::PermissionStatus)>& callback) |
| 67 override; | 65 override; |
| 68 int RequestPermissions( | 66 int RequestPermissions( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 82 const GURL& requesting_origin, | 80 const GURL& requesting_origin, |
| 83 const GURL& embedding_origin) override; | 81 const GURL& embedding_origin) override; |
| 84 int SubscribePermissionStatusChange( | 82 int SubscribePermissionStatusChange( |
| 85 content::PermissionType permission, | 83 content::PermissionType permission, |
| 86 const GURL& requesting_origin, | 84 const GURL& requesting_origin, |
| 87 const GURL& embedding_origin, | 85 const GURL& embedding_origin, |
| 88 const base::Callback<void(blink::mojom::PermissionStatus)>& callback) | 86 const base::Callback<void(blink::mojom::PermissionStatus)>& callback) |
| 89 override; | 87 override; |
| 90 void UnsubscribePermissionStatusChange(int subscription_id) override; | 88 void UnsubscribePermissionStatusChange(int subscription_id) override; |
| 91 | 89 |
| 92 // TODO(raymes): Rather than exposing this, expose a denial reason from | 90 // TODO(raymes): Rather than exposing this, use the denial reason from |
| 93 // GetPermissionStatus so that callers can determine whether a permission is | 91 // GetPermissionStatus in callers to determine whether a permission is |
| 94 // denied due to the kill switch. | 92 // denied due to the kill switch. |
| 95 bool IsPermissionKillSwitchOn(ContentSettingsType); | 93 bool IsPermissionKillSwitchOn(ContentSettingsType); |
| 96 | 94 |
| 97 private: | 95 private: |
| 98 friend class GeolocationPermissionContextTests; | 96 friend class GeolocationPermissionContextTests; |
| 99 | 97 |
| 100 class PendingRequest; | 98 class PendingRequest; |
| 101 using PendingRequestsMap = IDMap<std::unique_ptr<PendingRequest>>; | 99 using PendingRequestsMap = IDMap<std::unique_ptr<PendingRequest>>; |
| 102 | 100 |
| 103 struct Subscription; | 101 struct Subscription; |
| 104 using SubscriptionsMap = IDMap<std::unique_ptr<Subscription>>; | 102 using SubscriptionsMap = IDMap<std::unique_ptr<Subscription>>; |
| 105 | 103 |
| 106 PermissionContextBase* GetPermissionContext(ContentSettingsType type); | 104 PermissionContextBase* GetPermissionContext(ContentSettingsType type); |
| 107 | 105 |
| 108 // Called when a permission was decided for a given PendingRequest. The | 106 // Called when a permission was decided for a given PendingRequest. The |
| 109 // PendingRequest is identified by its |request_id| and the permission is | 107 // PendingRequest is identified by its |request_id| and the permission is |
| 110 // identified by its |permission_id|. If the PendingRequest contains more than | 108 // identified by its |permission_id|. If the PendingRequest contains more than |
| 111 // one permission, it will wait for the remaining permissions to be resolved. | 109 // one permission, it will wait for the remaining permissions to be resolved. |
| 112 // When all the permissions have been resolved, the PendingRequest's callback | 110 // When all the permissions have been resolved, the PendingRequest's callback |
| 113 // is run. | 111 // is run. |
| 114 void OnPermissionsRequestResponseStatus( | 112 void OnPermissionsRequestResponseStatus(int request_id, |
| 115 int request_id, | 113 int permission_id, |
| 116 int permission_id, | 114 ContentSetting status); |
| 117 blink::mojom::PermissionStatus status); | |
| 118 | 115 |
| 119 // content_settings::Observer implementation. | 116 // content_settings::Observer implementation. |
| 120 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, | 117 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, |
| 121 const ContentSettingsPattern& secondary_pattern, | 118 const ContentSettingsPattern& secondary_pattern, |
| 122 ContentSettingsType content_type, | 119 ContentSettingsType content_type, |
| 123 std::string resource_identifier) override; | 120 std::string resource_identifier) override; |
| 124 | 121 |
| 125 Profile* profile_; | 122 Profile* profile_; |
| 126 PendingRequestsMap pending_requests_; | 123 PendingRequestsMap pending_requests_; |
| 127 SubscriptionsMap subscriptions_; | 124 SubscriptionsMap subscriptions_; |
| 128 | 125 |
| 129 std::unordered_map<ContentSettingsType, | 126 std::unordered_map<ContentSettingsType, |
| 130 std::unique_ptr<PermissionContextBase>, | 127 std::unique_ptr<PermissionContextBase>, |
| 131 ContentSettingsTypeHash> | 128 ContentSettingsTypeHash> |
| 132 permission_contexts_; | 129 permission_contexts_; |
| 133 | 130 |
| 134 base::WeakPtrFactory<PermissionManager> weak_ptr_factory_; | 131 base::WeakPtrFactory<PermissionManager> weak_ptr_factory_; |
| 135 | 132 |
| 136 DISALLOW_COPY_AND_ASSIGN(PermissionManager); | 133 DISALLOW_COPY_AND_ASSIGN(PermissionManager); |
| 137 }; | 134 }; |
| 138 | 135 |
| 139 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ | 136 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ |
| OLD | NEW |