summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkristianm@chromium.org <kristianm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-05 02:05:39 +0000
committerkristianm@chromium.org <kristianm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-05 02:05:39 +0000
commit44100446a3f13e5fa2ef69a0f5d342e9bf5d23f4 (patch)
tree87f4650da39d5f67907a76f331f6f775ee00e32c
parente2d81b055fbfcdaff73c52da161ce330ea25b0ab (diff)
downloadchromium_src-44100446a3f13e5fa2ef69a0f5d342e9bf5d23f4.zip
chromium_src-44100446a3f13e5fa2ef69a0f5d342e9bf5d23f4.tar.gz
chromium_src-44100446a3f13e5fa2ef69a0f5d342e9bf5d23f4.tar.bz2
Callbacks cannot be owned by Java
Would like to merge js_result_handler into aw_javascript_dialog_manager as it is not that much code, and it would mean one less global. BUG= Review URL: https://chromiumcodereview.appspot.com/12797007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192445 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--android_webview/android_webview.gyp2
-rw-r--r--android_webview/browser/aw_contents_client_bridge_base.h14
-rw-r--r--android_webview/browser/aw_javascript_dialog_manager.cc (renamed from android_webview/native/aw_javascript_dialog_manager.cc)42
-rw-r--r--android_webview/browser/aw_javascript_dialog_manager.h (renamed from android_webview/native/aw_javascript_dialog_manager.h)6
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwContents.java21
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwContentsClientBridge.java38
-rw-r--r--android_webview/java/src/org/chromium/android_webview/JsResultHandler.java41
-rw-r--r--android_webview/native/android_webview_jni_registrar.cc2
-rw-r--r--android_webview/native/aw_contents.cc56
-rw-r--r--android_webview/native/aw_contents.h13
-rw-r--r--android_webview/native/aw_contents_client_bridge.cc107
-rw-r--r--android_webview/native/aw_contents_client_bridge.h18
-rw-r--r--android_webview/native/aw_web_contents_delegate.cc2
-rw-r--r--android_webview/native/js_result_handler.cc48
-rw-r--r--android_webview/native/js_result_handler.h23
-rw-r--r--android_webview/native/webview_native.gyp5
16 files changed, 216 insertions, 222 deletions
diff --git a/android_webview/android_webview.gyp b/android_webview/android_webview.gyp
index 0ce4bd7..65f33bc 100644
--- a/android_webview/android_webview.gyp
+++ b/android_webview/android_webview.gyp
@@ -110,6 +110,8 @@
'browser/aw_download_manager_delegate.h',
'browser/aw_http_auth_handler_base.cc',
'browser/aw_http_auth_handler_base.h',
+ 'browser/aw_javascript_dialog_manager.cc',
+ 'browser/aw_javascript_dialog_manager.h',
'browser/aw_login_delegate.cc',
'browser/aw_login_delegate.h',
'browser/aw_quota_manager_bridge.cc',
diff --git a/android_webview/browser/aw_contents_client_bridge_base.h b/android_webview/browser/aw_contents_client_bridge_base.h
index de2c13a..c9ab34d 100644
--- a/android_webview/browser/aw_contents_client_bridge_base.h
+++ b/android_webview/browser/aw_contents_client_bridge_base.h
@@ -7,6 +7,7 @@
#include "base/callback_forward.h"
#include "base/supports_user_data.h"
+#include "content/public/browser/javascript_dialog_manager.h"
class GURL;
@@ -42,6 +43,19 @@ class AwContentsClientBridgeBase {
const GURL& request_url,
const base::Callback<void(bool)>& callback,
bool* cancel_request) = 0;
+
+ virtual void RunJavaScriptDialog(
+ content::JavaScriptMessageType message_type,
+ const GURL& origin_url,
+ const string16& message_text,
+ const string16& default_prompt_text,
+ const content::JavaScriptDialogManager::DialogClosedCallback& callback)
+ = 0;
+ virtual void RunBeforeUnloadDialog(
+ const GURL& origin_url,
+ const string16& message_text,
+ const content::JavaScriptDialogManager::DialogClosedCallback& callback)
+ = 0;
};
} // namespace android_webview
diff --git a/android_webview/native/aw_javascript_dialog_manager.cc b/android_webview/browser/aw_javascript_dialog_manager.cc
index 608badb..4e9f6195 100644
--- a/android_webview/native/aw_javascript_dialog_manager.cc
+++ b/android_webview/browser/aw_javascript_dialog_manager.cc
@@ -2,22 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "android_webview/native/aw_javascript_dialog_manager.h"
-
-#include "android_webview/native/aw_contents.h"
-#include "android_webview/native/js_result_handler.h"
-#include "base/android/jni_android.h"
-#include "base/android/jni_helper.h"
-#include "base/android/jni_string.h"
-#include "base/android/scoped_java_ref.h"
-#include "base/logging.h"
-#include "base/string16.h"
+#include "android_webview/browser/aw_javascript_dialog_manager.h"
+
+#include "android_webview/browser/aw_contents_client_bridge_base.h"
#include "content/public/browser/javascript_dialog_manager.h"
#include "content/public/browser/web_contents.h"
-using base::android::AttachCurrentThread;
-using base::android::ScopedJavaLocalRef;
-
namespace android_webview {
AwJavaScriptDialogManager::AwJavaScriptDialogManager() {}
@@ -33,13 +23,13 @@ void AwJavaScriptDialogManager::RunJavaScriptDialog(
const string16& default_prompt_text,
const DialogClosedCallback& callback,
bool* did_suppress_message) {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jobject> js_result = createJsResultHandler(
- env,
- &callback);
- AwContents* contents = AwContents::FromWebContents(web_contents);
- contents->RunJavaScriptDialog(message_type, origin_url, message_text,
- default_prompt_text, js_result);
+ AwContentsClientBridgeBase* bridge =
+ AwContentsClientBridgeBase::FromWebContents(web_contents);
+ bridge->RunJavaScriptDialog(message_type,
+ origin_url,
+ message_text,
+ default_prompt_text,
+ callback);
}
void AwJavaScriptDialogManager::RunBeforeUnloadDialog(
@@ -47,13 +37,11 @@ void AwJavaScriptDialogManager::RunBeforeUnloadDialog(
const string16& message_text,
bool is_reload,
const DialogClosedCallback& callback) {
- JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jobject> js_result = createJsResultHandler(
- env,
- &callback);
- AwContents* contents = AwContents::FromWebContents(web_contents);
- contents->RunBeforeUnloadDialog(web_contents->GetURL(), message_text,
- js_result);
+ AwContentsClientBridgeBase* bridge =
+ AwContentsClientBridgeBase::FromWebContents(web_contents);
+ bridge->RunBeforeUnloadDialog(web_contents->GetURL(),
+ message_text,
+ callback);
}
void AwJavaScriptDialogManager::ResetJavaScriptState(
diff --git a/android_webview/native/aw_javascript_dialog_manager.h b/android_webview/browser/aw_javascript_dialog_manager.h
index 63aed51..69436dd 100644
--- a/android_webview/native/aw_javascript_dialog_manager.h
+++ b/android_webview/browser/aw_javascript_dialog_manager.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef ANDROID_WEBVIEW_NATIVE_AW_JAVASCRIPT_DIALOG_MANAGER_H_
-#define ANDROID_WEBVIEW_NATIVE_AW_JAVASCRIPT_DIALOG_MANAGER_H_
+#ifndef ANDROID_WEBVIEW_BROWSER_AW_JAVASCRIPT_DIALOG_MANAGER_H_
+#define ANDROID_WEBVIEW_BROWSER_AW_JAVASCRIPT_DIALOG_MANAGER_H_
#include "content/public/browser/javascript_dialog_manager.h"
@@ -38,4 +38,4 @@ class AwJavaScriptDialogManager : public content::JavaScriptDialogManager {
} // namespace android_webview
-#endif // ANDROID_WEBVIEW_NATIVE_AW_JAVASCRIPT_DIALOG_MANAGER_H_
+#endif // ANDROID_WEBVIEW_BROWSER_AW_JAVASCRIPT_DIALOG_MANAGER_H_
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java
index 6385881..b5d4e8d 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContents.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java
@@ -1245,27 +1245,6 @@ public class AwContents {
return result;
}
- @CalledByNative
- private void handleJsAlert(String url, String message, JsResultReceiver receiver) {
- mContentsClient.handleJsAlert(url, message, receiver);
- }
-
- @CalledByNative
- private void handleJsBeforeUnload(String url, String message, JsResultReceiver receiver) {
- mContentsClient.handleJsBeforeUnload(url, message, receiver);
- }
-
- @CalledByNative
- private void handleJsConfirm(String url, String message, JsResultReceiver receiver) {
- mContentsClient.handleJsConfirm(url, message, receiver);
- }
-
- @CalledByNative
- private void handleJsPrompt(String url, String message, String defaultValue,
- JsPromptResultReceiver receiver) {
- mContentsClient.handleJsPrompt(url, message, defaultValue, receiver);
- }
-
// -------------------------------------------------------------------------------------------
// Helper methods
// -------------------------------------------------------------------------------------------
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContentsClientBridge.java b/android_webview/java/src/org/chromium/android_webview/AwContentsClientBridge.java
index 5981d4a..7172cfb 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContentsClientBridge.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContentsClientBridge.java
@@ -67,9 +67,47 @@ public class AwContentsClientBridge {
nativeProceedSslError(mNativeContentsClientBridge, proceed, id);
}
+ @CalledByNative
+ private void handleJsAlert(String url, String message, int id) {
+ JsResultHandler handler = new JsResultHandler(this, id);
+ mClient.handleJsAlert(url, message, handler);
+ }
+
+ @CalledByNative
+ private void handleJsConfirm(String url, String message, int id) {
+ JsResultHandler handler = new JsResultHandler(this, id);
+ mClient.handleJsConfirm(url, message, handler);
+ }
+
+ @CalledByNative
+ private void handleJsPrompt(String url, String message, String defaultValue, int id) {
+ JsResultHandler handler = new JsResultHandler(this, id);
+ mClient.handleJsPrompt(url, message, defaultValue, handler);
+ }
+
+ @CalledByNative
+ private void handleJsBeforeUnload(String url, String message, int id) {
+ JsResultHandler handler = new JsResultHandler(this, id);
+ mClient.handleJsBeforeUnload(url, message, handler);
+ }
+
+ void confirmJsResult(int id, String prompt) {
+ if (mNativeContentsClientBridge == 0) return;
+ nativeConfirmJsResult(mNativeContentsClientBridge, id, prompt);
+ }
+
+ void cancelJsResult(int id) {
+ if (mNativeContentsClientBridge == 0) return;
+ nativeCancelJsResult(mNativeContentsClientBridge, id);
+ }
+
//--------------------------------------------------------------------------------------------
// Native methods
//--------------------------------------------------------------------------------------------
private native void nativeProceedSslError(int nativeAwContentsClientBridge, boolean proceed,
int id);
+
+ private native void nativeConfirmJsResult(int nativeAwContentsClientBridge, int id,
+ String prompt);
+ private native void nativeCancelJsResult(int nativeAwContentsClientBridge, int id);
} \ No newline at end of file
diff --git a/android_webview/java/src/org/chromium/android_webview/JsResultHandler.java b/android_webview/java/src/org/chromium/android_webview/JsResultHandler.java
index 3720324..30d4898 100644
--- a/android_webview/java/src/org/chromium/android_webview/JsResultHandler.java
+++ b/android_webview/java/src/org/chromium/android_webview/JsResultHandler.java
@@ -3,20 +3,16 @@
// found in the LICENSE file.
package org.chromium.android_webview;
-import org.chromium.base.CalledByNative;
-import org.chromium.base.JNINamespace;
-@JNINamespace("android_webview")
-public class JsResultHandler implements JsResultReceiver, JsPromptResultReceiver {
- private int mNativeDialogPointer;
+import org.chromium.base.ThreadUtils;
- @CalledByNative
- public static JsResultHandler create(int nativeDialogPointer) {
- return new JsResultHandler(nativeDialogPointer);
- }
+class JsResultHandler implements JsResultReceiver, JsPromptResultReceiver {
+ private AwContentsClientBridge mBridge;
+ private final int mId;
- private JsResultHandler(int nativeDialogPointer) {
- mNativeDialogPointer = nativeDialogPointer;
+ JsResultHandler(AwContentsClientBridge bridge, int id) {
+ mBridge = bridge;
+ mId = id;
}
@Override
@@ -25,15 +21,26 @@ public class JsResultHandler implements JsResultReceiver, JsPromptResultReceiver
}
@Override
- public void confirm(String promptResult) {
- nativeConfirmJsResult(mNativeDialogPointer, promptResult);
+ public void confirm(final String promptResult) {
+ ThreadUtils.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (mBridge != null)
+ mBridge.confirmJsResult(mId, promptResult);
+ mBridge = null;
+ }
+ });
}
@Override
public void cancel() {
- nativeCancelJsResult(mNativeDialogPointer);
+ ThreadUtils.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (mBridge != null)
+ mBridge.cancelJsResult(mId);
+ mBridge = null;
+ }
+ });
}
-
- private native void nativeConfirmJsResult(int dialogPointer, String promptResult);
- private native void nativeCancelJsResult(int dialogPointer);
}
diff --git a/android_webview/native/android_webview_jni_registrar.cc b/android_webview/native/android_webview_jni_registrar.cc
index dfe36af..cc503e3 100644
--- a/android_webview/native/android_webview_jni_registrar.cc
+++ b/android_webview/native/android_webview_jni_registrar.cc
@@ -17,7 +17,6 @@
#include "android_webview/native/input_stream_impl.h"
#include "android_webview/native/intercepted_request_data_impl.h"
#include "android_webview/native/java_browser_view_renderer_helper.h"
-#include "android_webview/native/js_result_handler.h"
#include "base/android/jni_android.h"
#include "base/android/jni_registrar.h"
@@ -38,7 +37,6 @@ static base::android::RegistrationMethod kWebViewRegisteredMethods[] = {
{ "InterceptedRequestDataImpl", RegisterInterceptedRequestData },
{ "InputStream", RegisterInputStream },
{ "JavaBrowserViewRendererHelper", RegisterJavaBrowserViewRendererHelper },
- { "JsResultHandler", RegisterJsResultHandler },
};
bool RegisterJni(JNIEnv* env) {
diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc
index 0284f56..61c9345 100644
--- a/android_webview/native/aw_contents.cc
+++ b/android_webview/native/aw_contents.cc
@@ -226,62 +226,6 @@ void AwContents::GenerateMHTML(JNIEnv* env, jobject obj,
base::Bind(&GenerateMHTMLCallback, base::Owned(j_callback)));
}
-void AwContents::RunJavaScriptDialog(
- content::JavaScriptMessageType message_type,
- const GURL& origin_url,
- const string16& message_text,
- const string16& default_prompt_text,
- const ScopedJavaLocalRef<jobject>& js_result) {
- JNIEnv* env = AttachCurrentThread();
-
- ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
- if (obj.is_null())
- return;
-
- ScopedJavaLocalRef<jstring> jurl(ConvertUTF8ToJavaString(
- env, origin_url.spec()));
- ScopedJavaLocalRef<jstring> jmessage(ConvertUTF16ToJavaString(
- env, message_text));
- switch (message_type) {
- case content::JAVASCRIPT_MESSAGE_TYPE_ALERT:
- Java_AwContents_handleJsAlert(
- env, obj.obj(), jurl.obj(), jmessage.obj(), js_result.obj());
- break;
- case content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM:
- Java_AwContents_handleJsConfirm(
- env, obj.obj(), jurl.obj(), jmessage.obj(), js_result.obj());
- break;
- case content::JAVASCRIPT_MESSAGE_TYPE_PROMPT: {
- ScopedJavaLocalRef<jstring> jdefault_value(
- ConvertUTF16ToJavaString(env, default_prompt_text));
- Java_AwContents_handleJsPrompt(
- env, obj.obj(), jurl.obj(), jmessage.obj(),
- jdefault_value.obj(), js_result.obj());
- break;
- }
- default:
- NOTREACHED();
- }
-}
-
-void AwContents::RunBeforeUnloadDialog(
- const GURL& origin_url,
- const string16& message_text,
- const ScopedJavaLocalRef<jobject>& js_result) {
- JNIEnv* env = AttachCurrentThread();
-
- ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
- if (obj.is_null())
- return;
-
- ScopedJavaLocalRef<jstring> jurl(ConvertUTF8ToJavaString(
- env, origin_url.spec()));
- ScopedJavaLocalRef<jstring> jmessage(ConvertUTF16ToJavaString(
- env, message_text));
- Java_AwContents_handleJsBeforeUnload(
- env, obj.obj(), jurl.obj(), jmessage.obj(), js_result.obj());
-}
-
void AwContents::PerformLongClick() {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
diff --git a/android_webview/native/aw_contents.h b/android_webview/native/aw_contents.h
index 8f0d0ea..667e67d 100644
--- a/android_webview/native/aw_contents.h
+++ b/android_webview/native/aw_contents.h
@@ -18,7 +18,6 @@
#include "base/android/jni_helper.h"
#include "base/callback_forward.h"
#include "base/memory/scoped_ptr.h"
-#include "content/public/browser/javascript_dialog_manager.h"
class SkBitmap;
class TabContents;
@@ -64,18 +63,6 @@ class AwContents : public FindHelper::Listener,
return render_view_host_ext_.get();
}
- void RunJavaScriptDialog(
- content::JavaScriptMessageType message_type,
- const GURL& origin_url,
- const string16& message_text,
- const string16& default_prompt_text,
- const base::android::ScopedJavaLocalRef<jobject>& js_result);
-
- void RunBeforeUnloadDialog(
- const GURL& origin_url,
- const string16& message_text,
- const base::android::ScopedJavaLocalRef<jobject>& js_result);
-
void PerformLongClick();
// |handler| is an instance of
diff --git a/android_webview/native/aw_contents_client_bridge.cc b/android_webview/native/aw_contents_client_bridge.cc
index 0c13ebe..213646f 100644
--- a/android_webview/native/aw_contents_client_bridge.cc
+++ b/android_webview/native/aw_contents_client_bridge.cc
@@ -16,6 +16,7 @@
using base::android::AttachCurrentThread;
using base::android::ConvertJavaStringToUTF16;
using base::android::ConvertUTF8ToJavaString;
+using base::android::ConvertUTF16ToJavaString;
using base::android::JavaRef;
using base::android::ScopedJavaLocalRef;
using content::BrowserThread;
@@ -25,8 +26,8 @@ namespace android_webview {
AwContentsClientBridge::AwContentsClientBridge(JNIEnv* env, jobject obj)
: java_ref_(env, obj) {
DCHECK(obj);
- Java_AwContentsClientBridge_setNativeContentsClientBridge(env, obj,
- reinterpret_cast<jint>(this));
+ Java_AwContentsClientBridge_setNativeContentsClientBridge(
+ env, obj, reinterpret_cast<jint>(this));
}
AwContentsClientBridge::~AwContentsClientBridge() {
@@ -56,16 +57,18 @@ void AwContentsClientBridge::AllowCertificateError(
std::string der_string;
net::X509Certificate::GetDEREncoded(cert->os_cert_handle(), &der_string);
- ScopedJavaLocalRef<jbyteArray> jcert = base::android::ToJavaByteArray(env,
- reinterpret_cast<const uint8*>(der_string.data()), der_string.length());
+ ScopedJavaLocalRef<jbyteArray> jcert = base::android::ToJavaByteArray(
+ env,
+ reinterpret_cast<const uint8*>(der_string.data()),
+ der_string.length());
ScopedJavaLocalRef<jstring> jurl(ConvertUTF8ToJavaString(
env, request_url.spec()));
// We need to add the callback before making the call to java side,
// as it may do a synchronous callback prior to returning.
int request_id = pending_cert_error_callbacks_.Add(
new CertErrorCallback(callback));
- *cancel_request = !Java_AwContentsClientBridge_allowCertificateError(env,
- obj.obj(), cert_error, jcert.obj(), jurl.obj(), request_id);
+ *cancel_request = !Java_AwContentsClientBridge_allowCertificateError(
+ env, obj.obj(), cert_error, jcert.obj(), jurl.obj(), request_id);
// if the request is cancelled, then cancel the stored callback
if (*cancel_request) {
pending_cert_error_callbacks_.Remove(request_id);
@@ -84,6 +87,98 @@ void AwContentsClientBridge::ProceedSslError(JNIEnv* env, jobject obj,
pending_cert_error_callbacks_.Remove(id);
}
+void AwContentsClientBridge::RunJavaScriptDialog(
+ content::JavaScriptMessageType message_type,
+ const GURL& origin_url,
+ const string16& message_text,
+ const string16& default_prompt_text,
+ const content::JavaScriptDialogManager::DialogClosedCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ JNIEnv* env = AttachCurrentThread();
+
+ ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
+ if (obj.is_null())
+ return;
+
+ int callback_id = pending_js_dialog_callbacks_.Add(
+ new content::JavaScriptDialogManager::DialogClosedCallback(callback));
+ ScopedJavaLocalRef<jstring> jurl(
+ ConvertUTF8ToJavaString(env, origin_url.spec()));
+ ScopedJavaLocalRef<jstring> jmessage(
+ ConvertUTF16ToJavaString(env, message_text));
+
+ switch (message_type) {
+ case content::JAVASCRIPT_MESSAGE_TYPE_ALERT:
+ Java_AwContentsClientBridge_handleJsAlert(
+ env, obj.obj(), jurl.obj(), jmessage.obj(), callback_id);
+ break;
+ case content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM:
+ Java_AwContentsClientBridge_handleJsConfirm(
+ env, obj.obj(), jurl.obj(), jmessage.obj(), callback_id);
+ break;
+ case content::JAVASCRIPT_MESSAGE_TYPE_PROMPT: {
+ ScopedJavaLocalRef<jstring> jdefault_value(
+ ConvertUTF16ToJavaString(env, default_prompt_text));
+ Java_AwContentsClientBridge_handleJsPrompt(env,
+ obj.obj(),
+ jurl.obj(),
+ jmessage.obj(),
+ jdefault_value.obj(),
+ callback_id);
+ break;
+ }
+ default:
+ NOTREACHED();
+ }
+}
+
+void AwContentsClientBridge::RunBeforeUnloadDialog(
+ const GURL& origin_url,
+ const string16& message_text,
+ const content::JavaScriptDialogManager::DialogClosedCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ JNIEnv* env = AttachCurrentThread();
+
+ ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
+ if (obj.is_null())
+ return;
+
+ int callback_id = pending_js_dialog_callbacks_.Add(
+ new content::JavaScriptDialogManager::DialogClosedCallback(callback));
+ ScopedJavaLocalRef<jstring> jurl(
+ ConvertUTF8ToJavaString(env, origin_url.spec()));
+ ScopedJavaLocalRef<jstring> jmessage(
+ ConvertUTF16ToJavaString(env, message_text));
+
+ Java_AwContentsClientBridge_handleJsBeforeUnload(
+ env, obj.obj(), jurl.obj(), jmessage.obj(), callback_id);
+}
+
+void AwContentsClientBridge::ConfirmJsResult(JNIEnv* env,
+ jobject,
+ int id,
+ jstring prompt) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ content::JavaScriptDialogManager::DialogClosedCallback* callback =
+ pending_js_dialog_callbacks_.Lookup(id);
+ string16 prompt_text;
+ if (prompt) {
+ prompt_text = ConvertJavaStringToUTF16(env, prompt);
+ }
+ if (callback)
+ callback->Run(true, prompt_text);
+ pending_js_dialog_callbacks_.Remove(id);
+}
+
+void AwContentsClientBridge::CancelJsResult(JNIEnv*, jobject, int id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ content::JavaScriptDialogManager::DialogClosedCallback* callback =
+ pending_js_dialog_callbacks_.Lookup(id);
+ if (callback)
+ callback->Run(false, string16());
+ pending_js_dialog_callbacks_.Remove(id);
+}
+
bool RegisterAwContentsClientBridge(JNIEnv* env) {
return RegisterNativesImpl(env) >= 0;
}
diff --git a/android_webview/native/aw_contents_client_bridge.h b/android_webview/native/aw_contents_client_bridge.h
index 5e160de..44b6314 100644
--- a/android_webview/native/aw_contents_client_bridge.h
+++ b/android_webview/native/aw_contents_client_bridge.h
@@ -12,6 +12,7 @@
#include "base/android/scoped_java_ref.h"
#include "base/callback.h"
#include "base/id_map.h"
+#include "content/public/browser/javascript_dialog_manager.h"
namespace net {
class X509Certificate;
@@ -39,14 +40,31 @@ class AwContentsClientBridge : public AwContentsClientBridgeBase {
const base::Callback<void(bool)>& callback,
bool* cancel_request) OVERRIDE;
+ virtual void RunJavaScriptDialog(
+ content::JavaScriptMessageType message_type,
+ const GURL& origin_url,
+ const string16& message_text,
+ const string16& default_prompt_text,
+ const content::JavaScriptDialogManager::DialogClosedCallback& callback)
+ OVERRIDE;
+ virtual void RunBeforeUnloadDialog(
+ const GURL& origin_url,
+ const string16& message_text,
+ const content::JavaScriptDialogManager::DialogClosedCallback& callback)
+ OVERRIDE;
+
// Methods called from Java.
void ProceedSslError(JNIEnv* env, jobject obj, jboolean proceed, jint id);
+ void ConfirmJsResult(JNIEnv*, jobject, int id, jstring prompt);
+ void CancelJsResult(JNIEnv*, jobject, int id);
private:
JavaObjectWeakGlobalRef java_ref_;
typedef const base::Callback<void(bool)> CertErrorCallback;
IDMap<CertErrorCallback, IDMapOwnPointer> pending_cert_error_callbacks_;
+ IDMap<content::JavaScriptDialogManager::DialogClosedCallback, IDMapOwnPointer>
+ pending_js_dialog_callbacks_;
};
bool RegisterAwContentsClientBridge(JNIEnv* env);
diff --git a/android_webview/native/aw_web_contents_delegate.cc b/android_webview/native/aw_web_contents_delegate.cc
index 427ffa3..78849a9 100644
--- a/android_webview/native/aw_web_contents_delegate.cc
+++ b/android_webview/native/aw_web_contents_delegate.cc
@@ -4,9 +4,9 @@
#include "android_webview/native/aw_web_contents_delegate.h"
+#include "android_webview/browser/aw_javascript_dialog_manager.h"
#include "android_webview/browser/find_helper.h"
#include "android_webview/native/aw_contents.h"
-#include "android_webview/native/aw_javascript_dialog_manager.h"
#include "base/android/scoped_java_ref.h"
#include "base/lazy_instance.h"
#include "base/message_loop.h"
diff --git a/android_webview/native/js_result_handler.cc b/android_webview/native/js_result_handler.cc
deleted file mode 100644
index 974c741..0000000
--- a/android_webview/native/js_result_handler.cc
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "android_webview/native/js_result_handler.h"
-
-#include "base/android/jni_string.h"
-#include "content/public/browser/android/content_view_core.h"
-#include "content/public/browser/javascript_dialog_manager.h"
-#include "jni/JsResultHandler_jni.h"
-
-using base::android::ConvertJavaStringToUTF16;
-using content::ContentViewCore;
-
-namespace android_webview {
-
-void ConfirmJsResult(JNIEnv* env,
- jobject obj,
- jint dialogPointer,
- jstring promptResult) {
- content::JavaScriptDialogManager::DialogClosedCallback* dialog_ =
- reinterpret_cast<content::JavaScriptDialogManager::DialogClosedCallback*>(
- dialogPointer);
- string16 prompt_text;
- if (promptResult) {
- prompt_text = ConvertJavaStringToUTF16(env, promptResult);
- }
- dialog_->Run(true,prompt_text);
-}
-
-void CancelJsResult(JNIEnv* env, jobject obj, jint dialogPointer) {
- content::JavaScriptDialogManager::DialogClosedCallback* dialog_ =
- reinterpret_cast<content::JavaScriptDialogManager::DialogClosedCallback*>(
- dialogPointer);
- dialog_->Run(false, string16());
-}
-
-base::android::ScopedJavaLocalRef<jobject> createJsResultHandler(
- JNIEnv* env,
- const content::JavaScriptDialogManager::DialogClosedCallback* dialog) {
- return Java_JsResultHandler_create(env, reinterpret_cast<jint>(dialog));
-}
-
-bool RegisterJsResultHandler(JNIEnv* env) {
- return RegisterNativesImpl(env);
-}
-
-} // namespace android_webview
diff --git a/android_webview/native/js_result_handler.h b/android_webview/native/js_result_handler.h
deleted file mode 100644
index 4bd478f..0000000
--- a/android_webview/native/js_result_handler.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef ANDROID_WEBVIEW_NATIVE_JS_RESULT_HANDLER_H_
-#define ANDROID_WEBVIEW_NATIVE_JS_RESULT_HANDLER_H_
-
-#include "base/android/jni_helper.h"
-#include "base/android/scoped_java_ref.h"
-#include "content/public/browser/javascript_dialog_manager.h"
-
-namespace android_webview {
-
-bool RegisterJsResultHandler(JNIEnv* env);
-
-base::android::ScopedJavaLocalRef<jobject> createJsResultHandler(
- JNIEnv* env,
- const content::JavaScriptDialogManager::DialogClosedCallback*
- native_dialog_pointer);
-
-} // namespace android_webview
-
-#endif // ANDROID_WEBVIEW_NATIVE_JS_RESULT_HANDLER_H_
diff --git a/android_webview/native/webview_native.gyp b/android_webview/native/webview_native.gyp
index d175d3c..594da68 100644
--- a/android_webview/native/webview_native.gyp
+++ b/android_webview/native/webview_native.gyp
@@ -42,8 +42,6 @@
'aw_geolocation_permission_context.h',
'aw_http_auth_handler.cc',
'aw_http_auth_handler.h',
- 'aw_javascript_dialog_manager.cc',
- 'aw_javascript_dialog_manager.h',
'aw_quota_manager_bridge_impl.cc',
'aw_quota_manager_bridge_impl.h',
'aw_resource.cc',
@@ -62,8 +60,6 @@
'intercepted_request_data_impl.h',
'java_browser_view_renderer_helper.cc',
'java_browser_view_renderer_helper.h',
- 'js_result_handler.cc',
- 'js_result_handler.h',
'net_init_native_callback.cc',
'state_serializer.cc',
'state_serializer.h',
@@ -94,7 +90,6 @@
'../java/src/org/chromium/android_webview/AwWebContentsDelegate.java',
'../java/src/org/chromium/android_webview/InterceptedRequestData.java',
'../java/src/org/chromium/android_webview/JavaBrowserViewRendererHelper.java',
- '../java/src/org/chromium/android_webview/JsResultHandler.java',
],
'variables': {
'jni_gen_package': 'android_webview',