OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ |
| 6 #define CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ |
| 7 |
| 8 #include "base/id_map.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "content/browser/permissions/permission_service_context.h" |
| 12 #include "content/common/permission_service.mojom.h" |
| 13 #include "content/public/browser/permission_type.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 // Implements the PermissionService Mojo interface. |
| 18 // This service can be created from a RenderFrameHost or a RenderProcessHost. |
| 19 // It receives at PermissionContext instance when created (that it then owns) |
| 20 // which allows it to have some information about the current context. That |
| 21 // allows the service to know whether it can show UI and have knowledge of the |
| 22 // associated WebContents for example. |
| 23 class PermissionServiceImpl : public mojo::InterfaceImpl<PermissionService> { |
| 24 public: |
| 25 virtual ~PermissionServiceImpl(); |
| 26 |
| 27 // Clear pending permissions associated with a given frame and request the |
| 28 // browser to cancel the permission requests. |
| 29 void CancelPendingRequests(); |
| 30 |
| 31 protected: |
| 32 friend PermissionServiceContext; |
| 33 |
| 34 PermissionServiceImpl(PermissionServiceContext* context); |
| 35 |
| 36 private: |
| 37 struct PendingRequest { |
| 38 PendingRequest(PermissionType permission, const GURL& origin); |
| 39 PermissionType permission; |
| 40 GURL origin; |
| 41 }; |
| 42 typedef IDMap<PendingRequest, IDMapOwnPointer> RequestsMap; |
| 43 |
| 44 // PermissionService. |
| 45 void QueryPermission( |
| 46 PermissionName permission, |
| 47 const mojo::String& origin, |
| 48 const mojo::Callback<void(PermissionStatus)>& callback) override; |
| 49 void RequestPermission( |
| 50 PermissionName permission, |
| 51 const mojo::String& origin, |
| 52 const mojo::Callback<void(PermissionStatus)>& callback) override; |
| 53 |
| 54 // mojo::InterfaceImpl. |
| 55 void OnConnectionError() override; |
| 56 |
| 57 void OnRequestPermissionResponse( |
| 58 const mojo::Callback<void(PermissionStatus)>& callback, |
| 59 int request_id, |
| 60 bool allowed); |
| 61 |
| 62 RequestsMap pending_requests_; |
| 63 PermissionServiceContext* context_; |
| 64 base::WeakPtrFactory<PermissionServiceImpl> weak_factory_; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(PermissionServiceImpl); |
| 67 }; |
| 68 |
| 69 } // namespace content |
| 70 |
| 71 #endif // CONTENT_BROWSER_PERMISSIONS_PERMISSION_SERVICE_IMPL_H_ |
OLD | NEW |