OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Finds desktop browsers that can be controlled by chrome_remote_control.""" | 4 """Finds desktop browsers that can be controlled by chrome_remote_control.""" |
5 | 5 |
6 import logging | 6 import logging |
7 import os as real_os | 7 import os |
8 import sys as real_sys | 8 import subprocess |
9 import subprocess as real_subprocess | 9 import sys |
10 | 10 |
11 from chrome_remote_control import browser | 11 from chrome_remote_control import browser |
12 from chrome_remote_control import desktop_browser_backend | 12 from chrome_remote_control import desktop_browser_backend |
13 from chrome_remote_control import possible_browser | 13 from chrome_remote_control import possible_browser |
14 | 14 |
15 ALL_BROWSER_TYPES = ','.join([ | 15 ALL_BROWSER_TYPES = ','.join([ |
16 'exact', | 16 'exact', |
17 'release', | 17 'release', |
18 'debug', | 18 'debug', |
19 'canary', | 19 'canary', |
(...skipping 10 matching lines...) Expand all Loading... |
30 self._is_content_shell = is_content_shell | 30 self._is_content_shell = is_content_shell |
31 | 31 |
32 def __repr__(self): | 32 def __repr__(self): |
33 return 'PossibleDesktopBrowser(browser_type=%s)' % self.browser_type | 33 return 'PossibleDesktopBrowser(browser_type=%s)' % self.browser_type |
34 | 34 |
35 def Create(self): | 35 def Create(self): |
36 backend = desktop_browser_backend.DesktopBrowserBackend( | 36 backend = desktop_browser_backend.DesktopBrowserBackend( |
37 self._options, self._local_executable, self._is_content_shell) | 37 self._options, self._local_executable, self._is_content_shell) |
38 return browser.Browser(backend) | 38 return browser.Browser(backend) |
39 | 39 |
40 def FindAllAvailableBrowsers(options, | 40 def FindAllAvailableBrowsers(options): |
41 os = real_os, | |
42 sys = real_sys, | |
43 subprocess = real_subprocess): | |
44 """Finds all the desktop browsers available on this machine.""" | 41 """Finds all the desktop browsers available on this machine.""" |
45 browsers = [] | 42 browsers = [] |
46 | 43 |
47 has_display = True | 44 has_display = True |
48 if (sys.platform.startswith('linux') and | 45 if (sys.platform.startswith('linux') and |
49 os.getenv('DISPLAY') == None): | 46 os.getenv('DISPLAY') == None): |
50 has_display = False | 47 has_display = False |
51 | 48 |
52 # Add the explicit browser executable if given. | 49 # Add the explicit browser executable if given. |
53 if options.browser_executable: | 50 if options.browser_executable: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 97 |
101 if os.path.exists(mac_system): | 98 if os.path.exists(mac_system): |
102 browsers.append(PossibleDesktopBrowser('system', options, | 99 browsers.append(PossibleDesktopBrowser('system', options, |
103 mac_system, False)) | 100 mac_system, False)) |
104 | 101 |
105 # Linux specific options. | 102 # Linux specific options. |
106 if sys.platform.startswith('linux'): | 103 if sys.platform.startswith('linux'): |
107 # Look for a google-chrome instance. | 104 # Look for a google-chrome instance. |
108 found = False | 105 found = False |
109 try: | 106 try: |
110 with open(real_os.devnull, 'w') as devnull: | 107 with open(os.devnull, 'w') as devnull: |
111 found = subprocess.call(['google-chrome', '--version'], | 108 found = subprocess.call(['google-chrome', '--version'], |
112 stdout=devnull, stderr=devnull) == 0 | 109 stdout=devnull, stderr=devnull) == 0 |
113 except OSError: | 110 except OSError: |
114 pass | 111 pass |
115 if found: | 112 if found: |
116 browsers.append( | 113 browsers.append( |
117 PossibleDesktopBrowser('system', options, | 114 PossibleDesktopBrowser('system', options, |
118 'google-chrome', False)) | 115 'google-chrome', False)) |
119 | 116 |
120 # Win32-specific options. | 117 # Win32-specific options. |
(...skipping 10 matching lines...) Expand all Loading... |
131 if os.path.exists(win_system): | 128 if os.path.exists(win_system): |
132 browsers.append(PossibleDesktopBrowser('system', options, | 129 browsers.append(PossibleDesktopBrowser('system', options, |
133 win_system, False)) | 130 win_system, False)) |
134 | 131 |
135 if len(browsers) and not has_display: | 132 if len(browsers) and not has_display: |
136 logging.warning('Found (%s), but you have a DISPLAY environment set.' % | 133 logging.warning('Found (%s), but you have a DISPLAY environment set.' % |
137 ','.join([b.browser_type for b in browsers])) | 134 ','.join([b.browser_type for b in browsers])) |
138 return [] | 135 return [] |
139 | 136 |
140 return browsers | 137 return browsers |
OLD | NEW |