Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Make HTTPS Everywhere always ON by default #18590

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions chromium/background-scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ async function initializeAllRules() {
* Load preferences. Structure is:
* {
* httpNowhere: Boolean,
* isExtensionEnabled: Boolean
* }
*/
var httpNowhereOn = false;
var isExtensionEnabled = true;
let disabledList = new Set();
let httpOnceList = new Set();

Expand Down Expand Up @@ -74,12 +72,10 @@ function initializeStoredGlobals() {
return new Promise(resolve => {
store.get({
httpNowhere: false,
globalEnabled: true,
enableMixedRulesets: false,
disabledList: []
}, function(item) {
httpNowhereOn = item.httpNowhere;
isExtensionEnabled = item.globalEnabled;
for (let disabledSite of item.disabledList) {
disabledList.add(disabledSite);
}
Expand Down Expand Up @@ -118,10 +114,6 @@ chrome.storage.onChanged.addListener(async function(changes, areaName) {
httpNowhereOn = changes.httpNowhere.newValue;
updateState();
}
if ('globalEnabled' in changes) {
isExtensionEnabled = changes.globalEnabled.newValue;
updateState();
}
if ('enableMixedRulesets' in changes) {
// Don't require users to restart the browsers
rules.settings.enableMixedRulesets = changes.enableMixedRulesets.newValue;
Expand Down Expand Up @@ -163,17 +155,14 @@ chrome.webNavigation.onCompleted.addListener(function() {
* Set the icon color correctly
* active: extension is enabled.
* blocking: extension is in "block all HTTP requests" mode.
* disabled: extension is disabled from the popup menu.
*/

function updateState () {
if (!chrome.tabs) return;

let iconState = 'active';

if (!isExtensionEnabled) {
iconState = 'disabled';
} else if (httpNowhereOn) {
if (httpNowhereOn) {
iconState = 'blocking';
}

Expand All @@ -192,7 +181,7 @@ function updateState () {
const tabUrl = new URL(tabs[0].url);
const host = util.getNormalisedHostname(tabUrl.host);

if (isExtensionDisabledOnSite(host) || iconState == "disabled") {
if (isExtensionDisabledOnSite(hostname)) {
if ('setIcon' in chrome.browserAction) {
chrome.browserAction.setIcon({
path: {
Expand Down Expand Up @@ -337,11 +326,6 @@ const newCancelUrl = originURL => `${cancelUrl}?originURL=${encodeURIComponent(o
* @param details of the handler, see Chrome doc
* */
function onBeforeRequest(details) {
// If HTTPSe has been disabled by the user, return immediately.
if (!isExtensionEnabled) {
return;
}

let uri = new URL(details.url);

// Normalise hosts with tailing dots, e.g. "www.example.com."
Expand Down Expand Up @@ -489,7 +473,7 @@ function onBeforeRequest(details) {
* @param changeInfo Cookie changed info, see Chrome doc
* */
function onCookieChanged(changeInfo) {
if (!changeInfo.removed && !changeInfo.cookie.secure && isExtensionEnabled) {
if (!changeInfo.removed && !changeInfo.cookie.secure) {
if (all_rules.shouldSecureCookie(changeInfo.cookie)) {
let cookie = {
name:changeInfo.cookie.name,
Expand Down Expand Up @@ -603,7 +587,7 @@ function onErrorOccurred(details) {
* @param details details for the chrome.webRequest (see chrome doc)
*/
function onHeadersReceived(details) {
if (isExtensionEnabled && httpNowhereOn) {
if (httpNowhereOn) {
// Do not upgrade the .onion requests in EASE mode,
// See https://github.com/EFForg/https-everywhere/pull/14600#discussion_r168072480
const uri = new URL(details.url);
Expand Down
9 changes: 0 additions & 9 deletions chromium/pages/popup/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@
</small>
</header>

<section id="disableButton" class="options settings_block" style="visibility: hidden;">
<div class="onoffswitch switch" aria-label="Toggle on or off">
<h1 id="onoffswitch_label" data-i18n="menu_globalEnable"></h1>
<span class="slider round"></span>
<input aria-hidden="true" id="onoffswitch" type="checkbox" checked> <label id="onoffswitch__label" for="onoffswitch">
</label>
</div>
</section>

<section id="HttpNowhere" class="options settings_block" style="visibility: hidden;">
<h1 id="HttpNowhere__header"></h1>
<input aria-hidden="true" id="http-nowhere-checkbox" type="checkbox"><label id="http-nowhere-checkbox_label" aria-label="Toggle on or off" for="http-nowhere-checkbox"></label>
Expand Down
7 changes: 1 addition & 6 deletions chromium/pages/popup/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,7 @@ input:checked+label:after {
clear: both;
}

#disableButton {
display: block;
}

#HttpNowhere h1,
#disableButton h1 {
#HttpNowhere h1 {
float: left;
}

Expand Down
36 changes: 1 addition & 35 deletions chromium/pages/popup/ux.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,39 +146,6 @@ function showHttpNowhereUI() {
});
};

// Change the UI to reflect extension enabled/disabled
function updateEnabledDisabledUI() {
getOption_('globalEnabled', true, function(item) {
e('onoffswitch').checked = item.globalEnabled;
e('disableButton').style.visibility = "visible";
// Hide or show the rules sections
if (item.globalEnabled) {
document.body.className = "";
e('onoffswitch_label').innerText = chrome.i18n.getMessage("menu_globalEnable");
showHttpNowhereUI();
} else {
document.body.className = "disabled";
e('onoffswitch_label').innerText = chrome.i18n.getMessage("menu_globalDisable");
}
});
}

// Toggle extension enabled/disabled status
function toggleEnabledDisabled() {
let extension_toggle_effect = function() {
updateEnabledDisabledUI();
// The extension state changed, give some time for toggle animation and reload tab
setTimeout(function() {
chrome.tabs.reload();
window.close();
}, 1500);
};

getOption_('globalEnabled', true, function(item) {
setOption_('globalEnabled', !item.globalEnabled, extension_toggle_effect);
});
}

/**
* @description Create the list of rules for a specific tab
* @param activeTab
Expand Down Expand Up @@ -220,8 +187,7 @@ document.addEventListener("DOMContentLoaded", function () {
});

// Set up the enabled/disabled switch & hide/show rules
updateEnabledDisabledUI();
e('onoffswitch').addEventListener('click', toggleEnabledDisabled);
showHttpNowhereUI();
e('http-nowhere-checkbox').addEventListener('click', toggleHttpNowhere, false);
e('RuleManagement__see_more--prompt').addEventListener('click', toggleSeeMore);

Expand Down
5 changes: 0 additions & 5 deletions test/selenium/test_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ def test_redirect(self):
self.driver.get(kittens_url)
self.assertTrue(self.driver.current_url.startswith('https'))

def test_no_redirect_when_disabled(self):
self.toggle_disabled()
self.driver.get(kittens_url)
self.assertEqual(self.driver.current_url, kittens_url) # not https

def test_httpnowhere_blocks(self):
# if self.shim.browser_type == 'firefox':
# raise unittest.SkipTest('broken on firefox')
Expand Down
24 changes: 0 additions & 24 deletions test/selenium/test_popup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,6 @@ def test_rule_shown(self):
checkbox_el = self.driver.find_element_by_id('stable_ruleset_1')
self.assertTrue(checkbox_el.is_selected())

def test_disable_enable(self):
selector = '#onoffswitch__label'
checkbox = 'onoffswitch'
var_name = 'background.state.isExtensionEnabled'

# disable https everywhere
with self.load_popup_for():
el = self.query_selector(selector)
# Using query_selector does not work here if element isn't "plainly" visible on page, fails on Chrome
checkbox_el = self.driver.find_element_by_id(checkbox)
self.assertTrue(checkbox_el.is_selected())
el.click() # disable

with self.load_popup_for():
el = self.query_selector(selector)
checkbox_el = self.driver.find_element_by_id(checkbox)
self.assertFalse(checkbox_el.is_selected())
el.click()

with self.load_popup_for():
el = self.query_selector(selector)
checkbox_el = self.driver.find_element_by_id(checkbox)
self.assertTrue(checkbox_el.is_selected())

def test_http_nowhere(self):
selector = '#http-nowhere-checkbox_label'
checkbox = 'http-nowhere-checkbox'
Expand Down