| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 cr.define('gpu', function() { | 4 cr.define('gpu', function() { |
| 5 /** | 5 /** |
| 6 * This class provides a 'bridge' for communicating between javascript and the | 6 * This class provides a 'bridge' for communicating between javascript and the |
| 7 * browser. When run outside of WebUI, e.g. as a regular webpage, it provides | 7 * browser. When run outside of WebUI, e.g. as a regular webpage, it provides |
| 8 * synthetic data to assist in testing. | 8 * synthetic data to assist in testing. |
| 9 * @constructor | 9 * @constructor |
| 10 */ | 10 */ |
| 11 function BrowserBridge() { | 11 function BrowserBridge() { |
| 12 // If we are not running inside WebUI, output chrome.send messages | 12 // If we are not running inside WebUI, output chrome.send messages |
| 13 // to the console to help with quick-iteration debugging. | 13 // to the console to help with quick-iteration debugging. |
| 14 this.debugMode_ = (chrome.send === undefined && console.log); | 14 this.debugMode_ = (chrome.send === undefined && console.log); |
| 15 if (this.debugMode_) { | 15 if (this.debugMode_) { |
| 16 var browserBridgeTests = document.createElement('script'); | 16 var browserBridgeTests = document.createElement('script'); |
| 17 browserBridgeTests.src = './gpu_internals/browser_bridge_tests.js'; | 17 browserBridgeTests.src = './gpu_internals/browser_bridge_tests.js'; |
| 18 document.body.appendChild(browserBridgeTests); | 18 document.body.appendChild(browserBridgeTests); |
| 19 } | 19 } |
| 20 | 20 |
| 21 this.nextRequestId_ = 0; | 21 this.nextRequestId_ = 0; |
| 22 this.pendingCallbacks_ = []; | 22 this.pendingCallbacks_ = []; |
| 23 this.logMessages_ = []; | 23 this.logMessages_ = []; |
| 24 | 24 |
| 25 // Tell c++ code that we are ready to receive GPU Info. | 25 // Tell c++ code that we are ready to receive GPU Info. |
| 26 if (!this.debugMode_) { | 26 if (!this.debugMode_) { |
| 27 chrome.send('browserBridgeInitialized'); | 27 chrome.send('browserBridgeInitialized'); |
| 28 this.beginRequestClientInfo_(); | 28 this.beginRequestClientInfo_(); |
| 29 this.beginRequestSandboxInfo_(); | |
| 30 this.beginRequestLogMessages_(); | 29 this.beginRequestLogMessages_(); |
| 31 this.beginRequestCrashList_(); | 30 this.beginRequestCrashList_(); |
| 32 } | 31 } |
| 33 } | 32 } |
| 34 | 33 |
| 35 BrowserBridge.prototype = { | 34 BrowserBridge.prototype = { |
| 36 __proto__: cr.EventTarget.prototype, | 35 __proto__: cr.EventTarget.prototype, |
| 37 | 36 |
| 38 applySimulatedData_: function applySimulatedData(data) { | 37 applySimulatedData_: function applySimulatedData(data) { |
| 39 // set up things according to the simulated data | 38 // set up things according to the simulated data |
| 40 this.gpuInfo_ = data.gpuInfo; | 39 this.gpuInfo_ = data.gpuInfo; |
| 41 this.clientInfo_ = data.clientInfo; | 40 this.clientInfo_ = data.clientInfo; |
| 42 this.sandboxInfo_ = data.sandboxInfo; | |
| 43 this.logMessages_ = data.logMessages; | 41 this.logMessages_ = data.logMessages; |
| 44 cr.dispatchSimpleEvent(this, 'gpuInfoUpdate'); | 42 cr.dispatchSimpleEvent(this, 'gpuInfoUpdate'); |
| 45 cr.dispatchSimpleEvent(this, 'clientInfoChange'); | 43 cr.dispatchSimpleEvent(this, 'clientInfoChange'); |
| 46 cr.dispatchSimpleEvent(this, 'sandboxInfoChange'); | |
| 47 cr.dispatchSimpleEvent(this, 'logMessagesChange'); | 44 cr.dispatchSimpleEvent(this, 'logMessagesChange'); |
| 48 }, | 45 }, |
| 49 | 46 |
| 50 /** | 47 /** |
| 51 * Returns true if the page is hosted inside Chrome WebUI | 48 * Returns true if the page is hosted inside Chrome WebUI |
| 52 * Helps have behavior conditional to emulate_webui.py | 49 * Helps have behavior conditional to emulate_webui.py |
| 53 */ | 50 */ |
| 54 get debugMode() { | 51 get debugMode() { |
| 55 return this.debugMode_; | 52 return this.debugMode_; |
| 56 }, | 53 }, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 }, | 111 }, |
| 115 | 112 |
| 116 /** | 113 /** |
| 117 * Returns information about the currently runnign Chrome build. | 114 * Returns information about the currently runnign Chrome build. |
| 118 */ | 115 */ |
| 119 get clientInfo() { | 116 get clientInfo() { |
| 120 return this.clientInfo_; | 117 return this.clientInfo_; |
| 121 }, | 118 }, |
| 122 | 119 |
| 123 /** | 120 /** |
| 124 * This function begins a request for the SandboxInfo. If it comes back | |
| 125 * as undefined, then we will issue the request again in 250ms. | |
| 126 */ | |
| 127 beginRequestSandboxInfo_: function() { | |
| 128 this.callAsync('requestSandboxInfo', undefined, (function(data) { | |
| 129 if (data === undefined) { // try again in 250 ms | |
| 130 window.setTimeout(this.beginRequestSandboxInfo_.bind(this), 250); | |
| 131 } else { | |
| 132 this.sandboxInfo_ = data; | |
| 133 cr.dispatchSimpleEvent(this, 'sandboxInfoChange'); | |
| 134 } | |
| 135 }).bind(this)); | |
| 136 }, | |
| 137 | |
| 138 /** | |
| 139 * Returns information about the currently runnign Chrome sandbox. | |
| 140 */ | |
| 141 get sandboxInfo() { | |
| 142 return this.sandboxInfo_; | |
| 143 }, | |
| 144 | |
| 145 /** | |
| 146 * This function checks for new GPU_LOG messages. | 121 * This function checks for new GPU_LOG messages. |
| 147 * If any are found, a refresh is triggered. | 122 * If any are found, a refresh is triggered. |
| 148 */ | 123 */ |
| 149 beginRequestLogMessages_: function() { | 124 beginRequestLogMessages_: function() { |
| 150 this.callAsync('requestLogMessages', undefined, | 125 this.callAsync('requestLogMessages', undefined, |
| 151 (function(messages) { | 126 (function(messages) { |
| 152 if (messages.length != this.logMessages_.length) { | 127 if (messages.length != this.logMessages_.length) { |
| 153 this.logMessages_ = messages; | 128 this.logMessages_ = messages; |
| 154 cr.dispatchSimpleEvent(this, 'logMessagesChange'); | 129 cr.dispatchSimpleEvent(this, 'logMessagesChange'); |
| 155 } | 130 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 186 get crashList() { | 161 get crashList() { |
| 187 return this.crashList_; | 162 return this.crashList_; |
| 188 } | 163 } |
| 189 | 164 |
| 190 }; | 165 }; |
| 191 | 166 |
| 192 return { | 167 return { |
| 193 BrowserBridge: BrowserBridge | 168 BrowserBridge: BrowserBridge |
| 194 }; | 169 }; |
| 195 }); | 170 }); |
| OLD | NEW |