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

Side by Side Diff: chrome/test/data/extensions/api_test/notification_provider/test_app/main.js

Issue 461403005: add a test app using notification provider API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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
(Empty)
1 // Window initialization code. Set up event handlers
2 window.addEventListener("load", function() {
3 // set up the event listeners
4 chrome.notificationProvider.onCreated.addListener(notificationCreated);
5 chrome.notificationProvider.onUpdated.addListener(notificationUpdated);
6 chrome.notificationProvider.onCleared.addListener(notificationCleared);
7 });
8
9 function displayImage(text, bitmap, div) {
10 var image = document.createElement("p");
11 image.appendChild(document.createTextNode(text));
12 var imageCanvas = document.createElement("canvas");
13 image.appendChild(imageCanvas);
14 div.appendChild(image);
15
16 var imageContext = imageCanvas.getContext('2d');
17 imageCanvas.width = bitmap.width;
18 imageCanvas.height = bitmap.height;
19 var imagedata = imageContext.createImageData(bitmap.width,
20 bitmap.height);
21 var dataView = new Uint8Array(bitmap.data);
22 for (var i = 0; i < bitmap.width * bitmap.height * 4; i += 1) {
23 imagedata.data[i] = dataView[i];
24 }
25 imageContext.putImageData(imagedata, 0, 0);
26 }
27
28 function addNotification(senderId, notificationId, details) {
29 console.log("--JS--- add notification");
30 var list = document.getElementById("notification_list");
31
32 var div = document.createElement("div");
33 div.class = "notifications";
34 div.id = senderId + notificationId;
35
36 line = document.createElement("br");
37 div.appendChild(line);
38
39 // close button
40 var closeButton = document.createElement("button");
41 closeButton.class = "closeButtons";
42 var buttonText = document.createTextNode("close notificaiton");
43 closeButton.appendChild(buttonText);
44 div.appendChild(closeButton);
45 closeButton.addEventListener("click", function(){
46 clearNotification(senderId, notificationId)
47 }, false);
48
49 // title
50 var bold = document.createElement("b");
51 var title = document.createElement("p");
52 bold.appendChild(document.createTextNode(details.title));
53 title.appendChild(bold);
54 div.appendChild(title);
55
56 // id
57 var id = document.createElement("p");
58 id.appendChild(document.createTextNode("Notification ID: " + notificationId));
59 div.appendChild(id);
60
61 // type
62 var notType = document.createElement("p");
63 notType.appendChild(document.createTextNode("Type: " + details.type));
64 div.appendChild(notType);
65
66 // priority
67 var priority = document.createElement("p");
68 priority.appendChild(document.createTextNode("Priority: " +
69 details.priority));
70 div.appendChild(priority);
71
72 // message
73 var message = document.createElement("p");
74 message.appendChild(document.createTextNode("Message: " + details.message));
75 div.appendChild(message);
76
77 // icon
78 displayImage("Icon: ", details.iconBitmap, div);
79
80 // context message
81 if ("contextMessage" in details) {
82 var message = document.createElement("p");
83 message.appendChild(document.createTextNode("Message: " + details.message));
84 div.appendChild(message);
85 }
86
87 // progress
88 if (details.type == "progress" && "progress" in details) {
89 var progress = document.createElement("p");
90 progress.appendChild(document.createTextNode("Progress: " +
91 details.progress));
92 div.appendChild(progress);
93 }
94
95 // isClickable
96 if ("isClickable" in details) {
97 var clickable = document.createElement("p");
98 clickable.appendChild(document.createTextNode("IsClickable: " +
99 details.isClickable));
100 div.appendChild(clickable);
101 }
102
103 // eventTime
104 if ("eventTime" in details) {
105 var time = document.createElement("p");
106 time.appendChild(document.createTextNode("Event Time: " +
107 details.eventTime));
108 div.appendChild(time);
109 }
110
111 // list
112 if (details.tyep = "list" && "items" in details) {
Pete Williamson 2014/08/14 00:07:55 tyep -> type?
liyanhou 2014/08/14 00:41:50 Done.
113 for (var i = 0, size = details.items.length; i < size; i++) {
114 var item = document.createElement("p");
115 item.appendChild(document.createTextNode(
116 "Item " + (i+1) + ": " +
117 details.items[i].title + " - " +
118 details.items[i].message));
119 div.appendChild(item);
120 }
121 }
122
123 // image
124 if (details.type = "image" && "imageBitmap" in details) {
125 displayImage("Image: ", details.imageBitmap, div);
126 }
127
128 // buttons
129 if ("buttons" in details) {
130 for (var i = 0, size = details.buttons.length; i < size; i++) {
131 var button = document.createElement("p");
132 // TODO: add button image after image is implemented
Pete Williamson 2014/08/14 00:07:55 If you actually check in a TODO (instead of doing
liyanhou 2014/08/14 00:41:50 Done.
133 button.appendChild(document.createTextNode(
134 "Button " + (i+1) + ": " + details.buttons[i].title));
135 div.appendChild(button);
136 }
137 }
138
139 div.appendChild(document.createElement("br"));
140 list.appendChild(div);
141 }
142
143 function clearedCallback(ifCleared){}
144
145 function clearNotification(senderId, notificationId) {
146 var list = document.getElementById("notification_list");
147 list.removeChild(document.getElementById(senderId + notificationId));
148 chrome.notificationProvider.notifyOnCleared(senderId,
149 notificationId,
150 clearedCallback);
151 }
152
153 function notificationCreated(senderId, notificationId, details){
154 addNotification(senderId, notificationId, details);
155 }
156
157 function notificationUpdated(senderId, notificationId, details){
158 var list = document.getElementById("notification_list");
159 list.removeChild(document.getElementById(senderId + notificationId));
160 addNotification(senderId, notificationId, details);
161 }
162
163 function notificationCleared(senderId, notificationId){
164 clearNotification(senderId, notificationId);
165 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698