Commit 872bf786 authored by nednguyen's avatar nednguyen Committed by Commit bot

Revert of Revert of Introduce GetBackendFromContextId to avoid using list...

Revert of Revert of Introduce GetBackendFromContextId to avoid using list index. (patchset #1 id:1 of https://codereview.chromium.org/573573003/)

Reason for revert:
Revert the revert since the bot is still red after the revert.

Original issue's description:
> Revert of Introduce GetBackendFromContextId to avoid using list index. (patchset #1 id:1 of https://codereview.chromium.org/556003005/)
>
> Reason for revert:
> It looks like the moto E perf bots are broken due to this change.
>
> BUG=414267
>
> Original issue's description:
> > Introduce GetBackendFromContextId to avoid using list index.
> >
> > BUG=398467
> > TEST=ExtensionTest
> >
> > Committed: https://crrev.com/a1a83005087fdac70e7809f9dc1d89f6c4f88dfc
> > Cr-Commit-Position: refs/heads/master@{#294455}
>
> TBR=tbarzic@chromium.org,achuith@chromium.org
> NOTREECHECKS=true
> NOTRY=true
> BUG=398467
>
> Committed: https://crrev.com/c8fad04c1e2119f9e8efc68f32d5268161d044d3
> Cr-Commit-Position: refs/heads/master@{#295136}

TBR=tbarzic@chromium.org,achuith@chromium.org,tonyg@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=414267

Review URL: https://codereview.chromium.org/578693002

Cr-Commit-Position: refs/heads/master@{#295205}
parent 1c24838a
......@@ -160,9 +160,11 @@ class ChromeBrowserBackend(browser_backend.BrowserBackend):
document.readyState == 'interactive')
"""
for e in self._extensions_to_load:
if not e.extension_id in self.extension_backend:
try:
extension_objects = self.extension_backend[e.extension_id]
except KeyError:
return False
for extension_object in self.extension_backend[e.extension_id]:
for extension_object in extension_objects:
try:
res = extension_object.EvaluateJavaScript(
extension_ready_js % e.extension_id)
......
......@@ -25,16 +25,12 @@ class ExtensionBackendDict(collections.Mapping):
def __init__(self, browser_backend):
self._extension_backend_list = ExtensionBackendList(browser_backend)
def __contains__(self, extension_id):
return (extension_id in
(self.ContextIdToExtensionId(context_id)
for context_id in self._extension_backend_list))
def __getitem__(self, extension_id):
extensions = []
for i, context_id in enumerate(self._extension_backend_list):
for context_id in self._extension_backend_list:
if self.ContextIdToExtensionId(context_id) == extension_id:
extensions.append(self._extension_backend_list[i])
extensions.append(
self._extension_backend_list.GetBackendFromContextId(context_id))
if not extensions:
raise KeyError('Cannot find an extension with id=%s' % extension_id)
return extensions
......
......@@ -42,6 +42,8 @@ class InspectorBackendList(collections.Sequence):
"""Override this method to control which contexts are included."""
return True
#TODO(nednguyen): Remove this method and turn inspector_backend_list API to
# dictionary-like API (crbug.com/398467)
def __getitem__(self, index):
self._Update()
if index >= len(self._inspectable_contexts_dict.keys()):
......@@ -51,6 +53,12 @@ class InspectorBackendList(collections.Sequence):
"keys": self._inspectable_contexts_dict.keys()
}))
context_id = self._inspectable_contexts_dict.keys()[index]
return self.GetBackendFromContextId(context_id)
def GetBackendFromContextId(self, context_id):
self._Update()
if context_id not in self._inspectable_contexts_dict:
raise KeyError('Cannot find a context with id=%s' % context_id)
if context_id not in self._inspector_backend_dict:
backend = inspector_backend.InspectorBackend(
self._browser_backend,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment