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

Unified 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, 10:54 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: popup.js
===================================================================
--- a/popup.js
+++ b/popup.js
@@ -16,14 +16,13 @@
*/
var backgroundPage = ext.backgroundPage.getWindow();
-var imports = ["require", "extractHostFromURL"];
-for (var i = 0; i < imports.length; i++)
- window[imports[i]] = backgroundPage[imports[i]];
+var require = backgroundPage.require;
var Filter = require("filterClasses").Filter;
var FilterStorage = require("filterStorage").FilterStorage;
var Prefs = require("prefs").Prefs;
-var isWhitelisted = require("whitelisting").isWhitelisted;
+var isPageWhitelisted = require("whitelisting").isPageWhitelisted;
+var getDecodedHostname = require("url").getDecodedHostname;
var page = null;
@@ -34,7 +33,8 @@
page = pages[0];
// Mark page as 'local' or 'nohtml' to hide non-relevant elements
- if (!page || !/^https?:\/\//.test(page.url))
+ if (!page || (page.url.protocol != "http:" &&
+ page.url.protocol != "https:"))
document.body.classList.add("local");
else if (!backgroundPage.htmlPages.has(page))
document.body.classList.add("nohtml");
@@ -45,7 +45,7 @@
// Otherwise, we are in default state.
if (page)
{
- if (isWhitelisted(page.url))
+ if (isPageWhitelisted(page))
document.getElementById("enabled").classList.add("off");
page.sendMessage({type: "get-clickhide-state"}, function(response)
@@ -83,7 +83,7 @@
var disabled = enabledButton.classList.toggle("off");
if (disabled)
{
- var host = extractHostFromURL(page.url).replace(/^www\./, "");
+ var host = getDecodedHostname(page.url).replace(/^www\./, "");
var filter = Filter.fromText("@@||" + host + "^$document");
if (filter.subscriptions.length && filter.disabled)
filter.disabled = false;
@@ -96,13 +96,13 @@
else
{
// Remove any exception rules applying to this URL
- var filter = isWhitelisted(page.url);
+ var filter = isPageWhitelisted(page);
while (filter)
{
FilterStorage.removeFilter(filter);
if (filter.subscriptions.length)
filter.disabled = true;
- filter = isWhitelisted(page.url);
+ filter = isPageWhitelisted(page);
}
}
}

Powered by Google App Engine
This is Rietveld