From 4a3244ab072e1622e73038f3c831ceeb4ce377bc Mon Sep 17 00:00:00 2001 From: Arthur Edelstein Date: Tue, 15 Aug 2023 10:11:15 -0700 Subject: [PATCH] Remove HTTPS Everywhere --- android/android_browser_tests.gni | 1 - .../website/BraveShieldsContentSettings.java | 18 - .../settings/BravePrivacySettings.java | 45 +-- .../browser/shields/BraveShieldsHandler.java | 89 +---- .../toolbar/top/BraveToolbarLayoutImpl.java | 2 +- .../res/xml/brave_privacy_preferences.xml | 5 - .../android/brave_shields_content_settings.cc | 21 - browser/brave_browser_process.h | 2 - browser/brave_browser_process_impl.cc | 12 - browser/brave_browser_process_impl.h | 5 - .../https_everywhere_component_installer.cc | 184 --------- .../https_everywhere_component_installer.h | 26 -- browser/brave_shields/sources.gni | 2 - .../brave_extension_provider_browsertest.cc | 1 - browser/net/BUILD.gn | 3 - .../brave_httpse_network_delegate_helper.cc | 105 ----- .../brave_httpse_network_delegate_helper.h | 18 - ...httpse_network_delegate_helper_unittest.cc | 56 --- browser/net/brave_request_handler.cc | 6 - browser/net/url_context.cc | 3 - .../default_brave_shields_browser_proxy.ts | 10 - .../default_brave_shields_page.ts | 4 - .../android/strings/android_brave_strings.grd | 6 - browser/ui/brave_shields_data_controller.cc | 13 - browser/ui/brave_shields_data_controller.h | 2 - .../shields_panel_data_handler.cc | 9 - .../shields_panel_data_handler.h | 1 - .../settings/default_brave_shields_handler.cc | 16 - .../settings/default_brave_shields_handler.h | 2 - chromium_presubmit_config.json5 | 3 - .../browser/component_updater/registration.cc | 2 - components/brave_shields/browser/BUILD.gn | 3 - .../browser/brave_shields_util.cc | 40 -- .../browser/brave_shields_util.h | 7 - .../browser/brave_shields_util_unittest.cc | 146 ------- .../https_everywhere_component_installer.cc | 167 -------- .../https_everywhere_component_installer.h | 27 -- .../https_everywhere_recently_used_cache.h | 45 --- ...verywhere_recently_used_cache_unittest.cpp | 30 -- .../browser/https_everywhere_service.cc | 375 ------------------ .../browser/https_everywhere_service.h | 113 ------ .../https_everywhere_service_browsertest.cc | 256 ------------ .../common/brave_shields_panel.mojom | 2 - .../advanced-controls-content/index.tsx | 26 -- .../panel/stories/component-panel.tsx | 1 - .../brave_content_settings_pref_provider.cc | 2 +- test/BUILD.gn | 2 - test/base/testing_brave_browser_process.cc | 6 - test/base/testing_brave_browser_process.h | 1 - 49 files changed, 17 insertions(+), 1904 deletions(-) delete mode 100644 browser/brave_shields/https_everywhere_component_installer.cc delete mode 100644 browser/brave_shields/https_everywhere_component_installer.h delete mode 100644 browser/net/brave_httpse_network_delegate_helper.cc delete mode 100644 browser/net/brave_httpse_network_delegate_helper.h delete mode 100644 browser/net/brave_httpse_network_delegate_helper_unittest.cc delete mode 100644 components/brave_shields/browser/https_everywhere_component_installer.cc delete mode 100644 components/brave_shields/browser/https_everywhere_component_installer.h delete mode 100644 components/brave_shields/browser/https_everywhere_recently_used_cache.h delete mode 100644 components/brave_shields/browser/https_everywhere_recently_used_cache_unittest.cpp delete mode 100644 components/brave_shields/browser/https_everywhere_service.cc delete mode 100644 components/brave_shields/browser/https_everywhere_service.h delete mode 100644 components/brave_shields/browser/https_everywhere_service_browsertest.cc diff --git a/android/android_browser_tests.gni b/android/android_browser_tests.gni index fc9233740d32..3cecb7aa3a23 100644 --- a/android/android_browser_tests.gni +++ b/android/android_browser_tests.gni @@ -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", diff --git a/android/java/org/chromium/chrome/browser/preferences/website/BraveShieldsContentSettings.java b/android/java/org/chromium/chrome/browser/preferences/website/BraveShieldsContentSettings.java index 668dc4628ab4..3c7d2ef86d58 100644 --- a/android/java/org/chromium/chrome/browser/preferences/website/BraveShieldsContentSettings.java +++ b/android/java/org/chromium/chrome/browser/preferences/website/BraveShieldsContentSettings.java @@ -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"; @@ -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)) { @@ -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)) { @@ -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); @@ -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); @@ -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); diff --git a/android/java/org/chromium/chrome/browser/privacy/settings/BravePrivacySettings.java b/android/java/org/chromium/chrome/browser/privacy/settings/BravePrivacySettings.java index 1d27a99633a6..dd2b3b4c38d6 100644 --- a/android/java/org/chromium/chrome/browser/privacy/settings/BravePrivacySettings.java +++ b/android/java/org/chromium/chrome/browser/privacy/settings/BravePrivacySettings.java @@ -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"; @@ -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 @@ -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; @@ -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; @@ -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); @@ -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); @@ -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)) { @@ -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()); diff --git a/android/java/org/chromium/chrome/browser/shields/BraveShieldsHandler.java b/android/java/org/chromium/chrome/browser/shields/BraveShieldsHandler.java index 7b5260322137..60f006a75303 100644 --- a/android/java/org/chromium/chrome/browser/shields/BraveShieldsHandler.java +++ b/android/java/org/chromium/chrome/browser/shields/BraveShieldsHandler.java @@ -77,7 +77,6 @@ private static class BlockersInfo { public BlockersInfo() { mAdsBlocked = 0; mTrackersBlocked = 0; - mHTTPSUpgrades = 0; mScriptsBlocked = 0; mFingerprintsBlocked = 0; mBlockerNames = new ArrayList(); @@ -85,7 +84,6 @@ public BlockersInfo() { public int mAdsBlocked; public int mTrackersBlocked; - public int mHTTPSUpgrades; public int mScriptsBlocked; public int mFingerprintsBlocked; public ArrayList mBlockerNames; @@ -100,8 +98,6 @@ public BlockersInfo() { Collections.synchronizedMap(new HashMap()); private ArrayList> mResourceToCompanyNameList = new ArrayList<>(); private OnCheckedChangeListener mBraveShieldsAdsTrackingChangeListener; - private SwitchCompat mBraveShieldsHTTPSEverywhereSwitch; - private OnCheckedChangeListener mBraveShieldsHTTPSEverywhereChangeListener; private SwitchCompat mBraveShieldsBlockingScriptsSwitch; private OnCheckedChangeListener mBraveShieldsBlockingScriptsChangeListener; private SwitchCompat mBraveShieldsForgetFirstPartyStorageSwitch; @@ -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)) { @@ -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) { @@ -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 getBlockerNamesList(int tabId) { if (!mTabsStat.containsKey(tabId)) { return new ArrayList(); @@ -425,12 +410,11 @@ public ArrayList 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() { @@ -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 } @@ -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); } @@ -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; @@ -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); diff --git a/android/java/org/chromium/chrome/browser/toolbar/top/BraveToolbarLayoutImpl.java b/android/java/org/chromium/chrome/browser/toolbar/top/BraveToolbarLayoutImpl.java index 6b2a266f2013..4085fc4814a4 100644 --- a/android/java/org/chromium/chrome/browser/toolbar/top/BraveToolbarLayoutImpl.java +++ b/android/java/org/chromium/chrome/browser/toolbar/top/BraveToolbarLayoutImpl.java @@ -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); } } }); diff --git a/android/java/res/xml/brave_privacy_preferences.xml b/android/java/res/xml/brave_privacy_preferences.xml index 1008f6968571..06c32ff63f4d 100644 --- a/android/java/res/xml/brave_privacy_preferences.xml +++ b/android/java/res/xml/brave_privacy_preferences.xml @@ -22,11 +22,6 @@ app:dialog_entries="@array/blockTrackersAdsTexts" app:dialog_default_index="1" /> - & url, - const base::android::JavaParamRef& j_profile) { - brave_shields::SetHTTPSEverywhereEnabled( - HostContentSettingsMapFactory::GetForProfile( - ProfileAndroid::FromProfileAndroid(j_profile)), - enabled, - GURL(base::android::ConvertJavaStringToUTF8(env, url)), - g_browser_process->local_state()); -} - -jboolean JNI_BraveShieldsContentSettings_GetHTTPSEverywhereEnabled(JNIEnv* env, - const base::android::JavaParamRef& url, - const base::android::JavaParamRef& j_profile) { - return brave_shields::GetHTTPSEverywhereEnabled( - HostContentSettingsMapFactory::GetForProfile( - ProfileAndroid::FromProfileAndroid(j_profile)), - GURL(base::android::ConvertJavaStringToUTF8(env, url))); -} - void JNI_BraveShieldsContentSettings_SetNoScriptControlType(JNIEnv* env, const base::android::JavaParamRef& type, const base::android::JavaParamRef& url, diff --git a/browser/brave_browser_process.h b/browser/brave_browser_process.h index 6a71cf05c5f4..08d9a4014d00 100644 --- a/browser/brave_browser_process.h +++ b/browser/brave_browser_process.h @@ -38,7 +38,6 @@ class LocalDataFilesService; namespace brave_shields { class AdBlockService; -class HTTPSEverywhereService; } // namespace brave_shields namespace brave_stats { @@ -121,7 +120,6 @@ class BraveBrowserProcess { #endif virtual brave::URLSanitizerComponentInstaller* URLSanitizerComponentInstaller() = 0; - virtual brave_shields::HTTPSEverywhereService* https_everywhere_service() = 0; virtual brave_component_updater::LocalDataFilesService* local_data_files_service() = 0; #if BUILDFLAG(ENABLE_TOR) diff --git a/browser/brave_browser_process_impl.cc b/browser/brave_browser_process_impl.cc index a15bf9c044a9..587817fc5c40 100644 --- a/browser/brave_browser_process_impl.cc +++ b/browser/brave_browser_process_impl.cc @@ -31,7 +31,6 @@ #include "brave/components/brave_shields/browser/ad_block_service.h" #include "brave/components/brave_shields/browser/ad_block_subscription_service_manager.h" #include "brave/components/brave_shields/browser/brave_farbling_service.h" -#include "brave/components/brave_shields/browser/https_everywhere_service.h" #include "brave/components/brave_shields/common/features.h" #include "brave/components/brave_sync/network_time_helper.h" #include "brave/components/constants/pref_names.h" @@ -214,7 +213,6 @@ ProfileManager* BraveBrowserProcessImpl::profile_manager() { void BraveBrowserProcessImpl::StartBraveServices() { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - https_everywhere_service()->Start(); resource_component(); if (base::FeatureList::IsEnabled(net::features::kBraveHttpsByDefault)) { @@ -346,16 +344,6 @@ BraveBrowserProcessImpl::URLSanitizerComponentInstaller() { return url_sanitizer_component_installer_.get(); } -brave_shields::HTTPSEverywhereService* -BraveBrowserProcessImpl::https_everywhere_service() { - if (!created_https_everywhere_service_) { - https_everywhere_service_ = brave_shields::HTTPSEverywhereServiceFactory( - brave_component_updater_delegate()->GetTaskRunner()); - created_https_everywhere_service_ = true; - } - return https_everywhere_service_.get(); -} - brave_component_updater::LocalDataFilesService* BraveBrowserProcessImpl::local_data_files_service() { if (!local_data_files_service_) { diff --git a/browser/brave_browser_process_impl.h b/browser/brave_browser_process_impl.h index ce055164c59a..03427fe43d6a 100644 --- a/browser/brave_browser_process_impl.h +++ b/browser/brave_browser_process_impl.h @@ -33,7 +33,6 @@ class LocalDataFilesService; namespace brave_shields { class AdBlockService; -class HTTPSEverywhereService; } // namespace brave_shields namespace https_upgrade_exceptions { @@ -126,7 +125,6 @@ class BraveBrowserProcessImpl : public BraveBrowserProcess, #endif brave::URLSanitizerComponentInstaller* URLSanitizerComponentInstaller() override; - brave_shields::HTTPSEverywhereService* https_everywhere_service() override; brave_component_updater::LocalDataFilesService* local_data_files_service() override; #if BUILDFLAG(ENABLE_TOR) @@ -199,9 +197,6 @@ class BraveBrowserProcessImpl : public BraveBrowserProcess, #endif std::unique_ptr url_sanitizer_component_installer_; - bool created_https_everywhere_service_ = false; - std::unique_ptr - https_everywhere_service_; std::unique_ptr brave_stats_updater_; std::unique_ptr brave_referrals_service_; #if BUILDFLAG(ENABLE_TOR) diff --git a/browser/brave_shields/https_everywhere_component_installer.cc b/browser/brave_shields/https_everywhere_component_installer.cc deleted file mode 100644 index 0f8f5bd18a23..000000000000 --- a/browser/brave_shields/https_everywhere_component_installer.cc +++ /dev/null @@ -1,184 +0,0 @@ -/* Copyright (c) 2021 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "brave/browser/brave_shields/https_everywhere_component_installer.h" - -#include -#include -#include - -#include "base/base64.h" -#include "base/functional/bind.h" -#include "base/functional/callback.h" -#include "base/no_destructor.h" -#include "brave/browser/brave_browser_process.h" -#include "brave/components/brave_component_updater/browser/brave_on_demand_updater.h" -#include "brave/components/brave_shields/browser/https_everywhere_service.h" -#include "chrome/browser/browser_process.h" -#include "components/component_updater/component_installer.h" -#include "components/component_updater/component_updater_service.h" -#include "crypto/sha2.h" - -using brave_component_updater::BraveOnDemandUpdater; - -namespace brave_shields { - -namespace { - -constexpr size_t kHashSize = 32; -const char kHTTPSEverywhereComponentName[] = "Brave HTTPS Everywhere Updater"; -const char kHTTPSEverywhereComponentId[] = "oofiananboodjbbmdelgdommihjbkfag"; -const char kHTTPSEverywhereComponentBase64PublicKey[] = - "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvn9zSMjTmhkQyrZu5UdN" - "350nPqLoSeCYngcC7yDFwaUHjoBQXCZqGeDC69ciCQ2mlRhcV2nxXqlUDkiC6+7m" - "651nI+gi4oVqHagc7EFUyGA0yuIk7qIMvCBdH7wbET27de0rzbRzRht9EKzEjIhC" - "BtoPnmyrO/8qPrH4XR4cPfnFPuJssBBxC1B35H7rh0Br9qePhPDDe9OjyqYxPuio" - "+YcC9obL4g5krVrfrlKLfFNpIewUcJyBpSlCgfxEyEhgDkK9cILTMUi5vC7GxS3P" - "OtZqgfRg8Da4i+NwmjQqrz0JFtPMMSyUnmeMj+mSOL4xZVWr8fU2/GOCXs9gczDp" - "JwIDAQAB"; - -class HTTPSEverywhereComponentInstallerPolicy - : public component_updater::ComponentInstallerPolicy { - public: - HTTPSEverywhereComponentInstallerPolicy(); - ~HTTPSEverywhereComponentInstallerPolicy() override; - - HTTPSEverywhereComponentInstallerPolicy( - const HTTPSEverywhereComponentInstallerPolicy&) = delete; - HTTPSEverywhereComponentInstallerPolicy& operator=( - const HTTPSEverywhereComponentInstallerPolicy&) = delete; - - // component_updater::ComponentInstallerPolicy - bool SupportsGroupPolicyEnabledComponentUpdates() const override; - bool RequiresNetworkEncryption() const override; - update_client::CrxInstaller::Result OnCustomInstall( - const base::Value::Dict& manifest, - const base::FilePath& install_dir) override; - void OnCustomUninstall() override; - bool VerifyInstallation(const base::Value::Dict& manifest, - const base::FilePath& install_dir) const override; - void ComponentReady(const base::Version& version, - const base::FilePath& path, - base::Value::Dict manifest) override; - base::FilePath GetRelativeInstallDir() const override; - void GetHash(std::vector* hash) const override; - std::string GetName() const override; - update_client::InstallerAttributes GetInstallerAttributes() const override; - - static base::NoDestructor g_https_everywhere_component_id_; - static base::NoDestructor - g_https_everywhere_component_base64_public_key_; - - private: - const std::string component_id_; - const std::string component_name_; - uint8_t component_hash_[kHashSize]; -}; - -base::NoDestructor - HTTPSEverywhereComponentInstallerPolicy::g_https_everywhere_component_id_( - kHTTPSEverywhereComponentId); -base::NoDestructor HTTPSEverywhereComponentInstallerPolicy:: - g_https_everywhere_component_base64_public_key_( - kHTTPSEverywhereComponentBase64PublicKey); - -HTTPSEverywhereComponentInstallerPolicy:: - HTTPSEverywhereComponentInstallerPolicy() - : component_id_(kHTTPSEverywhereComponentId), - component_name_(kHTTPSEverywhereComponentName) { - // Generate hash from public key. - std::string decoded_public_key; - base::Base64Decode(kHTTPSEverywhereComponentBase64PublicKey, - &decoded_public_key); - crypto::SHA256HashString(decoded_public_key, component_hash_, kHashSize); -} - -HTTPSEverywhereComponentInstallerPolicy:: - ~HTTPSEverywhereComponentInstallerPolicy() = default; - -bool HTTPSEverywhereComponentInstallerPolicy:: - SupportsGroupPolicyEnabledComponentUpdates() const { - return true; -} - -bool HTTPSEverywhereComponentInstallerPolicy::RequiresNetworkEncryption() - const { - return false; -} - -update_client::CrxInstaller::Result -HTTPSEverywhereComponentInstallerPolicy::OnCustomInstall( - const base::Value::Dict& manifest, - const base::FilePath& install_dir) { - return update_client::CrxInstaller::Result(0); -} - -void HTTPSEverywhereComponentInstallerPolicy::OnCustomUninstall() {} - -void HTTPSEverywhereComponentInstallerPolicy::ComponentReady( - const base::Version& version, - const base::FilePath& path, - base::Value::Dict manifest) { - if (g_browser_process->IsShuttingDown()) - return; - - g_brave_browser_process->https_everywhere_service()->InitDB(path); -} - -bool HTTPSEverywhereComponentInstallerPolicy::VerifyInstallation( - const base::Value::Dict& manifest, - const base::FilePath& install_dir) const { - return true; -} - -base::FilePath HTTPSEverywhereComponentInstallerPolicy::GetRelativeInstallDir() - const { - return base::FilePath::FromUTF8Unsafe(component_id_); -} - -void HTTPSEverywhereComponentInstallerPolicy::GetHash( - std::vector* hash) const { - hash->assign(component_hash_, component_hash_ + kHashSize); -} - -std::string HTTPSEverywhereComponentInstallerPolicy::GetName() const { - return component_name_; -} - -update_client::InstallerAttributes -HTTPSEverywhereComponentInstallerPolicy::GetInstallerAttributes() const { - return update_client::InstallerAttributes(); -} - -void OnRegistered() { - BraveOnDemandUpdater::GetInstance()->OnDemandUpdate( - kHTTPSEverywhereComponentId); -} - -} // namespace - -// static -void SetHTTPSEverywhereComponentIdAndBase64PublicKeyForTest( - const std::string& component_id, - const std::string& component_base64_public_key) { - *HTTPSEverywhereComponentInstallerPolicy::g_https_everywhere_component_id_ = - component_id; - *HTTPSEverywhereComponentInstallerPolicy:: - g_https_everywhere_component_base64_public_key_ = - component_base64_public_key; -} - -void RegisterHTTPSEverywhereComponent( - component_updater::ComponentUpdateService* cus) { - // In test, |cus| could be nullptr. - if (!cus) - return; - - auto installer = base::MakeRefCounted( - std::make_unique()); - installer->Register(cus, base::BindOnce(&OnRegistered)); -} - -} // namespace brave_shields diff --git a/browser/brave_shields/https_everywhere_component_installer.h b/browser/brave_shields/https_everywhere_component_installer.h deleted file mode 100644 index fd9c471342b1..000000000000 --- a/browser/brave_shields/https_everywhere_component_installer.h +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright (c) 2021 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_BROWSER_BRAVE_SHIELDS_HTTPS_EVERYWHERE_COMPONENT_INSTALLER_H_ -#define BRAVE_BROWSER_BRAVE_SHIELDS_HTTPS_EVERYWHERE_COMPONENT_INSTALLER_H_ - -#include - -namespace component_updater { -class ComponentUpdateService; -} // namespace component_updater - -namespace brave_shields { - -void SetHTTPSEverywhereComponentIdAndBase64PublicKeyForTest( - const std::string& component_id, - const std::string& component_base64_public_key); - -void RegisterHTTPSEverywhereComponent( - component_updater::ComponentUpdateService* cus); - -} // namespace brave_shields - -#endif // BRAVE_BROWSER_BRAVE_SHIELDS_HTTPS_EVERYWHERE_COMPONENT_INSTALLER_H_ diff --git a/browser/brave_shields/sources.gni b/browser/brave_shields/sources.gni index e7a19b819842..d11bce61ab2e 100644 --- a/browser/brave_shields/sources.gni +++ b/browser/brave_shields/sources.gni @@ -14,8 +14,6 @@ brave_browser_brave_shields_sources = [ "//brave/browser/brave_shields/cookie_list_opt_in_service_factory.h", "//brave/browser/brave_shields/filter_list_service_factory.cc", "//brave/browser/brave_shields/filter_list_service_factory.h", - "//brave/browser/brave_shields/https_everywhere_component_installer.cc", - "//brave/browser/brave_shields/https_everywhere_component_installer.h", ] brave_browser_brave_shields_deps = [ diff --git a/browser/extensions/brave_extension_provider_browsertest.cc b/browser/extensions/brave_extension_provider_browsertest.cc index 3796aa92be2c..73f9821311f2 100644 --- a/browser/extensions/brave_extension_provider_browsertest.cc +++ b/browser/extensions/brave_extension_provider_browsertest.cc @@ -7,7 +7,6 @@ #include "base/strings/utf_string_conversions.h" #include "base/test/thread_test_helper.h" #include "brave/browser/extensions/brave_extension_functional_test.h" -#include "brave/components/brave_shields/browser/https_everywhere_service.h" #include "brave/components/constants/brave_paths.h" #include "brave/components/constants/pref_names.h" #include "brave/components/constants/url_constants.h" diff --git a/browser/net/BUILD.gn b/browser/net/BUILD.gn index b53539ddf8a3..1c9a27c6e8b1 100644 --- a/browser/net/BUILD.gn +++ b/browser/net/BUILD.gn @@ -36,8 +36,6 @@ source_set("net") { "brave_block_safebrowsing_urls.h", "brave_common_static_redirect_network_delegate_helper.cc", "brave_common_static_redirect_network_delegate_helper.h", - "brave_httpse_network_delegate_helper.cc", - "brave_httpse_network_delegate_helper.h", "brave_localhost_permission_network_delegate_helper.cc", "brave_localhost_permission_network_delegate_helper.h", "brave_proxying_url_loader_factory.cc", @@ -190,7 +188,6 @@ source_set("unit_tests") { "brave_ads_status_header_network_delegate_helper_unittest.cc", "brave_block_safebrowsing_urls_unittest.cc", "brave_common_static_redirect_network_delegate_helper_unittest.cc", - "brave_httpse_network_delegate_helper_unittest.cc", "brave_network_delegate_base_unittest.cc", "brave_site_hacks_network_delegate_helper_unittest.cc", "brave_static_redirect_network_delegate_helper_unittest.cc", diff --git a/browser/net/brave_httpse_network_delegate_helper.cc b/browser/net/brave_httpse_network_delegate_helper.cc deleted file mode 100644 index a742991a380c..000000000000 --- a/browser/net/brave_httpse_network_delegate_helper.cc +++ /dev/null @@ -1,105 +0,0 @@ -/* Copyright 2019 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "brave/browser/net/brave_httpse_network_delegate_helper.h" - -#include -#include -#include - -#include "base/threading/scoped_blocking_call.h" -#include "brave/browser/brave_browser_process.h" -#include "brave/browser/brave_shields/brave_shields_web_contents_observer.h" -#include "brave/components/brave_shields/browser/https_everywhere_service.h" -#include "brave/components/brave_shields/common/brave_shield_constants.h" -#include "content/public/browser/browser_thread.h" -#include "net/base/net_errors.h" - -using brave_shields::BraveShieldsWebContentsObserver; -using content::BrowserThread; - -namespace brave { - -void OnBeforeURLRequest_HttpseFileWork( - base::WeakPtr engine, - std::shared_ptr ctx) { - base::ScopedBlockingCall scoped_blocking_call(FROM_HERE, - base::BlockingType::WILL_BLOCK); - DCHECK_NE(ctx->request_identifier, 0U); - if (engine) - engine->GetHTTPSURL(&ctx->request_url, ctx->request_identifier, - &ctx->new_url_spec); -} - -void OnBeforeURLRequest_HttpsePostFileWork( - const ResponseCallback& next_callback, - std::shared_ptr ctx) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - - if (!ctx->new_url_spec.empty() && - ctx->new_url_spec != ctx->request_url.spec()) { - brave_shields::BraveShieldsWebContentsObserver::DispatchBlockedEvent( - ctx->request_url, ctx->frame_tree_node_id, - brave_shields::kHTTPUpgradableResources); - } - - next_callback.Run(); -} - -int OnBeforeURLRequest_HttpsePreFileWork( - const ResponseCallback& next_callback, - std::shared_ptr ctx) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - - // Don't try to overwrite an already set URL by another delegate (adblock/tp) - if (!ctx->new_url_spec.empty() || !ctx->mock_data_url.empty()) { - return net::OK; - } - - if (ctx->tab_origin.is_empty() || ctx->allow_http_upgradable_resource || - !ctx->allow_brave_shields) { - return net::OK; - } - - bool is_valid_url = true; - is_valid_url = ctx->request_url.is_valid(); - std::string scheme = ctx->request_url.scheme(); - if (scheme.length()) { - std::transform(scheme.begin(), scheme.end(), scheme.begin(), ::tolower); - if ("http" != scheme && "https" != scheme) { - is_valid_url = false; - } - } - - if (is_valid_url) { - if (!g_brave_browser_process->https_everywhere_service() - ->GetHTTPSURLFromCacheOnly(&ctx->request_url, - ctx->request_identifier, - &ctx->new_url_spec)) { - g_brave_browser_process->https_everywhere_service() - ->GetTaskRunner() - ->PostTaskAndReply( - FROM_HERE, - base::BindOnce( - OnBeforeURLRequest_HttpseFileWork, - g_brave_browser_process->https_everywhere_service()->engine(), - ctx), - base::BindOnce( - base::IgnoreResult(&OnBeforeURLRequest_HttpsePostFileWork), - next_callback, ctx)); - return net::ERR_IO_PENDING; - } else { - if (!ctx->new_url_spec.empty()) { - brave_shields::BraveShieldsWebContentsObserver::DispatchBlockedEvent( - ctx->request_url, ctx->frame_tree_node_id, - brave_shields::kHTTPUpgradableResources); - } - } - } - - return net::OK; -} - -} // namespace brave diff --git a/browser/net/brave_httpse_network_delegate_helper.h b/browser/net/brave_httpse_network_delegate_helper.h deleted file mode 100644 index 880a6dd8ccfc..000000000000 --- a/browser/net/brave_httpse_network_delegate_helper.h +++ /dev/null @@ -1,18 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_BROWSER_NET_BRAVE_HTTPSE_NETWORK_DELEGATE_H_ -#define BRAVE_BROWSER_NET_BRAVE_HTTPSE_NETWORK_DELEGATE_H_ - -#include "brave/browser/net/url_context.h" - -namespace brave { - -int OnBeforeURLRequest_HttpsePreFileWork( - const ResponseCallback& next_callback, - std::shared_ptr ctx); - -} // namespace brave - -#endif // BRAVE_BROWSER_NET_BRAVE_NETWORK_DELEGATE_H_ diff --git a/browser/net/brave_httpse_network_delegate_helper_unittest.cc b/browser/net/brave_httpse_network_delegate_helper_unittest.cc deleted file mode 100644 index 10db0b3c617c..000000000000 --- a/browser/net/brave_httpse_network_delegate_helper_unittest.cc +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright (c) 2019 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include - -#include "brave/browser/net/brave_httpse_network_delegate_helper.h" - -#include "brave/browser/net/url_context.h" -#include "brave/components/constants/network_constants.h" -#include "chrome/test/base/chrome_render_view_host_test_harness.h" -#include "content/public/test/browser_task_environment.h" -#include "net/cookies/site_for_cookies.h" -#include "net/traffic_annotation/network_traffic_annotation_test_helper.h" -#include "net/url_request/url_request_context.h" -#include "net/url_request/url_request_context_builder.h" -#include "net/url_request/url_request_test_util.h" - -namespace { - -class BraveHTTPSENetworkDelegateHelperTest: public testing::Test { - public: - BraveHTTPSENetworkDelegateHelperTest() - : task_environment_(content::BrowserTaskEnvironment::IO_MAINLOOP) {} - ~BraveHTTPSENetworkDelegateHelperTest() override = default; - void SetUp() override { - context_ = net::CreateTestURLRequestContextBuilder()->Build(); - } - net::URLRequestContext* context() { return context_.get(); } - - private: - content::BrowserTaskEnvironment task_environment_; - std::unique_ptr context_; -}; - - -TEST_F(BraveHTTPSENetworkDelegateHelperTest, AlreadySetNewURLNoOp) { - net::TestDelegate test_delegate; - GURL url("http://bradhatesprimes.brave.com/composite_numbers_ftw"); - std::unique_ptr request = - context()->CreateRequest(url, net::IDLE, &test_delegate, - TRAFFIC_ANNOTATION_FOR_TESTS); - std::shared_ptr - brave_request_info(new brave::BraveRequestInfo()); - request->set_site_for_cookies(net::SiteForCookies::FromUrl( - GURL("http://brad.brave.com/hide_all_primes_in_ui/composites_forever"))); - brave_request_info->new_url_spec = "data:image/png;base64,iVB"; - brave::ResponseCallback callback; - int ret = - OnBeforeURLRequest_HttpsePreFileWork(callback, brave_request_info); - EXPECT_EQ(brave_request_info->new_url_spec, brave_request_info->new_url_spec); - EXPECT_EQ(ret, net::OK); -} - -} // namespace diff --git a/browser/net/brave_request_handler.cc b/browser/net/brave_request_handler.cc index 42a603011cef..88c9f07d7f9b 100644 --- a/browser/net/brave_request_handler.cc +++ b/browser/net/brave_request_handler.cc @@ -14,7 +14,6 @@ #include "brave/browser/net/brave_ad_block_tp_network_delegate_helper.h" #include "brave/browser/net/brave_ads_status_header_network_delegate_helper.h" #include "brave/browser/net/brave_common_static_redirect_network_delegate_helper.h" -#include "brave/browser/net/brave_httpse_network_delegate_helper.h" #include "brave/browser/net/brave_localhost_permission_network_delegate_helper.h" #include "brave/browser/net/brave_reduce_language_network_delegate_helper.h" #include "brave/browser/net/brave_referrals_network_delegate_helper.h" @@ -70,11 +69,6 @@ void BraveRequestHandler::SetupCallbacks() { callback = base::BindRepeating(brave::OnBeforeURLRequest_AdBlockTPPreWork); before_url_request_callbacks_.push_back(callback); - if (!base::FeatureList::IsEnabled(net::features::kBraveHttpsByDefault)) { - callback = base::BindRepeating(brave::OnBeforeURLRequest_HttpsePreFileWork); - before_url_request_callbacks_.push_back(callback); - } - callback = base::BindRepeating(brave::OnBeforeURLRequest_CommonStaticRedirectWork); before_url_request_callbacks_.push_back(callback); diff --git a/browser/net/url_context.cc b/browser/net/url_context.cc index 98c26da447d4..5c3a0c7be029 100644 --- a/browser/net/url_context.cc +++ b/browser/net/url_context.cc @@ -150,9 +150,6 @@ std::shared_ptr BraveRequestInfo::MakeCTX( map ? brave_shields::GetCosmeticFilteringControlType( map, ctx->tab_origin) == brave_shields::ControlType::BLOCK : false; - ctx->allow_http_upgradable_resource = - map ? !brave_shields::GetHTTPSEverywhereEnabled(map, ctx->tab_origin) - : false; // HACK: after we fix multiple creations of BraveRequestInfo we should // use only tab_origin. Since we recreate BraveRequestInfo during consequent diff --git a/browser/resources/settings/default_brave_shields_page/default_brave_shields_browser_proxy.ts b/browser/resources/settings/default_brave_shields_page/default_brave_shields_browser_proxy.ts index 02ff159b700f..0e478fc7bd21 100644 --- a/browser/resources/settings/default_brave_shields_page/default_brave_shields_browser_proxy.ts +++ b/browser/resources/settings/default_brave_shields_page/default_brave_shields_browser_proxy.ts @@ -46,11 +46,6 @@ export interface DefaultBraveShieldsBrowserProxy { */ setFingerprintingControlType(value) - /** - * @param {string} value name. - */ - setHTTPSEverywhereEnabled(value) - /** * @return {!Promise} */ @@ -116,11 +111,6 @@ export class DefaultBraveShieldsBrowserProxyImpl implements DefaultBraveShieldsB chrome.send('setFingerprintingControlType', [value]); } - /** @override */ - setHTTPSEverywhereEnabled(value) { - chrome.send('setHTTPSEverywhereEnabled', [value]); - } - /** @override */ getHttpsUpgradeControlType() { return sendWithPromise('getHttpsUpgradeControlType'); diff --git a/browser/resources/settings/default_brave_shields_page/default_brave_shields_page.ts b/browser/resources/settings/default_brave_shields_page/default_brave_shields_page.ts index 860eb86c3cb1..b6b8e257a1b3 100644 --- a/browser/resources/settings/default_brave_shields_page/default_brave_shields_page.ts +++ b/browser/resources/settings/default_brave_shields_page/default_brave_shields_page.ts @@ -197,10 +197,6 @@ class BraveShieldsPage extends BraveShieldsPageBase { this.browserProxy_.setFingerprintingControlType(this.$.fingerprintingControlType.value) } - onHTTPSEverywhereControlChange_ () { - this.browserProxy_.setHTTPSEverywhereEnabled(this.$.httpsEverywhereControlType.checked) - } - onHttpsUpgradeControlChange_ () { this.browserProxy_.setHttpsUpgradeControlType( this.$.httpsUpgradeControlType.value) diff --git a/browser/ui/android/strings/android_brave_strings.grd b/browser/ui/android/strings/android_brave_strings.grd index 99adfa57974b..9b9eb8e03912 100644 --- a/browser/ui/android/strings/android_brave_strings.grd +++ b/browser/ui/android/strings/android_brave_strings.grd @@ -395,9 +395,6 @@ This file contains all "about" strings. It is set to NOT be translated, in tran Turn on notifications - - Upgrade connections to HTTPS - Brave collects 5% of the sent amount as a processing fee. @@ -413,9 +410,6 @@ This file contains all "about" strings. It is set to NOT be translated, in tran I just contributed %1$sContributionAmount BAT using the Brave Browser. See how you can support your favorite creators and sites too: https://brave.com/rewards - - Opens some sites using a secure HTTPS connection instead of plain HTTP. - Auto-redirect AMP pages diff --git a/browser/ui/brave_shields_data_controller.cc b/browser/ui/brave_shields_data_controller.cc index 687e65e89bd2..f97708f0e0c2 100644 --- a/browser/ui/brave_shields_data_controller.cc +++ b/browser/ui/brave_shields_data_controller.cc @@ -244,11 +244,6 @@ CookieBlockMode BraveShieldsDataController::GetCookieBlockMode() { return CookieBlockMode::BLOCKED; } -bool BraveShieldsDataController::GetHTTPSEverywhereEnabled() { - return brave_shields::GetHTTPSEverywhereEnabled( - GetHostContentSettingsMap(web_contents()), GetCurrentSiteURL()); -} - HttpsUpgradeMode BraveShieldsDataController::GetHttpsUpgradeMode() { ControlType control_type = brave_shields::GetHttpsUpgradeControlType( GetHostContentSettingsMap(web_contents()), GetCurrentSiteURL()); @@ -391,14 +386,6 @@ void BraveShieldsDataController::SetIsNoScriptEnabled(bool is_enabled) { ReloadWebContents(); } -void BraveShieldsDataController::SetIsHTTPSEverywhereEnabled(bool is_enabled) { - brave_shields::SetHTTPSEverywhereEnabled( - GetHostContentSettingsMap(web_contents()), is_enabled, - GetCurrentSiteURL(), g_browser_process->local_state()); - - ReloadWebContents(); -} - void BraveShieldsDataController::SetForgetFirstPartyStorageEnabled( bool is_enabled) { brave_shields::SetForgetFirstPartyStorageEnabled( diff --git a/browser/ui/brave_shields_data_controller.h b/browser/ui/brave_shields_data_controller.h index 87caa2081848..fc91d7a5a8da 100644 --- a/browser/ui/brave_shields_data_controller.h +++ b/browser/ui/brave_shields_data_controller.h @@ -69,7 +69,6 @@ class BraveShieldsDataController CookieBlockMode GetCookieBlockMode(); bool IsBraveShieldsManaged(); bool IsForgetFirstPartyStorageFeatureEnabled() const; - bool GetHTTPSEverywhereEnabled(); HttpsUpgradeMode GetHttpsUpgradeMode(); bool GetNoScriptEnabled(); bool GetForgetFirstPartyStorageEnabled(); @@ -78,7 +77,6 @@ class BraveShieldsDataController void SetCookieBlockMode(CookieBlockMode mode); void SetHttpsUpgradeMode(HttpsUpgradeMode mode); void SetIsNoScriptEnabled(bool is_enabled); - void SetIsHTTPSEverywhereEnabled(bool is_enabled); void SetForgetFirstPartyStorageEnabled(bool is_enabled); void AllowScriptsOnce(const std::vector& origins); void BlockAllowedScripts(const std::vector& origins); diff --git a/browser/ui/webui/brave_shields/shields_panel_data_handler.cc b/browser/ui/webui/brave_shields/shields_panel_data_handler.cc index 985817feea34..83670e0ec5b2 100644 --- a/browser/ui/webui/brave_shields/shields_panel_data_handler.cc +++ b/browser/ui/webui/brave_shields/shields_panel_data_handler.cc @@ -69,8 +69,6 @@ void ShieldsPanelDataHandler::GetSiteSettings( active_shields_data_controller_->GetFingerprintMode(); settings.cookie_block_mode = active_shields_data_controller_->GetCookieBlockMode(); - settings.is_https_everywhere_enabled = - active_shields_data_controller_->GetHTTPSEverywhereEnabled(); settings.https_upgrade_mode = active_shields_data_controller_->GetHttpsUpgradeMode(); settings.is_noscript_enabled = @@ -135,13 +133,6 @@ void ShieldsPanelDataHandler::BlockAllowedScripts( active_shields_data_controller_->BlockAllowedScripts(origins); } -void ShieldsPanelDataHandler::SetHTTPSEverywhereEnabled(bool is_enabled) { - if (!active_shields_data_controller_) - return; - - active_shields_data_controller_->SetIsHTTPSEverywhereEnabled(is_enabled); -} - void ShieldsPanelDataHandler::SetBraveShieldsEnabled(bool is_enabled) { if (!active_shields_data_controller_) return; diff --git a/browser/ui/webui/brave_shields/shields_panel_data_handler.h b/browser/ui/webui/brave_shields/shields_panel_data_handler.h index 5bc7e3eaad1f..9da7906f6b9d 100644 --- a/browser/ui/webui/brave_shields/shields_panel_data_handler.h +++ b/browser/ui/webui/brave_shields/shields_panel_data_handler.h @@ -48,7 +48,6 @@ class ShieldsPanelDataHandler void SetCookieBlockMode(CookieBlockMode mode) override; void SetHttpsUpgradeMode(HttpsUpgradeMode mode) override; void SetIsNoScriptsEnabled(bool is_enabled) override; - void SetHTTPSEverywhereEnabled(bool is_enabled) override; void SetBraveShieldsEnabled(bool is_enabled) override; void SetForgetFirstPartyStorageEnabled(bool is_enabled) override; void OpenWebCompatWindow() override; diff --git a/browser/ui/webui/settings/default_brave_shields_handler.cc b/browser/ui/webui/settings/default_brave_shields_handler.cc index 86a2e53bde18..45c5427e66cb 100644 --- a/browser/ui/webui/settings/default_brave_shields_handler.cc +++ b/browser/ui/webui/settings/default_brave_shields_handler.cc @@ -64,11 +64,6 @@ void DefaultBraveShieldsHandler::RegisterMessages() { base::BindRepeating( &DefaultBraveShieldsHandler::SetFingerprintingControlType, base::Unretained(this))); - web_ui()->RegisterMessageCallback( - "setHTTPSEverywhereEnabled", - base::BindRepeating( - &DefaultBraveShieldsHandler::SetHTTPSEverywhereEnabled, - base::Unretained(this))); web_ui()->RegisterMessageCallback( "getHttpsUpgradeControlType", base::BindRepeating( @@ -228,17 +223,6 @@ void DefaultBraveShieldsHandler::SetFingerprintingControlType( profile_->GetPrefs()); } -void DefaultBraveShieldsHandler::SetHTTPSEverywhereEnabled( - const base::Value::List& args) { - CHECK_EQ(args.size(), 1U); - CHECK(profile_); - bool value = args[0].GetBool(); - - brave_shields::SetHTTPSEverywhereEnabled( - HostContentSettingsMapFactory::GetForProfile(profile_), value, GURL(), - g_browser_process->local_state()); -} - void DefaultBraveShieldsHandler::GetHttpsUpgradeControlType( const base::Value::List& args) { CHECK_EQ(args.size(), 1U); diff --git a/browser/ui/webui/settings/default_brave_shields_handler.h b/browser/ui/webui/settings/default_brave_shields_handler.h index 30de4dcda46e..91641f5e3d43 100644 --- a/browser/ui/webui/settings/default_brave_shields_handler.h +++ b/browser/ui/webui/settings/default_brave_shields_handler.h @@ -43,8 +43,6 @@ class DefaultBraveShieldsHandler : public settings::SettingsPageUIHandler, void GetCookieControlType(const base::Value::List& args); void SetFingerprintingControlType(const base::Value::List& args); void GetFingerprintingControlType(const base::Value::List& args); - void SetHTTPSEverywhereEnabled(const base::Value::List& args); - void GetHTTPSEverywhereEnabled(const base::Value::List& args); void SetHttpsUpgradeControlType(const base::Value::List& args); void GetHttpsUpgradeControlType(const base::Value::List& args); void SetNoScriptControlType(const base::Value::List& args); diff --git a/chromium_presubmit_config.json5 b/chromium_presubmit_config.json5 index 99fc9d4378a1..97a69c606954 100644 --- a/chromium_presubmit_config.json5 +++ b/chromium_presubmit_config.json5 @@ -168,9 +168,6 @@ "android/java/org/chromium/chrome/browser/qrreader/CameraSource\\.java", "browser/notifications/android/java/src/org/chromium/chrome/browser/notifications/BraveNotificationManagerProxyImpl\\.java", ], - "leveldb::DB::Open": [ - "components/brave_shields/browser/https_everywhere_service\\.cc", - ], "/\\s+UTF8String\\s*]": [ "base/mac/conversions\\.h", "browser/mac/sparkle_glue\\.mm", diff --git a/chromium_src/chrome/browser/component_updater/registration.cc b/chromium_src/chrome/browser/component_updater/registration.cc index a6bdb2ec36c9..4a1e10c43d3b 100644 --- a/chromium_src/chrome/browser/component_updater/registration.cc +++ b/chromium_src/chrome/browser/component_updater/registration.cc @@ -22,7 +22,6 @@ #undef RegisterWidevineCdmComponent #undef RegisterComponentsForUpdate -#include "brave/browser/brave_shields/https_everywhere_component_installer.h" #include "brave/components/brave_wallet/browser/wallet_data_files_installer.h" #include "chrome/browser/browser_process.h" @@ -32,7 +31,6 @@ void RegisterComponentsForUpdate() { RegisterComponentsForUpdate_ChromiumImpl(); ComponentUpdateService* cus = g_browser_process->component_updater(); brave_wallet::RegisterWalletDataFilesComponent(cus); - brave_shields::RegisterHTTPSEverywhereComponent(cus); } } // namespace component_updater diff --git a/components/brave_shields/browser/BUILD.gn b/components/brave_shields/browser/BUILD.gn index 5942f4279e23..28fbc5804225 100644 --- a/components/brave_shields/browser/BUILD.gn +++ b/components/brave_shields/browser/BUILD.gn @@ -65,9 +65,6 @@ if (!is_ios) { "filter_list_catalog_entry.h", "filter_list_service.cc", "filter_list_service.h", - "https_everywhere_recently_used_cache.h", - "https_everywhere_service.cc", - "https_everywhere_service.h", ] deps = [ diff --git a/components/brave_shields/browser/brave_shields_util.cc b/components/brave_shields/browser/brave_shields_util.cc index c6a5d3a78469..5f1eb311261e 100644 --- a/components/brave_shields/browser/brave_shields_util.cc +++ b/components/brave_shields/browser/brave_shields_util.cc @@ -593,46 +593,6 @@ bool IsBraveShieldsManaged(PrefService* prefs, return info.source == content_settings::SettingSource::SETTING_SOURCE_POLICY; } -void SetHTTPSEverywhereEnabled(HostContentSettingsMap* map, - bool enable, - const GURL& url, - PrefService* local_state) { - auto primary_pattern = GetPatternFromURL(url); - - if (!primary_pattern.IsValid()) - return; - - map->SetContentSettingCustomScope( - primary_pattern, ContentSettingsPattern::Wildcard(), - ContentSettingsType::BRAVE_HTTP_UPGRADABLE_RESOURCES, - // this is 'allow_http_upgradeable_resources' so enabling - // httpse will set the value to 'BLOCK' - enable ? CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); - - RecordShieldsSettingChanged(local_state); -} - -void ResetHTTPSEverywhereEnabled(HostContentSettingsMap* map, - bool enable, - const GURL& url) { - auto primary_pattern = GetPatternFromURL(url); - - if (!primary_pattern.IsValid()) - return; - - map->SetContentSettingCustomScope( - primary_pattern, ContentSettingsPattern::Wildcard(), - ContentSettingsType::BRAVE_HTTP_UPGRADABLE_RESOURCES, - CONTENT_SETTING_DEFAULT); -} - -bool GetHTTPSEverywhereEnabled(HostContentSettingsMap* map, const GURL& url) { - ContentSetting setting = map->GetContentSetting( - url, GURL(), ContentSettingsType::BRAVE_HTTP_UPGRADABLE_RESOURCES); - - return setting == CONTENT_SETTING_ALLOW ? false : true; -} - bool IsHttpsByDefaultFeatureEnabled() { return base::FeatureList::IsEnabled(net::features::kBraveHttpsByDefault); } diff --git a/components/brave_shields/browser/brave_shields_util.h b/components/brave_shields/browser/brave_shields_util.h index 06e0107d493d..abe3717b042a 100644 --- a/components/brave_shields/browser/brave_shields_util.h +++ b/components/brave_shields/browser/brave_shields_util.h @@ -110,13 +110,6 @@ ControlType GetFingerprintingControlType(HostContentSettingsMap* map, bool IsBraveShieldsManaged(PrefService* prefs, HostContentSettingsMap* map, GURL url); -void SetHTTPSEverywhereEnabled(HostContentSettingsMap* map, - bool enable, - const GURL& url, - PrefService* local_state = nullptr); -// reset to the default value -void ResetHTTPSEverywhereEnabled(HostContentSettingsMap* map, const GURL& url); -bool GetHTTPSEverywhereEnabled(HostContentSettingsMap* map, const GURL& url); bool IsHttpsByDefaultFeatureEnabled(); void SetHttpsUpgradeControlType(HostContentSettingsMap* map, diff --git a/components/brave_shields/browser/brave_shields_util_unittest.cc b/components/brave_shields/browser/brave_shields_util_unittest.cc index 6a2bdfc17d90..3fc2a05ce2bd 100644 --- a/components/brave_shields/browser/brave_shields_util_unittest.cc +++ b/components/brave_shields/browser/brave_shields_util_unittest.cc @@ -740,152 +740,6 @@ TEST_F(BraveShieldsUtilTest, SetFingerprintingControlType_ForOrigin) { EXPECT_EQ(ControlType::DEFAULT, type); } -/* HTTPSEVERYWHERE CONTROL */ -TEST_F(BraveShieldsUtilTest, SetHTTPSEverywhereEnabled_Default) { - auto* map = HostContentSettingsMapFactory::GetForProfile(profile()); - // settings should be default - auto setting = map->GetContentSetting( - GURL(), GURL(), ContentSettingsType::BRAVE_HTTP_UPGRADABLE_RESOURCES); - EXPECT_EQ(CONTENT_SETTING_BLOCK, setting); - setting = map->GetContentSetting( - GURL("http://brave.com"), GURL(), - ContentSettingsType::BRAVE_HTTP_UPGRADABLE_RESOURCES); - EXPECT_EQ(CONTENT_SETTING_BLOCK, setting); - - /* disabled */ - brave_shields::SetHTTPSEverywhereEnabled(map, false, GURL()); - setting = map->GetContentSetting( - GURL(), GURL(), ContentSettingsType::BRAVE_HTTP_UPGRADABLE_RESOURCES); - EXPECT_EQ(CONTENT_SETTING_ALLOW, setting); - - // override should apply to all origins - setting = map->GetContentSetting( - GURL("http://brave.com"), GURL(), - ContentSettingsType::BRAVE_HTTP_UPGRADABLE_RESOURCES); - EXPECT_EQ(CONTENT_SETTING_ALLOW, setting); - - /* enabled */ - brave_shields::SetHTTPSEverywhereEnabled(map, true, GURL()); - setting = map->GetContentSetting( - GURL(), GURL(), ContentSettingsType::BRAVE_HTTP_UPGRADABLE_RESOURCES); - EXPECT_EQ(CONTENT_SETTING_BLOCK, setting); - - // override should apply to all origins - setting = map->GetContentSetting( - GURL("http://brave.com"), GURL(), - ContentSettingsType::BRAVE_HTTP_UPGRADABLE_RESOURCES); - EXPECT_EQ(CONTENT_SETTING_BLOCK, setting); -} - -TEST_F(BraveShieldsUtilTest, SetHTTPSEverywhereEnabled_ForOrigin) { - auto* map = HostContentSettingsMapFactory::GetForProfile(profile()); - - brave_shields::SetHTTPSEverywhereEnabled(map, false, - GURL("http://brave.com")); - // setting should apply to origin - auto setting = map->GetContentSetting( - GURL("http://brave.com"), GURL(), - ContentSettingsType::BRAVE_HTTP_UPGRADABLE_RESOURCES); - EXPECT_EQ(CONTENT_SETTING_ALLOW, setting); - - // setting should apply to different scheme - setting = map->GetContentSetting( - GURL("https://brave.com"), GURL(), - ContentSettingsType::BRAVE_HTTP_UPGRADABLE_RESOURCES); - EXPECT_EQ(CONTENT_SETTING_ALLOW, setting); - - // setting should not apply to default - setting = map->GetContentSetting( - GURL(), GURL(), ContentSettingsType::BRAVE_HTTP_UPGRADABLE_RESOURCES); - EXPECT_EQ(CONTENT_SETTING_BLOCK, setting); -} - -TEST_F(BraveShieldsUtilTest, GetHTTPSEverywhereEnabled_Default) { - auto* map = HostContentSettingsMapFactory::GetForProfile(profile()); - - auto setting = brave_shields::GetHTTPSEverywhereEnabled(map, GURL()); - EXPECT_EQ(true, setting); - - /* ALLOW */ - map->SetContentSettingCustomScope( - ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), - ContentSettingsType::BRAVE_HTTP_UPGRADABLE_RESOURCES, - CONTENT_SETTING_ALLOW); - setting = brave_shields::GetHTTPSEverywhereEnabled(map, GURL()); - EXPECT_EQ(false, setting); - - /* BLOCK */ - map->SetContentSettingCustomScope( - ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), - ContentSettingsType::BRAVE_HTTP_UPGRADABLE_RESOURCES, - CONTENT_SETTING_BLOCK); - setting = brave_shields::GetHTTPSEverywhereEnabled(map, GURL()); - EXPECT_EQ(true, setting); -} - -TEST_F(BraveShieldsUtilTest, GetHTTPSEverywhereEnabled_ForOrigin) { - auto* map = HostContentSettingsMapFactory::GetForProfile(profile()); - - auto setting = brave_shields::GetHTTPSEverywhereEnabled(map, GURL()); - EXPECT_EQ(true, setting); - setting = - brave_shields::GetHTTPSEverywhereEnabled(map, GURL("http://brave.com")); - EXPECT_EQ(true, setting); - setting = - brave_shields::GetHTTPSEverywhereEnabled(map, GURL("https://brave.com")); - EXPECT_EQ(true, setting); - - /* ALLOW */ - map->SetContentSettingCustomScope( - ContentSettingsPattern::FromString("http://brave.com/*"), - ContentSettingsPattern::Wildcard(), - ContentSettingsType::BRAVE_HTTP_UPGRADABLE_RESOURCES, - CONTENT_SETTING_ALLOW); - setting = - brave_shields::GetHTTPSEverywhereEnabled(map, GURL("http://brave.com")); - EXPECT_EQ(ControlType::ALLOW, setting); - - // https in unchanged - setting = - brave_shields::GetHTTPSEverywhereEnabled(map, GURL("https://brave.com")); - EXPECT_EQ(true, setting); - // default is unchanged - setting = brave_shields::GetHTTPSEverywhereEnabled(map, GURL()); - EXPECT_EQ(true, setting); - - /* BLOCK */ - // change default to allow - map->SetContentSettingCustomScope( - ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), - ContentSettingsType::BRAVE_HTTP_UPGRADABLE_RESOURCES, - CONTENT_SETTING_ALLOW); - setting = - brave_shields::GetHTTPSEverywhereEnabled(map, GURL("http://brave.com")); - EXPECT_EQ(ControlType::ALLOW, setting); - setting = - brave_shields::GetHTTPSEverywhereEnabled(map, GURL("https://brave.com")); - EXPECT_EQ(ControlType::ALLOW, setting); - setting = brave_shields::GetHTTPSEverywhereEnabled(map, GURL()); - EXPECT_EQ(ControlType::ALLOW, setting); - - // set override to block - map->SetContentSettingCustomScope( - ContentSettingsPattern::FromString("http://brave.com/*"), - ContentSettingsPattern::Wildcard(), - ContentSettingsType::BRAVE_HTTP_UPGRADABLE_RESOURCES, - CONTENT_SETTING_BLOCK); - setting = - brave_shields::GetHTTPSEverywhereEnabled(map, GURL("http://brave.com/*")); - EXPECT_EQ(true, setting); - // https in unchanged - setting = - brave_shields::GetHTTPSEverywhereEnabled(map, GURL("https://brave.com")); - EXPECT_EQ(false, setting); - // default is unchanged - setting = brave_shields::GetHTTPSEverywhereEnabled(map, GURL()); - EXPECT_EQ(false, setting); -} - /* NOSCRIPT CONTROL */ TEST_F(BraveShieldsUtilTest, SetNoScriptControlType_Default) { auto* map = HostContentSettingsMapFactory::GetForProfile(profile()); diff --git a/components/brave_shields/browser/https_everywhere_component_installer.cc b/components/brave_shields/browser/https_everywhere_component_installer.cc deleted file mode 100644 index 635bfdb526c2..000000000000 --- a/components/brave_shields/browser/https_everywhere_component_installer.cc +++ /dev/null @@ -1,167 +0,0 @@ -/* Copyright (c) 2021 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "brave/components/brave_shields/browser/https_everywhere_component_installer.h" - -#include -#include -#include - -#include "base/base64.h" -#include "base/functional/bind.h" -#include "base/functional/callback.h" -#include "brave/components/brave_component_updater/browser/brave_on_demand_updater.h" -#include "components/component_updater/component_installer.h" -#include "components/component_updater/component_updater_service.h" -#include "crypto/sha2.h" - -using brave_component_updater::BraveOnDemandUpdater; - -namespace brave_shields { - -namespace { - -constexpr size_t kHashSize = 32; -const char kHTTPSEverywhereComponentName[] = "Brave HTTPS Everywhere Updater"; -const char kHTTPSEverywhereComponentId[] = "oofiananboodjbbmdelgdommihjbkfag"; -const char kHTTPSEverywhereComponentBase64PublicKey[] = - "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvn9zSMjTmhkQyrZu5UdN" - "350nPqLoSeCYngcC7yDFwaUHjoBQXCZqGeDC69ciCQ2mlRhcV2nxXqlUDkiC6+7m" - "651nI+gi4oVqHagc7EFUyGA0yuIk7qIMvCBdH7wbET27de0rzbRzRht9EKzEjIhC" - "BtoPnmyrO/8qPrH4XR4cPfnFPuJssBBxC1B35H7rh0Br9qePhPDDe9OjyqYxPuio" - "+YcC9obL4g5krVrfrlKLfFNpIewUcJyBpSlCgfxEyEhgDkK9cILTMUi5vC7GxS3P" - "OtZqgfRg8Da4i+NwmjQqrz0JFtPMMSyUnmeMj+mSOL4xZVWr8fU2/GOCXs9gczDp" - "JwIDAQAB"; - -class HTTPSEverywhereComponentInstallerPolicy - : public component_updater::ComponentInstallerPolicy { - public: - explicit HTTPSEverywhereComponentInstallerPolicy( - const std::string& component_public_key, - const std::string& component_id, - const std::string& component_name, - OnComponentReadyCallback callback); - ~HTTPSEverywhereComponentInstallerPolicy() override; - - HTTPSEverywhereComponentInstallerPolicy( - const HTTPSEverywhereComponentInstallerPolicy&) = delete; - HTTPSEverywhereComponentInstallerPolicy& operator=( - const HTTPSEverywhereComponentInstallerPolicy&) = delete; - - // component_updater::ComponentInstallerPolicy - bool SupportsGroupPolicyEnabledComponentUpdates() const override; - bool RequiresNetworkEncryption() const override; - update_client::CrxInstaller::Result OnCustomInstall( - const base::Value::Dict& manifest, - const base::FilePath& install_dir) override; - void OnCustomUninstall() override; - bool VerifyInstallation(const base::DictionaryValue& manifest, - const base::FilePath& install_dir) const override; - void ComponentReady(const base::Version& version, - const base::FilePath& path, - std::unique_ptr manifest) override; - base::FilePath GetRelativeInstallDir() const override; - void GetHash(std::vector* hash) const override; - std::string GetName() const override; - update_client::InstallerAttributes GetInstallerAttributes() const override; - - private: - const std::string component_id_; - const std::string component_name_; - OnComponentReadyCallback ready_callback_; - uint8_t component_hash_[kHashSize]; -}; - -HTTPSEverywhereComponentInstallerPolicy:: - HTTPSEverywhereComponentInstallerPolicy( - const std::string& component_public_key, - const std::string& component_id, - const std::string& component_name, - OnComponentReadyCallback callback) - : component_id_(component_id), - component_name_(component_name), - ready_callback_(callback) { - // Generate hash from public key. - std::string decoded_public_key; - base::Base64Decode(component_public_key, &decoded_public_key); - crypto::SHA256HashString(decoded_public_key, component_hash_, kHashSize); -} - -HTTPSEverywhereComponentInstallerPolicy:: - ~HTTPSEverywhereComponentInstallerPolicy() = default; - -bool HTTPSEverywhereComponentInstallerPolicy:: - SupportsGroupPolicyEnabledComponentUpdates() const { - return true; -} - -bool HTTPSEverywhereComponentInstallerPolicy::RequiresNetworkEncryption() - const { - return false; -} - -update_client::CrxInstaller::Result -HTTPSEverywhereComponentInstallerPolicy::OnCustomInstall( - const base::Value::Dict& manifest, - const base::FilePath& install_dir) { - return update_client::CrxInstaller::Result(0); -} - -void HTTPSEverywhereComponentInstallerPolicy::OnCustomUninstall() {} - -void HTTPSEverywhereComponentInstallerPolicy::ComponentReady( - const base::Version& version, - const base::FilePath& path, - std::unique_ptr manifest) { - ready_callback_.Run(path); -} - -bool HTTPSEverywhereComponentInstallerPolicy::VerifyInstallation( - const base::DictionaryValue& manifest, - const base::FilePath& install_dir) const { - return true; -} - -base::FilePath HTTPSEverywhereComponentInstallerPolicy::GetRelativeInstallDir() - const { - return base::FilePath::FromUTF8Unsafe(component_id_); -} - -void HTTPSEverywhereComponentInstallerPolicy::GetHash( - std::vector* hash) const { - hash->assign(component_hash_, component_hash_ + kHashSize); -} - -std::string HTTPSEverywhereComponentInstallerPolicy::GetName() const { - return component_name_; -} - -update_client::InstallerAttributes -HTTPSEverywhereComponentInstallerPolicy::GetInstallerAttributes() const { - return update_client::InstallerAttributes(); -} - -void OnRegistered(const std::string& component_id) { - BraveOnDemandUpdater::GetInstance()->OnDemandUpdate(component_id); -} - -} // namespace - -void RegisterHTTPSEverywhereComponent( - component_updater::ComponentUpdateService* cus, - OnComponentReadyCallback callback) { - // In test, |cus| could be nullptr. - if (!cus) - return; - - auto installer = base::MakeRefCounted( - std::make_unique( - kHTTPSEverywhereComponentBase64PublicKey, kHTTPSEverywhereComponentId, - kHTTPSEverywhereComponentName, callback)); - installer->Register( - cus, base::BindOnce(&OnRegistered, kHTTPSEverywhereComponentId)); -} - -} // namespace brave_shields diff --git a/components/brave_shields/browser/https_everywhere_component_installer.h b/components/brave_shields/browser/https_everywhere_component_installer.h deleted file mode 100644 index 465cbe6a7a03..000000000000 --- a/components/brave_shields/browser/https_everywhere_component_installer.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright (c) 2021 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_HTTPS_EVERYWHERE_COMPONENT_INSTALLER_H_ -#define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_HTTPS_EVERYWHERE_COMPONENT_INSTALLER_H_ - -#include "base/files/file_path.h" -#include "base/functional/callback.h" - -namespace component_updater { -class ComponentUpdateService; -} // namespace component_updater - -namespace brave_shields { - -using OnComponentReadyCallback = - base::RepeatingCallback; - -void RegisterHTTPSEverywhereComponent( - component_updater::ComponentUpdateService* cus, - OnComponentReadyCallback callback); - -} // namespace brave_shields - -#endif // BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_HTTPS_EVERYWHERE_COMPONENT_INSTALLER_H_ diff --git a/components/brave_shields/browser/https_everywhere_recently_used_cache.h b/components/brave_shields/browser/https_everywhere_recently_used_cache.h deleted file mode 100644 index 28e2b724b918..000000000000 --- a/components/brave_shields/browser/https_everywhere_recently_used_cache.h +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright 2016 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_HTTPS_EVERYWHERE_RECENTLY_USED_CACHE_H_ -#define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_HTTPS_EVERYWHERE_RECENTLY_USED_CACHE_H_ - -#include - -#include "base/containers/lru_cache.h" -#include "base/synchronization/lock.h" - -template class HTTPSERecentlyUsedCache { - public: - explicit HTTPSERecentlyUsedCache(size_t size = 100) : data_(size) {} - - void add(const std::string& key, const T& value) { - base::AutoLock create(lock_); - data_.Put(key, value); - } - - bool get(const std::string& key, T* value) { - base::AutoLock create(lock_); - auto it = data_.Get(key); - if (it != data_.end()) { - *value = it->second; - return true; - } - return false; - } - - void remove(const std::string& key) { - base::AutoLock lock(lock_); - auto it = data_.Peek(key); - if (it != data_.end()) - data_.Erase(it); - } - - private: - base::LRUCache data_; - base::Lock lock_; -}; - -#endif // BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_HTTPS_EVERYWHERE_RECENTLY_USED_CACHE_H_ diff --git a/components/brave_shields/browser/https_everywhere_recently_used_cache_unittest.cpp b/components/brave_shields/browser/https_everywhere_recently_used_cache_unittest.cpp deleted file mode 100644 index e10d6d1afd19..000000000000 --- a/components/brave_shields/browser/https_everywhere_recently_used_cache_unittest.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (c) 2019 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include - -#include "brave/components/brave_shields/browser/https_everywhere_recently_used_cache.h" -#include "testing/gtest/include/gtest/gtest.h" - -TEST(HTTPSEverywhereRecentlyUsedCacheTest, Operations) { - using Cache = HTTPSERecentlyUsedCache; - Cache cache(3); - - // Test add/get and check that max size is maintained. - cache.add("kA", "vA"); - cache.add("kB", "vB"); - cache.add("kC", "vC"); - std::string v; - ASSERT_TRUE(cache.get("kA", &v)); - ASSERT_STREQ(v.c_str(), "vA"); - // kA just became MRU, so adding a new k/v pair should evict the oldest. - cache.add("kD", "vD"); - ASSERT_FALSE(cache.get("kB", &v)); - ASSERT_TRUE(cache.get("kD", &v)); - - // Test remove. - cache.remove("kD"); - ASSERT_FALSE(cache.get("kD", &v)); -} diff --git a/components/brave_shields/browser/https_everywhere_service.cc b/components/brave_shields/browser/https_everywhere_service.cc deleted file mode 100644 index ad03e65597c2..000000000000 --- a/components/brave_shields/browser/https_everywhere_service.cc +++ /dev/null @@ -1,375 +0,0 @@ -/* Copyright (c) 2016 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at https://mozilla.org/MPL/2.0/. */ - -#include "brave/components/brave_shields/browser/https_everywhere_service.h" - -#include -#include -#include -#include - -#include "base/base_paths.h" -#include "base/files/file_util.h" -#include "base/functional/bind.h" -#include "base/json/json_reader.h" -#include "base/logging.h" -#include "base/memory/ptr_util.h" -#include "base/metrics/histogram_macros.h" -#include "base/strings/utf_string_conversions.h" -#include "base/threading/scoped_blocking_call.h" -#include "base/values.h" -#include "third_party/leveldatabase/src/include/leveldb/db.h" -#include "third_party/re2/src/re2/re2.h" -#include "third_party/zlib/google/zip.h" - -#define DAT_FILE "httpse.leveldb.zip" -#define DAT_FILE_VERSION "6.0" -#define HTTPSE_URLS_REDIRECTS_COUNT_QUEUE 1 -#define HTTPSE_URL_MAX_REDIRECTS_COUNT 5 - -namespace { - -std::vector Split(const std::string& s, char delim) { - std::stringstream ss(s); - std::string item; - std::vector result; - while (getline(ss, item, delim)) { - result.push_back(item); - } - return result; -} - -// returns parts in reverse order, makes list of lookup domains like com.foo.* -std::vector ExpandDomainForLookup(const std::string& domain) { - std::vector resultDomains; - std::vector domainParts = Split(domain, '.'); - if (domainParts.empty()) { - return resultDomains; - } - - for (size_t i = 0; i < domainParts.size() - 1; i++) { - // i < size()-1 is correct: don't want 'com.*' added to resultDomains - std::string slice = ""; - std::string dot = ""; - for (int j = domainParts.size() - 1; j >= static_cast(i); j--) { - slice += dot + domainParts[j]; - dot = "."; - } - if (0 != i) { - // We don't want * on the top URL - resultDomains.push_back(slice + ".*"); - } else { - resultDomains.push_back(slice); - } - } - return resultDomains; -} -std::string leveldbGet(leveldb::DB* db, const std::string &key) { - if (!db) { - return ""; - } - - std::string value; - leveldb::Status s = db->Get(leveldb::ReadOptions(), key, &value); - return s.ok() ? value : ""; -} - -} // namespace - -namespace brave_shields { - -HTTPSEverywhereService::Engine::Engine(HTTPSEverywhereService& service) - : service_(service) { - DETACH_FROM_SEQUENCE(sequence_checker_); -} - -HTTPSEverywhereService::Engine::~Engine() = default; - -void HTTPSEverywhereService::Engine::Init(const base::FilePath& base_dir) { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - base::FilePath zip_db_file_path = - base_dir.AppendASCII(DAT_FILE_VERSION).AppendASCII(DAT_FILE); - base::FilePath unzipped_level_db_path = zip_db_file_path.RemoveExtension(); - base::FilePath destination = zip_db_file_path.DirName(); - // Unzip doesn't allow overwriting existing files, so delete previously - // unzipped db. Attempting to delete a non-existent path returns success. - bool deleted = base::DeletePathRecursively(unzipped_level_db_path); - if (!deleted) { - LOG(ERROR) << "Failed to delete unzipped database directory " - << unzipped_level_db_path.value().c_str(); - return; - } - - if (!zip::Unzip(zip_db_file_path, destination)) { - LOG(ERROR) << "Failed to unzip database file " - << zip_db_file_path.value().c_str(); - return; - } - - CloseDatabase(); - - leveldb::Options options; - leveldb::DB* db = nullptr; - leveldb::Status status = - leveldb::DB::Open(options, unzipped_level_db_path.AsUTF8Unsafe(), &db); - if (!status.ok() || !db) { - LOG(ERROR) << "Level db open error " - << unzipped_level_db_path.value().c_str() - << ", error: " << status.ToString(); - CloseDatabase(); - return; - } - level_db_ = base::WrapUnique(db); -} - -bool HTTPSEverywhereService::Engine::GetHTTPSURL( - const GURL* url, - const uint64_t& request_identifier, - std::string* new_url) { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - - if (!url->is_valid()) - return false; - - if (!level_db_ || url->scheme() == url::kHttpsScheme) { - return false; - } - - if (!service_->ShouldHTTPSERedirect(request_identifier)) { - return false; - } - - if (service_->recently_used_cache().get(url->spec(), new_url)) { - service_->AddHTTPSEUrlToRedirectList(request_identifier); - return true; - } - - GURL candidate_url(*url); - if (g_ignore_port_for_test_ && candidate_url.has_port()) { - GURL::Replacements replacements; - replacements.ClearPort(); - candidate_url = candidate_url.ReplaceComponents(replacements); - } - - SCOPED_UMA_HISTOGRAM_TIMER("Brave.HTTPSE.GetHTTPSURL"); - const std::vector domains = - ExpandDomainForLookup(candidate_url.host()); - for (auto domain : domains) { - std::string value = leveldbGet(level_db_.get(), domain); - if (!value.empty()) { - *new_url = ApplyHTTPSRule(candidate_url.spec(), value); - if (0 != new_url->length()) { - service_->recently_used_cache().add(candidate_url.spec(), *new_url); - service_->AddHTTPSEUrlToRedirectList(request_identifier); - return true; - } - } - } - service_->recently_used_cache().remove(candidate_url.spec()); - return false; -} - -std::string HTTPSEverywhereService::Engine::ApplyHTTPSRule( - const std::string& originalUrl, - const std::string& rule) { - absl::optional json_object = base::JSONReader::Read(rule); - if (absl::nullopt == json_object || !json_object->is_list()) { - return ""; - } - - const base::Value::List& topValues = json_object->GetList(); - for (const auto& topValue : topValues) { - if (!topValue.is_dict()) { - continue; - } - const base::Value::Dict* childTopDictionary = topValue.GetIfDict(); - if (nullptr == childTopDictionary) { - continue; - } - - const base::Value* exclusion = childTopDictionary->Find("e"); - if (nullptr != exclusion) { - const base::Value::List* eValues = exclusion->GetIfList(); - if (nullptr != eValues) { - for (const auto& eValue : *eValues) { - const base::Value::Dict* pDictionary = eValue.GetIfDict(); - if (nullptr == pDictionary) { - continue; - } - const base::Value* patternValue = pDictionary->Find("p"); - if (!patternValue) { - continue; - } - if (!patternValue->is_string()) { - continue; - } - std::string pattern = - CorrecttoRuleToRE2Engine(patternValue->GetString()); - if (RE2::FullMatch(originalUrl, pattern)) { - return ""; - } - } - } - } - - const base::Value* rules = childTopDictionary->Find("r"); - if (!rules) { - return ""; - } - const base::Value::List* rValues = rules->GetIfList(); - if (nullptr == rValues) { - return ""; - } - - for (const auto& rValue : *rValues) { - const base::Value::Dict* pDictionary = rValue.GetIfDict(); - if (nullptr == pDictionary) { - continue; - } - const base::Value* patternValue = pDictionary->Find("d"); - if (patternValue) { - std::string newUrl(originalUrl); - return newUrl.insert(4, "s"); - } - - const base::Value* from_value = pDictionary->Find("f"); - const base::Value* to_value = pDictionary->Find("t"); - if (!from_value || !to_value) { - continue; - } - if (!from_value->is_string() || !to_value->is_string()) { - continue; - } - - std::string to = CorrecttoRuleToRE2Engine(to_value->GetString()); - std::string newUrl(originalUrl); - RE2 regExp(from_value->GetString()); - - if (RE2::Replace(&newUrl, regExp, to) && newUrl != originalUrl) { - return newUrl; - } - } - } - return ""; -} - -std::string HTTPSEverywhereService::Engine::CorrecttoRuleToRE2Engine( - const std::string& to) { - std::string correctedto(to); - size_t pos = to.find("$"); - while (std::string::npos != pos) { - correctedto[pos] = '\\'; - pos = correctedto.find("$"); - } - - return correctedto; -} - -void HTTPSEverywhereService::Engine::CloseDatabase() { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - level_db_.reset(); -} - -bool HTTPSEverywhereService::g_ignore_port_for_test_(false); - -HTTPSEverywhereService::HTTPSEverywhereService( - scoped_refptr task_runner) - : BaseBraveShieldsService(task_runner), - engine_(new Engine(*this), base::OnTaskRunnerDeleter(task_runner)) {} - -HTTPSEverywhereService::~HTTPSEverywhereService() { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); -} - -bool HTTPSEverywhereService::Init() { - return true; -} - -void HTTPSEverywhereService::InitDB(const base::FilePath& install_dir) { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - GetTaskRunner()->PostTask( - FROM_HERE, - base::BindOnce(&Engine::Init, engine_->AsWeakPtr(), install_dir)); -} - -bool HTTPSEverywhereService::GetHTTPSURLFromCacheOnly( - const GURL* url, - const uint64_t& request_identifier, - std::string* cached_url) { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - if (!url->is_valid()) - return false; - - if (!IsInitialized() || url->scheme() == url::kHttpsScheme) { - return false; - } - if (!ShouldHTTPSERedirect(request_identifier)) { - return false; - } - - if (recently_used_cache_.get(url->spec(), cached_url)) { - AddHTTPSEUrlToRedirectList(request_identifier); - return true; - } - return false; -} - -HTTPSERecentlyUsedCache& -HTTPSEverywhereService::recently_used_cache() { - return recently_used_cache_; -} - -bool HTTPSEverywhereService::ShouldHTTPSERedirect( - const uint64_t& request_identifier) { - base::AutoLock auto_lock(httpse_get_urls_redirects_count_mutex_); - for (auto& redirect : httpse_urls_redirects_count_) { - if (request_identifier == redirect.request_identifier_ && - redirect.redirects_ >= HTTPSE_URL_MAX_REDIRECTS_COUNT - 1) { - return false; - } - } - - return true; -} - -void HTTPSEverywhereService::AddHTTPSEUrlToRedirectList( - const uint64_t& request_identifier) { - // Adding redirects count for the current request - base::AutoLock auto_lock(httpse_get_urls_redirects_count_mutex_); - bool hostFound = false; - for (auto& redirect : httpse_urls_redirects_count_) { - if (request_identifier == redirect.request_identifier_) { - // Found the host, just increment the redirects_count - redirect.redirects_++; - hostFound = true; - break; - } - } - if (!hostFound) { - // The host is new, adding it to the redirects list - if (httpse_urls_redirects_count_.size() >= - HTTPSE_URLS_REDIRECTS_COUNT_QUEUE) { - // The queue is full, erase the first element - httpse_urls_redirects_count_.erase(httpse_urls_redirects_count_.begin()); - } - httpse_urls_redirects_count_.emplace_back(request_identifier, 1); - } -} - -// static -void HTTPSEverywhereService::SetIgnorePortForTest(bool ignore) { - g_ignore_port_for_test_ = ignore; -} - -/////////////////////////////////////////////////////////////////////////////// - -// The brave shields factory. Using the Brave Shields as a singleton -// is the job of the browser process. -std::unique_ptr HTTPSEverywhereServiceFactory( - scoped_refptr task_runner) { - return std::make_unique(task_runner); -} - -} // namespace brave_shields diff --git a/components/brave_shields/browser/https_everywhere_service.h b/components/brave_shields/browser/https_everywhere_service.h deleted file mode 100644 index 6081df95d29f..000000000000 --- a/components/brave_shields/browser/https_everywhere_service.h +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright (c) 2019 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_HTTPS_EVERYWHERE_SERVICE_H_ -#define BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_HTTPS_EVERYWHERE_SERVICE_H_ - -#include -#include -#include - -#include "base/files/file_path.h" -#include "base/memory/raw_ref.h" -#include "base/memory/weak_ptr.h" -#include "base/sequence_checker.h" -#include "base/synchronization/lock.h" -#include "brave/components/brave_shields/browser/base_brave_shields_service.h" -#include "brave/components/brave_shields/browser/https_everywhere_recently_used_cache.h" - -namespace leveldb { -class DB; -} - -class HTTPSEverywhereServiceTest; - -using brave_component_updater::BraveComponent; - -namespace brave_shields { - -extern const char kHTTPSEverywhereComponentName[]; -extern const char kHTTPSEverywhereComponentId[]; -extern const char kHTTPSEverywhereComponentBase64PublicKey[]; - -struct HTTPSE_REDIRECTS_COUNT_ST { - public: - HTTPSE_REDIRECTS_COUNT_ST(uint64_t request_identifier, - unsigned int redirects): - request_identifier_(request_identifier), - redirects_(redirects) { - } - - uint64_t request_identifier_; - unsigned int redirects_; -}; - -class HTTPSEverywhereService : public BaseBraveShieldsService { - public: - explicit HTTPSEverywhereService( - scoped_refptr task_runner); - HTTPSEverywhereService(const HTTPSEverywhereService&) = delete; - HTTPSEverywhereService& operator=(const HTTPSEverywhereService&) = delete; - ~HTTPSEverywhereService() override; - - class Engine : public base::SupportsWeakPtr { - public: - explicit Engine(HTTPSEverywhereService& service); - Engine(const Engine&) = delete; - Engine& operator=(const Engine&) = delete; - ~Engine(); - - void Init(const base::FilePath& base_dir); - bool GetHTTPSURL(const GURL* url, - const uint64_t& request_id, - std::string* new_url); - - private: - std::string ApplyHTTPSRule(const std::string& originalUrl, - const std::string& rule); - std::string CorrecttoRuleToRE2Engine(const std::string& to); - void CloseDatabase(); - - std::unique_ptr level_db_; - const raw_ref service_; - SEQUENCE_CHECKER(sequence_checker_); - }; - - void InitDB(const base::FilePath& install_dir); - - bool GetHTTPSURLFromCacheOnly(const GURL* url, - const uint64_t& request_id, - std::string* cached_url); - - base::WeakPtr engine() { return engine_->AsWeakPtr(); } - - protected: - bool Init() override; - - private: - friend class ::HTTPSEverywhereServiceTest; - friend class Engine; - static bool g_ignore_port_for_test_; - static void SetIgnorePortForTest(bool ignore); - - void AddHTTPSEUrlToRedirectList(const uint64_t& request_id); - bool ShouldHTTPSERedirect(const uint64_t& request_id); - HTTPSERecentlyUsedCache& recently_used_cache(); - - base::Lock httpse_get_urls_redirects_count_mutex_; - std::vector httpse_urls_redirects_count_; - HTTPSERecentlyUsedCache recently_used_cache_; - std::unique_ptr engine_; - - SEQUENCE_CHECKER(sequence_checker_); -}; - -// Creates the HTTPSEverywhereService -std::unique_ptr HTTPSEverywhereServiceFactory( - scoped_refptr task_runner); - -} // namespace brave_shields - -#endif // BRAVE_COMPONENTS_BRAVE_SHIELDS_BROWSER_HTTPS_EVERYWHERE_SERVICE_H_ diff --git a/components/brave_shields/browser/https_everywhere_service_browsertest.cc b/components/brave_shields/browser/https_everywhere_service_browsertest.cc deleted file mode 100644 index 62ea9769df23..000000000000 --- a/components/brave_shields/browser/https_everywhere_service_browsertest.cc +++ /dev/null @@ -1,256 +0,0 @@ -/* Copyright (c) 2019 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "base/base64.h" -#include "base/path_service.h" -#include "base/test/thread_test_helper.h" -#include "brave/browser/brave_browser_process.h" -#include "brave/browser/brave_shields/https_everywhere_component_installer.h" -#include "brave/components/brave_shields/browser/ad_block_component_filters_provider.h" -#include "brave/components/brave_shields/browser/ad_block_service.h" -#include "brave/components/brave_shields/browser/brave_shields_util.h" -#include "brave/components/brave_shields/browser/https_everywhere_service.h" -#include "brave/components/brave_shields/browser/test_filters_provider.h" -#include "brave/components/constants/brave_paths.h" -#include "chrome/browser/content_settings/host_content_settings_map_factory.h" -#include "chrome/browser/extensions/extension_browsertest.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/test/base/ui_test_utils.h" -#include "content/public/browser/browser_task_traits.h" -#include "content/public/test/browser_test.h" -#include "content/public/test/browser_test_utils.h" -#include "net/dns/mock_host_resolver.h" - -using extensions::ExtensionBrowserTest; - -const char kHTTPSEverywhereComponentTestId[] = - "bhlmpjhncoojbkemjkeppfahkglffilp"; - -const char kHTTPSEverywhereComponentTestBase64PublicKey[] = - "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3tAm7HooTNVGQ9cm7Yuc" - "M9sLM/V38JOXzdj7z9dyDIfO64N69Gr5dn3XRzLuD+Pyzpl8MzfY/tIbWNSw3I2a" - "8YcEPmyHl2L4HByKTm+eJ02ArhtkgtZKjiTDc84KQcsTBHqINkMUQYeUN3VW1lz2" - "yuZJrGlqlKCmQq7iRjCSUFu/C9mbJghTF8aKqmLbuf/pUXLpXFCRhCfaeabPqZP4" - "e9efRk7lsOraJMhF1Gcx0iubObKxl6Ov19e4nreYpw7Vp0fHodLzh0YxssLgNhTb" - "txtjWrJaXB5wghi1G0coTy6TgTXxoU9OU70eyf6PgdW4ZcaBIyM3tY6tme4zukvv" - "3wIDAQAB"; - -class HTTPSEverywhereServiceTest : public ExtensionBrowserTest { - public: - HTTPSEverywhereServiceTest() = default; - - void SetUpCommon() { - InitEmbeddedTestServer(); - InitService(); - ExtensionBrowserTest::SetUp(); - } - - void SetUp() override { - feature_list_.InitAndDisableFeature(net::features::kBraveHttpsByDefault); - SetUpCommon(); - } - - void SetUpOnMainThread() override { - ExtensionBrowserTest::SetUpOnMainThread(); - host_resolver()->AddRule("*", "127.0.0.1"); - } - - void PreRunTestOnMainThread() override { - ExtensionBrowserTest::PreRunTestOnMainThread(); - WaitForHTTPSEverywhereServiceThread(); - WaitForAdBlockServiceThreads(); - ASSERT_TRUE( - g_brave_browser_process->https_everywhere_service()->IsInitialized()); - } - - void InitEmbeddedTestServer() { - brave::RegisterPathProvider(); - base::FilePath test_data_dir; - base::PathService::Get(brave::DIR_TEST_DATA, &test_data_dir); - embedded_test_server()->ServeFilesFromDirectory(test_data_dir); - ASSERT_TRUE(embedded_test_server()->Start()); - } - - void InitService() { - brave_shields::HTTPSEverywhereService::SetIgnorePortForTest(true); - brave_shields::SetHTTPSEverywhereComponentIdAndBase64PublicKeyForTest( - kHTTPSEverywhereComponentTestId, - kHTTPSEverywhereComponentTestBase64PublicKey); - } - - void GetTestDataDir(base::FilePath* test_data_dir) { - base::ScopedAllowBlockingForTesting allow_blocking; - base::PathService::Get(brave::DIR_TEST_DATA, test_data_dir); - } - - bool InstallHTTPSEverywhereExtension() { - base::FilePath test_data_dir; - GetTestDataDir(&test_data_dir); - const extensions::Extension* httpse_extension = - InstallExtension(test_data_dir.AppendASCII("https-everywhere-data"), 1); - if (!httpse_extension) - return false; - - g_brave_browser_process->https_everywhere_service()->InitDB( - httpse_extension->path()); - WaitForHTTPSEverywhereServiceThread(); - - return true; - } - - void WaitForHTTPSEverywhereServiceThread() { - scoped_refptr io_helper(new base::ThreadTestHelper( - g_brave_browser_process->https_everywhere_service()->GetTaskRunner())); - ASSERT_TRUE(io_helper->Run()); - } - - void WaitForAdBlockServiceThreads() { - scoped_refptr tr_helper(new base::ThreadTestHelper( - g_brave_browser_process->ad_block_service()->GetTaskRunner())); - ASSERT_TRUE(tr_helper->Run()); - } - - std::vector> - source_providers_; - - void UpdateCustomAdBlockInstanceWithRules(const std::string& rules, - const std::string& resources) { - auto source_provider = - std::make_unique(rules, resources); - - brave_shields::AdBlockService* ad_block_service = - g_brave_browser_process->ad_block_service(); - ad_block_service->UseCustomSourceProvidersForTest(source_provider.get(), - source_provider.get()); - - source_providers_.push_back(std::move(source_provider)); - - WaitForAdBlockServiceThreads(); - } - - protected: - base::test::ScopedFeatureList feature_list_; -}; - -// Load a URL which has an HTTPSE rule and verify we rewrote it. -IN_PROC_BROWSER_TEST_F(HTTPSEverywhereServiceTest, RedirectsKnownSite) { - ASSERT_TRUE(InstallHTTPSEverywhereExtension()); - - GURL url = embedded_test_server()->GetURL("www.digg.com", "/"); - ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url)); - content::WebContents* contents = - browser()->tab_strip_model()->GetActiveWebContents(); - EXPECT_EQ(GURL("https://www.digg.com/"), contents->GetLastCommittedURL()); -} - -// Load a URL which has an HTTPSE rule and an adblock redirect rule - verify -// that the adblock rule takes precedence -IN_PROC_BROWSER_TEST_F(HTTPSEverywhereServiceTest, PreferAdblockRedirect) { - ASSERT_TRUE(InstallHTTPSEverywhereExtension()); - - std::string frame_html = - ""; - - std::string resource_base64; - base::Base64Encode(frame_html, &resource_base64); - - UpdateCustomAdBlockInstanceWithRules( - "www.digg.com$subdocument,redirect=custom-resource-html", - R"( - [ - { - "name": "custom-resource-html", - "aliases": [], - "kind": { - "mime":"text/html" - }, - "content": ")" + - resource_base64 + R"(" - } - ])"); - - GURL url = embedded_test_server()->GetURL("a.com", "/iframe.html"); - ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url)); - - GURL iframe_url = embedded_test_server()->GetURL("www.digg.com", "/"); - const char kIframeID[] = "test"; - content::WebContents* contents = - browser()->tab_strip_model()->GetActiveWebContents(); - EXPECT_TRUE(NavigateIframeToURL(contents, kIframeID, iframe_url)); - content::RenderFrameHost* iframe_contents = - ChildFrameAt(contents->GetPrimaryMainFrame(), 0); - WaitForLoadStop(contents); - - // The URL should not be modified - ASSERT_EQ(iframe_url, iframe_contents->GetLastCommittedURL()); - - // The `customResource` JS property should be defined - const GURL resource_url = - embedded_test_server()->GetURL("example.com", "/example.html"); - ASSERT_EQ(true, EvalJs(iframe_contents, "customResource")); -} - -// Load a URL which has no HTTPSE rule and verify we did not rewrite it. -IN_PROC_BROWSER_TEST_F(HTTPSEverywhereServiceTest, NoRedirectsNotKnownSite) { - ASSERT_TRUE(InstallHTTPSEverywhereExtension()); - - GURL url = embedded_test_server()->GetURL("www.brianbondy.com", "/"); - ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url)); - content::WebContents* contents = - browser()->tab_strip_model()->GetActiveWebContents(); - - GURL::Replacements clear_port; - clear_port.ClearPort(); - - EXPECT_EQ(GURL("http://www.brianbondy.com/"), - contents->GetLastCommittedURL().ReplaceComponents(clear_port)); -} - -// Make sure iframes that should redirect to HTTPS actually redirect and that -// the header is intact. -IN_PROC_BROWSER_TEST_F(HTTPSEverywhereServiceTest, RedirectsKnownSiteInIframe) { - ASSERT_TRUE(InstallHTTPSEverywhereExtension()); - GURL url = embedded_test_server()->GetURL("a.com", "/iframe.html"); - ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url)); - - GURL iframe_url = embedded_test_server()->GetURL("www.digg.com", "/"); - const char kIframeID[] = "test"; - content::WebContents* contents = - browser()->tab_strip_model()->GetActiveWebContents(); - EXPECT_TRUE(NavigateIframeToURL(contents, kIframeID, iframe_url)); - content::RenderFrameHost* iframe_contents = - ChildFrameAt(contents->GetPrimaryMainFrame(), 0); - WaitForLoadStop(contents); - EXPECT_EQ(GURL("https://www.digg.com/"), - iframe_contents->GetLastCommittedURL()); -} - -class HTTPSEverywhereServiceTest_HttpsByDefaultEnabled - : public HTTPSEverywhereServiceTest { - public: - HTTPSEverywhereServiceTest_HttpsByDefaultEnabled() = default; - - void SetUp() override { - feature_list_.InitAndEnableFeature(net::features::kBraveHttpsByDefault); - HTTPSEverywhereServiceTest::SetUpCommon(); - } -}; - -// Verify that HTTPE rules are disabled when HTTPS by Default is enabled -IN_PROC_BROWSER_TEST_F(HTTPSEverywhereServiceTest_HttpsByDefaultEnabled, - RedirectsKnownSite) { - ASSERT_TRUE(InstallHTTPSEverywhereExtension()); - auto* settings_map = - HostContentSettingsMapFactory::GetForProfile(browser()->profile()); - GURL insecure_url = embedded_test_server()->GetURL("www.digg.com", "/"); - brave_shields::SetHttpsUpgradeControlType( - settings_map, brave_shields::ControlType::ALLOW, GURL()); - ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), insecure_url)); - content::WebContents* contents = - browser()->tab_strip_model()->GetActiveWebContents(); - EXPECT_EQ(insecure_url, contents->GetLastCommittedURL()); -} diff --git a/components/brave_shields/common/brave_shields_panel.mojom b/components/brave_shields/common/brave_shields_panel.mojom index 509396fb0c1c..a6cac7751afa 100644 --- a/components/brave_shields/common/brave_shields_panel.mojom +++ b/components/brave_shields/common/brave_shields_panel.mojom @@ -42,7 +42,6 @@ interface DataHandler { SetCookieBlockMode(CookieBlockMode mode); SetHttpsUpgradeMode(HttpsUpgradeMode mode); SetIsNoScriptsEnabled(bool is_enabled); - SetHTTPSEverywhereEnabled(bool is_enabled); SetBraveShieldsEnabled(bool is_enabled); SetForgetFirstPartyStorageEnabled(bool is_enabled); OpenWebCompatWindow(); @@ -68,7 +67,6 @@ struct SiteSettings { AdBlockMode ad_block_mode; FingerprintMode fingerprint_mode; CookieBlockMode cookie_block_mode; - bool is_https_everywhere_enabled; HttpsUpgradeMode https_upgrade_mode; bool is_noscript_enabled; bool is_forget_first_party_storage_enabled; diff --git a/components/brave_shields/resources/panel/components/advanced-controls-content/index.tsx b/components/brave_shields/resources/panel/components/advanced-controls-content/index.tsx index 542fd797f2dd..ec0ff0669f25 100644 --- a/components/brave_shields/resources/panel/components/advanced-controls-content/index.tsx +++ b/components/brave_shields/resources/panel/components/advanced-controls-content/index.tsx @@ -97,11 +97,6 @@ function AdvancedControlsContent () { if (getSiteSettings) getSiteSettings() } - const handleHTTPSEverywhereEnabledChange = (isEnabled: boolean) => { - getPanelBrowserAPI().dataHandler.setHTTPSEverywhereEnabled(isEnabled) - if (getSiteSettings) getSiteSettings() - } - const handleForgetFirstPartyStorageEnabledChange = (isEnabled: boolean) => { getPanelBrowserAPI().dataHandler.setForgetFirstPartyStorageEnabled( isEnabled @@ -110,7 +105,6 @@ function AdvancedControlsContent () { } const adsListCount = siteBlockInfo?.adsList.length ?? 0 - const httpRedirectsListCount = siteBlockInfo?.httpRedirectsList.length ?? 0 const jsListCount = siteBlockInfo?.blockedJsList.length ?? 0 const isHttpsByDefaultEnabled = loadTimeData.getBoolean('isHttpsByDefaultEnabled') const isTorProfile = loadTimeData.getBoolean('isTorProfile') @@ -150,26 +144,6 @@ function AdvancedControlsContent () { {adsListCount > 99 ? '99+' : adsListCount} - {!isHttpsByDefaultEnabled && - - setViewType?.(ViewType.HttpsList)} - disabled={httpRedirectsListCount <= 0} - > - {httpRedirectsListCount > 99 ? '99+' : httpRedirectsListCount} - - } {(isHttpsByDefaultEnabled && !isTorProfile) &&