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

Side by Side Diff: include.preload.js

Issue 5168731525218304: Issue 1441 - Let the browser resolve URLs instead doing it ourselve (Closed)
Patch Set: Created Sept. 25, 2014, 7:47 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 | « include.postload.js ('k') | safari/ext/content.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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 return hasInlineURL(element, "src") || element.hasAttribute("srcdoc"); 90 return hasInlineURL(element, "src") || element.hasAttribute("srcdoc");
91 case "frame": 91 case "frame":
92 return hasInlineURL(element, "src"); 92 return hasInlineURL(element, "src");
93 case "object": 93 case "object":
94 return hasInlineURL(element, "data") && element.contentDocument; 94 return hasInlineURL(element, "data") && element.contentDocument;
95 default: 95 default:
96 return false; 96 return false;
97 } 97 }
98 } 98 }
99 99
100 // Converts relative to absolute URL 100 function resolveURL(url)
101 // e.g.: foo.swf on http://example.com/whatever/bar.html
102 // -> http://example.com/whatever/foo.swf
103 function relativeToAbsoluteUrl(url)
104 { 101 {
105 // If URL is already absolute, don't mess with it 102 var a = document.createElement("a");
106 if (!url || /^[\w\-]+:/i.test(url)) 103 a.href = url;
107 return url; 104 return a.href;
108
109 // Leading / means absolute path
110 // Leading // means network path
111 if (url[0] == '/')
112 {
113 if (url[1] == '/')
114 return window.location.protocol + url;
115 else
116 return window.location.protocol + "//" + window.location.host + url;
117 }
118
119 // Remove filename and add relative URL to it
120 var base = document.baseURI.match(/.+\//);
121 if (!base)
122 return document.baseURI + "/" + url;
123 return base[0] + url;
124 } 105 }
125 106
126 function init(document) 107 function init(document)
127 { 108 {
128 // prior to Chrome 37, content scripts don't run on about:blank 109 // prior to Chrome 37, content scripts don't run on about:blank
129 // and about:srcdoc. So we have to apply element hiding and collapsing 110 // and about:srcdoc. So we have to apply element hiding and collapsing
130 // from the parent frame, when inline frames are loaded. 111 // from the parent frame, when inline frames are loaded.
131 var match = navigator.userAgent.match(/\bChrome\/(\d+)/); 112 var match = navigator.userAgent.match(/\bChrome\/(\d+)/);
132 var fixInlineFrames = match && parseInt(match[1]) < 37; 113 var fixInlineFrames = match && parseInt(match[1]) < 37;
133 114
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 }, true); 191 }, true);
211 192
212 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); 193 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules);
213 } 194 }
214 195
215 if (document instanceof HTMLDocument) 196 if (document instanceof HTMLDocument)
216 { 197 {
217 checkSitekey(); 198 checkSitekey();
218 init(document); 199 init(document);
219 } 200 }
OLDNEW
« no previous file with comments | « include.postload.js ('k') | safari/ext/content.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld