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

Unified Diff: chrome/ext/background.js

Issue 5203459900964864: Issue 492 - Implemented popup blocking for Safari (Closed)
Patch Set: Created May 16, 2014, 9:46 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 | popupBlocker.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/ext/background.js
===================================================================
--- a/chrome/ext/background.js
+++ b/chrome/ext/background.js
@@ -50,6 +50,10 @@
{
chrome.tabs.update(this._id, {selected: true});
},
+ close: function()
+ {
+ chrome.tabs.remove(this._id);
+ },
sendMessage: function(message, responseCallback)
{
chrome.tabs.sendMessage(this._id, message, responseCallback);
@@ -98,11 +102,40 @@
}));
});
},
- onLoading: new ext._EventTarget()
+ onLoading: new ext._EventTarget(),
+ onPopup: new ext._EventTarget()
};
+ var popups = {__proto__: null};
+
+ chrome.webNavigation.onCreatedNavigationTarget.addListener(function(details)
+ {
+ var frames = framesOfTabs[details.sourceTabId];
+ if (!frames)
+ return;
+
+ var openerFrame = frames[details.sourceFrameId];
+ if (!openerFrame)
+ return;
+
+ var page = new Page({id: details.tabId, url: details.url});
+ var opener = {page: new Page({id: details.sourceTabId}), frame: openerFrame};
+
+ popups[details.tabId] = opener;
+ ext.pages.onPopup._dispatch(page, opener);
+ });
+
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab)
{
+ if (tabId in popups)
+ {
+ if ("url" in changeInfo)
+ ext.pages.onPopup._dispatch(new Page(tab), popups[tabId]);
+
+ if (changeInfo.status == "complete" && tab.url != "about:blank")
+ delete popups[tabId];
+ }
+
if (changeInfo.status == "loading")
ext.pages.onLoading._dispatch(new Page(tab));
});
@@ -116,7 +149,9 @@
chrome.tabs.onRemoved.addListener(function(tabId)
{
ext._removeFromAllPageMaps(tabId);
+
delete framesOfTabs[tabId];
+ delete popups[tabId];
});
« no previous file with comments | « no previous file | popupBlocker.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld