| OLD | NEW | 
|---|
| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 298         if ("lastFocusedWindow" in info && info.lastFocusedWindow != (win == saf
     ari.application.activeBrowserWindow)) | 300         if ("lastFocusedWindow" in info && info.lastFocusedWindow != (win == saf
     ari.application.activeBrowserWindow)) | 
| 299           continue; | 301           continue; | 
| 300 | 302 | 
| 301         matchedPages.push(page); | 303         matchedPages.push(page); | 
| 302       }; | 304       }; | 
| 303 | 305 | 
| 304       callback(matchedPages); | 306       callback(matchedPages); | 
| 305     }, | 307     }, | 
| 306     onLoading: new ext._EventTarget(), | 308     onLoading: new ext._EventTarget(), | 
| 307     onActivated: new ext._EventTarget(), | 309     onActivated: new ext._EventTarget(), | 
|  | 310     onRemoved: new ext._EventTarget() | 
| 308   }; | 311   }; | 
| 309 | 312 | 
| 310   safari.application.addEventListener("close", function(event) | 313   safari.application.addEventListener("close", function(event) | 
| 311   { | 314   { | 
| 312     // this event is dispatched on closing windows and tabs. However when a | 315     // 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 | 316     // 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. | 317     // then on the window itself. But we are only interested in closed tabs. | 
| 315     if (!(event.target instanceof SafariBrowserTab)) | 318     if (!(event.target instanceof SafariBrowserTab)) | 
| 316       return; | 319       return; | 
| 317 | 320 | 
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 747       { | 750       { | 
| 748         tab.activate(); | 751         tab.activate(); | 
| 749         if (callback) | 752         if (callback) | 
| 750           callback(page); | 753           callback(page); | 
| 751         return; | 754         return; | 
| 752       } | 755       } | 
| 753     } | 756     } | 
| 754 | 757 | 
| 755     ext.pages.open(optionsUrl, callback); | 758     ext.pages.open(optionsUrl, callback); | 
| 756   }; | 759   }; | 
|  | 760 | 
|  | 761   /* Windows */ | 
|  | 762   ext.windows = { | 
|  | 763     // Safari doesn't provide as rich a windows API as Chrome does, so instead | 
|  | 764     // of chrome.windows.create we have to fall back to just opening a new tab. | 
|  | 765     create: function(createData, callback) | 
|  | 766     { | 
|  | 767       if (createData) | 
|  | 768         ext.pages.open(createData.url, callback); | 
|  | 769     } | 
|  | 770   }; | 
| 757 })(); | 771 })(); | 
| OLD | NEW | 
|---|