Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Side by Side Diff: chrome/browser/resources/gpu_internals/browser_bridge.js

Issue 5228004: Switch the about:gpu implementation from an about handler to dom_ui.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 cr.define('gpu', function() {
6 /**
7 * This class provides a 'bridge' for communicating between javascript and
8 * the browser.
9 * @constructor
10 */
11 function BrowserBridge() {
12 // If we are not running inside DOMUI, output chrome.send messages
13 // to the console to help with quick-iteration debugging.
14 if (chrome.send === undefined && console.log) {
15 chrome.send = function(messageHandler, args) {
16 if (args) {
17 console.log('chrome.send', messageHandler, args);
arv (Not doing code reviews) 2010/12/06 19:45:57 No need for the branch. I think it is fine to prin
nduca 2010/12/07 01:03:40 Done.
18 } else {
19 console.log('chrome.send', messageHandler);
20 }
21 };
22 }
23
24 this.nextRequestId_ = 0;
25 this.pendingCallbacks_ = [];
26 }
27
28 BrowserBridge.prototype = {
29 __proto__: Object.prototype,
30
31 /**
32 * Sends a message to the browser with specified args. The
33 * browser will reply asynchronously via the provided callback.
34 */
35 callAsync: function(submessage, args, callback) {
36 var requestId = this.nextRequestId_;
37 this.nextRequestId_ += 1;
38 this.pendingCallbacks_[requestId] = callback;
39 if (!args) {
40 chrome.send('callAsync', [requestId.toString(), submessage]);
41 } else {
42 var allArgs = [requestId.toString(), submessage].concat(args);
43 chrome.send('callAsync', allArgs);
44 }
45 },
46
47 /**
48 * Called by gpu c++ code when client info is ready.
49 */
50 onCallAsyncReply: function(requestId, args) {
51 if (this.pendingCallbacks_[requestId] === undefined) {
52 throw new Error('requestId ' + requestId + ' is not pending');
53 }
54 var callback = this.pendingCallbacks_[requestId];
55 callback(args);
56 delete this.pendingCallbacks_[requestId];
57 }
58 };
59
60 return {
61 BrowserBridge : BrowserBridge
62 };
63 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698