| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" | 5 #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } else { | 114 } else { |
| 115 LogAction(kActionNavigationStarted); | 115 LogAction(kActionNavigationStarted); |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 | 118 |
| 119 bool ChromeSubresourceFilterClient::OnPageActivationComputed( | 119 bool ChromeSubresourceFilterClient::OnPageActivationComputed( |
| 120 content::NavigationHandle* navigation_handle, | 120 content::NavigationHandle* navigation_handle, |
| 121 bool activated) { | 121 bool activated) { |
| 122 const GURL& url(navigation_handle->GetURL()); | 122 const GURL& url(navigation_handle->GetURL()); |
| 123 DCHECK(navigation_handle->IsInMainFrame()); | 123 DCHECK(navigation_handle->IsInMainFrame()); |
| 124 |
| 125 // If the site is no longer activated, clear the metadata. This is to maintain |
| 126 // the invariant that metadata implies activated. |
| 127 if (!activated && url.SchemeIsHTTPOrHTTPS()) |
| 128 settings_manager_->ClearSiteMetadata(url); |
| 129 |
| 124 // Return whether the activation should be whitelisted. | 130 // Return whether the activation should be whitelisted. |
| 125 return whitelisted_hosts_.count(url.host()) || | 131 return whitelisted_hosts_.count(url.host()) || |
| 126 settings_manager_->GetSitePermission(url) == CONTENT_SETTING_BLOCK; | 132 settings_manager_->GetSitePermission(url) == CONTENT_SETTING_BLOCK; |
| 133 // TODO(csharrison): Consider setting the metadata to an empty dict here if |
| 134 // the site is activated and not whitelisted. Need to be careful about various |
| 135 // edge cases like |should_suppress_notification| and DRYRUN activation. |
| 127 } | 136 } |
| 128 | 137 |
| 129 void ChromeSubresourceFilterClient::WhitelistByContentSettings( | 138 void ChromeSubresourceFilterClient::WhitelistByContentSettings( |
| 130 const GURL& top_level_url) { | 139 const GURL& top_level_url) { |
| 131 settings_manager_->WhitelistSite(top_level_url); | 140 settings_manager_->WhitelistSite(top_level_url); |
| 132 } | 141 } |
| 133 | 142 |
| 134 void ChromeSubresourceFilterClient::WhitelistInCurrentWebContents( | 143 void ChromeSubresourceFilterClient::WhitelistInCurrentWebContents( |
| 135 const GURL& url) { | 144 const GURL& url) { |
| 136 if (url.SchemeIsHTTPOrHTTPS()) | 145 if (url.SchemeIsHTTPOrHTTPS()) |
| 137 whitelisted_hosts_.insert(url.host()); | 146 whitelisted_hosts_.insert(url.host()); |
| 138 } | 147 } |
| 139 | 148 |
| 140 // static | 149 // static |
| 141 void ChromeSubresourceFilterClient::LogAction(SubresourceFilterAction action) { | 150 void ChromeSubresourceFilterClient::LogAction(SubresourceFilterAction action) { |
| 142 UMA_HISTOGRAM_ENUMERATION("SubresourceFilter.Actions", action, | 151 UMA_HISTOGRAM_ENUMERATION("SubresourceFilter.Actions", action, |
| 143 kActionLastEntry); | 152 kActionLastEntry); |
| 144 } | 153 } |
| 145 | 154 |
| 146 subresource_filter::VerifiedRulesetDealer::Handle* | 155 subresource_filter::VerifiedRulesetDealer::Handle* |
| 147 ChromeSubresourceFilterClient::GetRulesetDealer() { | 156 ChromeSubresourceFilterClient::GetRulesetDealer() { |
| 148 subresource_filter::ContentRulesetService* ruleset_service = | 157 subresource_filter::ContentRulesetService* ruleset_service = |
| 149 g_browser_process->subresource_filter_ruleset_service(); | 158 g_browser_process->subresource_filter_ruleset_service(); |
| 150 return ruleset_service ? ruleset_service->ruleset_dealer() : nullptr; | 159 return ruleset_service ? ruleset_service->ruleset_dealer() : nullptr; |
| 151 } | 160 } |
| OLD | NEW |