Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
|
pfeldman
2016/09/14 00:18:48
2106
chenwilliam
2016/09/14 00:29:41
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 var childProcess = require("child_process"); | |
| 6 var fs = require("fs"); | |
| 7 var path = require("path"); | |
| 8 var shell = childProcess.execSync; | |
| 9 | |
| 10 var remoteDebuggingPort = parseInt(process.env.REMOTE_DEBUGGING_PORT, 10) || 922 2; | |
| 11 var serverPort = parseInt(process.env.PORT, 10) || 8090; | |
| 12 | |
| 13 var chromeArgs = [ | |
| 14 `--remote-debugging-port=${remoteDebuggingPort}`, | |
| 15 `--no-first-run`, | |
| 16 `http://localhost:${remoteDebuggingPort}#http://localhost:${serverPort}/fron t_end/inspector.html?experiments=true`, | |
| 17 `https://devtools.chrome.com` | |
| 18 ].concat(process.argv.slice(2)); | |
| 19 | |
| 20 if (process.platform === "win32") { | |
| 21 launchChromeWindows(); | |
| 22 return; | |
| 23 } | |
| 24 if (process.platform === "darwin") { | |
| 25 launchChromeMac(); | |
| 26 return; | |
| 27 } | |
| 28 if (process.platform === "linux") { | |
| 29 launchChromeLinux(); | |
| 30 return; | |
| 31 } | |
| 32 | |
| 33 throw new Error(`Unrecognized platform detected: ${process.platform}`); | |
| 34 | |
| 35 function launchChromeWindows() | |
| 36 { | |
| 37 var chromeCanaryPath; | |
| 38 var suffix = "\\Google\\Chrome SxS\\Application\\chrome.exe"; | |
| 39 var prefixes = [process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process. env["PROGRAMFILES(X86)"]]; | |
| 40 for (var i = 0; i < prefixes.length; i++) { | |
| 41 var prefix = prefixes[i]; | |
| 42 try { | |
| 43 chromeCanaryPath = path.join(prefix, suffix); | |
| 44 fs.accessSync(chromeCanaryPath); | |
| 45 break; | |
| 46 } catch (e) { | |
| 47 } | |
| 48 } | |
| 49 launchChrome(chromeCanaryPath, chromeArgs); | |
| 50 } | |
| 51 | |
| 52 function launchChromeMac() | |
| 53 { | |
| 54 var lsregister = "/System/Library/Frameworks/CoreServices.framework/Versions /A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister"; | |
| 55 var chromeCanaryPath = shellOutput(`${lsregister} -dump | grep -i 'applicati ons/google chrome canary.app$' | awk '{$1=""; print $0}' | head -n 1`); | |
| 56 var chromeCanaryExecPath = `${chromeCanaryPath}/Contents/MacOS/Google Chrome Canary`; | |
| 57 var tmpProfileDir = shellOutput("mktemp -d -t devtools"); | |
| 58 chromeArgs.push(`--user-data-dir=${tmpProfileDir}`); | |
| 59 launchChrome(chromeCanaryExecPath, chromeArgs, () => shell(`rm -r ${tmpProfi leDir}`)); | |
| 60 } | |
| 61 | |
| 62 function launchChromeLinux() | |
| 63 { | |
| 64 var tmpProfileDir = shellOutput("mktemp -d -t devtools.XXXXXXXXXX"); | |
| 65 chromeArgs.push(`--user-data-dir=${tmpProfileDir}`); | |
| 66 launchChrome(process.env.CHROMIUM_PATH, chromeArgs, () => shell(`rm -r ${tmp ProfileDir}`)); | |
| 67 } | |
| 68 | |
| 69 function launchChrome(filePath, chromeArgs, cleanup) | |
| 70 { | |
| 71 console.log(`Launching Chrome from ${filePath}`); | |
| 72 console.log("Chrome args:", chromeArgs.join(" "), "\n"); | |
| 73 var child; | |
| 74 try { | |
| 75 child = childProcess.spawn(filePath, chromeArgs, { | |
| 76 stdio: "ignore", | |
| 77 }); | |
| 78 } catch (error) { | |
| 79 onLaunchChromeError(); | |
| 80 } | |
| 81 child.on("error", onLaunchChromeError); | |
| 82 child.on("exit", onExit); | |
| 83 function onExit(code) | |
| 84 { | |
| 85 if (cleanup) | |
| 86 cleanup(); | |
| 87 console.log("Exited Chrome with code", code); | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 function onLaunchChromeError() | |
| 92 { | |
| 93 if (process.platform !== "linux") { | |
| 94 console.log("Cannot find Chrome Canary on your computer"); | |
| 95 console.log("Install Chome Canary at:"); | |
| 96 console.log("https://www.google.com/chrome/browser/canary.html\n"); | |
| 97 } else { | |
| 98 console.log("The environment variable CHROMIUM_PATH must be set to execu table of a build of Chromium"); | |
| 99 console.log("If you do not have a recent build of chromium, you can get one from:"); | |
| 100 console.log("https://download-chromium.appspot.com/\n"); | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 function print(buffer) | |
| 105 { | |
| 106 var string = buffer.toString(); | |
| 107 console.log(string); | |
| 108 return string; | |
| 109 } | |
| 110 | |
| 111 function shellOutput(command) | |
| 112 { | |
| 113 return shell(command).toString().trim(); | |
| 114 } | |
| OLD | NEW |