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.
4
5package org.chromium.components.web_contents_delegate_android;
6
7import android.view.KeyEvent;
8
9import org.chromium.base.CalledByNative;
10import org.chromium.base.JNINamespace;
11import org.chromium.content.browser.ContentViewCore;
12
13/**
14 * Java peer of the native class of the same name.
15 */
16@JNINamespace("web_contents_delegate_android")
17public class WebContentsDelegateAndroid {
18
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;
27
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;
38
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;
42
43    public int getMostRecentProgress() {
44        return mMostRecentProgress;
45    }
46
47    /**
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.
52     */
53    @CalledByNative
54    public void openNewTab(String url, String extraHeaders, byte[] postData, int disposition,
55            boolean isRendererInitiated) {
56    }
57
58    @CalledByNative
59    public void activateContents() {
60    }
61
62    @CalledByNative
63    public void closeContents() {
64    }
65
66    @CalledByNative
67    public void onLoadStarted() {
68    }
69
70    @CalledByNative
71    public void onLoadStopped() {
72    }
73
74    @CalledByNative
75    public void navigationStateChanged(int flags) {
76    }
77
78    @CalledByNative
79    public void visibleSSLStateChanged() {
80    }
81
82    @SuppressWarnings("unused")
83    @CalledByNative
84    private final void notifyLoadProgressChanged(double progress) {
85        mMostRecentProgress = (int) (100.0 * progress);
86        onLoadProgressChanged(mMostRecentProgress);
87    }
88
89    /**
90     * @param progress The load progress [0, 100] for the current web contents.
91     */
92    public void onLoadProgressChanged(int progress) {
93    }
94
95    /**
96     * Signaled when the renderer has been deemed to be unresponsive.
97     */
98    @CalledByNative
99    public void rendererUnresponsive() {
100    }
101
102    /**
103     * Signaled when the render has been deemed to be responsive.
104     */
105    @CalledByNative
106    public void rendererResponsive() {
107    }
108
109    @CalledByNative
110    public void onUpdateUrl(String url) {
111    }
112
113    @CalledByNative
114    public boolean takeFocus(boolean reverse) {
115        return false;
116    }
117
118    @CalledByNative
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.
122    }
123
124    /**
125     * Report a JavaScript console message.
126     *
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.
132     */
133    @CalledByNative
134    public boolean addMessageToConsole(int level, String message, int lineNumber,
135            String sourceId) {
136        return false;
137    }
138
139    /**
140     * Report a form resubmission. The overwriter of this function should eventually call
141     * either of ContentViewCore.ContinuePendingReload or ContentViewCore.CancelPendingReload.
142     */
143    @CalledByNative
144    public void showRepostFormWarningDialog(ContentViewCore contentViewCore) {
145    }
146
147    @CalledByNative
148    public void toggleFullscreenModeForTab(boolean enterFullscreen) {
149    }
150
151    @CalledByNative
152    public boolean isFullscreenForTabOrPending() {
153        return false;
154    }
155}
156