1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | package org.chromium.components.web_contents_delegate_android; |
6 | |
7 | import android.graphics.Rect; |
8 | import android.view.KeyEvent; |
9 | |
10 | import org.chromium.base.CalledByNative; |
11 | import org.chromium.base.JNINamespace; |
12 | import org.chromium.content.browser.ContentViewCore; |
13 | |
14 | /** |
15 | * Java peer of the native class of the same name. |
16 | */ |
17 | @JNINamespace("web_contents_delegate_android") |
18 | public class WebContentsDelegateAndroid { |
19 | |
20 | // Equivalent of WebCore::WebConsoleMessage::LevelTip. |
21 | public static final int LOG_LEVEL_TIP = 0; |
22 | // Equivalent of WebCore::WebConsoleMessage::LevelLog. |
23 | public static final int LOG_LEVEL_LOG = 1; |
24 | // Equivalent of WebCore::WebConsoleMessage::LevelWarning. |
25 | public static final int LOG_LEVEL_WARNING = 2; |
26 | // Equivalent of WebCore::WebConsoleMessage::LevelError. |
27 | public static final int LOG_LEVEL_ERROR = 3; |
28 | |
29 | // Flags passed to the WebContentsDelegateAndroid.navigationStateChanged to tell it |
30 | // what has changed. Should match the values in invalidate_type.h. |
31 | // Equivalent of InvalidateTypes::INVALIDATE_TYPE_URL. |
32 | public static final int INVALIDATE_TYPE_URL = 1 << 0; |
33 | // Equivalent of InvalidateTypes::INVALIDATE_TYPE_TAB. |
34 | public static final int INVALIDATE_TYPE_TAB = 1 << 1; |
35 | // Equivalent of InvalidateTypes::INVALIDATE_TYPE_LOAD. |
36 | public static final int INVALIDATE_TYPE_LOAD = 1 << 2; |
37 | // Equivalent of InvalidateTypes::INVALIDATE_TYPE_PAGE_ACTIONS. |
38 | public static final int INVALIDATE_TYPE_PAGE_ACTIONS = 1 << 3; |
39 | // Equivalent of InvalidateTypes::INVALIDATE_TYPE_TITLE. |
40 | public static final int INVALIDATE_TYPE_TITLE = 1 << 4; |
41 | |
42 | // The most recent load progress callback received from WebContents, as a percentage. |
43 | // Initialize to 100 to indicate that we're not in a loading state. |
44 | private int mMostRecentProgress = 100; |
45 | |
46 | public int getMostRecentProgress() { |
47 | return mMostRecentProgress; |
48 | } |
49 | |
50 | /** |
51 | * @param disposition The new tab disposition as per the constants in |
52 | * org.chromium.ui.WindowOpenDisposition (See window_open_disposition_list.h |
53 | * for the enumeration definitions). |
54 | */ |
55 | @CalledByNative |
56 | public void openNewTab(String url, String extraHeaders, byte[] postData, int disposition) { |
57 | } |
58 | |
59 | @CalledByNative |
60 | public boolean addNewContents(int nativeSourceWebContents, int nativeWebContents, |
61 | int disposition, Rect initialPosition, boolean userGesture) { |
62 | return false; |
63 | } |
64 | |
65 | @CalledByNative |
66 | public void activateContents() { |
67 | } |
68 | |
69 | @CalledByNative |
70 | public void closeContents() { |
71 | } |
72 | |
73 | @CalledByNative |
74 | public void onLoadStarted() { |
75 | } |
76 | |
77 | @CalledByNative |
78 | public void onLoadStopped() { |
79 | } |
80 | |
81 | @CalledByNative |
82 | public void navigationStateChanged(int flags) { |
83 | } |
84 | |
85 | @SuppressWarnings("unused") |
86 | @CalledByNative |
87 | private final void notifyLoadProgressChanged(double progress) { |
88 | mMostRecentProgress = (int) (100.0 * progress); |
89 | onLoadProgressChanged(mMostRecentProgress); |
90 | } |
91 | |
92 | /** |
93 | * @param progress The load progress [0, 100] for the current web contents. |
94 | */ |
95 | public void onLoadProgressChanged(int progress) { |
96 | } |
97 | |
98 | /** |
99 | * Signaled when the renderer has been deemed to be unresponsive. |
100 | */ |
101 | @CalledByNative |
102 | public void rendererUnresponsive() { |
103 | } |
104 | |
105 | /** |
106 | * Signaled when the render has been deemed to be responsive. |
107 | */ |
108 | @CalledByNative |
109 | public void rendererResponsive() { |
110 | } |
111 | |
112 | @CalledByNative |
113 | public void onUpdateUrl(String url) { |
114 | } |
115 | |
116 | @CalledByNative |
117 | public boolean takeFocus(boolean reverse) { |
118 | return false; |
119 | } |
120 | |
121 | @CalledByNative |
122 | public void handleKeyboardEvent(KeyEvent event) { |
123 | // TODO(bulach): we probably want to re-inject the KeyEvent back into |
124 | // the system. Investigate if this is at all possible. |
125 | } |
126 | |
127 | /** |
128 | * Report a JavaScript console message. |
129 | * |
130 | * @param level message level. One of WebContentsDelegateAndroid.LOG_LEVEL*. |
131 | * @param message the error message. |
132 | * @param lineNumber the line number int the source file at which the error is reported. |
133 | * @param sourceId the name of the source file that caused the error. |
134 | * @return true if the client will handle logging the message. |
135 | */ |
136 | @CalledByNative |
137 | public boolean addMessageToConsole(int level, String message, int lineNumber, |
138 | String sourceId) { |
139 | return false; |
140 | } |
141 | |
142 | /** |
143 | * Report a form resubmission. The overwriter of this function should eventually call |
144 | * either of ContentViewCore.ContinuePendingReload or ContentViewCore.CancelPendingReload. |
145 | */ |
146 | @CalledByNative |
147 | public void showRepostFormWarningDialog(ContentViewCore contentViewCore) { |
148 | } |
149 | |
150 | @CalledByNative |
151 | public void toggleFullscreenModeForTab(boolean enterFullscreen) { |
152 | } |
153 | |
154 | @CalledByNative |
155 | public boolean isFullscreenForTabOrPending() { |
156 | return false; |
157 | } |
158 | |
159 | /** |
160 | * Called from WebKit to request that the top controls be shown or hidden. |
161 | * The implementation should call ContentViewCore.showTopControls to actually |
162 | * show or hide the top controls. |
163 | */ |
164 | @CalledByNative |
165 | public void didProgrammaticallyScroll(int scrollX, int scrollY) { |
166 | } |
167 | } |