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.
5 #ifndef ANDROID_WEBVIEW_NATIVE_PERMISSION_AW_PERMISSION_REQUEST_H
6 #define ANDROID_WEBVIEW_NATIVE_PERMISSION_AW_PERMISSION_REQUEST_H
8 #include "base/android/jni_weak_ref.h"
9 #include "base/android/scoped_java_ref.h"
10 #include "base/memory/weak_ptr.h"
13 namespace android_webview
{
15 class AwPermissionRequestDelegate
;
17 // This class wraps a permission request, it works with PermissionRequestHandler
18 // and its' Java peer to represent the request to AwContentsClient.
19 // The specific permission request should implement the
20 // AwPermissionRequestDelegate interface, See MediaPermissionRequest.
21 // This object is owned by the java peer.
22 class AwPermissionRequest
{
24 // The definition must synced with
25 // com.android.webview.chromium.WebViewContentsClientAdapter.
28 VideoCapture
= 1 << 1,
29 AudioCapture
= 1 << 2,
30 ProtectedMediaId
= 1 << 3,
34 // Take the ownership of |delegate|. Returns the native pointer in
35 // |weak_ptr|, which is owned by the returned java peer.
36 static base::android::ScopedJavaLocalRef
<jobject
> Create(
37 scoped_ptr
<AwPermissionRequestDelegate
> delegate
,
38 base::WeakPtr
<AwPermissionRequest
>* weak_ptr
);
40 // Return the Java peer. Must be null-checked.
41 base::android::ScopedJavaLocalRef
<jobject
> GetJavaObject();
43 // Invoked by Java peer when request is processed, |granted| indicates the
44 // request was granted or not.
45 void OnAccept(JNIEnv
* env
, jobject jcaller
, jboolean granted
);
46 void Destroy(JNIEnv
* env
, jobject obj
);
48 // Return the origin which initiated the request.
49 const GURL
& GetOrigin();
51 // Return the resources origin requested.
54 // Cancel this request. Guarantee that
55 // AwPermissionRequestDelegate::NotifyRequestResult will not be called after
56 // this call. This also deletes this object, so weak pointers are invalidated
57 // and raw pointers become dangling pointers.
58 void CancelAndDelete();
61 AwPermissionRequest(scoped_ptr
<AwPermissionRequestDelegate
> delegate
,
62 base::android::ScopedJavaLocalRef
<jobject
>* java_peer
);
63 ~AwPermissionRequest();
65 void OnAcceptInternal(bool accept
);
68 scoped_ptr
<AwPermissionRequestDelegate
> delegate_
;
69 JavaObjectWeakGlobalRef java_ref_
;
72 base::WeakPtrFactory
<AwPermissionRequest
> weak_factory_
;
74 DISALLOW_COPY_AND_ASSIGN(AwPermissionRequest
);
77 bool RegisterAwPermissionRequest(JNIEnv
* env
);
79 } // namespace android_webivew
81 #endif // ANDROID_WEBVIEW_NATIVE_PERMISSION_AW_PERMISSION_REQUEST_H