Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: safari/ext/background.js

Issue 29334223: Issue 3532 - Generate animation images at runtime (Closed)
Patch Set: Avoid exceptions when active tab is closed Created Jan. 24, 2016, 3:42 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « metadata.safari ('k') | safari/icons/abp-16.png » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 var activeTab = event.target.browserWindow.activeTab;
158 var pageId = addPage(activeTab, activeTab.url, false);
159 ext.pages.onActivated._dispatch(pages[pageId]);
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(event.target._visiblePage, event.target.browserWind ow);
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 {
172 this._id = id; 176 this._id = id;
173 this._tab = tab; 177 this._tab = tab;
174 this._frames = [{url: new URL(url), parent: null}]; 178 this._frames = [{url: new URL(url || "about:blank"), parent: null}];
175 179
176 if (tab.page) 180 if (tab.page)
177 this._messageProxy = new ext._MessageProxy(tab.page); 181 this._messageProxy = new ext._MessageProxy(tab.page);
178 else 182 else
179 // while the new tab page is shown on Safari 7, the 'page' property 183 // while the new tab page is shown on Safari 7, the 'page' property
180 // of the tab is undefined, and we can't send messages to that page 184 // of the tab is undefined, and we can't send messages to that page
181 this._messageProxy = { 185 this._messageProxy = {
182 handleRequest: function() {}, 186 handleRequest: function() {},
183 handleResponse: function() {}, 187 handleResponse: function() {},
184 sendMessage: function() {} 188 sendMessage: function() {}
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 })();
OLDNEW
« no previous file with comments | « metadata.safari ('k') | safari/icons/abp-16.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld