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

Unified Diff: popup.js

Issue 5464830253203456: Refactored the abstraction layer to address prerendered pages on Safari caused by leaky abstraction (Closed)
Patch Set: Addressed comments Created April 11, 2014, 2:47 p.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
« no previous file with comments | « notification.js ('k') | popupBlocker.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: popup.js
===================================================================
--- a/popup.js
+++ b/popup.js
@@ -25,18 +25,33 @@
var Prefs = require("prefs").Prefs;
var isWhitelisted = require("whitelisting").isWhitelisted;
-var tab = null;
+var page = null;
function init()
{
- // Mark page as local to hide non-relevant elements
- ext.windows.getLastFocused(function(win)
+ ext.pages.query({active: true, lastFocusedWindow: true}, function(pages)
{
- win.getActiveTab(function(tab)
+ page = pages[0];
+
+ // Mark page as local to hide non-relevant elements
+ if (!page || !/^https?:\/\//.test(page.url))
+ document.body.classList.add("local");
+
+ // Ask content script whether clickhide is active. If so, show cancel button.
+ // If that isn't the case, ask background.html whether it has cached filters. If so,
+ // ask the user whether she wants those filters.
+ // Otherwise, we are in default state.
+ if (page)
{
- if (!/^https?:\/\//.exec(tab.url))
- document.body.classList.add("local");
- });
+ if (isWhitelisted(page.url))
+ document.getElementById("enabled").classList.add("off");
+
+ page.sendMessage({type: "get-clickhide-state"}, function(response)
+ {
+ if (response && response.active)
+ document.body.classList.add("clickhide-active");
+ });
+ }
});
// Attach event listeners
@@ -57,26 +72,6 @@
if (!Prefs[collapser.dataset.option])
document.getElementById(collapser.dataset.collapsable).classList.add("collapsed");
}
-
- // Ask content script whether clickhide is active. If so, show cancel button.
- // If that isn't the case, ask background.html whether it has cached filters. If so,
- // ask the user whether she wants those filters.
- // Otherwise, we are in default state.
- ext.windows.getLastFocused(function(win)
- {
- win.getActiveTab(function(t)
- {
- tab = t;
- if (isWhitelisted(tab.url))
- document.getElementById("enabled").classList.add("off");
-
- tab.sendMessage({type: "get-clickhide-state"}, function(response)
- {
- if (response && response.active)
- document.body.classList.add("clickhide-active");
- });
- });
- });
}
window.addEventListener("DOMContentLoaded", init, false);
@@ -86,7 +81,7 @@
var disabled = enabledButton.classList.toggle("off");
if (disabled)
{
- var host = extractHostFromURL(tab.url).replace(/^www\./, "");
+ var host = extractHostFromURL(page.url).replace(/^www\./, "");
var filter = Filter.fromText("@@||" + host + "^$document");
if (filter.subscriptions.length && filter.disabled)
filter.disabled = false;
@@ -99,13 +94,13 @@
else
{
// Remove any exception rules applying to this URL
- var filter = isWhitelisted(tab.url);
+ var filter = isWhitelisted(page.url);
while (filter)
{
FilterStorage.removeFilter(filter);
if (filter.subscriptions.length)
filter.disabled = true;
- filter = isWhitelisted(tab.url);
+ filter = isWhitelisted(page.url);
}
}
}
@@ -113,7 +108,7 @@
function activateClickHide()
{
document.body.classList.add("clickhide-active");
- tab.sendMessage({type: "clickhide-activate"});
+ page.sendMessage({type: "clickhide-activate"});
// Close the popup after a few seconds, so user doesn't have to
activateClickHide.timeout = window.setTimeout(ext.closePopup, 5000);
@@ -127,7 +122,7 @@
activateClickHide.timeout = null;
}
document.body.classList.remove("clickhide-active");
- tab.sendMessage({type: "clickhide-deactivate"});
+ page.sendMessage({type: "clickhide-deactivate"});
}
function toggleCollapse(event)
« no previous file with comments | « notification.js ('k') | popupBlocker.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld