Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 from telemetry.core import exceptions | 4 from telemetry.core import exceptions |
| 5 | 5 |
| 6 | 6 |
| 7 class InspectorRuntime(object): | 7 class InspectorRuntime(object): |
| 8 def __init__(self, inspector_websocket): | 8 def __init__(self, inspector_websocket): |
| 9 self._inspector_websocket = inspector_websocket | 9 self._inspector_websocket = inspector_websocket |
| 10 self._inspector_websocket.RegisterDomain('Runtime', self._OnNotification) | 10 self._inspector_websocket.RegisterDomain('Runtime', self._OnNotification) |
| 11 self._contexts_enabled = False | 11 self._contexts_enabled = False |
| 12 self._max_context_id = None | 12 self._all_context_ids = None |
| 13 | 13 |
| 14 def _OnNotification(self, msg): | 14 def _OnNotification(self, msg): |
| 15 if (self._contexts_enabled and | 15 if (self._contexts_enabled and |
| 16 msg['method'] == 'Runtime.executionContextCreated'): | 16 msg['method'] == 'Runtime.executionContextCreated'): |
| 17 self._max_context_id = max(self._max_context_id, | 17 self._all_context_ids.add(msg['params']['context']['id']) |
| 18 msg['params']['context']['id']) | |
| 19 | 18 |
| 20 def Execute(self, expr, context_id, timeout): | 19 def Execute(self, expr, context_id, timeout): |
| 21 self.Evaluate(expr + '; 0;', context_id, timeout) | 20 self.Evaluate(expr + '; 0;', context_id, timeout) |
| 22 | 21 |
| 23 def Evaluate(self, expr, context_id, timeout): | 22 def Evaluate(self, expr, context_id, timeout): |
| 24 """Evaluates a javascript expression and returns the result. | 23 """Evaluates a javascript expression and returns the result. |
| 25 | 24 |
| 26 |context_id| can refer to an iframe. The main page has context_id=1, the | 25 |context_id| can refer to an iframe. The main page has context_id=1, the |
| 27 first iframe context_id=2, etc. | 26 first iframe context_id=2, etc. |
| 28 | 27 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 def EnableAllContexts(self): | 59 def EnableAllContexts(self): |
| 61 """Allow access to iframes. | 60 """Allow access to iframes. |
| 62 | 61 |
| 63 Raises: | 62 Raises: |
| 64 exceptions.WebSocketDisconnected | 63 exceptions.WebSocketDisconnected |
| 65 websocket.WebSocketException | 64 websocket.WebSocketException |
| 66 socket.error | 65 socket.error |
| 67 """ | 66 """ |
| 68 if not self._contexts_enabled: | 67 if not self._contexts_enabled: |
| 69 self._contexts_enabled = True | 68 self._contexts_enabled = True |
| 69 self._all_context_ids = set() | |
| 70 self._inspector_websocket.SyncRequest({'method': 'Runtime.enable'}, | 70 self._inspector_websocket.SyncRequest({'method': 'Runtime.enable'}, |
| 71 timeout=30) | 71 timeout=30) |
| 72 return self._max_context_id | 72 return self._all_context_ids |
|
wkorman
2017/09/20 20:11:04
Is there a doc comment we should update or add her
nednguyen
2017/09/26 13:01:34
We have unittest for this
| |
| 73 | 73 |
| 74 def RunInspectorCommand(self, command, timeout): | 74 def RunInspectorCommand(self, command, timeout): |
| 75 """Runs an inspector command. | 75 """Runs an inspector command. |
| 76 | 76 |
| 77 Raises: | 77 Raises: |
| 78 exceptions.WebSocketDisconnected | 78 exceptions.WebSocketDisconnected |
| 79 websocket.WebSocketException | 79 websocket.WebSocketException |
| 80 socket.error | 80 socket.error |
| 81 """ | 81 """ |
| 82 res = self._inspector_websocket.SyncRequest(command, timeout) | 82 res = self._inspector_websocket.SyncRequest(command, timeout) |
| 83 return res | 83 return res |
| OLD | NEW |