| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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); | 225 ext.pages.onRemoved._dispatch(id); |
| 226 | 226 |
| 227 ext._removeFromAllPageMaps(id); | 227 ext._removeFromAllPageMaps(id); |
| 228 | 228 |
| 229 delete pages[id]._tab._pages[id]; | 229 delete pages[id]._tab._pages[id]; |
| 230 delete pages[id]; | 230 delete pages[id]; |
| 231 }; | 231 }; |
| 232 | 232 |
| 233 var replacePage = function(page) | 233 var replacePage = function(page) |
| 234 { | 234 { |
| 235 var tab = page._tab; | 235 var tab = page._tab; |
| 236 tab._visiblePage = page; | 236 tab._visiblePage = page; |
| 237 | 237 |
| 238 for (var id in tab._pages) | 238 for (var id in tab._pages) |
| 239 { | 239 { |
| 240 if (id != page._id) | 240 if (id != page.id) |
| 241 forgetPage(id); | 241 forgetPage(id); |
| 242 } | 242 } |
| 243 | 243 |
| 244 if (isPageActive(page)) | 244 if (isPageActive(page)) |
| 245 updateToolbarItemForPage(page, tab.browserWindow); | 245 updateToolbarItemForPage(page, tab.browserWindow); |
| 246 }; | 246 }; |
| 247 | 247 |
| 248 var addPage = function(tab, url, prerendered) | 248 var addPage = function(tab, url, prerendered) |
| 249 { | 249 { |
| 250 var pageId = ++pageCounter; | 250 var pageId = ++pageCounter; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 268 }; | 268 }; |
| 269 | 269 |
| 270 ext.pages = { | 270 ext.pages = { |
| 271 open: function(url, callback) | 271 open: function(url, callback) |
| 272 { | 272 { |
| 273 var tab = safari.application.activeBrowserWindow.openTab(); | 273 var tab = safari.application.activeBrowserWindow.openTab(); |
| 274 tab.url = url; | 274 tab.url = url; |
| 275 | 275 |
| 276 if (callback) | 276 if (callback) |
| 277 { | 277 { |
| 278 var onLoading = function(page) | 278 var onNavigate = function(event) |
| 279 { | 279 { |
| 280 if (page._tab == tab) | 280 if (event.target == tab) |
| 281 { | 281 { |
| 282 ext.pages.onLoading.removeListener(onLoading); | 282 safari.application.removeEventListener(onNavigate); |
| 283 callback(page); | 283 callback(tab._visiblePage); |
| 284 } | 284 } |
| 285 }; | 285 }; |
| 286 ext.pages.onLoading.addListener(onLoading); | 286 |
| 287 safari.application.addEventListener("navigate", onNavigate); | |
| 287 } | 288 } |
| 288 }, | 289 }, |
| 289 query: function(info, callback) | 290 query: function(info, callback) |
| 290 { | 291 { |
| 291 var matchedPages = []; | 292 var matchedPages = []; |
| 292 | 293 |
| 293 for (var id in pages) | 294 for (var id in pages) |
| 294 { | 295 { |
| 295 var page = pages[id]; | 296 var page = pages[id]; |
| 296 var win = page._tab.browserWindow; | 297 var win = page._tab.browserWindow; |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 757 | 758 |
| 758 ext.pages.open(optionsUrl, callback); | 759 ext.pages.open(optionsUrl, callback); |
| 759 }; | 760 }; |
| 760 | 761 |
| 761 /* Windows */ | 762 /* Windows */ |
| 762 ext.windows = { | 763 ext.windows = { |
| 763 // Safari doesn't provide as rich a windows API as Chrome does, so instead | 764 // 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 // of chrome.windows.create we have to fall back to just opening a new tab. |
| 765 create: function(createData, callback) | 766 create: function(createData, callback) |
| 766 { | 767 { |
| 767 if (createData && createData.url) | 768 ext.pages.open(createData.url, callback); |
|
Sebastian Noack
2016/02/10 12:26:57
Just assume the URL to be given? If it's missing,
kzar
2016/02/10 14:20:17
Done.
| |
| 768 ext.pages.open(createData.url, callback); | |
| 769 } | 769 } |
| 770 }; | 770 }; |
| 771 })(); | 771 })(); |
| LEFT | RIGHT |