diff --git a/android/java/org/chromium/chrome/browser/app/BraveActivity.java b/android/java/org/chromium/chrome/browser/app/BraveActivity.java index 3027e18f1ff6..6bf74e5160d5 100644 --- a/android/java/org/chromium/chrome/browser/app/BraveActivity.java +++ b/android/java/org/chromium/chrome/browser/app/BraveActivity.java @@ -478,7 +478,6 @@ private void checkForYandexSE() { private void checkForNotificationData() { Intent notifIntent = getIntent(); if (notifIntent != null && notifIntent.getStringExtra(RetentionNotificationUtil.NOTIFICATION_TYPE) != null) { - Log.e("NTP", notifIntent.getStringExtra(RetentionNotificationUtil.NOTIFICATION_TYPE)); String notificationType = notifIntent.getStringExtra(RetentionNotificationUtil.NOTIFICATION_TYPE); switch (notificationType) { case RetentionNotificationUtil.HOUR_3: 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 fa22ae9ed41d..00cf8f4b93ba 100644 --- a/android/java/org/chromium/chrome/browser/preferences/website/BraveShieldsContentSettings.java +++ b/android/java/org/chromium/chrome/browser/preferences/website/BraveShieldsContentSettings.java @@ -95,6 +95,9 @@ public static void setShieldsValue(Profile profile, String host, String resource BraveShieldsContentSettingsJni.get().setFingerprintingControlType(settingOption, host, profile); } else if (resourceIndentifier.equals(RESOURCE_IDENTIFIER_COOKIES)) { BraveShieldsContentSettingsJni.get().setCookieControlType(settingOption, host, profile); + } else if (resourceIndentifier.equals(RESOURCE_IDENTIFIER_TRACKERS)) { + BraveShieldsContentSettingsJni.get().setCosmeticFilteringControlType( + settingOption, host, profile); } } @@ -119,6 +122,9 @@ public static String getShieldsValue(Profile profile, String host, String resour settings = BraveShieldsContentSettingsJni.get().getFingerprintingControlType(host, profile); } else if (resourceIndentifier.equals(RESOURCE_IDENTIFIER_COOKIES)) { settings = BraveShieldsContentSettingsJni.get().getCookieControlType(host, profile); + } else if (resourceIndentifier.equals(RESOURCE_IDENTIFIER_TRACKERS)) { + settings = BraveShieldsContentSettingsJni.get().getCosmeticFilteringControlType( + host, profile); } return settings; } @@ -160,5 +166,8 @@ interface Natives { boolean getHTTPSEverywhereEnabled(String url, Profile profile); void setNoScriptControlType(String type, String url, Profile profile); String getNoScriptControlType(String url, Profile profile); + + void setCosmeticFilteringControlType(String type, String url, Profile profile); + String getCosmeticFilteringControlType(String url, Profile profile); } } diff --git a/android/java/org/chromium/chrome/browser/shields/BraveShieldsHandler.java b/android/java/org/chromium/chrome/browser/shields/BraveShieldsHandler.java index 4fb47a269287..156d3e4fb7aa 100644 --- a/android/java/org/chromium/chrome/browser/shields/BraveShieldsHandler.java +++ b/android/java/org/chromium/chrome/browser/shields/BraveShieldsHandler.java @@ -81,6 +81,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -486,16 +487,138 @@ private void setUpSecondaryLayout() { shieldsText.setText(mTitle.replaceFirst("^(http[s]?://www\\.|http[s]?://|www\\.)", "")); setUpSwitchLayouts(); - setUpCookiesLayout(); - setUpFingerprintingLayout(); + + setupDetailsLayouts(); + } + + private void setupDetailsLayouts() { + ArrayList detailsLayouts = new ArrayList<>(); + detailsLayouts.add(BraveShieldsContentSettings.RESOURCE_IDENTIFIER_TRACKERS); + detailsLayouts.add(BraveShieldsContentSettings.RESOURCE_IDENTIFIER_FINGERPRINTING); + detailsLayouts.add(BraveShieldsContentSettings.RESOURCE_IDENTIFIER_COOKIES); + + int layoutId = 0; + int mSecondaryLayoutId = 0; + int titleStringId = 0; + int subtitleStringId = 0; + int option1StringId = 0; + int option2StringId = 0; + int option3StringId = 0; + + for (final String layout : detailsLayouts) { + switch (layout) { + case BraveShieldsContentSettings.RESOURCE_IDENTIFIER_TRACKERS: + layoutId = R.id.brave_shields_block_cross_trackers_layout_id; + mSecondaryLayoutId = R.id.brave_shields_cross_site_trackers_layout_id; + titleStringId = R.string.block_trackers_ads_title; + subtitleStringId = R.string.block_trackers_ads_summary; + option1StringId = R.string.block_trackers_ads_option_1; + option2StringId = R.string.block_trackers_ads_option_2; + option3StringId = R.string.block_trackers_ads_option_3; + break; + case BraveShieldsContentSettings.RESOURCE_IDENTIFIER_FINGERPRINTING: + layoutId = R.id.brave_shields_block_fingerprinting_layout_id; + mSecondaryLayoutId = R.id.brave_shields_fingerprinting_layout_id; + titleStringId = R.string.block_fingerprinting; + subtitleStringId = R.string.block_fingerprinting_text; + option1StringId = R.string.block_fingerprinting_option_1; + option2StringId = R.string.block_fingerprinting_option_2; + option3StringId = R.string.block_fingerprinting_option_3; + break; + case BraveShieldsContentSettings.RESOURCE_IDENTIFIER_COOKIES: + layoutId = R.id.brave_shields_block_cookies_layout_id; + mSecondaryLayoutId = R.id.brave_shields_cookies_layout_id; + titleStringId = R.string.block_cookies; + subtitleStringId = R.string.block_cookies_text; + option1StringId = R.string.block_cookies_option_1; + option2StringId = R.string.block_cross_site_cookies; + option3StringId = R.string.block_cookies_option_3; + break; + } + + LinearLayout mBlockShieldsLayout = mPopupView.findViewById(layoutId); + TextView mBlockShieldsOptionTitle = mBlockShieldsLayout.findViewById(R.id.option_title); + mBlockShieldsOptionTitle.setText(titleStringId); + TextView mBlockShieldsOptionText = mBlockShieldsLayout.findViewById(R.id.option_text); + mBlockShieldsOptionText.setText(subtitleStringId); + RadioButton mBlockShieldsOption1 = mBlockShieldsLayout.findViewById(R.id.option1); + mBlockShieldsOption1.setText(option1StringId); + RadioButton mBlockShieldsOption2 = mBlockShieldsLayout.findViewById(R.id.option2); + mBlockShieldsOption2.setText(option2StringId); + RadioButton mBlockShieldsOption3 = mBlockShieldsLayout.findViewById(R.id.option3); + mBlockShieldsOption3.setText(option3StringId); + Button mBlockShieldsDoneButton = mBlockShieldsLayout.findViewById(R.id.done_button); + mBlockShieldsDoneButton.setOnClickListener(mDoneClickListener); + ImageView mBlockShieldsBackButton = mBlockShieldsLayout.findViewById(R.id.back_button); + mBlockShieldsBackButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mBlockShieldsLayout.setVisibility(View.GONE); + mMainLayout.setVisibility(View.VISIBLE); + } + }); + + LinearLayout mShieldsLayout = mSecondaryLayout.findViewById(mSecondaryLayoutId); + mShieldsLayout.setBackground(null); + mShieldsLayout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + mMainLayout.setVisibility(View.GONE); + mBlockShieldsLayout.setVisibility(View.VISIBLE); + } + }); + ImageView mBlockShieldsIcon = mShieldsLayout.findViewById(R.id.toggle_favicon); + mBlockShieldsIcon.setImageResource(R.drawable.ic_chevron_right); + mBlockShieldsIcon.setColorFilter( + mContext.getResources().getColor(R.color.default_icon_color_tint_list)); + TextView mBlockShieldsText = mShieldsLayout.findViewById(R.id.toggle_text); + mBlockShieldsText.setText(titleStringId); + + String settingOption = + BraveShieldsContentSettings.getShieldsValue(mProfile, mHost, layout); + if (settingOption.equals(BraveShieldsContentSettings.BLOCK_RESOURCE)) { + mBlockShieldsOption1.setChecked(true); + } else if (settingOption.equals( + BraveShieldsContentSettings.BLOCK_THIRDPARTY_RESOURCE)) { + mBlockShieldsOption2.setChecked(true); + } else if (settingOption.equals(BraveShieldsContentSettings.ALLOW_RESOURCE)) { + mBlockShieldsOption3.setChecked(true); + } + + RadioGroup mBlockShieldsOptionGroup = + mBlockShieldsLayout.findViewById(R.id.options_radio_group); + mBlockShieldsOptionGroup.setOnCheckedChangeListener( + new RadioGroup.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(RadioGroup group, int checkedId) { + RadioButton checkedRadioButton = + (RadioButton) group.findViewById(checkedId); + boolean isChecked = checkedRadioButton.isChecked(); + if (isChecked) { + if (checkedId == R.id.option1) { + BraveShieldsContentSettings.setShieldsValue(mProfile, mHost, + layout, BraveShieldsContentSettings.BLOCK_RESOURCE, + false); + } else if (checkedId == R.id.option2) { + BraveShieldsContentSettings.setShieldsValue(mProfile, mHost, + layout, + BraveShieldsContentSettings.BLOCK_THIRDPARTY_RESOURCE, + false); + } else if (checkedId == R.id.option3) { + BraveShieldsContentSettings.setShieldsValue(mProfile, mHost, + layout, BraveShieldsContentSettings.ALLOW_RESOURCE, + false); + } + if (null != mMenuObserver) { + mMenuObserver.onMenuTopShieldsChanged(isChecked, false); + } + } + } + }); + } } private void setUpSwitchLayouts() { - LinearLayout mBlockTrackersLayout = mSecondaryLayout.findViewById(R.id.brave_shields_block_trackers_id); - TextView mBlockTrackersText = mBlockTrackersLayout.findViewById(R.id.brave_shields_switch_text); - mBraveShieldsBlockTrackersSwitch = mBlockTrackersLayout.findViewById(R.id.brave_shields_switch); - mBlockTrackersText.setText(R.string.brave_shields_ads_and_trackers); - setupAdsTrackingSwitchClick(mBraveShieldsBlockTrackersSwitch); LinearLayout mUpgradeHttpsLayout = mSecondaryLayout.findViewById(R.id.brave_shields_upgrade_https_id); TextView mUpgradeHttpsText = mUpgradeHttpsLayout.findViewById(R.id.brave_shields_switch_text); @@ -510,146 +633,6 @@ private void setUpSwitchLayouts() { setupBlockingScriptsSwitchClick(mBraveShieldsBlockingScriptsSwitch); } - private void setUpCookiesLayout() { - LinearLayout mBlockCookiesLayout = mPopupView.findViewById(R.id.brave_shields_block_cookies_layout_id); - TextView mCookiesOptionTitle = mBlockCookiesLayout.findViewById(R.id.option_title); - mCookiesOptionTitle.setText(R.string.block_cookies); - TextView mCookiesOptionText = mBlockCookiesLayout.findViewById(R.id.option_text); - mCookiesOptionText.setText(R.string.block_cookies_text); - RadioButton mCookiesOption1 = mBlockCookiesLayout.findViewById(R.id.option1); - mCookiesOption1.setText(R.string.block_cookies_option_1); - RadioButton mCookiesOption2 = mBlockCookiesLayout.findViewById(R.id.option2); - mCookiesOption2.setText(R.string.block_cross_site_cookies); - RadioButton mCookiesOption3 = mBlockCookiesLayout.findViewById(R.id.option3); - mCookiesOption3.setText(R.string.block_cookies_option_3); - Button mCookiesDoneButton = mBlockCookiesLayout.findViewById(R.id.done_button); - mCookiesDoneButton.setOnClickListener(mDoneClickListener); - ImageView mCookiesBackButton = mBlockCookiesLayout.findViewById(R.id.back_button); - mCookiesBackButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - mBlockCookiesLayout.setVisibility(View.GONE); - mMainLayout.setVisibility(View.VISIBLE); - } - }); - - LinearLayout mCookiesLayout = mSecondaryLayout.findViewById(R.id.brave_shields_cookies_layout_id); - mCookiesLayout.setBackground(null); - mCookiesLayout.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - mMainLayout.setVisibility(View.GONE); - mBlockCookiesLayout.setVisibility(View.VISIBLE); - } - }); - ImageView mCookiesIcon = mCookiesLayout.findViewById(R.id.toggle_favicon); - mCookiesIcon.setImageResource(R.drawable.ic_chevron_right); - mCookiesIcon.setColorFilter(mContext.getResources().getColor(R.color.default_icon_color_tint_list)); - TextView mCookiesText = mCookiesLayout.findViewById(R.id.toggle_text); - mCookiesText.setText(R.string.block_cookies); - - String settingOption = BraveShieldsContentSettings.getShieldsValue(mProfile, mHost, BraveShieldsContentSettings.RESOURCE_IDENTIFIER_COOKIES); - if (settingOption.equals(BraveShieldsContentSettings.BLOCK_RESOURCE)) { - mCookiesOption1.setChecked(true); - } else if (settingOption.equals(BraveShieldsContentSettings.BLOCK_THIRDPARTY_RESOURCE)) { - mCookiesOption2.setChecked(true); - } else if (settingOption.equals(BraveShieldsContentSettings.ALLOW_RESOURCE)) { - mCookiesOption3.setChecked(true); - } - - RadioGroup mCookiesOptionGroup = mBlockCookiesLayout.findViewById(R.id.options_radio_group); - mCookiesOptionGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(RadioGroup group, int checkedId) { - RadioButton checkedRadioButton = (RadioButton)group.findViewById(checkedId); - boolean isChecked = checkedRadioButton.isChecked(); - - if (isChecked) { - if (checkedId == R.id.option1) { - BraveShieldsContentSettings.setShieldsValue(mProfile, mHost, BraveShieldsContentSettings.RESOURCE_IDENTIFIER_COOKIES, BraveShieldsContentSettings.BLOCK_RESOURCE, false); - } else if (checkedId == R.id.option2) { - BraveShieldsContentSettings.setShieldsValue(mProfile, mHost, BraveShieldsContentSettings.RESOURCE_IDENTIFIER_COOKIES, BraveShieldsContentSettings.BLOCK_THIRDPARTY_RESOURCE, false); - } else if (checkedId == R.id.option3) { - BraveShieldsContentSettings.setShieldsValue(mProfile, mHost, BraveShieldsContentSettings.RESOURCE_IDENTIFIER_COOKIES, BraveShieldsContentSettings.ALLOW_RESOURCE, false); - } - if (null != mMenuObserver) { - mMenuObserver.onMenuTopShieldsChanged(isChecked, false); - } - } - } - }); - } - - private void setUpFingerprintingLayout() { - LinearLayout mBlockFingerPrintingLayout = mPopupView.findViewById(R.id.brave_shields_block_fingerprinting_layout_id); - TextView mFingerprintingOptionTitle = mBlockFingerPrintingLayout.findViewById(R.id.option_title); - mFingerprintingOptionTitle.setText(R.string.block_fingerprinting); - TextView mFingerprintingOptionText = mBlockFingerPrintingLayout.findViewById(R.id.option_text); - mFingerprintingOptionText.setText(R.string.block_fingerprinting_text); - RadioButton mFingerprintingOption1 = mBlockFingerPrintingLayout.findViewById(R.id.option1); - mFingerprintingOption1.setText(R.string.block_fingerprinting_option_1); - RadioButton mFingerprintingOption2 = mBlockFingerPrintingLayout.findViewById(R.id.option2); - mFingerprintingOption2.setText(R.string.block_fingerprinting_option_2); - RadioButton mFingerprintingOption3 = mBlockFingerPrintingLayout.findViewById(R.id.option3); - mFingerprintingOption3.setText(R.string.block_fingerprinting_option_3); - Button mFingerprintingDoneButton = mBlockFingerPrintingLayout.findViewById(R.id.done_button); - mFingerprintingDoneButton.setOnClickListener(mDoneClickListener); - ImageView mFingerprintingBackButton = mBlockFingerPrintingLayout.findViewById(R.id.back_button); - mFingerprintingBackButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - mBlockFingerPrintingLayout.setVisibility(View.GONE); - mMainLayout.setVisibility(View.VISIBLE); - } - }); - - LinearLayout mFingerPrintingLayout = mSecondaryLayout.findViewById(R.id.brave_shields_fingerprinting_layout_id); - mFingerPrintingLayout.setBackground(null); - mFingerPrintingLayout.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - mMainLayout.setVisibility(View.GONE); - mBlockFingerPrintingLayout.setVisibility(View.VISIBLE); - } - }); - ImageView mFingerPrintingIcon = mFingerPrintingLayout.findViewById(R.id.toggle_favicon); - mFingerPrintingIcon.setImageResource(R.drawable.ic_chevron_right); - mFingerPrintingIcon.setColorFilter(mContext.getResources().getColor(R.color.default_icon_color_tint_list)); - TextView mFingerPrintingText = mFingerPrintingLayout.findViewById(R.id.toggle_text); - mFingerPrintingText.setText(R.string.block_fingerprinting); - - String settingOption = BraveShieldsContentSettings.getShieldsValue(mProfile, mHost, BraveShieldsContentSettings.RESOURCE_IDENTIFIER_FINGERPRINTING); - if (settingOption.equals(BraveShieldsContentSettings.BLOCK_RESOURCE)) { - mFingerprintingOption1.setChecked(true); - } else if (settingOption.equals(BraveShieldsContentSettings.DEFAULT)) { - mFingerprintingOption2.setChecked(true); - } else if (settingOption.equals(BraveShieldsContentSettings.ALLOW_RESOURCE)) { - mFingerprintingOption3.setChecked(true); - } - - RadioGroup mFingerprintingOptionGroup = mBlockFingerPrintingLayout.findViewById(R.id.options_radio_group); - mFingerprintingOptionGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(RadioGroup group, int checkedId) { - RadioButton checkedRadioButton = (RadioButton)group.findViewById(checkedId); - boolean isChecked = checkedRadioButton.isChecked(); - - if (isChecked) { - if (checkedId == R.id.option1) { - BraveShieldsContentSettings.setShieldsValue(mProfile, mHost, BraveShieldsContentSettings.RESOURCE_IDENTIFIER_FINGERPRINTING, BraveShieldsContentSettings.BLOCK_RESOURCE, false); - } else if (checkedId == R.id.option2) { - BraveShieldsContentSettings.setShieldsValue(mProfile, mHost, BraveShieldsContentSettings.RESOURCE_IDENTIFIER_FINGERPRINTING, BraveShieldsContentSettings.DEFAULT, false); - } else if (checkedId == R.id.option3) { - BraveShieldsContentSettings.setShieldsValue(mProfile, mHost, BraveShieldsContentSettings.RESOURCE_IDENTIFIER_FINGERPRINTING, BraveShieldsContentSettings.ALLOW_RESOURCE, false); - } - if (null != mMenuObserver) { - mMenuObserver.onMenuTopShieldsChanged(isChecked, false); - } - } - } - }); - } - private void setUpAboutLayout() { TextView mAboutText = mAboutLayout.findViewById(R.id.about_text); mAboutText.setVisibility(View.VISIBLE); diff --git a/android/java/res/layout/brave_shields_main_layout.xml b/android/java/res/layout/brave_shields_main_layout.xml index bcdcf684e18d..b419e8eecc9e 100644 --- a/android/java/res/layout/brave_shields_main_layout.xml +++ b/android/java/res/layout/brave_shields_main_layout.xml @@ -139,6 +139,10 @@ + + diff --git a/android/java/res/layout/brave_shields_secondary_layout.xml b/android/java/res/layout/brave_shields_secondary_layout.xml index 6d34f0ef0496..9e79b045718d 100644 --- a/android/java/res/layout/brave_shields_secondary_layout.xml +++ b/android/java/res/layout/brave_shields_secondary_layout.xml @@ -27,22 +27,23 @@ android:textStyle="bold" android:textColor="@color/shield_text_color" /> - - - - + - - \ No newline at end of file + + diff --git a/browser/android/brave_shields_content_settings.cc b/browser/android/brave_shields_content_settings.cc index 88e98ad66353..10860ba180c5 100644 --- a/browser/android/brave_shields_content_settings.cc +++ b/browser/android/brave_shields_content_settings.cc @@ -144,6 +144,20 @@ void JNI_BraveShieldsContentSettings_SetCookieControlType(JNIEnv* env, g_browser_process->local_state()); } +void JNI_BraveShieldsContentSettings_SetCosmeticFilteringControlType( + JNIEnv* env, + const base::android::JavaParamRef& type, + const base::android::JavaParamRef& url, + const base::android::JavaParamRef& j_profile) { + brave_shields::SetCosmeticFilteringControlType( + HostContentSettingsMapFactory::GetForProfile( + ProfileAndroid::FromProfileAndroid(j_profile)), + brave_shields::ControlTypeFromString( + base::android::ConvertJavaStringToUTF8(env, type)), + GURL(base::android::ConvertJavaStringToUTF8(env, url)), + g_browser_process->local_state()); +} + base::android::ScopedJavaLocalRef JNI_BraveShieldsContentSettings_GetCookieControlType(JNIEnv* env, const base::android::JavaParamRef& url, @@ -185,6 +199,21 @@ base::android::ScopedJavaLocalRef brave_shields::ControlTypeToString(control_type)); } +base::android::ScopedJavaLocalRef +JNI_BraveShieldsContentSettings_GetCosmeticFilteringControlType( + JNIEnv* env, + const base::android::JavaParamRef& url, + const base::android::JavaParamRef& j_profile) { + brave_shields::ControlType cosmetic_type = + brave_shields::GetCosmeticFilteringControlType( + HostContentSettingsMapFactory::GetForProfile( + ProfileAndroid::FromProfileAndroid(j_profile)), + GURL(base::android::ConvertJavaStringToUTF8(env, url))); + + return base::android::ConvertUTF8ToJavaString( + env, brave_shields::ControlTypeToString(cosmetic_type)); +} + void JNI_BraveShieldsContentSettings_SetHTTPSEverywhereEnabled(JNIEnv* env, jboolean enabled, const base::android::JavaParamRef& url,