Roll src/third_party/WebKit 46ff567:25f83be (svn 200502:200512)
[chromium-blink-merge.git] / android_webview / native / permission / aw_permission_request.h
blobcd27a3700d0fce94dfb37ffd14525a66b726176a
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"
11 #include "url/gurl.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 {
23 public:
24 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.android_webview.permission
25 enum Resource {
26 Geolocation = 1 << 0,
27 VideoCapture = 1 << 1,
28 AudioCapture = 1 << 2,
29 ProtectedMediaId = 1 << 3,
30 MIDISysex = 1 << 4,
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.
51 int64 GetResources();
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();
59 private:
60 AwPermissionRequest(scoped_ptr<AwPermissionRequestDelegate> delegate,
61 base::android::ScopedJavaLocalRef<jobject>* java_peer);
62 ~AwPermissionRequest();
64 void OnAcceptInternal(bool accept);
65 void DeleteThis();
67 scoped_ptr<AwPermissionRequestDelegate> delegate_;
68 JavaObjectWeakGlobalRef java_ref_;
70 bool processed_;
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