Chromium Code Reviews| 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.TargetApi; | 7 import android.annotation.TargetApi; |
| 8 import android.app.Application; | 8 import android.app.Application; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.content.ContextWrapper; | 10 import android.content.ContextWrapper; |
| 11 import android.content.pm.PackageInfo; | 11 import android.content.pm.PackageInfo; |
| 12 import android.content.res.AssetManager; | 12 import android.content.res.AssetManager; |
| 13 import android.content.res.Resources; | 13 import android.content.res.Resources; |
| 14 import android.graphics.Canvas; | 14 import android.graphics.Canvas; |
| 15 import android.os.Build; | 15 import android.os.Build; |
| 16 import android.os.Trace; | 16 import android.os.Trace; |
| 17 import android.provider.Settings; | |
| 17 import android.util.SparseArray; | 18 import android.util.SparseArray; |
| 18 import android.view.View; | 19 import android.view.View; |
| 19 | 20 |
| 21 import org.chromium.base.ContextUtils; | |
| 22 | |
| 20 import java.lang.reflect.Method; | 23 import java.lang.reflect.Method; |
| 21 | 24 |
| 22 /** | 25 /** |
| 23 * Factory class for {@link WebViewDelegate com.android.webview.chromium.WebView Delegate}s. | 26 * Factory class for {@link WebViewDelegate com.android.webview.chromium.WebView Delegate}s. |
| 24 * | 27 * |
| 25 * <p>{@link WebViewDelegate com.android.webview.chromium.WebViewDelegate}s prov ide the same | 28 * <p>{@link WebViewDelegate com.android.webview.chromium.WebViewDelegate}s prov ide the same |
| 26 * interface as {@link android.webkit.WebViewDelegate android.webkit.WebViewDele gate} but without | 29 * interface as {@link android.webkit.WebViewDelegate android.webkit.WebViewDele gate} but without |
| 27 * a dependency on the webkit class. Defining our own | 30 * a dependency on the webkit class. Defining our own |
| 28 * {@link WebViewDelegate com.android.webview.chromium.WebViewDelegate} in frame works/webview | 31 * {@link WebViewDelegate com.android.webview.chromium.WebViewDelegate} in frame works/webview |
| 29 * allows the WebView apk to be binary compatible with the API 21 version of the framework, in | 32 * allows the WebView apk to be binary compatible with the API 21 version of the framework, in |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 int getPackageId(Resources resources, String packageName); | 78 int getPackageId(Resources resources, String packageName); |
| 76 | 79 |
| 77 /** @see android.webkit.WebViewDelegate#getApplication */ | 80 /** @see android.webkit.WebViewDelegate#getApplication */ |
| 78 Application getApplication(); | 81 Application getApplication(); |
| 79 | 82 |
| 80 /** @see android.webkit.WebViewDelegate#getErrorString */ | 83 /** @see android.webkit.WebViewDelegate#getErrorString */ |
| 81 String getErrorString(Context context, int errorCode); | 84 String getErrorString(Context context, int errorCode); |
| 82 | 85 |
| 83 /** @see android.webkit.WebViewDelegate#addWebViewAssetPath */ | 86 /** @see android.webkit.WebViewDelegate#addWebViewAssetPath */ |
| 84 void addWebViewAssetPath(Context context); | 87 void addWebViewAssetPath(Context context); |
| 88 | |
| 89 /** @see android.webkit.WebViewDelegate#isMultiProcessEnabled */ | |
| 90 boolean isMultiProcessEnabled(); | |
| 85 } | 91 } |
| 86 | 92 |
| 87 /** | 93 /** |
| 88 * Creates a {@link WebViewDelegate com.android.webview.chromium.WebViewDele gate} that proxies | 94 * Creates a {@link WebViewDelegate com.android.webview.chromium.WebViewDele gate} that proxies |
| 89 * requests to the given {@link android.webkit.WebViewDelegate android.webki t.WebViewDelegate}. | 95 * requests to the given {@link android.webkit.WebViewDelegate android.webki t.WebViewDelegate}. |
| 90 * | 96 * |
| 91 * @return the created delegate | 97 * @return the created delegate |
| 92 */ | 98 */ |
| 93 static WebViewDelegate createProxyDelegate(android.webkit.WebViewDelegate de legate) { | 99 static WebViewDelegate createProxyDelegate(android.webkit.WebViewDelegate de legate) { |
| 94 return new ProxyDelegate(delegate); | 100 return new ProxyDelegate(delegate); |
| 95 } | 101 } |
| 96 | 102 |
| 97 /** | 103 /** |
| 98 * Creates a {@link WebViewDelegate com.android.webview.chromium.WebViewDele gate} compatible | 104 * Creates a {@link WebViewDelegate com.android.webview.chromium.WebViewDele gate} compatible |
| 99 * with the API 21 version of the framework in which | 105 * with the API 21 version of the framework in which |
| 100 * {@link android.webkit.WebViewDelegate android.webkit.WebViewDelegate} had not yet been | 106 * {@link android.webkit.WebViewDelegate android.webkit.WebViewDelegate} had not yet been |
| 101 * introduced. | 107 * introduced. |
| 102 * | 108 * |
| 103 * @return the created delegate | 109 * @return the created delegate |
| 104 */ | 110 */ |
| 105 static WebViewDelegate createApi21CompatibilityDelegate() { | 111 static WebViewDelegate createApi21CompatibilityDelegate() { |
| 106 return new Api21CompatibilityDelegate(); | 112 return new Api21CompatibilityDelegate(); |
| 107 } | 113 } |
| 108 | 114 |
| 109 /** | 115 /** |
| 110 * A {@link WebViewDelegate com.android.webview.chromium.WebViewDelegate} th at proxies requests | 116 * A {@link WebViewDelegate com.android.webview.chromium.WebViewDelegate} th at proxies requests |
| 111 * to a {@link android.webkit.WebViewDelegate android.webkit.WebViewDelegate }. | 117 * to a {@link android.webkit.WebViewDelegate android.webkit.WebViewDelegate }. |
| 112 */ | 118 */ |
| 113 private static class ProxyDelegate implements WebViewDelegate { | 119 static class ProxyDelegate implements WebViewDelegate { |
|
boliu
2017/01/23 16:34:18
does protected work here too..?
Torne
2017/01/23 17:27:30
Likewise no point.
| |
| 114 android.webkit.WebViewDelegate mDelegate; | 120 android.webkit.WebViewDelegate mDelegate; |
| 115 | 121 |
| 116 ProxyDelegate(android.webkit.WebViewDelegate delegate) { | 122 ProxyDelegate(android.webkit.WebViewDelegate delegate) { |
| 117 mDelegate = delegate; | 123 mDelegate = delegate; |
| 118 } | 124 } |
| 119 | 125 |
| 120 @Override | 126 @Override |
| 121 public void setOnTraceEnabledChangeListener(final OnTraceEnabledChangeLi stener listener) { | 127 public void setOnTraceEnabledChangeListener(final OnTraceEnabledChangeLi stener listener) { |
| 122 mDelegate.setOnTraceEnabledChangeListener( | 128 mDelegate.setOnTraceEnabledChangeListener( |
| 123 new android.webkit.WebViewDelegate.OnTraceEnabledChangeListe ner() { | 129 new android.webkit.WebViewDelegate.OnTraceEnabledChangeListe ner() { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 // wrapper here here to avoid calling the getAssets() | 197 // wrapper here here to avoid calling the getAssets() |
| 192 // proxy chain (which we cannot change because it is in | 198 // proxy chain (which we cannot change because it is in |
| 193 // WebView framework code). | 199 // WebView framework code). |
| 194 mDelegate.addWebViewAssetPath(new ContextWrapper(context) { | 200 mDelegate.addWebViewAssetPath(new ContextWrapper(context) { |
| 195 @Override | 201 @Override |
| 196 public AssetManager getAssets() { | 202 public AssetManager getAssets() { |
| 197 return getResources().getAssets(); | 203 return getResources().getAssets(); |
| 198 } | 204 } |
| 199 }); | 205 }); |
| 200 } | 206 } |
| 207 | |
| 208 @Override | |
| 209 public boolean isMultiProcessEnabled() { | |
| 210 // Multiprocess requires N or later. | |
|
boliu
2017/01/23 16:34:18
I suppose this class was never meant to contain im
Torne
2017/01/23 17:27:30
I was considering renaming it to Api22AndUpDelegat
boliu
2017/01/23 17:44:04
Err, no :p
I meant at callsite, have a if <= N, d
Torne
2017/01/24 11:24:01
I think that's a better idea actually; I'll do it
| |
| 211 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return false; | |
| 212 | |
| 213 // Check the multiprocess developer setting. | |
| 214 return Settings.Global.getInt(ContextUtils.getApplicationContext().g etContentResolver(), | |
| 215 Settings.Global.WEBVIEW_MULTIPROCESS, 0) == 1; | |
| 216 } | |
| 201 } | 217 } |
| 202 | 218 |
| 203 /** | 219 /** |
| 204 * A {@link WebViewDelegate com.android.webview.chromium.WebViewDelegate} co mpatible with the | 220 * A {@link WebViewDelegate com.android.webview.chromium.WebViewDelegate} co mpatible with the |
| 205 * API 21 version of the framework in which | 221 * API 21 version of the framework in which |
| 206 * {@link android.webkit.WebViewDelegate android.webkit.WebViewDelegate} had not yet been | 222 * {@link android.webkit.WebViewDelegate android.webkit.WebViewDelegate} had not yet been |
| 207 * introduced. | 223 * introduced. |
| 208 * | 224 * |
| 209 * <p>This class implements the | 225 * <p>This class implements the |
| 210 * {@link WebViewDelegate com.android.webview.chromium.WebViewDelegate} func tionality by using | 226 * {@link WebViewDelegate com.android.webview.chromium.WebViewDelegate} func tionality by using |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 try { | 392 try { |
| 377 PackageInfo info = (PackageInfo) mGetLoadedPackageInfoMethod.inv oke(null); | 393 PackageInfo info = (PackageInfo) mGetLoadedPackageInfoMethod.inv oke(null); |
| 378 // Avoid calling the ContextWrapper.getAssets() proxy | 394 // Avoid calling the ContextWrapper.getAssets() proxy |
| 379 // chain, which can return an unexpected AssetManager. | 395 // chain, which can return an unexpected AssetManager. |
| 380 mAddAssetPathMethod.invoke( | 396 mAddAssetPathMethod.invoke( |
| 381 context.getResources().getAssets(), info.applicationInfo .sourceDir); | 397 context.getResources().getAssets(), info.applicationInfo .sourceDir); |
| 382 } catch (Exception e) { | 398 } catch (Exception e) { |
| 383 throw new RuntimeException("Invalid reflection", e); | 399 throw new RuntimeException("Invalid reflection", e); |
| 384 } | 400 } |
| 385 } | 401 } |
| 402 | |
| 403 @Override | |
| 404 public boolean isMultiProcessEnabled() { | |
| 405 return false; | |
| 406 } | |
| 386 } | 407 } |
| 387 } | 408 } |
| OLD | NEW |