Index: chrome/browser/resources/quota_internals/quota-internals.js |
diff --git a/chrome/browser/resources/quota_internals/quota-internals.js b/chrome/browser/resources/quota_internals/quota-internals.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f1bfa48373289a80720b6f47f8e3d92626057d6c |
--- /dev/null |
+++ b/chrome/browser/resources/quota_internals/quota-internals.js |
@@ -0,0 +1,82 @@ |
+// Copyright (c) 2011 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. |
+ |
+// require cr.js |
+// require cr/event_target.js |
+// require cr/util.js |
+ |
+/** |
+ * Bridge between the browser and the page. |
+ * In this file: |
+ * * define EventTargets to recieve message from the browser, |
+ * * dispatch browser messages to EventTarget, |
+ * * define interface to request data to the browser. |
+ */ |
+ |
+cr.define('cr.quota', function() { |
+ 'use strict'; |
+ |
+ /** |
+ * Post requestData message to Browser. |
+ */ |
+ function requestData() { |
+ chrome.send('requestData'); |
+ } |
+ |
+ /** |
+ * Callback entry poing from Browser. |
+ * Messages are Dispatched as Event to: |
+ * * onAvailableSpaceUpdated, |
+ * * onGlobalDataUpdated, |
+ * * onHostDataUpdated, |
+ * * onOriginDataUpdated, |
+ * * onStatisticsUpdated. |
+ * @param {string} message Message label. Possible Values are: |
+ * * AvailableSpaceUpdated, |
+ * * GlobalDataUpdated, |
+ * * HostDataUpdated, |
+ * * OriginDataUpdated, |
+ * * StatisticsUpdated. |
+ * @param {Object} detais Message specific additional data. |
Evan Stade
2011/06/07 16:54:44
s/detais/detail
tzik
2011/06/13 05:40:57
Done.
|
+ */ |
+ function messageHandler_(message, detail) { |
Evan Stade
2011/06/07 16:54:44
remove final underscore
tzik
2011/06/13 05:40:57
Done.
|
+ var target = null; |
+ switch (message) { |
+ case 'AvailableSpaceUpdated': |
Evan Stade
2011/06/07 16:54:44
everything inside switch should be indented 2 spac
tzik
2011/06/13 05:40:57
Done.
|
+ target = cr.quota.onAvailableSpaceUpdated; |
+ break; |
+ case 'GlobalDataUpdated': |
+ target = cr.quota.onGlobalDataUpdated; |
+ break; |
+ case 'HostDataUpdated': |
+ target = cr.quota.onHostDataUpdated; |
+ break; |
+ case 'OriginDataUpdated': |
+ target = cr.quota.onOriginDataUpdated; |
+ break; |
+ case 'StatisticsUpdated': |
+ target = cr.quota.onStatisticsUpdated; |
+ break; |
+ default: |
+ console.log('Unknown Message'); |
Evan Stade
2011/06/07 16:54:44
probably worthy of a console.error
tzik
2011/06/13 05:40:57
Done.
|
+ break; |
+ } |
+ var event = cr.doc.createEvent('CustomEvent'); |
Evan Stade
2011/06/07 16:54:44
move inside if statement?
tzik
2011/06/13 05:40:57
Done.
|
+ if (target) { |
+ event.initCustomEvent('update', false, false, detail); |
+ target.dispatchEvent(event); |
+ } |
+ } |
+ |
+ return { |
+ onAvailableSpaceUpdated: new cr.EventTarget(), |
+ onGlobalDataUpdated: new cr.EventTarget(), |
+ onHostDataUpdated: new cr.EventTarget(), |
+ onOriginDataUpdated: new cr.EventTarget(), |
+ onStatisticsUpdated: new cr.EventTarget(), |
+ |
+ requestData: requestData, |
+ messageHandler_: messageHandler_ |
+ }; |
+}); |