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 ANDROID_WEBVIEW_BROWSER_AW_PERMISSION_MANAGER_H_ | 5 #ifndef ANDROID_WEBVIEW_BROWSER_AW_PERMISSION_MANAGER_H_ |
6 #define ANDROID_WEBVIEW_BROWSER_AW_PERMISSION_MANAGER_H_ | 6 #define ANDROID_WEBVIEW_BROWSER_AW_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/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "content/public/browser/permission_manager.h" | 13 #include "content/public/browser/permission_manager.h" |
14 | 14 |
15 namespace android_webview { | 15 namespace android_webview { |
16 | 16 |
17 class LastRequestResultCache; | 17 class LastRequestResultCache; |
18 | 18 |
19 class AwPermissionManager : public content::PermissionManager { | 19 class AwPermissionManager : public content::PermissionManager { |
20 public: | 20 public: |
21 AwPermissionManager(); | 21 AwPermissionManager(); |
22 ~AwPermissionManager() override; | 22 ~AwPermissionManager() override; |
23 | 23 |
24 // PermissionManager implementation. | 24 // PermissionManager implementation. |
25 int RequestPermission( | 25 int RequestPermission( |
26 content::PermissionType permission, | 26 content::PermissionType permission, |
27 content::RenderFrameHost* render_frame_host, | 27 content::RenderFrameHost* render_frame_host, |
28 const GURL& requesting_origin, | 28 const GURL& requesting_origin, |
29 bool user_gesture, | 29 bool user_gesture, |
30 const base::Callback<void(content::PermissionStatus)>& callback) override; | 30 const base::Callback<void(permission::Status)>& callback) override; |
31 void CancelPermissionRequest(int request_id) override; | 31 void CancelPermissionRequest(int request_id) override; |
32 void ResetPermission(content::PermissionType permission, | 32 void ResetPermission(content::PermissionType permission, |
33 const GURL& requesting_origin, | 33 const GURL& requesting_origin, |
34 const GURL& embedding_origin) override; | 34 const GURL& embedding_origin) override; |
35 content::PermissionStatus GetPermissionStatus( | 35 permission::Status GetPermissionStatus(content::PermissionType permission, |
36 content::PermissionType permission, | 36 const GURL& requesting_origin, |
37 const GURL& requesting_origin, | 37 const GURL& embedding_origin) override; |
38 const GURL& embedding_origin) override; | |
39 void RegisterPermissionUsage(content::PermissionType permission, | 38 void RegisterPermissionUsage(content::PermissionType permission, |
40 const GURL& requesting_origin, | 39 const GURL& requesting_origin, |
41 const GURL& embedding_origin) override; | 40 const GURL& embedding_origin) override; |
42 int SubscribePermissionStatusChange( | 41 int SubscribePermissionStatusChange( |
43 content::PermissionType permission, | 42 content::PermissionType permission, |
44 const GURL& requesting_origin, | 43 const GURL& requesting_origin, |
45 const GURL& embedding_origin, | 44 const GURL& embedding_origin, |
46 const base::Callback<void(content::PermissionStatus)>& callback) override; | 45 const base::Callback<void(permission::Status)>& callback) override; |
47 void UnsubscribePermissionStatusChange(int subscription_id) override; | 46 void UnsubscribePermissionStatusChange(int subscription_id) override; |
48 | 47 |
49 private: | 48 private: |
50 struct PendingRequest; | 49 struct PendingRequest; |
51 using PendingRequestsMap = IDMap<PendingRequest, IDMapOwnPointer>; | 50 using PendingRequestsMap = IDMap<PendingRequest, IDMapOwnPointer>; |
52 | 51 |
53 // The weak pointer to this is used to clean up any information which is | 52 // The weak pointer to this is used to clean up any information which is |
54 // stored in the pending request or result cache maps. However, the callback | 53 // stored in the pending request or result cache maps. However, the callback |
55 // should be run regardless of whether the class is still alive so the method | 54 // should be run regardless of whether the class is still alive so the method |
56 // is static. | 55 // is static. |
57 static void OnRequestResponse( | 56 static void OnRequestResponse( |
58 const base::WeakPtr<AwPermissionManager>& manager, | 57 const base::WeakPtr<AwPermissionManager>& manager, |
59 int request_id, | 58 int request_id, |
60 const base::Callback<void(content::PermissionStatus)>& callback, | 59 const base::Callback<void(permission::Status)>& callback, |
61 bool allowed); | 60 bool allowed); |
62 | 61 |
63 PendingRequestsMap pending_requests_; | 62 PendingRequestsMap pending_requests_; |
64 scoped_ptr<LastRequestResultCache> result_cache_; | 63 scoped_ptr<LastRequestResultCache> result_cache_; |
65 | 64 |
66 base::WeakPtrFactory<AwPermissionManager> weak_ptr_factory_; | 65 base::WeakPtrFactory<AwPermissionManager> weak_ptr_factory_; |
67 | 66 |
68 DISALLOW_COPY_AND_ASSIGN(AwPermissionManager); | 67 DISALLOW_COPY_AND_ASSIGN(AwPermissionManager); |
69 }; | 68 }; |
70 | 69 |
71 } // namespace android_webview | 70 } // namespace android_webview |
72 | 71 |
73 #endif // ANDROID_WEBVIEW_BROWSER_AW_PERMISSION_MANAGER_H_ | 72 #endif // ANDROID_WEBVIEW_BROWSER_AW_PERMISSION_MANAGER_H_ |
OLD | NEW |