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

Delta Between Two Patch Sets: safari/ext/background.js

Issue 5464830253203456: Refactored the abstraction layer to address prerendered pages on Safari caused by leaky abstraction (Closed)
Left Patch Set: Created Feb. 22, 2014, 10:45 a.m.
Right Patch Set: Addressed comments Created April 11, 2014, 2:47 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « popupBlocker.js ('k') | safari/ext/common.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
(...skipping 28 matching lines...) Expand all
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();
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
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
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))
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); 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);
211 else if ("number" in badge) 208 else if ("number" in badge)
212 this._set("badge", badge.number); 209 this._set("badge", badge.number);
213 } 210 }
214 }; 211 };
215 212
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 // when a prerendered page is shown, forget the previous page 651 // when a prerendered page is shown, forget the previous page
655 // associated with its tab, and reset the toolbar item if necessary. 652 // associated with its tab, and reset the toolbar item if necessary.
656 // Note that it wouldn't be sufficient to do that when the old 653 // Note that it wouldn't be sufficient to do that when the old
657 // page is unloading, because Safari dispatches window.onunload 654 // page is unloading, because Safari dispatches window.onunload
658 // only when reloading the page or following links, but not when 655 // only when reloading the page or following links, but not when
659 // the current page is replaced with a prerendered page. 656 // the current page is replaced with a prerendered page.
660 replacePage(page); 657 replacePage(page);
661 break; 658 break;
662 } 659 }
663 }); 660 });
661
662
663 /* Storage */
664
665 ext.storage = safari.extension.settings;
664 })(); 666 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld