From bf22f208d6fb755dd4ddebbde1a1a3b23e597990 Mon Sep 17 00:00:00 2001 From: Ben Murdoch Date: Tue, 12 May 2009 19:41:18 +0100 Subject: Implement adding console messages --- WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp | 6 +++--- WebKit/android/jni/WebViewCore.cpp | 12 ++++++++++++ WebKit/android/jni/WebViewCore.h | 2 ++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp b/WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp index c4ff2f0..6e97ae5 100644 --- a/WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp +++ b/WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp @@ -143,10 +143,10 @@ bool ChromeClientAndroid::menubarVisible() { notImplemented(); return false; } void ChromeClientAndroid::setResizable(bool) { notImplemented(); } // This function is called by the JavaScript bindings to print usually an error to -// a message console. +// a message console. Pass the message to the java side so that the client can +// handle it as it sees fit. void ChromeClientAndroid::addMessageToConsole(const String& message, unsigned int lineNumber, const String& sourceID) { - notImplemented(); - LOGD("Console: %s line: %d source: %s\n", message.latin1().data(), lineNumber, sourceID.latin1().data()); + android::WebViewCore::getWebViewCore(m_webFrame->page()->mainFrame()->view())->addMessageToConsole(message, lineNumber, sourceID); } bool ChromeClientAndroid::canRunBeforeUnloadConfirmPanel() { return true; } diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp index 9563638..78681bc 100644 --- a/WebKit/android/jni/WebViewCore.cpp +++ b/WebKit/android/jni/WebViewCore.cpp @@ -169,6 +169,7 @@ struct WebViewCore::JavaGlue { jmethodID m_restoreScale; jmethodID m_needTouchEvents; jmethodID m_exceededDatabaseQuota; + jmethodID m_addMessageToConsole; AutoJObject object(JNIEnv* env) { return getRealObject(env, m_obj); } @@ -233,6 +234,7 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m m_javaGlue->m_restoreScale = GetJMethod(env, clazz, "restoreScale", "(I)V"); m_javaGlue->m_needTouchEvents = GetJMethod(env, clazz, "needTouchEvents", "(Z)V"); m_javaGlue->m_exceededDatabaseQuota = GetJMethod(env, clazz, "exceededDatabaseQuota", "(Ljava/lang/String;Ljava/lang/String;J)V"); + m_javaGlue->m_addMessageToConsole = GetJMethod(env, clazz, "addMessageToConsole", "(Ljava/lang/String;ILjava/lang/String;)V"); env->SetIntField(javaWebViewCore, gWebViewCoreFields.m_nativeClass, (jint)this); @@ -1787,6 +1789,16 @@ void WebViewCore::popupReply(const int* array, int count) } } +void WebViewCore::addMessageToConsole(const WebCore::String& message, unsigned int lineNumber, const WebCore::String& sourceID) { + JNIEnv* env = JSC::Bindings::getJNIEnv(); + jstring jMessageStr = env->NewString((unsigned short *)message.characters(), message.length()); + jstring jSourceIDStr = env->NewString((unsigned short *)sourceID.characters(), sourceID.length()); + env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_addMessageToConsole, jMessageStr, lineNumber, jSourceIDStr); + env->DeleteLocalRef(jMessageStr); + env->DeleteLocalRef(jSourceIDStr); + checkException(env); +} + void WebViewCore::jsAlert(const WebCore::String& url, const WebCore::String& text) { JNIEnv* env = JSC::Bindings::getJNIEnv(); diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h index 7f8aebd..c60a12c 100644 --- a/WebKit/android/jni/WebViewCore.h +++ b/WebKit/android/jni/WebViewCore.h @@ -179,6 +179,8 @@ namespace android { const WebCore::String& databaseIdentifier, const unsigned long long currentQuota); + void addMessageToConsole(const String& message, unsigned int lineNumber, const String& sourceID); + // // Followings support calls from Java to native WebCore // -- cgit v1.1