cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / android_webview / native / permission / aw_permission_request.cc
blobf25db3e03aeff8c559d7881a7527ebaafc1166f5
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::ScopedJavaLocalRef;
15 namespace android_webview {
17 // static
18 base::android::ScopedJavaLocalRef<jobject> AwPermissionRequest::Create(
19 scoped_ptr<AwPermissionRequestDelegate> delegate,
20 base::WeakPtr<AwPermissionRequest>* weak_ptr) {
21 base::android::ScopedJavaLocalRef<jobject> java_peer;
22 AwPermissionRequest* permission_request =
23 new AwPermissionRequest(delegate.Pass(), &java_peer);
24 *weak_ptr = permission_request->weak_factory_.GetWeakPtr();
25 return java_peer;
28 AwPermissionRequest::AwPermissionRequest(
29 scoped_ptr<AwPermissionRequestDelegate> delegate,
30 ScopedJavaLocalRef<jobject>* java_peer)
31 : delegate_(delegate.Pass()),
32 processed_(false),
33 weak_factory_(this) {
34 DCHECK(delegate_.get());
35 DCHECK(java_peer);
37 JNIEnv* env = AttachCurrentThread();
38 *java_peer = Java_AwPermissionRequest_create(
39 env, reinterpret_cast<jlong>(this),
40 ConvertUTF8ToJavaString(env, GetOrigin().spec()).obj(), GetResources());
41 java_ref_ = JavaObjectWeakGlobalRef(env, java_peer->obj());
44 AwPermissionRequest::~AwPermissionRequest() {
45 OnAcceptInternal(false);
48 void AwPermissionRequest::OnAccept(JNIEnv* env,
49 jobject jcaller,
50 jboolean accept) {
51 OnAcceptInternal(accept);
54 void AwPermissionRequest::OnAcceptInternal(bool accept) {
55 if (!processed_) {
56 delegate_->NotifyRequestResult(accept);
57 processed_ = true;
61 void AwPermissionRequest::DeleteThis() {
62 ScopedJavaLocalRef<jobject> j_request = GetJavaObject();
63 if (j_request.is_null())
64 return;
65 Java_AwPermissionRequest_destroyNative(AttachCurrentThread(),
66 j_request.obj());
69 void AwPermissionRequest::Destroy(JNIEnv* env, jobject obj) {
70 delete this;
73 ScopedJavaLocalRef<jobject> AwPermissionRequest::GetJavaObject() {
74 return java_ref_.get(AttachCurrentThread());
77 const GURL& AwPermissionRequest::GetOrigin() {
78 return delegate_->GetOrigin();
81 int64 AwPermissionRequest::GetResources() {
82 return delegate_->GetResources();
85 void AwPermissionRequest::CancelAndDelete() {
86 processed_ = true;
87 DeleteThis();
90 bool RegisterAwPermissionRequest(JNIEnv* env) {
91 return RegisterNativesImpl(env);
94 } // namespace android_webivew