Index: chrome/browser/subresource_filter/chrome_subresource_filter_client.cc |
diff --git a/chrome/browser/subresource_filter/chrome_subresource_filter_client.cc b/chrome/browser/subresource_filter/chrome_subresource_filter_client.cc |
index 02b40dbbb4661b71b3982f6173eed4d10a333e8f..acedf395594287c031e7d5b37092dd2f42a693ec 100644 |
--- a/chrome/browser/subresource_filter/chrome_subresource_filter_client.cc |
+++ b/chrome/browser/subresource_filter/chrome_subresource_filter_client.cc |
@@ -4,27 +4,26 @@ |
#include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" |
-#include <string> |
- |
#include "base/metrics/histogram_macros.h" |
#include "chrome/browser/browser_process.h" |
-#include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
#include "chrome/browser/content_settings/tab_specific_content_settings.h" |
#include "chrome/browser/infobars/infobar_service.h" |
#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/subresource_filter/subresource_filter_content_settings_manager.h" |
#include "chrome/browser/subresource_filter/subresource_filter_content_settings_manager_factory.h" |
#include "chrome/browser/ui/android/content_settings/subresource_filter_infobar_delegate.h" |
-#include "components/content_settings/core/browser/host_content_settings_map.h" |
-#include "components/content_settings/core/common/content_settings_types.h" |
#include "components/subresource_filter/content/browser/content_ruleset_service.h" |
+#include "components/subresource_filter/core/common/activation_level.h" |
+#include "components/subresource_filter/core/common/activation_state.h" |
ChromeSubresourceFilterClient::ChromeSubresourceFilterClient( |
content::WebContents* web_contents) |
- : web_contents_(web_contents), shown_for_navigation_(false) { |
- DCHECK(web_contents); |
- // Ensure the content settings manager is initialized. |
- SubresourceFilterContentSettingsManagerFactory::EnsureForProfile( |
- Profile::FromBrowserContext(web_contents_->GetBrowserContext())); |
+ : settings_manager_( |
+ SubresourceFilterContentSettingsManagerFactory::EnsureForProfile( |
+ Profile::FromBrowserContext(web_contents->GetBrowserContext()))), |
+ web_contents_(web_contents), |
+ shown_for_navigation_(false) { |
+ DCHECK(settings_manager_); |
} |
ChromeSubresourceFilterClient::~ChromeSubresourceFilterClient() {} |
@@ -33,44 +32,56 @@ void ChromeSubresourceFilterClient::ToggleNotificationVisibility( |
bool visibility) { |
if (shown_for_navigation_ && visibility) |
return; |
- |
- shown_for_navigation_ = visibility; |
- TabSpecificContentSettings* content_settings = |
- TabSpecificContentSettings::FromWebContents(web_contents_); |
+ shown_for_navigation_ = false; |
// |visibility| is false when a new navigation starts. |
if (visibility) { |
- content_settings->OnContentBlocked( |
- CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER); |
- LogAction(kActionUIShown); |
+ const GURL& top_level_url = web_contents_->GetLastCommittedURL(); |
+ if (!settings_manager_->ShouldShowUIForSite(top_level_url)) { |
+ LogAction(kActionUISuppressed); |
+ return; |
+ } |
#if defined(OS_ANDROID) |
InfoBarService* infobar_service = |
InfoBarService::FromWebContents(web_contents_); |
SubresourceFilterInfobarDelegate::Create(infobar_service); |
#endif |
+ TabSpecificContentSettings* content_settings = |
+ TabSpecificContentSettings::FromWebContents(web_contents_); |
+ content_settings->OnContentBlocked( |
+ CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER); |
+ |
+ LogAction(kActionUIShown); |
+ shown_for_navigation_ = true; |
+ settings_manager_->OnDidShowUI(top_level_url); |
} else { |
LogAction(kActionNavigationStarted); |
} |
} |
bool ChromeSubresourceFilterClient::IsWhitelistedByContentSettings( |
- const GURL& url) { |
- return GetContentSettingForUrl(url) == CONTENT_SETTING_BLOCK; |
+ const GURL& top_level_url) { |
+ return settings_manager_->GetContentSetting(top_level_url) == |
+ CONTENT_SETTING_BLOCK; |
} |
void ChromeSubresourceFilterClient::WhitelistByContentSettings( |
- const GURL& url) { |
- // Whitelist via content settings. |
- Profile* profile = |
- Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
- DCHECK(profile); |
- HostContentSettingsMap* settings_map = |
- HostContentSettingsMapFactory::GetForProfile(profile); |
- settings_map->SetContentSettingDefaultScope( |
- url, url, ContentSettingsType::CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER, |
- std::string(), CONTENT_SETTING_BLOCK); |
+ const GURL& top_level_url) { |
+ // Whitelist via content settings. SetContentSettings has logic to ignore |
+ // metrics for these calls, so also log the generic blocked metrics. |
+ settings_manager_->SetContentSetting(top_level_url, CONTENT_SETTING_BLOCK, |
+ true /* from_ui */); |
+} |
- LogAction(kActionContentSettingsBlockedFromUI); |
+void ChromeSubresourceFilterClient::OnActivationComputed( |
+ const GURL& top_level_url, |
+ const subresource_filter::ActivationState& state) { |
+ // Clear the content setting when the site does not trigger activation. |
+ if (state.activation_level != subresource_filter::ActivationLevel::ENABLED && |
+ settings_manager_->GetContentSetting(top_level_url) == |
+ CONTENT_SETTING_ALLOW) { |
+ settings_manager_->ClearContentSetting(top_level_url); |
+ } |
} |
// static |
@@ -79,18 +90,6 @@ void ChromeSubresourceFilterClient::LogAction(SubresourceFilterAction action) { |
kActionLastEntry); |
} |
-ContentSetting ChromeSubresourceFilterClient::GetContentSettingForUrl( |
- const GURL& url) { |
- Profile* profile = |
- Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
- DCHECK(profile); |
- HostContentSettingsMap* settings_map = |
- HostContentSettingsMapFactory::GetForProfile(profile); |
- return settings_map->GetContentSetting( |
- url, url, ContentSettingsType::CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER, |
- std::string()); |
-} |
- |
subresource_filter::VerifiedRulesetDealer::Handle* |
ChromeSubresourceFilterClient::GetRulesetDealer() { |
subresource_filter::ContentRulesetService* ruleset_service = |