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

Side by Side Diff: background.js

Issue 29338764: Issue 3842 - Split up the logic updating the icon and context menu (Closed)
Patch Set: Rebased Created March 21, 2016, 10:07 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 | lib/filterComposer.js » ('j') | popup.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 <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 15 matching lines...) Expand all
26 this.checkWhitelisted = checkWhitelisted; 26 this.checkWhitelisted = checkWhitelisted;
27 this.getKey = getKey; 27 this.getKey = getKey;
28 } 28 }
29 with(require("url")) 29 with(require("url"))
30 { 30 {
31 this.stringifyURL = stringifyURL; 31 this.stringifyURL = stringifyURL;
32 this.isThirdParty = isThirdParty; 32 this.isThirdParty = isThirdParty;
33 this.extractHostFromFrame = extractHostFromFrame; 33 this.extractHostFromFrame = extractHostFromFrame;
34 } 34 }
35 var FilterStorage = require("filterStorage").FilterStorage; 35 var FilterStorage = require("filterStorage").FilterStorage;
36 var FilterNotifier = require("filterNotifier").FilterNotifier;
37 var SpecialSubscription = require("subscriptionClasses").SpecialSubscription; 36 var SpecialSubscription = require("subscriptionClasses").SpecialSubscription;
38 var ElemHide = require("elemHide").ElemHide; 37 var ElemHide = require("elemHide").ElemHide;
39 var defaultMatcher = require("matcher").defaultMatcher; 38 var defaultMatcher = require("matcher").defaultMatcher;
40 var Prefs = require("prefs").Prefs; 39 var Prefs = require("prefs").Prefs;
41 var updateIcon = require("icon").updateIcon;
42 var showNextNotificationForUrl = require("notificationHelper").showNextNotificat ionForUrl; 40 var showNextNotificationForUrl = require("notificationHelper").showNextNotificat ionForUrl;
43 var port = require("messaging").port; 41 var port = require("messaging").port;
44 var devtools = require("devtools"); 42 var devtools = require("devtools");
45 43
46 var htmlPages = new ext.PageMap();
47
48 var contextMenuItem = {
49 title: ext.i18n.getMessage("block_element"),
50 contexts: ["image", "video", "audio"],
51 onclick: function(page)
52 {
53 page.sendMessage({type: "composer.content.contextMenuClicked"});
54 }
55 };
56
57 // Adds or removes browser action icon according to options.
58 function refreshIconAndContextMenu(page)
59 {
60 var whitelisted = !!checkWhitelisted(page);
61 updateIcon(page, whitelisted);
62
63 // show or hide the context menu entry dependent on whether
64 // adblocking is active on that page
65 page.contextMenus.remove(contextMenuItem);
66 if (Prefs.shouldShowBlockElementMenu && !whitelisted && htmlPages.has(page))
67 page.contextMenus.create(contextMenuItem);
68 }
69
70 function refreshIconAndContextMenuForAllPages()
71 {
72 ext.pages.query({}, function(pages)
73 {
74 pages.forEach(refreshIconAndContextMenu);
75 });
76 }
77
78 FilterNotifier.addListener(function(action)
79 {
80 if (action == "load" || action == "save")
81 refreshIconAndContextMenuForAllPages();
82 });
83
84 Prefs.on("shouldShowBlockElementMenu", refreshIconAndContextMenuForAllPages);
85
86 // This is a hack to speedup loading of the options page on Safari. 44 // This is a hack to speedup loading of the options page on Safari.
87 // Once we replaced the background page proxy with message passing 45 // Once we replaced the background page proxy with message passing
88 // this global function should removed. 46 // this global function should removed.
89 function getUserFilters() 47 function getUserFilters()
90 { 48 {
91 var filters = []; 49 var filters = [];
92 var exceptions = []; 50 var exceptions = [];
93 51
94 for (var i = 0; i < FilterStorage.subscriptions.length; i++) 52 for (var i = 0; i < FilterStorage.subscriptions.length; i++)
95 { 53 {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 if (msg.expectsResponse) 142 if (msg.expectsResponse)
185 return new Promise(targetPage.sendMessage.bind(targetPage, msg.payload)); 143 return new Promise(targetPage.sendMessage.bind(targetPage, msg.payload));
186 targetPage.sendMessage(msg.payload); 144 targetPage.sendMessage(msg.payload);
187 } 145 }
188 }); 146 });
189 147
190 // update icon when page changes location 148 // update icon when page changes location
191 ext.pages.onLoading.addListener(function(page) 149 ext.pages.onLoading.addListener(function(page)
192 { 150 {
193 page.sendMessage({type: "composer.content.finished"}); 151 page.sendMessage({type: "composer.content.finished"});
194 refreshIconAndContextMenu(page);
195 showNextNotificationForUrl(page.url); 152 showNextNotificationForUrl(page.url);
196 }); 153 });
OLDNEW
« no previous file with comments | « no previous file | lib/filterComposer.js » ('j') | popup.js » ('J')

Powered by Google App Engine
This is Rietveld