Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 }); | 279 }); |
280 }); | 280 }); |
281 }); | 281 }); |
282 } | 282 } |
283 | 283 |
284 function prepareNotificationIconAndPopup() | 284 function prepareNotificationIconAndPopup() |
285 { | 285 { |
286 activeNotification.onClicked = function() | 286 activeNotification.onClicked = function() |
287 { | 287 { |
288 iconAnimation.stop(); | 288 iconAnimation.stop(); |
289 activeNotification = null; | |
290 }; | 289 }; |
290 | |
Felix Dahlke
2014/02/26 17:22:58
Why did you change this logic?
Thomas Greiner
2014/02/26 17:37:35
@Felix The problem is that onClicked is never call
Felix Dahlke
2014/02/26 17:47:10
Ah I see. That event handler name is a bit confusi
saroyanm
2014/02/26 18:15:34
@Thomas but the current approach with createHTMLNo
saroyanm
2014/02/26 18:25:08
From My point of view, the logic should change:
We
| |
291 iconAnimation.update(activeNotification.severity); | |
292 activeNotification = null; | |
293 } | |
291 | 294 |
292 iconAnimation.update(activeNotification.severity); | 295 function openNotificationLinks() |
296 { | |
297 if (activeNotification.links) | |
298 { | |
299 activeNotification.links.forEach(function(link) | |
300 { | |
301 ext.windows.getLastFocused(function(win) | |
302 { | |
303 win.openTab(Utils.getDocLink(link)); | |
304 }); | |
305 }); | |
306 } | |
307 } | |
308 | |
309 function notificationButtonClick(id, index) | |
310 { | |
311 if (activeNotification.links && activeNotification.links[index]) | |
312 { | |
313 ext.windows.getLastFocused(function(win) | |
314 { | |
315 win.openTab(Utils.getDocLink(activeNotification.links[index])); | |
316 }); | |
317 } | |
293 } | 318 } |
294 | 319 |
295 function showNotification(notification) | 320 function showNotification(notification) |
296 { | 321 { |
297 activeNotification = notification; | 322 activeNotification = notification; |
298 | 323 if (activeNotification.severity === "critical") |
299 if (activeNotification.severity === "critical" | |
300 && typeof webkitNotifications !== "undefined") | |
301 { | 324 { |
302 var notification = webkitNotifications.createHTMLNotification("notification. html"); | 325 var hasWebkitNotifications = typeof webkitNotifications !== "undefined"; |
303 notification.show(); | 326 if (hasWebkitNotifications && "createHTMLNotification" in webkitNotification s) |
304 notification.addEventListener("close", prepareNotificationIconAndPopup); | 327 { |
328 var notification = webkitNotifications.createHTMLNotification("notificatio n.html"); | |
329 notification.show(); | |
330 notification.addEventListener("close", prepareNotificationIconAndPopup, fa lse); | |
331 return; | |
332 } | |
333 | |
334 var texts = Notification.getLocalizedTexts(notification); | |
335 var title = texts.title || ""; | |
336 var message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; | |
337 var iconUrl = ext.getURL("icons/abp-128.png"); | |
338 var hasLinks = activeNotification.links && activeNotification.links.length > 0; | |
339 if ("browserNotifications" in ext) | |
340 { | |
341 var opts = { | |
342 type: "basic", | |
343 title: title, | |
344 message: message, | |
345 iconUrl: iconUrl, | |
346 buttons: [] | |
347 }; | |
348 var regex = /<a>(.*?)<\/a>/g; | |
349 var plainMessage = texts.message || ""; | |
350 var match; | |
351 while (match = regex.exec(plainMessage)) | |
352 opts.buttons.push({title: match[1]}); | |
353 | |
354 var notification = ext.browserNotifications; | |
355 notification.create("", opts, function() {}); | |
356 notification.onClosed.addListener(prepareNotificationIconAndPopup); | |
357 notification.onButtonClicked.addListener(notificationButtonClick); | |
358 } | |
359 else if (hasWebkitNotifications && "createNotification" in webkitNotificatio ns) | |
360 { | |
361 if (hasLinks) | |
362 message += " " + ext.i18n.getMessage("notification_without_buttons"); | |
363 | |
364 var notification = webkitNotifications.createNotification(iconUrl, title, message); | |
365 notification.show(); | |
366 notification.addEventListener("close", prepareNotificationIconAndPopup, fa lse); | |
367 notification.addEventListener("click", openNotificationLinks, false); | |
368 } | |
369 else | |
370 { | |
371 var message = title + "\n" + message; | |
372 if (hasLinks) | |
373 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); | |
374 | |
375 var notification = confirm(message); | |
376 if (notification == true) | |
377 openNotificationLinks(); | |
378 else | |
379 prepareNotificationIconAndPopup(); | |
380 } | |
305 } | 381 } |
306 else | 382 else |
307 prepareNotificationIconAndPopup(); | 383 prepareNotificationIconAndPopup(); |
308 } | 384 } |
309 | 385 |
310 ext.onMessage.addListener(function (msg, sender, sendResponse) | 386 ext.onMessage.addListener(function (msg, sender, sendResponse) |
311 { | 387 { |
312 switch (msg.type) | 388 switch (msg.type) |
313 { | 389 { |
314 case "get-selectors": | 390 case "get-selectors": |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 tab.sendMessage({type: "clickhide-deactivate"}); | 495 tab.sendMessage({type: "clickhide-deactivate"}); |
420 refreshIconAndContextMenu(tab); | 496 refreshIconAndContextMenu(tab); |
421 }); | 497 }); |
422 | 498 |
423 setTimeout(function() | 499 setTimeout(function() |
424 { | 500 { |
425 var notificationToShow = Notification.getNextToShow(); | 501 var notificationToShow = Notification.getNextToShow(); |
426 if (notificationToShow) | 502 if (notificationToShow) |
427 showNotification(notificationToShow); | 503 showNotification(notificationToShow); |
428 }, 3 * 60 * 1000); | 504 }, 3 * 60 * 1000); |
OLD | NEW |