Index: tools/chrome_remote_control/chrome_remote_control/browser_finder.py |
diff --git a/tools/chrome_remote_control/chrome_remote_control/browser_finder.py b/tools/chrome_remote_control/chrome_remote_control/browser_finder.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3cd12eccd0aa9e79a97ec42c4127ade425816ab9 |
--- /dev/null |
+++ b/tools/chrome_remote_control/chrome_remote_control/browser_finder.py |
@@ -0,0 +1,75 @@ |
+# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import os as real_os |
+import sys as real_sys |
+import subprocess as real_subprocess |
+ |
+def Find(options, |
+ chrome_src_dir = None, |
+ os = real_os, |
+ sys = real_sys, |
+ subprocess = real_subprocess): |
+ # Use an absolute browser path if given |
+ if options.browser_executable: |
+ if os.path.exists(options.browser_executable): |
+ return options.browser_executable |
+ return None |
+ |
+ # Look for a browser in the standard chrome build locations. |
+ if chrome_src_dir == None: |
+ chrome_src_dir = os.path.join(os.path.dirname(__file__), "../../../") |
+ |
+ if options.debug: |
+ buildname = "Debug" |
+ else: |
+ buildname = "Release" |
+ |
+ if sys.platform == 'darwin': |
+ app_name = "Chromium.app/Contents/MacOS/Chromium" |
+ elif sys.platform.startswith('linux'): |
+ app_name = "chrome" |
+ elif sys.platform == 'win': |
+ app_name = "chrome.exe" |
+ else: |
+ raise Exception("Platform not recognized") |
+ |
+ built_app = os.path.join(chrome_src_dir, "out", buildname, app_name) |
+ if os.path.exists(built_app): |
+ return built_app |
+ |
+ # Look for an installed version of the browser. |
+ if sys.platform == 'darwin': |
+ mac_canary = "/Applications/Google Chrome Canary.app/" + |
dtu
2012/08/24 08:55:43
Parentheses around these string literals, and you
|
+ "Contents/MacOS/Google Chrome Canary" |
+ mac_stable = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" |
+ if options.canary: |
+ if os.path.exists(mac_canary): |
+ return mac_canary |
+ return None |
+ |
+ if os.path.exists(mac_stable): |
+ return mac_stable |
+ |
+ if os.path.exists(mac_canary): |
+ return mac_canary |
+ |
+ # TODO(nduca): Look for a browser in the cwd |
+ return None |
+ |
+ if sys.platform.startswith('linux'): |
+ if options.canary: |
+ return None |
+ |
+ # look for a google-chrome |
+ found = False |
+ try: |
+ found = subprocess.call(['google-chrome', '--version']) == 0 |
+ except OSError: |
+ pass |
+ if found: |
+ return 'google-chrome' |
+ return None |
+ |
+ raise Exception("Unsupported platform.") |