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 ANDROID_WEBVIEW_NATIVE_PERMISSION_AW_PERMISSION_REQUEST_H | |
6 #define ANDROID_WEBVIEW_NATIVE_PERMISSION_AW_PERMISSION_REQUEST_H | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include "base/android/jni_weak_ref.h" | |
11 #include "base/android/scoped_java_ref.h" | |
12 #include "base/macros.h" | |
13 #include "base/memory/weak_ptr.h" | |
14 #include "url/gurl.h" | |
15 | |
16 namespace android_webview { | |
17 | |
18 class AwPermissionRequestDelegate; | |
19 | |
20 // This class wraps a permission request, it works with PermissionRequestHandler | |
21 // and its' Java peer to represent the request to AwContentsClient. | |
22 // The specific permission request should implement the | |
23 // AwPermissionRequestDelegate interface, See MediaPermissionRequest. | |
24 // This object is owned by the java peer. | |
25 class AwPermissionRequest { | |
26 public: | |
27 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.android_webview.permission | |
28 enum Resource { | |
29 Geolocation = 1 << 0, | |
30 VideoCapture = 1 << 1, | |
31 AudioCapture = 1 << 2, | |
32 ProtectedMediaId = 1 << 3, | |
33 MIDISysex = 1 << 4, | |
34 }; | |
35 | |
36 // Take the ownership of |delegate|. Returns the native pointer in | |
37 // |weak_ptr|, which is owned by the returned java peer. | |
38 static base::android::ScopedJavaLocalRef<jobject> Create( | |
39 std::unique_ptr<AwPermissionRequestDelegate> delegate, | |
40 base::WeakPtr<AwPermissionRequest>* weak_ptr); | |
41 | |
42 // Return the Java peer. Must be null-checked. | |
43 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(); | |
44 | |
45 // Invoked by Java peer when request is processed, |granted| indicates the | |
46 // request was granted or not. | |
47 void OnAccept(JNIEnv* env, | |
48 const base::android::JavaParamRef<jobject>& jcaller, | |
49 jboolean granted); | |
50 void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); | |
51 | |
52 // Return the origin which initiated the request. | |
53 const GURL& GetOrigin(); | |
54 | |
55 // Return the resources origin requested. | |
56 int64_t GetResources(); | |
57 | |
58 // Cancel this request. Guarantee that | |
59 // AwPermissionRequestDelegate::NotifyRequestResult will not be called after | |
60 // this call. This also deletes this object, so weak pointers are invalidated | |
61 // and raw pointers become dangling pointers. | |
62 void CancelAndDelete(); | |
63 | |
64 private: | |
65 friend class TestPermissionRequestHandlerClient; | |
66 | |
67 AwPermissionRequest(std::unique_ptr<AwPermissionRequestDelegate> delegate, | |
68 base::android::ScopedJavaLocalRef<jobject>* java_peer); | |
69 ~AwPermissionRequest(); | |
70 | |
71 void OnAcceptInternal(bool accept); | |
72 void DeleteThis(); | |
73 | |
74 std::unique_ptr<AwPermissionRequestDelegate> delegate_; | |
75 JavaObjectWeakGlobalRef java_ref_; | |
76 | |
77 bool processed_; | |
78 base::WeakPtrFactory<AwPermissionRequest> weak_factory_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(AwPermissionRequest); | |
81 }; | |
82 | |
83 bool RegisterAwPermissionRequest(JNIEnv* env); | |
84 | |
85 } // namespace android_webivew | |
86 | |
87 #endif // ANDROID_WEBVIEW_NATIVE_PERMISSION_AW_PERMISSION_REQUEST_H | |
OLD | NEW |