Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: background.js

Issue 6182748523855872: Issue 1518 - Got rid of deprecated code using webkitNotifications (Closed)
Patch Set: Use addEventListener() Created Jan. 13, 2015, 12:29 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/notification.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 23 matching lines...) Expand all
34 this.isFrameWhitelisted = isFrameWhitelisted; 34 this.isFrameWhitelisted = isFrameWhitelisted;
35 this.processKey = processKey; 35 this.processKey = processKey;
36 this.getKey = getKey; 36 this.getKey = getKey;
37 } 37 }
38 var FilterStorage = require("filterStorage").FilterStorage; 38 var FilterStorage = require("filterStorage").FilterStorage;
39 var ElemHide = require("elemHide").ElemHide; 39 var ElemHide = require("elemHide").ElemHide;
40 var defaultMatcher = require("matcher").defaultMatcher; 40 var defaultMatcher = require("matcher").defaultMatcher;
41 var Prefs = require("prefs").Prefs; 41 var Prefs = require("prefs").Prefs;
42 var Synchronizer = require("synchronizer").Synchronizer; 42 var Synchronizer = require("synchronizer").Synchronizer;
43 var Utils = require("utils").Utils; 43 var Utils = require("utils").Utils;
44 var Notification = require("notification").Notification; 44 var NotificationStorage = require("notification").Notification;
45 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti fication; 45 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti fication;
46 var parseFilters = require("filterValidation").parseFilters; 46 var parseFilters = require("filterValidation").parseFilters;
47 47
48 // Some types cannot be distinguished 48 // Some types cannot be distinguished
49 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; 49 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT;
50 RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OT HER; 50 RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OT HER;
51 51
52 // Chrome on Linux does not fully support chrome.notifications until version 35 52 // Chrome on Linux does not fully support chrome.notifications until version 35
53 // https://code.google.com/p/chromium/issues/detail?id=291485 53 // https://code.google.com/p/chromium/issues/detail?id=291485
54 var canUseChromeNotifications = require("info").platform == "chromium" 54 var canUseChromeNotifications = require("info").platform == "chromium"
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 win.openTab(Utils.getDocLink(link)); 292 win.openTab(Utils.getDocLink(link));
293 }); 293 });
294 }); 294 });
295 } 295 }
296 } 296 }
297 297
298 function notificationButtonClick(buttonIndex) 298 function notificationButtonClick(buttonIndex)
299 { 299 {
300 if (activeNotification.type === "question") 300 if (activeNotification.type === "question")
301 { 301 {
302 Notification.triggerQuestionListeners(activeNotification.id, buttonIndex === 0); 302 NotificationStorage.triggerQuestionListeners(activeNotification.id, buttonIn dex === 0);
303 Notification.markAsShown(activeNotification.id); 303 NotificationStorage.markAsShown(activeNotification.id);
304 activeNotification.onClicked(); 304 activeNotification.onClicked();
305 } 305 }
306 else if (activeNotification.links && activeNotification.links[buttonIndex]) 306 else if (activeNotification.links && activeNotification.links[buttonIndex])
307 { 307 {
308 ext.windows.getLastFocused(function(win) 308 ext.windows.getLastFocused(function(win)
309 { 309 {
310 win.openTab(Utils.getDocLink(activeNotification.links[buttonIndex])); 310 win.openTab(Utils.getDocLink(activeNotification.links[buttonIndex]));
311 }); 311 });
312 } 312 }
313 } 313 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 } 358 }
359 359
360 function showNotification(notification) 360 function showNotification(notification)
361 { 361 {
362 if (activeNotification && activeNotification.id === notification.id) 362 if (activeNotification && activeNotification.id === notification.id)
363 return; 363 return;
364 364
365 activeNotification = notification; 365 activeNotification = notification;
366 if (activeNotification.type === "critical" || activeNotification.type === "que stion") 366 if (activeNotification.type === "critical" || activeNotification.type === "que stion")
367 { 367 {
368 var hasWebkitNotifications = typeof webkitNotifications !== "undefined"; 368 var texts = NotificationStorage.getLocalizedTexts(notification);
369 if (hasWebkitNotifications && "createHTMLNotification" in webkitNotification s)
370 {
371 var notification = webkitNotifications.createHTMLNotification("notificatio n.html");
372 notification.show();
373 prepareNotificationIconAndPopup();
374 return;
375 }
376
377 var texts = Notification.getLocalizedTexts(notification);
378 var title = texts.title || ""; 369 var title = texts.title || "";
379 var message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; 370 var message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : "";
380 var iconUrl = ext.getURL("icons/abp-128.png"); 371 var iconUrl = ext.getURL("icons/abp-128.png");
381 var hasLinks = activeNotification.links && activeNotification.links.length > 0; 372 var hasLinks = activeNotification.links && activeNotification.links.length > 0;
382 373
383 if (canUseChromeNotifications) 374 if (canUseChromeNotifications)
384 { 375 {
385 var opts = { 376 var opts = {
386 type: "basic", 377 type: "basic",
387 title: title, 378 title: title,
(...skipping 14 matching lines...) Expand all
402 while (match = regex.exec(plainMessage)) 393 while (match = regex.exec(plainMessage))
403 opts.buttons.push({title: match[1]}); 394 opts.buttons.push({title: match[1]});
404 } 395 }
405 396
406 imgToBase64(iconUrl, function(iconData) 397 imgToBase64(iconUrl, function(iconData)
407 { 398 {
408 opts["iconUrl"] = iconData; 399 opts["iconUrl"] = iconData;
409 chrome.notifications.create("", opts, function() {}); 400 chrome.notifications.create("", opts, function() {});
410 }); 401 });
411 } 402 }
412 else if (hasWebkitNotifications && "createNotification" in webkitNotificatio ns && activeNotification.type !== "question") 403 else if ("Notification" in window && activeNotification.type !== "question")
413 { 404 {
414 if (hasLinks) 405 if (hasLinks)
415 message += " " + ext.i18n.getMessage("notification_without_buttons"); 406 message += " " + ext.i18n.getMessage("notification_without_buttons");
416 407
417 imgToBase64(iconUrl, function(iconData) 408 imgToBase64(iconUrl, function(iconData)
418 { 409 {
419 var notification = webkitNotifications.createNotification(iconData, titl e, message); 410 var notification = new Notification(
420 notification.show(); 411 title,
421 notification.addEventListener("click", openNotificationLinks, false); 412 {
422 notification.addEventListener("close", notificationClosed, false); 413 lang: Utils.appLocale,
414 dir: ext.i18n.getMessage("@@bidi_dir"),
415 body: message,
416 icon: iconData
417 }
418 );
419
420 notification.addEventListener("click", openNotificationLinks);
421 notification.addEventListener("close", notificationClosed);
423 }); 422 });
424 } 423 }
425 else 424 else
426 { 425 {
427 var message = title + "\n" + message; 426 var message = title + "\n" + message;
428 if (hasLinks) 427 if (hasLinks)
429 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); 428 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons");
430 429
431 var approved = confirm(message); 430 var approved = confirm(message);
432 if (activeNotification.type === "question") 431 if (activeNotification.type === "question")
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 574
576 // update icon when page changes location 575 // update icon when page changes location
577 ext.pages.onLoading.addListener(function(page) 576 ext.pages.onLoading.addListener(function(page)
578 { 577 {
579 page.sendMessage({type: "clickhide-deactivate"}); 578 page.sendMessage({type: "clickhide-deactivate"});
580 refreshIconAndContextMenu(page); 579 refreshIconAndContextMenu(page);
581 }); 580 });
582 581
583 setTimeout(function() 582 setTimeout(function()
584 { 583 {
585 var notificationToShow = Notification.getNextToShow(); 584 var notificationToShow = NotificationStorage.getNextToShow();
586 if (notificationToShow) 585 if (notificationToShow)
587 showNotification(notificationToShow); 586 showNotification(notificationToShow);
588 }, 3 * 60 * 1000); 587 }, 3 * 60 * 1000);
OLDNEW
« no previous file with comments | « no previous file | chrome/notification.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld