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

Side by Side Diff: chrome/content/ui/sidebar.js

Issue 6241284884791296: issue #660 - Switch to version 2 of the HTTP cache API (Closed)
Patch Set: Created July 2, 2014, 6:56 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 | « no previous file | 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-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
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 let {Services} = Cu.import("resource://gre/modules/Services.jsm", null);
304 cacheSession = cacheService.createSession("HTTP", Ci.nsICache.STORE_ANYWHE RE, true); 304 // Cache v2 API is enabled by default starting with Gecko 32
305 if (Services.vc.compare(Utils.platformVersion, "32.0") >= 0)
306 {
307 let {LoadContextInfo} = Cu.import("resource://gre/modules/LoadContextInf o.jsm", null);
308 cacheStorage = Services.cache2.diskCacheStorage(LoadContextInfo.default, true);
309 }
310 else
311 cacheStorage = Services.cache.createSession("HTTP", Ci.nsICache.STORE_AN YWHERE, true);
305 } 312 }
306 313
307 let cacheListener = 314 let showTooltipPreview = function ()
308 { 315 {
309 onCacheEntryAvailable: function(descriptor, accessGranted, status) 316 E("tooltipPreview").setAttribute("src", item.location);
310 { 317 E("tooltipPreviewBox").hidden = false;
311 if (!descriptor)
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 }; 318 };
324 try 319 try
325 { 320 {
326 cacheSession.asyncOpenCacheEntry(item.location, Ci.nsICache.ACCESS_READ, c acheListener); 321 if (Ci.nsICacheStorage && cacheStorage instanceof Ci.nsICacheStorage)
322 {
323 cacheStorage.asyncOpenURI(Utils.makeURI(item.location), "", Ci.nsICacheS torage.OPEN_READONLY, {
324 onCacheEntryCheck: function (entry, appCache)
325 {
326 return Ci.nsICacheEntryOpenCallback.ENTRY_WANTED;
327 },
328 onCacheEntryAvailable: function (entry, isNew, appCache, status) {
329 if (!isNew)
330 showTooltipPreview();
331 }
332 });
333 }
334 else
335 {
336 cacheStorage.asyncOpenCacheEntry(item.location, Ci.nsICache.ACCESS_READ, {
337 onCacheEntryAvailable: function(descriptor, accessGranted, status)
338 {
339 if (!descriptor)
340 return;
341 descriptor.close();
342 showTooltipPreview();
343 },
344 onCacheEntryDoomed: function(status)
345 {
346 }
347 });
348 }
327 } 349 }
328 catch (e) 350 catch (e)
329 { 351 {
330 Cu.reportError(e); 352 Cu.reportError(e);
331 } 353 }
332 } 354 }
333
334 E("tooltipPreviewBox").hidden = true;
335 } 355 }
336 356
337 const visual = { 357 const visual = {
338 OTHER: true, 358 OTHER: true,
339 IMAGE: true, 359 IMAGE: true,
340 SUBDOCUMENT: true 360 SUBDOCUMENT: true
341 } 361 }
342 362
343 /** 363 /**
344 * Updates context menu before it is shown. 364 * Updates context menu before it is shown.
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 return {tooltip: this.itemsDummyTooltip}; 1257 return {tooltip: this.itemsDummyTooltip};
1238 }, 1258 },
1239 1259
1240 invalidateItem: function(item) 1260 invalidateItem: function(item)
1241 { 1261 {
1242 let row = this.data.indexOf(item); 1262 let row = this.data.indexOf(item);
1243 if (row >= 0) 1263 if (row >= 0)
1244 this.boxObject.invalidateRow(row); 1264 this.boxObject.invalidateRow(row);
1245 } 1265 }
1246 } 1266 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld