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

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

Issue 5420918314631168: Issue 1372 - Work around a bug in Chrome 38 where 'object' requests have the wrong type (Closed)
Patch Set: Created Sept. 25, 2014, 2:53 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 | « 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
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 chrome.webRequest.onBeforeRequest.addListener(function(details) 281 chrome.webRequest.onBeforeRequest.addListener(function(details)
282 { 282 {
283 try 283 try
284 { 284 {
285 // the high-level code isn't interested in requests that aren't related 285 // the high-level code isn't interested in requests that aren't related
286 // to a tab and since those can only be handled in Chrome, we ignore 286 // to a tab and since those can only be handled in Chrome, we ignore
287 // them here instead of in the browser independent high-level code. 287 // them here instead of in the browser independent high-level code.
288 if (details.tabId == -1) 288 if (details.tabId == -1)
289 return; 289 return;
290 290
291 var isMainFrame = details.type == "main_frame" || ( 291 var requestType = details.type;
292 var isMainFrame = requestType == "main_frame" || (
293
292 // assume that the first request belongs to the top frame. Chrome 294 // assume that the first request belongs to the top frame. Chrome
293 // may give the top frame the type "object" instead of "main_frame". 295 // may give the top frame the type "object" instead of "main_frame".
294 // https://code.google.com/p/chromium/issues/detail?id=281711 296 // https://code.google.com/p/chromium/issues/detail?id=281711
295 details.frameId == 0 && !(details.tabId in framesOfTabs) 297 details.frameId == 0 && !(details.tabId in framesOfTabs)
296 ); 298 );
297 299
298 var frames = null; 300 var frames = null;
299 if (!isMainFrame) 301 if (!isMainFrame)
300 frames = framesOfTabs[details.tabId]; 302 frames = framesOfTabs[details.tabId];
301 if (!frames) 303 if (!frames)
302 frames = framesOfTabs[details.tabId] = {__proto__: null}; 304 frames = framesOfTabs[details.tabId] = {__proto__: null};
303 305
304 var frame = null; 306 var frame = null;
305 if (!isMainFrame) 307 if (!isMainFrame)
306 { 308 {
307 // we are looking for the frame that contains the element that 309 // we are looking for the frame that contains the element that
308 // is about to load, however if a frame is loading the surrounding 310 // is about to load, however if a frame is loading the surrounding
309 // frame is indicated by parentFrameId instead of frameId 311 // frame is indicated by parentFrameId instead of frameId
310 var frameId; 312 var frameId;
311 if (details.type == "sub_frame") 313 if (requestType == "sub_frame")
312 frameId = details.parentFrameId; 314 frameId = details.parentFrameId;
313 else 315 else
314 frameId = details.frameId; 316 frameId = details.frameId;
315 317
316 frame = frames[frameId] || frames[Object.keys(frames)[0]]; 318 frame = frames[frameId] || frames[Object.keys(frames)[0]];
317 319
318 if (frame && !ext.webRequest.onBeforeRequest._dispatch(details.url, deta ils.type, new Page({id: details.tabId}), frame)) 320 if (frame)
319 return {cancel: true}; 321 {
322 // Chrome 38 mistakenly reports requests of type 'object'
323 // (e.g. requests initiated by Flash) with the type 'other'.
324 // https://code.google.com/p/chromium/issues/detail?id=410382
325 if (requestType == "other" && / Chrome\/38\b/.test(navigator.userAgent ))
Sebastian Noack 2014/09/25 15:00:53 Just in case you wonder why I didn't used info.pla
Wladimir Palant 2014/09/25 16:18:16 I wonder whether we should really do this for Chro
Sebastian Noack 2014/09/25 16:24:06 In case this isn't fixed in Chrome 39, this workar
326 requestType = "object";
327
328 if (!ext.webRequest.onBeforeRequest._dispatch(details.url, requestType , new Page({id: details.tabId}), frame))
329 return {cancel: true};
330 }
320 } 331 }
321 332
322 if (isMainFrame || details.type == "sub_frame") 333 if (isMainFrame || details.type == "sub_frame")
323 frames[details.frameId] = {url: details.url, parent: frame}; 334 frames[details.frameId] = {url: details.url, parent: frame};
324 } 335 }
325 catch (e) 336 catch (e)
326 { 337 {
327 // recent versions of Chrome cancel the request when an error occurs in 338 // recent versions of Chrome cancel the request when an error occurs in
328 // the onBeforeRequest listener. However in our case it is preferred, to 339 // the onBeforeRequest listener. However in our case it is preferred, to
329 // let potentially some ads through, rather than blocking legit requests. 340 // let potentially some ads through, rather than blocking legit requests.
(...skipping 29 matching lines...) Expand all
359 }; 370 };
360 371
361 return ext.onMessage._dispatch(message, sender, sendResponse); 372 return ext.onMessage._dispatch(message, sender, sendResponse);
362 }); 373 });
363 374
364 375
365 /* Storage */ 376 /* Storage */
366 377
367 ext.storage = localStorage; 378 ext.storage = localStorage;
368 })(); 379 })();
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