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; |
11 import android.graphics.Rect; | 11 import android.graphics.Rect; |
12 import android.net.http.SslCertificate; | 12 import android.net.http.SslCertificate; |
| 13 import android.net.http.SslError; |
13 import android.os.AsyncTask; | 14 import android.os.AsyncTask; |
14 import android.os.Build; | 15 import android.os.Build; |
15 import android.os.Bundle; | 16 import android.os.Bundle; |
16 import android.os.Message; | 17 import android.os.Message; |
17 import android.text.TextUtils; | 18 import android.text.TextUtils; |
18 import android.util.Log; | 19 import android.util.Log; |
19 import android.view.MotionEvent; | 20 import android.view.MotionEvent; |
20 import android.view.View; | 21 import android.view.View; |
21 import android.view.ViewGroup; | 22 import android.view.ViewGroup; |
22 import android.webkit.GeolocationPermissions; | 23 import android.webkit.GeolocationPermissions; |
| 24 import android.webkit.SslErrorHandler; |
23 import android.webkit.ValueCallback; | 25 import android.webkit.ValueCallback; |
24 | 26 |
25 import org.chromium.base.CalledByNative; | 27 import org.chromium.base.CalledByNative; |
26 import org.chromium.base.JNINamespace; | 28 import org.chromium.base.JNINamespace; |
27 import org.chromium.base.ThreadUtils; | 29 import org.chromium.base.ThreadUtils; |
28 import org.chromium.content.browser.ContentSettings; | 30 import org.chromium.content.browser.ContentSettings; |
29 import org.chromium.content.browser.ContentViewCore; | 31 import org.chromium.content.browser.ContentViewCore; |
30 import org.chromium.content.browser.LoadUrlParams; | 32 import org.chromium.content.browser.LoadUrlParams; |
31 import org.chromium.content.browser.NavigationHistory; | 33 import org.chromium.content.browser.NavigationHistory; |
32 import org.chromium.content.browser.PageTransitionTypes; | 34 import org.chromium.content.browser.PageTransitionTypes; |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 String password) { | 578 String password) { |
577 HttpAuthDatabase.getInstance(mContentViewCore.getContext()) | 579 HttpAuthDatabase.getInstance(mContentViewCore.getContext()) |
578 .setHttpAuthUsernamePassword(host, realm, username, password); | 580 .setHttpAuthUsernamePassword(host, realm, username, password); |
579 } | 581 } |
580 | 582 |
581 /** | 583 /** |
582 * @see android.webkit.WebView#getCertificate() | 584 * @see android.webkit.WebView#getCertificate() |
583 */ | 585 */ |
584 public SslCertificate getCertificate() { | 586 public SslCertificate getCertificate() { |
585 if (mNativeAwContents == 0) return null; | 587 if (mNativeAwContents == 0) return null; |
586 byte[] derBytes = nativeGetCertificate(mNativeAwContents); | 588 return getCertificateFromDerBytes(nativeGetCertificate(mNativeAwContents
)); |
587 if (derBytes == null) { | |
588 return null; | |
589 } | |
590 | |
591 try { | |
592 X509Certificate x509Certificate = | |
593 X509Util.createCertificateFromBytes(derBytes); | |
594 return new SslCertificate(x509Certificate); | |
595 } catch (CertificateException e) { | |
596 // Intentional fall through | |
597 // A SSL related exception must have occured. This shouldn't happen
. | |
598 Log.w(TAG, "Could not read certificate: " + e); | |
599 } catch (KeyStoreException e) { | |
600 // Intentional fall through | |
601 // A SSL related exception must have occured. This shouldn't happen
. | |
602 Log.w(TAG, "Could not read certificate: " + e); | |
603 } catch (NoSuchAlgorithmException e) { | |
604 // Intentional fall through | |
605 // A SSL related exception must have occured. This shouldn't happen
. | |
606 Log.w(TAG, "Could not read certificate: " + e); | |
607 } | |
608 return null; | |
609 } | 589 } |
610 | 590 |
611 /** | 591 /** |
612 * Method to return all hit test values relevant to public WebView API. | 592 * Method to return all hit test values relevant to public WebView API. |
613 * Note that this expose more data than needed for WebView.getHitTestResult. | 593 * Note that this expose more data than needed for WebView.getHitTestResult. |
614 * Unsafely returning reference to mutable internal object to avoid excessiv
e | 594 * Unsafely returning reference to mutable internal object to avoid excessiv
e |
615 * garbage allocation on repeated calls. | 595 * garbage allocation on repeated calls. |
616 */ | 596 */ |
617 public HitTestData getLastHitTestResult() { | 597 public HitTestData getLastHitTestResult() { |
618 if (mNativeAwContents == 0) return null; | 598 if (mNativeAwContents == 0) return null; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 String path, long size, ValueCallback<String> callback) { | 813 String path, long size, ValueCallback<String> callback) { |
834 if (callback == null) return; | 814 if (callback == null) return; |
835 callback.onReceiveValue(size < 0 ? null : path); | 815 callback.onReceiveValue(size < 0 ? null : path); |
836 } | 816 } |
837 | 817 |
838 @CalledByNative | 818 @CalledByNative |
839 private void onReceivedHttpAuthRequest(AwHttpAuthHandler handler, String hos
t, String realm) { | 819 private void onReceivedHttpAuthRequest(AwHttpAuthHandler handler, String hos
t, String realm) { |
840 mContentsClient.onReceivedHttpAuthRequest(handler, host, realm); | 820 mContentsClient.onReceivedHttpAuthRequest(handler, host, realm); |
841 } | 821 } |
842 | 822 |
| 823 @CalledByNative |
| 824 private boolean allowCertificateError(int certError, byte[] derBytes, String
url) { |
| 825 SslCertificate cert = getCertificateFromDerBytes(derBytes); |
| 826 if (cert == null) { |
| 827 // if the certificate is null, cancel the request |
| 828 return true; |
| 829 } |
| 830 final SslError sslError = SslError.SslErrorFromChromiumErrorCode(certErr
or, cert, url); |
| 831 if (SslCertLookupTable.getInstance().isAllowed(sslError)) { |
| 832 proceedSslError(true); |
| 833 return false; |
| 834 } |
| 835 |
| 836 SslErrorHandler handler = new SslErrorHandler() { |
| 837 @Override |
| 838 public void proceed() { |
| 839 post(new Runnable() { |
| 840 @Override |
| 841 public void run() { |
| 842 SslCertLookupTable.getInstance().setIsAllowed(sslErr
or); |
| 843 proceedSslError(true); |
| 844 } |
| 845 }); |
| 846 } |
| 847 @Override |
| 848 public void cancel() { |
| 849 post(new Runnable() { |
| 850 @Override |
| 851 public void run() { |
| 852 proceedSslError(false); |
| 853 } |
| 854 }); |
| 855 } |
| 856 }; |
| 857 mContentsClient.onReceivedSslError(handler, sslError); |
| 858 return false; |
| 859 } |
| 860 |
| 861 private void proceedSslError(boolean proceed) { |
| 862 if (mNativeAwContents == 0) return; |
| 863 nativeProceedSslError(mNativeAwContents, proceed); |
| 864 } |
| 865 |
843 private static class ChromiumGeolocationCallback implements GeolocationPermi
ssions.Callback { | 866 private static class ChromiumGeolocationCallback implements GeolocationPermi
ssions.Callback { |
844 final int mRenderProcessId; | 867 final int mRenderProcessId; |
845 final int mRenderViewId; | 868 final int mRenderViewId; |
846 final int mBridgeId; | 869 final int mBridgeId; |
847 final String mRequestingFrame; | 870 final String mRequestingFrame; |
848 | 871 |
849 private ChromiumGeolocationCallback(int renderProcessId, int renderViewI
d, int bridgeId, | 872 private ChromiumGeolocationCallback(int renderProcessId, int renderViewI
d, int bridgeId, |
850 String requestingFrame) { | 873 String requestingFrame) { |
851 mRenderProcessId = renderProcessId; | 874 mRenderProcessId = renderProcessId; |
852 mRenderViewId = renderViewId; | 875 mRenderViewId = renderViewId; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 | 963 |
941 for (int i = 1; i < 100; i++) { | 964 for (int i = 1; i < 100; i++) { |
942 testName = baseName + name + "-" + i + WEB_ARCHIVE_EXTENSION; | 965 testName = baseName + name + "-" + i + WEB_ARCHIVE_EXTENSION; |
943 if (!new File(testName).exists()) return testName; | 966 if (!new File(testName).exists()) return testName; |
944 } | 967 } |
945 | 968 |
946 Log.e(TAG, "Unable to auto generate archive name for path: " + baseName)
; | 969 Log.e(TAG, "Unable to auto generate archive name for path: " + baseName)
; |
947 return null; | 970 return null; |
948 } | 971 } |
949 | 972 |
| 973 private SslCertificate getCertificateFromDerBytes(byte[] derBytes) { |
| 974 if (derBytes == null) { |
| 975 return null; |
| 976 } |
| 977 |
| 978 try { |
| 979 X509Certificate x509Certificate = |
| 980 X509Util.createCertificateFromBytes(derBytes); |
| 981 return new SslCertificate(x509Certificate); |
| 982 } catch (CertificateException e) { |
| 983 // Intentional fall through |
| 984 // A SSL related exception must have occured. This shouldn't happen
. |
| 985 Log.w(TAG, "Could not read certificate: " + e); |
| 986 } catch (KeyStoreException e) { |
| 987 // Intentional fall through |
| 988 // A SSL related exception must have occured. This shouldn't happen
. |
| 989 Log.w(TAG, "Could not read certificate: " + e); |
| 990 } catch (NoSuchAlgorithmException e) { |
| 991 // Intentional fall through |
| 992 // A SSL related exception must have occured. This shouldn't happen
. |
| 993 Log.w(TAG, "Could not read certificate: " + e); |
| 994 } |
| 995 return null; |
| 996 } |
| 997 |
950 @CalledByNative | 998 @CalledByNative |
951 private void handleJsAlert(String url, String message, JsResultReceiver rece
iver) { | 999 private void handleJsAlert(String url, String message, JsResultReceiver rece
iver) { |
952 mContentsClient.handleJsAlert(url, message, receiver); | 1000 mContentsClient.handleJsAlert(url, message, receiver); |
953 } | 1001 } |
954 | 1002 |
955 @CalledByNative | 1003 @CalledByNative |
956 private void handleJsBeforeUnload(String url, String message, JsResultReceiv
er receiver) { | 1004 private void handleJsBeforeUnload(String url, String message, JsResultReceiv
er receiver) { |
957 mContentsClient.handleJsBeforeUnload(url, message, receiver); | 1005 mContentsClient.handleJsBeforeUnload(url, message, receiver); |
958 } | 1006 } |
959 | 1007 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 private native void nativeAddVisitedLinks(int nativeAwContents, String[] vis
itedLinks); | 1041 private native void nativeAddVisitedLinks(int nativeAwContents, String[] vis
itedLinks); |
994 | 1042 |
995 private native boolean nativeDrawSW(int nativeAwContents, Canvas canvas); | 1043 private native boolean nativeDrawSW(int nativeAwContents, Canvas canvas); |
996 private native void nativeSetScrollForHWFrame(int nativeAwContents, int scro
llX, int scrollY); | 1044 private native void nativeSetScrollForHWFrame(int nativeAwContents, int scro
llX, int scrollY); |
997 private native int nativeFindAllSync(int nativeAwContents, String searchStri
ng); | 1045 private native int nativeFindAllSync(int nativeAwContents, String searchStri
ng); |
998 private native void nativeFindAllAsync(int nativeAwContents, String searchSt
ring); | 1046 private native void nativeFindAllAsync(int nativeAwContents, String searchSt
ring); |
999 private native void nativeFindNext(int nativeAwContents, boolean forward); | 1047 private native void nativeFindNext(int nativeAwContents, boolean forward); |
1000 private native void nativeClearMatches(int nativeAwContents); | 1048 private native void nativeClearMatches(int nativeAwContents); |
1001 private native void nativeClearCache(int nativeAwContents, boolean includeDi
skFiles); | 1049 private native void nativeClearCache(int nativeAwContents, boolean includeDi
skFiles); |
1002 private native byte[] nativeGetCertificate(int nativeAwContents); | 1050 private native byte[] nativeGetCertificate(int nativeAwContents); |
| 1051 private native void nativeProceedSslError(int nativeAwContents, boolean proc
eed); |
1003 private native void nativeRequestNewHitTestDataAt(int nativeAwContents, int
x, int y); | 1052 private native void nativeRequestNewHitTestDataAt(int nativeAwContents, int
x, int y); |
1004 private native void nativeUpdateLastHitTestData(int nativeAwContents); | 1053 private native void nativeUpdateLastHitTestData(int nativeAwContents); |
1005 private native void nativeOnSizeChanged(int nativeAwContents, int w, int h,
int ow, int oh); | 1054 private native void nativeOnSizeChanged(int nativeAwContents, int w, int h,
int ow, int oh); |
1006 private native void nativeSetWindowViewVisibility(int nativeAwContents, bool
ean windowVisible, | 1055 private native void nativeSetWindowViewVisibility(int nativeAwContents, bool
ean windowVisible, |
1007 boolean viewVisible); | 1056 boolean viewVisible); |
1008 private native void nativeOnAttachedToWindow(int nativeAwContents, int w, in
t h); | 1057 private native void nativeOnAttachedToWindow(int nativeAwContents, int w, in
t h); |
1009 private native void nativeOnDetachedFromWindow(int nativeAwContents); | 1058 private native void nativeOnDetachedFromWindow(int nativeAwContents); |
1010 | 1059 |
1011 // Returns null if save state fails. | 1060 // Returns null if save state fails. |
1012 private native byte[] nativeGetOpaqueState(int nativeAwContents); | 1061 private native byte[] nativeGetOpaqueState(int nativeAwContents); |
1013 | 1062 |
1014 // Returns false if restore state fails. | 1063 // Returns false if restore state fails. |
1015 private native boolean nativeRestoreFromOpaqueState(int nativeAwContents, by
te[] state); | 1064 private native boolean nativeRestoreFromOpaqueState(int nativeAwContents, by
te[] state); |
1016 | 1065 |
1017 private native int nativeReleasePopupWebContents(int nativeAwContents); | 1066 private native int nativeReleasePopupWebContents(int nativeAwContents); |
1018 private native void nativeSetWebContents(int nativeAwContents, int nativeNew
WebContents); | 1067 private native void nativeSetWebContents(int nativeAwContents, int nativeNew
WebContents); |
1019 private native void nativeFocusFirstNode(int nativeAwContents); | 1068 private native void nativeFocusFirstNode(int nativeAwContents); |
1020 } | 1069 } |
OLD | NEW |