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

Side by Side Diff: popup.js

Issue 5564089086509056: Issue 1801 - Use URL objects to process URLs in the background page (Closed)
Patch Set: Rebased and addressed comments Created Feb. 11, 2015, 5:06 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 | « metadata.common ('k') | popupBlocker.js » ('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 <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 var backgroundPage = ext.backgroundPage.getWindow(); 18 var backgroundPage = ext.backgroundPage.getWindow();
19 var imports = ["require", "extractHostFromURL"]; 19 var require = backgroundPage.require;
20 for (var i = 0; i < imports.length; i++)
21 window[imports[i]] = backgroundPage[imports[i]];
22 20
23 var Filter = require("filterClasses").Filter; 21 var Filter = require("filterClasses").Filter;
24 var FilterStorage = require("filterStorage").FilterStorage; 22 var FilterStorage = require("filterStorage").FilterStorage;
25 var Prefs = require("prefs").Prefs; 23 var Prefs = require("prefs").Prefs;
26 var isWhitelisted = require("whitelisting").isWhitelisted; 24 var isPageWhitelisted = require("whitelisting").isPageWhitelisted;
25 var getDecodedHostname = require("url").getDecodedHostname;
27 26
28 var page = null; 27 var page = null;
29 28
30 function init() 29 function init()
31 { 30 {
32 ext.pages.query({active: true, lastFocusedWindow: true}, function(pages) 31 ext.pages.query({active: true, lastFocusedWindow: true}, function(pages)
33 { 32 {
34 page = pages[0]; 33 page = pages[0];
35 34
36 // Mark page as 'local' or 'nohtml' to hide non-relevant elements 35 // Mark page as 'local' or 'nohtml' to hide non-relevant elements
37 if (!page || !/^https?:\/\//.test(page.url)) 36 if (!page || (page.url.protocol != "http:" &&
37 page.url.protocol != "https:"))
38 document.body.classList.add("local"); 38 document.body.classList.add("local");
39 else if (!backgroundPage.htmlPages.has(page)) 39 else if (!backgroundPage.htmlPages.has(page))
40 document.body.classList.add("nohtml"); 40 document.body.classList.add("nohtml");
41 41
42 // Ask content script whether clickhide is active. If so, show cancel button . 42 // Ask content script whether clickhide is active. If so, show cancel button .
43 // If that isn't the case, ask background.html whether it has cached filters . If so, 43 // If that isn't the case, ask background.html whether it has cached filters . If so,
44 // ask the user whether she wants those filters. 44 // ask the user whether she wants those filters.
45 // Otherwise, we are in default state. 45 // Otherwise, we are in default state.
46 if (page) 46 if (page)
47 { 47 {
48 if (isWhitelisted(page.url)) 48 if (isPageWhitelisted(page))
49 document.getElementById("enabled").classList.add("off"); 49 document.getElementById("enabled").classList.add("off");
50 50
51 page.sendMessage({type: "get-clickhide-state"}, function(response) 51 page.sendMessage({type: "get-clickhide-state"}, function(response)
52 { 52 {
53 if (response && response.active) 53 if (response && response.active)
54 document.body.classList.add("clickhide-active"); 54 document.body.classList.add("clickhide-active");
55 }); 55 });
56 } 56 }
57 }); 57 });
58 58
(...skipping 17 matching lines...) Expand all
76 } 76 }
77 } 77 }
78 window.addEventListener("DOMContentLoaded", init, false); 78 window.addEventListener("DOMContentLoaded", init, false);
79 79
80 function toggleEnabled() 80 function toggleEnabled()
81 { 81 {
82 var enabledButton = document.getElementById("enabled") 82 var enabledButton = document.getElementById("enabled")
83 var disabled = enabledButton.classList.toggle("off"); 83 var disabled = enabledButton.classList.toggle("off");
84 if (disabled) 84 if (disabled)
85 { 85 {
86 var host = extractHostFromURL(page.url).replace(/^www\./, ""); 86 var host = getDecodedHostname(page.url).replace(/^www\./, "");
87 var filter = Filter.fromText("@@||" + host + "^$document"); 87 var filter = Filter.fromText("@@||" + host + "^$document");
88 if (filter.subscriptions.length && filter.disabled) 88 if (filter.subscriptions.length && filter.disabled)
89 filter.disabled = false; 89 filter.disabled = false;
90 else 90 else
91 { 91 {
92 filter.disabled = false; 92 filter.disabled = false;
93 FilterStorage.addFilter(filter); 93 FilterStorage.addFilter(filter);
94 } 94 }
95 } 95 }
96 else 96 else
97 { 97 {
98 // Remove any exception rules applying to this URL 98 // Remove any exception rules applying to this URL
99 var filter = isWhitelisted(page.url); 99 var filter = isPageWhitelisted(page);
100 while (filter) 100 while (filter)
101 { 101 {
102 FilterStorage.removeFilter(filter); 102 FilterStorage.removeFilter(filter);
103 if (filter.subscriptions.length) 103 if (filter.subscriptions.length)
104 filter.disabled = true; 104 filter.disabled = true;
105 filter = isWhitelisted(page.url); 105 filter = isPageWhitelisted(page);
106 } 106 }
107 } 107 }
108 } 108 }
109 109
110 function activateClickHide() 110 function activateClickHide()
111 { 111 {
112 document.body.classList.add("clickhide-active"); 112 document.body.classList.add("clickhide-active");
113 page.sendMessage({type: "clickhide-activate"}); 113 page.sendMessage({type: "clickhide-activate"});
114 114
115 // Close the popup after a few seconds, so user doesn't have to 115 // Close the popup after a few seconds, so user doesn't have to
(...skipping 10 matching lines...) Expand all
126 document.body.classList.remove("clickhide-active"); 126 document.body.classList.remove("clickhide-active");
127 page.sendMessage({type: "clickhide-deactivate"}); 127 page.sendMessage({type: "clickhide-deactivate"});
128 } 128 }
129 129
130 function toggleCollapse(event) 130 function toggleCollapse(event)
131 { 131 {
132 var collapser = event.currentTarget; 132 var collapser = event.currentTarget;
133 Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option]; 133 Prefs[collapser.dataset.option] = !Prefs[collapser.dataset.option];
134 collapser.parentNode.classList.toggle("collapsed"); 134 collapser.parentNode.classList.toggle("collapsed");
135 } 135 }
OLDNEW
« no previous file with comments | « metadata.common ('k') | popupBlocker.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld