summaryrefslogtreecommitdiff
path: root/chromium/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc')
-rw-r--r--chromium/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc77
1 files changed, 60 insertions, 17 deletions
diff --git a/chromium/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc b/chromium/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc
index 01d474160f0..3a8bf2a3efe 100644
--- a/chromium/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc
+++ b/chromium/components/subresource_filter/content/browser/content_subresource_filter_driver_factory.cc
@@ -7,12 +7,17 @@
#include "base/memory/ptr_util.h"
#include "base/rand_util.h"
#include "base/time/time.h"
+#include "components/subresource_filter/content/browser/page_load_statistics.h"
#include "components/subresource_filter/content/browser/subresource_filter_client.h"
#include "components/subresource_filter/content/browser/subresource_filter_observer_manager.h"
+#include "components/subresource_filter/core/browser/subresource_filter_constants.h"
#include "components/subresource_filter/core/common/activation_list.h"
#include "components/subresource_filter/core/common/activation_state.h"
#include "content/public/browser/navigation_handle.h"
+#include "content/public/browser/page_navigator.h"
+#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/common/console_message_level.h"
#include "net/base/net_errors.h"
#include "url/gurl.h"
@@ -64,28 +69,37 @@ ContentSubresourceFilterDriverFactory::
void ContentSubresourceFilterDriverFactory::NotifyPageActivationComputed(
content::NavigationHandle* navigation_handle,
ActivationDecision activation_decision,
- Configuration::ActivationOptions matched_options) {
+ const Configuration& matched_configuration) {
DCHECK(navigation_handle->IsInMainFrame());
DCHECK(!navigation_handle->IsSameDocument());
if (navigation_handle->GetNetErrorCode() != net::OK)
return;
activation_decision_ = activation_decision;
- activation_options_ = matched_options;
+ matched_configuration_ = matched_configuration;
DCHECK_NE(activation_decision_, ActivationDecision::UNKNOWN);
// ACTIVATION_DISABLED implies DISABLED activation level.
DCHECK(activation_decision_ != ActivationDecision::ACTIVATION_DISABLED ||
- activation_options_.activation_level == ActivationLevel::DISABLED);
- ActivationState state = ActivationState(activation_options_.activation_level);
+ activation_options().activation_level == ActivationLevel::DISABLED);
+
+ // Ensure the matched config is in our config list. If it wasn't then this
+ // must be a forced activation via devtools.
+ DCHECK(activation_decision_ != ActivationDecision::ACTIVATED ||
+ HasEnabledConfiguration(matched_configuration) ||
+ matched_configuration == Configuration::MakeForForcedActivation())
+ << matched_configuration;
+
+ ActivationState state =
+ ActivationState(activation_options().activation_level);
state.measure_performance = ShouldMeasurePerformanceForPageLoad(
- activation_options_.performance_measurement_rate);
+ activation_options().performance_measurement_rate);
// TODO(csharrison): Also use metadata returned from the safe browsing filter,
// when it is available to set enable_logging. Add tests for this behavior.
state.enable_logging =
- activation_options_.activation_level == ActivationLevel::ENABLED &&
- !activation_options_.should_suppress_notifications &&
+ activation_options().activation_level == ActivationLevel::ENABLED &&
+ !activation_options().should_suppress_notifications &&
base::FeatureList::IsEnabled(
kSafeBrowsingSubresourceFilterExperimentalUI);
@@ -94,19 +108,48 @@ void ContentSubresourceFilterDriverFactory::NotifyPageActivationComputed(
state);
}
-void ContentSubresourceFilterDriverFactory::OnFirstSubresourceLoadDisallowed() {
- if (activation_options_.should_suppress_notifications)
- return;
- client_->ToggleNotificationVisibility(activation_options_.activation_level ==
- ActivationLevel::ENABLED);
+// Blocking popups here should trigger the standard popup blocking UI, so don't
+// force the subresource filter specific UI.
+bool ContentSubresourceFilterDriverFactory::ShouldDisallowNewWindow(
+ const content::OpenURLParams* open_url_params) {
+ if (activation_options().activation_level != ActivationLevel::ENABLED ||
+ !activation_options().should_strengthen_popup_blocker)
+ return false;
+
+ // Block new windows from navigations whose triggering JS Event has an
+ // isTrusted bit set to false. This bit is set to true if the event is
+ // generated via a user action. See docs:
+ // https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted
+ bool should_block = true;
+ if (open_url_params) {
+ should_block = open_url_params->triggering_event_info ==
+ blink::WebTriggeringEventInfo::kFromUntrustedEvent;
+ }
+ if (should_block) {
+ web_contents()->GetMainFrame()->AddMessageToConsole(
+ content::CONSOLE_MESSAGE_LEVEL_ERROR, kDisallowNewWindowMessage);
+ if (PageLoadStatistics* statistics =
+ throttle_manager_->page_load_statistics()) {
+ statistics->OnBlockedPopup();
+ }
+ }
+ return should_block;
}
-bool ContentSubresourceFilterDriverFactory::AllowStrongPopupBlocking() {
- return activation_options_.should_strengthen_popup_blocker;
+void ContentSubresourceFilterDriverFactory::OnFirstSubresourceLoadDisallowed() {
+ if (activation_options().should_suppress_notifications)
+ return;
+ // This shouldn't happen normally, but in the rare case that an IPC from a
+ // previous page arrives late we should guard against it.
+ if (activation_options().should_disable_ruleset_rules ||
+ activation_options().activation_level != ActivationLevel::ENABLED) {
+ return;
+ }
+ client_->ShowNotification();
}
bool ContentSubresourceFilterDriverFactory::AllowRulesetRules() {
- return !activation_options_.should_disable_ruleset_rules;
+ return !activation_options().should_disable_ruleset_rules;
}
void ContentSubresourceFilterDriverFactory::DidStartNavigation(
@@ -114,7 +157,7 @@ void ContentSubresourceFilterDriverFactory::DidStartNavigation(
if (navigation_handle->IsInMainFrame() &&
!navigation_handle->IsSameDocument()) {
activation_decision_ = ActivationDecision::UNKNOWN;
- client_->ToggleNotificationVisibility(false);
+ client_->OnNewNavigationStarted();
}
}
@@ -125,7 +168,7 @@ void ContentSubresourceFilterDriverFactory::DidFinishNavigation(
activation_decision_ == ActivationDecision::UNKNOWN &&
navigation_handle->HasCommitted()) {
activation_decision_ = ActivationDecision::ACTIVATION_DISABLED;
- activation_options_ = Configuration::ActivationOptions();
+ matched_configuration_ = Configuration();
}
}