| 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 "base/memory/weak_ptr.h" |
| 12 #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" | 13 #include "components/content_settings/core/common/content_settings.h" |
| 14 #include "components/keyed_service/core/keyed_service.h" | 14 #include "components/keyed_service/core/keyed_service.h" |
| 15 #include "content/public/browser/permission_manager.h" | 15 #include "content/public/browser/permission_manager.h" |
| 16 | 16 |
| 17 | |
| 18 class Profile; | 17 class Profile; |
| 19 | 18 |
| 20 namespace content { | 19 namespace content { |
| 21 enum class PermissionType; | 20 enum class PermissionType; |
| 22 class WebContents; | 21 class WebContents; |
| 23 }; // namespace content | 22 }; // namespace content |
| 24 | 23 |
| 25 class PermissionManager : public KeyedService, | 24 class PermissionManager : public KeyedService, |
| 26 public content::PermissionManager, | 25 public content::PermissionManager, |
| 27 public content_settings::Observer { | 26 public content_settings::Observer { |
| 28 public: | 27 public: |
| 29 explicit PermissionManager(Profile* profile); | 28 explicit PermissionManager(Profile* profile); |
| 30 ~PermissionManager() override; | 29 ~PermissionManager() override; |
| 31 | 30 |
| 32 // content::PermissionManager implementation. | 31 // content::PermissionManager implementation. |
| 33 int RequestPermission( | 32 int RequestPermission( |
| 34 content::PermissionType permission, | 33 content::PermissionType permission, |
| 35 content::RenderFrameHost* render_frame_host, | 34 content::RenderFrameHost* render_frame_host, |
| 36 const GURL& requesting_origin, | 35 const GURL& requesting_origin, |
| 37 bool user_gesture, | 36 bool user_gesture, |
| 38 const base::Callback<void(content::PermissionStatus)>& callback) override; | 37 const base::Callback<void(content::PermissionStatus)>& callback) override; |
| 38 int RequestPermissions( |
| 39 const std::vector<content::PermissionType>& permissions, |
| 40 content::RenderFrameHost* render_frame_host, |
| 41 const GURL& requesting_origin, |
| 42 bool user_gesture, |
| 43 const base::Callback<void( |
| 44 const std::vector<content::PermissionStatus>&)>& callback) override; |
| 39 void CancelPermissionRequest(int request_id) override; | 45 void CancelPermissionRequest(int request_id) override; |
| 40 void ResetPermission(content::PermissionType permission, | 46 void ResetPermission(content::PermissionType permission, |
| 41 const GURL& requesting_origin, | 47 const GURL& requesting_origin, |
| 42 const GURL& embedding_origin) override; | 48 const GURL& embedding_origin) override; |
| 43 content::PermissionStatus GetPermissionStatus( | 49 content::PermissionStatus GetPermissionStatus( |
| 44 content::PermissionType permission, | 50 content::PermissionType permission, |
| 45 const GURL& requesting_origin, | 51 const GURL& requesting_origin, |
| 46 const GURL& embedding_origin) override; | 52 const GURL& embedding_origin) override; |
| 47 void RegisterPermissionUsage(content::PermissionType permission, | 53 void RegisterPermissionUsage(content::PermissionType permission, |
| 48 const GURL& requesting_origin, | 54 const GURL& requesting_origin, |
| 49 const GURL& embedding_origin) override; | 55 const GURL& embedding_origin) override; |
| 50 int SubscribePermissionStatusChange( | 56 int SubscribePermissionStatusChange( |
| 51 content::PermissionType permission, | 57 content::PermissionType permission, |
| 52 const GURL& requesting_origin, | 58 const GURL& requesting_origin, |
| 53 const GURL& embedding_origin, | 59 const GURL& embedding_origin, |
| 54 const base::Callback<void(content::PermissionStatus)>& callback) override; | 60 const base::Callback<void(content::PermissionStatus)>& callback) override; |
| 55 void UnsubscribePermissionStatusChange(int subscription_id) override; | 61 void UnsubscribePermissionStatusChange(int subscription_id) override; |
| 56 | 62 |
| 57 private: | 63 private: |
| 58 struct PendingRequest; | 64 class PendingRequest; |
| 59 using PendingRequestsMap = IDMap<PendingRequest, IDMapOwnPointer>; | 65 using PendingRequestsMap = IDMap<PendingRequest, IDMapOwnPointer>; |
| 60 | 66 |
| 61 struct Subscription; | 67 struct Subscription; |
| 62 using SubscriptionsMap = IDMap<Subscription, IDMapOwnPointer>; | 68 using SubscriptionsMap = IDMap<Subscription, IDMapOwnPointer>; |
| 63 | 69 |
| 64 void OnPermissionRequestResponse( | 70 // Called when a permission was decided for a given PendingRequest. The |
| 71 // PendingRequest is identified by its |request_id| and the permission is |
| 72 // identified by its |permission_id|. If the PendingRequest contains more than |
| 73 // one permission, it will wait for the remaining permissions to be resolved. |
| 74 // When all the permissions have been resolved, the PendingRequest's callback |
| 75 // is run. |
| 76 void OnPermissionsRequestResponseStatus( |
| 65 int request_id, | 77 int request_id, |
| 66 const base::Callback<void(content::PermissionStatus)>& callback, | 78 int permission_id, |
| 67 ContentSetting content_setting); | 79 content::PermissionStatus status); |
| 68 | 80 |
| 69 // Not all WebContents are able to display permission requests. If the PBM | 81 // Not all WebContents are able to display permission requests. If the PBM |
| 70 // is required but missing for |web_contents|, don't pass along the request. | 82 // is required but missing for |web_contents|, don't pass along the request. |
| 71 bool IsPermissionBubbleManagerMissing(content::WebContents* web_contents); | 83 bool IsPermissionBubbleManagerMissing(content::WebContents* web_contents); |
| 72 | 84 |
| 73 // content_settings::Observer implementation. | 85 // content_settings::Observer implementation. |
| 74 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, | 86 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, |
| 75 const ContentSettingsPattern& secondary_pattern, | 87 const ContentSettingsPattern& secondary_pattern, |
| 76 ContentSettingsType content_type, | 88 ContentSettingsType content_type, |
| 77 std::string resource_identifier) override; | 89 std::string resource_identifier) override; |
| 78 | 90 |
| 79 Profile* profile_; | 91 Profile* profile_; |
| 80 PendingRequestsMap pending_requests_; | 92 PendingRequestsMap pending_requests_; |
| 81 SubscriptionsMap subscriptions_; | 93 SubscriptionsMap subscriptions_; |
| 82 | 94 |
| 83 base::WeakPtrFactory<PermissionManager> weak_ptr_factory_; | 95 base::WeakPtrFactory<PermissionManager> weak_ptr_factory_; |
| 84 | 96 |
| 85 DISALLOW_COPY_AND_ASSIGN(PermissionManager); | 97 DISALLOW_COPY_AND_ASSIGN(PermissionManager); |
| 86 }; | 98 }; |
| 87 | 99 |
| 88 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ | 100 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ |
| OLD | NEW |