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

Delta Between Two Patch Sets: include.preload.js

Issue 29349737: Issue 1727 - Fix WebSocket constructor without second argument in Chrome 47 (Closed)
Left Patch Set: Created Aug. 11, 2016, 2:12 p.m.
Right Patch Set: Omit the second argument if absent Created Aug. 11, 2016, 3:38 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 type: "filters.collapse", 143 type: "filters.collapse",
144 urls: urls, 144 urls: urls,
145 mediatype: mediatype, 145 mediatype: mediatype,
146 baseURL: document.location.href 146 baseURL: document.location.href
147 }, 147 },
148 148
149 function(collapse) 149 function(collapse)
150 { 150 {
151 function collapseElement() 151 function collapseElement()
152 { 152 {
153 var propertyName = "display";
154 var propertyValue = "none";
153 if (element.localName == "frame") 155 if (element.localName == "frame")
154 element.style.setProperty("visibility", "hidden", "important"); 156 {
155 else 157 propertyName = "visibility";
156 element.style.setProperty("display", "none", "important"); 158 propertyValue = "hidden";
157 } 159 }
158 160
159 if (collapse && !element._collapsed) 161 if (element.style.getPropertyValue(propertyName) != propertyValue ||
162 element.style.getPropertyPriority(propertyName) != "important")
163 element.style.setProperty(propertyName, propertyValue, "important");
164 }
165
166 if (collapse)
160 { 167 {
161 collapseElement(); 168 collapseElement();
162 element._collapsed = true;
163 169
164 if (MutationObserver) 170 if (MutationObserver)
165 new MutationObserver(collapseElement).observe( 171 new MutationObserver(collapseElement).observe(
166 element, { 172 element, {
167 attributes: true, 173 attributes: true,
168 attributeFilter: ["style"] 174 attributeFilter: ["style"]
169 } 175 }
170 ); 176 );
171 } 177 }
172 } 178 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 new CustomEvent(eventName + "-" + event.detail.url, {detail: block}) 372 new CustomEvent(eventName + "-" + event.detail.url, {detail: block})
367 ); 373 );
368 }); 374 });
369 }); 375 });
370 376
371 runInDocument(document, function(eventName) 377 runInDocument(document, function(eventName)
372 { 378 {
373 // As far as possible we must track everything we use that could be 379 // As far as possible we must track everything we use that could be
374 // sabotaged by the website later in order to circumvent us. 380 // sabotaged by the website later in order to circumvent us.
375 var RealWebSocket = WebSocket; 381 var RealWebSocket = WebSocket;
376 var bindWebSocket = Function.prototype.bind.apply.bind(Function.prototype.bi nd, RealWebSocket);
377 var closeWebSocket = Function.prototype.call.bind(RealWebSocket.prototype.cl ose); 382 var closeWebSocket = Function.prototype.call.bind(RealWebSocket.prototype.cl ose);
378 var addEventListener = document.addEventListener.bind(document); 383 var addEventListener = document.addEventListener.bind(document);
379 var removeEventListener = document.removeEventListener.bind(document); 384 var removeEventListener = document.removeEventListener.bind(document);
380 var dispatchEvent = document.dispatchEvent.bind(document); 385 var dispatchEvent = document.dispatchEvent.bind(document);
381 var CustomEvent = window.CustomEvent; 386 var CustomEvent = window.CustomEvent;
382 387
383 function checkRequest(url, callback) 388 function checkRequest(url, callback)
384 { 389 {
385 var incomingEventName = eventName + "-" + url; 390 var incomingEventName = eventName + "-" + url;
386 function listener(event) 391 function listener(event)
387 { 392 {
388 callback(event.detail); 393 callback(event.detail);
389 removeEventListener(incomingEventName, listener); 394 removeEventListener(incomingEventName, listener);
390 } 395 }
391 addEventListener(incomingEventName, listener); 396 addEventListener(incomingEventName, listener);
392 397
393 dispatchEvent(new CustomEvent(eventName, { 398 dispatchEvent(new CustomEvent(eventName, {
394 detail: {url: url} 399 detail: {url: url}
395 })); 400 }));
396 } 401 }
397 402
398 WebSocket = function WrappedWebSocket() 403 WebSocket = function WrappedWebSocket(url, protocols)
399 { 404 {
400 var args = [null]; 405 // Throw correct exceptions if the constructor is used improperly.
kzar 2016/08/11 14:25:05 I think this approach is extremely hard to follow,
Sebastian Noack 2016/08/11 14:38:46 Well, if you'd write your logic compliant to our c
kzar 2016/08/11 14:54:16 I didn't say anything about the code being shorter
Sebastian Noack 2016/08/11 15:11:35 I don't think that I agree. But there you go.
401 for (var i = 0; i < arguments.length; i++) 406 if (!(this instanceof WrappedWebSocket)) return RealWebSocket();
402 args.push(arguments[i]); 407 if (arguments.length < 1) return new RealWebSocket();
kzar 2016/08/11 14:25:05 This would allow for circumvention since we didn't
Sebastian Noack 2016/08/11 14:38:46 Well spotted, fixed.
403 408
404 var ctor = bindWebSocket(args); 409 var websocket;
405 var websocket = this instanceof WrappedWebSocket ? new ctor : ctor(); 410 if (arguments.length == 1)
411 websocket = new RealWebSocket(url);
412 else
413 websocket = new RealWebSocket(url, protocols);
Wladimir Palant 2016/08/15 12:33:24 Why make assumptions about the arguments in the fi
Wladimir Palant 2016/08/15 12:45:36 This will also allow dropping protocols parameter
Wladimir Palant 2016/08/15 13:01:24 Never mind, calling RealWebSocket.apply() won't wo
Sebastian Noack 2016/08/15 13:06:10 See patchset #2 (and the related discussin) for a
406 414
407 checkRequest(websocket.url, function(blocked) 415 checkRequest(websocket.url, function(blocked)
408 { 416 {
409 if (blocked) 417 if (blocked)
410 closeWebSocket(websocket); 418 closeWebSocket(websocket);
411 }); 419 });
412 420
413 return websocket; 421 return websocket;
414 }.bind(); 422 }.bind();
415 423
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 }, true); 618 }, true);
611 619
612 return updateStylesheet; 620 return updateStylesheet;
613 } 621 }
614 622
615 if (document instanceof HTMLDocument) 623 if (document instanceof HTMLDocument)
616 { 624 {
617 checkSitekey(); 625 checkSitekey();
618 window.updateStylesheet = init(document); 626 window.updateStylesheet = init(document);
619 } 627 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld