• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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"
12 
13 namespace android_webview {
14 
15 class AwPermissionRequestDelegate;
16 
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 class AwPermissionRequest {
22  public:
23   // The definition must synced with Android's
24   // android.webkit.PermissionRequest.
25   enum Resource {
26     Geolocation = 1 << 0,
27     VideoCapture = 1 << 1,
28     AudioCapture = 1 << 2,
29     ProtectedMediaId = 1 << 3,
30   };
31 
32   // Take the ownership of |delegate|.
33   AwPermissionRequest(scoped_ptr<AwPermissionRequestDelegate> delegate);
34   virtual ~AwPermissionRequest();
35 
GetWeakPtr()36   base::WeakPtr<AwPermissionRequest> GetWeakPtr() {
37     return weak_factory_.GetWeakPtr();
38   }
39 
40   // Create and return Java peer.
41   base::android::ScopedJavaLocalRef<jobject> CreateJavaPeer();
42 
43   // Return the Java peer.
44   base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
45 
46   // Invoked by Java peer when request is processed, |granted| indicates the
47   // request was granted or not.
48   void OnAccept(JNIEnv* env, jobject jcaller, jboolean granted);
49 
50   // Return the origin which initiated the request.
51   const GURL& GetOrigin();
52 
53   // Return the resources origin requested.
54   int64 GetResources();
55 
56  private:
57   friend class TestAwPermissionRequest;
58 
59   scoped_ptr<AwPermissionRequestDelegate> delegate_;
60   JavaObjectWeakGlobalRef java_ref_;
61 
62   base::WeakPtrFactory<AwPermissionRequest> weak_factory_;
63 
64   DISALLOW_COPY_AND_ASSIGN(AwPermissionRequest);
65 };
66 
67 bool RegisterAwPermissionRequest(JNIEnv* env);
68 
69 }  // namespace android_webivew
70 
71 #endif  // ANDROID_WEBVIEW_NATIVE_PERMISSION_AW_PERMISSION_REQUEST_H
72