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 import os | 4 import os |
5 | 5 |
6 from chrome_remote_control import temporary_http_server | 6 from chrome_remote_control import temporary_http_server |
7 from chrome_remote_control import browser_credentials | 7 from chrome_remote_control import browser_credentials |
8 from chrome_remote_control import wpr_modes | 8 from chrome_remote_control import wpr_modes |
9 from chrome_remote_control import wpr_server | 9 from chrome_remote_control import wpr_server |
10 | 10 |
11 class Browser(object): | 11 class Browser(object): |
12 """A running browser instance that can be controlled in a limited way. | 12 """A running browser instance that can be controlled in a limited way. |
13 | 13 |
14 To create a browser instance, use browser_finder.FindBrowser. | 14 To create a browser instance, use browser_finder.FindBrowser. |
15 | 15 |
16 Be sure to clean up after yourself by calling Close() when you are done with | 16 Be sure to clean up after yourself by calling Close() when you are done with |
17 the browser. Or better yet: | 17 the browser. Or better yet: |
18 browser_to_create = FindBrowser(options) | 18 browser_to_create = FindBrowser(options) |
19 with browser_to_create.Create() as browser: | 19 with browser_to_create.Create() as browser: |
20 ... do all your operations on browser here | 20 ... do all your operations on browser here |
21 """ | 21 """ |
22 def __init__(self, backend): | 22 def __init__(self, backend, platform): |
23 self._backend = backend | 23 self._backend = backend |
24 self._http_server = None | 24 self._http_server = None |
25 self._wpr_server = None | 25 self._wpr_server = None |
| 26 self._platform = platform |
26 self.credentials = browser_credentials.BrowserCredentials() | 27 self.credentials = browser_credentials.BrowserCredentials() |
27 | 28 |
28 def __enter__(self): | 29 def __enter__(self): |
29 return self | 30 return self |
30 | 31 |
31 def __exit__(self, *args): | 32 def __exit__(self, *args): |
32 self.Close() | 33 self.Close() |
33 | 34 |
34 @property | 35 @property |
35 def is_content_shell(self): | 36 def is_content_shell(self): |
36 """Returns whether this browser is a content shell, only.""" | 37 """Returns whether this browser is a content shell, only.""" |
37 return self._backend.is_content_shell | 38 return self._backend.is_content_shell |
38 | 39 |
39 @property | 40 @property |
40 def num_tabs(self): | 41 def num_tabs(self): |
41 return self._backend.num_tabs | 42 return self._backend.num_tabs |
42 | 43 |
| 44 @property |
| 45 def platform(self): |
| 46 return self._platform |
| 47 |
43 def GetNthTabUrl(self, index): | 48 def GetNthTabUrl(self, index): |
44 return self._backend.GetNthTabUrl(index) | 49 return self._backend.GetNthTabUrl(index) |
45 | 50 |
46 def ConnectToNthTab(self, index): | 51 def ConnectToNthTab(self, index): |
47 return self._backend.ConnectToNthTab(self, index) | 52 return self._backend.ConnectToNthTab(self, index) |
48 | 53 |
49 def Close(self): | 54 def Close(self): |
50 if self._wpr_server: | 55 if self._wpr_server: |
51 self._wpr_server.Close() | 56 self._wpr_server.Close() |
52 self._wpr_server = None | 57 self._wpr_server = None |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 95 |
91 if self._backend.wpr_mode == wpr_modes.WPR_OFF: | 96 if self._backend.wpr_mode == wpr_modes.WPR_OFF: |
92 return | 97 return |
93 | 98 |
94 use_record_mode = self._backend.wpr_mode == wpr_modes.WPR_RECORD | 99 use_record_mode = self._backend.wpr_mode == wpr_modes.WPR_RECORD |
95 if not use_record_mode: | 100 if not use_record_mode: |
96 assert os.path.isfile(archive_path) | 101 assert os.path.isfile(archive_path) |
97 | 102 |
98 self._wpr_server = wpr_server.ReplayServer( | 103 self._wpr_server = wpr_server.ReplayServer( |
99 self._backend, archive_path, use_record_mode) | 104 self._backend, archive_path, use_record_mode) |
OLD | NEW |