OLD | NEW |
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.annotation.TargetApi; | 8 import android.annotation.TargetApi; |
9 import android.app.Activity; | 9 import android.app.Activity; |
10 import android.content.ComponentCallbacks2; | 10 import android.content.ComponentCallbacks2; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 import org.chromium.base.ObserverList; | 51 import org.chromium.base.ObserverList; |
52 import org.chromium.base.ThreadUtils; | 52 import org.chromium.base.ThreadUtils; |
53 import org.chromium.base.TraceEvent; | 53 import org.chromium.base.TraceEvent; |
54 import org.chromium.base.VisibleForTesting; | 54 import org.chromium.base.VisibleForTesting; |
55 import org.chromium.base.annotations.CalledByNative; | 55 import org.chromium.base.annotations.CalledByNative; |
56 import org.chromium.base.annotations.JNINamespace; | 56 import org.chromium.base.annotations.JNINamespace; |
57 import org.chromium.base.annotations.SuppressFBWarnings; | 57 import org.chromium.base.annotations.SuppressFBWarnings; |
58 import org.chromium.components.navigation_interception.InterceptNavigationDelega
te; | 58 import org.chromium.components.navigation_interception.InterceptNavigationDelega
te; |
59 import org.chromium.components.navigation_interception.NavigationParams; | 59 import org.chromium.components.navigation_interception.NavigationParams; |
60 import org.chromium.content.browser.AppWebMessagePort; | 60 import org.chromium.content.browser.AppWebMessagePort; |
61 import org.chromium.content.browser.AppWebMessagePortService; | |
62 import org.chromium.content.browser.ContentViewClient; | 61 import org.chromium.content.browser.ContentViewClient; |
63 import org.chromium.content.browser.ContentViewCore; | 62 import org.chromium.content.browser.ContentViewCore; |
64 import org.chromium.content.browser.ContentViewStatics; | 63 import org.chromium.content.browser.ContentViewStatics; |
65 import org.chromium.content.browser.PostMessageSender; | |
66 import org.chromium.content.browser.SmartClipProvider; | 64 import org.chromium.content.browser.SmartClipProvider; |
67 import org.chromium.content_public.browser.GestureStateListener; | 65 import org.chromium.content_public.browser.GestureStateListener; |
68 import org.chromium.content_public.browser.JavaScriptCallback; | 66 import org.chromium.content_public.browser.JavaScriptCallback; |
69 import org.chromium.content_public.browser.LoadUrlParams; | 67 import org.chromium.content_public.browser.LoadUrlParams; |
70 import org.chromium.content_public.browser.MessagePort; | 68 import org.chromium.content_public.browser.MessagePort; |
71 import org.chromium.content_public.browser.NavigationController; | 69 import org.chromium.content_public.browser.NavigationController; |
72 import org.chromium.content_public.browser.NavigationHistory; | 70 import org.chromium.content_public.browser.NavigationHistory; |
73 import org.chromium.content_public.browser.WebContents; | 71 import org.chromium.content_public.browser.WebContents; |
74 import org.chromium.content_public.browser.navigation_controller.LoadURLType; | 72 import org.chromium.content_public.browser.navigation_controller.LoadURLType; |
75 import org.chromium.content_public.browser.navigation_controller.UserAgentOverri
deOption; | 73 import org.chromium.content_public.browser.navigation_controller.UserAgentOverri
deOption; |
(...skipping 17 matching lines...) Expand all Loading... |
93 | 91 |
94 /** | 92 /** |
95 * Exposes the native AwContents class, and together these classes wrap the Cont
entViewCore | 93 * Exposes the native AwContents class, and together these classes wrap the Cont
entViewCore |
96 * and Browser components that are required to implement Android WebView API. Th
is is the | 94 * and Browser components that are required to implement Android WebView API. Th
is is the |
97 * primary entry point for the WebViewProvider implementation; it holds a 1:1 ob
ject | 95 * primary entry point for the WebViewProvider implementation; it holds a 1:1 ob
ject |
98 * relationship with application WebView instances. | 96 * relationship with application WebView instances. |
99 * (We define this class independent of the hidden WebViewProvider interfaces, t
o allow | 97 * (We define this class independent of the hidden WebViewProvider interfaces, t
o allow |
100 * continuous build & test in the open source SDK-based tree). | 98 * continuous build & test in the open source SDK-based tree). |
101 */ | 99 */ |
102 @JNINamespace("android_webview") | 100 @JNINamespace("android_webview") |
103 public class AwContents implements SmartClipProvider, PostMessageSender.PostMess
ageSenderDelegate { | 101 public class AwContents implements SmartClipProvider { |
104 private static final String TAG = "AwContents"; | 102 private static final String TAG = "AwContents"; |
105 private static final boolean TRACE = false; | 103 private static final boolean TRACE = false; |
106 private static final int NO_WARN = 0; | 104 private static final int NO_WARN = 0; |
107 private static final int WARN = 1; | 105 private static final int WARN = 1; |
108 private static final String PRODUCT_VERSION = AwContentsStatics.getProductVe
rsion(); | 106 private static final String PRODUCT_VERSION = AwContentsStatics.getProductVe
rsion(); |
109 | 107 |
110 private static final String WEB_ARCHIVE_EXTENSION = ".mht"; | 108 private static final String WEB_ARCHIVE_EXTENSION = ".mht"; |
111 // The request code should be unique per WebView/AwContents object. | 109 // The request code should be unique per WebView/AwContents object. |
112 private static final int PROCESS_TEXT_REQUEST_CODE = 100; | 110 private static final int PROCESS_TEXT_REQUEST_CODE = 100; |
113 | 111 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 private float mContentWidthDip; | 330 private float mContentWidthDip; |
333 private float mContentHeightDip; | 331 private float mContentHeightDip; |
334 | 332 |
335 private AwAutofillClient mAwAutofillClient; | 333 private AwAutofillClient mAwAutofillClient; |
336 | 334 |
337 private AwPdfExporter mAwPdfExporter; | 335 private AwPdfExporter mAwPdfExporter; |
338 | 336 |
339 private AwViewMethods mAwViewMethods; | 337 private AwViewMethods mAwViewMethods; |
340 private final FullScreenTransitionsState mFullScreenTransitionsState; | 338 private final FullScreenTransitionsState mFullScreenTransitionsState; |
341 | 339 |
342 private PostMessageSender mPostMessageSender; | |
343 | |
344 // This flag indicates that ShouldOverrideUrlNavigation should be posted | 340 // This flag indicates that ShouldOverrideUrlNavigation should be posted |
345 // through the resourcethrottle. This is only used for popup windows. | 341 // through the resourcethrottle. This is only used for popup windows. |
346 private boolean mDeferredShouldOverrideUrlLoadingIsPendingForPopup; | 342 private boolean mDeferredShouldOverrideUrlLoadingIsPendingForPopup; |
347 | 343 |
348 // This is a workaround for some qualcomm devices discarding buffer on | 344 // This is a workaround for some qualcomm devices discarding buffer on |
349 // Activity restore. | 345 // Activity restore. |
350 private boolean mInvalidateRootViewOnNextDraw; | 346 private boolean mInvalidateRootViewOnNextDraw; |
351 | 347 |
352 // The framework may temporarily detach our container view, for example duri
ng layout if | 348 // The framework may temporarily detach our container view, for example duri
ng layout if |
353 // we are a child of a ListView. This may cause many toggles of View focus,
which we suppress | 349 // we are a child of a ListView. This may cause many toggles of View focus,
which we suppress |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 /** | 1187 /** |
1192 * Destroys this object and deletes its native counterpart. | 1188 * Destroys this object and deletes its native counterpart. |
1193 */ | 1189 */ |
1194 public void destroy() { | 1190 public void destroy() { |
1195 if (TRACE) Log.i(TAG, "%s destroy", this); | 1191 if (TRACE) Log.i(TAG, "%s destroy", this); |
1196 if (isDestroyed(NO_WARN)) return; | 1192 if (isDestroyed(NO_WARN)) return; |
1197 | 1193 |
1198 // Remove pending messages | 1194 // Remove pending messages |
1199 mContentsClient.getCallbackHelper().removeCallbacksAndMessages(); | 1195 mContentsClient.getCallbackHelper().removeCallbacksAndMessages(); |
1200 | 1196 |
1201 if (mPostMessageSender != null) { | |
1202 mBrowserContext.getMessagePortService().removeObserver(mPostMessageS
ender); | |
1203 mPostMessageSender = null; | |
1204 } | |
1205 | |
1206 if (mIsAttachedToWindow) { | 1197 if (mIsAttachedToWindow) { |
1207 Log.w(TAG, "WebView.destroy() called while WebView is still attached
to window."); | 1198 Log.w(TAG, "WebView.destroy() called while WebView is still attached
to window."); |
1208 // Need to call detach to avoid leaks because the real detach later
will be ignored. | 1199 // Need to call detach to avoid leaks because the real detach later
will be ignored. |
1209 onDetachedFromWindow(); | 1200 onDetachedFromWindow(); |
1210 } | 1201 } |
1211 mIsNoOperation = true; | 1202 mIsNoOperation = true; |
1212 mIsDestroyed = true; | 1203 mIsDestroyed = true; |
1213 mHandler.post(new Runnable() { | 1204 mHandler.post(new Runnable() { |
1214 @Override | 1205 @Override |
1215 public void run() { | 1206 public void run() { |
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2278 * @param frameName The name of the frame. If the name is null the message i
s posted | 2269 * @param frameName The name of the frame. If the name is null the message i
s posted |
2279 * to the main frame. | 2270 * to the main frame. |
2280 * @param message The message | 2271 * @param message The message |
2281 * @param targetOrigin The target origin | 2272 * @param targetOrigin The target origin |
2282 * @param sentPorts The sent message ports, if any. Pass null if there is no | 2273 * @param sentPorts The sent message ports, if any. Pass null if there is no |
2283 * message ports to pass. | 2274 * message ports to pass. |
2284 */ | 2275 */ |
2285 public void postMessageToFrame( | 2276 public void postMessageToFrame( |
2286 String frameName, String message, String targetOrigin, MessagePort[]
sentPorts) { | 2277 String frameName, String message, String targetOrigin, MessagePort[]
sentPorts) { |
2287 if (isDestroyedOrNoOperation(WARN)) return; | 2278 if (isDestroyedOrNoOperation(WARN)) return; |
2288 if (mPostMessageSender == null) { | 2279 if (sentPorts != null) { |
2289 AppWebMessagePortService service = mBrowserContext.getMessagePortSer
vice(); | 2280 for (MessagePort port : sentPorts) { |
2290 mPostMessageSender = new PostMessageSender(this, service); | 2281 if (port.isClosed() || port.isTransferred()) { |
2291 service.addObserver(mPostMessageSender); | 2282 throw new IllegalStateException("Port is already closed or t
ransferred"); |
| 2283 } |
| 2284 if (port.isStarted()) { |
| 2285 throw new IllegalStateException("Port is already started"); |
| 2286 } |
| 2287 } |
2292 } | 2288 } |
2293 mPostMessageSender.postMessage(frameName, message, targetOrigin, | 2289 nativePostMessageToFrame(mNativeAwContents, frameName, message, targetOr
igin, sentPorts); |
2294 (AppWebMessagePort[]) sentPorts); | |
2295 } | |
2296 | |
2297 // Implements PostMessageSender.PostMessageSenderDelegate interface method. | |
2298 @Override | |
2299 public boolean isPostMessageSenderReady() { | |
2300 return true; | |
2301 } | |
2302 | |
2303 // Implements PostMessageSender.PostMessageSenderDelegate interface method. | |
2304 @Override | |
2305 public void onPostMessageQueueEmpty() { } | |
2306 | |
2307 // Implements PostMessageSender.PostMessageSenderDelegate interface method. | |
2308 @Override | |
2309 public void postMessageToWeb(String frameName, String message, String target
Origin, | |
2310 int[] sentPortIds) { | |
2311 if (TRACE) Log.i(TAG, "%s postMessageToWeb. TargetOrigin=%s", this, targ
etOrigin); | |
2312 if (isDestroyedOrNoOperation(NO_WARN)) return; | |
2313 nativePostMessageToFrame(mNativeAwContents, frameName, message, targetOr
igin, | |
2314 sentPortIds); | |
2315 } | 2290 } |
2316 | 2291 |
2317 /** | 2292 /** |
2318 * Creates a message channel and returns the ports for each end of the chann
el. | 2293 * Creates a message channel and returns the ports for each end of the chann
el. |
2319 */ | 2294 */ |
2320 public AppWebMessagePort[] createMessageChannel() { | 2295 public AppWebMessagePort[] createMessageChannel() { |
2321 if (TRACE) Log.i(TAG, "%s createMessageChannel", this); | 2296 if (TRACE) Log.i(TAG, "%s createMessageChannel", this); |
2322 if (isDestroyedOrNoOperation(WARN)) return null; | 2297 if (isDestroyedOrNoOperation(WARN)) return null; |
2323 AppWebMessagePort[] ports = mBrowserContext.getMessagePortService().crea
teMessageChannel(); | 2298 return AppWebMessagePort.createPair(); |
2324 nativeCreateMessageChannel(mNativeAwContents, ports); | |
2325 return ports; | |
2326 } | 2299 } |
2327 | 2300 |
2328 public boolean hasAccessedInitialDocument() { | 2301 public boolean hasAccessedInitialDocument() { |
2329 if (isDestroyedOrNoOperation(NO_WARN)) return false; | 2302 if (isDestroyedOrNoOperation(NO_WARN)) return false; |
2330 return mWebContents.hasAccessedInitialDocument(); | 2303 return mWebContents.hasAccessedInitialDocument(); |
2331 } | 2304 } |
2332 | 2305 |
2333 @TargetApi(Build.VERSION_CODES.M) | 2306 @TargetApi(Build.VERSION_CODES.M) |
2334 public void onProvideVirtualStructure(ViewStructure structure) { | 2307 public void onProvideVirtualStructure(ViewStructure structure) { |
2335 if (isDestroyedOrNoOperation(WARN)) return; | 2308 if (isDestroyedOrNoOperation(WARN)) return; |
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3442 private native void nativeSetJsOnlineProperty(long nativeAwContents, boolean
networkUp); | 3415 private native void nativeSetJsOnlineProperty(long nativeAwContents, boolean
networkUp); |
3443 | 3416 |
3444 private native void nativeTrimMemory(long nativeAwContents, int level, boole
an visible); | 3417 private native void nativeTrimMemory(long nativeAwContents, int level, boole
an visible); |
3445 | 3418 |
3446 private native void nativeCreatePdfExporter(long nativeAwContents, AwPdfExpo
rter awPdfExporter); | 3419 private native void nativeCreatePdfExporter(long nativeAwContents, AwPdfExpo
rter awPdfExporter); |
3447 | 3420 |
3448 private native void nativePreauthorizePermission(long nativeAwContents, Stri
ng origin, | 3421 private native void nativePreauthorizePermission(long nativeAwContents, Stri
ng origin, |
3449 long resources); | 3422 long resources); |
3450 | 3423 |
3451 private native void nativePostMessageToFrame(long nativeAwContents, String f
rameId, | 3424 private native void nativePostMessageToFrame(long nativeAwContents, String f
rameId, |
3452 String message, String targetOrigin, int[] msgPorts); | 3425 String message, String targetOrigin, MessagePort[] ports); |
3453 | |
3454 private native void nativeCreateMessageChannel( | |
3455 long nativeAwContents, AppWebMessagePort[] ports); | |
3456 | 3426 |
3457 private native void nativeGrantFileSchemeAccesstoChildProcess(long nativeAwC
ontents); | 3427 private native void nativeGrantFileSchemeAccesstoChildProcess(long nativeAwC
ontents); |
3458 private native void nativeResumeLoadingCreatedPopupWebContents(long nativeAw
Contents); | 3428 private native void nativeResumeLoadingCreatedPopupWebContents(long nativeAw
Contents); |
3459 } | 3429 } |
OLD | NEW |