| OLD | NEW | 
|---|
| (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 /** | 
|  | 6  * Object to communicate between the renderer and the browser. | 
|  | 7  * @type {!BrowserBridge} | 
|  | 8  */ | 
|  | 9 var g_browser = null; | 
|  | 10 | 
|  | 11 /** | 
|  | 12  * Main entry point. called once the page has loaded. | 
|  | 13  */ | 
|  | 14 function onLoaded() { | 
|  | 15   g_browser = new BrowserBridge(); | 
|  | 16 | 
|  | 17   // Create a view which will display general information | 
|  | 18   // about the gpu. | 
|  | 19   var infoView = new InfoView("infoTabContent"); | 
|  | 20   g_browser.infoView_ = infoView; | 
|  | 21 | 
|  | 22   // Create a view which lets you tab between the different sub-views. | 
|  | 23   var categoryTabSwitcher = | 
|  | 24       new TabSwitcherView(new DivView('categoryTabHandles')); | 
|  | 25 | 
|  | 26   // Populate the main tabs. | 
|  | 27   categoryTabSwitcher.addTab('infoTab', infoView, false); | 
|  | 28 | 
|  | 29   // Build a map from the anchor name of each tab handle to its "tab ID". | 
|  | 30   // We will consider navigations to the #hash as a switch tab request. | 
|  | 31   var anchorMap = {}; | 
|  | 32   var tabIds = categoryTabSwitcher.getAllTabIds(); | 
|  | 33   for (var i = 0; i < tabIds.length; ++i) { | 
|  | 34     var aNode = document.getElementById(tabIds[i]); | 
|  | 35     anchorMap[aNode.hash] = tabIds[i]; | 
|  | 36   } | 
|  | 37   // Default the empty hash to the info tab. | 
|  | 38   anchorMap['#'] = anchorMap[''] = 'infoTab'; | 
|  | 39 | 
|  | 40   window.onhashchange = function() { | 
|  | 41     var tabId = anchorMap[window.location.hash]; | 
|  | 42     if (tabId) | 
|  | 43       categoryTabSwitcher.switchToTab(tabId); | 
|  | 44   }; | 
|  | 45 | 
|  | 46   // Make this category tab widget the primary view, that fills the whole page. | 
|  | 47   var windowView = new WindowView(categoryTabSwitcher); | 
|  | 48 | 
|  | 49   // Trigger initial layout. | 
|  | 50   windowView.resetGeometry(); | 
|  | 51 | 
|  | 52   // Select the initial view based on the current URL. | 
|  | 53   window.onhashchange(); | 
|  | 54 } | 
|  | 55 | 
|  | 56 /** | 
|  | 57  * This class provides a "bridge" for communicating between the javascript and | 
|  | 58  * the browser. | 
|  | 59  * | 
|  | 60  * @constructor | 
|  | 61  */ | 
|  | 62 function BrowserBridge() { | 
|  | 63   this.nextRequestId = 0 | 
|  | 64   this.pendingCallbacks_ = [] | 
|  | 65   // If we are not running inside DOMUI, otuput chrome.send messages | 
|  | 66   // to the console to help with quick-iteration debugging. | 
|  | 67   if(chrome.send === undefined && console.log) { | 
|  | 68     chrome.send = function(messageHandler,args) { | 
|  | 69       if(args) { | 
|  | 70         console.log("chrome.send(" + messageHandler + ", " + | 
|  | 71             args.toString() + ")"); | 
|  | 72       } else { | 
|  | 73         console.log("chrome.send(" + messageHandler + ")"); | 
|  | 74       } | 
|  | 75     }; | 
|  | 76   } | 
|  | 77 } | 
|  | 78 | 
|  | 79 /** | 
|  | 80  * This function sends the specified message and arguments, if any, to | 
|  | 81  * Chrome.  It will prepend the message arugments with a requestId. The | 
|  | 82  * C++-side Chrome code to call onSendReply with that requestId | 
|  | 83  * in order to complete the request. | 
|  | 84  */ | 
|  | 85 BrowserBridge.prototype.callAsync = function(submessage, args, callback) { | 
|  | 86   var requestId = this.nextRequestId; | 
|  | 87   this.nextRequestId += 1; | 
|  | 88   this.pendingCallbacks_[requestId] = callback; | 
|  | 89   if(args === undefined) { | 
|  | 90     chrome.send("callAsync", [requestId.toString(), submessage]); | 
|  | 91   } else { | 
|  | 92     var all_args = [requestId.toString(), submessage].concat(args); | 
|  | 93     chrome.send("callAsync", all_args); | 
|  | 94   } | 
|  | 95 }; | 
|  | 96 | 
|  | 97 /** | 
|  | 98  * Called by gpu c++ code when client info is ready. | 
|  | 99  */ | 
|  | 100 BrowserBridge.prototype.onCallAsyncReply = function(requestId,args) { | 
|  | 101   if(this.pendingCallbacks_[requestId] === undefined) { | 
|  | 102     throw "requestId " + requestId + " is not pending"; | 
|  | 103   } | 
|  | 104   var callback = this.pendingCallbacks_[requestId]; | 
|  | 105   callback(args); | 
|  | 106   delete this.pendingCallbacks_[requestId]; | 
|  | 107 } | 
|  | 108 | 
|  | 109 convertTimeTicksToDate = function(timeTicks) { | 
|  | 110   // Note that the subtraction by 0 is to cast to a number (probably a float | 
|  | 111   // since the numbers are big). | 
|  | 112   var timeStampMs = (this.timeTickOffset_ - 0) + (timeTicks - 0); | 
|  | 113   var d = new Date(); | 
|  | 114   d.setTime(timeStampMs); | 
|  | 115   return d; | 
|  | 116 }; | 
| OLD | NEW | 
|---|