Index: chrome/browser/resources/gpu/main.js |
=================================================================== |
--- chrome/browser/resources/gpu/main.js (revision 0) |
+++ chrome/browser/resources/gpu/main.js (revision 0) |
@@ -0,0 +1,116 @@ |
+// 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. |
+ |
+/** |
+ * Object to communicate between the renderer and the browser. |
+ * @type {!BrowserBridge} |
+ */ |
+var g_browser = null; |
+ |
+/** |
+ * Main entry point. called once the page has loaded. |
+ */ |
+function onLoaded() { |
+ g_browser = new BrowserBridge(); |
+ |
+ // Create a view which will display general information |
+ // about the gpu. |
+ var infoView = new InfoView("infoTabContent"); |
arv (Not doing code reviews)
2010/11/24 19:07:38
Use single quotes for all js
nduca
2010/12/03 21:32:50
Done.
|
+ g_browser.infoView_ = infoView; |
+ |
+ // Create a view which lets you tab between the different sub-views. |
+ var categoryTabSwitcher = |
+ new TabSwitcherView(new DivView('categoryTabHandles')); |
+ |
+ // Populate the main tabs. |
+ categoryTabSwitcher.addTab('infoTab', infoView, false); |
+ |
+ // Build a map from the anchor name of each tab handle to its "tab ID". |
+ // We will consider navigations to the #hash as a switch tab request. |
+ var anchorMap = {}; |
+ var tabIds = categoryTabSwitcher.getAllTabIds(); |
+ for (var i = 0; i < tabIds.length; ++i) { |
+ var aNode = document.getElementById(tabIds[i]); |
+ anchorMap[aNode.hash] = tabIds[i]; |
+ } |
+ // Default the empty hash to the info tab. |
+ anchorMap['#'] = anchorMap[''] = 'infoTab'; |
+ |
+ window.onhashchange = function() { |
+ var tabId = anchorMap[window.location.hash]; |
+ if (tabId) |
+ categoryTabSwitcher.switchToTab(tabId); |
+ }; |
+ |
+ // Make this category tab widget the primary view, that fills the whole page. |
+ var windowView = new WindowView(categoryTabSwitcher); |
+ |
+ // Trigger initial layout. |
+ windowView.resetGeometry(); |
+ |
+ // Select the initial view based on the current URL. |
+ window.onhashchange(); |
+} |
+ |
+/** |
+ * This class provides a "bridge" for communicating between the javascript and |
+ * the browser. |
+ * |
+ * @constructor |
+ */ |
+function BrowserBridge() { |
+ this.nextRequestId = 0; |
+ this.pendingCallbacks_ = [] |
+ // If we are not running inside DOMUI, otuput chrome.send messages |
+ // to the console to help with quick-iteration debugging. |
+ if(chrome.send === undefined && console.log) { |
+ chrome.send = function(messageHandler,args) { |
+ if(args) { |
+ console.log("chrome.send(" + messageHandler + ", " + |
+ args.toString() + ")"); |
+ } else { |
+ console.log("chrome.send(" + messageHandler + ")"); |
+ } |
+ }; |
+ } |
+} |
+ |
+/** |
+ * This function sends the specified message and arguments, if any, to |
+ * Chrome. It will prepend the message arugments with a requestId. The |
+ * C++-side Chrome code to call onSendReply with that requestId |
+ * in order to complete the request. |
+ */ |
+BrowserBridge.prototype.callAsync = function(submessage, args, callback) { |
+ var requestId = this.nextRequestId; |
+ this.nextRequestId += 1; |
+ this.pendingCallbacks_[requestId] = callback; |
+ if(args === undefined) { |
+ chrome.send("callAsync", [requestId.toString(), submessage]); |
+ } else { |
+ var all_args = [requestId.toString(), submessage].concat(args); |
+ chrome.send("callAsync", all_args); |
+ } |
+}; |
+ |
+/** |
+ * Called by gpu c++ code when client info is ready. |
+ */ |
+BrowserBridge.prototype.onCallAsyncReply = function(requestId,args) { |
+ if(this.pendingCallbacks_[requestId] === undefined) { |
+ throw "requestId " + requestId + " is not pending"; |
arv (Not doing code reviews)
2010/11/24 19:07:38
only throw errors
nduca
2010/12/03 21:32:50
Done.
|
+ } |
+ var callback = this.pendingCallbacks_[requestId]; |
+ callback(args); |
+ delete this.pendingCallbacks_[requestId]; |
+} |
+ |
+convertTimeTicksToDate = function(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); |
+ var d = new Date(); |
+ d.setTime(timeStampMs); |
+ return d; |
+}; |
Property changes on: chrome\browser\resources\gpu\main.js |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |