Chromium Code Reviews| 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.library_loader.LibraryLoader; | |
| 17 import org.chromium.base.library_loader.ProcessInitException; | |
| 18 import org.chromium.content.browser.BrowserStartupController; | |
| 19 import org.chromium.content.browser.DeviceUtils; | |
| 20 | |
| 21 /** | |
| 22 * Static, one-time initialization for the browser process. | |
| 23 */ | |
| 24 public class CastBrowserHelper { | |
| 25 private static final String TAG = "CastBrowserHelper"; | |
| 26 | |
| 27 public static final String COMMAND_LINE_FILE = "/data/local/tmp/castshell-co mmand-line"; | |
| 28 public static final String COMMAND_LINE_ARGS_KEY = "commandLineArgs"; | |
| 29 | |
| 30 private static boolean sIsBrowserInitialized = false; | |
| 31 | |
| 32 /** | |
| 33 * Starts the browser process synchronously, returning success or failure. I f the browser has | |
| 34 * already started, immediately returns true without performing any more ini tialization. | |
| 35 * This may only be called on the UI thread. | |
| 36 * | |
| 37 * @return whether or not the process started successfully | |
| 38 */ | |
| 39 public static boolean initializeBrowser(Context context) { | |
| 40 if (sIsBrowserInitialized) return true; | |
| 41 | |
| 42 Log.d(TAG, "Performing one-time browser initialization"); | |
| 43 | |
| 44 // Initializing the command line must occur before loading the library. | |
| 45 if (!CommandLine.isInitialized()) { | |
| 46 if (allowCommandLineImport()) { | |
| 47 Log.d(TAG, "Initializing command line from " + COMMAND_LINE_FILE ); | |
| 48 CommandLine.initFromFile(COMMAND_LINE_FILE); | |
| 49 } else { | |
| 50 CommandLine.init(null); | |
| 51 } | |
| 52 | |
| 53 if (context instanceof Activity) { | |
| 54 Intent launchingIntent = ((Activity) context).getIntent(); | |
| 55 String[] commandLineParams = getCommandLineParamsFromIntent(laun chingIntent); | |
| 56 if (commandLineParams != null) { | |
| 57 CommandLine.getInstance().appendSwitchesAndArguments(command LineParams); | |
| 58 } | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 CommandLine.getInstance().appendSwitchWithValue("force-device-scale-fact or", "1"); | |
|
Yaron
2014/09/06 01:10:14
use constant from ContentSwitches
gunsch
2014/09/08 19:42:23
Done.
| |
| 63 | |
| 64 waitForDebuggerIfNeeded(); | |
| 65 | |
| 66 DeviceUtils.addDeviceSpecificUserAgentSwitch(context); | |
| 67 | |
| 68 try { | |
| 69 LibraryLoader.ensureInitialized(); | |
| 70 | |
| 71 Log.d(TAG, "Loading BrowserStartupController..."); | |
| 72 BrowserStartupController.get(context).startBrowserProcessesSync(fals e); | |
| 73 | |
| 74 sIsBrowserInitialized = true; | |
| 75 return true; | |
| 76 } catch (ProcessInitException e) { | |
| 77 Log.e(TAG, "Unable to launch browser process.", e); | |
| 78 return false; | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 private static boolean allowCommandLineImport() { | |
| 83 return !Build.TYPE.equals("user"); | |
| 84 } | |
| 85 | |
| 86 private static String[] getCommandLineParamsFromIntent(Intent intent) { | |
| 87 return intent != null ? intent.getStringArrayExtra(COMMAND_LINE_ARGS_KEY ) : null; | |
| 88 } | |
| 89 | |
| 90 private static void waitForDebuggerIfNeeded() { | |
| 91 if (!CommandLine.getInstance().hasSwitch(BaseSwitches.WAIT_FOR_JAVA_DEBU GGER)) { | |
| 92 return; | |
| 93 } | |
| 94 Log.e(TAG, "Waiting for Java debugger to connect..."); | |
| 95 Debug.waitForDebugger(); | |
| 96 Log.e(TAG, "Java debugger connected. Resuming execution."); | |
| 97 } | |
| 98 } | |
| OLD | NEW |