OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 { | 43 { |
44 var frame = frames[0]; | 44 var frame = frames[0]; |
45 if (frame) | 45 if (frame) |
46 return frame.url; | 46 return frame.url; |
47 } | 47 } |
48 }, | 48 }, |
49 activate: function() | 49 activate: function() |
50 { | 50 { |
51 chrome.tabs.update(this._id, {selected: true}); | 51 chrome.tabs.update(this._id, {selected: true}); |
52 }, | 52 }, |
| 53 close: function() |
| 54 { |
| 55 chrome.tabs.remove(this._id); |
| 56 }, |
53 sendMessage: function(message, responseCallback) | 57 sendMessage: function(message, responseCallback) |
54 { | 58 { |
55 chrome.tabs.sendMessage(this._id, message, responseCallback); | 59 chrome.tabs.sendMessage(this._id, message, responseCallback); |
56 } | 60 } |
57 }; | 61 }; |
58 | 62 |
59 ext.pages = { | 63 ext.pages = { |
60 open: function(url, callback) | 64 open: function(url, callback) |
61 { | 65 { |
62 if (callback) | 66 if (callback) |
(...skipping 28 matching lines...) Expand all Loading... |
91 } | 95 } |
92 | 96 |
93 chrome.tabs.query(rawInfo, function(tabs) | 97 chrome.tabs.query(rawInfo, function(tabs) |
94 { | 98 { |
95 callback(tabs.map(function(tab) | 99 callback(tabs.map(function(tab) |
96 { | 100 { |
97 return new Page(tab); | 101 return new Page(tab); |
98 })); | 102 })); |
99 }); | 103 }); |
100 }, | 104 }, |
101 onLoading: new ext._EventTarget() | 105 onLoading: new ext._EventTarget(), |
| 106 onPopup: new ext._EventTarget() |
102 }; | 107 }; |
103 | 108 |
| 109 var popups = {__proto__: null}; |
| 110 |
| 111 chrome.webNavigation.onCreatedNavigationTarget.addListener(function(details) |
| 112 { |
| 113 var frames = framesOfTabs[details.sourceTabId]; |
| 114 if (!frames) |
| 115 return; |
| 116 |
| 117 var openerFrame = frames[details.sourceFrameId]; |
| 118 if (!openerFrame) |
| 119 return; |
| 120 |
| 121 var page = new Page({id: details.tabId, url: details.url}); |
| 122 var opener = {page: new Page({id: details.sourceTabId}), frame: openerFrame}
; |
| 123 |
| 124 popups[details.tabId] = opener; |
| 125 ext.pages.onPopup._dispatch(page, opener); |
| 126 }); |
| 127 |
104 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) | 128 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) |
105 { | 129 { |
| 130 if (tabId in popups) |
| 131 { |
| 132 if ("url" in changeInfo) |
| 133 ext.pages.onPopup._dispatch(new Page(tab), popups[tabId]); |
| 134 |
| 135 if (changeInfo.status == "complete" && tab.url != "about:blank") |
| 136 delete popups[tabId]; |
| 137 } |
| 138 |
106 if (changeInfo.status == "loading") | 139 if (changeInfo.status == "loading") |
107 ext.pages.onLoading._dispatch(new Page(tab)); | 140 ext.pages.onLoading._dispatch(new Page(tab)); |
108 }); | 141 }); |
109 | 142 |
110 chrome.webNavigation.onBeforeNavigate.addListener(function(details) | 143 chrome.webNavigation.onBeforeNavigate.addListener(function(details) |
111 { | 144 { |
112 if (details.frameId == 0) | 145 if (details.frameId == 0) |
113 ext._removeFromAllPageMaps(details.tabId); | 146 ext._removeFromAllPageMaps(details.tabId); |
114 }); | 147 }); |
115 | 148 |
116 chrome.tabs.onRemoved.addListener(function(tabId) | 149 chrome.tabs.onRemoved.addListener(function(tabId) |
117 { | 150 { |
118 ext._removeFromAllPageMaps(tabId); | 151 ext._removeFromAllPageMaps(tabId); |
| 152 |
119 delete framesOfTabs[tabId]; | 153 delete framesOfTabs[tabId]; |
| 154 delete popups[tabId]; |
120 }); | 155 }); |
121 | 156 |
122 | 157 |
123 /* Browser actions */ | 158 /* Browser actions */ |
124 | 159 |
125 var BrowserAction = function(tabId) | 160 var BrowserAction = function(tabId) |
126 { | 161 { |
127 this._tabId = tabId; | 162 this._tabId = tabId; |
128 }; | 163 }; |
129 BrowserAction.prototype = { | 164 BrowserAction.prototype = { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 }; | 394 }; |
360 | 395 |
361 return ext.onMessage._dispatch(message, sender, sendResponse); | 396 return ext.onMessage._dispatch(message, sender, sendResponse); |
362 }); | 397 }); |
363 | 398 |
364 | 399 |
365 /* Storage */ | 400 /* Storage */ |
366 | 401 |
367 ext.storage = localStorage; | 402 ext.storage = localStorage; |
368 })(); | 403 })(); |
OLD | NEW |