| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ |
| 6 #define CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ | 6 #define CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/id_map.h" | 8 #include "base/id_map.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "content/browser/permissions/permission_service_context.h" | 11 #include "content/browser/permissions/permission_service_context.h" |
| 12 #include "content/common/permission_service.mojom.h" | 12 #include "content/common/permission_service.mojom.h" |
| 13 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" | 13 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 class PermissionPendingRequest; |
| 17 enum class PermissionType; | 18 enum class PermissionType; |
| 18 | 19 |
| 19 // Implements the PermissionService Mojo interface. | 20 // Implements the PermissionService Mojo interface. |
| 20 // This service can be created from a RenderFrameHost or a RenderProcessHost. | 21 // This service can be created from a RenderFrameHost or a RenderProcessHost. |
| 21 // It is owned by a PermissionServiceContext. | 22 // It is owned by a PermissionServiceContext. |
| 22 // It receives at PermissionServiceContext instance when created which allows it | 23 // It receives at PermissionServiceContext instance when created which allows it |
| 23 // to have some information about the current context. That enables the service | 24 // to have some information about the current context. That enables the service |
| 24 // to know whether it can show UI and have knowledge of the associated | 25 // to know whether it can show UI and have knowledge of the associated |
| 25 // WebContents for example. | 26 // WebContents for example. |
| 26 class PermissionServiceImpl : public PermissionService { | 27 class PermissionServiceImpl : public PermissionService { |
| 27 public: | 28 public: |
| 28 ~PermissionServiceImpl() override; | 29 ~PermissionServiceImpl() override; |
| 29 | |
| 30 // Clear pending operations currently run by the service. This will be called | 30 // Clear pending operations currently run by the service. This will be called |
| 31 // by PermissionServiceContext when it will need the service to clear its | 31 // by PermissionServiceContext when it will need the service to clear its |
| 32 // state for example, if the frame changes. | 32 // state for example, if the frame changes. |
| 33 void CancelPendingOperations(); | 33 void CancelPendingOperations(); |
| 34 | 34 |
| 35 protected: | 35 protected: |
| 36 friend PermissionServiceContext; | 36 friend PermissionServiceContext; |
| 37 | 37 |
| 38 PermissionServiceImpl(PermissionServiceContext* context, | 38 PermissionServiceImpl(PermissionServiceContext* context, |
| 39 mojo::InterfaceRequest<PermissionService> request); | 39 mojo::InterfaceRequest<PermissionService> request); |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 using PermissionStatusCallback = mojo::Callback<void(PermissionStatus)>; | 42 using PermissionStatusCallback = mojo::Callback<void(PermissionStatus)>; |
| 43 using BatchPermissionStatusCallback = |
| 44 mojo::Callback<void(mojo::Array<PermissionStatus>)>; |
| 43 | 45 |
| 44 struct PendingRequest { | 46 using RequestsMap = IDMap<PermissionPendingRequest, IDMapOwnPointer>; |
| 45 PendingRequest(PermissionType permission, const GURL& origin, | |
| 46 const PermissionStatusCallback& callback); | |
| 47 ~PendingRequest(); | |
| 48 | |
| 49 PermissionType permission; | |
| 50 GURL origin; | |
| 51 PermissionStatusCallback callback; | |
| 52 }; | |
| 53 using RequestsMap = IDMap<PendingRequest, IDMapOwnPointer>; | |
| 54 | 47 |
| 55 struct PendingSubscription { | 48 struct PendingSubscription { |
| 56 PendingSubscription(PermissionType permission, const GURL& origin, | 49 PendingSubscription(PermissionType permission, const GURL& origin, |
| 57 const PermissionStatusCallback& callback); | 50 const PermissionStatusCallback& callback); |
| 58 ~PendingSubscription(); | 51 ~PendingSubscription(); |
| 59 | 52 |
| 60 // Subscription ID received from the PermissionManager. | 53 // Subscription ID received from the PermissionManager. |
| 61 int id; | 54 int id; |
| 62 PermissionType permission; | 55 PermissionType permission; |
| 63 GURL origin; | 56 GURL origin; |
| 64 PermissionStatusCallback callback; | 57 PermissionStatusCallback callback; |
| 65 }; | 58 }; |
| 66 using SubscriptionsMap = IDMap<PendingSubscription, IDMapOwnPointer>; | 59 using SubscriptionsMap = IDMap<PendingSubscription, IDMapOwnPointer>; |
| 67 | 60 |
| 68 // PermissionService. | 61 // PermissionService. |
| 69 void HasPermission(PermissionName permission, | 62 void HasPermission(PermissionName permission, |
| 70 const mojo::String& origin, | 63 const mojo::String& origin, |
| 71 const PermissionStatusCallback& callback) override; | 64 const PermissionStatusCallback& callback) override; |
| 72 void RequestPermission(PermissionName permission, | 65 void RequestPermission(PermissionName permission, |
| 73 const mojo::String& origin, | 66 const mojo::String& origin, |
| 74 bool user_gesture, | 67 bool user_gesture, |
| 75 const PermissionStatusCallback& callback) override; | 68 const PermissionStatusCallback& callback) override; |
| 69 void RequestBatchPermission( |
| 70 mojo::Array<PermissionName> permissions, |
| 71 const mojo::String& origin, |
| 72 bool user_gesture, |
| 73 const BatchPermissionStatusCallback& callback) override; |
| 76 void RevokePermission(PermissionName permission, | 74 void RevokePermission(PermissionName permission, |
| 77 const mojo::String& origin, | 75 const mojo::String& origin, |
| 78 const PermissionStatusCallback& callback) override; | 76 const PermissionStatusCallback& callback) override; |
| 79 void GetNextPermissionChange( | 77 void GetNextPermissionChange( |
| 80 PermissionName permission, | 78 PermissionName permission, |
| 81 const mojo::String& origin, | 79 const mojo::String& origin, |
| 82 PermissionStatus last_known_status, | 80 PermissionStatus last_known_status, |
| 83 const PermissionStatusCallback& callback) override; | 81 const PermissionStatusCallback& callback) override; |
| 84 | 82 |
| 85 void OnConnectionError(); | 83 void OnConnectionError(); |
| 86 | 84 |
| 87 void OnRequestPermissionResponse(int request_id, PermissionStatus status); | 85 void RequestPermissionInternal( |
| 86 mojo::Array<PermissionName> permissions, |
| 87 const mojo::String& origin, |
| 88 bool user_gesture, |
| 89 const BatchPermissionStatusCallback& callback); |
| 90 |
| 91 void OnRequestPermissionResponse(int request_id, |
| 92 const std::vector<PermissionStatus>& status); |
| 88 | 93 |
| 89 PermissionStatus GetPermissionStatusFromName(PermissionName permission, | 94 PermissionStatus GetPermissionStatusFromName(PermissionName permission, |
| 90 const GURL& origin); | 95 const GURL& origin); |
| 91 PermissionStatus GetPermissionStatusFromType(PermissionType type, | 96 PermissionStatus GetPermissionStatusFromType(PermissionType type, |
| 92 const GURL& origin); | 97 const GURL& origin); |
| 93 void ResetPermissionStatus(PermissionType type, const GURL& origin); | 98 void ResetPermissionStatus(PermissionType type, const GURL& origin); |
| 94 | 99 |
| 95 void OnPermissionStatusChanged(int pending_subscription_id, | 100 void OnPermissionStatusChanged(int pending_subscription_id, |
| 96 PermissionStatus status); | 101 PermissionStatus status); |
| 97 | 102 |
| 98 RequestsMap pending_requests_; | 103 RequestsMap pending_requests_; |
| 99 SubscriptionsMap pending_subscriptions_; | 104 SubscriptionsMap pending_subscriptions_; |
| 100 // context_ owns |this|. | 105 // context_ owns |this|. |
| 101 PermissionServiceContext* context_; | 106 PermissionServiceContext* context_; |
| 102 mojo::Binding<PermissionService> binding_; | 107 mojo::Binding<PermissionService> binding_; |
| 103 base::WeakPtrFactory<PermissionServiceImpl> weak_factory_; | 108 base::WeakPtrFactory<PermissionServiceImpl> weak_factory_; |
| 104 | 109 |
| 105 DISALLOW_COPY_AND_ASSIGN(PermissionServiceImpl); | 110 DISALLOW_COPY_AND_ASSIGN(PermissionServiceImpl); |
| 106 }; | 111 }; |
| 107 | 112 |
| 108 } // namespace content | 113 } // namespace content |
| 109 | 114 |
| 110 #endif // CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ | 115 #endif // CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ |
| OLD | NEW |