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

Side by Side Diff: lib/compat.js

Issue 29424786: Issue 5182 - fix IsConnectionAllowed (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created April 28, 2017, 2:42 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 | « include/AdblockPlus/JsEngine.h ('k') | src/FilterEngine.cpp » ('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 <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 }, 377 },
378 378
379 send: function(data) 379 send: function(data)
380 { 380 {
381 if (this.readyState != 1) 381 if (this.readyState != 1)
382 throw new Error("XMLHttpRequest.send() is being called before XMLHttpReque st.open()"); 382 throw new Error("XMLHttpRequest.send() is being called before XMLHttpReque st.open()");
383 if (typeof data != "undefined" && data) 383 if (typeof data != "undefined" && data)
384 throw new Error("Sending data to server is not supported"); 384 throw new Error("Sending data to server is not supported");
385 385
386 this.readyState = 3; 386 this.readyState = 3;
387 window._webRequest.GET(this._url, this._requestHeaders, function(result) 387
388 var onGetDone = function(result)
388 { 389 {
389 this.channel.status = result.status; 390 this.channel.status = result.status;
390 this.status = result.responseStatus; 391 this.status = result.responseStatus;
391 this.responseText = result.responseText; 392 this.responseText = result.responseText;
392 this._responseHeaders = result.responseHeaders; 393 this._responseHeaders = result.responseHeaders;
393 this.readyState = 4; 394 this.readyState = 4;
394 395
395 // Notify event listeners 396 // Notify event listeners
396 const NS_OK = 0; 397 const NS_OK = 0;
397 var eventName = (this.channel.status == NS_OK ? "load" : "error"); 398 var eventName = (this.channel.status == NS_OK ? "load" : "error");
398 var event = {type: eventName}; 399 var event = {type: eventName};
399 400
400 if (this["on" + eventName]) 401 if (this["on" + eventName])
401 this.onload.call(this, event); 402 this.onload.call(this, event);
402 403
403 var list = this["_" + eventName + "Handlers"]; 404 var list = this["_" + eventName + "Handlers"];
404 for (var i = 0; i < list.length; i++) 405 for (var i = 0; i < list.length; i++)
405 list[i].call(this, event); 406 list[i].call(this, event);
407 }.bind(this);
408 // HACK (#5066): the code checking whether the connection is allowed is temp orary,
409 // the actual check should be in the core when we make a decision whether
410 // to update a subscription with current connection or not, thus whether to
411 // even construct XMLHttpRequest object or not.
412 _isSubscriptionDownloadAllowed(function(isAllowed)
413 {
414 if (!isAllowed)
415 {
416 onGetDone({
417 status: 0x804b000d, //NS_ERROR_CONNECTION_REFUSED;
418 responseStatus: 0
419 });
420 return;
421 }
422 window._webRequest.GET(this._url, this._requestHeaders, onGetDone);
406 }.bind(this)); 423 }.bind(this));
407 }, 424 },
408 425
409 overrideMimeType: function(mime) 426 overrideMimeType: function(mime)
410 { 427 {
411 }, 428 },
412 429
413 setRequestHeader: function(name, value) 430 setRequestHeader: function(name, value)
414 { 431 {
415 if (this.readyState > 1) 432 if (this.readyState > 1)
(...skipping 21 matching lines...) Expand all
437 loadFlags: 0, 454 loadFlags: 0,
438 INHIBIT_CACHING: 0, 455 INHIBIT_CACHING: 0,
439 VALIDATE_ALWAYS: 0, 456 VALIDATE_ALWAYS: 0,
440 QueryInterface: function() 457 QueryInterface: function()
441 { 458 {
442 return this; 459 return this;
443 } 460 }
444 } 461 }
445 }; 462 };
446 463
464 function _isSubscriptionDownloadAllowed(callback) {
465 // It's a bit hacky, JsEngine interface which is used by FilterEngine does
466 // not allow to inject an arbitrary callback, so we use triggerEvent
467 // mechanism.
468 // Yet one hack (#5039).
469 var allowed_connection_type = require("prefs").Prefs.allowed_connection_type;
470 if (allowed_connection_type == "")
471 allowed_connection_type = null;
472 _triggerEvent("_isSubscriptionDownloadAllowed", allowed_connection_type, callb ack);
473 }
447 474
448 // Polyfill Array.prototype.find 475 // Polyfill Array.prototype.find
449 // from https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Ob jects/Array/find 476 // from https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Ob jects/Array/find
450 // https://tc39.github.io/ecma262/#sec-array.prototype.find 477 // https://tc39.github.io/ecma262/#sec-array.prototype.find
451 if (!Array.prototype.find) { 478 if (!Array.prototype.find) {
452 Object.defineProperty(Array.prototype, 'find', { 479 Object.defineProperty(Array.prototype, 'find', {
453 value: function (predicate) { 480 value: function (predicate) {
454 // 1. Let O be ? ToObject(this value). 481 // 1. Let O be ? ToObject(this value).
455 if (this == null) { 482 if (this == null) {
456 throw new TypeError('"this" is null or not defined'); 483 throw new TypeError('"this" is null or not defined');
(...skipping 24 matching lines...) Expand all
481 var kValue = o[k]; 508 var kValue = o[k];
482 if (predicate.call(thisArg, kValue, k, o)) { 509 if (predicate.call(thisArg, kValue, k, o)) {
483 return kValue; 510 return kValue;
484 } 511 }
485 // e. Increase k by 1. 512 // e. Increase k by 1.
486 k++; 513 k++;
487 } 514 }
488 } 515 }
489 }); 516 });
490 } 517 }
OLDNEW
« no previous file with comments | « include/AdblockPlus/JsEngine.h ('k') | src/FilterEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld