Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 import json | |
| 7 import os | |
| 8 | |
| 9 class TimelineModelProxy: | |
|
nduca
2012/07/18 05:51:35
Seems to me you can just read the js here one-off,
| |
| 10 def __init__(self, tracing_js_host, remote_object_js): | |
| 11 self._tracing_js_host = tracing_js_host | |
| 12 self._remote_object_js = remote_object_js | |
|
nduca
2012/07/18 05:51:35
_remote_shim_name
| |
| 13 | |
| 14 def _escape_for_quoted_javascript_execution(self, js): | |
|
nduca
2012/07/18 05:51:35
this should be a global var. It doesn't need anyt
| |
| 15 # Poor man's string escape. | |
| 16 return js.replace("'", "\\'"); | |
| 17 | |
| 18 # Do note that the JSON serialization process removes cyclic references. | |
| 19 # TODO(eatnumber) regenerate these cyclic references on deserialization. | |
| 20 def _js_call(self, method_name, *args): | |
|
nduca
2012/07/18 05:51:35
I think this is overcomplex.
I think that you sho
| |
| 21 result = json.loads(self._tracing_js_host.ExecuteJavascriptWithFile( | |
| 22 js = """ | |
| 23 // For simplicity, I'm putting a vulnerability to js injection here (in | |
| 24 // the eval), as this code should never be invoked by untrusted code. | |
| 25 // This injection allows the caller to use remote_object_jss like | |
| 26 // "profilingView.timelineView.model" which is a needed feature. | |
| 27 invokeJsMethodFromPython(eval('%s'), '%s', '%s'); | |
| 28 """ % ( | |
| 29 self._escape_for_quoted_javascript_execution(self._remote_object_js), | |
| 30 self._escape_for_quoted_javascript_execution(method_name), | |
| 31 self._escape_for_quoted_javascript_execution(json.dumps(args)) | |
| 32 ), | |
| 33 fileName = os.path.join(os.path.dirname(__file__), 'timeline_model.js'), | |
| 34 windex = self._tracing_js_host._trace_win) | |
|
nduca
2012/07/18 05:51:35
Is accessing _trace_win a normative pracice in pya
| |
| 35 ) | |
| 36 if( result["success"] ): | |
| 37 return result["data"] | |
| 38 # TODO(eatnumber) Make these exceptions more reader friendly | |
| 39 raise Exception(result) | |
| 40 | |
| 41 def getAllThreads(self): | |
| 42 return self._js_call("getAllThreads") | |
| 43 | |
| 44 def getAllCpus(self): | |
| 45 return self._js_call("getAllCpus") | |
| 46 | |
| 47 def getAllProcesses(self): | |
| 48 return self._js_call("getAllProcesses") | |
| 49 | |
| 50 def getAllCounters(self): | |
| 51 return self._js_call("getAllCounters") | |
| 52 | |
| 53 def findAllThreadsNamed(self, name): | |
| 54 return self._js_call("findAllThreadsNamed", name); | |
| 55 | |
| 56 # Alias TimelineModel to TimelineModelProxy for convenience | |
| 57 TimelineModel = TimelineModelProxy | |
| OLD | NEW |