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

Side by Side Diff: include.postload.js

Issue 6686166900277248: Issue 573 - Resolve relative URLs in the beforeload handler on Safari (Closed)
Patch Set: Created May 28, 2014, 10:08 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 | include.preload.js » ('j') | 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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 params = elt.querySelectorAll("param[name=\"src\"]"); 348 params = elt.querySelectorAll("param[name=\"src\"]");
349 if(params[0]) 349 if(params[0])
350 url = params[0].getAttribute("value"); 350 url = params[0].getAttribute("value");
351 } 351 }
352 } else if(!url) { 352 } else if(!url) {
353 url = elt.getAttribute("src") || elt.getAttribute("href"); 353 url = elt.getAttribute("src") || elt.getAttribute("href");
354 } 354 }
355 return url; 355 return url;
356 } 356 }
357 357
358 // Converts relative to absolute URL
359 // e.g.: foo.swf on http://example.com/whatever/bar.html
360 // -> http://example.com/whatever/foo.swf
361 function relativeToAbsoluteUrl(url)
362 {
363 // If URL is already absolute, don't mess with it
364 if (!url || /^[\w\-]+:/i.test(url))
365 return url;
366
367 // Leading / means absolute path
368 // Leading // means network path
369 if (url[0] == '/')
370 {
371 if (url[1] == '/')
372 return document.location.protocol + url;
373 else
374 return document.location.protocol + "//" + document.location.host + url;
375 }
376
377 // Remove filename and add relative URL to it
378 var base = document.baseURI.match(/.+\//);
379 if (!base)
380 return document.baseURI + "/" + url;
381 return base[0] + url;
382 }
383
384 // This function Copyright (c) 2008 Jeni Tennison, from jquery.uri.js 358 // This function Copyright (c) 2008 Jeni Tennison, from jquery.uri.js
385 // and licensed under the MIT license. See jquery-*.min.js for details. 359 // and licensed under the MIT license. See jquery-*.min.js for details.
386 function removeDotSegments(u) { 360 function removeDotSegments(u) {
387 var r = '', m = []; 361 var r = '', m = [];
388 if (/\./.test(u)) { 362 if (/\./.test(u)) {
389 while (u !== undefined && u !== '') { 363 while (u !== undefined && u !== '') {
390 if (u === '.' || u === '..') { 364 if (u === '.' || u === '..') {
391 u = ''; 365 u = '';
392 } else if (/^\.\.\//.test(u)) { // starts with ../ 366 } else if (/^\.\.\//.test(u)) { // starts with ../
393 u = u.substring(3); 367 u = u.substring(3);
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 559
586 clickHide_deactivate(); 560 clickHide_deactivate();
587 } 561 }
588 break; 562 break;
589 default: 563 default:
590 sendResponse({}); 564 sendResponse({});
591 break; 565 break;
592 } 566 }
593 }); 567 });
594 } 568 }
OLDNEW
« no previous file with comments | « no previous file | include.preload.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld