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 httplib | 4 import httplib |
5 import json | 5 import json |
6 import socket | 6 import socket |
7 import urllib2 | 7 import urllib2 |
8 import weakref | 8 import weakref |
9 | 9 |
10 from telemetry import browser_gone_exception | 10 from telemetry.core import util |
11 from telemetry import tab | 11 from telemetry.core import exceptions |
12 from telemetry import inspector_backend | 12 from telemetry.core import tab |
13 from telemetry import util | 13 from telemetry.core.chrome import inspector_backend |
14 | 14 |
15 class TabListBackend(object): | 15 class TabListBackend(object): |
16 def __init__(self, browser_backend): | 16 def __init__(self, browser_backend): |
17 self._browser_backend = browser_backend | 17 self._browser_backend = browser_backend |
18 | 18 |
19 # Stores web socket debugger URLs in iteration order. | 19 # Stores web socket debugger URLs in iteration order. |
20 self._tab_list = [] | 20 self._tab_list = [] |
21 # Maps debugger URLs to Tab objects. | 21 # Maps debugger URLs to Tab objects. |
22 self._tab_dict = weakref.WeakValueDictionary() | 22 self._tab_dict = weakref.WeakValueDictionary() |
23 | 23 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 def _ListTabs(self, timeout=None): | 118 def _ListTabs(self, timeout=None): |
119 try: | 119 try: |
120 data = self._browser_backend.Request('', timeout=timeout) | 120 data = self._browser_backend.Request('', timeout=timeout) |
121 all_contexts = json.loads(data) | 121 all_contexts = json.loads(data) |
122 tabs = [ctx for ctx in all_contexts | 122 tabs = [ctx for ctx in all_contexts |
123 if not ctx['url'].startswith('chrome-extension://')] | 123 if not ctx['url'].startswith('chrome-extension://')] |
124 return tabs | 124 return tabs |
125 except (socket.error, httplib.BadStatusLine, urllib2.URLError): | 125 except (socket.error, httplib.BadStatusLine, urllib2.URLError): |
126 if not self._browser_backend.IsBrowserRunning(): | 126 if not self._browser_backend.IsBrowserRunning(): |
127 raise browser_gone_exception.BrowserGoneException() | 127 raise exceptions.BrowserGoneException() |
128 raise browser_gone_exception.BrowserConnectionGoneException() | 128 raise exceptions.BrowserConnectionGoneException() |
129 | 129 |
130 def _UpdateTabList(self): | 130 def _UpdateTabList(self): |
131 def GetDebuggerUrl(tab_info): | 131 def GetDebuggerUrl(tab_info): |
132 if 'webSocketDebuggerUrl' not in tab_info: | 132 if 'webSocketDebuggerUrl' not in tab_info: |
133 return None | 133 return None |
134 return tab_info['webSocketDebuggerUrl'] | 134 return tab_info['webSocketDebuggerUrl'] |
135 new_tab_list = map(GetDebuggerUrl, self._ListTabs()) | 135 new_tab_list = map(GetDebuggerUrl, self._ListTabs()) |
136 self._tab_list = [t for t in self._tab_list | 136 self._tab_list = [t for t in self._tab_list |
137 if t in self._tab_dict or t in new_tab_list] | 137 if t in self._tab_dict or t in new_tab_list] |
138 self._tab_list += [t for t in new_tab_list | 138 self._tab_list += [t for t in new_tab_list |
139 if t is not None and t not in self._tab_list] | 139 if t is not None and t not in self._tab_list] |
140 | 140 |
141 def _FindTabInfo(self, debugger_url): | 141 def _FindTabInfo(self, debugger_url): |
142 for tab_info in self._ListTabs(): | 142 for tab_info in self._ListTabs(): |
143 if tab_info.get('webSocketDebuggerUrl') == debugger_url: | 143 if tab_info.get('webSocketDebuggerUrl') == debugger_url: |
144 return tab_info | 144 return tab_info |
145 return None | 145 return None |
OLD | NEW |