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 // If returns true, the request is immediately canceled, and any call to pro ceedSslError | |
824 // has no effect. If returns false, the request should be canceled or procee ded using | |
825 // proceedSslError(). | |
826 @CalledByNative | |
827 private boolean cancelCertificateError(int certError, byte[] derBytes, Strin g url) { | |
828 SslCertificate cert = getCertificateFromDerBytes(derBytes); | |
829 if (cert == null) { | |
830 // if the certificate is null, cancel the request | |
831 return true; | |
832 } | |
833 final SslError sslError = SslError.SslErrorFromChromiumErrorCode(certErr or, cert, url); | |
834 if (SslCertLookupTable.getInstance().isAllowed(sslError)) { | |
835 proceedSslError(true); | |
836 return false; | |
boliu
2013/02/01 23:07:13
so we are not doing this optimization?
sgurun-gerrit only
2013/02/02 01:01:10
I think you mean why do we have to use the callbac
boliu
2013/02/02 01:10:42
Can you just return true here without calling proc
sgurun-gerrit only
2013/02/02 03:16:10
Nop, it won't work (Please take a look at the plac
| |
837 } | |
838 | |
839 SslErrorHandler handler = new SslErrorHandler() { | |
840 @Override | |
841 public void proceed() { | |
842 post(new Runnable() { | |
843 @Override | |
844 public void run() { | |
845 SslCertLookupTable.getInstance().setIsAllowed(sslErr or); | |
846 proceedSslError(true); | |
847 } | |
848 }); | |
849 } | |
850 @Override | |
851 public void cancel() { | |
852 post(new Runnable() { | |
853 @Override | |
854 public void run() { | |
855 proceedSslError(false); | |
856 } | |
857 }); | |
858 } | |
859 }; | |
860 mContentsClient.onReceivedSslError(handler, sslError); | |
861 return false; | |
862 } | |
863 | |
864 private void proceedSslError(boolean proceed) { | |
865 if (mNativeAwContents == 0) return; | |
866 nativeProceedSslError(mNativeAwContents, proceed); | |
867 } | |
868 | |
843 private static class ChromiumGeolocationCallback implements GeolocationPermi ssions.Callback { | 869 private static class ChromiumGeolocationCallback implements GeolocationPermi ssions.Callback { |
844 final int mRenderProcessId; | 870 final int mRenderProcessId; |
845 final int mRenderViewId; | 871 final int mRenderViewId; |
846 final int mBridgeId; | 872 final int mBridgeId; |
847 final String mRequestingFrame; | 873 final String mRequestingFrame; |
848 | 874 |
849 private ChromiumGeolocationCallback(int renderProcessId, int renderViewI d, int bridgeId, | 875 private ChromiumGeolocationCallback(int renderProcessId, int renderViewI d, int bridgeId, |
850 String requestingFrame) { | 876 String requestingFrame) { |
851 mRenderProcessId = renderProcessId; | 877 mRenderProcessId = renderProcessId; |
852 mRenderViewId = renderViewId; | 878 mRenderViewId = renderViewId; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
940 | 966 |
941 for (int i = 1; i < 100; i++) { | 967 for (int i = 1; i < 100; i++) { |
942 testName = baseName + name + "-" + i + WEB_ARCHIVE_EXTENSION; | 968 testName = baseName + name + "-" + i + WEB_ARCHIVE_EXTENSION; |
943 if (!new File(testName).exists()) return testName; | 969 if (!new File(testName).exists()) return testName; |
944 } | 970 } |
945 | 971 |
946 Log.e(TAG, "Unable to auto generate archive name for path: " + baseName) ; | 972 Log.e(TAG, "Unable to auto generate archive name for path: " + baseName) ; |
947 return null; | 973 return null; |
948 } | 974 } |
949 | 975 |
976 private SslCertificate getCertificateFromDerBytes(byte[] derBytes) { | |
977 if (derBytes == null) { | |
978 return null; | |
979 } | |
980 | |
981 try { | |
982 X509Certificate x509Certificate = | |
983 X509Util.createCertificateFromBytes(derBytes); | |
984 return new SslCertificate(x509Certificate); | |
985 } catch (CertificateException e) { | |
986 // Intentional fall through | |
987 // A SSL related exception must have occured. This shouldn't happen . | |
988 Log.w(TAG, "Could not read certificate: " + e); | |
989 } catch (KeyStoreException e) { | |
990 // Intentional fall through | |
991 // A SSL related exception must have occured. This shouldn't happen . | |
992 Log.w(TAG, "Could not read certificate: " + e); | |
993 } catch (NoSuchAlgorithmException e) { | |
994 // Intentional fall through | |
995 // A SSL related exception must have occured. This shouldn't happen . | |
996 Log.w(TAG, "Could not read certificate: " + e); | |
997 } | |
998 return null; | |
999 } | |
1000 | |
950 @CalledByNative | 1001 @CalledByNative |
951 private void handleJsAlert(String url, String message, JsResultReceiver rece iver) { | 1002 private void handleJsAlert(String url, String message, JsResultReceiver rece iver) { |
952 mContentsClient.handleJsAlert(url, message, receiver); | 1003 mContentsClient.handleJsAlert(url, message, receiver); |
953 } | 1004 } |
954 | 1005 |
955 @CalledByNative | 1006 @CalledByNative |
956 private void handleJsBeforeUnload(String url, String message, JsResultReceiv er receiver) { | 1007 private void handleJsBeforeUnload(String url, String message, JsResultReceiv er receiver) { |
957 mContentsClient.handleJsBeforeUnload(url, message, receiver); | 1008 mContentsClient.handleJsBeforeUnload(url, message, receiver); |
958 } | 1009 } |
959 | 1010 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
993 private native void nativeAddVisitedLinks(int nativeAwContents, String[] vis itedLinks); | 1044 private native void nativeAddVisitedLinks(int nativeAwContents, String[] vis itedLinks); |
994 | 1045 |
995 private native boolean nativeDrawSW(int nativeAwContents, Canvas canvas); | 1046 private native boolean nativeDrawSW(int nativeAwContents, Canvas canvas); |
996 private native void nativeSetScrollForHWFrame(int nativeAwContents, int scro llX, int scrollY); | 1047 private native void nativeSetScrollForHWFrame(int nativeAwContents, int scro llX, int scrollY); |
997 private native int nativeFindAllSync(int nativeAwContents, String searchStri ng); | 1048 private native int nativeFindAllSync(int nativeAwContents, String searchStri ng); |
998 private native void nativeFindAllAsync(int nativeAwContents, String searchSt ring); | 1049 private native void nativeFindAllAsync(int nativeAwContents, String searchSt ring); |
999 private native void nativeFindNext(int nativeAwContents, boolean forward); | 1050 private native void nativeFindNext(int nativeAwContents, boolean forward); |
1000 private native void nativeClearMatches(int nativeAwContents); | 1051 private native void nativeClearMatches(int nativeAwContents); |
1001 private native void nativeClearCache(int nativeAwContents, boolean includeDi skFiles); | 1052 private native void nativeClearCache(int nativeAwContents, boolean includeDi skFiles); |
1002 private native byte[] nativeGetCertificate(int nativeAwContents); | 1053 private native byte[] nativeGetCertificate(int nativeAwContents); |
1054 private native void nativeProceedSslError(int nativeAwContents, boolean proc eed); | |
1003 private native void nativeRequestNewHitTestDataAt(int nativeAwContents, int x, int y); | 1055 private native void nativeRequestNewHitTestDataAt(int nativeAwContents, int x, int y); |
1004 private native void nativeUpdateLastHitTestData(int nativeAwContents); | 1056 private native void nativeUpdateLastHitTestData(int nativeAwContents); |
1005 private native void nativeOnSizeChanged(int nativeAwContents, int w, int h, int ow, int oh); | 1057 private native void nativeOnSizeChanged(int nativeAwContents, int w, int h, int ow, int oh); |
1006 private native void nativeSetWindowViewVisibility(int nativeAwContents, bool ean windowVisible, | 1058 private native void nativeSetWindowViewVisibility(int nativeAwContents, bool ean windowVisible, |
1007 boolean viewVisible); | 1059 boolean viewVisible); |
1008 private native void nativeOnAttachedToWindow(int nativeAwContents, int w, in t h); | 1060 private native void nativeOnAttachedToWindow(int nativeAwContents, int w, in t h); |
1009 private native void nativeOnDetachedFromWindow(int nativeAwContents); | 1061 private native void nativeOnDetachedFromWindow(int nativeAwContents); |
1010 | 1062 |
1011 // Returns null if save state fails. | 1063 // Returns null if save state fails. |
1012 private native byte[] nativeGetOpaqueState(int nativeAwContents); | 1064 private native byte[] nativeGetOpaqueState(int nativeAwContents); |
1013 | 1065 |
1014 // Returns false if restore state fails. | 1066 // Returns false if restore state fails. |
1015 private native boolean nativeRestoreFromOpaqueState(int nativeAwContents, by te[] state); | 1067 private native boolean nativeRestoreFromOpaqueState(int nativeAwContents, by te[] state); |
1016 | 1068 |
1017 private native int nativeReleasePopupWebContents(int nativeAwContents); | 1069 private native int nativeReleasePopupWebContents(int nativeAwContents); |
1018 private native void nativeSetWebContents(int nativeAwContents, int nativeNew WebContents); | 1070 private native void nativeSetWebContents(int nativeAwContents, int nativeNew WebContents); |
1019 private native void nativeFocusFirstNode(int nativeAwContents); | 1071 private native void nativeFocusFirstNode(int nativeAwContents); |
1020 } | 1072 } |
OLD | NEW |