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: Created March 19, 2016, 8:33 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') | lib/filterComposer.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 // Special-case domains for which we cannot use style-based hiding rules. 44 // Special-case domains for which we cannot use style-based hiding rules.
47 // See http://crbug.com/68705. 45 // See http://crbug.com/68705.
48 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; 46 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"];
49 47
50 var htmlPages = new ext.PageMap();
51
52 var contextMenuItem = {
53 title: ext.i18n.getMessage("block_element"),
54 contexts: ["image", "video", "audio"],
55 onclick: function(page)
56 {
57 page.sendMessage({type: "composer.content.contextMenuClicked"});
58 }
59 };
60
61 // Adds or removes browser action icon according to options.
62 function refreshIconAndContextMenu(page)
63 {
64 var whitelisted = !!checkWhitelisted(page);
65 updateIcon(page, whitelisted);
66
67 // show or hide the context menu entry dependent on whether
68 // adblocking is active on that page
69 page.contextMenus.remove(contextMenuItem);
70 if (Prefs.shouldShowBlockElementMenu && !whitelisted && htmlPages.has(page))
71 page.contextMenus.create(contextMenuItem);
72 }
73
74 function refreshIconAndContextMenuForAllPages()
75 {
76 ext.pages.query({}, function(pages)
77 {
78 pages.forEach(refreshIconAndContextMenu);
79 });
80 }
81
82 FilterNotifier.addListener(function(action)
83 {
84 if (action == "load" || action == "save")
85 refreshIconAndContextMenuForAllPages();
86 });
87
88 Prefs.on("shouldShowBlockElementMenu", refreshIconAndContextMenuForAllPages);
89
90 // This is a hack to speedup loading of the options page on Safari. 48 // This is a hack to speedup loading of the options page on Safari.
91 // Once we replaced the background page proxy with message passing 49 // Once we replaced the background page proxy with message passing
92 // this global function should removed. 50 // this global function should removed.
93 function getUserFilters() 51 function getUserFilters()
94 { 52 {
95 var filters = []; 53 var filters = [];
96 var exceptions = []; 54 var exceptions = [];
97 55
98 for (var i = 0; i < FilterStorage.subscriptions.length; i++) 56 for (var i = 0; i < FilterStorage.subscriptions.length; i++)
99 { 57 {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 if (msg.expectsResponse) 163 if (msg.expectsResponse)
206 return new Promise(targetPage.sendMessage.bind(targetPage, msg.payload)); 164 return new Promise(targetPage.sendMessage.bind(targetPage, msg.payload));
207 targetPage.sendMessage(msg.payload); 165 targetPage.sendMessage(msg.payload);
208 } 166 }
209 }); 167 });
210 168
211 // update icon when page changes location 169 // update icon when page changes location
212 ext.pages.onLoading.addListener(function(page) 170 ext.pages.onLoading.addListener(function(page)
213 { 171 {
214 page.sendMessage({type: "composer.content.finished"}); 172 page.sendMessage({type: "composer.content.finished"});
215 refreshIconAndContextMenu(page);
216 showNextNotificationForUrl(page.url); 173 showNextNotificationForUrl(page.url);
217 }); 174 });
OLDNEW
« no previous file with comments | « no previous file | lib/filterComposer.js » ('j') | lib/filterComposer.js » ('J')

Powered by Google App Engine
This is Rietveld