This source file includes following definitions.
- JNINamespace
- overScrollBy
- super_scrollTo
- setMeasuredDimension
- super_getScrollBarStyle
- requestDrawGL
- executeHardwareAction
- createLayoutSizer
- createScrollOffsetManager
- run
- getCacheMode
- shouldInterceptRequest
- shouldBlockContentUrls
- shouldBlockFileUrls
- shouldBlockNetworkLoads
- onDownloadStart
- newLoginRequest
- shouldIgnoreNavigation
- requestLayout
- setMeasuredDimension
- setFixedLayoutSize
- isLayoutParamsHeightWrapContent
- overScrollContainerViewBy
- scrollContainerViewTo
- scrollNativeTo
- getContainerViewScrollX
- getContainerViewScrollY
- invalidate
- onPinchStarted
- onPinchEnded
- onFlingCancelGesture
- onUnhandledFlingStartEvent
- onScrollUpdateGestureConsumed
- onTrimMemory
- onLowMemory
- onConfigurationChanged
- onLayoutChange
- createAndInitializeContentViewCore
- setNewAwContents
- supplyContentsForPopup
- receivePopupContents
- destroy
- getContentViewCore
- getSettings
- getPdfExporter
- setAwDrawSWFunctionTable
- setAwDrawGLFunctionTable
- getAwDrawGLFunction
- setShouldDownloadFavicons
- disableJavascriptInterfacesInspection
- getNativeInstanceCount
- getAwDrawGLViewContext
- getGlobalVisibleRect
- onDraw
- onMeasure
- getContentHeightCss
- getContentWidthCss
- capturePicture
- clearView
- enableOnNewPicture
- findAllAsync
- findNext
- clearMatches
- getMostRecentProgress
- getFavicon
- requestVisitedHistoryFromClient
- loadUrl
- getUrl
- requestFocus
- setBackgroundColor
- setLayerType
- updateHardwareAcceleratedFeaturesToggle
- getEffectiveBackgroundColor
- isMultiTouchZoomSupported
- getZoomControlsForTest
- getContentSettings
- setOverScrollMode
- setScrollBarStyle
- setHorizontalScrollbarOverlay
- setVerticalScrollbarOverlay
- overlayHorizontalScrollbar
- overlayVerticalScrollbar
- onContainerViewScrollChanged
- onContainerViewOverScrolled
- requestChildRectangleOnScreen
- computeScroll
- computeHorizontalScrollRange
- computeHorizontalScrollOffset
- computeVerticalScrollRange
- computeVerticalScrollOffset
- computeVerticalScrollExtent
- stopLoading
- reload
- canGoBack
- goBack
- canGoForward
- goForward
- canGoBackOrForward
- goBackOrForward
- pauseTimers
- resumeTimers
- onPause
- onResume
- isPaused
- onCreateInputConnection
- onKeyUp
- isDpadEvent
- dispatchKeyEvent
- clearCache
- documentHasImages
- saveWebArchive
- getOriginalUrl
- getNavigationHistory
- getTitle
- clearHistory
- getHttpAuthUsernamePassword
- setHttpAuthUsernamePassword
- getCertificate
- clearSslPreferences
- getLastHitTestResult
- requestFocusNodeHref
- requestImageRef
- getPageScaleFactor
- getScale
- flingScroll
- pageUp
- pageDown
- canZoomIn
- canZoomOut
- zoomIn
- zoomOut
- invokeZoomPicker
- evaluateJavaScript
- evaluateJavaScriptEvenIfNotYetNavigated
- onTouchEvent
- onHoverEvent
- onGenericMotionEvent
- onConfigurationChanged
- onAttachedToWindow
- SuppressLint
- onDetachedFromWindow
- onWindowFocusChanged
- onFocusChanged
- onSizeChanged
- onVisibilityChanged
- onWindowVisibilityChanged
- setViewVisibilityInternal
- setWindowVisibilityInternal
- saveState
- restoreState
- addPossiblyUnsafeJavascriptInterface
- removeJavascriptInterface
- getAccessibilityNodeProvider
- onInitializeAccessibilityNodeInfo
- onInitializeAccessibilityEvent
- supportsAccessibilityAction
- performAccessibilityAction
- hideAutofillPopup
- setNetworkAvailable
- onDocumentHasImagesResponse
- onReceivedTouchIconUrl
- onReceivedIcon
- generateMHTMLCallback
- onReceivedHttpAuthRequest
- invoke
- onGeolocationPermissionsShowPrompt
- onGeolocationPermissionsHidePrompt
- onFindResultReceived
- onNewPicture
- updateHitTestData
- requestDrawGL
- postInvalidateOnAnimation
- getLocationOnScreen
- onWebLayoutPageScaleFactorChanged
- onWebLayoutContentsSizeChanged
- setMaxContainerViewScrollOffset
- scrollContainerViewTo
- isFlingActive
- setContentsSize
- setPageScaleFactorAndLimits
- setAwAutofillManagerDelegate
- didOverscroll
- saveWebArchiveInternal
- generateArchiveAutoNamePath
- extractSmartClipData
- setSmartClipDataListener
- nativeInit
- nativeDestroy
- nativeSetAwDrawSWFunctionTable
- nativeSetAwDrawGLFunctionTable
- nativeGetAwDrawGLFunction
- nativeGetNativeInstanceCount
- nativeSetShouldDownloadFavicons
- nativeSetJavaPeers
- nativeGetWebContents
- nativeDocumentHasImages
- nativeGenerateMHTML
- nativeAddVisitedLinks
- nativeOnDraw
- nativeFindAllAsync
- nativeFindNext
- nativeClearMatches
- nativeClearCache
- nativeGetCertificate
- nativeRequestNewHitTestDataAt
- nativeUpdateLastHitTestData
- nativeOnSizeChanged
- nativeScrollTo
- nativeSetViewVisibility
- nativeSetWindowVisibility
- nativeSetIsPaused
- nativeOnAttachedToWindow
- nativeOnDetachedFromWindow
- nativeReleaseHardwareDrawOnRenderThread
- nativeSetDipScale
- nativeSetFixedLayoutSize
- nativeGetOpaqueState
- nativeRestoreFromOpaqueState
- nativeReleasePopupAwContents
- nativeFocusFirstNode
- nativeSetBackgroundColor
- nativeGetAwDrawGLViewContext
- nativeCapturePicture
- nativeEnableOnNewPicture
- nativeClearView
- nativeSetExtraHeadersForUrl
- nativeInvokeGeolocationCallback
- nativeSetJsOnlineProperty
- nativeTrimMemoryOnRenderThread
- nativeCreatePdfExporter
package org.chromium.android_webview;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Picture;
import android.graphics.Rect;
import android.net.http.SslCertificate;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.AccessibilityNodeProvider;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.webkit.GeolocationPermissions;
import android.webkit.ValueCallback;
import android.widget.OverScroller;
import com.google.common.annotations.VisibleForTesting;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import org.chromium.base.ThreadUtils;
import org.chromium.components.navigation_interception.InterceptNavigationDelegate;
import org.chromium.components.navigation_interception.NavigationParams;
import org.chromium.content.browser.ContentSettings;
import org.chromium.content.browser.ContentViewClient;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.content.browser.ContentViewStatics;
import org.chromium.content.browser.LoadUrlParams;
import org.chromium.content.browser.NavigationHistory;
import org.chromium.content.browser.PageTransitionTypes;
import org.chromium.content.common.CleanupReference;
import org.chromium.content_public.browser.GestureStateListener;
import org.chromium.ui.base.ActivityWindowAndroid;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.gfx.DeviceDisplayInfo;
import java.io.File;
import java.lang.annotation.Annotation;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Callable;
@JNINamespace("android_webview")
public class AwContents {
private static final String TAG = "AwContents";
private static final String WEB_ARCHIVE_EXTENSION = ".mht";
private static final float ZOOM_CONTROLS_EPSILON = 0.007f;
public static class HitTestData {
public int hitTestResultType;
public String hitTestResultExtraData;
public String href;
public String anchorText;
public String imgSrc;
}
public interface InternalAccessDelegate extends ContentViewCore.InternalAccessDelegate {
void overScrollBy(int deltaX, int deltaY,
int scrollX, int scrollY,
int scrollRangeX, int scrollRangeY,
int maxOverScrollX, int maxOverScrollY,
boolean isTouchEvent);
void super_scrollTo(int scrollX, int scrollY);
void setMeasuredDimension(int measuredWidth, int measuredHeight);
int super_getScrollBarStyle();
boolean requestDrawGL(Canvas canvas);
public boolean executeHardwareAction(Runnable action);
}
public static class DependencyFactory {
public AwLayoutSizer createLayoutSizer() {
return new AwLayoutSizer();
}
public AwScrollOffsetManager createScrollOffsetManager(
AwScrollOffsetManager.Delegate delegate, OverScroller overScroller) {
return new AwScrollOffsetManager(delegate, overScroller);
}
}
private long mNativeAwContents;
private final AwBrowserContext mBrowserContext;
private final ViewGroup mContainerView;
private ContentViewCore mContentViewCore;
private final AwContentsClient mContentsClient;
private final AwContentViewClient mContentViewClient;
private final AwContentsClientBridge mContentsClientBridge;
private final AwWebContentsDelegate mWebContentsDelegate;
private final AwContentsIoThreadClient mIoThreadClient;
private final InterceptNavigationDelegateImpl mInterceptNavigationDelegate;
private final InternalAccessDelegate mInternalAccessAdapter;
private final AwLayoutSizer mLayoutSizer;
private final AwZoomControls mZoomControls;
private final AwScrollOffsetManager mScrollOffsetManager;
private OverScrollGlow mOverScrollGlow;
private final AwSettings mSettings;
private final ScrollAccessibilityHelper mScrollAccessibilityHelper;
private boolean mIsPaused;
private boolean mIsViewVisible;
private boolean mIsWindowVisible;
private boolean mIsAttachedToWindow;
private Bitmap mFavicon;
private boolean mHasRequestedVisitedHistoryFromClient;
private final double mDIPScale;
private int mBaseBackgroundColor = Color.WHITE;
private int mLayerType = View.LAYER_TYPE_NONE;
private final HitTestData mPossiblyStaleHitTestData = new HitTestData();
private final DefaultVideoPosterRequestHandler mDefaultVideoPosterRequestHandler;
private Callable<Picture> mPictureListenerContentProvider;
private boolean mContainerViewFocused;
private boolean mWindowFocused;
private float mPageScaleFactor = 1.0f;
private float mMinPageScaleFactor = 1.0f;
private float mMaxPageScaleFactor = 1.0f;
private float mContentWidthDip;
private float mContentHeightDip;
private AwAutofillManagerDelegate mAwAutofillManagerDelegate;
private ComponentCallbacks2 mComponentCallbacks;
private AwPdfExporter mAwPdfExporter;
private boolean mDeferredShouldOverrideUrlLoadingIsPendingForPopup;
private static final class DestroyRunnable implements Runnable {
private final long mNativeAwContents;
private DestroyRunnable(long nativeAwContents) {
mNativeAwContents = nativeAwContents;
}
@Override
public void run() {
nativeOnDetachedFromWindow(mNativeAwContents);
nativeDestroy(mNativeAwContents);
}
}
private CleanupReference mCleanupReference;
private List<CleanupReference> mPendingDetachCleanupReferences;
private class IoThreadClientImpl implements AwContentsIoThreadClient {
@Override
public int getCacheMode() {
return mSettings.getCacheMode();
}
@Override
public InterceptedRequestData shouldInterceptRequest(final String url,
boolean isMainFrame) {
InterceptedRequestData interceptedRequestData;
interceptedRequestData = mDefaultVideoPosterRequestHandler.shouldInterceptRequest(url);
if (interceptedRequestData != null) return interceptedRequestData;
interceptedRequestData = mContentsClient.shouldInterceptRequest(url);
if (interceptedRequestData == null) {
mContentsClient.getCallbackHelper().postOnLoadResource(url);
}
if (isMainFrame && interceptedRequestData != null &&
interceptedRequestData.getData() == null) {
mContentsClient.getCallbackHelper().postOnReceivedError(
ErrorCodeConversionHelper.ERROR_UNKNOWN,
null , url);
}
return interceptedRequestData;
}
@Override
public boolean shouldBlockContentUrls() {
return !mSettings.getAllowContentAccess();
}
@Override
public boolean shouldBlockFileUrls() {
return !mSettings.getAllowFileAccess();
}
@Override
public boolean shouldBlockNetworkLoads() {
return mSettings.getBlockNetworkLoads();
}
@Override
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimeType, long contentLength) {
mContentsClient.getCallbackHelper().postOnDownloadStart(url, userAgent,
contentDisposition, mimeType, contentLength);
}
@Override
public void newLoginRequest(String realm, String account, String args) {
mContentsClient.getCallbackHelper().postOnReceivedLoginRequest(realm, account, args);
}
}
private class InterceptNavigationDelegateImpl implements InterceptNavigationDelegate {
@Override
public boolean shouldIgnoreNavigation(NavigationParams navigationParams) {
final String url = navigationParams.url;
boolean ignoreNavigation = false;
if (mDeferredShouldOverrideUrlLoadingIsPendingForPopup) {
mDeferredShouldOverrideUrlLoadingIsPendingForPopup = false;
if (!navigationParams.isPost) {
ignoreNavigation = mContentsClient.shouldOverrideUrlLoading(url);
}
}
if (!ignoreNavigation) {
mContentsClient.getCallbackHelper().postOnPageStarted(url);
}
return ignoreNavigation;
}
}
private class AwLayoutSizerDelegate implements AwLayoutSizer.Delegate {
@Override
public void requestLayout() {
mContainerView.requestLayout();
}
@Override
public void setMeasuredDimension(int measuredWidth, int measuredHeight) {
mInternalAccessAdapter.setMeasuredDimension(measuredWidth, measuredHeight);
}
@Override
public void setFixedLayoutSize(int widthDip, int heightDip) {
if (mNativeAwContents == 0) return;
nativeSetFixedLayoutSize(mNativeAwContents, widthDip, heightDip);
}
@Override
public boolean isLayoutParamsHeightWrapContent() {
return mContainerView.getLayoutParams() != null &&
mContainerView.getLayoutParams().height == ViewGroup.LayoutParams.WRAP_CONTENT;
}
}
private class AwScrollOffsetManagerDelegate implements AwScrollOffsetManager.Delegate {
@Override
public void overScrollContainerViewBy(int deltaX, int deltaY, int scrollX, int scrollY,
int scrollRangeX, int scrollRangeY, boolean isTouchEvent) {
mInternalAccessAdapter.overScrollBy(deltaX, deltaY, scrollX, scrollY,
scrollRangeX, scrollRangeY, 0, 0, isTouchEvent);
}
@Override
public void scrollContainerViewTo(int x, int y) {
mInternalAccessAdapter.super_scrollTo(x, y);
}
@Override
public void scrollNativeTo(int x, int y) {
if (mNativeAwContents == 0) return;
nativeScrollTo(mNativeAwContents, x, y);
}
@Override
public int getContainerViewScrollX() {
return mContainerView.getScrollX();
}
@Override
public int getContainerViewScrollY() {
return mContainerView.getScrollY();
}
@Override
public void invalidate() {
mContainerView.invalidate();
}
}
private class AwGestureStateListener extends GestureStateListener {
@Override
public void onPinchStarted() {
mLayoutSizer.freezeLayoutRequests();
}
@Override
public void onPinchEnded() {
mLayoutSizer.unfreezeLayoutRequests();
}
@Override
public void onFlingCancelGesture() {
mScrollOffsetManager.onFlingCancelGesture();
}
@Override
public void onUnhandledFlingStartEvent(int velocityX, int velocityY) {
mScrollOffsetManager.onUnhandledFlingStartEvent(velocityX, velocityY);
}
@Override
public void onScrollUpdateGestureConsumed() {
mScrollAccessibilityHelper.postViewScrolledAccessibilityEventCallback();
}
}
private class AwComponentCallbacks implements ComponentCallbacks2 {
@Override
public void onTrimMemory(final int level) {
if (mNativeAwContents == 0) return;
boolean visibleRectEmpty = getGlobalVisibleRect().isEmpty();
final boolean visible = mIsViewVisible && mIsWindowVisible && !visibleRectEmpty;
mInternalAccessAdapter.executeHardwareAction(new Runnable() {
@Override
public void run() {
nativeTrimMemoryOnRenderThread(mNativeAwContents, level, visible);
}
});
}
@Override
public void onLowMemory() {}
@Override
public void onConfigurationChanged(Configuration configuration) {}
};
private class AwLayoutChangeListener implements View.OnLayoutChangeListener {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) {
assert v == mContainerView;
mLayoutSizer.onLayoutChange();
}
}
public AwContents(AwBrowserContext browserContext, ViewGroup containerView,
InternalAccessDelegate internalAccessAdapter, AwContentsClient contentsClient,
AwSettings awSettings) {
this(browserContext, containerView, internalAccessAdapter, contentsClient, awSettings,
new DependencyFactory());
}
public AwContents(AwBrowserContext browserContext, ViewGroup containerView,
InternalAccessDelegate internalAccessAdapter, AwContentsClient contentsClient,
AwSettings settings, DependencyFactory dependencyFactory) {
mBrowserContext = browserContext;
mContainerView = containerView;
mInternalAccessAdapter = internalAccessAdapter;
mContentsClient = contentsClient;
mContentViewClient = new AwContentViewClient(contentsClient, settings);
mLayoutSizer = dependencyFactory.createLayoutSizer();
mSettings = settings;
mDIPScale = DeviceDisplayInfo.create(mContainerView.getContext()).getDIPScale();
mLayoutSizer.setDelegate(new AwLayoutSizerDelegate());
mLayoutSizer.setDIPScale(mDIPScale);
mWebContentsDelegate = new AwWebContentsDelegateAdapter(contentsClient, mContainerView);
mContentsClientBridge = new AwContentsClientBridge(contentsClient);
mZoomControls = new AwZoomControls(this);
mIoThreadClient = new IoThreadClientImpl();
mInterceptNavigationDelegate = new InterceptNavigationDelegateImpl();
AwSettings.ZoomSupportChangeListener zoomListener =
new AwSettings.ZoomSupportChangeListener() {
@Override
public void onGestureZoomSupportChanged(
boolean supportsDoubleTapZoom, boolean supportsMultiTouchZoom) {
mContentViewCore.updateDoubleTapSupport(supportsDoubleTapZoom);
mContentViewCore.updateMultiTouchZoomSupport(supportsMultiTouchZoom);
}
};
mSettings.setZoomListener(zoomListener);
mDefaultVideoPosterRequestHandler = new DefaultVideoPosterRequestHandler(mContentsClient);
mSettings.setDefaultVideoPosterURL(
mDefaultVideoPosterRequestHandler.getDefaultVideoPosterURL());
mSettings.setDIPScale(mDIPScale);
mScrollOffsetManager = dependencyFactory.createScrollOffsetManager(
new AwScrollOffsetManagerDelegate(), new OverScroller(mContainerView.getContext()));
mScrollAccessibilityHelper = new ScrollAccessibilityHelper(mContainerView);
setOverScrollMode(mContainerView.getOverScrollMode());
setScrollBarStyle(mInternalAccessAdapter.super_getScrollBarStyle());
mContainerView.addOnLayoutChangeListener(new AwLayoutChangeListener());
setNewAwContents(nativeInit(mBrowserContext));
onVisibilityChanged(mContainerView, mContainerView.getVisibility());
onWindowVisibilityChanged(mContainerView.getWindowVisibility());
}
private static ContentViewCore createAndInitializeContentViewCore(ViewGroup containerView,
InternalAccessDelegate internalDispatcher, long nativeWebContents,
GestureStateListener gestureStateListener,
ContentViewClient contentViewClient,
ContentViewCore.ZoomControlsDelegate zoomControlsDelegate) {
Context context = containerView.getContext();
ContentViewCore contentViewCore = new ContentViewCore(context);
contentViewCore.initialize(containerView, internalDispatcher, nativeWebContents,
context instanceof Activity ?
new ActivityWindowAndroid((Activity) context) :
new WindowAndroid(context.getApplicationContext()));
contentViewCore.addGestureStateListener(gestureStateListener);
contentViewCore.setContentViewClient(contentViewClient);
contentViewCore.setZoomControlsDelegate(zoomControlsDelegate);
return contentViewCore;
}
private void setNewAwContents(long newAwContentsPtr) {
if (mNativeAwContents != 0) {
destroy();
mContentViewCore = null;
}
assert mNativeAwContents == 0 && mCleanupReference == null && mContentViewCore == null;
mNativeAwContents = newAwContentsPtr;
mCleanupReference = new CleanupReference(this, new DestroyRunnable(mNativeAwContents));
long nativeWebContents = nativeGetWebContents(mNativeAwContents);
mContentViewCore = createAndInitializeContentViewCore(
mContainerView, mInternalAccessAdapter, nativeWebContents,
new AwGestureStateListener(), mContentViewClient, mZoomControls);
nativeSetJavaPeers(mNativeAwContents, this, mWebContentsDelegate, mContentsClientBridge,
mIoThreadClient, mInterceptNavigationDelegate);
mContentsClient.installWebContentsObserver(mContentViewCore);
mSettings.setWebContents(nativeWebContents);
nativeSetDipScale(mNativeAwContents, (float) mDIPScale);
mContentViewCore.onShow();
}
public void supplyContentsForPopup(AwContents newContents) {
long popupNativeAwContents = nativeReleasePopupAwContents(mNativeAwContents);
if (popupNativeAwContents == 0) {
Log.w(TAG, "Popup WebView bind failed: no pending content.");
if (newContents != null) newContents.destroy();
return;
}
if (newContents == null) {
nativeDestroy(popupNativeAwContents);
return;
}
newContents.receivePopupContents(popupNativeAwContents);
}
private void receivePopupContents(long popupNativeAwContents) {
mDeferredShouldOverrideUrlLoadingIsPendingForPopup = true;
final boolean wasAttached = mIsAttachedToWindow;
final boolean wasViewVisible = mIsViewVisible;
final boolean wasWindowVisible = mIsWindowVisible;
final boolean wasPaused = mIsPaused;
final boolean wasFocused = mContainerViewFocused;
final boolean wasWindowFocused = mWindowFocused;
if (wasFocused) onFocusChanged(false, 0, null);
if (wasWindowFocused) onWindowFocusChanged(false);
if (wasViewVisible) setViewVisibilityInternal(false);
if (wasWindowVisible) setWindowVisibilityInternal(false);
if (!wasPaused) onPause();
setNewAwContents(popupNativeAwContents);
if (!wasPaused) onResume();
if (wasAttached) onAttachedToWindow();
onSizeChanged(mContainerView.getWidth(), mContainerView.getHeight(), 0, 0);
if (wasWindowVisible) setWindowVisibilityInternal(true);
if (wasViewVisible) setViewVisibilityInternal(true);
if (wasWindowFocused) onWindowFocusChanged(wasWindowFocused);
if (wasFocused) onFocusChanged(true, 0, null);
}
public void destroy() {
if (mCleanupReference != null) {
mContentViewCore.destroy();
mNativeAwContents = 0;
if (mIsAttachedToWindow) {
if (mPendingDetachCleanupReferences == null) {
mPendingDetachCleanupReferences = new ArrayList<CleanupReference>();
}
mPendingDetachCleanupReferences.add(mCleanupReference);
} else {
mCleanupReference.cleanupNow();
}
mCleanupReference = null;
}
assert !mContentViewCore.isAlive();
assert mNativeAwContents == 0;
}
@VisibleForTesting
public ContentViewCore getContentViewCore() {
return mContentViewCore;
}
public AwSettings getSettings() {
return mSettings;
}
public AwPdfExporter getPdfExporter() {
if (mNativeAwContents == 0) {
return null;
}
if (mAwPdfExporter == null) {
mAwPdfExporter = new AwPdfExporter(mContainerView);
nativeCreatePdfExporter(mNativeAwContents, mAwPdfExporter);
}
return mAwPdfExporter;
}
public static void setAwDrawSWFunctionTable(long functionTablePointer) {
nativeSetAwDrawSWFunctionTable(functionTablePointer);
}
public static void setAwDrawGLFunctionTable(long functionTablePointer) {
nativeSetAwDrawGLFunctionTable(functionTablePointer);
}
public static long getAwDrawGLFunction() {
return nativeGetAwDrawGLFunction();
}
public static void setShouldDownloadFavicons() {
nativeSetShouldDownloadFavicons();
}
public void disableJavascriptInterfacesInspection() {
mContentViewCore.setAllowJavascriptInterfacesInspection(false);
}
@VisibleForTesting
public static int getNativeInstanceCount() {
return nativeGetNativeInstanceCount();
}
public long getAwDrawGLViewContext() {
assert mNativeAwContents != 0;
return nativeGetAwDrawGLViewContext(mNativeAwContents);
}
private static final Rect sLocalGlobalVisibleRect = new Rect();
private Rect getGlobalVisibleRect() {
if (!mContainerView.getGlobalVisibleRect(sLocalGlobalVisibleRect)) {
sLocalGlobalVisibleRect.setEmpty();
}
return sLocalGlobalVisibleRect;
}
private final Rect mClipBoundsTemporary = new Rect();
public void onDraw(Canvas canvas) {
if (mNativeAwContents == 0) {
canvas.drawColor(getEffectiveBackgroundColor());
return;
}
mScrollOffsetManager.syncScrollOffsetFromOnDraw();
canvas.getClipBounds(mClipBoundsTemporary);
Rect globalVisibleRect = getGlobalVisibleRect();
if (!nativeOnDraw(mNativeAwContents, canvas, canvas.isHardwareAccelerated(),
mContainerView.getScrollX(), mContainerView.getScrollY(),
globalVisibleRect.left, globalVisibleRect.top,
globalVisibleRect.right, globalVisibleRect.bottom,
mClipBoundsTemporary.left, mClipBoundsTemporary.top,
mClipBoundsTemporary.right, mClipBoundsTemporary.bottom)) {
canvas.drawColor(getEffectiveBackgroundColor());
}
if (mOverScrollGlow != null && mOverScrollGlow.drawEdgeGlows(canvas,
mScrollOffsetManager.computeMaximumHorizontalScrollOffset(),
mScrollOffsetManager.computeMaximumVerticalScrollOffset())) {
mContainerView.invalidate();
}
}
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
mLayoutSizer.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
public int getContentHeightCss() {
return (int) Math.ceil(mContentHeightDip);
}
public int getContentWidthCss() {
return (int) Math.ceil(mContentWidthDip);
}
public Picture capturePicture() {
if (mNativeAwContents == 0) return null;
return new AwPicture(nativeCapturePicture(mNativeAwContents,
mScrollOffsetManager.computeHorizontalScrollRange(),
mScrollOffsetManager.computeVerticalScrollRange()));
}
public void clearView() {
if (mNativeAwContents == 0) return;
nativeClearView(mNativeAwContents);
}
public void enableOnNewPicture(boolean enabled, boolean invalidationOnly) {
if (mNativeAwContents == 0) return;
if (invalidationOnly) {
mPictureListenerContentProvider = null;
} else if (enabled && mPictureListenerContentProvider == null) {
mPictureListenerContentProvider = new Callable<Picture>() {
@Override
public Picture call() {
return capturePicture();
}
};
}
nativeEnableOnNewPicture(mNativeAwContents, enabled);
}
public void findAllAsync(String searchString) {
if (mNativeAwContents == 0) return;
nativeFindAllAsync(mNativeAwContents, searchString);
}
public void findNext(boolean forward) {
if (mNativeAwContents == 0) return;
nativeFindNext(mNativeAwContents, forward);
}
public void clearMatches() {
if (mNativeAwContents == 0) return;
nativeClearMatches(mNativeAwContents);
}
public int getMostRecentProgress() {
return mWebContentsDelegate.getMostRecentProgress();
}
public Bitmap getFavicon() {
return mFavicon;
}
private void requestVisitedHistoryFromClient() {
ValueCallback<String[]> callback = new ValueCallback<String[]>() {
@Override
public void onReceiveValue(final String[] value) {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
if (mNativeAwContents == 0) return;
nativeAddVisitedLinks(mNativeAwContents, value);
}
});
}
};
mContentsClient.getVisitedHistory(callback);
}
public void loadUrl(LoadUrlParams params) {
if (params.getLoadUrlType() == LoadUrlParams.LOAD_TYPE_DATA &&
!params.isBaseUrlDataScheme()) {
params.setCanLoadLocalResources(true);
}
if (params.getUrl() != null &&
params.getUrl().equals(mContentViewCore.getUrl()) &&
params.getTransitionType() == PageTransitionTypes.PAGE_TRANSITION_LINK) {
params.setTransitionType(PageTransitionTypes.PAGE_TRANSITION_RELOAD);
}
params.setTransitionType(
params.getTransitionType() | PageTransitionTypes.PAGE_TRANSITION_FROM_API);
params.setOverrideUserAgent(LoadUrlParams.UA_OVERRIDE_TRUE);
if (mNativeAwContents != 0) {
nativeSetExtraHeadersForUrl(
mNativeAwContents, params.getUrl(), params.getExtraHttpRequestHeadersString());
}
params.setExtraHeaders(new HashMap<String, String>());
mContentViewCore.loadUrl(params);
if (!mHasRequestedVisitedHistoryFromClient) {
mHasRequestedVisitedHistoryFromClient = true;
requestVisitedHistoryFromClient();
}
if (params.getLoadUrlType() == LoadUrlParams.LOAD_TYPE_DATA &&
params.getBaseUrl() != null) {
mContentsClient.getCallbackHelper().postOnPageStarted(params.getBaseUrl());
}
}
public String getUrl() {
String url = mContentViewCore.getUrl();
if (url == null || url.trim().isEmpty()) return null;
return url;
}
public void requestFocus() {
if (mNativeAwContents == 0) return;
if (!mContainerView.isInTouchMode() && mSettings.shouldFocusFirstNode()) {
nativeFocusFirstNode(mNativeAwContents);
}
}
public void setBackgroundColor(int color) {
mBaseBackgroundColor = color;
if (mNativeAwContents != 0) nativeSetBackgroundColor(mNativeAwContents, color);
}
public void setLayerType(int layerType, Paint paint) {
mLayerType = layerType;
updateHardwareAcceleratedFeaturesToggle();
}
private void updateHardwareAcceleratedFeaturesToggle() {
mSettings.setEnableSupportedHardwareAcceleratedFeatures(
mIsAttachedToWindow && mContainerView.isHardwareAccelerated() &&
(mLayerType == View.LAYER_TYPE_NONE || mLayerType == View.LAYER_TYPE_HARDWARE));
}
private int getEffectiveBackgroundColor() {
if (mNativeAwContents == 0 || !mContentsClient.isCachedRendererBackgroundColorValid()) {
return mBaseBackgroundColor;
}
return mContentsClient.getCachedRendererBackgroundColor();
}
public boolean isMultiTouchZoomSupported() {
return mSettings.supportsMultiTouchZoom();
}
public View getZoomControlsForTest() {
return mZoomControls.getZoomControlsViewForTest();
}
public ContentSettings getContentSettings() {
return mContentViewCore.getContentSettings();
}
public void setOverScrollMode(int mode) {
if (mode != View.OVER_SCROLL_NEVER) {
mOverScrollGlow = new OverScrollGlow(mContainerView);
} else {
mOverScrollGlow = null;
}
}
private boolean mOverlayHorizontalScrollbar = true;
private boolean mOverlayVerticalScrollbar = false;
public void setScrollBarStyle(int style) {
if (style == View.SCROLLBARS_INSIDE_OVERLAY
|| style == View.SCROLLBARS_OUTSIDE_OVERLAY) {
mOverlayHorizontalScrollbar = mOverlayVerticalScrollbar = true;
} else {
mOverlayHorizontalScrollbar = mOverlayVerticalScrollbar = false;
}
}
public void setHorizontalScrollbarOverlay(boolean overlay) {
mOverlayHorizontalScrollbar = overlay;
}
public void setVerticalScrollbarOverlay(boolean overlay) {
mOverlayVerticalScrollbar = overlay;
}
public boolean overlayHorizontalScrollbar() {
return mOverlayHorizontalScrollbar;
}
public boolean overlayVerticalScrollbar() {
return mOverlayVerticalScrollbar;
}
public void onContainerViewScrollChanged(int l, int t, int oldl, int oldt) {
mScrollAccessibilityHelper.removePostedViewScrolledAccessibilityEventCallback();
mScrollOffsetManager.onContainerViewScrollChanged(l, t);
}
public void onContainerViewOverScrolled(int scrollX, int scrollY, boolean clampedX,
boolean clampedY) {
int oldX = mContainerView.getScrollX();
int oldY = mContainerView.getScrollY();
mScrollOffsetManager.onContainerViewOverScrolled(scrollX, scrollY, clampedX, clampedY);
if (mOverScrollGlow != null) {
mOverScrollGlow.pullGlow(mContainerView.getScrollX(), mContainerView.getScrollY(),
oldX, oldY,
mScrollOffsetManager.computeMaximumHorizontalScrollOffset(),
mScrollOffsetManager.computeMaximumVerticalScrollOffset());
}
}
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {
return mScrollOffsetManager.requestChildRectangleOnScreen(
child.getLeft() - child.getScrollX(), child.getTop() - child.getScrollY(),
rect, immediate);
}
public void computeScroll() {
mScrollOffsetManager.computeScrollAndAbsorbGlow(mOverScrollGlow);
}
public int computeHorizontalScrollRange() {
return mScrollOffsetManager.computeHorizontalScrollRange();
}
public int computeHorizontalScrollOffset() {
return mScrollOffsetManager.computeHorizontalScrollOffset();
}
public int computeVerticalScrollRange() {
return mScrollOffsetManager.computeVerticalScrollRange();
}
public int computeVerticalScrollOffset() {
return mScrollOffsetManager.computeVerticalScrollOffset();
}
public int computeVerticalScrollExtent() {
return mScrollOffsetManager.computeVerticalScrollExtent();
}
public void stopLoading() {
mContentViewCore.stopLoading();
}
public void reload() {
mContentViewCore.reload(true);
}
public boolean canGoBack() {
return mContentViewCore.canGoBack();
}
public void goBack() {
mContentViewCore.goBack();
}
public boolean canGoForward() {
return mContentViewCore.canGoForward();
}
public void goForward() {
mContentViewCore.goForward();
}
public boolean canGoBackOrForward(int steps) {
return mContentViewCore.canGoToOffset(steps);
}
public void goBackOrForward(int steps) {
mContentViewCore.goToOffset(steps);
}
public void pauseTimers() {
ContentViewStatics.setWebKitSharedTimersSuspended(true);
}
public void resumeTimers() {
ContentViewStatics.setWebKitSharedTimersSuspended(false);
}
public void onPause() {
if (mIsPaused || mNativeAwContents == 0) return;
mIsPaused = true;
nativeSetIsPaused(mNativeAwContents, mIsPaused);
}
public void onResume() {
if (!mIsPaused || mNativeAwContents == 0) return;
mIsPaused = false;
nativeSetIsPaused(mNativeAwContents, mIsPaused);
}
public boolean isPaused() {
return mIsPaused;
}
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
return mContentViewCore.onCreateInputConnection(outAttrs);
}
public boolean onKeyUp(int keyCode, KeyEvent event) {
return mContentViewCore.onKeyUp(keyCode, event);
}
private boolean isDpadEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_DPAD_DOWN:
case KeyEvent.KEYCODE_DPAD_UP:
case KeyEvent.KEYCODE_DPAD_LEFT:
case KeyEvent.KEYCODE_DPAD_RIGHT:
return true;
}
}
return false;
}
public boolean dispatchKeyEvent(KeyEvent event) {
if (isDpadEvent(event)) {
mSettings.setSpatialNavigationEnabled(true);
}
return mContentViewCore.dispatchKeyEvent(event);
}
public void clearCache(boolean includeDiskFiles) {
if (mNativeAwContents == 0) return;
nativeClearCache(mNativeAwContents, includeDiskFiles);
}
public void documentHasImages(Message message) {
if (mNativeAwContents == 0) return;
nativeDocumentHasImages(mNativeAwContents, message);
}
public void saveWebArchive(
final String basename, boolean autoname, final ValueCallback<String> callback) {
if (!autoname) {
saveWebArchiveInternal(basename, callback);
return;
}
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
return generateArchiveAutoNamePath(getOriginalUrl(), basename);
}
@Override
protected void onPostExecute(String result) {
saveWebArchiveInternal(result, callback);
}
}.execute();
}
public String getOriginalUrl() {
NavigationHistory history = mContentViewCore.getNavigationHistory();
int currentIndex = history.getCurrentEntryIndex();
if (currentIndex >= 0 && currentIndex < history.getEntryCount()) {
return history.getEntryAtIndex(currentIndex).getOriginalUrl();
}
return null;
}
public NavigationHistory getNavigationHistory() {
return mContentViewCore.getNavigationHistory();
}
public String getTitle() {
return mContentViewCore.getTitle();
}
public void clearHistory() {
mContentViewCore.clearHistory();
}
public String[] getHttpAuthUsernamePassword(String host, String realm) {
return mBrowserContext.getHttpAuthDatabase(mContentViewCore.getContext())
.getHttpAuthUsernamePassword(host, realm);
}
public void setHttpAuthUsernamePassword(String host, String realm, String username,
String password) {
mBrowserContext.getHttpAuthDatabase(mContentViewCore.getContext())
.setHttpAuthUsernamePassword(host, realm, username, password);
}
public SslCertificate getCertificate() {
if (mNativeAwContents == 0) return null;
return SslUtil.getCertificateFromDerBytes(nativeGetCertificate(mNativeAwContents));
}
public void clearSslPreferences() {
mContentViewCore.clearSslPreferences();
}
public HitTestData getLastHitTestResult() {
if (mNativeAwContents == 0) return null;
nativeUpdateLastHitTestData(mNativeAwContents);
return mPossiblyStaleHitTestData;
}
public void requestFocusNodeHref(Message msg) {
if (msg == null || mNativeAwContents == 0) return;
nativeUpdateLastHitTestData(mNativeAwContents);
Bundle data = msg.getData();
data.putString("url", mPossiblyStaleHitTestData.href);
data.putString("title", mPossiblyStaleHitTestData.anchorText);
data.putString("src", mPossiblyStaleHitTestData.imgSrc);
msg.setData(data);
msg.sendToTarget();
}
public void requestImageRef(Message msg) {
if (msg == null || mNativeAwContents == 0) return;
nativeUpdateLastHitTestData(mNativeAwContents);
Bundle data = msg.getData();
data.putString("url", mPossiblyStaleHitTestData.imgSrc);
msg.setData(data);
msg.sendToTarget();
}
@VisibleForTesting
public float getPageScaleFactor() {
return mPageScaleFactor;
}
public float getScale() {
return (float)(mPageScaleFactor * mDIPScale);
}
public void flingScroll(int velocityX, int velocityY) {
mScrollOffsetManager.flingScroll(velocityX, velocityY);
}
public boolean pageUp(boolean top) {
return mScrollOffsetManager.pageUp(top);
}
public boolean pageDown(boolean bottom) {
return mScrollOffsetManager.pageDown(bottom);
}
public boolean canZoomIn() {
final float zoomInExtent = mMaxPageScaleFactor - mPageScaleFactor;
return zoomInExtent > ZOOM_CONTROLS_EPSILON;
}
public boolean canZoomOut() {
final float zoomOutExtent = mPageScaleFactor - mMinPageScaleFactor;
return zoomOutExtent > ZOOM_CONTROLS_EPSILON;
}
public boolean zoomIn() {
if (!canZoomIn()) {
return false;
}
return mContentViewCore.pinchByDelta(1.25f);
}
public boolean zoomOut() {
if (!canZoomOut()) {
return false;
}
return mContentViewCore.pinchByDelta(0.8f);
}
public void invokeZoomPicker() {
mContentViewCore.invokeZoomPicker();
}
public void evaluateJavaScript(String script, final ValueCallback<String> callback) {
ContentViewCore.JavaScriptCallback jsCallback = null;
if (callback != null) {
jsCallback = new ContentViewCore.JavaScriptCallback() {
@Override
public void handleJavaScriptResult(String jsonResult) {
callback.onReceiveValue(jsonResult);
}
};
}
mContentViewCore.evaluateJavaScript(script, jsCallback);
}
public void evaluateJavaScriptEvenIfNotYetNavigated(String script) {
mContentViewCore.evaluateJavaScriptEvenIfNotYetNavigated(script);
}
public boolean onTouchEvent(MotionEvent event) {
if (mNativeAwContents == 0) return false;
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
mSettings.setSpatialNavigationEnabled(false);
}
mScrollOffsetManager.setProcessingTouchEvent(true);
boolean rv = mContentViewCore.onTouchEvent(event);
mScrollOffsetManager.setProcessingTouchEvent(false);
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
int actionIndex = event.getActionIndex();
nativeRequestNewHitTestDataAt(mNativeAwContents,
(int) Math.round(event.getX(actionIndex) / mDIPScale),
(int) Math.round(event.getY(actionIndex) / mDIPScale));
}
if (mOverScrollGlow != null && event.getActionMasked() == MotionEvent.ACTION_UP) {
mOverScrollGlow.releaseAll();
}
return rv;
}
public boolean onHoverEvent(MotionEvent event) {
return mContentViewCore.onHoverEvent(event);
}
public boolean onGenericMotionEvent(MotionEvent event) {
return mContentViewCore.onGenericMotionEvent(event);
}
public void onConfigurationChanged(Configuration newConfig) {
mContentViewCore.onConfigurationChanged(newConfig);
}
public void onAttachedToWindow() {
if (mNativeAwContents == 0) return;
mIsAttachedToWindow = true;
mContentViewCore.onAttachedToWindow();
nativeOnAttachedToWindow(mNativeAwContents, mContainerView.getWidth(),
mContainerView.getHeight());
updateHardwareAcceleratedFeaturesToggle();
if (mComponentCallbacks != null) return;
mComponentCallbacks = new AwComponentCallbacks();
mContainerView.getContext().registerComponentCallbacks(mComponentCallbacks);
}
@SuppressLint("MissingSuperCall")
public void onDetachedFromWindow() {
mIsAttachedToWindow = false;
hideAutofillPopup();
if (mNativeAwContents != 0) {
if (mContainerView.isHardwareAccelerated()) {
boolean result = mInternalAccessAdapter.executeHardwareAction(new Runnable() {
@Override
public void run() {
nativeReleaseHardwareDrawOnRenderThread(mNativeAwContents);
}
});
if (!result) {
Log.d(TAG, "executeHardwareAction failed");
}
}
nativeOnDetachedFromWindow(mNativeAwContents);
}
mContentViewCore.onDetachedFromWindow();
updateHardwareAcceleratedFeaturesToggle();
if (mComponentCallbacks != null) {
mContainerView.getContext().unregisterComponentCallbacks(mComponentCallbacks);
mComponentCallbacks = null;
}
mScrollAccessibilityHelper.removePostedCallbacks();
if (mPendingDetachCleanupReferences != null) {
for (int i = 0; i < mPendingDetachCleanupReferences.size(); ++i) {
mPendingDetachCleanupReferences.get(i).cleanupNow();
}
mPendingDetachCleanupReferences = null;
}
}
public void onWindowFocusChanged(boolean hasWindowFocus) {
mWindowFocused = hasWindowFocus;
mContentViewCore.onWindowFocusChanged(hasWindowFocus);
}
public void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
mContainerViewFocused = focused;
mContentViewCore.onFocusChanged(focused);
}
public void onSizeChanged(int w, int h, int ow, int oh) {
if (mNativeAwContents == 0) return;
mScrollOffsetManager.setContainerViewSize(w, h);
mLayoutSizer.onSizeChanged(w, h, ow, oh);
mContentViewCore.onPhysicalBackingSizeChanged(w, h);
mContentViewCore.onSizeChanged(w, h, ow, oh);
nativeOnSizeChanged(mNativeAwContents, w, h, ow, oh);
}
public void onVisibilityChanged(View changedView, int visibility) {
boolean viewVisible = mContainerView.getVisibility() == View.VISIBLE;
if (mIsViewVisible == viewVisible) return;
setViewVisibilityInternal(viewVisible);
}
public void onWindowVisibilityChanged(int visibility) {
boolean windowVisible = visibility == View.VISIBLE;
if (mIsWindowVisible == windowVisible) return;
setWindowVisibilityInternal(windowVisible);
}
private void setViewVisibilityInternal(boolean visible) {
mIsViewVisible = visible;
if (mNativeAwContents == 0) return;
nativeSetViewVisibility(mNativeAwContents, mIsViewVisible);
}
private void setWindowVisibilityInternal(boolean visible) {
mIsWindowVisible = visible;
if (mNativeAwContents == 0) return;
nativeSetWindowVisibility(mNativeAwContents, mIsWindowVisible);
}
public static final String SAVE_RESTORE_STATE_KEY = "WEBVIEW_CHROMIUM_STATE";
public boolean saveState(Bundle outState) {
if (mNativeAwContents == 0 || outState == null) return false;
byte[] state = nativeGetOpaqueState(mNativeAwContents);
if (state == null) return false;
outState.putByteArray(SAVE_RESTORE_STATE_KEY, state);
return true;
}
public boolean restoreState(Bundle inState) {
if (mNativeAwContents == 0 || inState == null) return false;
byte[] state = inState.getByteArray(SAVE_RESTORE_STATE_KEY);
if (state == null) return false;
boolean result = nativeRestoreFromOpaqueState(mNativeAwContents, state);
if (result) mContentsClient.onReceivedTitle(mContentViewCore.getTitle());
return result;
}
public void addPossiblyUnsafeJavascriptInterface(Object object, String name,
Class<? extends Annotation> requiredAnnotation) {
mContentViewCore.addPossiblyUnsafeJavascriptInterface(object, name, requiredAnnotation);
}
public void removeJavascriptInterface(String interfaceName) {
mContentViewCore.removeJavascriptInterface(interfaceName);
}
public AccessibilityNodeProvider getAccessibilityNodeProvider() {
return mContentViewCore.getAccessibilityNodeProvider();
}
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
mContentViewCore.onInitializeAccessibilityNodeInfo(info);
}
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
mContentViewCore.onInitializeAccessibilityEvent(event);
}
public boolean supportsAccessibilityAction(int action) {
return mContentViewCore.supportsAccessibilityAction(action);
}
public boolean performAccessibilityAction(int action, Bundle arguments) {
return mContentViewCore.performAccessibilityAction(action, arguments);
}
public void hideAutofillPopup() {
if (mAwAutofillManagerDelegate != null) {
mAwAutofillManagerDelegate.hideAutofillPopup();
}
}
public void setNetworkAvailable(boolean networkUp) {
if (mNativeAwContents == 0) return;
nativeSetJsOnlineProperty(mNativeAwContents, networkUp);
}
@CalledByNative
private static void onDocumentHasImagesResponse(boolean result, Message message) {
message.arg1 = result ? 1 : 0;
message.sendToTarget();
}
@CalledByNative
private void onReceivedTouchIconUrl(String url, boolean precomposed) {
mContentsClient.onReceivedTouchIconUrl(url, precomposed);
}
@CalledByNative
private void onReceivedIcon(Bitmap bitmap) {
mContentsClient.onReceivedIcon(bitmap);
mFavicon = bitmap;
}
@CalledByNative
private static void generateMHTMLCallback(
String path, long size, ValueCallback<String> callback) {
if (callback == null) return;
callback.onReceiveValue(size < 0 ? null : path);
}
@CalledByNative
private void onReceivedHttpAuthRequest(AwHttpAuthHandler handler, String host, String realm) {
mContentsClient.onReceivedHttpAuthRequest(handler, host, realm);
}
private class AwGeolocationCallback implements GeolocationPermissions.Callback {
@Override
public void invoke(final String origin, final boolean allow, final boolean retain) {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
if (retain) {
if (allow) {
mBrowserContext.getGeolocationPermissions().allow(origin);
} else {
mBrowserContext.getGeolocationPermissions().deny(origin);
}
}
if (mNativeAwContents == 0) return;
nativeInvokeGeolocationCallback(mNativeAwContents, allow, origin);
}
});
}
}
@CalledByNative
private void onGeolocationPermissionsShowPrompt(String origin) {
if (mNativeAwContents == 0) return;
AwGeolocationPermissions permissions = mBrowserContext.getGeolocationPermissions();
if (!mSettings.getGeolocationEnabled()) {
nativeInvokeGeolocationCallback(mNativeAwContents, false, origin);
return;
}
if (permissions.hasOrigin(origin)) {
nativeInvokeGeolocationCallback(mNativeAwContents, permissions.isOriginAllowed(origin),
origin);
return;
}
mContentsClient.onGeolocationPermissionsShowPrompt(
origin, new AwGeolocationCallback());
}
@CalledByNative
private void onGeolocationPermissionsHidePrompt() {
mContentsClient.onGeolocationPermissionsHidePrompt();
}
@CalledByNative
public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches,
boolean isDoneCounting) {
mContentsClient.onFindResultReceived(activeMatchOrdinal, numberOfMatches, isDoneCounting);
}
@CalledByNative
public void onNewPicture() {
mContentsClient.getCallbackHelper().postOnNewPicture(mPictureListenerContentProvider);
}
@CalledByNative
private void updateHitTestData(
int type, String extra, String href, String anchorText, String imgSrc) {
mPossiblyStaleHitTestData.hitTestResultType = type;
mPossiblyStaleHitTestData.hitTestResultExtraData = extra;
mPossiblyStaleHitTestData.href = href;
mPossiblyStaleHitTestData.anchorText = anchorText;
mPossiblyStaleHitTestData.imgSrc = imgSrc;
}
@CalledByNative
private boolean requestDrawGL(Canvas canvas) {
return mInternalAccessAdapter.requestDrawGL(canvas);
}
private static final boolean SUPPORTS_ON_ANIMATION =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
@CalledByNative
private void postInvalidateOnAnimation() {
if (SUPPORTS_ON_ANIMATION) {
mContainerView.postInvalidateOnAnimation();
} else {
mContainerView.postInvalidate();
}
}
@CalledByNative
private int[] getLocationOnScreen() {
int[] result = new int[2];
mContainerView.getLocationOnScreen(result);
return result;
}
@CalledByNative
private void onWebLayoutPageScaleFactorChanged(float webLayoutPageScaleFactor) {
mLayoutSizer.onPageScaleChanged(webLayoutPageScaleFactor);
}
@CalledByNative
private void onWebLayoutContentsSizeChanged(int widthCss, int heightCss) {
mLayoutSizer.onContentSizeChanged(widthCss, heightCss);
}
@CalledByNative
private void setMaxContainerViewScrollOffset(int maxX, int maxY) {
mScrollOffsetManager.setMaxScrollOffset(maxX, maxY);
}
@CalledByNative
private void scrollContainerViewTo(int x, int y) {
mScrollOffsetManager.scrollContainerViewTo(x, y);
}
@CalledByNative
private boolean isFlingActive() {
return mScrollOffsetManager.isFlingActive();
}
@CalledByNative
private void setContentsSize(int widthDip, int heightDip) {
mContentWidthDip = widthDip;
mContentHeightDip = heightDip;
}
@CalledByNative
private void setPageScaleFactorAndLimits(
float pageScaleFactor, float minPageScaleFactor, float maxPageScaleFactor) {
if (mPageScaleFactor == pageScaleFactor &&
mMinPageScaleFactor == minPageScaleFactor &&
mMaxPageScaleFactor == maxPageScaleFactor) {
return;
}
mMinPageScaleFactor = minPageScaleFactor;
mMaxPageScaleFactor = maxPageScaleFactor;
if (mPageScaleFactor != pageScaleFactor) {
float oldPageScaleFactor = mPageScaleFactor;
mPageScaleFactor = pageScaleFactor;
mContentsClient.getCallbackHelper().postOnScaleChangedScaled(
(float)(oldPageScaleFactor * mDIPScale),
(float)(mPageScaleFactor * mDIPScale));
}
}
@CalledByNative
private void setAwAutofillManagerDelegate(AwAutofillManagerDelegate delegate) {
mAwAutofillManagerDelegate = delegate;
delegate.init(mContentViewCore);
}
@CalledByNative
private void didOverscroll(int deltaX, int deltaY) {
if (mOverScrollGlow != null) {
mOverScrollGlow.setOverScrollDeltas(deltaX, deltaY);
}
mScrollOffsetManager.overScrollBy(deltaX, deltaY);
if (mOverScrollGlow != null && mOverScrollGlow.isAnimating()) {
mContainerView.invalidate();
}
}
private void saveWebArchiveInternal(String path, final ValueCallback<String> callback) {
if (path == null || mNativeAwContents == 0) {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
callback.onReceiveValue(null);
}
});
} else {
nativeGenerateMHTML(mNativeAwContents, path, callback);
}
}
private static String generateArchiveAutoNamePath(String originalUrl, String baseName) {
String name = null;
if (originalUrl != null && !originalUrl.isEmpty()) {
try {
String path = new URL(originalUrl).getPath();
int lastSlash = path.lastIndexOf('/');
if (lastSlash > 0) {
name = path.substring(lastSlash + 1);
} else {
name = path;
}
} catch (MalformedURLException e) {
}
}
if (TextUtils.isEmpty(name)) name = "index";
String testName = baseName + name + WEB_ARCHIVE_EXTENSION;
if (!new File(testName).exists()) return testName;
for (int i = 1; i < 100; i++) {
testName = baseName + name + "-" + i + WEB_ARCHIVE_EXTENSION;
if (!new File(testName).exists()) return testName;
}
Log.e(TAG, "Unable to auto generate archive name for path: " + baseName);
return null;
}
public void extractSmartClipData(int x, int y, int width, int height) {
mContentViewCore.extractSmartClipData(x, y, width, height);
}
public void setSmartClipDataListener(ContentViewCore.SmartClipDataListener listener) {
mContentViewCore.setSmartClipDataListener(listener);
}
private static native long nativeInit(AwBrowserContext browserContext);
private static native void nativeDestroy(long nativeAwContents);
private static native void nativeSetAwDrawSWFunctionTable(long functionTablePointer);
private static native void nativeSetAwDrawGLFunctionTable(long functionTablePointer);
private static native long nativeGetAwDrawGLFunction();
private static native int nativeGetNativeInstanceCount();
private static native void nativeSetShouldDownloadFavicons();
private native void nativeSetJavaPeers(long nativeAwContents, AwContents awContents,
AwWebContentsDelegate webViewWebContentsDelegate,
AwContentsClientBridge contentsClientBridge,
AwContentsIoThreadClient ioThreadClient,
InterceptNavigationDelegate navigationInterceptionDelegate);
private native long nativeGetWebContents(long nativeAwContents);
private native void nativeDocumentHasImages(long nativeAwContents, Message message);
private native void nativeGenerateMHTML(
long nativeAwContents, String path, ValueCallback<String> callback);
private native void nativeAddVisitedLinks(long nativeAwContents, String[] visitedLinks);
private native boolean nativeOnDraw(long nativeAwContents, Canvas canvas,
boolean isHardwareAccelerated, int scrollX, int scrollY,
int visibleLeft, int visibleTop, int visibleRight, int visibleBottom,
int clipLeft, int clipTop, int clipRight, int clipBottom);
private native void nativeFindAllAsync(long nativeAwContents, String searchString);
private native void nativeFindNext(long nativeAwContents, boolean forward);
private native void nativeClearMatches(long nativeAwContents);
private native void nativeClearCache(long nativeAwContents, boolean includeDiskFiles);
private native byte[] nativeGetCertificate(long nativeAwContents);
private native void nativeRequestNewHitTestDataAt(long nativeAwContents, int x, int y);
private native void nativeUpdateLastHitTestData(long nativeAwContents);
private native void nativeOnSizeChanged(long nativeAwContents, int w, int h, int ow, int oh);
private native void nativeScrollTo(long nativeAwContents, int x, int y);
private native void nativeSetViewVisibility(long nativeAwContents, boolean visible);
private native void nativeSetWindowVisibility(long nativeAwContents, boolean visible);
private native void nativeSetIsPaused(long nativeAwContents, boolean paused);
private native void nativeOnAttachedToWindow(long nativeAwContents, int w, int h);
private static native void nativeOnDetachedFromWindow(long nativeAwContents);
private static native void nativeReleaseHardwareDrawOnRenderThread(long nativeAwContents);
private native void nativeSetDipScale(long nativeAwContents, float dipScale);
private native void nativeSetFixedLayoutSize(long nativeAwContents,
int widthDip, int heightDip);
private native byte[] nativeGetOpaqueState(long nativeAwContents);
private native boolean nativeRestoreFromOpaqueState(long nativeAwContents, byte[] state);
private native long nativeReleasePopupAwContents(long nativeAwContents);
private native void nativeFocusFirstNode(long nativeAwContents);
private native void nativeSetBackgroundColor(long nativeAwContents, int color);
private native long nativeGetAwDrawGLViewContext(long nativeAwContents);
private native long nativeCapturePicture(long nativeAwContents, int width, int height);
private native void nativeEnableOnNewPicture(long nativeAwContents, boolean enabled);
private native void nativeClearView(long nativeAwContents);
private native void nativeSetExtraHeadersForUrl(long nativeAwContents,
String url, String extraHeaders);
private native void nativeInvokeGeolocationCallback(
long nativeAwContents, boolean value, String requestingFrame);
private native void nativeSetJsOnlineProperty(long nativeAwContents, boolean networkUp);
private native void nativeTrimMemoryOnRenderThread(long nativeAwContents, int level,
boolean visible);
private native void nativeCreatePdfExporter(long nativeAwContents, AwPdfExporter awPdfExporter);
}