OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 com.android.webview.chromium; | 5 package com.android.webview.chromium; |
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.content.Context; | 9 import android.content.Context; |
10 import android.content.Intent; | 10 import android.content.Intent; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 import org.chromium.android_webview.AwPrintDocumentAdapter; | 55 import org.chromium.android_webview.AwPrintDocumentAdapter; |
56 import org.chromium.android_webview.AwSettings; | 56 import org.chromium.android_webview.AwSettings; |
57 import org.chromium.android_webview.ResourcesContextWrapperFactory; | 57 import org.chromium.android_webview.ResourcesContextWrapperFactory; |
58 import org.chromium.base.ThreadUtils; | 58 import org.chromium.base.ThreadUtils; |
59 import org.chromium.base.annotations.SuppressFBWarnings; | 59 import org.chromium.base.annotations.SuppressFBWarnings; |
60 import org.chromium.content.browser.SmartClipProvider; | 60 import org.chromium.content.browser.SmartClipProvider; |
61 import org.chromium.content_public.browser.NavigationHistory; | 61 import org.chromium.content_public.browser.NavigationHistory; |
62 | 62 |
63 import java.io.BufferedWriter; | 63 import java.io.BufferedWriter; |
64 import java.io.File; | 64 import java.io.File; |
65 import java.lang.reflect.Field; | |
65 import java.lang.reflect.Method; | 66 import java.lang.reflect.Method; |
66 import java.util.Map; | 67 import java.util.Map; |
67 import java.util.concurrent.Callable; | 68 import java.util.concurrent.Callable; |
68 | 69 |
69 /** | 70 /** |
70 * This class is the delegate to which WebViewProxy forwards all API calls. | 71 * This class is the delegate to which WebViewProxy forwards all API calls. |
71 * | 72 * |
72 * Most of the actual functionality is implemented by AwContents (or ContentView Core within | 73 * Most of the actual functionality is implemented by AwContents (or ContentView Core within |
73 * it). This class also contains WebView-specific APIs that require the creation of other | 74 * it). This class also contains WebView-specific APIs that require the creation of other |
74 * adapters (otherwise org.chromium.content would depend on the webview.chromium package) | 75 * adapters (otherwise org.chromium.content would depend on the webview.chromium package) |
(...skipping 20 matching lines...) Expand all Loading... | |
95 private AwContents mAwContents; | 96 private AwContents mAwContents; |
96 // Non-null if this webview is using the GL accelerated draw path. | 97 // Non-null if this webview is using the GL accelerated draw path. |
97 private DrawGLFunctor mGLfunctor; | 98 private DrawGLFunctor mGLfunctor; |
98 | 99 |
99 private final WebView.HitTestResult mHitTestResult; | 100 private final WebView.HitTestResult mHitTestResult; |
100 | 101 |
101 private final int mAppTargetSdkVersion; | 102 private final int mAppTargetSdkVersion; |
102 | 103 |
103 private WebViewChromiumFactoryProvider mFactory; | 104 private WebViewChromiumFactoryProvider mFactory; |
104 | 105 |
106 private final boolean mIsHtcMail; | |
107 | |
105 private static boolean sRecordWholeDocumentEnabledByApi = false; | 108 private static boolean sRecordWholeDocumentEnabledByApi = false; |
106 static void enableSlowWholeDocumentDraw() { | 109 static void enableSlowWholeDocumentDraw() { |
107 sRecordWholeDocumentEnabledByApi = true; | 110 sRecordWholeDocumentEnabledByApi = true; |
108 } | 111 } |
109 | 112 |
110 // This does not touch any global / non-threadsafe state, but note that | 113 // This does not touch any global / non-threadsafe state, but note that |
111 // init is ofter called right after and is NOT threadsafe. | 114 // init is ofter called right after and is NOT threadsafe. |
112 public WebViewChromium(WebViewChromiumFactoryProvider factory, WebView webVi ew, | 115 public WebViewChromium(WebViewChromiumFactoryProvider factory, WebView webVi ew, |
113 WebView.PrivateAccess webViewPrivate) { | 116 WebView.PrivateAccess webViewPrivate, boolean isHtcMail) { |
Torne
2016/08/16 11:45:07
Let's not call this "isHtcMail" - let's name it af
Changwan Ryu
2016/08/17 08:00:13
changed as shouldDisableThreadChecking
| |
114 mWebView = webView; | 117 mWebView = webView; |
115 mWebViewPrivate = webViewPrivate; | 118 mWebViewPrivate = webViewPrivate; |
116 mHitTestResult = new WebView.HitTestResult(); | 119 mHitTestResult = new WebView.HitTestResult(); |
117 mContext = ResourcesContextWrapperFactory.get(mWebView.getContext()); | 120 mContext = ResourcesContextWrapperFactory.get(mWebView.getContext()); |
118 mAppTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; | 121 mAppTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
119 mFactory = factory; | 122 mFactory = factory; |
123 mIsHtcMail = isHtcMail; | |
120 factory.getWebViewDelegate().addWebViewAssetPath(mWebView.getContext()); | 124 factory.getWebViewDelegate().addWebViewAssetPath(mWebView.getContext()); |
121 } | 125 } |
122 | 126 |
123 static void completeWindowCreation(WebView parent, WebView child) { | 127 static void completeWindowCreation(WebView parent, WebView child) { |
124 AwContents parentContents = ((WebViewChromium) parent.getWebViewProvider ()).mAwContents; | 128 AwContents parentContents = ((WebViewChromium) parent.getWebViewProvider ()).mAwContents; |
125 AwContents childContents = | 129 AwContents childContents = |
126 child == null ? null : ((WebViewChromium) child.getWebViewProvid er()).mAwContents; | 130 child == null ? null : ((WebViewChromium) child.getWebViewProvid er()).mAwContents; |
127 parentContents.supplyContentsForPopup(childContents); | 131 parentContents.supplyContentsForPopup(childContents); |
128 } | 132 } |
129 | 133 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 initForReal(); | 193 initForReal(); |
190 if (privateBrowsing) { | 194 if (privateBrowsing) { |
191 // Intentionally irreversibly disable the webview instance, so that private | 195 // Intentionally irreversibly disable the webview instance, so that private |
192 // user data cannot leak through misuse of a non-privateBrow ing WebView | 196 // user data cannot leak through misuse of a non-privateBrow ing WebView |
193 // instance. Can't just null out mAwContents as we never nul l-check it | 197 // instance. Can't just null out mAwContents as we never nul l-check it |
194 // before use. | 198 // before use. |
195 destroy(); | 199 destroy(); |
196 } | 200 } |
197 } | 201 } |
198 }); | 202 }); |
203 // This is called here because otherwise compiler optimization may call | |
204 // disableThreadChecking before setting WebView#sEnforceThreadChecking. | |
205 if (mIsHtcMail) disableThreadChecking(); | |
206 } | |
207 | |
208 // This is a workaround for https://crbug.com/622151. | |
209 // In HTC's email app, InputConnection.setComposingText() will call WebView. evaluateJavaScript, | |
210 // and thread assertion will occur. We turn off WebView thread assertion for this app. | |
211 private void disableThreadChecking() { | |
212 try { | |
213 Class<?> webViewClass = Class.forName("android.webkit.WebView"); | |
214 Field field = webViewClass.getDeclaredField("sEnforceThreadChecking" ); | |
215 field.setAccessible(true); | |
216 field.setBoolean(null, false); | |
217 field.setAccessible(false); | |
218 } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessEx ception | |
219 | IllegalArgumentException e) { | |
220 Log.w(TAG, "Failed to disable thread checking."); | |
221 } | |
199 } | 222 } |
200 | 223 |
201 private void initForReal() { | 224 private void initForReal() { |
202 AwContentsStatics.setRecordFullDocument(sRecordWholeDocumentEnabledByApi | 225 AwContentsStatics.setRecordFullDocument(sRecordWholeDocumentEnabledByApi |
203 || mAppTargetSdkVersion < Build.VERSION_CODES.LOLLIPOP); | 226 || mAppTargetSdkVersion < Build.VERSION_CODES.LOLLIPOP); |
204 | 227 |
205 mAwContents = new AwContents(mFactory.getBrowserContextOnUiThread(), mWe bView, mContext, | 228 mAwContents = new AwContents(mFactory.getBrowserContextOnUiThread(), mWe bView, mContext, |
206 new InternalAccessAdapter(), new WebViewNativeDrawGLFunctorFacto ry(), | 229 new InternalAccessAdapter(), new WebViewNativeDrawGLFunctorFacto ry(), |
207 mContentsClientAdapter, mWebSettings.getAwSettings()); | 230 mContentsClientAdapter, mWebSettings.getAwSettings()); |
208 | 231 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 @Override | 556 @Override |
534 public void run() { | 557 public void run() { |
535 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, enc oding, historyUrl); | 558 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, enc oding, historyUrl); |
536 } | 559 } |
537 }); | 560 }); |
538 return; | 561 return; |
539 } | 562 } |
540 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, histo ryUrl); | 563 mAwContents.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, histo ryUrl); |
541 } | 564 } |
542 | 565 |
543 public void evaluateJavaScript(String script, ValueCallback<String> resultCa llback) { | 566 @Override |
544 checkThread(); | 567 public void evaluateJavaScript( |
545 mAwContents.evaluateJavaScript(script, resultCallback); | 568 final String script, final ValueCallback<String> resultCallback) { |
569 if (mIsHtcMail) { | |
570 // This is a workaround for https://crbug.com/622151. | |
571 if (checkNeedsPost()) { | |
572 mFactory.addTask(new Runnable() { | |
573 @Override | |
574 public void run() { | |
575 mAwContents.evaluateJavaScript(script, resultCallback); | |
576 } | |
577 }); | |
578 return; | |
579 } | |
580 } else { | |
581 checkThread(); | |
582 mAwContents.evaluateJavaScript(script, resultCallback); | |
583 } | |
546 } | 584 } |
547 | 585 |
548 @Override | 586 @Override |
549 public void saveWebArchive(String filename) { | 587 public void saveWebArchive(String filename) { |
550 saveWebArchive(filename, false, null); | 588 saveWebArchive(filename, false, null); |
551 } | 589 } |
552 | 590 |
553 @Override | 591 @Override |
554 public void saveWebArchive(final String basename, final boolean autoname, | 592 public void saveWebArchive(final String basename, final boolean autoname, |
555 final ValueCallback<String> callback) { | 593 final ValueCallback<String> callback) { |
(...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2011 return originalHandler; | 2049 return originalHandler; |
2012 } | 2050 } |
2013 | 2051 |
2014 // Overrides method added to WebViewProvider.ViewDelegate interface | 2052 // Overrides method added to WebViewProvider.ViewDelegate interface |
2015 // (not called in M and below) | 2053 // (not called in M and below) |
2016 public View findFocus(View originalFocusedView) { | 2054 public View findFocus(View originalFocusedView) { |
2017 return originalFocusedView; | 2055 return originalFocusedView; |
2018 } | 2056 } |
2019 | 2057 |
2020 // Remove from superclass | 2058 // Remove from superclass |
2059 @Override | |
2021 public void preDispatchDraw(Canvas canvas) { | 2060 public void preDispatchDraw(Canvas canvas) { |
2022 // TODO(leandrogracia): remove this method from WebViewProvider if we th ink | 2061 // TODO(leandrogracia): remove this method from WebViewProvider if we th ink |
2023 // we won't need it again. | 2062 // we won't need it again. |
2024 } | 2063 } |
2025 | 2064 |
2065 @Override | |
2026 public void onStartTemporaryDetach() { | 2066 public void onStartTemporaryDetach() { |
2027 mAwContents.onStartTemporaryDetach(); | 2067 mAwContents.onStartTemporaryDetach(); |
2028 } | 2068 } |
2029 | 2069 |
2070 @Override | |
2030 public void onFinishTemporaryDetach() { | 2071 public void onFinishTemporaryDetach() { |
2031 mAwContents.onFinishTemporaryDetach(); | 2072 mAwContents.onFinishTemporaryDetach(); |
2032 } | 2073 } |
2033 | 2074 |
2034 // WebViewProvider.ScrollDelegate implementation --------------------------- ------------------- | 2075 // WebViewProvider.ScrollDelegate implementation --------------------------- ------------------- |
2035 | 2076 |
2036 @Override | 2077 @Override |
2037 public int computeHorizontalScrollRange() { | 2078 public int computeHorizontalScrollRange() { |
2038 mFactory.startYourEngines(false); | 2079 mFactory.startYourEngines(false); |
2039 if (checkNeedsPost()) { | 2080 if (checkNeedsPost()) { |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2227 mAwContents.extractSmartClipData(x, y, width, height); | 2268 mAwContents.extractSmartClipData(x, y, width, height); |
2228 } | 2269 } |
2229 | 2270 |
2230 // Implements SmartClipProvider | 2271 // Implements SmartClipProvider |
2231 @Override | 2272 @Override |
2232 public void setSmartClipResultHandler(final Handler resultHandler) { | 2273 public void setSmartClipResultHandler(final Handler resultHandler) { |
2233 checkThread(); | 2274 checkThread(); |
2234 mAwContents.setSmartClipResultHandler(resultHandler); | 2275 mAwContents.setSmartClipResultHandler(resultHandler); |
2235 } | 2276 } |
2236 } | 2277 } |
OLD | NEW |