1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.webkit;
18 
19 import android.compat.annotation.UnsupportedAppUsage;
20 import android.os.Build;
21 
22 /**
23  * Public class representing a JavaScript console message from WebCore. This could be a issued
24  * by a call to one of the <code>console</code> logging functions (e.g.
25  * <code>console.log('...')</code>) or a JavaScript error on the  page. To receive notifications
26  * of these messages, override the
27  * {@link WebChromeClient#onConsoleMessage(ConsoleMessage)} function.
28  */
29 public class ConsoleMessage {
30 
31     // This must be kept in sync with the WebCore enum in WebCore/page/Console.h
32     public enum MessageLevel {
33         TIP,
34         LOG,
35         WARNING,
36         ERROR,
37         DEBUG
38     };
39 
40     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
41     private MessageLevel mLevel;
42     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
43     private String mMessage;
44     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
45     private String mSourceId;
46     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
47     private int mLineNumber;
48 
ConsoleMessage(String message, String sourceId, int lineNumber, MessageLevel msgLevel)49     public ConsoleMessage(String message, String sourceId, int lineNumber, MessageLevel msgLevel) {
50         mMessage = message;
51         mSourceId = sourceId;
52         mLineNumber = lineNumber;
53         mLevel = msgLevel;
54     }
55 
messageLevel()56     public MessageLevel messageLevel() {
57         return mLevel;
58     }
59 
message()60     public String message() {
61         return mMessage;
62     }
63 
sourceId()64     public String sourceId() {
65         return mSourceId;
66     }
67 
lineNumber()68     public int lineNumber() {
69         return mLineNumber;
70     }
71 };
72