Commit 7bb2612e authored by jaekyun's avatar jaekyun Committed by Commit bot

Add AddMessageToDevToolsConsole to WebContentsAndroid

For now there isn't any API to write some logs to dev tools console from
Java layer.
It is required to fix http://crbug.com/426751 .

BUG=426751

Review URL: https://codereview.chromium.org/873133002

Cr-Commit-Position: refs/heads/master@{#313388}
parent 7439d046
......@@ -51,6 +51,7 @@ $(call intermediates-dir-for,GYP,shared)/enums/cert_verify_status_android_java/o
$(call intermediates-dir-for,GYP,shared)/enums/certificate_mime_types_java/org/chromium/net/CertificateMimeType.java \
$(call intermediates-dir-for,GYP,shared)/enums/network_change_notifier_types_java/org/chromium/net/ConnectionSubtype.java \
$(call intermediates-dir-for,GYP,shared)/enums/network_change_notifier_types_java/org/chromium/net/ConnectionType.java \
$(call intermediates-dir-for,GYP,shared)/enums/console_message_level_java/org/chromium/content_public/common/ConsoleMessageLevel.java \
$(call intermediates-dir-for,GYP,shared)/enums/content_gamepad_mapping/org/chromium/content/browser/input/CanonicalAxisIndex.java \
$(call intermediates-dir-for,GYP,shared)/enums/content_gamepad_mapping/org/chromium/content/browser/input/CanonicalButtonIndex.java \
$(call intermediates-dir-for,GYP,shared)/enums/gesture_event_type_java/org/chromium/content/browser/GestureEventType.java \
......
......@@ -16,6 +16,7 @@
'../base/base.gyp:base_java_application_state',
'../base/base.gyp:base_java_library_load_from_apk_status_codes',
'../base/base.gyp:base_java_memory_pressure_level',
'../content/content.gyp:console_message_level_java',
'../content/content.gyp:content_gamepad_mapping',
'../content/content.gyp:gesture_event_type_java',
'../content/content.gyp:navigation_controller_java',
......
......@@ -15,6 +15,7 @@
#include "content/browser/media/media_web_contents_observer.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/devtools_messages.h"
#include "content/common/frame_messages.h"
#include "content/common/input_messages.h"
#include "content/common/view_messages.h"
......@@ -466,4 +467,17 @@ void WebContentsAndroid::EvaluateJavaScript(JNIEnv* env,
ConvertJavaStringToUTF16(env, script), js_callback);
}
void WebContentsAndroid::AddMessageToDevToolsConsole(JNIEnv* env,
jobject jobj,
jint level,
jstring message) {
DCHECK_GE(level, 0);
DCHECK_LE(level, CONSOLE_MESSAGE_LEVEL_LAST);
web_contents_->GetMainFrame()->Send(new DevToolsAgentMsg_AddMessageToConsole(
web_contents_->GetMainFrame()->GetRoutingID(),
static_cast<ConsoleMessageLevel>(level),
ConvertJavaStringToUTF8(env, message)));
}
} // namespace content
......@@ -103,6 +103,12 @@ class CONTENT_EXPORT WebContentsAndroid
jobject obj,
jstring script,
jobject callback);
void AddMessageToDevToolsConsole(JNIEnv* env,
jobject jobj,
jint level,
jstring message);
private:
RenderWidgetHostViewAndroid* GetRenderWidgetHostViewAndroid();
......
......@@ -438,6 +438,7 @@
'../ui/touch_selection/ui_touch_selection.gyp:selection_event_type_java',
'../third_party/WebKit/public/blink_headers.gyp:blink_headers_java',
'common_aidl',
'console_message_level_java',
'content_common',
'content_strings_grd',
'content_gamepad_mapping',
......@@ -457,6 +458,14 @@
},
'includes': [ '../build/java.gypi' ],
},
{
'target_name': 'console_message_level_java',
'type': 'none',
'variables': {
'source_file': 'public/common/console_message_level.h',
},
'includes': [ '../build/android/java_cpp_enum.gypi' ],
},
{
'target_name': 'content_strings_grd',
# The android_webview/Android.mk file depends on this target directly.
......
......@@ -291,6 +291,11 @@ import org.chromium.content_public.browser.WebContents;
nativeEvaluateJavaScript(mNativeWebContentsAndroid, script, callback);
}
@Override
public void addMessageToDevToolsConsole(int level, String message) {
nativeAddMessageToDevToolsConsole(mNativeWebContentsAndroid, level, message);
}
@CalledByNative
private static void onEvaluateJavaScriptResult(
String jsonResult, JavaScriptCallback callback) {
......@@ -340,4 +345,6 @@ import org.chromium.content_public.browser.WebContents;
private native void nativeFetchTransitionElements(long nativeWebContentsAndroid, String url);
private native void nativeEvaluateJavaScript(long nativeWebContentsAndroid,
String script, JavaScriptCallback callback);
private native void nativeAddMessageToDevToolsConsole(
long nativeWebContentsAndroid, int level, String message);
}
......@@ -208,4 +208,9 @@ public interface WebContents {
*/
public void evaluateJavaScript(String script, JavaScriptCallback callback);
/**
* Adds a log message to dev tools console. |level| must be a value of
* org.chromium.content_public.common.ConsoleMessageLevel.
*/
public void addMessageToDevToolsConsole(int level, String message);
}
......@@ -7,6 +7,8 @@
namespace content {
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.content_public.common
enum ConsoleMessageLevel {
CONSOLE_MESSAGE_LEVEL_DEBUG,
CONSOLE_MESSAGE_LEVEL_LOG,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment