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

Delta Between Two Patch Sets: background.js

Issue 6346177440120832: Added abstraction for frames, to fix domain-based rules, whitelisting and ad counter on Safari (Closed)
Left Patch Set: Created Dec. 21, 2013, 7:48 p.m.
Right Patch Set: Addressed another comment Created Jan. 20, 2014, 8:50 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | chrome/ext/background.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 function removeDeprecatedOptions() 72 function removeDeprecatedOptions()
73 { 73 {
74 var deprecatedOptions = ["specialCaseYouTube", "experimental", "disableInlineT extAds"]; 74 var deprecatedOptions = ["specialCaseYouTube", "experimental", "disableInlineT extAds"];
75 deprecatedOptions.forEach(function(option) 75 deprecatedOptions.forEach(function(option)
76 { 76 {
77 if (option in localStorage) 77 if (option in localStorage)
78 delete localStorage[option]; 78 delete localStorage[option];
79 }); 79 });
80 } 80 }
81 81
82 // Sets options to defaults, upgrading old options from previous versions as nec essary 82 // Remove deprecated options before we do anything else.
83 function setDefaultOptions() 83 removeDeprecatedOptions();
84 {
85 function defaultOptionValue(opt, val)
86 {
87 if(!(opt in localStorage))
88 localStorage[opt] = val;
89 }
90
91 defaultOptionValue("shouldShowBlockElementMenu", "true");
92
93 removeDeprecatedOptions();
94 }
95
96 // Upgrade options before we do anything else.
97 setDefaultOptions();
98 84
99 var activeNotification = null; 85 var activeNotification = null;
100 86
101 // Adds or removes browser action icon according to options. 87 // Adds or removes browser action icon according to options.
102 function refreshIconAndContextMenu(tab) 88 function refreshIconAndContextMenu(tab)
103 { 89 {
104 if(!/^https?:/.test(tab.url)) 90 if(!/^https?:/.test(tab.url))
105 return; 91 return;
106 92
107 var iconFilename; 93 var iconFilename;
108 if (require("info").platform == "safari") 94 if (require("info").platform == "safari")
109 // There is no grayscale version of the icon for whitelisted tabs 95 // There is no grayscale version of the icon for whitelisted tabs
110 // when using Safari, because icons are grayscale already and icons 96 // when using Safari, because icons are grayscale already and icons
111 // aren't per tab in Safari. 97 // aren't per tab in Safari.
112 iconFilename = "icons/abp-16.png" 98 iconFilename = "icons/abp-16.png"
113 else 99 else
114 { 100 {
115 var excluded = isWhitelisted(tab.url); 101 var excluded = isWhitelisted(tab.url);
116 iconFilename = excluded ? "icons/abp-19-whitelisted.png" : "icons/abp-19.png "; 102 iconFilename = excluded ? "icons/abp-19-whitelisted.png" : "icons/abp-19.png ";
117 } 103 }
118 104
119 tab.browserAction.setIcon(iconFilename); 105 tab.browserAction.setIcon(iconFilename);
120 tab.browserAction.setTitle(ext.i18n.getMessage("name"));
121
122 iconAnimation.registerTab(tab, iconFilename); 106 iconAnimation.registerTab(tab, iconFilename);
123 107
124 // Set context menu status according to whether current tab has whitelisted do main 108 // Set context menu status according to whether current tab has whitelisted do main
125 if (excluded) 109 if (excluded)
126 chrome.contextMenus.removeAll(); 110 ext.contextMenus.hideMenuItems();
127 else 111 else
128 showContextMenu(); 112 ext.contextMenus.showMenuItems();
129 } 113 }
130 114
131 /** 115 /**
132 * Old versions for Opera stored patterns.ini in the localStorage object, this 116 * Old versions for Opera stored patterns.ini in the localStorage object, this
133 * will import it into FilterStorage properly. 117 * will import it into FilterStorage properly.
134 * @return {Boolean} true if data import is in progress 118 * @return {Boolean} true if data import is in progress
135 */ 119 */
136 function importOldData() 120 function importOldData()
137 { 121 {
138 if ("patterns.ini" in localStorage) 122 if ("patterns.ini" in localStorage)
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 220
237 notifyUser(); 221 notifyUser();
238 } 222 }
239 }, false); 223 }, false);
240 request.send(null); 224 request.send(null);
241 } 225 }
242 else 226 else
243 notifyUser(); 227 notifyUser();
244 } 228 }
245 229
246 // Set up context menu for user selection of elements to block 230 function setContextMenu()
247 function showContextMenu() 231 {
248 { 232 if (Prefs.shouldShowBlockElementMenu)
249 ext.contextMenus.removeAll(function() 233 {
250 { 234 // Register context menu item
251 if(typeof localStorage["shouldShowBlockElementMenu"] == "string" && localSto rage["shouldShowBlockElementMenu"] == "true") 235 ext.contextMenus.addMenuItem(ext.i18n.getMessage("block_element"), ["image", "video", "audio"], function(srcUrl, tab)
252 { 236 {
253 ext.contextMenus.create(ext.i18n.getMessage("block_element"), ["image", "v ideo", "audio"], function(srcUrl, tab) 237 if (srcUrl)
254 { 238 tab.sendMessage({type: "clickhide-new-filter", filter: srcUrl});
255 if(srcUrl) 239 });
256 tab.sendMessage({type: "clickhide-new-filter", filter: srcUrl}); 240 }
257 }); 241 else
258 } 242 ext.contextMenus.removeMenuItems();
259 }); 243 }
260 } 244
245 Prefs.addListener(function(name)
246 {
247 if (name == "shouldShowBlockElementMenu")
248 setContextMenu();
249 });
250 setContextMenu();
261 251
262 /** 252 /**
263 * Opens options tab or focuses an existing one, within the last focused window . 253 * Opens options tab or focuses an existing one, within the last focused window .
264 * @param {Function} callback function to be called with the 254 * @param {Function} callback function to be called with the
265 Tab object of the options tab 255 Tab object of the options tab
266 */ 256 */
267 function openOptions(callback) 257 function openOptions(callback)
268 { 258 {
269 ext.windows.getLastFocused(function(win) 259 ext.windows.getLastFocused(function(win)
270 { 260 {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 } 348 }
359 349
360 var requestHost = extractHostFromURL(msg.url); 350 var requestHost = extractHostFromURL(msg.url);
361 var documentHost = extractHostFromURL(sender.frame.url); 351 var documentHost = extractHostFromURL(sender.frame.url);
362 var thirdParty = isThirdParty(requestHost, documentHost); 352 var thirdParty = isThirdParty(requestHost, documentHost);
363 var filter = defaultMatcher.matchesAny(msg.url, msg.mediatype, documentHos t, thirdParty); 353 var filter = defaultMatcher.matchesAny(msg.url, msg.mediatype, documentHos t, thirdParty);
364 if (filter instanceof BlockingFilter) 354 if (filter instanceof BlockingFilter)
365 { 355 {
366 var collapse = filter.collapse; 356 var collapse = filter.collapse;
367 if (collapse == null) 357 if (collapse == null)
368 collapse = (localStorage.hidePlaceholders != "false"); 358 collapse = Prefs.hidePlaceholders;
369 sendResponse(collapse); 359 sendResponse(collapse);
370 } 360 }
371 else 361 else
372 sendResponse(false); 362 sendResponse(false);
373 break; 363 break;
374 case "get-domain-enabled-state": 364 case "get-domain-enabled-state":
375 // Returns whether this domain is in the exclusion list. 365 // Returns whether this domain is in the exclusion list.
376 // The browser action popup asks us this. 366 // The browser action popup asks us this.
377 if(sender.tab) 367 if(sender.tab)
378 { 368 {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 tab.sendMessage({type: "clickhide-deactivate"}); 419 tab.sendMessage({type: "clickhide-deactivate"});
430 refreshIconAndContextMenu(tab); 420 refreshIconAndContextMenu(tab);
431 }); 421 });
432 422
433 setTimeout(function() 423 setTimeout(function()
434 { 424 {
435 var notificationToShow = Notification.getNextToShow(); 425 var notificationToShow = Notification.getNextToShow();
436 if (notificationToShow) 426 if (notificationToShow)
437 showNotification(notificationToShow); 427 showNotification(notificationToShow);
438 }, 3 * 60 * 1000); 428 }, 3 * 60 * 1000);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld