OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.chromecast.shell; | |
6 | |
7 import android.app.Activity; | |
8 import android.content.Context; | |
9 import android.content.Intent; | |
10 import android.os.Build; | |
11 import android.os.Debug; | |
12 import android.util.Log; | |
13 | |
14 import org.chromium.base.BaseSwitches; | |
15 import org.chromium.base.CommandLine; | |
16 import org.chromium.base.PathUtils; | |
17 import org.chromium.base.library_loader.LibraryLoader; | |
18 import org.chromium.base.library_loader.ProcessInitException; | |
19 import org.chromium.content.browser.BrowserStartupController; | |
20 import org.chromium.content.browser.DeviceUtils; | |
21 import org.chromium.content.browser.ResourceExtractor; | |
22 | |
23 /** | |
24 * Static, one-time initialization for the browser process. | |
25 */ | |
26 public class CastBrowserHelper { | |
27 private static final String TAG = "CastBrowserHelper"; | |
28 | |
29 public static final String COMMAND_LINE_FILE = "/data/local/tmp/castshell-co mmand-line"; | |
30 public static final String COMMAND_LINE_ARGS_KEY = "commandLineArgs"; | |
31 | |
32 private static final String[] MANDATORY_PAK_FILES = new String[] {"cast_shel l.pak"}; | |
33 private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "cast_shell"; | |
34 private static boolean sIsBrowserInitialized = false; | |
35 | |
36 /** | |
37 * Starts the browser process synchronously, returning success or failure. I f the browser has | |
38 * already started, immediately returns true without performing any more ini tialization. | |
39 * This may only be called on the UI thread. | |
40 * | |
41 * @return whether or not the process started successfully | |
42 */ | |
43 public static boolean initializeBrowser(Context context) { | |
44 if (sIsBrowserInitialized) return true; | |
45 | |
46 Log.d(TAG, "Performing one-time browser initialization"); | |
47 | |
48 ResourceExtractor.setMandatoryPaksToExtract(MANDATORY_PAK_FILES); | |
Yaron
2014/08/20 18:11:02
Aren't both of these done in CastApplication.initi
gunsch
2014/08/21 22:31:28
Done.
| |
49 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX); | |
50 | |
51 // Initializing the command line must occur before loading the library. | |
52 if (!CommandLine.isInitialized()) { | |
53 if (allowCommandLineImport()) { | |
54 Log.d(TAG, "Initializing command line from " + COMMAND_LINE_FILE ); | |
55 CommandLine.initFromFile(COMMAND_LINE_FILE); | |
56 } else { | |
57 CommandLine.init(null); | |
58 } | |
59 | |
60 if (context instanceof Activity) { | |
61 Intent launchingIntent = ((Activity) context).getIntent(); | |
62 String[] commandLineParams = getCommandLineParamsFromIntent(laun chingIntent); | |
63 if (commandLineParams != null) { | |
64 CommandLine.getInstance().appendSwitchesAndArguments(command LineParams); | |
65 } | |
66 } | |
67 } | |
68 | |
69 CommandLine.getInstance().appendSwitchWithValue("force-device-scale-fact or", "1"); | |
70 | |
71 waitForDebuggerIfNeeded(); | |
72 | |
73 DeviceUtils.addDeviceSpecificUserAgentSwitch(context); | |
74 | |
75 try { | |
76 LibraryLoader.ensureInitialized(); | |
77 | |
78 Log.d(TAG, "Loading BrowserStartupController..."); | |
79 BrowserStartupController.get(context).startBrowserProcessesSync(fals e); | |
80 initializePlatformKeySystem(); | |
81 | |
82 sIsBrowserInitialized = true; | |
83 return true; | |
84 } catch (ProcessInitException e) { | |
85 Log.e(TAG, "Unable to launch browser process.", e); | |
86 return false; | |
87 } | |
88 } | |
89 | |
90 private static boolean allowCommandLineImport() { | |
91 return !Build.TYPE.equals("user"); | |
92 } | |
93 | |
94 private static String[] getCommandLineParamsFromIntent(Intent intent) { | |
95 return intent != null ? intent.getStringArrayExtra(COMMAND_LINE_ARGS_KEY ) : null; | |
96 } | |
97 | |
98 private static void waitForDebuggerIfNeeded() { | |
99 if (CommandLine.getInstance().hasSwitch(BaseSwitches.WAIT_FOR_JAVA_DEBUG GER)) { | |
100 Log.e(TAG, "Waiting for Java debugger to connect..."); | |
101 Debug.waitForDebugger(); | |
102 Log.e(TAG, "Java debugger connected. Resuming execution."); | |
103 } | |
104 } | |
105 | |
106 private static void initializePlatformKeySystem() { | |
Yaron
2014/08/20 18:11:02
?
gunsch
2014/08/21 22:31:28
Was left as a known TODO for more code to be added
| |
107 } | |
108 | |
109 } | |
OLD | NEW |