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 re | 6 import re |
7 import socket | 7 import socket |
8 import urllib2 | 8 import urllib2 |
9 import weakref | 9 import weakref |
10 | 10 |
11 from telemetry import browser_gone_exception | 11 from telemetry.core import exceptions |
12 from telemetry import extension_page | 12 from telemetry.core import extension_page |
13 from telemetry import inspector_backend | 13 from telemetry.core.chrome import inspector_backend |
14 | 14 |
15 class ExtensionNotFoundException(Exception): | 15 class ExtensionNotFoundException(Exception): |
16 pass | 16 pass |
17 | 17 |
18 class ExtensionDictBackend(object): | 18 class ExtensionDictBackend(object): |
19 def __init__(self, browser_backend): | 19 def __init__(self, browser_backend): |
20 self._browser_backend = browser_backend | 20 self._browser_backend = browser_backend |
21 # Maps extension ids to ExtensionPage objects. | 21 # Maps extension ids to ExtensionPage objects. |
22 self._extension_dict = weakref.WeakValueDictionary() | 22 self._extension_dict = weakref.WeakValueDictionary() |
23 | 23 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 if self._GetExtensionId(extension_info) == extension_id: | 62 if self._GetExtensionId(extension_info) == extension_id: |
63 return extension_info | 63 return extension_info |
64 return None | 64 return None |
65 | 65 |
66 def _GetExtensionInfoList(self, timeout=None): | 66 def _GetExtensionInfoList(self, timeout=None): |
67 try: | 67 try: |
68 data = self._browser_backend.Request('', timeout=timeout) | 68 data = self._browser_backend.Request('', timeout=timeout) |
69 return self._FilterExtensions(json.loads(data)) | 69 return self._FilterExtensions(json.loads(data)) |
70 except (socket.error, httplib.BadStatusLine, urllib2.URLError): | 70 except (socket.error, httplib.BadStatusLine, urllib2.URLError): |
71 if not self._browser_backend.IsBrowserRunning(): | 71 if not self._browser_backend.IsBrowserRunning(): |
72 raise browser_gone_exception.BrowserGoneException() | 72 raise exceptions.BrowserGoneException() |
73 raise browser_gone_exception.BrowserConnectionGoneException() | 73 raise exceptions.BrowserConnectionGoneException() |
74 | 74 |
75 def _FilterExtensions(self, all_pages): | 75 def _FilterExtensions(self, all_pages): |
76 return [page_info for page_info in all_pages | 76 return [page_info for page_info in all_pages |
77 if page_info['url'].startswith('chrome-extension://')] | 77 if page_info['url'].startswith('chrome-extension://')] |
78 | 78 |
79 def _GetExtensionIds(self): | 79 def _GetExtensionIds(self): |
80 return map(self._GetExtensionId, self._GetExtensionInfoList()) | 80 return map(self._GetExtensionId, self._GetExtensionInfoList()) |
OLD | NEW |