| Left: | ||
| Right: | 
| LEFT | RIGHT | 
|---|---|
| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 | 42 | 
| 43 this.browserAction = new BrowserAction(this); | 43 this.browserAction = new BrowserAction(this); | 
| 44 }; | 44 }; | 
| 45 Page.prototype = { | 45 Page.prototype = { | 
| 46 get url() | 46 get url() | 
| 47 { | 47 { | 
| 48 return this._frames[0].url; | 48 return this._frames[0].url; | 
| 49 }, | 49 }, | 
| 50 activate: function() | 50 activate: function() | 
| 51 { | 51 { | 
| 52 pages[this._id]._tab.activate(); | 52 this._tab.activate(); | 
| 
 
Wladimir Palant
2014/04/11 13:02:35
Why not this._tab.activate()?
If it is because mu
 
Sebastian Noack
2014/04/11 14:47:45
Done. When I began to write this code there was no
 
 | |
| 53 }, | 53 }, | 
| 54 sendMessage: function(message, responseCallback) | 54 sendMessage: function(message, responseCallback) | 
| 55 { | 55 { | 
| 56 this._messageProxy.sendMessage(message, responseCallback, {pageId: this._i d}); | 56 this._messageProxy.sendMessage(message, responseCallback, {pageId: this._i d}); | 
| 57 } | 57 } | 
| 58 }; | 58 }; | 
| 59 | 59 | 
| 60 var isPageActive = function(page) | 60 var isPageActive = function(page) | 
| 61 { | 61 { | 
| 62 return page._tab == page._tab.browserWindow.activeTab && !page._prerendered; | 62 return page._tab == page._tab.browserWindow.activeTab && !page._prerendered; | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 | 105 | 
| 106 for (var id in pages) | 106 for (var id in pages) | 
| 107 { | 107 { | 
| 108 var page = pages[id]; | 108 var page = pages[id]; | 
| 109 var win = page._tab.browserWindow; | 109 var win = page._tab.browserWindow; | 
| 110 | 110 | 
| 111 if ("active" in info && info.active != isPageActive(page)) | 111 if ("active" in info && info.active != isPageActive(page)) | 
| 112 continue; | 112 continue; | 
| 113 if ("lastFocusedWindow" in info && info.lastFocusedWindow != (win == saf ari.application.activeBrowserWindow)) | 113 if ("lastFocusedWindow" in info && info.lastFocusedWindow != (win == saf ari.application.activeBrowserWindow)) | 
| 114 continue; | 114 continue; | 
| 115 if ("visibleWindow" in info && info.visibleWindow != win.visible) | |
| 116 continue; | |
| 117 | 115 | 
| 118 matchedPages.push(page); | 116 matchedPages.push(page); | 
| 119 }; | 117 }; | 
| 120 | 118 | 
| 121 callback(matchedPages); | 119 callback(matchedPages); | 
| 122 }, | 120 }, | 
| 123 onLoading: new ext._EventTarget() | 121 onLoading: new ext._EventTarget() | 
| 124 }; | 122 }; | 
| 125 | 123 | 
| 126 safari.application.addEventListener("close", function(event) | 124 safari.application.addEventListener("close", function(event) | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 } | 174 } | 
| 177 }; | 175 }; | 
| 178 | 176 | 
| 179 var BrowserAction = function(page) | 177 var BrowserAction = function(page) | 
| 180 { | 178 { | 
| 181 this._page = page; | 179 this._page = page; | 
| 182 }; | 180 }; | 
| 183 BrowserAction.prototype = { | 181 BrowserAction.prototype = { | 
| 184 _set: function(name, value) | 182 _set: function(name, value) | 
| 185 { | 183 { | 
| 186 var currentWindow = this._page._tab.browserWindow; | 184 var toolbarItem = getToolbarItemForWindow(this._page._tab.browserWindow); | 
| 187 var toolbarItem = getToolbarItemForWindow(currentWindow); | |
| 188 if (!toolbarItem) | 185 if (!toolbarItem) | 
| 189 return; | 186 return; | 
| 190 | 187 | 
| 191 var property = toolbarItemProperties[name]; | 188 var property = toolbarItemProperties[name]; | 
| 192 if (!property) | 189 if (!property) | 
| 193 property = toolbarItemProperties[name] = { | 190 property = toolbarItemProperties[name] = { | 
| 194 pages: new ext.PageMap(), | 191 pages: new ext.PageMap(), | 
| 195 global: toolbarItem[name] | 192 global: toolbarItem[name] | 
| 196 }; | 193 }; | 
| 197 | 194 | 
| 198 property.pages.set(this._page, value); | 195 property.pages.set(this._page, value); | 
| 199 | 196 | 
| 200 if (this._page._tab == currentWindow.activeTab && !this._page._prerendered ) | 197 if (isPageActive(this._page)) | 
| 
 
Wladimir Palant
2014/04/11 13:02:35
This should use isPageActive instead of duplicatin
 
Sebastian Noack
2014/04/11 14:47:45
Done.
 
 | |
| 201 toolbarItem[name] = value; | 198 toolbarItem[name] = value; | 
| 202 }, | 199 }, | 
| 203 setIcon: function(path) | 200 setIcon: function(path) | 
| 204 { | 201 { | 
| 205 this._set("image", safari.extension.baseURI + path.replace("$size", "16")) ; | 202 this._set("image", safari.extension.baseURI + path.replace("$size", "16")) ; | 
| 206 }, | 203 }, | 
| 207 setBadge: function(badge) | 204 setBadge: function(badge) | 
| 208 { | 205 { | 
| 209 if (!badge) | 206 if (!badge) | 
| 210 this._set("badge", 0); | 207 this._set("badge", 0); | 
| (...skipping 17 matching lines...) Expand all Loading... | |
| 228 for (var id in pages) | 225 for (var id in pages) | 
| 229 { | 226 { | 
| 230 var page = pages[id]; | 227 var page = pages[id]; | 
| 231 if (page._tab == event.target && !page._prerendered) | 228 if (page._tab == event.target && !page._prerendered) | 
| 232 { | 229 { | 
| 233 activePage = page; | 230 activePage = page; | 
| 234 break; | 231 break; | 
| 235 } | 232 } | 
| 236 } | 233 } | 
| 237 | 234 | 
| 238 updateToolbarItemForPage(activePage, event.target.browserWindow); | 235 updateToolbarItemForPage(activePage, event.target.browserWindow); | 
| 
 
Wladimir Palant
2014/04/11 13:02:35
Please add a check for activePage - it might poten
 
Sebastian Noack
2014/04/11 14:47:45
In that case we have to reset the toolbar item pro
 
 | |
| 239 }, true); | 236 }, true); | 
| 240 | 237 | 
| 241 | 238 | 
| 242 /* Web requests */ | 239 /* Web requests */ | 
| 243 | 240 | 
| 244 ext.webRequest = { | 241 ext.webRequest = { | 
| 245 onBeforeRequest: new ext._EventTarget(true), | 242 onBeforeRequest: new ext._EventTarget(true), | 
| 246 handlerBehaviorChanged: function() {} | 243 handlerBehaviorChanged: function() {} | 
| 247 }; | 244 }; | 
| 248 | 245 | 
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 return; | 388 return; | 
| 392 | 389 | 
| 393 page._tab.page.dispatchMessage("proxyCallback", | 390 page._tab.page.dispatchMessage("proxyCallback", | 
| 394 { | 391 { | 
| 395 pageId: pageId, | 392 pageId: pageId, | 
| 396 frameId: frameId, | 393 frameId: frameId, | 
| 397 callbackId: callbackId, | 394 callbackId: callbackId, | 
| 398 contextId: proxy.registerObject(this, objects), | 395 contextId: proxy.registerObject(this, objects), | 
| 399 args: proxy.serializeSequence(arguments, objects) | 396 args: proxy.serializeSequence(arguments, objects) | 
| 400 }); | 397 }); | 
| 401 }; | 398 }; | 
| 
 
