Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: chrome/test/data/extensions/api_test/notifications/galore/app/controller.js

Issue 12313115: Take notification API out of experimental. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Missed one pathname. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 var Galore = Galore || {}; 5 var Galore = Galore || {};
6 6
7 Galore.controller = { 7 Galore.controller = {
8 8
9 BUTTON_IMAGE_SIZE: 64, 9 BUTTON_IMAGE_SIZE: 64,
10 NOTIFICATION_ICON_SIZE: 80, 10 NOTIFICATION_ICON_SIZE: 80,
11 11
12 create: function() { 12 create: function() {
13 var controller = Object.create(this); 13 var controller = Object.create(this);
14 controller.counter = 0; 14 controller.counter = 0;
15 controller.prefix = chrome.runtime.getURL('').slice(0, -1); 15 controller.prefix = chrome.runtime.getURL('').slice(0, -1);
16 controller.view = Galore.view.create(this.prepare_.bind(controller)); 16 controller.view = Galore.view.create(this.prepare_.bind(controller));
17 controller.listen_('onDisplayed'); 17 controller.listen_('onDisplayed');
18 controller.listen_('onError'); 18 controller.listen_('onError');
19 controller.listen_('onClosed'); 19 controller.listen_('onClosed');
20 controller.listen_('onClicked'); 20 controller.listen_('onClicked');
21 controller.listen_('onButtonClicked'); 21 controller.listen_('onButtonClicked');
22 return controller; 22 return controller;
23 }, 23 },
24 24
25 /** @private */ 25 /** @private */
26 listen_: function(event) { 26 listen_: function(event) {
27 var listener = this.event_.bind(this, event); 27 var listener = this.event_.bind(this, event);
28 chrome.experimental.notification[event].addListener(listener); 28 chrome.notification[event].addListener(listener);
dharcourt 2013/03/04 23:46:27 "chrome.notification*" should be "chrome.notificat
29 }, 29 },
30 30
31 /** @private */ 31 /** @private */
32 prepare_: function() { 32 prepare_: function() {
33 Galore.NOTIFICATIONS.forEach(function (type) { 33 Galore.NOTIFICATIONS.forEach(function (type) {
34 type.notifications.forEach(function (options) { 34 type.notifications.forEach(function (options) {
35 this.view.addNotificationButton( 35 this.view.addNotificationButton(
36 type.templateType, 36 type.templateType,
37 type.name, 37 type.name,
38 this.replace_(options.iconUrl, this.BUTTON_IMAGE_SIZE), 38 this.replace_(options.iconUrl, this.BUTTON_IMAGE_SIZE),
39 this.notify_.bind(this, type.templateType, options)); 39 this.notify_.bind(this, type.templateType, options));
40 }, this); 40 }, this);
41 }, this); 41 }, this);
42 }, 42 },
43 43
44 /** @private */ 44 /** @private */
45 id_: function() { 45 id_: function() {
46 this.counter += 1; 46 this.counter += 1;
47 return String(this.counter); 47 return String(this.counter);
48 }, 48 },
49 49
50 /** @private */ 50 /** @private */
51 notify_: function(type, options) { 51 notify_: function(type, options) {
52 var id = this.id_(); 52 var id = this.id_();
53 var priority = this.view.getPriority(); 53 var priority = this.view.getPriority();
54 var expanded = this.expand_(options, type, priority); 54 var expanded = this.expand_(options, type, priority);
55 if (chrome.experimental.notification.create) { 55 if (chrome.notification.create) {
56 chrome.experimental.notification.create(id, expanded, function() {}); 56 chrome.notification.create(id, expanded, function() {});
57 } else { 57 } else {
58 expanded.replaceId = id; 58 expanded.replaceId = id;
59 delete expanded.buttonOneIconUrl; 59 delete expanded.buttonOneIconUrl;
60 delete expanded.buttonOneTitle; 60 delete expanded.buttonOneTitle;
61 delete expanded.buttonTwoIconUrl; 61 delete expanded.buttonTwoIconUrl;
62 delete expanded.buttonTwoTitle; 62 delete expanded.buttonTwoTitle;
63 chrome.experimental.notification.show(expanded, function() {}); 63 chrome.notification.show(expanded, function() {});
64 } 64 }
65 this.event_('create', id, 'priority: ' + priority); 65 this.event_('create', id, 'priority: ' + priority);
66 }, 66 },
67 67
68 /** @private */ 68 /** @private */
69 expand_: function(options, type, priority) { 69 expand_: function(options, type, priority) {
70 var expanded = {templateType: type, priority: priority}; 70 var expanded = {templateType: type, priority: priority};
71 Object.keys(options).forEach(function (key) { 71 Object.keys(options).forEach(function (key) {
72 expanded[key] = this.replace_(options[key], this.NOTIFICATION_ICON_SIZE); 72 expanded[key] = this.replace_(options[key], this.NOTIFICATION_ICON_SIZE);
73 }, this); 73 }, this);
(...skipping 22 matching lines...) Expand all
96 }, 96 },
97 97
98 /** @private */ 98 /** @private */
99 event_: function(event, id, var_args) { 99 event_: function(event, id, var_args) {
100 this.view.logEvent('Notification #' + id + ': ' + event + '(' + 100 this.view.logEvent('Notification #' + id + ': ' + event + '(' +
101 Array.prototype.slice.call(arguments, 2).join(', ') + 101 Array.prototype.slice.call(arguments, 2).join(', ') +
102 ')'); 102 ')');
103 } 103 }
104 104
105 }; 105 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698