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

Side by Side Diff: include.preload.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 | « 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 if (tag == "frame") 112 if (tag == "frame")
113 target.style.setProperty("visibility", "hidden", "important"); 113 target.style.setProperty("visibility", "hidden", "important");
114 else 114 else
115 target.style.setProperty("display", "none", "important"); 115 target.style.setProperty("display", "none", "important");
116 } 116 }
117 } 117 }
118 ); 118 );
119 } 119 }
120 } 120 }
121 121
122 // Converts relative to absolute URL
123 // e.g.: foo.swf on http://example.com/whatever/bar.html
124 // -> http://example.com/whatever/foo.swf
125 function relativeToAbsoluteUrl(url)
126 {
127 // If URL is already absolute, don't mess with it
128 if (!url || /^[\w\-]+:/i.test(url))
129 return url;
130
131 // Leading / means absolute path
132 // Leading // means network path
133 if (url[0] == '/')
134 {
135 if (url[1] == '/')
136 return document.location.protocol + url;
137 else
138 return document.location.protocol + "//" + document.location.host + url;
139 }
140
141 // Remove filename and add relative URL to it
142 var base = document.baseURI.match(/.+\//);
143 if (!base)
144 return document.baseURI + "/" + url;
145 return base[0] + url;
146 }
147
122 function init() 148 function init()
123 { 149 {
124 // Make sure this is really an HTML page, as Chrome runs these scripts on just about everything 150 // Make sure this is really an HTML page, as Chrome runs these scripts on just about everything
125 if (!(document.documentElement instanceof HTMLElement)) 151 if (!(document.documentElement instanceof HTMLElement))
126 return; 152 return;
127 153
128 document.addEventListener("error", checkCollapse, true); 154 document.addEventListener("error", checkCollapse, true);
129 document.addEventListener("load", checkCollapse, true); 155 document.addEventListener("load", checkCollapse, true);
130 156
131 var attr = document.documentElement.getAttribute("data-adblockkey"); 157 var attr = document.documentElement.getAttribute("data-adblockkey");
132 if (attr) 158 if (attr)
133 ext.backgroundPage.sendMessage({type: "add-key-exception", token: attr}); 159 ext.backgroundPage.sendMessage({type: "add-key-exception", token: attr});
134 160
135 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); 161 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules);
136 } 162 }
137 163
138 // In Chrome 18 the document might not be initialized yet 164 // In Chrome 18 the document might not be initialized yet
139 if (document.documentElement) 165 if (document.documentElement)
140 init(); 166 init();
141 else 167 else
142 window.setTimeout(init, 0); 168 window.setTimeout(init, 0);
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