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-2014 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 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | 18 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
19 | 19 |
20 // Main browser window | 20 // Main browser window |
21 var mainWin = parent; | 21 var mainWin = parent; |
22 | 22 |
23 // The window handler currently in use | 23 // The window handler currently in use |
24 var requestNotifier = null; | 24 var requestNotifier = null; |
25 | 25 |
26 var cacheSession = null; | 26 var cacheStorage = null; |
27 var noFlash = false; | 27 var noFlash = false; |
28 | 28 |
29 // Matcher for disabled filters | 29 // Matcher for disabled filters |
30 var disabledMatcher = new CombinedMatcher(); | 30 var disabledMatcher = new CombinedMatcher(); |
31 | 31 |
32 // Cached string values | 32 // Cached string values |
33 var docDomainThirdParty = null; | 33 var docDomainThirdParty = null; |
34 var docDomainFirstParty = null; | 34 var docDomainFirstParty = null; |
35 | 35 |
36 function init() { | 36 function init() { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 while (sourceElement.firstChild) | 288 while (sourceElement.firstChild) |
289 sourceElement.removeChild(sourceElement.firstChild); | 289 sourceElement.removeChild(sourceElement.firstChild); |
290 for (let i = 0; i < subscriptions.length; i++) | 290 for (let i = 0; i < subscriptions.length; i++) |
291 setMultilineContent(sourceElement, subscriptions[i].title, true); | 291 setMultilineContent(sourceElement, subscriptions[i].title, true); |
292 } | 292 } |
293 } | 293 } |
294 | 294 |
295 var showPreview = Prefs.previewimages && !("tooltip" in item); | 295 var showPreview = Prefs.previewimages && !("tooltip" in item); |
296 showPreview = showPreview && item.typeDescr == "IMAGE"; | 296 showPreview = showPreview && item.typeDescr == "IMAGE"; |
297 showPreview = showPreview && (!item.filter || item.filter.disabled || item.fil ter instanceof WhitelistFilter); | 297 showPreview = showPreview && (!item.filter || item.filter.disabled || item.fil ter instanceof WhitelistFilter); |
298 E("tooltipPreviewBox").hidden = true; | |
298 if (showPreview) | 299 if (showPreview) |
299 { | 300 { |
300 // Check whether image is in cache (stolen from ImgLikeOpera) | 301 if (!cacheStorage) |
301 if (!cacheSession) | |
302 { | 302 { |
303 var cacheService = Cc["@mozilla.org/network/cache-service;1"].getService(C i.nsICacheService); | 303 // Cache v2 API is enabled by default starting with Gecko 32 |
304 cacheSession = cacheService.createSession("HTTP", Ci.nsICache.STORE_ANYWHE RE, true); | 304 if (Services.vc.compare(Utils.platformVersion, "32.0") >= 0) |
305 { | |
306 let {LoadContextInfo} = Cu.import("resource://gre/modules/LoadContextInf o.jsm", null); | |
307 let cacheService = Cc["@mozilla.org/netwerk/cache-storage-service;1"].ge tService(Ci.nsICacheStorageService); | |
308 cacheStorage = cacheService.diskCacheStorage(LoadContextInfo.default, tr ue); | |
Wladimir Palant
2014/07/02 05:00:03
Apparently, this interface was added to Services.j
saroyanm
2014/07/02 07:03:41
Good point.
| |
309 } | |
310 else | |
311 { | |
312 let cacheService = Cc["@mozilla.org/network/cache-service;1"].getService (Ci.nsICacheService); | |
313 cacheStorage = cacheService.createSession("HTTP", Ci.nsICache.STORE_ANYW HERE, true); | |
Wladimir Palant
2014/07/02 05:00:03
We should use Services.cache here.
| |
314 } | |
305 } | 315 } |
306 | 316 |
307 let cacheListener = | 317 let showTooltipPreview = function () |
308 { | 318 { |
309 onCacheEntryAvailable: function(descriptor, accessGranted, status) | 319 E("tooltipPreview").setAttribute("src", item.location); |
310 { | 320 E("tooltipPreviewBox").hidden = false; |
311 if (!descriptor) | 321 } |
Wladimir Palant
2014/07/02 05:00:03
Missing semicolon after } here.
saroyanm
2014/07/02 07:03:41
Done.
| |
312 return; | |
313 | |
314 descriptor.close(); | |
315 // Show preview here since this is asynchronous now | |
316 // and we have a valid descriptor | |
317 E("tooltipPreview").setAttribute("src", item.location); | |
318 E("tooltipPreviewBox").hidden = false; | |
319 }, | |
320 onCacheEntryDoomed: function(status) | |
321 { | |
322 } | |
323 }; | |
324 try | 322 try |
325 { | 323 { |
326 cacheSession.asyncOpenCacheEntry(item.location, Ci.nsICache.ACCESS_READ, c acheListener); | 324 if (Ci.nsICacheStorage && cacheStorage instanceof Ci.nsICacheStorage) |
325 { | |
326 cacheStorage.asyncOpenURI(Utils.makeURI(item.location), "", Ci.nsICacheS torage.OPEN_READONLY, { | |
327 onCacheEntryCheck: function (entry, appCache) | |
328 { | |
329 return Ci.nsICacheEntryOpenCallback.ENTRY_WANTED; | |
330 }, | |
331 onCacheEntryAvailable: function (entry, isNew, appCache, status) { | |
332 if (!isNew) | |
333 showTooltipPreview(); | |
334 } | |
335 }); | |
336 } | |
337 else | |
338 { | |
339 cacheStorage.asyncOpenCacheEntry(item.location, Ci.nsICache.ACCESS_READ, { | |
340 onCacheEntryAvailable: function(descriptor, accessGranted, status) | |
341 { | |
342 if (!descriptor) | |
343 return; | |
344 descriptor.close(); | |
345 showTooltipPreview(); | |
346 }, | |
347 onCacheEntryDoomed: function(status) | |
348 { | |
349 } | |
350 }); | |
351 } | |
327 } | 352 } |
328 catch (e) | 353 catch (e) |
329 { | 354 { |
330 Cu.reportError(e); | 355 Cu.reportError(e); |
331 } | 356 } |
332 } | 357 } |
333 | |
334 E("tooltipPreviewBox").hidden = true; | |
335 } | 358 } |
336 | 359 |
337 const visual = { | 360 const visual = { |
338 OTHER: true, | 361 OTHER: true, |
339 IMAGE: true, | 362 IMAGE: true, |
340 SUBDOCUMENT: true | 363 SUBDOCUMENT: true |
341 } | 364 } |
342 | 365 |
343 /** | 366 /** |
344 * Updates context menu before it is shown. | 367 * Updates context menu before it is shown. |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1237 return {tooltip: this.itemsDummyTooltip}; | 1260 return {tooltip: this.itemsDummyTooltip}; |
1238 }, | 1261 }, |
1239 | 1262 |
1240 invalidateItem: function(item) | 1263 invalidateItem: function(item) |
1241 { | 1264 { |
1242 let row = this.data.indexOf(item); | 1265 let row = this.data.indexOf(item); |
1243 if (row >= 0) | 1266 if (row >= 0) |
1244 this.boxObject.invalidateRow(row); | 1267 this.boxObject.invalidateRow(row); |
1245 } | 1268 } |
1246 } | 1269 } |
OLD | NEW |