Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: android_webview/java/src/org/chromium/android_webview/AwContents.java

Issue 970883002: [Android WebView] Synthesize a fake page loading event on page source modification (Re-land) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.android_webview; 5 package org.chromium.android_webview;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.app.Activity; 8 import android.app.Activity;
9 import android.content.ComponentCallbacks2; 9 import android.content.ComponentCallbacks2;
10 import android.content.Context; 10 import android.content.Context;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 import org.chromium.base.JNINamespace; 42 import org.chromium.base.JNINamespace;
43 import org.chromium.base.ThreadUtils; 43 import org.chromium.base.ThreadUtils;
44 import org.chromium.base.TraceEvent; 44 import org.chromium.base.TraceEvent;
45 import org.chromium.base.VisibleForTesting; 45 import org.chromium.base.VisibleForTesting;
46 import org.chromium.components.navigation_interception.InterceptNavigationDelega te; 46 import org.chromium.components.navigation_interception.InterceptNavigationDelega te;
47 import org.chromium.components.navigation_interception.NavigationParams; 47 import org.chromium.components.navigation_interception.NavigationParams;
48 import org.chromium.content.browser.ContentViewClient; 48 import org.chromium.content.browser.ContentViewClient;
49 import org.chromium.content.browser.ContentViewCore; 49 import org.chromium.content.browser.ContentViewCore;
50 import org.chromium.content.browser.ContentViewStatics; 50 import org.chromium.content.browser.ContentViewStatics;
51 import org.chromium.content.browser.SmartClipProvider; 51 import org.chromium.content.browser.SmartClipProvider;
52 import org.chromium.content.browser.WebContentsObserver;
53 import org.chromium.content.common.CleanupReference; 52 import org.chromium.content.common.CleanupReference;
54 import org.chromium.content_public.browser.GestureStateListener; 53 import org.chromium.content_public.browser.GestureStateListener;
55 import org.chromium.content_public.browser.JavaScriptCallback; 54 import org.chromium.content_public.browser.JavaScriptCallback;
56 import org.chromium.content_public.browser.LoadUrlParams; 55 import org.chromium.content_public.browser.LoadUrlParams;
57 import org.chromium.content_public.browser.NavigationController; 56 import org.chromium.content_public.browser.NavigationController;
58 import org.chromium.content_public.browser.NavigationHistory; 57 import org.chromium.content_public.browser.NavigationHistory;
59 import org.chromium.content_public.browser.WebContents; 58 import org.chromium.content_public.browser.WebContents;
60 import org.chromium.content_public.browser.navigation_controller.LoadURLType; 59 import org.chromium.content_public.browser.navigation_controller.LoadURLType;
61 import org.chromium.content_public.browser.navigation_controller.UserAgentOverri deOption; 60 import org.chromium.content_public.browser.navigation_controller.UserAgentOverri deOption;
62 import org.chromium.content_public.common.Referrer; 61 import org.chromium.content_public.common.Referrer;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 private final AwBrowserContext mBrowserContext; 196 private final AwBrowserContext mBrowserContext;
198 private ViewGroup mContainerView; 197 private ViewGroup mContainerView;
199 private final AwLayoutChangeListener mLayoutChangeListener; 198 private final AwLayoutChangeListener mLayoutChangeListener;
200 private final Context mContext; 199 private final Context mContext;
201 private ContentViewCore mContentViewCore; 200 private ContentViewCore mContentViewCore;
202 private WindowAndroid mWindowAndroid; 201 private WindowAndroid mWindowAndroid;
203 private WebContents mWebContents; 202 private WebContents mWebContents;
204 private NavigationController mNavigationController; 203 private NavigationController mNavigationController;
205 private final AwContentsClient mContentsClient; 204 private final AwContentsClient mContentsClient;
206 private final AwContentViewClient mContentViewClient; 205 private final AwContentViewClient mContentViewClient;
207 private WebContentsObserver mWebContentsObserver; 206 private AwWebContentsObserver mWebContentsObserver;
208 private final AwContentsClientBridge mContentsClientBridge; 207 private final AwContentsClientBridge mContentsClientBridge;
209 private final AwWebContentsDelegateAdapter mWebContentsDelegate; 208 private final AwWebContentsDelegateAdapter mWebContentsDelegate;
210 private final AwContentsIoThreadClient mIoThreadClient; 209 private final AwContentsIoThreadClient mIoThreadClient;
211 private final InterceptNavigationDelegateImpl mInterceptNavigationDelegate; 210 private final InterceptNavigationDelegateImpl mInterceptNavigationDelegate;
212 private InternalAccessDelegate mInternalAccessAdapter; 211 private InternalAccessDelegate mInternalAccessAdapter;
213 private final NativeGLDelegate mNativeGLDelegate; 212 private final NativeGLDelegate mNativeGLDelegate;
214 private final AwLayoutSizer mLayoutSizer; 213 private final AwLayoutSizer mLayoutSizer;
215 private final AwZoomControls mZoomControls; 214 private final AwZoomControls mZoomControls;
216 private final AwScrollOffsetManager mScrollOffsetManager; 215 private final AwScrollOffsetManager mScrollOffsetManager;
217 private OverScrollGlow mOverScrollGlow; 216 private OverScrollGlow mOverScrollGlow;
218 // This can be accessed on any thread after construction. See AwContentsIoTh readClient. 217 // This can be accessed on any thread after construction. See AwContentsIoTh readClient.
219 private final AwSettings mSettings; 218 private final AwSettings mSettings;
220 private final ScrollAccessibilityHelper mScrollAccessibilityHelper; 219 private final ScrollAccessibilityHelper mScrollAccessibilityHelper;
221 220
222 private boolean mIsPaused; 221 private boolean mIsPaused;
223 private boolean mIsViewVisible; 222 private boolean mIsViewVisible;
224 private boolean mIsWindowVisible; 223 private boolean mIsWindowVisible;
225 private boolean mIsAttachedToWindow; 224 private boolean mIsAttachedToWindow;
226 private Bitmap mFavicon; 225 private Bitmap mFavicon;
227 private boolean mHasRequestedVisitedHistoryFromClient; 226 private boolean mHasRequestedVisitedHistoryFromClient;
228 // TODO(boliu): This should be in a global context, not per webview. 227 // TODO(boliu): This should be in a global context, not per webview.
229 private final double mDIPScale; 228 private final double mDIPScale;
229 // Whether the WebView has attempted to do any load (including uncommitted l oads).
230 private boolean mDidAttemptLoad = false;
230 231
231 // The base background color, i.e. not accounting for any CSS body from the current page. 232 // The base background color, i.e. not accounting for any CSS body from the current page.
232 private int mBaseBackgroundColor = Color.WHITE; 233 private int mBaseBackgroundColor = Color.WHITE;
233 234
234 // Must call nativeUpdateLastHitTestData first to update this before use. 235 // Must call nativeUpdateLastHitTestData first to update this before use.
235 private final HitTestData mPossiblyStaleHitTestData = new HitTestData(); 236 private final HitTestData mPossiblyStaleHitTestData = new HitTestData();
236 237
237 private final DefaultVideoPosterRequestHandler mDefaultVideoPosterRequestHan dler; 238 private final DefaultVideoPosterRequestHandler mDefaultVideoPosterRequestHan dler;
238 239
239 // Bound method for suppling Picture instances to the AwContentsClient. Will be null if the 240 // Bound method for suppling Picture instances to the AwContentsClient. Will be null if the
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 if (wasAttached) { 902 if (wasAttached) {
902 onAttachedToWindow(); 903 onAttachedToWindow();
903 postInvalidateOnAnimation(); 904 postInvalidateOnAnimation();
904 } 905 }
905 onSizeChanged(mContainerView.getWidth(), mContainerView.getHeight(), 0, 0); 906 onSizeChanged(mContainerView.getWidth(), mContainerView.getHeight(), 0, 0);
906 if (wasWindowVisible) setWindowVisibilityInternal(true); 907 if (wasWindowVisible) setWindowVisibilityInternal(true);
907 if (wasViewVisible) setViewVisibilityInternal(true); 908 if (wasViewVisible) setViewVisibilityInternal(true);
908 if (wasWindowFocused) onWindowFocusChanged(wasWindowFocused); 909 if (wasWindowFocused) onWindowFocusChanged(wasWindowFocused);
909 if (wasFocused) onFocusChanged(true, 0, null); 910 if (wasFocused) onFocusChanged(true, 0, null);
910 911
912 // Popups are always assumed as having made a load attempt.
913 mDidAttemptLoad = true;
Charlie Reis 2015/03/03 22:21:00 What about window.open() (with no arguments)? Tha
mnaganov (inactive) 2015/03/04 10:30:29 I specifically checked this case, and for WebView
914
911 // Restore injected JavaScript interfaces. 915 // Restore injected JavaScript interfaces.
912 for (Map.Entry<String, Pair<Object, Class>> entry : javascriptInterfaces .entrySet()) { 916 for (Map.Entry<String, Pair<Object, Class>> entry : javascriptInterfaces .entrySet()) {
913 @SuppressWarnings("unchecked") 917 @SuppressWarnings("unchecked")
914 Class<? extends Annotation> requiredAnnotation = entry.getValue().se cond; 918 Class<? extends Annotation> requiredAnnotation = entry.getValue().se cond;
915 mContentViewCore.addPossiblyUnsafeJavascriptInterface( 919 mContentViewCore.addPossiblyUnsafeJavascriptInterface(
916 entry.getValue().first, 920 entry.getValue().first,
917 entry.getKey(), 921 entry.getKey(),
918 requiredAnnotation); 922 requiredAnnotation);
919 } 923 }
920 } 924 }
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 * 1236 *
1233 * @return The URL of the current page or null if it's empty. 1237 * @return The URL of the current page or null if it's empty.
1234 */ 1238 */
1235 public String getUrl() { 1239 public String getUrl() {
1236 if (isDestroyed()) return null; 1240 if (isDestroyed()) return null;
1237 String url = mWebContents.getUrl(); 1241 String url = mWebContents.getUrl();
1238 if (url == null || url.trim().isEmpty()) return null; 1242 if (url == null || url.trim().isEmpty()) return null;
1239 return url; 1243 return url;
1240 } 1244 }
1241 1245
1246 /**
1247 * Gets the last committed URL. It represents the current page that is
1248 * displayed in WebContents. It represents the current security context.
1249 *
1250 * @return The URL of the current page or null if it's empty.
1251 */
1252 public String getLastCommittedUrl() {
1253 if (isDestroyed()) return null;
1254 String url = mWebContents.getLastCommittedUrl();
1255 if (url == null || url.trim().isEmpty()) return null;
1256 return url;
1257 }
1258
1242 public void requestFocus() { 1259 public void requestFocus() {
1243 mAwViewMethods.requestFocus(); 1260 mAwViewMethods.requestFocus();
1244 } 1261 }
1245 1262
1246 public void setBackgroundColor(int color) { 1263 public void setBackgroundColor(int color) {
1247 mBaseBackgroundColor = color; 1264 mBaseBackgroundColor = color;
1248 if (!isDestroyed()) nativeSetBackgroundColor(mNativeAwContents, color); 1265 if (!isDestroyed()) nativeSetBackgroundColor(mNativeAwContents, color);
1249 } 1266 }
1250 1267
1251 /** 1268 /**
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1831 /** 1848 /**
1832 * Creates a message channel and returns the ports for each end of the chann el. 1849 * Creates a message channel and returns the ports for each end of the chann el.
1833 */ 1850 */
1834 public MessagePort[] createMessageChannel() { 1851 public MessagePort[] createMessageChannel() {
1835 if (isDestroyed()) return null; 1852 if (isDestroyed()) return null;
1836 MessagePort[] ports = mBrowserContext.getMessagePortService().createMess ageChannel(); 1853 MessagePort[] ports = mBrowserContext.getMessagePortService().createMess ageChannel();
1837 nativeCreateMessageChannel(mNativeAwContents, ports); 1854 nativeCreateMessageChannel(mNativeAwContents, ports);
1838 return ports; 1855 return ports;
1839 } 1856 }
1840 1857
1858 public boolean hasAccessedInitialDocument() {
1859 if (isDestroyed()) return false;
1860 return mWebContents.hasAccessedInitialDocument();
1861 }
1862
1841 //-------------------------------------------------------------------------- ------------------ 1863 //-------------------------------------------------------------------------- ------------------
1842 // View and ViewGroup method implementations 1864 // View and ViewGroup method implementations
1843 //-------------------------------------------------------------------------- ------------------ 1865 //-------------------------------------------------------------------------- ------------------
1844 1866
1845 /** 1867 /**
1846 * @see android.webkit.View#onTouchEvent() 1868 * @see android.webkit.View#onTouchEvent()
1847 */ 1869 */
1848 public boolean onTouchEvent(MotionEvent event) { 1870 public boolean onTouchEvent(MotionEvent event) {
1849 return mAwViewMethods.onTouchEvent(event); 1871 return mAwViewMethods.onTouchEvent(event);
1850 } 1872 }
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
2065 * 3. A frame swap happens that draws the active tree into the screen 2087 * 3. A frame swap happens that draws the active tree into the screen
2066 * 2088 *
2067 * @param requestId an id that will be returned from the callback invocation to allow 2089 * @param requestId an id that will be returned from the callback invocation to allow
2068 * callers to match requests with callbacks. 2090 * callers to match requests with callbacks.
2069 * @param callback the callback to be inserted 2091 * @param callback the callback to be inserted
2070 */ 2092 */
2071 public void insertVisualStateCallback(long requestId, VisualStateCallback ca llback) { 2093 public void insertVisualStateCallback(long requestId, VisualStateCallback ca llback) {
2072 nativeInsertVisualStateCallback(mNativeAwContents, requestId, callback); 2094 nativeInsertVisualStateCallback(mNativeAwContents, requestId, callback);
2073 } 2095 }
2074 2096
2097 public boolean getDidAttemptLoad() {
2098 if (mDidAttemptLoad) return mDidAttemptLoad;
2099 mDidAttemptLoad = mWebContentsObserver.getDidStartProvisionalLoadForFram eFired();
2100 return mDidAttemptLoad;
2101 }
2102
2075 //-------------------------------------------------------------------------- ------------------ 2103 //-------------------------------------------------------------------------- ------------------
2076 // Methods called from native via JNI 2104 // Methods called from native via JNI
2077 //-------------------------------------------------------------------------- ------------------ 2105 //-------------------------------------------------------------------------- ------------------
2078 2106
2079 @CalledByNative 2107 @CalledByNative
2080 private static void onDocumentHasImagesResponse(boolean result, Message mess age) { 2108 private static void onDocumentHasImagesResponse(boolean result, Message mess age) {
2081 message.arg1 = result ? 1 : 0; 2109 message.arg1 = result ? 1 : 0;
2082 message.sendToTarget(); 2110 message.sendToTarget();
2083 } 2111 }
2084 2112
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
2771 private native void nativeCreatePdfExporter(long nativeAwContents, AwPdfExpo rter awPdfExporter); 2799 private native void nativeCreatePdfExporter(long nativeAwContents, AwPdfExpo rter awPdfExporter);
2772 2800
2773 private native void nativePreauthorizePermission(long nativeAwContents, Stri ng origin, 2801 private native void nativePreauthorizePermission(long nativeAwContents, Stri ng origin,
2774 long resources); 2802 long resources);
2775 2803
2776 private native void nativePostMessageToFrame(long nativeAwContents, String f rameId, 2804 private native void nativePostMessageToFrame(long nativeAwContents, String f rameId,
2777 String message, String targetOrigin, int[] msgPorts); 2805 String message, String targetOrigin, int[] msgPorts);
2778 2806
2779 private native void nativeCreateMessageChannel(long nativeAwContents, Messag ePort[] ports); 2807 private native void nativeCreateMessageChannel(long nativeAwContents, Messag ePort[] ports);
2780 } 2808 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698