LEFT | RIGHT |
(no file at all) | |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 }, true); | 172 }, true); |
173 | 173 |
174 | 174 |
175 /* Pages */ | 175 /* Pages */ |
176 | 176 |
177 var pages = Object.create(null); | 177 var pages = Object.create(null); |
178 var pageCounter = 0; | 178 var pageCounter = 0; |
179 | 179 |
180 var Page = function(id, tab, url) | 180 var Page = function(id, tab, url) |
181 { | 181 { |
182 this._id = id; | 182 this.id = id; |
183 this._tab = tab; | 183 this._tab = tab; |
184 this._frames = [{url: new URL(url), parent: null}]; | 184 this._frames = [{url: new URL(url), parent: null}]; |
185 | 185 |
186 if (tab.page) | 186 if (tab.page) |
187 this._messageProxy = new ext._MessageProxy(tab.page); | 187 this._messageProxy = new ext._MessageProxy(tab.page); |
188 else | 188 else |
189 // while the new tab page is shown on Safari 7, the 'page' property | 189 // while the new tab page is shown on Safari 7, the 'page' property |
190 // of the tab is undefined, and we can't send messages to that page | 190 // of the tab is undefined, and we can't send messages to that page |
191 this._messageProxy = { | 191 this._messageProxy = { |
192 handleRequest: function() {}, | 192 handleRequest: function() {}, |
193 handleResponse: function() {}, | 193 handleResponse: function() {}, |
194 sendMessage: function() {} | 194 sendMessage: function() {} |
195 }; | 195 }; |
196 | 196 |
197 this.browserAction = new BrowserAction(this); | 197 this.browserAction = new BrowserAction(this); |
198 this.contextMenus = new ContextMenus(this); | 198 this.contextMenus = new ContextMenus(this); |
199 }; | 199 }; |
200 Page.prototype = { | 200 Page.prototype = { |
201 get url() | 201 get url() |
202 { | 202 { |
203 return this._frames[0].url; | 203 return this._frames[0].url; |
204 }, | 204 }, |
205 sendMessage: function(message, responseCallback) | 205 sendMessage: function(message, responseCallback) |
206 { | 206 { |
207 this._messageProxy.sendMessage(message, responseCallback, {pageId: this._i
d}); | 207 this._messageProxy.sendMessage(message, responseCallback, {pageId: this.id
}); |
208 } | 208 } |
209 }; | 209 }; |
210 | 210 |
211 ext._getPage = function(id) | 211 ext.getPage = function(id) |
212 { | 212 { |
213 return pages[id]; | 213 return pages[id]; |
214 }; | 214 }; |
215 | 215 |
216 var isPageActive = function(page) | 216 var isPageActive = function(page) |
217 { | 217 { |
218 var tab = page._tab; | 218 var tab = page._tab; |
219 var win = tab.browserWindow; | 219 var win = tab.browserWindow; |
220 return win && tab == win.activeTab && page == tab._visiblePage; | 220 return win && tab == win.activeTab && page == tab._visiblePage; |
221 }; | 221 }; |
222 | 222 |
223 var forgetPage = function(id) | 223 var forgetPage = function(id) |
224 { | 224 { |
| 225 ext.pages.onRemoved._dispatch(id); |
| 226 |
225 ext._removeFromAllPageMaps(id); | 227 ext._removeFromAllPageMaps(id); |
226 | 228 |
227 delete pages[id]._tab._pages[id]; | 229 delete pages[id]._tab._pages[id]; |
228 delete pages[id]; | 230 delete pages[id]; |
229 }; | 231 }; |
230 | 232 |
231 var replacePage = function(page) | 233 var replacePage = function(page) |
232 { | 234 { |
233 var tab = page._tab; | 235 var tab = page._tab; |
234 tab._visiblePage = page; | 236 tab._visiblePage = page; |
235 | 237 |
236 for (var id in tab._pages) | 238 for (var id in tab._pages) |
237 { | 239 { |
238 if (id != page._id) | 240 if (id != page.id) |
239 forgetPage(id); | 241 forgetPage(id); |
240 } | 242 } |
241 | 243 |
242 if (isPageActive(page)) | 244 if (isPageActive(page)) |
243 updateToolbarItemForPage(page, tab.browserWindow); | 245 updateToolbarItemForPage(page, tab.browserWindow); |
244 }; | 246 }; |
245 | 247 |
246 var addPage = function(tab, url, prerendered) | 248 var addPage = function(tab, url, prerendered) |
247 { | 249 { |
248 var pageId = ++pageCounter; | 250 var pageId = ++pageCounter; |
(...skipping 17 matching lines...) Expand all Loading... |
266 }; | 268 }; |
267 | 269 |
268 ext.pages = { | 270 ext.pages = { |
269 open: function(url, callback) | 271 open: function(url, callback) |
270 { | 272 { |
271 var tab = safari.application.activeBrowserWindow.openTab(); | 273 var tab = safari.application.activeBrowserWindow.openTab(); |
272 tab.url = url; | 274 tab.url = url; |
273 | 275 |
274 if (callback) | 276 if (callback) |
275 { | 277 { |
276 var onLoading = function(page) | 278 var onNavigate = function(event) |
277 { | 279 { |
278 if (page._tab == tab) | 280 if (event.target == tab) |
279 { | 281 { |
280 ext.pages.onLoading.removeListener(onLoading); | 282 safari.application.removeEventListener(onNavigate); |
281 callback(page); | 283 callback(tab._visiblePage); |
282 } | 284 } |
283 }; | 285 }; |
284 ext.pages.onLoading.addListener(onLoading); | 286 |
| 287 safari.application.addEventListener("navigate", onNavigate); |
285 } | 288 } |
286 }, | 289 }, |
287 query: function(info, callback) | 290 query: function(info, callback) |
288 { | 291 { |
289 var matchedPages = []; | 292 var matchedPages = []; |
290 | 293 |
291 for (var id in pages) | 294 for (var id in pages) |
292 { | 295 { |
293 var page = pages[id]; | 296 var page = pages[id]; |
294 var win = page._tab.browserWindow; | 297 var win = page._tab.browserWindow; |
295 | 298 |
296 if ("active" in info && info.active != isPageActive(page)) | 299 if ("active" in info && info.active != isPageActive(page)) |
297 continue; | 300 continue; |
298 if ("lastFocusedWindow" in info && info.lastFocusedWindow != (win == saf
ari.application.activeBrowserWindow)) | 301 if ("lastFocusedWindow" in info && info.lastFocusedWindow != (win == saf
ari.application.activeBrowserWindow)) |
299 continue; | 302 continue; |
300 | 303 |
301 matchedPages.push(page); | 304 matchedPages.push(page); |
302 }; | 305 }; |
303 | 306 |
304 callback(matchedPages); | 307 callback(matchedPages); |
305 }, | 308 }, |
306 onLoading: new ext._EventTarget(), | 309 onLoading: new ext._EventTarget(), |
307 onActivated: new ext._EventTarget(), | 310 onActivated: new ext._EventTarget(), |
| 311 onRemoved: new ext._EventTarget() |
308 }; | 312 }; |
309 | 313 |
310 safari.application.addEventListener("close", function(event) | 314 safari.application.addEventListener("close", function(event) |
311 { | 315 { |
312 // this event is dispatched on closing windows and tabs. However when a | 316 // this event is dispatched on closing windows and tabs. However when a |
313 // window is closed, it is first dispatched on each tab in the window and | 317 // window is closed, it is first dispatched on each tab in the window and |
314 // then on the window itself. But we are only interested in closed tabs. | 318 // then on the window itself. But we are only interested in closed tabs. |
315 if (!(event.target instanceof SafariBrowserTab)) | 319 if (!(event.target instanceof SafariBrowserTab)) |
316 return; | 320 return; |
317 | 321 |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 { | 751 { |
748 tab.activate(); | 752 tab.activate(); |
749 if (callback) | 753 if (callback) |
750 callback(page); | 754 callback(page); |
751 return; | 755 return; |
752 } | 756 } |
753 } | 757 } |
754 | 758 |
755 ext.pages.open(optionsUrl, callback); | 759 ext.pages.open(optionsUrl, callback); |
756 }; | 760 }; |
| 761 |
| 762 /* Windows */ |
| 763 ext.windows = { |
| 764 // Safari doesn't provide as rich a windows API as Chrome does, so instead |
| 765 // of chrome.windows.create we have to fall back to just opening a new tab. |
| 766 create: function(createData, callback) |
| 767 { |
| 768 ext.pages.open(createData.url, callback); |
| 769 } |
| 770 }; |
757 })(); | 771 })(); |
LEFT | RIGHT |