| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import collections |
| 6 |
| 7 from telemetry.core import extension_page |
| 8 from telemetry.core.backends.chrome import inspector_backend_list |
| 9 |
| 10 |
| 11 class ExtensionBackendList(inspector_backend_list.InspectorBackendList): |
| 12 """A dynamic sequence of extension_page.ExtensionPages.""" |
| 13 |
| 14 def __init__(self, browser_backend): |
| 15 super(ExtensionBackendList, self).__init__( |
| 16 browser_backend, backend_wrapper=extension_page.ExtensionPage) |
| 17 |
| 18 def ShouldIncludeContext(self, context): |
| 19 return context['url'].startswith('chrome-extension://') |
| 20 |
| 21 |
| 22 class ExtensionBackendDict(collections.Mapping): |
| 23 """A dynamic mapping of extension_id to extension_page.ExtensionPages.""" |
| 24 |
| 25 def __init__(self, browser_backend): |
| 26 self._extension_backend_list = ExtensionBackendList(browser_backend) |
| 27 |
| 28 def __getitem__(self, extension_id): |
| 29 for i, context_id in enumerate(self._extension_backend_list): |
| 30 if self.ContextIdToExtensionId(context_id) == extension_id: |
| 31 return self._extension_backend_list[i] |
| 32 raise KeyError('Cannot find an extension with id=%s' % extension_id) |
| 33 |
| 34 def __iter__(self): |
| 35 for context_id in self._extension_backend_list: |
| 36 yield self.ContextIdToExtensionId(context_id) |
| 37 |
| 38 def __len__(self): |
| 39 return len(self._extension_backend_list) |
| 40 |
| 41 def ContextIdToExtensionId(self, context_id): |
| 42 context = self._extension_backend_list.GetContextInfo(context_id) |
| 43 return extension_page.UrlToExtensionId(context['url']) |
| OLD | NEW |