OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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.content.res.Configuration; | 7 import android.content.res.Configuration; |
8 import android.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
9 import android.graphics.Canvas; | 9 import android.graphics.Canvas; |
10 import android.graphics.Color; | 10 import android.graphics.Color; |
(...skipping 18 matching lines...) Expand all Loading... |
29 import org.chromium.content.browser.ContentSettings; | 29 import org.chromium.content.browser.ContentSettings; |
30 import org.chromium.content.browser.ContentVideoView; | 30 import org.chromium.content.browser.ContentVideoView; |
31 import org.chromium.content.browser.ContentViewCore; | 31 import org.chromium.content.browser.ContentViewCore; |
32 import org.chromium.content.browser.LoadUrlParams; | 32 import org.chromium.content.browser.LoadUrlParams; |
33 import org.chromium.content.browser.NavigationHistory; | 33 import org.chromium.content.browser.NavigationHistory; |
34 import org.chromium.content.browser.PageTransitionTypes; | 34 import org.chromium.content.browser.PageTransitionTypes; |
35 import org.chromium.content.common.CleanupReference; | 35 import org.chromium.content.common.CleanupReference; |
36 import org.chromium.components.navigation_interception.InterceptNavigationDelega
te; | 36 import org.chromium.components.navigation_interception.InterceptNavigationDelega
te; |
37 import org.chromium.components.navigation_interception.NavigationParams; | 37 import org.chromium.components.navigation_interception.NavigationParams; |
38 import org.chromium.net.GURLUtils; | 38 import org.chromium.net.GURLUtils; |
39 import org.chromium.net.X509Util; | |
40 import org.chromium.ui.gfx.DeviceDisplayInfo; | 39 import org.chromium.ui.gfx.DeviceDisplayInfo; |
41 import org.chromium.ui.gfx.NativeWindow; | 40 import org.chromium.ui.gfx.NativeWindow; |
42 | 41 |
43 import java.io.File; | 42 import java.io.File; |
44 import java.net.MalformedURLException; | 43 import java.net.MalformedURLException; |
45 import java.net.URL; | 44 import java.net.URL; |
46 import java.security.KeyStoreException; | |
47 import java.security.NoSuchAlgorithmException; | |
48 import java.security.cert.CertificateException; | |
49 import java.security.cert.X509Certificate; | |
50 | 45 |
51 /** | 46 /** |
52 * Exposes the native AwContents class, and together these classes wrap the Cont
entViewCore | 47 * Exposes the native AwContents class, and together these classes wrap the Cont
entViewCore |
53 * and Browser components that are required to implement Android WebView API. Th
is is the | 48 * and Browser components that are required to implement Android WebView API. Th
is is the |
54 * primary entry point for the WebViewProvider implementation; it holds a 1:1 ob
ject | 49 * primary entry point for the WebViewProvider implementation; it holds a 1:1 ob
ject |
55 * relationship with application WebView instances. | 50 * relationship with application WebView instances. |
56 * (We define this class independent of the hidden WebViewProvider interfaces, t
o allow | 51 * (We define this class independent of the hidden WebViewProvider interfaces, t
o allow |
57 * continuous build & test in the open source SDK-based tree). | 52 * continuous build & test in the open source SDK-based tree). |
58 */ | 53 */ |
59 @JNINamespace("android_webview") | 54 @JNINamespace("android_webview") |
(...skipping 27 matching lines...) Expand all Loading... |
87 /** | 82 /** |
88 * @see View#setMeasuredDimension(int, int) | 83 * @see View#setMeasuredDimension(int, int) |
89 */ | 84 */ |
90 void setMeasuredDimension(int measuredWidth, int measuredHeight); | 85 void setMeasuredDimension(int measuredWidth, int measuredHeight); |
91 } | 86 } |
92 | 87 |
93 private int mNativeAwContents; | 88 private int mNativeAwContents; |
94 private ViewGroup mContainerView; | 89 private ViewGroup mContainerView; |
95 private ContentViewCore mContentViewCore; | 90 private ContentViewCore mContentViewCore; |
96 private AwContentsClient mContentsClient; | 91 private AwContentsClient mContentsClient; |
| 92 private AwContentsClientBridge mContentsClientBridge; |
97 private AwContentsIoThreadClient mIoThreadClient; | 93 private AwContentsIoThreadClient mIoThreadClient; |
98 private InterceptNavigationDelegateImpl mInterceptNavigationDelegate; | 94 private InterceptNavigationDelegateImpl mInterceptNavigationDelegate; |
99 private InternalAccessDelegate mInternalAccessAdapter; | 95 private InternalAccessDelegate mInternalAccessAdapter; |
100 private final AwLayoutSizer mLayoutSizer; | 96 private final AwLayoutSizer mLayoutSizer; |
101 // This can be accessed on any thread after construction. See AwContentsIoTh
readClient. | 97 // This can be accessed on any thread after construction. See AwContentsIoTh
readClient. |
102 private final AwSettings mSettings; | 98 private final AwSettings mSettings; |
103 private boolean mIsPaused; | 99 private boolean mIsPaused; |
104 private Bitmap mFavicon; | 100 private Bitmap mFavicon; |
105 private boolean mHasRequestedVisitedHistoryFromClient; | 101 private boolean mHasRequestedVisitedHistoryFromClient; |
106 // TODO(boliu): This should be in a global context, not per webview. | 102 // TODO(boliu): This should be in a global context, not per webview. |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 setInterceptNavigationDelegate(new InterceptNavigationDelegateImpl()); | 266 setInterceptNavigationDelegate(new InterceptNavigationDelegateImpl()); |
271 | 267 |
272 mPossiblyStaleHitTestData = new HitTestData(); | 268 mPossiblyStaleHitTestData = new HitTestData(); |
273 nativeDidInitializeContentViewCore(mNativeAwContents, | 269 nativeDidInitializeContentViewCore(mNativeAwContents, |
274 mContentViewCore.getNativeContentViewCore()); | 270 mContentViewCore.getNativeContentViewCore()); |
275 | 271 |
276 mDIPScale = DeviceDisplayInfo.create(containerView.getContext()).getDIPS
cale(); | 272 mDIPScale = DeviceDisplayInfo.create(containerView.getContext()).getDIPS
cale(); |
277 | 273 |
278 ContentVideoView.registerContentVideoViewContextDelegate( | 274 ContentVideoView.registerContentVideoViewContextDelegate( |
279 new AwContentVideoViewDelegate(contentsClient, containerView.get
Context())); | 275 new AwContentVideoViewDelegate(contentsClient, containerView.get
Context())); |
| 276 |
| 277 mContentsClientBridge = new AwContentsClientBridge(contentsClient, mNati
veAwContents); |
280 } | 278 } |
281 | 279 |
282 public ContentViewCore getContentViewCore() { | 280 public ContentViewCore getContentViewCore() { |
283 return mContentViewCore; | 281 return mContentViewCore; |
284 } | 282 } |
285 | 283 |
286 // Can be called from any thread. | 284 // Can be called from any thread. |
287 public AwSettings getSettings() { | 285 public AwSettings getSettings() { |
288 return mSettings; | 286 return mSettings; |
289 } | 287 } |
290 | 288 |
291 public void setIoThreadClient(AwContentsIoThreadClient ioThreadClient) { | 289 public void setIoThreadClient(AwContentsIoThreadClient ioThreadClient) { |
292 mIoThreadClient = ioThreadClient; | 290 mIoThreadClient = ioThreadClient; |
293 nativeSetIoThreadClient(mNativeAwContents, mIoThreadClient); | 291 nativeSetIoThreadClient(mNativeAwContents, mIoThreadClient); |
294 } | 292 } |
295 | 293 |
296 private void setInterceptNavigationDelegate(InterceptNavigationDelegateImpl
delegate) { | 294 private void setInterceptNavigationDelegate(InterceptNavigationDelegateImpl
delegate) { |
297 mInterceptNavigationDelegate = delegate; | 295 mInterceptNavigationDelegate = delegate; |
298 nativeSetInterceptNavigationDelegate(mNativeAwContents, delegate); | 296 nativeSetInterceptNavigationDelegate(mNativeAwContents, delegate); |
299 } | 297 } |
300 | 298 |
301 public void destroy() { | 299 public void destroy() { |
302 mContentViewCore.destroy(); | 300 mContentViewCore.destroy(); |
| 301 mContentsClientBridge.destroy(); |
303 // The native part of AwSettings isn't needed for the IoThreadClient ins
tance. | 302 // The native part of AwSettings isn't needed for the IoThreadClient ins
tance. |
304 mSettings.destroy(); | 303 mSettings.destroy(); |
305 // We explicitly do not null out the mContentViewCore reference here | 304 // We explicitly do not null out the mContentViewCore reference here |
306 // because ContentViewCore already has code to deal with the case | 305 // because ContentViewCore already has code to deal with the case |
307 // methods are called on it after it's been destroyed, and other | 306 // methods are called on it after it's been destroyed, and other |
308 // code relies on AwContents.getContentViewCore to return non-null. | 307 // code relies on AwContents.getContentViewCore to return non-null. |
309 mCleanupReference.cleanupNow(); | 308 mCleanupReference.cleanupNow(); |
310 mNativeAwContents = 0; | 309 mNativeAwContents = 0; |
311 } | 310 } |
312 | 311 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 String password) { | 602 String password) { |
604 HttpAuthDatabase.getInstance(mContentViewCore.getContext()) | 603 HttpAuthDatabase.getInstance(mContentViewCore.getContext()) |
605 .setHttpAuthUsernamePassword(host, realm, username, password); | 604 .setHttpAuthUsernamePassword(host, realm, username, password); |
606 } | 605 } |
607 | 606 |
608 /** | 607 /** |
609 * @see android.webkit.WebView#getCertificate() | 608 * @see android.webkit.WebView#getCertificate() |
610 */ | 609 */ |
611 public SslCertificate getCertificate() { | 610 public SslCertificate getCertificate() { |
612 if (mNativeAwContents == 0) return null; | 611 if (mNativeAwContents == 0) return null; |
613 byte[] derBytes = nativeGetCertificate(mNativeAwContents); | 612 return AwContentsClientBridge |
614 if (derBytes == null) { | 613 .getCertificateFromDerBytes(nativeGetCertificate(mNativeAwConten
ts)); |
615 return null; | |
616 } | |
617 | |
618 try { | |
619 X509Certificate x509Certificate = | |
620 X509Util.createCertificateFromBytes(derBytes); | |
621 return new SslCertificate(x509Certificate); | |
622 } catch (CertificateException e) { | |
623 // Intentional fall through | |
624 // A SSL related exception must have occured. This shouldn't happen
. | |
625 Log.w(TAG, "Could not read certificate: " + e); | |
626 } catch (KeyStoreException e) { | |
627 // Intentional fall through | |
628 // A SSL related exception must have occured. This shouldn't happen
. | |
629 Log.w(TAG, "Could not read certificate: " + e); | |
630 } catch (NoSuchAlgorithmException e) { | |
631 // Intentional fall through | |
632 // A SSL related exception must have occured. This shouldn't happen
. | |
633 Log.w(TAG, "Could not read certificate: " + e); | |
634 } | |
635 return null; | |
636 } | 614 } |
637 | 615 |
638 /** | 616 /** |
639 * Method to return all hit test values relevant to public WebView API. | 617 * Method to return all hit test values relevant to public WebView API. |
640 * Note that this expose more data than needed for WebView.getHitTestResult. | 618 * Note that this expose more data than needed for WebView.getHitTestResult. |
641 * Unsafely returning reference to mutable internal object to avoid excessiv
e | 619 * Unsafely returning reference to mutable internal object to avoid excessiv
e |
642 * garbage allocation on repeated calls. | 620 * garbage allocation on repeated calls. |
643 */ | 621 */ |
644 public HitTestData getLastHitTestResult() { | 622 public HitTestData getLastHitTestResult() { |
645 if (mNativeAwContents == 0) return null; | 623 if (mNativeAwContents == 0) return null; |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 private native void nativeSetWebContents(int nativeAwContents, int nativeNew
WebContents); | 1083 private native void nativeSetWebContents(int nativeAwContents, int nativeNew
WebContents); |
1106 private native void nativeFocusFirstNode(int nativeAwContents); | 1084 private native void nativeFocusFirstNode(int nativeAwContents); |
1107 | 1085 |
1108 private native Picture nativeCapturePicture(int nativeAwContents); | 1086 private native Picture nativeCapturePicture(int nativeAwContents); |
1109 private native void nativeEnableOnNewPicture(int nativeAwContents, boolean e
nabled, | 1087 private native void nativeEnableOnNewPicture(int nativeAwContents, boolean e
nabled, |
1110 boolean invalidationOnly); | 1088 boolean invalidationOnly); |
1111 | 1089 |
1112 private native void nativeInvokeGeolocationCallback( | 1090 private native void nativeInvokeGeolocationCallback( |
1113 int nativeAwContents, boolean value, String requestingFrame); | 1091 int nativeAwContents, boolean value, String requestingFrame); |
1114 } | 1092 } |
OLD | NEW |