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 urllib2 | 4 import urllib2 |
5 import httplib | 5 import httplib |
6 import socket | 6 import socket |
7 import json | 7 import json |
8 | 8 |
9 from telemetry import browser_gone_exception | 9 from telemetry import browser_gone_exception |
| 10 from telemetry import extension_page |
10 from telemetry import inspector_backend | 11 from telemetry import inspector_backend |
11 from telemetry import tab | 12 from telemetry import tab |
12 from telemetry import user_agent | 13 from telemetry import user_agent |
13 from telemetry import util | 14 from telemetry import util |
14 from telemetry import wpr_modes | 15 from telemetry import wpr_modes |
15 from telemetry import wpr_server | 16 from telemetry import wpr_server |
16 | 17 |
17 class BrowserBackend(object): | 18 class BrowserBackend(object): |
18 """A base class for browser backends. Provides basic functionality | 19 """A base class for browser backends. Provides basic functionality |
19 once a remote-debugger port has been established.""" | 20 once a remote-debugger port has been established.""" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 return True | 59 return True |
59 try: | 60 try: |
60 util.WaitFor(IsBrowserUp, timeout=30) | 61 util.WaitFor(IsBrowserUp, timeout=30) |
61 except util.TimeoutException: | 62 except util.TimeoutException: |
62 raise browser_gone_exception.BrowserGoneException() | 63 raise browser_gone_exception.BrowserGoneException() |
63 | 64 |
64 @property | 65 @property |
65 def _debugger_url(self): | 66 def _debugger_url(self): |
66 return 'http://localhost:%i/json' % self._port | 67 return 'http://localhost:%i/json' % self._port |
67 | 68 |
| 69 def _ListExtensionPages(self, extension_id, timeout=None): |
| 70 req = urllib2.urlopen(self._debugger_url, timeout=timeout) |
| 71 data = req.read() |
| 72 all_contexts = json.loads(data) |
| 73 pages = [ctx for ctx in all_contexts |
| 74 if ctx['url'].startswith('chrome-extension://%s' % extension_id)] |
| 75 return pages |
| 76 |
68 def _ListTabs(self, timeout=None): | 77 def _ListTabs(self, timeout=None): |
69 req = urllib2.urlopen(self._debugger_url, timeout=timeout) | 78 req = urllib2.urlopen(self._debugger_url, timeout=timeout) |
70 data = req.read() | 79 data = req.read() |
71 all_contexts = json.loads(data) | 80 all_contexts = json.loads(data) |
72 tabs = [ctx for ctx in all_contexts | 81 tabs = [ctx for ctx in all_contexts |
73 if not ctx['url'].startswith('chrome-extension://')] | 82 if not ctx['url'].startswith('chrome-extension://')] |
74 # FIXME(dtu): The remote debugger protocol returns in order of most | 83 # FIXME(dtu): The remote debugger protocol returns in order of most |
75 # recently created tab first. In order to convert it to the UI tab | 84 # recently created tab first. In order to convert it to the UI tab |
76 # order, we just reverse the list, which assumes we can't move tabs. | 85 # order, we just reverse the list, which assumes we can't move tabs. |
77 # We should guarantee that the remote debugger returns in the UI tab order. | 86 # We should guarantee that the remote debugger returns in the UI tab order. |
(...skipping 17 matching lines...) Expand all Loading... |
95 | 104 |
96 util.WaitFor(lambda: self.num_tabs == target_num_tabs, timeout=5) | 105 util.WaitFor(lambda: self.num_tabs == target_num_tabs, timeout=5) |
97 | 106 |
98 @property | 107 @property |
99 def num_tabs(self): | 108 def num_tabs(self): |
100 return len(self._ListTabs()) | 109 return len(self._ListTabs()) |
101 | 110 |
102 def GetNthTabUrl(self, index): | 111 def GetNthTabUrl(self, index): |
103 return self._ListTabs()[index]['url'] | 112 return self._ListTabs()[index]['url'] |
104 | 113 |
| 114 def ConnectToExtensionPage(self, browser, extension_id): |
| 115 ib = inspector_backend.InspectorBackend(self, |
| 116 self._ListExtensionPages(extension_id)[0]) |
| 117 return extension_page.ExtensionPage(browser, ib) |
| 118 |
105 def ConnectToNthTab(self, browser, index): | 119 def ConnectToNthTab(self, browser, index): |
106 ib = inspector_backend.InspectorBackend(self, self._ListTabs()[index]) | 120 ib = inspector_backend.InspectorBackend(self, self._ListTabs()[index]) |
107 return tab.Tab(browser, ib) | 121 return tab.Tab(browser, ib) |
108 | 122 |
109 def DoesDebuggerUrlExist(self, url): | 123 def DoesDebuggerUrlExist(self, url): |
110 matches = [t for t in self._ListTabs() | 124 matches = [t for t in self._ListTabs() |
111 if 'webSocketDebuggerUrl' in t and\ | 125 if 'webSocketDebuggerUrl' in t and\ |
112 t['webSocketDebuggerUrl'] == url] | 126 t['webSocketDebuggerUrl'] == url] |
113 return len(matches) >= 1 | 127 return len(matches) >= 1 |
114 | 128 |
115 def CreateForwarder(self, host_port): | 129 def CreateForwarder(self, host_port): |
116 raise NotImplementedError() | 130 raise NotImplementedError() |
117 | 131 |
118 def IsBrowserRunning(self): | 132 def IsBrowserRunning(self): |
119 raise NotImplementedError() | 133 raise NotImplementedError() |
OLD | NEW |