OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.chrome.browser; | 5 package org.chromium.chrome.browser; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.os.AsyncTask; | 8 import android.os.AsyncTask; |
9 import android.os.StrictMode; | 9 import android.os.StrictMode; |
10 import android.view.ContextThemeWrapper; | 10 import android.view.ContextThemeWrapper; |
11 import android.view.InflateException; | 11 import android.view.InflateException; |
12 import android.view.LayoutInflater; | 12 import android.view.LayoutInflater; |
13 import android.view.View; | 13 import android.view.View; |
14 import android.view.ViewGroup; | 14 import android.view.ViewGroup; |
15 import android.view.ViewStub; | 15 import android.view.ViewStub; |
16 import android.widget.FrameLayout; | 16 import android.widget.FrameLayout; |
17 | 17 |
18 import org.chromium.base.Log; | 18 import org.chromium.base.Log; |
19 import org.chromium.base.SysUtils; | 19 import org.chromium.base.SysUtils; |
20 import org.chromium.base.ThreadUtils; | 20 import org.chromium.base.ThreadUtils; |
21 import org.chromium.base.TraceEvent; | 21 import org.chromium.base.TraceEvent; |
22 import org.chromium.chrome.R; | 22 import org.chromium.chrome.R; |
23 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; | 23 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; |
24 import org.chromium.chrome.browser.profiles.Profile; | 24 import org.chromium.chrome.browser.profiles.Profile; |
25 import org.chromium.chrome.browser.widget.ControlContainer; | 25 import org.chromium.chrome.browser.widget.ControlContainer; |
26 import org.chromium.content.browser.ChildProcessCreationParams; | |
26 import org.chromium.content_public.browser.WebContents; | 27 import org.chromium.content_public.browser.WebContents; |
27 | 28 |
28 import java.net.InetAddress; | 29 import java.net.InetAddress; |
29 import java.net.MalformedURLException; | 30 import java.net.MalformedURLException; |
30 import java.net.URL; | 31 import java.net.URL; |
31 import java.net.UnknownHostException; | 32 import java.net.UnknownHostException; |
32 import java.util.HashMap; | 33 import java.util.HashMap; |
33 import java.util.HashSet; | 34 import java.util.HashSet; |
34 import java.util.Map; | 35 import java.util.Map; |
35 import java.util.Set; | 36 import java.util.Set; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 /** | 214 /** |
214 * Creates and initializes a spare WebContents, to be used in a subsequent n avigation. | 215 * Creates and initializes a spare WebContents, to be used in a subsequent n avigation. |
215 * | 216 * |
216 * This creates a renderer that is suitable for any navigation. It can be pi cked up by any tab. | 217 * This creates a renderer that is suitable for any navigation. It can be pi cked up by any tab. |
217 * Can be called multiple times, and must be called from the UI thread. | 218 * Can be called multiple times, and must be called from the UI thread. |
218 * Note that this is a no-op on low-end devices. | 219 * Note that this is a no-op on low-end devices. |
219 */ | 220 */ |
220 public void createSpareWebContents() { | 221 public void createSpareWebContents() { |
221 ThreadUtils.assertOnUiThread(); | 222 ThreadUtils.assertOnUiThread(); |
222 if (mSpareWebContents != null || SysUtils.isLowEndDevice()) return; | 223 if (mSpareWebContents != null || SysUtils.isLowEndDevice()) return; |
223 mSpareWebContents = WebContentsFactory.createWebContentsWithWarmRenderer (false, false); | 224 mSpareWebContents = WebContentsFactory.createWebContentsWithWarmRenderer ( |
225 ChildProcessCreationParams.DEFAULT_ID, false, false); | |
224 } | 226 } |
225 | 227 |
226 /** | 228 /** |
227 * Destroys the spare WebContents if there is one. | 229 * Destroys the spare WebContents if there is one. |
228 */ | 230 */ |
229 public void destroySpareWebContents() { | 231 public void destroySpareWebContents() { |
230 ThreadUtils.assertOnUiThread(); | 232 ThreadUtils.assertOnUiThread(); |
231 if (mSpareWebContents == null) return; | 233 if (mSpareWebContents == null) return; |
232 mSpareWebContents.destroy(); | 234 mSpareWebContents.destroy(); |
233 mSpareWebContents = null; | 235 mSpareWebContents = null; |
234 } | 236 } |
235 | 237 |
236 /** | 238 /** |
237 * Returns a spare WebContents or null, depending on the availability of one . | 239 * Returns a spare WebContents or null, depending on the availability of one . |
238 * | 240 * |
239 * The parameters are the same as for {@link WebContentsFactory#createWebCon tents()}. | 241 * The parameters are the same as for {@link WebContentsFactory#createWebCon tents()}. |
240 * | 242 * |
241 * @return a WebContents, or null. | 243 * @return a WebContents, or null. |
242 */ | 244 */ |
243 public WebContents takeSpareWebContents(boolean incognito, boolean initially Hidden) { | 245 public WebContents takeSpareWebContents( |
246 boolean incognito, boolean initiallyHidden, int childProcessParamId) { | |
boliu
2017/02/23 00:51:30
so this s a general pattern I followed here. All w
| |
244 ThreadUtils.assertOnUiThread(); | 247 ThreadUtils.assertOnUiThread(); |
245 if (incognito || initiallyHidden) return null; | 248 if (incognito || initiallyHidden |
249 || childProcessParamId != ChildProcessCreationParams.DEFAULT_ID) { | |
250 return null; | |
251 } | |
246 WebContents result = mSpareWebContents; | 252 WebContents result = mSpareWebContents; |
247 mSpareWebContents = null; | 253 mSpareWebContents = null; |
248 return result; | 254 return result; |
249 } | 255 } |
250 | 256 |
251 /** | 257 /** |
252 * @return Whether a spare renderer is available. | 258 * @return Whether a spare renderer is available. |
253 */ | 259 */ |
254 public boolean hasSpareWebContents() { | 260 public boolean hasSpareWebContents() { |
255 return mSpareWebContents != null; | 261 return mSpareWebContents != null; |
256 } | 262 } |
257 | 263 |
258 private static native void nativePreconnectUrlAndSubresources(Profile profil e, String url); | 264 private static native void nativePreconnectUrlAndSubresources(Profile profil e, String url); |
259 } | 265 } |
OLD | NEW |