1 // Copyright (c) 2012 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 "content/browser/android/interstitial_page_delegate_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h"
10 #include "content/public/browser/interstitial_page.h"
11 #include "jni/InterstitialPageDelegateAndroid_jni.h"
13 using base::android::AttachCurrentThread
;
14 using base::android::ScopedJavaLocalRef
;
18 InterstitialPageDelegateAndroid::InterstitialPageDelegateAndroid(
21 const std::string
& html_content
)
22 : weak_java_obj_(env
, obj
),
23 html_content_(html_content
),
27 InterstitialPageDelegateAndroid::~InterstitialPageDelegateAndroid() {
28 JNIEnv
* env
= AttachCurrentThread();
29 ScopedJavaLocalRef
<jobject
> obj
= weak_java_obj_
.get(env
);
31 Java_InterstitialPageDelegateAndroid_onNativeDestroyed(env
, obj
.obj());
34 void InterstitialPageDelegateAndroid::Proceed(JNIEnv
* env
, jobject obj
) {
39 void InterstitialPageDelegateAndroid::DontProceed(JNIEnv
* env
,
45 std::string
InterstitialPageDelegateAndroid::GetHTMLContents() {
49 void InterstitialPageDelegateAndroid::OnProceed() {
50 JNIEnv
* env
= AttachCurrentThread();
51 ScopedJavaLocalRef
<jobject
> obj
= weak_java_obj_
.get(env
);
53 Java_InterstitialPageDelegateAndroid_onProceed(env
, obj
.obj());
56 void InterstitialPageDelegateAndroid::OnDontProceed() {
57 JNIEnv
* env
= AttachCurrentThread();
58 ScopedJavaLocalRef
<jobject
> obj
= weak_java_obj_
.get(env
);
60 Java_InterstitialPageDelegateAndroid_onDontProceed(env
, obj
.obj());
63 void InterstitialPageDelegateAndroid::CommandReceived(
64 const std::string
& command
) {
65 JNIEnv
* env
= AttachCurrentThread();
66 ScopedJavaLocalRef
<jobject
> obj
= weak_java_obj_
.get(env
);
68 std::string
sanitized_command(command
);
69 // The JSONified response has quotes, remove them.
70 if (sanitized_command
.length() > 1 && sanitized_command
[0] == '"') {
71 sanitized_command
= sanitized_command
.substr(
72 1, sanitized_command
.length() - 2);
75 Java_InterstitialPageDelegateAndroid_commandReceived(
77 base::android::ConvertUTF8ToJavaString(env
, sanitized_command
).obj());
82 bool InterstitialPageDelegateAndroid
83 ::RegisterInterstitialPageDelegateAndroid(JNIEnv
* env
) {
84 return RegisterNativesImpl(env
);
87 static jlong
Init(JNIEnv
* env
, jobject obj
, jstring html_content
) {
88 InterstitialPageDelegateAndroid
* delegate
=
89 new InterstitialPageDelegateAndroid(
90 env
, obj
, base::android::ConvertJavaStringToUTF8(env
, html_content
));
91 return reinterpret_cast<intptr_t>(delegate
);
94 } // namespace content