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

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

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

Powered by Google App Engine
This is Rietveld 408576698