1 // Copyright 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.
5 package org.chromium.components.web_contents_delegate_android;
7 import android.view.KeyEvent;
9 import org.chromium.base.CalledByNative;
10 import org.chromium.base.JNINamespace;
11 import org.chromium.content.browser.ContentViewCore;
14 * Java peer of the native class of the same name.
16 @JNINamespace("web_contents_delegate_android")
17 public class WebContentsDelegateAndroid {
19 // Equivalent of WebCore::WebConsoleMessage::LevelTip.
20 public static final int LOG_LEVEL_TIP = 0;
21 // Equivalent of WebCore::WebConsoleMessage::LevelLog.
22 public static final int LOG_LEVEL_LOG = 1;
23 // Equivalent of WebCore::WebConsoleMessage::LevelWarning.
24 public static final int LOG_LEVEL_WARNING = 2;
25 // Equivalent of WebCore::WebConsoleMessage::LevelError.
26 public static final int LOG_LEVEL_ERROR = 3;
28 // Flags passed to the WebContentsDelegateAndroid.navigationStateChanged to tell it
29 // what has changed. Should match the values in invalidate_type.h.
30 // Equivalent of InvalidateTypes::INVALIDATE_TYPE_URL.
31 public static final int INVALIDATE_TYPE_URL = 1 << 0;
32 // Equivalent of InvalidateTypes::INVALIDATE_TYPE_TAB.
33 public static final int INVALIDATE_TYPE_TAB = 1 << 1;
34 // Equivalent of InvalidateTypes::INVALIDATE_TYPE_LOAD.
35 public static final int INVALIDATE_TYPE_LOAD = 1 << 2;
36 // Equivalent of InvalidateTypes::INVALIDATE_TYPE_TITLE.
37 public static final int INVALIDATE_TYPE_TITLE = 1 << 3;
39 // The most recent load progress callback received from WebContents, as a percentage.
40 // Initialize to 100 to indicate that we're not in a loading state.
41 private int mMostRecentProgress = 100;
43 public int getMostRecentProgress() {
44 return mMostRecentProgress;
48 * @param disposition The new tab disposition as per the constants in
49 * org.chromium.ui.WindowOpenDisposition (See
50 * window_open_disposition_list.h for the enumeration definitions).
51 * @param isRendererInitiated Whether or not the renderer initiated this action.
54 public void openNewTab(String url, String extraHeaders, byte[] postData, int disposition,
55 boolean isRendererInitiated) {
59 public void activateContents() {
63 public void closeContents() {
67 public void onLoadStarted() {
71 public void onLoadStopped() {
75 public void navigationStateChanged(int flags) {
79 public void visibleSSLStateChanged() {
82 @SuppressWarnings("unused")
84 private final void notifyLoadProgressChanged(double progress) {
85 mMostRecentProgress = (int) (100.0 * progress);
86 onLoadProgressChanged(mMostRecentProgress);
90 * @param progress The load progress [0, 100] for the current web contents.
92 public void onLoadProgressChanged(int progress) {
96 * Signaled when the renderer has been deemed to be unresponsive.
99 public void rendererUnresponsive() {
103 * Signaled when the render has been deemed to be responsive.
106 public void rendererResponsive() {
110 public void onUpdateUrl(String url) {
114 public boolean takeFocus(boolean reverse) {
119 public void handleKeyboardEvent(KeyEvent event) {
120 // TODO(bulach): we probably want to re-inject the KeyEvent back into
121 // the system. Investigate if this is at all possible.
125 * Report a JavaScript console message.
127 * @param level message level. One of WebContentsDelegateAndroid.LOG_LEVEL*.
128 * @param message the error message.
129 * @param lineNumber the line number int the source file at which the error is reported.
130 * @param sourceId the name of the source file that caused the error.
131 * @return true if the client will handle logging the message.
134 public boolean addMessageToConsole(int level, String message, int lineNumber,
140 * Report a form resubmission. The overwriter of this function should eventually call
141 * either of ContentViewCore.ContinuePendingReload or ContentViewCore.CancelPendingReload.
144 public void showRepostFormWarningDialog(ContentViewCore contentViewCore) {
148 public void toggleFullscreenModeForTab(boolean enterFullscreen) {
152 public boolean isFullscreenForTabOrPending() {