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
3 // found in the LICENSE file.
6 // require cr/event_target.js
10 * Bridge between the browser and the page.
12 * * define EventTargets to recieve message from the browser,
13 * * dispatch browser messages to EventTarget,
14 * * define interface to request data to the browser.
17 cr.define('cr.quota', function() {
21 * Post requestInfo message to Browser.
23 function requestInfo() {
24 chrome.send('requestInfo');
28 * Callback entry point from Browser.
29 * Messages are Dispatched as Event to:
30 * * onAvailableSpaceUpdated,
31 * * onGlobalInfoUpdated,
32 * * onPerHostInfoUpdated,
33 * * onPerOriginInfoUpdated,
34 * * onStatisticsUpdated.
35 * @param {string} message Message label. Possible Values are:
36 * * 'AvailableSpaceUpdated',
37 * * 'GlobalInfoUpdated',
38 * * 'PerHostInfoUpdated',
39 * * 'PerOriginInfoUpdated',
40 * * 'StatisticsUpdated'.
41 * @param {Object} detail Message specific additional data.
43 function messageHandler(message, detail) {
46 case 'AvailableSpaceUpdated':
47 target = cr.quota.onAvailableSpaceUpdated;
49 case 'GlobalInfoUpdated':
50 target = cr.quota.onGlobalInfoUpdated;
52 case 'PerHostInfoUpdated':
53 target = cr.quota.onPerHostInfoUpdated;
55 case 'PerOriginInfoUpdated':
56 target = cr.quota.onPerOriginInfoUpdated;
58 case 'StatisticsUpdated':
59 target = cr.quota.onStatisticsUpdated;
62 console.error('Unknown Message');
66 var event = cr.doc.createEvent('CustomEvent');
67 event.initCustomEvent('update', false, false, detail);
68 target.dispatchEvent(event);
73 onAvailableSpaceUpdated: new cr.EventTarget(),
74 onGlobalInfoUpdated: new cr.EventTarget(),
75 onPerHostInfoUpdated: new cr.EventTarget(),
76 onPerOriginInfoUpdated: new cr.EventTarget(),
77 onStatisticsUpdated: new cr.EventTarget(),
79 requestInfo: requestInfo,
80 messageHandler: messageHandler