OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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 /** |
| 6 * @fileoverview These stubs emulate backend functionality and allows |
| 7 * DevTools frontend to function as a standalone web app. |
| 8 */ |
| 9 |
| 10 /** |
| 11 * @constructor |
| 12 */ |
| 13 RemoteDebuggerAgentStub = function() { |
| 14 this.activeProfilerModules_ = |
| 15 devtools.DebuggerAgent.ProfilerModules.PROFILER_MODULE_NONE; |
| 16 this.profileLogPos_ = 0; |
| 17 this.heapProfSample_ = 0; |
| 18 this.heapProfLog_ = ''; |
| 19 }; |
| 20 |
| 21 |
| 22 RemoteDebuggerAgentStub.prototype.DebugBreak = function() { |
| 23 }; |
| 24 |
| 25 |
| 26 RemoteDebuggerAgentStub.prototype.GetContextId = function() { |
| 27 RemoteDebuggerAgent.SetContextId(3); |
| 28 }; |
| 29 |
| 30 |
| 31 RemoteDebuggerAgentStub.prototype.StopProfiling = function(modules) { |
| 32 this.activeProfilerModules_ &= ~modules; |
| 33 }; |
| 34 |
| 35 |
| 36 RemoteDebuggerAgentStub.prototype.StartProfiling = function(modules) { |
| 37 var profModules = devtools.DebuggerAgent.ProfilerModules; |
| 38 if (modules & profModules.PROFILER_MODULE_HEAP_SNAPSHOT) { |
| 39 if (modules & profModules.PROFILER_MODULE_HEAP_STATS) { |
| 40 this.heapProfLog_ += |
| 41 'heap-sample-begin,"Heap","allocated",' + |
| 42 (new Date()).getTime() + '\n' + |
| 43 'heap-sample-stats,"Heap","allocated",10000,1000\n'; |
| 44 this.heapProfLog_ += |
| 45 'heap-sample-item,STRING_TYPE,100,1000\n' + |
| 46 'heap-sample-item,CODE_TYPE,10,200\n' + |
| 47 'heap-sample-item,MAP_TYPE,20,350\n'; |
| 48 this.heapProfLog_ += RemoteDebuggerAgentStub.HeapSamples[this.heapProfSamp
le_++]; |
| 49 this.heapProfSample_ %= RemoteDebuggerAgentStub.HeapSamples.length; |
| 50 this.heapProfLog_ += |
| 51 'heap-sample-end,"Heap","allocated"\n'; |
| 52 } |
| 53 } else { |
| 54 this.activeProfilerModules_ |= modules; |
| 55 } |
| 56 }; |
| 57 |
| 58 |
| 59 RemoteDebuggerAgentStub.prototype.GetActiveProfilerModules = function() { |
| 60 var self = this; |
| 61 setTimeout(function() { |
| 62 RemoteDebuggerAgent.DidGetActiveProfilerModules( |
| 63 self.activeProfilerModules_); |
| 64 }, 100); |
| 65 }; |
| 66 |
| 67 |
| 68 RemoteDebuggerAgentStub.prototype.GetNextLogLines = function() { |
| 69 var profModules = devtools.DebuggerAgent.ProfilerModules; |
| 70 var logLines = ''; |
| 71 if (this.activeProfilerModules_ & profModules.PROFILER_MODULE_CPU) { |
| 72 if (this.profileLogPos_ < RemoteDebuggerAgentStub.ProfilerLogBuffer.length)
{ |
| 73 this.profileLogPos_ += RemoteDebuggerAgentStub.ProfilerLogBuffer.length; |
| 74 logLines += RemoteDebuggerAgentStub.ProfilerLogBuffer; |
| 75 } |
| 76 } |
| 77 if (this.heapProfLog_) { |
| 78 logLines += this.heapProfLog_; |
| 79 this.heapProfLog_ = ''; |
| 80 } |
| 81 setTimeout(function() { |
| 82 RemoteDebuggerAgent.DidGetNextLogLines(logLines); |
| 83 }, 100); |
| 84 }; |
| 85 |
| 86 |
| 87 /** |
| 88 * @constructor |
| 89 */ |
| 90 RemoteToolsAgentStub = function() { |
| 91 }; |
| 92 |
| 93 |
| 94 RemoteToolsAgentStub.prototype.DispatchOnInjectedScript = function() { |
| 95 }; |
| 96 |
| 97 |
| 98 RemoteToolsAgentStub.prototype.DispatchOnInspectorController = function() { |
| 99 }; |
| 100 |
| 101 |
| 102 RemoteToolsAgentStub.prototype.ExecuteVoidJavaScript = function() { |
| 103 }; |
| 104 |
| 105 |
| 106 RemoteDebuggerAgentStub.ProfilerLogBuffer = |
| 107 'profiler,begin,1\n' + |
| 108 'profiler,resume\n' + |
| 109 'code-creation,LazyCompile,0x1000,256,"test1 http://aaa.js:1"\n' + |
| 110 'code-creation,LazyCompile,0x2000,256,"test2 http://bbb.js:2"\n' + |
| 111 'code-creation,LazyCompile,0x3000,256,"test3 http://ccc.js:3"\n' + |
| 112 'tick,0x1010,0x0,3\n' + |
| 113 'tick,0x2020,0x0,3,0x1010\n' + |
| 114 'tick,0x2020,0x0,3,0x1010\n' + |
| 115 'tick,0x3010,0x0,3,0x2020, 0x1010\n' + |
| 116 'tick,0x2020,0x0,3,0x1010\n' + |
| 117 'tick,0x2030,0x0,3,0x2020, 0x1010\n' + |
| 118 'tick,0x2020,0x0,3,0x1010\n' + |
| 119 'tick,0x1010,0x0,3\n' + |
| 120 'profiler,pause\n'; |
| 121 |
| 122 |
| 123 RemoteDebuggerAgentStub.HeapSamples = [ |
| 124 'heap-js-cons-item,foo,1,100\n' + |
| 125 'heap-js-cons-item,bar,20,2000\n' + |
| 126 'heap-js-cons-item,Object,5,100\n' + |
| 127 'heap-js-ret-item,foo,bar;3\n' + |
| 128 'heap-js-ret-item,bar,foo;5\n' + |
| 129 'heap-js-ret-item,Object:0x1234,(roots);1\n', |
| 130 |
| 131 'heap-js-cons-item,foo,2000,200000\n' + |
| 132 'heap-js-cons-item,bar,10,1000\n' + |
| 133 'heap-js-cons-item,Object,6,120\n' + |
| 134 'heap-js-ret-item,foo,bar;7,Object:0x1234;10\n' + |
| 135 'heap-js-ret-item,bar,foo;10,Object:0x1234;10\n' + |
| 136 'heap-js-ret-item,Object:0x1234,(roots);1\n', |
| 137 |
| 138 'heap-js-cons-item,foo,15,1500\n' + |
| 139 'heap-js-cons-item,bar,15,1500\n' + |
| 140 'heap-js-cons-item,Object,5,100\n' + |
| 141 'heap-js-cons-item,Array,3,1000\n' + |
| 142 'heap-js-ret-item,foo,bar;3,Array:0x5678;1\n' + |
| 143 'heap-js-ret-item,bar,foo;5,Object:0x1234;8,Object:0x5678;2\n' + |
| 144 'heap-js-ret-item,Object:0x1234,(roots);1,Object:0x5678;2\n' + |
| 145 'heap-js-ret-item,Object:0x5678,(global property);3,Object:0x1234;5\n' + |
| 146 'heap-js-ret-item,Array:0x5678,(global property);3,Array:0x5678;2\n', |
| 147 |
| 148 'heap-js-cons-item,bar,20,2000\n' + |
| 149 'heap-js-cons-item,Object,6,120\n' + |
| 150 'heap-js-ret-item,bar,foo;5,Object:0x1234;1,Object:0x1235;3\n' + |
| 151 'heap-js-ret-item,Object:0x1234,(global property);3\n' + |
| 152 'heap-js-ret-item,Object:0x1235,(global property);5\n', |
| 153 |
| 154 'heap-js-cons-item,foo,15,1500\n' + |
| 155 'heap-js-cons-item,bar,15,1500\n' + |
| 156 'heap-js-cons-item,Array,10,1000\n' + |
| 157 'heap-js-ret-item,foo,bar;1,Array:0x5678;1\n' + |
| 158 'heap-js-ret-item,bar,foo;5\n' + |
| 159 'heap-js-ret-item,Array:0x5678,(roots);3\n', |
| 160 |
| 161 'heap-js-cons-item,bar,20,2000\n' + |
| 162 'heap-js-cons-item,baz,15,1500\n' + |
| 163 'heap-js-ret-item,bar,baz;3\n' + |
| 164 'heap-js-ret-item,baz,bar;3\n' |
| 165 ]; |
| 166 |
| 167 |
| 168 /** |
| 169 * @constructor |
| 170 */ |
| 171 RemoteDebuggerCommandExecutorStub = function() { |
| 172 }; |
| 173 |
| 174 |
| 175 RemoteDebuggerCommandExecutorStub.prototype.DebuggerCommand = function(cmd) { |
| 176 if ('{"seq":2,"type":"request","command":"scripts","arguments":{"' + |
| 177 'includeSource":false}}' == cmd) { |
| 178 var response1 = |
| 179 '{"seq":5,"request_seq":2,"type":"response","command":"scripts","' + |
| 180 'success":true,"body":[{"handle":61,"type":"script","name":"' + |
| 181 'http://www/~test/t.js","id":59,"lineOffset":0,"columnOffset":0,' + |
| 182 '"lineCount":1,"sourceStart":"function fib(n) {","sourceLength":300,' + |
| 183 '"scriptType":2,"compilationType":0,"context":{"ref":60}}],"refs":[{' + |
| 184 '"handle":60,"type":"context","data":{"type":"page","value":3}}],' + |
| 185 '"running":false}'; |
| 186 this.sendResponse_(response1); |
| 187 } else if ('{"seq":3,"type":"request","command":"scripts","arguments":{' + |
| 188 '"ids":[59],"includeSource":true}}' == cmd) { |
| 189 this.sendResponse_( |
| 190 '{"seq":8,"request_seq":3,"type":"response","command":"scripts",' + |
| 191 '"success":true,"body":[{"handle":1,"type":"script","name":' + |
| 192 '"http://www/~test/t.js","id":59,"lineOffset":0,"columnOffset":0,' + |
| 193 '"lineCount":1,"source":"function fib(n) {return n+1;}",' + |
| 194 '"sourceLength":244,"scriptType":2,"compilationType":0,"context":{' + |
| 195 '"ref":0}}],"refs":[{"handle":0,"type":"context","data":{"type":' + |
| 196 '"page","value":3}}],"running":false}'); |
| 197 } else { |
| 198 debugPrint('Unexpected command: ' + cmd); |
| 199 } |
| 200 }; |
| 201 |
| 202 |
| 203 RemoteDebuggerCommandExecutorStub.prototype.sendResponse_ = function(response) { |
| 204 setTimeout(function() { |
| 205 RemoteDebuggerAgent.DebuggerOutput(response); |
| 206 }, 0); |
| 207 }; |
| 208 |
| 209 |
| 210 /** |
| 211 * @constructor |
| 212 */ |
| 213 DevToolsHostStub = function() { |
| 214 this.isStub = true; |
| 215 window.domAutomationController = { |
| 216 send: function(text) { |
| 217 debugPrint(text); |
| 218 } |
| 219 }; |
| 220 }; |
| 221 |
| 222 |
| 223 function addDummyResource() { |
| 224 var payload = { |
| 225 requestHeaders : {}, |
| 226 requestURL: 'http://google.com/simple_page.html', |
| 227 host: 'google.com', |
| 228 path: 'simple_page.html', |
| 229 lastPathComponent: 'simple_page.html', |
| 230 isMainResource: true, |
| 231 cached: false, |
| 232 mimeType: 'text/html', |
| 233 suggestedFilename: 'simple_page.html', |
| 234 expectedContentLength: 10000, |
| 235 statusCode: 200, |
| 236 contentLength: 10000, |
| 237 responseHeaders: {}, |
| 238 type: WebInspector.Resource.Type.Document, |
| 239 finished: true, |
| 240 startTime: new Date(), |
| 241 |
| 242 didResponseChange: true, |
| 243 didCompletionChange: true, |
| 244 didTypeChange: true |
| 245 }; |
| 246 |
| 247 WebInspector.addResource(1, payload); |
| 248 WebInspector.updateResource(1, payload); |
| 249 } |
| 250 |
| 251 |
| 252 DevToolsHostStub.prototype.loaded = function() { |
| 253 addDummyResource(); |
| 254 }; |
| 255 |
| 256 |
| 257 DevToolsHostStub.prototype.reset = function() { |
| 258 }; |
| 259 |
| 260 |
| 261 DevToolsHostStub.prototype.getPlatform = function() { |
| 262 return "windows"; |
| 263 }; |
| 264 |
| 265 |
| 266 DevToolsHostStub.prototype.hiddenPanels = function() { |
| 267 return ""; |
| 268 }; |
| 269 |
| 270 |
| 271 DevToolsHostStub.prototype.addResourceSourceToFrame = function( |
| 272 identifier, mimeType, element) { |
| 273 }; |
| 274 |
| 275 |
| 276 DevToolsHostStub.prototype.addSourceToFrame = function(mimeType, source, |
| 277 element) { |
| 278 }; |
| 279 |
| 280 |
| 281 DevToolsHostStub.prototype.getApplicationLocale = function() { |
| 282 return "en-US"; |
| 283 }; |
| 284 |
| 285 |
| 286 if (!window['DevToolsHost']) { |
| 287 window['RemoteDebuggerAgent'] = new RemoteDebuggerAgentStub(); |
| 288 window['RemoteDebuggerCommandExecutor'] = |
| 289 new RemoteDebuggerCommandExecutorStub(); |
| 290 window['RemoteToolsAgent'] = new RemoteToolsAgentStub(); |
| 291 window['DevToolsHost'] = new DevToolsHostStub(); |
| 292 } |
OLD | NEW |