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 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.android_webview.permission
27 VideoCapture
= 1 << 1,
28 AudioCapture
= 1 << 2,
29 ProtectedMediaId
= 1 << 3,
33 // Take the ownership of |delegate|. Returns the native pointer in
34 // |weak_ptr|, which is owned by the returned java peer.
35 static base::android::ScopedJavaLocalRef
<jobject
> Create(
36 scoped_ptr
<AwPermissionRequestDelegate
> delegate
,
37 base::WeakPtr
<AwPermissionRequest
>* weak_ptr
);
39 // Return the Java peer. Must be null-checked.
40 base::android::ScopedJavaLocalRef
<jobject
> GetJavaObject();
42 // Invoked by Java peer when request is processed, |granted| indicates the
43 // request was granted or not.
44 void OnAccept(JNIEnv
* env
, jobject jcaller
, jboolean granted
);
45 void Destroy(JNIEnv
* env
, jobject obj
);
47 // Return the origin which initiated the request.
48 const GURL
& GetOrigin();
50 // Return the resources origin requested.
53 // Cancel this request. Guarantee that
54 // AwPermissionRequestDelegate::NotifyRequestResult will not be called after
55 // this call. This also deletes this object, so weak pointers are invalidated
56 // and raw pointers become dangling pointers.
57 void CancelAndDelete();
60 AwPermissionRequest(scoped_ptr
<AwPermissionRequestDelegate
> delegate
,
61 base::android::ScopedJavaLocalRef
<jobject
>* java_peer
);
62 ~AwPermissionRequest();
64 void OnAcceptInternal(bool accept
);
67 scoped_ptr
<AwPermissionRequestDelegate
> delegate_
;
68 JavaObjectWeakGlobalRef java_ref_
;
71 base::WeakPtrFactory
<AwPermissionRequest
> weak_factory_
;
73 DISALLOW_COPY_AND_ASSIGN(AwPermissionRequest
);
76 bool RegisterAwPermissionRequest(JNIEnv
* env
);
78 } // namespace android_webivew
80 #endif // ANDROID_WEBVIEW_NATIVE_PERMISSION_AW_PERMISSION_REQUEST_H