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

Side by Side Diff: background.js

Issue 5589897452716032: Implemented ext.contextMenus for Safari (Closed)
Patch Set: Created Jan. 18, 2014, 10:29 a.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 | block.js » ('j') | safari/background.js » ('J')
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-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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 function removeDeprecatedOptions() 66 function removeDeprecatedOptions()
67 { 67 {
68 var deprecatedOptions = ["specialCaseYouTube", "experimental", "disableInlineT extAds"]; 68 var deprecatedOptions = ["specialCaseYouTube", "experimental", "disableInlineT extAds"];
69 deprecatedOptions.forEach(function(option) 69 deprecatedOptions.forEach(function(option)
70 { 70 {
71 if (option in localStorage) 71 if (option in localStorage)
72 delete localStorage[option]; 72 delete localStorage[option];
73 }); 73 });
74 } 74 }
75 75
76 // Sets options to defaults, upgrading old options from previous versions as nec essary 76 // Remove deprecated options before we do anything else.
77 function setDefaultOptions() 77 removeDeprecatedOptions();
78 {
79 function defaultOptionValue(opt, val)
80 {
81 if(!(opt in localStorage))
82 localStorage[opt] = val;
83 }
84
85 defaultOptionValue("shouldShowBlockElementMenu", "true");
86
87 removeDeprecatedOptions();
88 }
89
90 // Upgrade options before we do anything else.
91 setDefaultOptions();
92 78
93 /** 79 /**
94 * Checks whether a page is whitelisted. 80 * Checks whether a page is whitelisted.
95 * @param {String} url 81 * @param {String} url
96 * @param {String} [parentUrl] URL of the parent frame 82 * @param {String} [parentUrl] URL of the parent frame
97 * @param {String} [type] content type to be checked, default is "DOCUMENT" 83 * @param {String} [type] content type to be checked, default is "DOCUMENT"
98 * @return {Filter} filter that matched the URL or null if not whitelisted 84 * @return {Filter} filter that matched the URL or null if not whitelisted
99 */ 85 */
100 function isWhitelisted(url, parentUrl, type) 86 function isWhitelisted(url, parentUrl, type)
101 { 87 {
(...skipping 24 matching lines...) Expand all
126 { 112 {
127 var excluded = isWhitelisted(tab.url); 113 var excluded = isWhitelisted(tab.url);
128 iconFilename = excluded ? "icons/abp-19-whitelisted.png" : "icons/abp-19.png "; 114 iconFilename = excluded ? "icons/abp-19-whitelisted.png" : "icons/abp-19.png ";
129 } 115 }
130 116
131 tab.browserAction.setIcon(iconFilename); 117 tab.browserAction.setIcon(iconFilename);
132 tab.browserAction.setTitle(ext.i18n.getMessage("name")); 118 tab.browserAction.setTitle(ext.i18n.getMessage("name"));
133 119
134 iconAnimation.registerTab(tab, iconFilename); 120 iconAnimation.registerTab(tab, iconFilename);
135 121
136 // Set context menu status according to whether current tab has whitelisted do main
137 if (excluded) 122 if (excluded)
138 chrome.contextMenus.removeAll(); 123 ext.contextMenus.hideMenuItems();
139 else 124 else
140 showContextMenu(); 125 ext.contextMenus.showMenuItems();
141 } 126 }
142 127
143 /** 128 /**
144 * Old versions for Opera stored patterns.ini in the localStorage object, this 129 * Old versions for Opera stored patterns.ini in the localStorage object, this
145 * will import it into FilterStorage properly. 130 * will import it into FilterStorage properly.
146 * @return {Boolean} true if data import is in progress 131 * @return {Boolean} true if data import is in progress
147 */ 132 */
148 function importOldData() 133 function importOldData()
149 { 134 {
150 if ("patterns.ini" in localStorage) 135 if ("patterns.ini" in localStorage)
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 233
249 notifyUser(); 234 notifyUser();
250 } 235 }
251 }, false); 236 }, false);
252 request.send(null); 237 request.send(null);
253 } 238 }
254 else 239 else
255 notifyUser(); 240 notifyUser();
256 } 241 }
257 242
258 // Set up context menu for user selection of elements to block 243 function setContextMenu()
259 function showContextMenu()
260 { 244 {
261 ext.contextMenus.removeAll(function() 245 if (Prefs.shouldShowBlockElementMenu)
262 { 246 {
263 if(typeof localStorage["shouldShowBlockElementMenu"] == "string" && localSto rage["shouldShowBlockElementMenu"] == "true") 247 // Register context menu item
248 ext.contextMenus.addMenuItem(ext.i18n.getMessage("block_element"), ["image", "video", "audio"], function(srcUrl, tab)
264 { 249 {
265 ext.contextMenus.create(ext.i18n.getMessage("block_element"), ["image", "v ideo", "audio"], function(srcUrl, tab) 250 if (srcUrl)
266 { 251 tab.sendMessage({type: "clickhide-new-filter", filter: srcUrl});
267 if(srcUrl) 252 });
268 tab.sendMessage({type: "clickhide-new-filter", filter: srcUrl}); 253 }
269 }); 254 else
270 } 255 ext.contextMenus.removeMenuItems();
271 });
272 } 256 }
273 257
258 Prefs.addListener(function(name)
259 {
260 if (name == "shouldShowBlockElementMenu")
261 setContextMenu();
262 });
263 setContextMenu();
264
274 /** 265 /**
275 * Opens options tab or focuses an existing one, within the last focused window . 266 * Opens options tab or focuses an existing one, within the last focused window .
276 * @param {Function} callback function to be called with the 267 * @param {Function} callback function to be called with the
277 Tab object of the options tab 268 Tab object of the options tab
278 */ 269 */
279 function openOptions(callback) 270 function openOptions(callback)
280 { 271 {
281 ext.windows.getLastFocused(function(win) 272 ext.windows.getLastFocused(function(win)
282 { 273 {
283 win.getAllTabs(function(tabs) 274 win.getAllTabs(function(tabs)
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 } 377 }
387 378
388 var requestHost = extractHostFromURL(msg.url); 379 var requestHost = extractHostFromURL(msg.url);
389 var documentHost = extractHostFromURL(msg.documentUrl); 380 var documentHost = extractHostFromURL(msg.documentUrl);
390 var thirdParty = isThirdParty(requestHost, documentHost); 381 var thirdParty = isThirdParty(requestHost, documentHost);
391 var filter = defaultMatcher.matchesAny(msg.url, msg.mediatype, documentHos t, thirdParty); 382 var filter = defaultMatcher.matchesAny(msg.url, msg.mediatype, documentHos t, thirdParty);
392 if (filter instanceof BlockingFilter) 383 if (filter instanceof BlockingFilter)
393 { 384 {
394 var collapse = filter.collapse; 385 var collapse = filter.collapse;
395 if (collapse == null) 386 if (collapse == null)
396 collapse = (localStorage.hidePlaceholders != "false"); 387 collapse = Prefs.hidePlaceholders;
397 sendResponse(collapse); 388 sendResponse(collapse);
398 } 389 }
399 else 390 else
400 sendResponse(false); 391 sendResponse(false);
401 break; 392 break;
402 case "get-domain-enabled-state": 393 case "get-domain-enabled-state":
403 // Returns whether this domain is in the exclusion list. 394 // Returns whether this domain is in the exclusion list.
404 // The browser action popup asks us this. 395 // The browser action popup asks us this.
405 if(sender.tab) 396 if(sender.tab)
406 { 397 {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 tab.sendMessage({type: "clickhide-deactivate"}); 445 tab.sendMessage({type: "clickhide-deactivate"});
455 refreshIconAndContextMenu(tab); 446 refreshIconAndContextMenu(tab);
456 }); 447 });
457 448
458 setTimeout(function() 449 setTimeout(function()
459 { 450 {
460 var notificationToShow = Notification.getNextToShow(); 451 var notificationToShow = Notification.getNextToShow();
461 if (notificationToShow) 452 if (notificationToShow)
462 showNotification(notificationToShow); 453 showNotification(notificationToShow);
463 }, 3 * 60 * 1000); 454 }, 3 * 60 * 1000);
OLDNEW
« no previous file with comments | « no previous file | block.js » ('j') | safari/background.js » ('J')

Powered by Google App Engine
This is Rietveld