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

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

Issue 5735785512828928: Remove tabs from TabMap onLoading instead of onBeforeNavigate on Safari (Closed)
Patch Set: Created Jan. 23, 2014, 11:33 a.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 | « chrome/ext/background.js ('k') | no next file » | 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 <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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
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); 84 this.browserAction = new BrowserAction(this);
85 85
86 this.onLoading = new LoadingTabEventTarget(tab); 86 this.onLoading = new LoadingTabEventTarget(tab);
87 this.onBeforeNavigate = new TabEventTarget(tab, "beforeNavigate", false);
88 this.onCompleted = new TabEventTarget(tab, "navigate", false); 87 this.onCompleted = new TabEventTarget(tab, "navigate", false);
89 this.onActivated = new TabEventTarget(tab, "activate", false); 88 this.onActivated = new TabEventTarget(tab, "activate", false);
90 this.onRemoved = new TabEventTarget(tab, "close", false); 89 this.onRemoved = new TabEventTarget(tab, "close", false);
91 }; 90 };
92 Tab.prototype = { 91 Tab.prototype = {
93 get url() 92 get url()
94 { 93 {
95 return this._tab.url; 94 return this._tab.url;
96 }, 95 },
97 close: function() 96 close: function()
98 { 97 {
99 this._tab.close(); 98 this._tab.close();
100 }, 99 },
101 activate: function() 100 activate: function()
102 { 101 {
103 this._tab.activate(); 102 this._tab.activate();
104 }, 103 },
105 sendMessage: function(message, responseCallback) 104 sendMessage: function(message, responseCallback)
106 { 105 {
107 _sendMessage( 106 _sendMessage(
108 message, responseCallback, 107 message, responseCallback,
109 this._tab.page, this._tab 108 this._tab.page, this._tab
110 ); 109 );
111 } 110 }
112 }; 111 };
113 112
114 TabMap = function(deleteTabOnBeforeNavigate) 113 TabMap = function(deleteTabOnLoading)
Wladimir Palant 2014/01/23 13:34:13 Having to change a parameter name just because the
Sebastian Noack 2014/01/23 13:51:13 Done.
115 { 114 {
116 this._tabs = []; 115 this._tabs = [];
Wladimir Palant 2014/01/23 13:34:13 This property is no longer in use.
Sebastian Noack 2014/01/23 13:51:13 Done.
117 this._values = []; 116 this._data = [];
118 117
119 this._deleteOnEvent = this._deleteOnEvent.bind(this); 118 this.delete = this.delete.bind(this);
120 this._deleteTabOnBeforeNavigate = deleteTabOnBeforeNavigate; 119 this._delete = this._delete.bind(this);
120
121 this._deleteTabOnLoading = deleteTabOnLoading;
121 }; 122 };
122 TabMap.prototype = 123 TabMap.prototype =
123 { 124 {
125 _indexOf: function(tab)
126 {
127 for (var i = 0; i < this._data.length; i++)
128 if (this._data[i].tab._tab == tab._tab)
129 return i;
130
131 return -1;
132 },
133 _delete: function(tab)
134 {
135 // delay so that other onClosed listeners can still look this tab up
136 setTimeout(this.delete.bind(this, tab), 0);
137 },
124 get: function(tab) { 138 get: function(tab) {
125 var idx; 139 var idx;
126 140
127 if (!tab || (idx = this._tabs.indexOf(tab._tab)) == -1) 141 if (!tab || (idx = this._indexOf(tab)) == -1)
128 return null; 142 return null;
129 143
130 return this._values[idx]; 144 return this._data[idx].value;
131 }, 145 },
132 set: function(tab, value) 146 set: function(tab, value)
133 { 147 {
134 var idx = this._tabs.indexOf(tab._tab); 148 var idx = this._indexOf(tab);
135 149
136 if (idx != -1) 150 if (idx != -1)
137 this._values[idx] = value; 151 this._data[idx].value = value;
138 else 152 else
139 { 153 {
140 this._tabs.push(tab._tab); 154 this._data.push({value: value, tab: tab});
141 this._values.push(value);
142 155
143 tab._tab.addEventListener("close", this._deleteOnEvent, false); 156 tab.onRemoved.addListener(this._delete);
144 if (this._deleteTabOnBeforeNavigate) 157 if (this._deleteTabOnLoading)
145 tab._tab.addEventListener("beforeNavigate", this._deleteOnEvent, false ); 158 tab.onLoading.addListener(this.delete);
Wladimir Palant 2014/01/23 13:34:13 What if about:blank is loaded into the tab or some
Sebastian Noack 2014/01/23 13:51:13 I've just checked that. And surprisingly our conte
146 } 159 }
147 }, 160 },
148 has: function(tab) 161 has: function(tab)
149 { 162 {
150 return this._tabs.indexOf(tab._tab) != -1; 163 return this._indexOf(tab) != -1;
151 }, 164 },
152 clear: function() 165 clear: function()
153 { 166 {
154 while (this._tabs.length > 0) 167 while (this._data.length > 0)
155 this._delete(this._tabs[0]); 168 this.delete(this._data[0].tab);
156 },
157 _delete: function(tab)
158 {
159 var idx = this._tabs.indexOf(tab);
160
161 if (idx != -1)
162 {
163 this._tabs.splice(idx, 1);
164 this._values.splice(idx, 1);
165
166 tab.removeEventListener("close", this._deleteOnEvent, false);
167 tab.removeEventListener("beforeNavigate", this._deleteOnEvent, false);
168 }
169 },
170 _deleteOnEvent: function(event)
171 {
172 // delay so that other event handlers can still look this tab up
173 setTimeout(this._delete.bind(this, event.target), 0);
174 } 169 }
175 }; 170 };
176 TabMap.prototype["delete"] = function(tab) 171 TabMap.prototype["delete"] = function(tab)
Wladimir Palant 2014/01/23 13:34:13 I am still wondering why this method isn't defined
Sebastian Noack 2014/01/23 13:51:13 It leads to a syntax error, at least in Safari and
Wladimir Palant 2014/01/23 14:44:37 No, for me it doesn't (tested in Safari 7.0 and Ch
Sebastian Noack 2014/01/23 15:27:44 You are right. I tried it in the console, and in t
177 { 172 {
178 this._delete(tab._tab); 173 var idx = this._indexOf(tab);
174
175 if (idx != -1)
176 {
177 tab = this._data[idx].tab;
178 this._data.splice(idx, 1);
179
180 tab.onRemoved.removeListener(this._delete);
181 tab.onLoading.removeListener(this.delete);
182 }
179 }; 183 };
180 184
181 ext.tabs = { 185 ext.tabs = {
182 onLoading: new LoadingTabEventTarget(safari.application), 186 onLoading: new LoadingTabEventTarget(safari.application),
183 onBeforeNavigate: new TabEventTarget(safari.application, "beforeNavigate", t rue),
184 onCompleted: new TabEventTarget(safari.application, "navigate", true), 187 onCompleted: new TabEventTarget(safari.application, "navigate", true),
185 onActivated: new TabEventTarget(safari.application, "activate", true), 188 onActivated: new TabEventTarget(safari.application, "activate", true),
186 onRemoved: new TabEventTarget(safari.application, "close", true) 189 onRemoved: new TabEventTarget(safari.application, "close", true)
187 }; 190 };
188 191
189 192
190 /* Browser actions */ 193 /* Browser actions */
191 194
192 var toolbarItemProperties = {}; 195 var toolbarItemProperties = {};
193 196
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 for (var i = 0; i < contextMenuItems.length; i++) 708 for (var i = 0; i < contextMenuItems.length; i++)
706 { 709 {
707 if (contextMenuItems[i].id == event.command) 710 if (contextMenuItems[i].id == event.command)
708 { 711 {
709 contextMenuItems[i].onclick(event.userInfo.srcUrl, new Tab(safari.applic ation.activeBrowserWindow.activeTab)); 712 contextMenuItems[i].onclick(event.userInfo.srcUrl, new Tab(safari.applic ation.activeBrowserWindow.activeTab));
710 break; 713 break;
711 } 714 }
712 } 715 }
713 }, false); 716 }, false);
714 })(); 717 })();
OLDNEW
« no previous file with comments | « chrome/ext/background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld