| 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]; |
| }); |