Roll src/third_party/WebKit bf18a82:a9cee16 (svn 185297:185304)
[chromium-blink-merge.git] / chrome / browser / resources / quota_internals / message_dispatcher.js
blob7088a6842a2d9e06a16c6280e4c46b61952ddad4
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.
5 // require cr.js
6 // require cr/event_target.js
7 // require cr/util.js
9 /**
10 * Bridge between the browser and the page.
11 * In this file:
12 * * define EventTargets to receive 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() {
18 'use strict';
20 /**
21 * Post requestInfo message to Browser.
23 function requestInfo() {
24 chrome.send('requestInfo');
27 /**
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) {
44 var target = null;
45 switch (message) {
46 case 'AvailableSpaceUpdated':
47 target = cr.quota.onAvailableSpaceUpdated;
48 break;
49 case 'GlobalInfoUpdated':
50 target = cr.quota.onGlobalInfoUpdated;
51 break;
52 case 'PerHostInfoUpdated':
53 target = cr.quota.onPerHostInfoUpdated;
54 break;
55 case 'PerOriginInfoUpdated':
56 target = cr.quota.onPerOriginInfoUpdated;
57 break;
58 case 'StatisticsUpdated':
59 target = cr.quota.onStatisticsUpdated;
60 break;
61 default:
62 console.error('Unknown Message');
63 break;
65 if (target) {
66 var event = cr.doc.createEvent('CustomEvent');
67 event.initCustomEvent('update', false, false, detail);
68 target.dispatchEvent(event);
72 return {
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
82 });