Add new ConsoleMessage class that adds more information (such as the Message Log Level from WebCore) and a new overload of onConsoleMessage that takes this as a parameter.
This change requires a corresponding change in external/webkit. BUG=2401755 Change-Id: Iea2c58e93172240f162d8ad57eb2c8f2352f8162
This commit is contained in:
117
api/current.xml
117
api/current.xml
@@ -186353,6 +186353,108 @@
|
||||
</parameter>
|
||||
</method>
|
||||
</class>
|
||||
<class name="ConsoleMessage"
|
||||
extends="java.lang.Object"
|
||||
abstract="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<constructor name="ConsoleMessage"
|
||||
type="android.webkit.ConsoleMessage"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="message" type="java.lang.String">
|
||||
</parameter>
|
||||
<parameter name="sourceId" type="java.lang.String">
|
||||
</parameter>
|
||||
<parameter name="lineNumber" type="int">
|
||||
</parameter>
|
||||
<parameter name="msgLevel" type="android.webkit.ConsoleMessage.MessageLevel">
|
||||
</parameter>
|
||||
</constructor>
|
||||
<method name="lineNumber"
|
||||
return="int"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="message"
|
||||
return="java.lang.String"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="messageLevel"
|
||||
return="android.webkit.ConsoleMessage.MessageLevel"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="sourceId"
|
||||
return="java.lang.String"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
</class>
|
||||
<class name="ConsoleMessage.MessageLevel"
|
||||
extends="java.lang.Enum"
|
||||
abstract="false"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<method name="valueOf"
|
||||
return="android.webkit.ConsoleMessage.MessageLevel"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="true"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="name" type="java.lang.String">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="values"
|
||||
return="android.webkit.ConsoleMessage.MessageLevel[]"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
</class>
|
||||
<class name="CookieManager"
|
||||
extends="java.lang.Object"
|
||||
abstract="false"
|
||||
@@ -187841,7 +187943,7 @@
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
deprecated="deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="message" type="java.lang.String">
|
||||
@@ -187851,6 +187953,19 @@
|
||||
<parameter name="sourceID" type="java.lang.String">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="onConsoleMessage"
|
||||
return="boolean"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="consoleMessage" type="android.webkit.ConsoleMessage">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="onCreateWindow"
|
||||
return="boolean"
|
||||
abstract="false"
|
||||
|
||||
@@ -651,7 +651,42 @@ class CallbackProxy extends Handler {
|
||||
String message = msg.getData().getString("message");
|
||||
String sourceID = msg.getData().getString("sourceID");
|
||||
int lineNumber = msg.getData().getInt("lineNumber");
|
||||
mWebChromeClient.onConsoleMessage(message, lineNumber, sourceID);
|
||||
int msgLevel = msg.getData().getInt("msgLevel");
|
||||
int numberOfMessageLevels = ConsoleMessage.MessageLevel.values().length;
|
||||
// Sanity bounds check as we'll index an array with msgLevel
|
||||
if (msgLevel < 0 || msgLevel >= numberOfMessageLevels) {
|
||||
msgLevel = 0;
|
||||
}
|
||||
|
||||
ConsoleMessage.MessageLevel messageLevel =
|
||||
ConsoleMessage.MessageLevel.values()[msgLevel];
|
||||
|
||||
if (!mWebChromeClient.onConsoleMessage(new ConsoleMessage(message, sourceID,
|
||||
lineNumber, messageLevel))) {
|
||||
// If false was returned the user did not provide their own console function so
|
||||
// we should output some default messages to the system log.
|
||||
String logTag = "Web Console";
|
||||
String logMessage = message + " at " + sourceID + ":" + lineNumber;
|
||||
|
||||
switch (messageLevel) {
|
||||
case TIP:
|
||||
Log.v(logTag, logMessage);
|
||||
break;
|
||||
case LOG:
|
||||
Log.i(logTag, logMessage);
|
||||
break;
|
||||
case WARNING:
|
||||
Log.w(logTag, logMessage);
|
||||
break;
|
||||
case ERROR:
|
||||
Log.e(logTag, logMessage);
|
||||
break;
|
||||
case DEBUG:
|
||||
Log.d(logTag, logMessage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case GET_VISITED_HISTORY:
|
||||
@@ -1286,8 +1321,10 @@ class CallbackProxy extends Handler {
|
||||
* occurred.
|
||||
* @param sourceID The filename of the source file in which the error
|
||||
* occurred.
|
||||
* @param msgLevel The message level, corresponding to the MessageLevel enum in
|
||||
* WebCore/page/Console.h
|
||||
*/
|
||||
public void addMessageToConsole(String message, int lineNumber, String sourceID) {
|
||||
public void addMessageToConsole(String message, int lineNumber, String sourceID, int msgLevel) {
|
||||
if (mWebChromeClient == null) {
|
||||
return;
|
||||
}
|
||||
@@ -1296,6 +1333,7 @@ class CallbackProxy extends Handler {
|
||||
msg.getData().putString("message", message);
|
||||
msg.getData().putString("sourceID", sourceID);
|
||||
msg.getData().putInt("lineNumber", lineNumber);
|
||||
msg.getData().putInt("msgLevel", msgLevel);
|
||||
sendMessage(msg);
|
||||
}
|
||||
|
||||
|
||||
64
core/java/android/webkit/ConsoleMessage.java
Normal file
64
core/java/android/webkit/ConsoleMessage.java
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.webkit;
|
||||
|
||||
/**
|
||||
* Public class representing a JavaScript console message from WebCore. This could be a issued
|
||||
* by a call to one of the <code>console</code> logging functions (e.g.
|
||||
* <code>console.log('...')</code>) or a JavaScript error on the page. To receive notifications
|
||||
* of these messages, override the
|
||||
* {@link WebChromeClient#onConsoleMessage(ConsoleMessage)} function.
|
||||
*/
|
||||
public class ConsoleMessage {
|
||||
|
||||
// This must be kept in sync with the WebCore enum in WebCore/page/Console.h
|
||||
public enum MessageLevel {
|
||||
TIP,
|
||||
LOG,
|
||||
WARNING,
|
||||
ERROR,
|
||||
DEBUG
|
||||
};
|
||||
|
||||
private MessageLevel mLevel;
|
||||
private String mMessage;
|
||||
private String mSourceId;
|
||||
private int mLineNumber;
|
||||
|
||||
public ConsoleMessage(String message, String sourceId, int lineNumber, MessageLevel msgLevel) {
|
||||
mMessage = message;
|
||||
mSourceId = sourceId;
|
||||
mLineNumber = lineNumber;
|
||||
mLevel = msgLevel;
|
||||
}
|
||||
|
||||
public MessageLevel messageLevel() {
|
||||
return mLevel;
|
||||
}
|
||||
|
||||
public String message() {
|
||||
return mMessage;
|
||||
}
|
||||
|
||||
public String sourceId() {
|
||||
return mSourceId;
|
||||
}
|
||||
|
||||
public int lineNumber() {
|
||||
return mLineNumber;
|
||||
}
|
||||
};
|
||||
@@ -262,8 +262,24 @@ public class WebChromeClient {
|
||||
* @param message The error message to report.
|
||||
* @param lineNumber The line number of the error.
|
||||
* @param sourceID The name of the source file that caused the error.
|
||||
* @deprecated Use {@link #onConsoleMessage(ConsoleMessage) onConsoleMessage(ConsoleMessage)}
|
||||
* instead.
|
||||
*/
|
||||
public void onConsoleMessage(String message, int lineNumber, String sourceID) {}
|
||||
@Deprecated
|
||||
public void onConsoleMessage(String message, int lineNumber, String sourceID) { }
|
||||
|
||||
/**
|
||||
* Report a JavaScript console message to the host application. The ChromeClient
|
||||
* should override this to process the log message as they see fit.
|
||||
* @param consoleMessage Object containing details of the console message.
|
||||
* @return true if the message is handled by the client.
|
||||
*/
|
||||
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
|
||||
// Call the old version of this function for backwards compatability.
|
||||
onConsoleMessage(consoleMessage.message(), consoleMessage.lineNumber(),
|
||||
consoleMessage.sourceId());
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* When not playing, video elements are represented by a 'poster' image. The
|
||||
|
||||
@@ -260,9 +260,12 @@ final class WebViewCore {
|
||||
* @param message The message to add
|
||||
* @param lineNumber the line on which the error occurred
|
||||
* @param sourceID the filename of the source that caused the error.
|
||||
* @param msgLevel the log level of this message. This is a value casted to int
|
||||
* from WebCore::MessageLevel in WebCore/page/Console.h.
|
||||
*/
|
||||
protected void addMessageToConsole(String message, int lineNumber, String sourceID) {
|
||||
mCallbackProxy.addMessageToConsole(message, lineNumber, sourceID);
|
||||
protected void addMessageToConsole(String message, int lineNumber, String sourceID,
|
||||
int msgLevel) {
|
||||
mCallbackProxy.addMessageToConsole(message, lineNumber, sourceID, msgLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user