Wladimir Palant
2014/04/11 13:02:35
Use .bind(this) instead of the proxy variable?
 
Sebastian Noack
2014/04/11 14:47:45
I can't, since I also need the actual context the
 
 | |
| 402 }, | 399 }, | 
| 403 deserialize: function(spec, objects, pageId, memo) | 400 deserialize: function(spec, objects, pageId, memo) | 
| 404 { | 401 { | 
| 405 switch (spec.type) | 402 switch (spec.type) | 
| 406 { | 403 { | 
| 407 case "value": | 404 case "value": | 
| 408 return spec.value; | 405 return spec.value; | 
| 409 case "hosted": | 406 case "hosted": | 
| 410 return objects[spec.objectId]; | 407 return objects[spec.objectId]; | 
| 411 case "callback": | 408 case "callback": | 
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 660 replacePage(page); | 657 replacePage(page); | 
| 661 break; | 658 break; | 
| 662 } | 659 } | 
| 663 }); | 660 }); | 
| 664 | 661 | 
| 665 | 662 | 
| 666 /* Storage */ | 663 /* Storage */ | 
| 667 | 664 | 
| 668 ext.storage = safari.extension.settings; | 665 ext.storage = safari.extension.settings; | 
| 669 })(); | 666 })(); | 
| LEFT | RIGHT |