Skip to content

Commit

Permalink
Remove HTTPS Everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
arthuredelstein committed Sep 19, 2023
1 parent 4b30cbb commit 4a3244a
Show file tree
Hide file tree
Showing 49 changed files with 17 additions and 1,904 deletions.
1 change: 0 additions & 1 deletion android/android_browser_tests.gni
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ android_test_exception_sources = [
"//brave/components/brave_rewards/browser/test/rewards_promotion_browsertest.cc",
"//brave/components/brave_rewards/browser/test/rewards_publisher_browsertest.cc",
"//brave/components/brave_rewards/browser/test/rewards_state_browsertest.cc",
"//brave/components/brave_shields/browser/https_everywhere_service_browsertest.cc",
"//brave/components/brave_shields/browser/test_filters_provider.cc",
"//brave/components/content_settings/renderer/brave_content_settings_agent_impl_browsertest.cc",
"//brave/third_party/blink/renderer/modules/brave/navigator_browsertest.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class BraveShieldsContentSettings {
static public final String RESOURCE_IDENTIFIER_ADS = "shieldsAds";
static public final String RESOURCE_IDENTIFIER_TRACKERS = "trackers";
static public final String RESOURCE_IDENTIFIER_DATA_SAVED = "data_saved";
static public final String RESOURCE_IDENTIFIER_HTTP_UPGRADABLE_RESOURCES = "httpUpgradableResources";
static public final String RESOURCE_IDENTIFIER_BRAVE_SHIELDS = "braveShields";
static public final String RESOURCE_IDENTIFIER_FINGERPRINTING = "fingerprinting";
static public final String RESOURCE_IDENTIFIER_COOKIES = "shieldsCookies";
Expand Down Expand Up @@ -85,8 +84,6 @@ static public void setShields(Profile profile, String host, String resourceInden
String setting_string = (value ? BLOCK_RESOURCE : ALLOW_RESOURCE);
if (resourceIndentifier.equals(RESOURCE_IDENTIFIER_BRAVE_SHIELDS)) {
BraveShieldsContentSettingsJni.get().setBraveShieldsEnabled(value, host, profile);
} else if (resourceIndentifier.equals(RESOURCE_IDENTIFIER_HTTP_UPGRADABLE_RESOURCES)) {
BraveShieldsContentSettingsJni.get().setHTTPSEverywhereEnabled(value, host, profile);
} else if (resourceIndentifier.equals(RESOURCE_IDENTIFIER_JAVASCRIPTS)) {
BraveShieldsContentSettingsJni.get().setNoScriptControlType(setting_string, host, profile);
} else if (resourceIndentifier.equals(RESOURCE_IDENTIFIER_FORGET_FIRST_PARTY_STORAGE)) {
Expand Down Expand Up @@ -119,8 +116,6 @@ public static boolean getShields(Profile profile, String host, String resourceIn
String settings = BLOCK_RESOURCE;
if (resourceIndentifier.equals(RESOURCE_IDENTIFIER_BRAVE_SHIELDS)) {
return BraveShieldsContentSettingsJni.get().getBraveShieldsEnabled(host, profile);
} else if (resourceIndentifier.equals(RESOURCE_IDENTIFIER_HTTP_UPGRADABLE_RESOURCES)) {
return BraveShieldsContentSettingsJni.get().getHTTPSEverywhereEnabled(host, profile);
} else if (resourceIndentifier.equals(RESOURCE_IDENTIFIER_JAVASCRIPTS)) {
settings = BraveShieldsContentSettingsJni.get().getNoScriptControlType(host, profile);
} else if (resourceIndentifier.equals(RESOURCE_IDENTIFIER_FORGET_FIRST_PARTY_STORAGE)) {
Expand Down Expand Up @@ -151,12 +146,6 @@ public static String getShieldsValue(Profile profile, String host, String resour
return settings;
}

public static void setHTTPSEverywherePref(boolean value) {
setShields(Profile.getLastUsedRegularProfile(), "",
BraveShieldsContentSettings.RESOURCE_IDENTIFIER_HTTP_UPGRADABLE_RESOURCES, value,
false);
}

public static void setFingerprintingPref(String value) {
setShieldsValue(Profile.getLastUsedRegularProfile(), "",
BraveShieldsContentSettings.RESOURCE_IDENTIFIER_FINGERPRINTING, value, false);
Expand Down Expand Up @@ -208,11 +197,6 @@ public static String getHttpsUpgradePref() {
BraveShieldsContentSettings.RESOURCE_IDENTIFIER_HTTPS_UPGRADE);
}

public static boolean getHTTPSEverywherePref() {
return getShields(Profile.getLastUsedRegularProfile(), "",
BraveShieldsContentSettings.RESOURCE_IDENTIFIER_HTTP_UPGRADABLE_RESOURCES);
}

public static boolean getForgetFirstPartyStoragePref() {
return getShields(Profile.getLastUsedRegularProfile(), "",
BraveShieldsContentSettings.RESOURCE_IDENTIFIER_FORGET_FIRST_PARTY_STORAGE);
Expand Down Expand Up @@ -251,8 +235,6 @@ interface Natives {
String getCookieControlType(String url, Profile profile);
void setFingerprintingControlType(String type, String url, Profile profile);
String getFingerprintingControlType(String url, Profile profile);
void setHTTPSEverywhereEnabled(boolean enabled, String url, Profile profile);
boolean getHTTPSEverywhereEnabled(String url, Profile profile);
void setHttpsUpgradeControlType(String type, String url, Profile profile);
String getHttpsUpgradeControlType(String url, Profile profile);
void setNoScriptControlType(String type, String url, Profile profile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public class BravePrivacySettings extends PrivacySettings implements ConnectionE
private static final String PREF_OTHER_PRIVACY_SETTINGS_SECTION =
"other_privacy_settings_section";

private static final String PREF_HTTPSE = "httpse";
private static final String PREF_DE_AMP = "de_amp";
private static final String PREF_DEBOUNCE = "debounce";
private static final String PREF_IPFS_GATEWAY = "ipfs_gateway";
Expand Down Expand Up @@ -118,7 +117,7 @@ public class BravePrivacySettings extends PrivacySettings implements ConnectionE
private static final String[] NEW_PRIVACY_PREFERENCE_ORDER = {
PREF_BRAVE_SHIELDS_GLOBALS_SECTION, // shields globals section
PREF_SHIELDS_SUMMARY, PREF_BLOCK_TRACKERS_ADS, PREF_DE_AMP, PREF_DEBOUNCE,
PREF_HTTPS_UPGRADE, PREF_HTTPSE, PREF_HTTPS_FIRST_MODE, PREF_BLOCK_SCRIPTS,
PREF_HTTPS_UPGRADE, PREF_HTTPS_FIRST_MODE, PREF_BLOCK_SCRIPTS,
PREF_BLOCK_CROSS_SITE_COOKIES, PREF_FINGERPRINTING_PROTECTION,
PREF_FINGERPRINT_LANGUAGE, PREF_CONTENT_FILTERING, PREF_FORGET_FIRST_PARTY_STORAGE,
PREF_CLEAR_DATA_SECTION, // clear data automatically section
Expand Down Expand Up @@ -153,7 +152,6 @@ public class BravePrivacySettings extends PrivacySettings implements ConnectionE
private BraveDialogPreference mBlockCrosssiteCookies;
private ChromeSwitchPreference mShowAutocompleteInAddressBar;
private ChromeSwitchPreference mAutocompleteTopSites;
private ChromeSwitchPreference mHttpsePref;
private ChromeSwitchPreference mDeAmpPref;
private ChromeSwitchPreference mDebouncePref;
private ChromeSwitchPreference mHttpsFirstModePref;
Expand All @@ -173,7 +171,6 @@ public class BravePrivacySettings extends PrivacySettings implements ConnectionE
private ChromeSwitchPreference mHideYoutubeDistractingElementsPref;
private PreferenceCategory mSocialBlockingCategory;
private ChromeSwitchPreference mSocialBlockingGoogle;
private ChromeSwitchPreference mHttpsEverywhere;
private ChromeSwitchPreference mSocialBlockingFacebook;
private ChromeSwitchPreference mSocialBlockingTwitter;
private ChromeSwitchPreference mSocialBlockingLinkedin;
Expand Down Expand Up @@ -218,9 +215,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

initFilterListAndroidHandler();

mHttpsePref = (ChromeSwitchPreference) findPreference(PREF_HTTPSE);
mHttpsePref.setOnPreferenceChangeListener(this);

mDeAmpPref = (ChromeSwitchPreference) findPreference(PREF_DE_AMP);
mDeAmpPref.setOnPreferenceChangeListener(this);

Expand All @@ -238,8 +232,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

boolean httpsByDefaultIsEnabled =
ChromeFeatureList.isEnabled(BraveFeatureList.HTTPS_BY_DEFAULT);
mHttpsePref.setVisible(!httpsByDefaultIsEnabled);
mHttpsFirstModePref.setVisible(!httpsByDefaultIsEnabled && mHttpsePref.isChecked());
mHttpsFirstModePref.setVisible(!httpsByDefaultIsEnabled);
mHttpsUpgradePref.setVisible(httpsByDefaultIsEnabled);

mCanMakePayment = (ChromeSwitchPreference) findPreference(PREF_CAN_MAKE_PAYMENT);
Expand Down Expand Up @@ -410,27 +403,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
SharedPreferences.Editor sharedPreferencesEditor =
ContextUtils.getAppSharedPreferences().edit();
if (PREF_HTTPSE.equals(key)) {
boolean newValueBool = (boolean) newValue;
BraveShieldsContentSettings.setHTTPSEverywherePref(newValueBool);
mHttpsFirstModePref.setVisible(newValueBool);
if (newValueBool) {
// Restore state of HTTPS_ONLY_MODE.
UserPrefs.get(Profile.getLastUsedRegularProfile())
.setBoolean(Pref.HTTPS_ONLY_MODE_ENABLED,
ContextUtils.getAppSharedPreferences().getBoolean(
PREF_HTTPS_ONLY_MODE_ENABLED_SAVED_STATE, false));
mHttpsFirstModePref.setChecked(UserPrefs.get(Profile.getLastUsedRegularProfile())
.getBoolean(Pref.HTTPS_ONLY_MODE_ENABLED));
} else {
// Save state for HTTPS_ONLY_MODE and disable it.
sharedPreferencesEditor.putBoolean(PREF_HTTPS_ONLY_MODE_ENABLED_SAVED_STATE,
UserPrefs.get(Profile.getLastUsedRegularProfile())
.getBoolean(Pref.HTTPS_ONLY_MODE_ENABLED));
UserPrefs.get(Profile.getLastUsedRegularProfile())
.setBoolean(Pref.HTTPS_ONLY_MODE_ENABLED, newValueBool);
}
} else if (PREF_HTTPS_FIRST_MODE.equals(key)) {
if (PREF_HTTPS_FIRST_MODE.equals(key)) {
UserPrefs.get(Profile.getLastUsedRegularProfile())
.setBoolean(Pref.HTTPS_ONLY_MODE_ENABLED, (boolean) newValue);
} else if (PREF_HTTPS_UPGRADE.equals(key)) {
Expand Down Expand Up @@ -640,16 +613,12 @@ private void updateBravePreferences() {

mBlockScriptsPref.setChecked(BraveShieldsContentSettings.getJavascriptPref());

// HTTPSE and HTTPS only mode
final boolean httpseEnabled = BraveShieldsContentSettings.getHTTPSEverywherePref();
mHttpsePref.setChecked(httpseEnabled);
// HTTPS only mode
boolean httpsByDefaultIsEnabled =
ChromeFeatureList.isEnabled(BraveFeatureList.HTTPS_BY_DEFAULT);
mHttpsFirstModePref.setVisible(!httpsByDefaultIsEnabled && httpseEnabled);
mHttpsFirstModePref.setChecked(httpseEnabled
? UserPrefs.get(Profile.getLastUsedRegularProfile())
.getBoolean(Pref.HTTPS_ONLY_MODE_ENABLED)
: false);
mHttpsFirstModePref.setVisible(!httpsByDefaultIsEnabled);
mHttpsFirstModePref.setChecked(UserPrefs.get(Profile.getLastUsedRegularProfile())
.getBoolean(Pref.HTTPS_ONLY_MODE_ENABLED));

// IPFS Gateway
mIpfsGatewayPref.setChecked(BravePrivacySettingsIPFSUtils.getIPFSGatewayPref());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,13 @@ private static class BlockersInfo {
public BlockersInfo() {
mAdsBlocked = 0;
mTrackersBlocked = 0;
mHTTPSUpgrades = 0;
mScriptsBlocked = 0;
mFingerprintsBlocked = 0;
mBlockerNames = new ArrayList<String>();
}

public int mAdsBlocked;
public int mTrackersBlocked;
public int mHTTPSUpgrades;
public int mScriptsBlocked;
public int mFingerprintsBlocked;
public ArrayList<String> mBlockerNames;
Expand All @@ -100,8 +98,6 @@ public BlockersInfo() {
Collections.synchronizedMap(new HashMap<Integer, BlockersInfo>());
private ArrayList<Pair<String, String>> mResourceToCompanyNameList = new ArrayList<>();
private OnCheckedChangeListener mBraveShieldsAdsTrackingChangeListener;
private SwitchCompat mBraveShieldsHTTPSEverywhereSwitch;
private OnCheckedChangeListener mBraveShieldsHTTPSEverywhereChangeListener;
private SwitchCompat mBraveShieldsBlockingScriptsSwitch;
private OnCheckedChangeListener mBraveShieldsBlockingScriptsChangeListener;
private SwitchCompat mBraveShieldsForgetFirstPartyStorageSwitch;
Expand Down Expand Up @@ -213,8 +209,6 @@ public void addStat(int tabId, String block_type, String subresource) {
if (!BraveShieldsUtils.hasShieldsTooltipShown(BraveShieldsUtils.PREF_SHIELDS_TOOLTIP)) {
blockersInfo = addBlockerNames(blockersInfo, subresource);
}
} else if (block_type.equals(BraveShieldsContentSettings.RESOURCE_IDENTIFIER_HTTP_UPGRADABLE_RESOURCES)) {
blockersInfo.mHTTPSUpgrades++;
} else if (block_type.equals(BraveShieldsContentSettings.RESOURCE_IDENTIFIER_JAVASCRIPTS)) {
blockersInfo.mScriptsBlocked++;
} else if (block_type.equals(BraveShieldsContentSettings.RESOURCE_IDENTIFIER_FINGERPRINTING)) {
Expand Down Expand Up @@ -386,7 +380,7 @@ public void updateValues(int tabId) {
}
BlockersInfo blockersInfo = mTabsStat.get(tabId);
updateValues(blockersInfo.mAdsBlocked + blockersInfo.mTrackersBlocked,
blockersInfo.mHTTPSUpgrades, blockersInfo.mScriptsBlocked, blockersInfo.mFingerprintsBlocked);
blockersInfo.mScriptsBlocked, blockersInfo.mFingerprintsBlocked);
}

public int getAdsBlockedCount(int tabId) {
Expand All @@ -407,15 +401,6 @@ public int getTrackersBlockedCount(int tabId) {
return blockersInfo.mTrackersBlocked;
}

public int getHttpsUpgradeCount(int tabId) {
if (!mTabsStat.containsKey(tabId)) {
return 0;
}

BlockersInfo blockersInfo = mTabsStat.get(tabId);
return blockersInfo.mHTTPSUpgrades;
}

public ArrayList<String> getBlockerNamesList(int tabId) {
if (!mTabsStat.containsKey(tabId)) {
return new ArrayList<String>();
Expand All @@ -425,12 +410,11 @@ public ArrayList<String> getBlockerNamesList(int tabId) {
return blockersInfo.mBlockerNames;
}

public void updateValues(int adsAndTrackers, int httpsUpgrades, int scriptsBlocked, int fingerprintsBlocked) {
public void updateValues(int adsAndTrackers, int scriptsBlocked, int fingerprintsBlocked) {
if (mContext == null) {
return;
}
final int fadsAndTrackers = adsAndTrackers;
final int fhttpsUpgrades = httpsUpgrades;
final int fscriptsBlocked = scriptsBlocked;
final int ffingerprintsBlocked = fingerprintsBlocked;
((Activity)mContext).runOnUiThread(new Runnable() {
Expand All @@ -440,10 +424,8 @@ public void run() {
return;
}
try {
mSiteBlockCounterText.setText(String.valueOf(fadsAndTrackers
+ fhttpsUpgrades
+ fscriptsBlocked
+ ffingerprintsBlocked));
mSiteBlockCounterText.setText(String.valueOf(
fadsAndTrackers + fscriptsBlocked + ffingerprintsBlocked));
} catch (NullPointerException exc) {
// It means that the Bravery Panel was destroyed during the update, we just do nothing
}
Expand Down Expand Up @@ -748,14 +730,7 @@ public void onCheckedChanged(RadioGroup group, int checkedId) {
private void setUpSwitchLayouts() {
LinearLayout upgradeHttpsLayout =
mSecondaryLayout.findViewById(R.id.brave_shields_upgrade_https_id);
if (!ChromeFeatureList.isEnabled(BraveFeatureList.HTTPS_BY_DEFAULT)) {
TextView upgradeHttpsText =
upgradeHttpsLayout.findViewById(R.id.brave_shields_switch_text);
mBraveShieldsHTTPSEverywhereSwitch =
upgradeHttpsLayout.findViewById(R.id.brave_shields_switch);
upgradeHttpsText.setText(R.string.brave_shields_https_everywhere_switch);
setupHTTPSEverywhereSwitchClick(mBraveShieldsHTTPSEverywhereSwitch);
} else {
if (ChromeFeatureList.isEnabled(BraveFeatureList.HTTPS_BY_DEFAULT)) {
upgradeHttpsLayout.setVisibility(View.GONE);
}

Expand Down Expand Up @@ -885,55 +860,6 @@ private void setUpViews() {
setUpMainLayout();
}

private void setupHTTPSEverywhereSwitchClick(SwitchCompat braveShieldsHTTPSEverywhereSwitch) {
if (null == braveShieldsHTTPSEverywhereSwitch) {
return;
}
setupHTTPSEverywhereSwitch(braveShieldsHTTPSEverywhereSwitch, false);

mBraveShieldsHTTPSEverywhereChangeListener = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (0 != mHost.length()) {
BraveShieldsContentSettings.setShields(mProfile, mHost, BraveShieldsContentSettings.RESOURCE_IDENTIFIER_HTTP_UPGRADABLE_RESOURCES, isChecked, false);
if (null != mMenuObserver) {
mMenuObserver.onMenuTopShieldsChanged(isChecked, false);
}
}
}
};

braveShieldsHTTPSEverywhereSwitch.setOnCheckedChangeListener(mBraveShieldsHTTPSEverywhereChangeListener);
}

private void setupHTTPSEverywhereSwitch(
SwitchCompat braveShieldsHTTPSEverywhereSwitch, boolean fromTopSwitch) {
if (null == braveShieldsHTTPSEverywhereSwitch) {
return;
}
if (fromTopSwitch) {
// Prevents to fire an event when top shields changed
braveShieldsHTTPSEverywhereSwitch.setOnCheckedChangeListener(null);
}
if (0 != mHost.length()) {
if (BraveShieldsContentSettings.getShields(mProfile, mHost, BraveShieldsContentSettings.RESOURCE_IDENTIFIER_BRAVE_SHIELDS)) {
if (BraveShieldsContentSettings.getShields(mProfile, mHost, BraveShieldsContentSettings.RESOURCE_IDENTIFIER_HTTP_UPGRADABLE_RESOURCES)) {
braveShieldsHTTPSEverywhereSwitch.setChecked(true);
} else {
braveShieldsHTTPSEverywhereSwitch.setChecked(false);
}
braveShieldsHTTPSEverywhereSwitch.setEnabled(true);
} else {
braveShieldsHTTPSEverywhereSwitch.setChecked(false);
braveShieldsHTTPSEverywhereSwitch.setEnabled(false);
}
}
if (fromTopSwitch) {
braveShieldsHTTPSEverywhereSwitch.setOnCheckedChangeListener(mBraveShieldsHTTPSEverywhereChangeListener);
}
}

private void setupBlockingScriptsSwitchClick(SwitchCompat braveShieldsBlockingScriptsSwitch) {
if (null == braveShieldsBlockingScriptsSwitch) {
return;
Expand Down Expand Up @@ -1055,8 +981,9 @@ private void setupMainSwitchClick(SwitchCompat braveShieldsSwitch) {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (0 != mHost.length()) {
BraveShieldsContentSettings.setShields(mProfile, mHost, BraveShieldsContentSettings.RESOURCE_IDENTIFIER_BRAVE_SHIELDS, isChecked, false);
setupHTTPSEverywhereSwitch(mBraveShieldsHTTPSEverywhereSwitch, true);
BraveShieldsContentSettings.setShields(mProfile, mHost,
BraveShieldsContentSettings.RESOURCE_IDENTIFIER_BRAVE_SHIELDS,
isChecked, false);
setupBlockingScriptsSwitch(mBraveShieldsBlockingScriptsSwitch, true);
setupForgetFirstPartyStorageSwitch(
mBraveShieldsForgetFirstPartyStorageSwitch, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public void onMenuTopShieldsChanged(boolean isOn, boolean isTopShield) {
currentTab.reloadIgnoringCache();
if (null != mBraveShieldsHandler) {
// Clean the Bravery Panel
mBraveShieldsHandler.updateValues(0, 0, 0, 0);
mBraveShieldsHandler.updateValues(0, 0, 0);
}
}
});
Expand Down
Loading

0 comments on commit 4a3244a

Please sign in to comment.