Chromium Code Reviews| Index: chrome/browser/resources/gpu_internals/browser_bridge.js |
| =================================================================== |
| --- chrome/browser/resources/gpu_internals/browser_bridge.js (revision 0) |
| +++ chrome/browser/resources/gpu_internals/browser_bridge.js (revision 0) |
| @@ -0,0 +1,74 @@ |
| +// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * This class provides a 'bridge' for communicating between javascript and |
| + * the browser. |
| + * |
| + * @constructor |
|
arv (Not doing code reviews)
2010/12/03 22:19:20
Wrong annotation
|
| + */ |
| +cr.define('gpu', function() { |
| + function convertTimeTicksToDate(timeTicks) { |
| + // Note that the subtraction by 0 is to cast to a number (probably a float |
| + // since the numbers are big). |
| + var timeStampMs = (this.timeTickOffset_ - 0) + (timeTicks - 0); |
|
arv (Not doing code reviews)
2010/12/03 22:19:20
Number(expr) is cleaner
nduca
2010/12/03 22:49:39
Turns out I'm not even using this function anymore
arv (Not doing code reviews)
2010/12/06 19:45:57
Non existing code is the cleanest code ;)
|
| + var d = new Date(); |
| + d.setTime(timeStampMs); |
| + return d; |
| + } |
| + |
| + // If we are not running inside DOMUI, output chrome.send messages |
| + // to the console to help with quick-iteration debugging. |
| + function BrowserBridge() { |
|
arv (Not doing code reviews)
2010/12/03 22:19:20
This one should have the @constructor
nduca
2010/12/03 22:49:39
Done.
|
| + if(chrome.send === undefined && console.log) { |
| + chrome.send = function(messageHandler,args) { |
|
arv (Not doing code reviews)
2010/12/03 22:19:20
ws after comma
nduca
2010/12/03 22:49:39
Done.
|
| + if(args) { |
| + console.log('chrome.send(' + messageHandler + ', ' + |
| + args.toString() + ')'); |
|
arv (Not doing code reviews)
2010/12/03 22:19:20
Why not?
console.log('chrome.send', messageHandle
nduca
2010/12/03 22:49:39
Done.
|
| + } else { |
| + console.log('chrome.send(' + messageHandler + ')'); |
| + } |
| + }; |
| + } |
| + |
| + this.nextRequestId_ = 0; |
| + this.pendingCallbacks_ = []; |
| + } |
| + |
| + BrowserBridge.prototype = { |
| + __proto__: Object.prototype, |
| + |
| + /** |
| + * Sends a message to the browser with specified args. The |
| + * browser will reply asynchronously via the provided callback. |
| + */ |
| + callAsync: function(submessage, args, callback) { |
| + var requestId = this.nextRequestId_; |
| + this.nextRequestId_ += 1; |
| + this.pendingCallbacks_[requestId] = callback; |
| + if(args === undefined) { |
|
arv (Not doing code reviews)
2010/12/03 22:19:20
ws
arv (Not doing code reviews)
2010/12/03 22:19:20
if (!args) {
nduca
2010/12/03 22:49:39
Done.
|
| + chrome.send('callAsync', [requestId.toString(), submessage]); |
| + } else { |
| + var all_args = [requestId.toString(), submessage].concat(args); |
|
arv (Not doing code reviews)
2010/12/03 22:19:20
no underscores in js
nduca
2010/12/03 22:49:39
Done.
|
| + chrome.send('callAsync', all_args); |
| + } |
| + }, |
| + |
| + /** |
| + * Called by gpu c++ code when client info is ready. |
| + */ |
| + onCallAsyncReply: function(requestId,args) { |
| + if(this.pendingCallbacks_[requestId] === undefined) { |
|
arv (Not doing code reviews)
2010/12/03 22:19:20
ws
nduca
2010/12/03 22:49:39
Done.
|
| + throw new Error('requestId ' + requestId + ' is not pending'); |
| + } |
| + var callback = this.pendingCallbacks_[requestId]; |
| + callback(args); |
| + delete this.pendingCallbacks_[requestId]; |
| + } |
| + }; |
| + |
| + return { |
| + BrowserBridge : BrowserBridge |
| + }; |
| +}); |
| Property changes on: chrome/browser/resources/gpu_internals/browser_bridge.js |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |