GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / android_webview / native / permission / aw_permission_request.cc
blob41b24494cc1cdba23e6f0be2cc01cdbc3e124074
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 #include "android_webview/native/permission/aw_permission_request.h"
7 #include "android_webview/native/permission/aw_permission_request_delegate.h"
8 #include "base/android/jni_string.h"
9 #include "jni/AwPermissionRequest_jni.h"
11 using base::android::AttachCurrentThread;
12 using base::android::ConvertUTF8ToJavaString;
13 using base::android::ScopedJavaGlobalRef;
14 using base::android::ScopedJavaLocalRef;
16 namespace android_webview {
18 AwPermissionRequest::AwPermissionRequest(
19 scoped_ptr<AwPermissionRequestDelegate> delegate)
20 : delegate_(delegate.Pass()),
21 weak_factory_(this) {
22 DCHECK(delegate_.get());
25 AwPermissionRequest::~AwPermissionRequest() {
26 JNIEnv* env = AttachCurrentThread();
27 ScopedJavaLocalRef<jobject> j_object = java_ref_.get(env);
28 if (j_object.is_null())
29 return;
30 Java_AwPermissionRequest_detachNativeInstance(env, j_object.obj());
33 void AwPermissionRequest::OnAccept(JNIEnv* env,
34 jobject jcaller,
35 jboolean accept) {
36 delegate_->NotifyRequestResult(accept);
37 delete this;
40 ScopedJavaLocalRef<jobject> AwPermissionRequest::CreateJavaPeer() {
41 JNIEnv* env = AttachCurrentThread();
42 ScopedJavaLocalRef<jobject> j_object = Java_AwPermissionRequest_create(
43 env, reinterpret_cast<jlong>(this),
44 ConvertUTF8ToJavaString(env, GetOrigin().spec()).obj(), GetResources());
45 java_ref_ = JavaObjectWeakGlobalRef(env, j_object.obj());
46 return j_object;
49 ScopedJavaLocalRef<jobject> AwPermissionRequest::GetJavaObject() {
50 return java_ref_.get(AttachCurrentThread());
53 const GURL& AwPermissionRequest::GetOrigin() {
54 return delegate_->GetOrigin();
57 int64 AwPermissionRequest::GetResources() {
58 return delegate_->GetResources();
61 bool RegisterAwPermissionRequest(JNIEnv* env) {
62 return RegisterNativesImpl(env);
65 } // namespace android_webivew