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

Unified Diff: popupBlocker.js

Issue 9496013: Pop-up blocking functionality for Chrome (Closed)
Patch Set: Use webNavigation API rather than tabs API (see issue 13021) Created March 5, 2013, 12:14 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 | « metadata.chrome ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: popupBlocker.js
===================================================================
--- a/popupBlocker.js
+++ b/popupBlocker.js
@@ -12,55 +12,49 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
var tabsLoading = {};
-chrome.tabs.onCreated.addListener(function(tab)
+chrome.webNavigation.onCreatedNavigationTarget.addListener(function(details)
{
- if (!("openerTabId" in tab))
- {
- // This isn't a pop-up
- return;
- }
-
- if (isFrameWhitelisted(tab.openerTabId, 0))
+ if (isFrameWhitelisted(details.sourceTabId, details.sourceFrameId))
return;
- var openerUrl = getFrameUrl(tab.openerTabId, 0);
+ var openerUrl = getFrameUrl(details.sourceTabId, details.sourceFrameId);
if (!openerUrl)
{
// We don't know the opener tab
return;
}
- tabsLoading[tab.id] = openerUrl;
+ tabsLoading[details.tabId] = openerUrl;
- checkPotentialPopup(tab, openerUrl);
+ checkPotentialPopup(details.tabId, details.url, openerUrl);
});
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab)
{
if (!(tabId in tabsLoading))
{
// Not a pop-up we've previously seen
return;
}
if ("url" in changeInfo)
- checkPotentialPopup(tab, tabsLoading[tabId]);
+ checkPotentialPopup(tabId, tab.url, tabsLoading[tabId]);
if ("status" in changeInfo && changeInfo.status == "complete")
delete tabsLoading[tabId];
});
-function checkPotentialPopup(tab)
+function checkPotentialPopup(tabId, url, opener)
{
- var requestHost = extractHostFromURL(tab.url);
- var documentHost = extractHostFromURL(tabsLoading[tab.id]);
+ var requestHost = extractHostFromURL(url);
+ var documentHost = extractHostFromURL(opener);
var thirdParty = isThirdParty(requestHost, documentHost);
- var filter = defaultMatcher.matchesAny(tab.url || "about:blank", "POPUP", documentHost, thirdParty);
+ var filter = defaultMatcher.matchesAny(url || "about:blank", "POPUP", documentHost, thirdParty);
if (filter instanceof BlockingFilter)
- chrome.tabs.remove(tab.id);
+ chrome.tabs.remove(tabId);
}
« no previous file with comments | « metadata.chrome ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld