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

Unified Diff: background.js

Issue 5464830253203456: Refactored the abstraction layer to address prerendered pages on Safari caused by leaky abstraction (Closed)
Patch Set: Created Feb. 22, 2014, 10:45 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
« no previous file with comments | « no previous file | chrome/ext/background.js » ('j') | chrome/ext/background.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: background.js
===================================================================
--- a/background.js
+++ b/background.js
@@ -85,27 +85,27 @@
var activeNotification = null;
// Adds or removes browser action icon according to options.
-function refreshIconAndContextMenu(tab)
+function refreshIconAndContextMenu(page)
{
- if(!/^https?:/.test(tab.url))
+ if(!/^https?:/.test(page.url))
return;
var iconFilename;
if (require("info").platform == "safari")
- // There is no grayscale version of the icon for whitelisted tabs
+ // There is no grayscale version of the icon for whitelisted pages
// when using Safari, because icons are grayscale already and icons
- // aren't per tab in Safari.
+ // aren't per page in Safari.
iconFilename = "icons/abp-16.png"
else
{
- var excluded = isWhitelisted(tab.url);
+ var excluded = isWhitelisted(page.url);
iconFilename = excluded ? "icons/abp-19-whitelisted.png" : "icons/abp-19.png";
}
- tab.browserAction.setIcon(iconFilename);
- iconAnimation.registerTab(tab, iconFilename);
+ page.browserAction.setIcon(iconFilename);
+ iconAnimation.registerPage(page, iconFilename);
- // Set context menu status according to whether current tab has whitelisted domain
+ // Set context menu status according to whether the page has a whitelisted domain
if (excluded)
ext.contextMenus.hideMenuItems();
else
@@ -194,10 +194,7 @@
function notifyUser()
{
- ext.windows.getLastFocused(function(win)
- {
- win.openTab(ext.getURL("firstRun.html"));
- });
+ ext.pages.open(ext.getURL("firstRun.html"));
}
if (addSubscription)
@@ -232,10 +229,10 @@
if (Prefs.shouldShowBlockElementMenu)
{
// Register context menu item
- ext.contextMenus.addMenuItem(ext.i18n.getMessage("block_element"), ["image", "video", "audio"], function(srcUrl, tab)
+ ext.contextMenus.addMenuItem(ext.i18n.getMessage("block_element"), ["image", "video", "audio"], function(srcUrl, page)
{
if (srcUrl)
- tab.sendMessage({type: "clickhide-new-filter", filter: srcUrl});
+ page.sendMessage({type: "clickhide-new-filter", filter: srcUrl});
});
}
else
@@ -250,34 +247,29 @@
setContextMenu();
/**
- * Opens options tab or focuses an existing one, within the last focused window.
+ * Opens options page or focuses an existing one, within the last focused window.
* @param {Function} callback function to be called with the
- Tab object of the options tab
+ Page object of the options page
*/
function openOptions(callback)
{
- ext.windows.getLastFocused(function(win)
+ ext.pages.query({lastFocusedWindow: true}, function(pages)
Wladimir Palant 2014/04/04 14:00:35 The compat info for Chrome needs to be changed - l
Sebastian Noack 2014/04/07 13:15:25 Done.
{
- win.getAllTabs(function(tabs)
+ var optionsUrl = ext.getURL("options.html");
+
+ for (var i = 0; i < pages.length; i++)
{
- var optionsUrl = ext.getURL("options.html");
+ var page = pages[i];
+ if (page.url == optionsUrl)
+ {
+ page.activate();
+ if (callback)
+ callback(page);
+ return;
+ }
+ }
- for (var i = 0; i < tabs.length; i++)
- {
- if (tabs[i].url == optionsUrl)
- {
- tabs[i].activate();
- if (callback)
- callback(tabs[i]);
- return;
- }
- }
-
- win.openTab(optionsUrl, callback && function(tab)
- {
- tab.onCompleted.addListener(callback);
- });
- });
+ ext.pages.open(optionsUrl, callback);
Wladimir Palant 2014/04/04 14:00:35 Won't this break abp: links? The add-subscription
Sebastian Noack 2014/04/07 13:15:25 It was wishful thinking, that the callback passed
});
}
@@ -314,8 +306,8 @@
case "get-selectors":
var selectors = null;
- if (!isFrameWhitelisted(sender.tab, sender.frame, "DOCUMENT") &&
- !isFrameWhitelisted(sender.tab, sender.frame, "ELEMHIDE"))
+ if (!isFrameWhitelisted(sender.page, sender.frame, "DOCUMENT") &&
+ !isFrameWhitelisted(sender.page, sender.frame, "ELEMHIDE"))
{
var noStyleRules = false;
var host = extractHostFromURL(sender.frame.url);
@@ -341,7 +333,7 @@
sendResponse(selectors);
break;
case "should-collapse":
- if (isFrameWhitelisted(sender.tab, sender.frame, "DOCUMENT"))
+ if (isFrameWhitelisted(sender.page, sender.frame, "DOCUMENT"))
{
sendResponse(false);
break;
@@ -364,9 +356,9 @@
case "get-domain-enabled-state":
// Returns whether this domain is in the exclusion list.
// The browser action popup asks us this.
- if(sender.tab)
+ if(sender.page)
{
- sendResponse({enabled: !isWhitelisted(sender.tab.url)});
+ sendResponse({enabled: !isWhitelisted(sender.page.url)});
return;
}
break;
@@ -378,18 +370,18 @@
}
break;
case "add-subscription":
- openOptions(function(tab)
+ openOptions(function(page)
{
- tab.sendMessage(msg);
+ page.sendMessage(msg);
});
break;
case "add-key-exception":
- processKeyException(msg.token, sender.tab, sender.frame);
+ processKeyException(msg.token, sender.page, sender.frame);
break;
case "forward":
- if (sender.tab)
+ if (sender.page)
{
- sender.tab.sendMessage(msg.payload, sendResponse);
+ sender.page.sendMessage(msg.payload, sendResponse);
// Return true to indicate that we want to call
// sendResponse asynchronously
return true;
@@ -401,23 +393,17 @@
}
});
-// Show icon as browser action for all tabs that already exist
-ext.windows.getAll(function(windows)
+// Show icon as browser action for all pages that already exist
+ext.pages.query({}, function(pages)
{
- for (var i = 0; i < windows.length; i++)
- {
- windows[i].getAllTabs(function(tabs)
- {
- tabs.forEach(refreshIconAndContextMenu);
- });
- }
+ pages.forEach(refreshIconAndContextMenu);
});
-// Update icon if a tab changes location
-ext.tabs.onLoading.addListener(function(tab)
+// Update icon for new loaded pages
+ext.pages.onLoading.addListener(function(page)
{
- tab.sendMessage({type: "clickhide-deactivate"});
- refreshIconAndContextMenu(tab);
+ page.sendMessage({type: "clickhide-deactivate"});
+ refreshIconAndContextMenu(page);
});
setTimeout(function()
« no previous file with comments | « no previous file | chrome/ext/background.js » ('j') | chrome/ext/background.js » ('J')

Powered by Google App Engine
This is Rietveld