diff options
| author | Primiano Tucci <primiano@google.com> | 2014-10-02 11:03:06 +0100 |
|---|---|---|
| committer | Primiano Tucci <primiano@google.com> | 2014-10-02 11:05:09 +0100 |
| commit | 0c913299e7c9fde0b23cab4cd22b3ad61de50897 (patch) | |
| tree | 7bc50452d535318db44cf52312b863dbfb2156a3 | |
| parent | 76399f9cd23a85c1789f720bfa523a9cdc8efc2b (diff) | |
| parent | a1b0248c80f239e2f6476b9f395b27d0ba1eb3cd (diff) | |
| download | android_frameworks_webview-0c913299e7c9fde0b23cab4cd22b3ad61de50897.tar.gz android_frameworks_webview-0c913299e7c9fde0b23cab4cd22b3ad61de50897.tar.bz2 android_frameworks_webview-0c913299e7c9fde0b23cab4cd22b3ad61de50897.zip | |
Merge chromium-dev @ a1b0248 into aosp/master.
This is to match the push of the chromium M39 branch point (267aeeb8d85c)
into the chromium_org projects.
Change-Id: Ica595e265eea939f2254f009e0e4b7f4ef4336f3
5 files changed, 132 insertions, 56 deletions
diff --git a/chromium/java/com/android/webview/chromium/ResourcesContextWrapperFactory.java b/chromium/java/com/android/webview/chromium/ResourcesContextWrapperFactory.java new file mode 100644 index 0000000..667259e --- /dev/null +++ b/chromium/java/com/android/webview/chromium/ResourcesContextWrapperFactory.java @@ -0,0 +1,121 @@ +/* + * Copyright 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.webview.chromium; + +import android.content.ComponentCallbacks; +import android.content.Context; +import android.content.ContextWrapper; +import android.content.res.AssetManager; +import android.content.res.Resources; +import android.view.LayoutInflater; + +import java.util.WeakHashMap; + +/** + * This class allows us to wrap the application context so we can use resources from the WebView + * apk. We keep a weak map from contexts to wrapped contexts to avoid constantly re-wrapping + * or doubly wrapping contexts. + */ +public class ResourcesContextWrapperFactory { + private static WeakHashMap<Context,ContextWrapper> sCtxToWrapper + = new WeakHashMap<Context,ContextWrapper>(); + private static Object sLock = new Object(); + + private ResourcesContextWrapperFactory() { + } + + public static Context get(Context ctx) { + ContextWrapper wrappedCtx; + synchronized (sLock) { + wrappedCtx = sCtxToWrapper.get(ctx); + if (wrappedCtx == null) { + wrappedCtx = createWrapper(ctx); + sCtxToWrapper.put(ctx, wrappedCtx); + } + } + return wrappedCtx; + } + + // Wrap Context so that we can use resources from the webview resource apk. + private static ContextWrapper createWrapper(final Context ctx) { + final Resources resources = WebViewChromiumFactoryProvider.getWebViewPackageResources(ctx); + final Resources.Theme theme = resources.newTheme(); + + return new ContextWrapper(ctx) { + @Override + public ClassLoader getClassLoader() { + final ClassLoader appCl = getBaseContext().getClassLoader(); + final ClassLoader webViewCl = this.getClass().getClassLoader(); + return new ClassLoader() { + @Override + protected Class<?> findClass(String name) throws ClassNotFoundException { + // First look in the WebViewProvider class loader. + try { + return webViewCl.loadClass(name); + } catch (ClassNotFoundException e) { + // Look in the app class loader; allowing it to throw + // ClassNotFoundException. + return appCl.loadClass(name); + } + } + }; + } + + @Override + public Context getApplicationContext() { + return get(ctx.getApplicationContext()); + } + + @Override + public void registerComponentCallbacks(ComponentCallbacks callback) { + // We have to override registerComponentCallbacks and unregisterComponentCallbacks + // since they call getApplicationContext().[un]registerComponentCallbacks() + // which causes us to go into a loop. + ctx.registerComponentCallbacks(callback); + } + + @Override + public void unregisterComponentCallbacks(ComponentCallbacks callback) { + ctx.unregisterComponentCallbacks(callback); + } + + @Override + public Object getSystemService(String name) { + if (name.equals(Context.LAYOUT_INFLATER_SERVICE)) { + LayoutInflater i = (LayoutInflater) getBaseContext().getSystemService(name); + return i.cloneInContext(this); + } else { + return getBaseContext().getSystemService(name); + } + } + + @Override + public AssetManager getAssets() { + return resources.getAssets(); + } + + @Override + public Resources getResources() { + return resources; + } + + @Override + public Resources.Theme getTheme() { + return theme; + } + }; + } +} diff --git a/chromium/java/com/android/webview/chromium/WebBackForwardListChromium.java b/chromium/java/com/android/webview/chromium/WebBackForwardListChromium.java index ad2b64b..b584ee9 100644 --- a/chromium/java/com/android/webview/chromium/WebBackForwardListChromium.java +++ b/chromium/java/com/android/webview/chromium/WebBackForwardListChromium.java @@ -16,7 +16,7 @@ package com.android.webview.chromium; -import org.chromium.content.browser.NavigationHistory; +import org.chromium.content_public.browser.NavigationHistory; import android.webkit.WebBackForwardList; import android.webkit.WebHistoryItem; diff --git a/chromium/java/com/android/webview/chromium/WebHistoryItemChromium.java b/chromium/java/com/android/webview/chromium/WebHistoryItemChromium.java index 18ab645..e36384b 100644 --- a/chromium/java/com/android/webview/chromium/WebHistoryItemChromium.java +++ b/chromium/java/com/android/webview/chromium/WebHistoryItemChromium.java @@ -16,7 +16,7 @@ package com.android.webview.chromium; -import org.chromium.content.browser.NavigationEntry; +import org.chromium.content_public.browser.NavigationEntry; import android.graphics.Bitmap; import android.webkit.WebHistoryItem; diff --git a/chromium/java/com/android/webview/chromium/WebViewChromium.java b/chromium/java/com/android/webview/chromium/WebViewChromium.java index bc6bec4..23d34d7 100644 --- a/chromium/java/com/android/webview/chromium/WebViewChromium.java +++ b/chromium/java/com/android/webview/chromium/WebViewChromium.java @@ -17,10 +17,8 @@ package com.android.webview.chromium; import android.content.Context; -import android.content.ContextWrapper; import android.content.pm.PackageManager; import android.content.res.Configuration; -import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; @@ -38,7 +36,6 @@ import android.util.Base64; import android.util.Log; import android.view.HardwareCanvas; import android.view.KeyEvent; -import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.View.MeasureSpec; @@ -66,7 +63,7 @@ import org.chromium.android_webview.AwLayoutSizer; import org.chromium.android_webview.AwSettings; import org.chromium.android_webview.AwPrintDocumentAdapter; import org.chromium.base.ThreadUtils; -import org.chromium.content.browser.LoadUrlParams; +import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.net.NetworkChangeNotifier; import java.io.BufferedWriter; @@ -253,54 +250,8 @@ class WebViewChromium implements WebViewProvider, }); } - // Wrap Context so that we can use resources from the webview resource apk. - private static Context resourcesContextWrapper(final Context ctx) { - final Resources resources = WebViewChromiumFactoryProvider.getWebViewPackageResources(ctx); - final Resources.Theme theme = resources.newTheme(); - - return new ContextWrapper(ctx) { - @Override - public ClassLoader getClassLoader() { - final ClassLoader appCl = getBaseContext().getClassLoader(); - final ClassLoader webViewCl = this.getClass().getClassLoader(); - return new ClassLoader() { - @Override - protected Class<?> findClass(String name) throws ClassNotFoundException { - // First look in the WebViewProvider class loader. - try { - return webViewCl.loadClass(name); - } catch (ClassNotFoundException e) { - // Look in the app class loader; allowing it to throw ClassNotFoundException. - return appCl.loadClass(name); - } - } - }; - } - - @Override - public Object getSystemService(String name) { - if (name.equals(Context.LAYOUT_INFLATER_SERVICE)) { - LayoutInflater i = (LayoutInflater) getBaseContext().getSystemService(name); - return i.cloneInContext(this); - } else { - return getBaseContext().getSystemService(name); - } - } - - @Override - public Resources getResources() { - return resources; - } - - @Override - public Resources.Theme getTheme() { - return theme; - } - }; - } - private void initForReal() { - Context ctx = resourcesContextWrapper(mWebView.getContext()); + Context ctx = ResourcesContextWrapperFactory.get(mWebView.getContext()); mAwContents = new AwContents(mFactory.getBrowserContext(), mWebView, ctx, new InternalAccessAdapter(), new WebViewNativeGLDelegate(), mContentsClientAdapter, mWebSettings.getAwSettings()); diff --git a/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java b/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java index aaa11eb..8bde8d6 100644 --- a/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java +++ b/chromium/java/com/android/webview/chromium/WebViewChromiumFactoryProvider.java @@ -51,12 +51,12 @@ import org.chromium.android_webview.AwSettings; import org.chromium.base.CommandLine; import org.chromium.base.MemoryPressureListener; import org.chromium.base.PathService; +import org.chromium.base.ResourceExtractor; import org.chromium.base.ThreadUtils; import org.chromium.base.library_loader.LibraryLoader; import org.chromium.base.library_loader.ProcessInitException; import org.chromium.content.app.ContentMain; import org.chromium.content.browser.ContentViewStatics; -import org.chromium.content.browser.ResourceExtractor; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -191,7 +191,7 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { // Make sure that ResourceProvider is initialized before starting the browser process. setUpResources(ActivityThread.currentApplication()); - AwBrowserProcess.start(ActivityThread.currentApplication()); + AwBrowserProcess.start(getWrappedCurrentApplicationContext()); initPlatSupportLibrary(); if (Build.IS_DEBUGGABLE) { @@ -220,6 +220,10 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { } } + private Context getWrappedCurrentApplicationContext() { + return ResourcesContextWrapperFactory.get(ActivityThread.currentApplication()); + } + AwBrowserContext getBrowserContext() { synchronized (mLock) { return getBrowserContextLocked(); @@ -346,7 +350,7 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { // will bring up just the parts it needs to make this work on a temporary // basis until Chromium is started for real. The temporary cookie manager // needs the application context to have been set. - ContentMain.initApplicationContext(ActivityThread.currentApplication()); + ContentMain.initApplicationContext(getWrappedCurrentApplicationContext()); } mCookieManager = new CookieManagerAdapter(new AwCookieManager()); } |
