| Left: | ||
| Right: |
| 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-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 } | 74 } |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 | 77 |
| 78 /* Tabs */ | 78 /* Tabs */ |
| 79 | 79 |
| 80 Tab = function(tab) | 80 Tab = function(tab) |
| 81 { | 81 { |
| 82 this._tab = tab; | 82 this._tab = tab; |
| 83 | 83 |
| 84 this.browserAction = new BrowserAction(this); | |
| 85 | |
| 84 this.onLoading = new LoadingTabEventTarget(tab); | 86 this.onLoading = new LoadingTabEventTarget(tab); |
| 85 this.onBeforeNavigate = new TabEventTarget(tab, "beforeNavigate", false); | 87 this.onBeforeNavigate = new TabEventTarget(tab, "beforeNavigate", false); |
| 86 this.onCompleted = new TabEventTarget(tab, "navigate", false); | 88 this.onCompleted = new TabEventTarget(tab, "navigate", false); |
| 87 this.onActivated = new TabEventTarget(tab, "activate", false); | 89 this.onActivated = new TabEventTarget(tab, "activate", false); |
| 88 this.onRemoved = new TabEventTarget(tab, "close", false); | 90 this.onRemoved = new TabEventTarget(tab, "close", false); |
| 89 }; | 91 }; |
| 90 Tab.prototype = { | 92 Tab.prototype = { |
| 91 get url() | 93 get url() |
| 92 { | 94 { |
| 93 return this._tab.url; | 95 return this._tab.url; |
| 94 }, | 96 }, |
| 95 close: function() | 97 close: function() |
| 96 { | 98 { |
| 97 this._tab.close(); | 99 this._tab.close(); |
| 98 }, | 100 }, |
| 99 activate: function() | 101 activate: function() |
| 100 { | 102 { |
| 101 this._tab.activate(); | 103 this._tab.activate(); |
| 102 }, | 104 }, |
| 103 sendMessage: function(message, responseCallback) | 105 sendMessage: function(message, responseCallback) |
| 104 { | 106 { |
| 105 _sendMessage( | 107 _sendMessage( |
| 106 message, responseCallback, | 108 message, responseCallback, |
| 107 this._tab.page, this._tab | 109 this._tab.page, this._tab |
| 108 ); | 110 ); |
| 109 }, | |
| 110 browserAction: { | |
| 111 setIcon: function(path) | |
| 112 { | |
| 113 safari.extension.toolbarItems[0].image = safari.extension.baseURI + path ; | |
| 114 }, | |
| 115 setTitle: function(title) | |
| 116 { | |
| 117 safari.extension.toolbarItems[0].toolTip = title; | |
| 118 }, | |
| 119 setBadge: function(badge) | |
| 120 { | |
| 121 if (!badge) | |
| 122 safari.extension.toolbarItems[0].badge = 0; | |
| 123 else if ("number" in badge) | |
| 124 safari.extension.toolbarItems[0].badge = badge.number; | |
| 125 } | |
| 126 } | 111 } |
| 127 }; | 112 }; |
| 128 | 113 |
| 129 TabMap = function(deleteTabOnBeforeNavigate) | 114 TabMap = function(deleteTabOnBeforeNavigate) |
| 130 { | 115 { |
| 131 this._tabs = []; | 116 this._tabs = []; |
| 132 this._values = []; | 117 this._values = []; |
| 133 | 118 |
| 134 this._deleteOnEvent = this._deleteOnEvent.bind(this); | 119 this._deleteOnEvent = this._deleteOnEvent.bind(this); |
| 135 this._deleteTabOnBeforeNavigate = deleteTabOnBeforeNavigate; | 120 this._deleteTabOnBeforeNavigate = deleteTabOnBeforeNavigate; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 { | 171 { |
| 187 // delay so that other event handlers can still lookup this tab | 172 // delay so that other event handlers can still lookup this tab |
| 188 setTimeout(this._delete.bind(this, event.target), 0); | 173 setTimeout(this._delete.bind(this, event.target), 0); |
| 189 } | 174 } |
| 190 }; | 175 }; |
| 191 TabMap.prototype["delete"] = function(tab) | 176 TabMap.prototype["delete"] = function(tab) |
| 192 { | 177 { |
| 193 this._delete(tab._tab); | 178 this._delete(tab._tab); |
| 194 }; | 179 }; |
| 195 | 180 |
| 181 ext.tabs = { | |
| 182 onLoading: new LoadingTabEventTarget(safari.application), | |
| 183 onBeforeNavigate: new TabEventTarget(safari.application, "beforeNavigate", t rue), | |
| 184 onCompleted: new TabEventTarget(safari.application, "navigate", true), | |
| 185 onActivated: new TabEventTarget(safari.application, "activate", true), | |
| 186 onRemoved: new TabEventTarget(safari.application, "close", true) | |
| 187 }; | |
| 188 | |
| 189 | |
| 190 /* Browser actions */ | |
| 191 | |
| 192 var globalTooltipItemProperties = {} | |
| 193 var tooltipItemPropertiesPerTab = new TabMap(); | |
|
Wladimir Palant
2014/01/15 15:24:47
You meant toolbarItem, not tooltipItem, right?
Sebastian Noack
2014/01/15 19:25:47
It is gone now.
| |
| 194 | |
| 195 var getToolbarItemForWindow = function(win) | |
| 196 { | |
| 197 for (var i = 0; i < safari.extension.toolbarItems.length; i++) | |
| 198 { | |
| 199 var toolbarItem = safari.extension.toolbarItems[i]; | |
| 200 | |
| 201 if (toolbarItem.browserWindow == win) | |
| 202 return toolbarItem; | |
| 203 } | |
|
Wladimir Palant
2014/01/15 15:24:47
This should return something if no toolbar item is
Sebastian Noack
2014/01/15 19:25:47
Done. Even though I think that it is a bug when th
| |
| 204 }; | |
| 205 | |
| 206 var BrowserAction = function(tab) | |
| 207 { | |
| 208 this._tab = tab; | |
| 209 }; | |
| 210 BrowserAction.prototype = { | |
| 211 _set: function(property, value) | |
| 212 { | |
| 213 var currentWindow = this._tab._tab.browserWindow; | |
| 214 var toolbarItem = getToolbarItemForWindow(currentWindow); | |
| 215 | |
| 216 if (!(property in globalTooltipItemProperties)) | |
| 217 globalTooltipItemProperties[property] = toolbarItem[property]; | |
| 218 | |
| 219 if (this._tab._tab == currentWindow.activeTab) | |
| 220 toolbarItem[property] = value; | |
| 221 | |
| 222 var props = tooltipItemPropertiesPerTab.get(this._tab); | |
| 223 if (!props) | |
| 224 { | |
| 225 props = {}; | |
| 226 tooltipItemPropertiesPerTab.set(this._tab, props); | |
| 227 } | |
| 228 props[property] = value; | |
| 229 }, | |
| 230 setIcon: function(path) | |
| 231 { | |
| 232 this._set("image", safari.extension.baseURI + path); | |
| 233 }, | |
| 234 setTitle: function(title) | |
| 235 { | |
| 236 this._set("toolTip", title); | |
| 237 }, | |
| 238 setBadge: function(badge) | |
| 239 { | |
| 240 if (!badge) | |
| 241 this._set("badge", 0); | |
| 242 else if ("number" in badge) | |
| 243 this._set("badge", badge.number); | |
| 244 } | |
| 245 }; | |
| 246 | |
| 247 ext.tabs.onActivated.addListener(function(tab) | |
| 248 { | |
| 249 var props = tooltipItemPropertiesPerTab.get(tab); | |
| 250 var toolbarItem = getToolbarItemForWindow(tab._tab.browserWindow); | |
| 251 | |
| 252 for (var property in globalTooltipItemProperties) | |
| 253 { | |
| 254 if (props && property in props) | |
| 255 toolbarItem[property] = props[property]; | |
| 256 else | |
| 257 toolbarItem[property] = globalTooltipItemProperties[property]; | |
| 258 } | |
|
Wladimir Palant
2014/01/15 15:24:47
What's the point of globalTooltipItemProperties? I
Sebastian Noack
2014/01/15 19:25:47
This approach just emulates the behavior we alread
| |
| 259 }); | |
| 260 | |
| 196 | 261 |
| 197 /* Windows */ | 262 /* Windows */ |
| 198 | 263 |
| 199 Window = function(win) | 264 Window = function(win) |
| 200 { | 265 { |
| 201 this._win = win; | 266 this._win = win; |
| 202 } | 267 } |
| 203 Window.prototype = { | 268 Window.prototype = { |
| 204 get visible() | 269 get visible() |
| 205 { | 270 { |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 { | 596 { |
| 532 return new Window(win); | 597 return new Window(win); |
| 533 })); | 598 })); |
| 534 }, | 599 }, |
| 535 getLastFocused: function(callback) | 600 getLastFocused: function(callback) |
| 536 { | 601 { |
| 537 callback(new Window(safari.application.activeBrowserWindow)); | 602 callback(new Window(safari.application.activeBrowserWindow)); |
| 538 } | 603 } |
| 539 }; | 604 }; |
| 540 | 605 |
| 541 ext.tabs = { | |
| 542 onLoading: new LoadingTabEventTarget(safari.application), | |
| 543 onBeforeNavigate: new TabEventTarget(safari.application, "beforeNavigate", t rue), | |
| 544 onCompleted: new TabEventTarget(safari.application, "navigate", true), | |
| 545 onActivated: new TabEventTarget(safari.application, "activate", true), | |
| 546 onRemoved: new TabEventTarget(safari.application, "close", true) | |
| 547 }; | |
| 548 | |
| 549 ext.backgroundPage = { | 606 ext.backgroundPage = { |
| 550 getWindow: function() | 607 getWindow: function() |
| 551 { | 608 { |
| 552 return safari.extension.globalPage.contentWindow; | 609 return safari.extension.globalPage.contentWindow; |
| 553 } | 610 } |
| 554 }; | 611 }; |
| 555 | 612 |
| 556 ext.onMessage = new BackgroundMessageEventTarget(); | 613 ext.onMessage = new BackgroundMessageEventTarget(); |
| 557 | 614 |
| 558 // TODO: Implement context menu | 615 // TODO: Implement context menu |
| 559 ext.contextMenus = { | 616 ext.contextMenus = { |
| 560 create: function(title, contexts, onclick) {}, | 617 create: function(title, contexts, onclick) {}, |
| 561 removeAll: function(callback) {} | 618 removeAll: function(callback) {} |
| 562 }; | 619 }; |
| 563 })(); | 620 })(); |
| OLD | NEW |