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.content.ComponentCallbacks; | 7 import android.content.ComponentCallbacks; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.ContextWrapper; | 9 import android.content.ContextWrapper; |
10 import android.view.LayoutInflater; | 10 import android.view.LayoutInflater; |
11 | 11 |
| 12 import org.chromium.base.annotations.SuppressFBWarnings; |
| 13 |
12 import java.util.WeakHashMap; | 14 import java.util.WeakHashMap; |
13 | 15 |
14 /** | 16 /** |
15 * This class allows us to wrap the application context so that the WebView impl
ementation can | 17 * This class allows us to wrap the application context so that the WebView impl
ementation can |
16 * correctly reference both org.chromium.* and application classes which is nece
ssary to properly | 18 * correctly reference both org.chromium.* and application classes which is nece
ssary to properly |
17 * inflate UI. We keep a weak map from contexts to wrapped contexts to avoid co
nstantly re-wrapping | 19 * inflate UI. We keep a weak map from contexts to wrapped contexts to avoid co
nstantly re-wrapping |
18 * or doubly wrapping contexts. | 20 * or doubly wrapping contexts. |
19 */ | 21 */ |
20 public class ResourcesContextWrapperFactory { | 22 public class ResourcesContextWrapperFactory { |
21 private static WeakHashMap<Context, ContextWrapper> sCtxToWrapper = | 23 private static WeakHashMap<Context, ContextWrapper> sCtxToWrapper = |
(...skipping 11 matching lines...) Expand all Loading... |
33 sCtxToWrapper.put(ctx, wrappedCtx); | 35 sCtxToWrapper.put(ctx, wrappedCtx); |
34 } | 36 } |
35 } | 37 } |
36 return wrappedCtx; | 38 return wrappedCtx; |
37 } | 39 } |
38 | 40 |
39 private static ContextWrapper createWrapper(final Context ctx) { | 41 private static ContextWrapper createWrapper(final Context ctx) { |
40 return new ContextWrapper(ctx) { | 42 return new ContextWrapper(ctx) { |
41 private Context mApplicationContext; | 43 private Context mApplicationContext; |
42 | 44 |
| 45 @SuppressFBWarnings("DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED") |
43 @Override | 46 @Override |
44 public ClassLoader getClassLoader() { | 47 public ClassLoader getClassLoader() { |
45 final ClassLoader appCl = getBaseContext().getClassLoader(); | 48 final ClassLoader appCl = getBaseContext().getClassLoader(); |
46 final ClassLoader webViewCl = this.getClass().getClassLoader(); | 49 final ClassLoader webViewCl = this.getClass().getClassLoader(); |
47 return new ClassLoader() { | 50 return new ClassLoader() { |
48 @Override | 51 @Override |
49 protected Class<?> findClass(String name) throws ClassNotFou
ndException { | 52 protected Class<?> findClass(String name) throws ClassNotFou
ndException { |
50 // First look in the WebViewProvider class loader. | 53 // First look in the WebViewProvider class loader. |
51 try { | 54 try { |
52 return webViewCl.loadClass(name); | 55 return webViewCl.loadClass(name); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 ctx.registerComponentCallbacks(callback); | 87 ctx.registerComponentCallbacks(callback); |
85 } | 88 } |
86 | 89 |
87 @Override | 90 @Override |
88 public void unregisterComponentCallbacks(ComponentCallbacks callback
) { | 91 public void unregisterComponentCallbacks(ComponentCallbacks callback
) { |
89 ctx.unregisterComponentCallbacks(callback); | 92 ctx.unregisterComponentCallbacks(callback); |
90 } | 93 } |
91 }; | 94 }; |
92 } | 95 } |
93 } | 96 } |
OLD | NEW |