Skip to content

Commit d1192a8

Browse files
committed
Merge pull request EFForg#2104 from semenko/reduce-https-listener
Cleanups & prep for reducing HTTPS listeners
2 parents b496918 + e074b6b commit d1192a8

4 files changed

Lines changed: 25 additions & 16 deletions

File tree

chromium/background.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* @param url: a relative URL to local XML
66
*/
7-
function getRuleXml(url) {
7+
function loadExtensionFile(url, returnType) {
88
var xhr = new XMLHttpRequest();
99
// Use blocking XHR to ensure everything is loaded by the time
1010
// we return.
@@ -14,14 +14,18 @@ function getRuleXml(url) {
1414
if (xhr.readyState != 4) {
1515
return;
1616
}
17-
return xhr.responseXML;
17+
if (returnType === 'xml') {
18+
return xhr.responseXML;
19+
}
20+
return xhr.responseText;
1821
}
1922

23+
2024
// Rules are loaded here
2125
var all_rules = new RuleSets(navigator.userAgent, LRUCache, localStorage);
22-
for (var i = 0; i < rule_list.length; i++) {
23-
all_rules.addFromXml(getRuleXml(rule_list[i]));
24-
}
26+
var rule_list = 'rules/default.rulesets';
27+
all_rules.addFromXml(loadExtensionFile(rule_list, 'xml'));
28+
2529

2630
var USER_RULE_KEY = 'userRules';
2731
// Records which tabId's are active in the HTTPS Switch Planner (see
@@ -504,7 +508,14 @@ function onBeforeRedirect(details) {
504508
}
505509

506510
// Registers the handler for requests
507-
wr.onBeforeRequest.addListener(onBeforeRequest, {urls: ["https://*/*", "http://*/*"]}, ["blocking"]);
511+
// We listen to all HTTP hosts, because RequestFilter can't handle tons of url restrictions.
512+
wr.onBeforeRequest.addListener(onBeforeRequest, {urls: ["http://*/*"]}, ["blocking"]);
513+
514+
// TODO: Listen only to the tiny subset of HTTPS hosts that we rewrite/downgrade.
515+
var httpsUrlsWeListenTo = ["https://*/*"];
516+
// See: https://developer.chrome.com/extensions/match_patterns
517+
wr.onBeforeRequest.addListener(onBeforeRequest, {urls: httpsUrlsWeListenTo}, ["blocking"]);
518+
508519

509520
// Try to catch redirect loops on URLs we've redirected to HTTPS.
510521
wr.onBeforeRedirect.addListener(onBeforeRedirect, {urls: ["https://*/*"]});

chromium/manifest.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"background": {
66
"scripts": [
77
"lru.js",
8-
"rule_list.js",
98
"rules.js",
109
"util.js",
1110
"background.js"

chromium/rule_list.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

chromium/util.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
VERB=1;
2-
DBUG=2;
3-
INFO=3;
4-
NOTE=4;
5-
WARN=5;
1+
"use strict";
2+
3+
var VERB=1;
4+
var DBUG=2;
5+
var INFO=3;
6+
var NOTE=4;
7+
var WARN=5;
68
// FYI: Logging everything is /very/ slow. Chrome will log & buffer
79
// these console logs even when the debug tools are closed. :(
810

911
// TODO: Add an easy UI to change the log level.
1012
// (Developers can just type DEFAULT_LOG_LEVEL=1 in the console)
11-
DEFAULT_LOG_LEVEL=4;
13+
var DEFAULT_LOG_LEVEL=4;
1214
console.log("Hey developer! Want to see more verbose logging?");
1315
console.log("Type this into the console: DEFAULT_LOG_LEVEL=1");
1416

0 commit comments

Comments
 (0)