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 5 package org.chromium.components.web_contents_delegate_android; 6 7 import android.view.KeyEvent; 8 9 import org.chromium.base.CalledByNative; 10 import org.chromium.base.JNINamespace; 11 import 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") 17 public 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_PAGE_ACTIONS. 37 public static final int INVALIDATE_TYPE_PAGE_ACTIONS = 1 << 3; 38 // Equivalent of InvalidateTypes::INVALIDATE_TYPE_TITLE. 39 public static final int INVALIDATE_TYPE_TITLE = 1 << 4; 40 41 // The most recent load progress callback received from WebContents, as a percentage. 42 // Initialize to 100 to indicate that we're not in a loading state. 43 private int mMostRecentProgress = 100; 44 getMostRecentProgress()45 public int getMostRecentProgress() { 46 return mMostRecentProgress; 47 } 48 49 /** 50 * @param disposition The new tab disposition as per the constants in 51 * org.chromium.ui.WindowOpenDisposition (See 52 * window_open_disposition_list.h for the enumeration definitions). 53 * @param isRendererInitiated Whether or not the renderer initiated this action. 54 */ 55 @CalledByNative openNewTab(String url, String extraHeaders, byte[] postData, int disposition, boolean isRendererInitiated)56 public void openNewTab(String url, String extraHeaders, byte[] postData, int disposition, 57 boolean isRendererInitiated) { 58 } 59 60 @CalledByNative activateContents()61 public void activateContents() { 62 } 63 64 @CalledByNative closeContents()65 public void closeContents() { 66 } 67 68 @CalledByNative onLoadStarted()69 public void onLoadStarted() { 70 } 71 72 @CalledByNative onLoadStopped()73 public void onLoadStopped() { 74 } 75 76 @CalledByNative navigationStateChanged(int flags)77 public void navigationStateChanged(int flags) { 78 } 79 80 @CalledByNative visibleSSLStateChanged()81 public void visibleSSLStateChanged() { 82 } 83 84 @SuppressWarnings("unused") 85 @CalledByNative notifyLoadProgressChanged(double progress)86 private final void notifyLoadProgressChanged(double progress) { 87 mMostRecentProgress = (int) (100.0 * progress); 88 onLoadProgressChanged(mMostRecentProgress); 89 } 90 91 /** 92 * @param progress The load progress [0, 100] for the current web contents. 93 */ onLoadProgressChanged(int progress)94 public void onLoadProgressChanged(int progress) { 95 } 96 97 /** 98 * Signaled when the renderer has been deemed to be unresponsive. 99 */ 100 @CalledByNative rendererUnresponsive()101 public void rendererUnresponsive() { 102 } 103 104 /** 105 * Signaled when the render has been deemed to be responsive. 106 */ 107 @CalledByNative rendererResponsive()108 public void rendererResponsive() { 109 } 110 111 @CalledByNative onUpdateUrl(String url)112 public void onUpdateUrl(String url) { 113 } 114 115 @CalledByNative takeFocus(boolean reverse)116 public boolean takeFocus(boolean reverse) { 117 return false; 118 } 119 120 @CalledByNative handleKeyboardEvent(KeyEvent event)121 public void handleKeyboardEvent(KeyEvent event) { 122 // TODO(bulach): we probably want to re-inject the KeyEvent back into 123 // the system. Investigate if this is at all possible. 124 } 125 126 /** 127 * Report a JavaScript console message. 128 * 129 * @param level message level. One of WebContentsDelegateAndroid.LOG_LEVEL*. 130 * @param message the error message. 131 * @param lineNumber the line number int the source file at which the error is reported. 132 * @param sourceId the name of the source file that caused the error. 133 * @return true if the client will handle logging the message. 134 */ 135 @CalledByNative addMessageToConsole(int level, String message, int lineNumber, String sourceId)136 public boolean addMessageToConsole(int level, String message, int lineNumber, 137 String sourceId) { 138 return false; 139 } 140 141 /** 142 * Report a form resubmission. The overwriter of this function should eventually call 143 * either of ContentViewCore.ContinuePendingReload or ContentViewCore.CancelPendingReload. 144 */ 145 @CalledByNative showRepostFormWarningDialog(ContentViewCore contentViewCore)146 public void showRepostFormWarningDialog(ContentViewCore contentViewCore) { 147 } 148 149 @CalledByNative toggleFullscreenModeForTab(boolean enterFullscreen)150 public void toggleFullscreenModeForTab(boolean enterFullscreen) { 151 } 152 153 @CalledByNative isFullscreenForTabOrPending()154 public boolean isFullscreenForTabOrPending() { 155 return false; 156 } 157 } 158