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

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: Fix merge conflict. 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');
19 controller.listen_('onClosed'); 18 controller.listen_('onClosed');
20 controller.listen_('onClicked'); 19 controller.listen_('onClicked');
21 controller.listen_('onButtonClicked'); 20 controller.listen_('onButtonClicked');
22 return controller; 21 return controller;
23 }, 22 },
24 23
25 /** @private */ 24 /** @private */
26 listen_: function(event) { 25 listen_: function(event) {
27 var listener = this.event_.bind(this, event); 26 var listener = this.event_.bind(this, event);
28 chrome.experimental.notification[event].addListener(listener); 27 chrome.notifications[event].addListener(listener);
29 }, 28 },
30 29
31 /** @private */ 30 /** @private */
32 prepare_: function() { 31 prepare_: function() {
33 Galore.NOTIFICATIONS.forEach(function (type) { 32 Galore.NOTIFICATIONS.forEach(function (type) {
34 type.notifications.forEach(function (options) { 33 type.notifications.forEach(function (options) {
35 this.view.addNotificationButton( 34 this.view.addNotificationButton(
36 type.templateType, 35 type.templateType,
37 type.name, 36 type.name,
38 this.replace_(options.iconUrl, this.BUTTON_IMAGE_SIZE), 37 this.replace_(options.iconUrl, this.BUTTON_IMAGE_SIZE),
39 this.notify_.bind(this, type.templateType, options)); 38 this.notify_.bind(this, type.templateType, options));
40 }, this); 39 }, this);
41 }, this); 40 }, this);
42 }, 41 },
43 42
44 /** @private */ 43 /** @private */
45 id_: function() { 44 id_: function() {
46 this.counter += 1; 45 this.counter += 1;
47 return String(this.counter); 46 return String(this.counter);
48 }, 47 },
49 48
50 /** @private */ 49 /** @private */
51 notify_: function(type, options) { 50 notify_: function(type, options) {
52 var id = this.id_(); 51 var id = this.id_();
53 var priority = this.view.getPriority(); 52 var priority = this.view.getPriority();
54 var expanded = this.expand_(options, type, priority); 53 var expanded = this.expand_(options, type, priority);
55 if (chrome.experimental.notification.create) { 54 if (chrome.notifications.create) {
56 chrome.experimental.notification.create(id, expanded, function() {}); 55 chrome.notifications.create(id, expanded, function() {});
57 } else { 56 } else {
58 expanded.replaceId = id; 57 expanded.replaceId = id;
59 delete expanded.buttonOneIconUrl; 58 delete expanded.buttonOneIconUrl;
60 delete expanded.buttonOneTitle; 59 delete expanded.buttonOneTitle;
61 delete expanded.buttonTwoIconUrl; 60 delete expanded.buttonTwoIconUrl;
62 delete expanded.buttonTwoTitle; 61 delete expanded.buttonTwoTitle;
63 chrome.experimental.notification.show(expanded, function() {}); 62 chrome.notifications.show(expanded, function() {});
64 } 63 }
65 this.event_('create', id, 'priority: ' + priority); 64 this.event_('create', id, 'priority: ' + priority);
66 }, 65 },
67 66
68 /** @private */ 67 /** @private */
69 expand_: function(options, type, priority) { 68 expand_: function(options, type, priority) {
70 var expanded = {templateType: type, priority: priority}; 69 var expanded = {templateType: type, priority: priority};
71 Object.keys(options).forEach(function (key) { 70 Object.keys(options).forEach(function (key) {
72 expanded[key] = this.replace_(options[key], this.NOTIFICATION_ICON_SIZE); 71 expanded[key] = this.replace_(options[key], this.NOTIFICATION_ICON_SIZE);
73 }, this); 72 }, this);
(...skipping 22 matching lines...) Expand all
96 }, 95 },
97 96
98 /** @private */ 97 /** @private */
99 event_: function(event, id, var_args) { 98 event_: function(event, id, var_args) {
100 this.view.logEvent('Notification #' + id + ': ' + event + '(' + 99 this.view.logEvent('Notification #' + id + ': ' + event + '(' +
101 Array.prototype.slice.call(arguments, 2).join(', ') + 100 Array.prototype.slice.call(arguments, 2).join(', ') +
102 ')'); 101 ')');
103 } 102 }
104 103
105 }; 104 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698