| 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(content::RenderFrameHost* render_frame_host, |
| 39 content::RenderFrameHost* render_frame_host, | 40 int request_id) override; |
| 40 int request_id, | |
| 41 const GURL& requesting_origin) override; | |
| 42 void ResetPermission(content::PermissionType permission, | 41 void ResetPermission(content::PermissionType permission, |
| 43 const GURL& requesting_origin, | 42 const GURL& requesting_origin, |
| 44 const GURL& embedding_origin) override; | 43 const GURL& embedding_origin) override; |
| 45 content::PermissionStatus GetPermissionStatus( | 44 content::PermissionStatus GetPermissionStatus( |
| 46 content::PermissionType permission, | 45 content::PermissionType permission, |
| 47 const GURL& requesting_origin, | 46 const GURL& requesting_origin, |
| 48 const GURL& embedding_origin) override; | 47 const GURL& embedding_origin) override; |
| 49 void RegisterPermissionUsage(content::PermissionType permission, | 48 void RegisterPermissionUsage(content::PermissionType permission, |
| 50 const GURL& requesting_origin, | 49 const GURL& requesting_origin, |
| 51 const GURL& embedding_origin) override; | 50 const GURL& embedding_origin) override; |
| 52 int SubscribePermissionStatusChange( | 51 int SubscribePermissionStatusChange( |
| 53 content::PermissionType permission, | 52 content::PermissionType permission, |
| 54 const GURL& requesting_origin, | 53 const GURL& requesting_origin, |
| 55 const GURL& embedding_origin, | 54 const GURL& embedding_origin, |
| 56 const base::Callback<void(content::PermissionStatus)>& callback) override; | 55 const base::Callback<void(content::PermissionStatus)>& callback) override; |
| 57 void UnsubscribePermissionStatusChange(int subscription_id) override; | 56 void UnsubscribePermissionStatusChange(int subscription_id) override; |
| 58 | 57 |
| 59 private: | 58 private: |
| 59 struct PendingRequest; |
| 60 using PendingRequestsMap = IDMap<PendingRequest, IDMapOwnPointer>; |
| 61 |
| 60 struct Subscription; | 62 struct Subscription; |
| 61 using SubscriptionsMap = IDMap<Subscription, IDMapOwnPointer>; | 63 using SubscriptionsMap = IDMap<Subscription, IDMapOwnPointer>; |
| 62 | 64 |
| 65 void OnPermissionRequestResponse( |
| 66 int request_id, |
| 67 const base::Callback<void(content::PermissionStatus)>& callback, |
| 68 ContentSetting content_setting); |
| 69 |
| 63 // Not all WebContents are able to display permission requests. If the PBM | 70 // 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. | 71 // is required but missing for |web_contents|, don't pass along the request. |
| 65 bool IsPermissionBubbleManagerMissing(content::WebContents* web_contents); | 72 bool IsPermissionBubbleManagerMissing(content::WebContents* web_contents); |
| 66 | 73 |
| 67 // content_settings::Observer implementation. | 74 // content_settings::Observer implementation. |
| 68 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, | 75 void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern, |
| 69 const ContentSettingsPattern& secondary_pattern, | 76 const ContentSettingsPattern& secondary_pattern, |
| 70 ContentSettingsType content_type, | 77 ContentSettingsType content_type, |
| 71 std::string resource_identifier) override; | 78 std::string resource_identifier) override; |
| 72 | 79 |
| 73 Profile* profile_; | 80 Profile* profile_; |
| 81 PendingRequestsMap pending_requests_; |
| 74 SubscriptionsMap subscriptions_; | 82 SubscriptionsMap subscriptions_; |
| 75 | 83 |
| 84 base::WeakPtrFactory<PermissionManager> weak_ptr_factory_; |
| 85 |
| 76 DISALLOW_COPY_AND_ASSIGN(PermissionManager); | 86 DISALLOW_COPY_AND_ASSIGN(PermissionManager); |
| 77 }; | 87 }; |
| 78 | 88 |
| 79 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ | 89 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_MANAGER_H_ |
| OLD | NEW |