Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Unified Diff: tools/telemetry/telemetry/core/backends/chrome/inspector_runtime.py

Issue 214963004: Support for figuring out the number of contexts in a page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: max_context_id Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/core/backends/chrome/inspector_runtime.py
diff --git a/tools/telemetry/telemetry/core/backends/chrome/inspector_runtime.py b/tools/telemetry/telemetry/core/backends/chrome/inspector_runtime.py
index 3b8d19db7fbe812121f78628319c126157342d97..2d1c764cdcf09f6f88bdce7a5c531a514412a2ae 100644
--- a/tools/telemetry/telemetry/core/backends/chrome/inspector_runtime.py
+++ b/tools/telemetry/telemetry/core/backends/chrome/inspector_runtime.py
@@ -11,9 +11,13 @@ class InspectorRuntime(object):
self._OnNotification,
self._OnClose)
self._contexts_enabled = False
+ self._max_context_id = None
def _OnNotification(self, msg):
- pass
+ if (self._contexts_enabled and
+ msg['method'] == 'Runtime.executionContextCreated'):
+ self._max_context_id = max(self._max_context_id,
+ msg['params']['context']['id'])
def _OnClose(self):
pass
@@ -22,7 +26,6 @@ class InspectorRuntime(object):
self.Evaluate(expr + '; 0;', context_id, timeout)
def Evaluate(self, expr, context_id, timeout):
- self._EnableAllContexts(context_id)
request = {
'method': 'Runtime.evaluate',
'params': {
@@ -31,6 +34,7 @@ class InspectorRuntime(object):
}
}
if context_id is not None:
+ self.EnableAllContexts()
request['params']['contextId'] = context_id
res = self._inspector_backend.SyncRequest(request, timeout)
if 'error' in res:
@@ -44,9 +48,10 @@ class InspectorRuntime(object):
return None
return res['result']['result']['value']
- def _EnableAllContexts(self, context_id):
- """Allow access to iframes as necessary."""
- if context_id is not None and not self._contexts_enabled:
+ def EnableAllContexts(self):
+ """Allow access to iframes."""
+ if not self._contexts_enabled:
+ self._contexts_enabled = True
self._inspector_backend.SyncRequest({'method': 'Runtime.enable'},
timeout=30)
- self._contexts_enabled = True
+ return self._max_context_id

Powered by Google App Engine
This is Rietveld 408576698