| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // require cr.js | 5 // require cr.js |
| 6 // require cr/event_target.js | 6 // require cr/event_target.js |
| 7 // require cr/util.js | 7 // require cr/util.js |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Bridge between the browser and the page. | 10 * Bridge between the browser and the page. |
| 11 * In this file: | 11 * In this file: |
| 12 * * define EventTargets to recieve message from the browser, | 12 * * define EventTargets to recieve message from the browser, |
| 13 * * dispatch browser messages to EventTarget, | 13 * * dispatch browser messages to EventTarget, |
| 14 * * define interface to request data to the browser. | 14 * * define interface to request data to the browser. |
| 15 */ | 15 */ |
| 16 | 16 |
| 17 cr.define('cr.quota', function() { | 17 cr.define('cr.quota', function() { |
| 18 'use strict'; | 18 'use strict'; |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * Post requestData message to Browser. | 21 * Post requestInfo message to Browser. |
| 22 */ | 22 */ |
| 23 function requestData() { | 23 function requestInfo() { |
| 24 chrome.send('requestData'); | 24 chrome.send('requestInfo'); |
| 25 } | 25 } |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * Callback entry point from Browser. | 28 * Callback entry point from Browser. |
| 29 * Messages are Dispatched as Event to: | 29 * Messages are Dispatched as Event to: |
| 30 * * onAvailableSpaceUpdated, | 30 * * onAvailableSpaceUpdated, |
| 31 * * onGlobalDataUpdated, | 31 * * onGlobalInfoUpdated, |
| 32 * * onHostDataUpdated, | 32 * * onPerHostInfoUpdated, |
| 33 * * onOriginDataUpdated, | 33 * * onPerOriginInfoUpdated, |
| 34 * * onStatisticsUpdated. | 34 * * onStatisticsUpdated. |
| 35 * @param {string} message Message label. Possible Values are: | 35 * @param {string} message Message label. Possible Values are: |
| 36 * * 'AvailableSpaceUpdated', | 36 * * 'AvailableSpaceUpdated', |
| 37 * * 'GlobalDataUpdated', | 37 * * 'GlobalInfoUpdated', |
| 38 * * 'HostDataUpdated', | 38 * * 'PerHostInfoUpdated', |
| 39 * * 'OriginDataUpdated', | 39 * * 'PerOriginInfoUpdated', |
| 40 * * 'StatisticsUpdated'. | 40 * * 'StatisticsUpdated'. |
| 41 * @param {Object} detail Message specific additional data. | 41 * @param {Object} detail Message specific additional data. |
| 42 */ | 42 */ |
| 43 function messageHandler(message, detail) { | 43 function messageHandler(message, detail) { |
| 44 var target = null; | 44 var target = null; |
| 45 switch (message) { | 45 switch (message) { |
| 46 case 'AvailableSpaceUpdated': | 46 case 'AvailableSpaceUpdated': |
| 47 target = cr.quota.onAvailableSpaceUpdated; | 47 target = cr.quota.onAvailableSpaceUpdated; |
| 48 break; | 48 break; |
| 49 case 'GlobalDataUpdated': | 49 case 'GlobalInfoUpdated': |
| 50 target = cr.quota.onGlobalDataUpdated; | 50 target = cr.quota.onGlobalInfoUpdated; |
| 51 break; | 51 break; |
| 52 case 'HostDataUpdated': | 52 case 'PerHostInfoUpdated': |
| 53 target = cr.quota.onHostDataUpdated; | 53 target = cr.quota.onPerHostInfoUpdated; |
| 54 break; | 54 break; |
| 55 case 'OriginDataUpdated': | 55 case 'PerOriginInfoUpdated': |
| 56 target = cr.quota.onOriginDataUpdated; | 56 target = cr.quota.onPerOriginInfoUpdated; |
| 57 break; | 57 break; |
| 58 case 'StatisticsUpdated': | 58 case 'StatisticsUpdated': |
| 59 target = cr.quota.onStatisticsUpdated; | 59 target = cr.quota.onStatisticsUpdated; |
| 60 break; | 60 break; |
| 61 default: | 61 default: |
| 62 console.error('Unknown Message'); | 62 console.error('Unknown Message'); |
| 63 break; | 63 break; |
| 64 } | 64 } |
| 65 if (target) { | 65 if (target) { |
| 66 var event = cr.doc.createEvent('CustomEvent'); | 66 var event = cr.doc.createEvent('CustomEvent'); |
| 67 event.initCustomEvent('update', false, false, detail); | 67 event.initCustomEvent('update', false, false, detail); |
| 68 target.dispatchEvent(event); | 68 target.dispatchEvent(event); |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 return { | 72 return { |
| 73 onAvailableSpaceUpdated: new cr.EventTarget(), | 73 onAvailableSpaceUpdated: new cr.EventTarget(), |
| 74 onGlobalDataUpdated: new cr.EventTarget(), | 74 onGlobalInfoUpdated: new cr.EventTarget(), |
| 75 onHostDataUpdated: new cr.EventTarget(), | 75 onPerHostInfoUpdated: new cr.EventTarget(), |
| 76 onOriginDataUpdated: new cr.EventTarget(), | 76 onPerOriginInfoUpdated: new cr.EventTarget(), |
| 77 onStatisticsUpdated: new cr.EventTarget(), | 77 onStatisticsUpdated: new cr.EventTarget(), |
| 78 | 78 |
| 79 requestData: requestData, | 79 requestInfo: requestInfo, |
| 80 messageHandler: messageHandler | 80 messageHandler: messageHandler |
| 81 }; | 81 }; |
| 82 }); | 82 }); |
| OLD | NEW |