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

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

Issue 12211020: Added "Notifications Galore!" notification test app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed copyright message for commit checks. Created 7 years, 10 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
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/notification/galore/app/images/Image1-300x225.jpg » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 var Galore = Galore || {};
6
7 Galore.controller = {
8
9 BUTTON_IMAGE_SIZE: 64,
10 NOTIFICATION_ICON_SIZE: 80,
11
12 create: function() {
13 var controller = Object.create(this);
14 controller.counter = 0;
15 controller.prefix = chrome.runtime.getURL('').slice(0, -1);
16 controller.view = Galore.view.create(this.prepare_.bind(controller));
17 controller.listen_('onDisplayed');
18 controller.listen_('onError');
19 controller.listen_('onClosed');
20 controller.listen_('onClicked');
21 controller.listen_('onButtonClicked');
22 return controller;
23 },
24
25 /** @private */
26 listen_: function(event) {
27 var listener = this.event_.bind(this, event);
28 chrome.experimental.notification[event].addListener(listener);
29 },
30
31 /** @private */
32 prepare_: function() {
33 Galore.NOTIFICATIONS.forEach(function (type) {
34 type.notifications.forEach(function (options) {
35 this.view.addNotificationButton(
36 type.type,
37 type.name,
38 this.replace_(options.iconUrl, this.BUTTON_IMAGE_SIZE),
39 this.notify_.bind(this, type.type, options));
40 }, this);
41 }, this);
42 },
43
44 /** @private */
45 id_: function() {
46 this.counter += 1;
47 return String(this.counter);
48 },
49
50 /** @private */
51 notify_: function(type, options) {
52 var id = this.id_();
53 var priority = this.view.getPriority();
54 var expanded = this.expand_(options, type, priority);
55 if (chrome.experimental.notification.create) {
56 chrome.experimental.notification.create(id, expanded, function() {});
57 } else {
58 expanded.replaceId = id;
59 delete expanded.buttonOneIconUrl;
60 delete expanded.buttonOneTitle;
61 delete expanded.buttonTwoIconUrl;
62 delete expanded.buttonTwoTitle;
63 chrome.experimental.notification.show(expanded, function() {});
64 }
65 this.event_('create', id, 'priority: ' + priority);
66 },
67
68 /** @private */
69 expand_: function(options, type, priority) {
70 var expanded = {type: type, priority: priority};
71 Object.keys(options).forEach(function (key) {
72 expanded[key] = this.replace_(options[key], this.NOTIFICATION_ICON_SIZE);
73 }, this);
74 return expanded;
75 },
76
77 /** @private */
78 replace_: function(option, size) {
79 var replaced = option;
80 if (typeof replaced === 'string') {
81 replaced = replaced.replace(/\$#/g, this.counter);
82 replaced = replaced.replace(/\$@/g, this.prefix);
83 replaced = replaced.replace(/\$%/g, size);
84 }
85 return replaced;
86 },
87
88 /** @private */
89 event_: function(event, id, var_args) {
90 this.view.logEvent('Notification #' + id + ': ' + event + '(' +
91 Array.prototype.slice.call(arguments, 2).join(', ') +
92 ')');
93 }
94
95 };
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/notification/galore/app/images/Image1-300x225.jpg » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698