| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 147 } |
| 148 }; | 148 }; |
| 149 | 149 |
| 150 safari.application.addEventListener("activate", function(event) | 150 safari.application.addEventListener("activate", function(event) |
| 151 { | 151 { |
| 152 // this event is also dispatched on windows that got focused. But we | 152 // this event is also dispatched on windows that got focused. But we |
| 153 // are only interested in tabs, which became active in their window. | 153 // are only interested in tabs, which became active in their window. |
| 154 if (!(event.target instanceof SafariBrowserTab)) | 154 if (!(event.target instanceof SafariBrowserTab)) |
| 155 return; | 155 return; |
| 156 | 156 |
| 157 let visiblePage = event.target._visiblePage; |
| 158 if (visiblePage) |
| 159 ext.pages.onActivated._dispatch(visiblePage); |
| 160 |
| 157 // update the toolbar item for the page visible in the tab that just | 161 // update the toolbar item for the page visible in the tab that just |
| 158 // became active. If we can't find that page (e.g. when a page was | 162 // became active. If we can't find that page (e.g. when a page was |
| 159 // opened in a new tab, and our content script didn't run yet), the | 163 // opened in a new tab, and our content script didn't run yet), the |
| 160 // toolbar item of the window, is reset to its intial configuration. | 164 // toolbar item of the window, is reset to its intial configuration. |
| 161 updateToolbarItemForPage(event.target._visiblePage, event.target.browserWind
ow); | 165 updateToolbarItemForPage(visiblePage, event.target.browserWindow); |
| 162 }, true); | 166 }, true); |
| 163 | 167 |
| 164 | 168 |
| 165 /* Pages */ | 169 /* Pages */ |
| 166 | 170 |
| 167 var pages = Object.create(null); | 171 var pages = Object.create(null); |
| 168 var pageCounter = 0; | 172 var pageCounter = 0; |
| 169 | 173 |
| 170 var Page = function(id, tab, url) | 174 var Page = function(id, tab, url) |
| 171 { | 175 { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 if ("active" in info && info.active != isPageActive(page)) | 290 if ("active" in info && info.active != isPageActive(page)) |
| 287 continue; | 291 continue; |
| 288 if ("lastFocusedWindow" in info && info.lastFocusedWindow != (win == saf
ari.application.activeBrowserWindow)) | 292 if ("lastFocusedWindow" in info && info.lastFocusedWindow != (win == saf
ari.application.activeBrowserWindow)) |
| 289 continue; | 293 continue; |
| 290 | 294 |
| 291 matchedPages.push(page); | 295 matchedPages.push(page); |
| 292 }; | 296 }; |
| 293 | 297 |
| 294 callback(matchedPages); | 298 callback(matchedPages); |
| 295 }, | 299 }, |
| 296 onLoading: new ext._EventTarget() | 300 onLoading: new ext._EventTarget(), |
| 301 onActivated: new ext._EventTarget(), |
| 297 }; | 302 }; |
| 298 | 303 |
| 299 safari.application.addEventListener("close", function(event) | 304 safari.application.addEventListener("close", function(event) |
| 300 { | 305 { |
| 301 // this event is dispatched on closing windows and tabs. However when a | 306 // this event is dispatched on closing windows and tabs. However when a |
| 302 // window is closed, it is first dispatched on each tab in the window and | 307 // window is closed, it is first dispatched on each tab in the window and |
| 303 // then on the window itself. But we are only interested in closed tabs. | 308 // then on the window itself. But we are only interested in closed tabs. |
| 304 if (!(event.target instanceof SafariBrowserTab)) | 309 if (!(event.target instanceof SafariBrowserTab)) |
| 305 return; | 310 return; |
| 306 | 311 |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 tab.activate(); | 742 tab.activate(); |
| 738 if (callback) | 743 if (callback) |
| 739 callback(page); | 744 callback(page); |
| 740 return; | 745 return; |
| 741 } | 746 } |
| 742 } | 747 } |
| 743 | 748 |
| 744 ext.pages.open(optionsUrl, callback); | 749 ext.pages.open(optionsUrl, callback); |
| 745 }; | 750 }; |
| 746 })(); | 751 })(); |
| OLD | NEW |