Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Unified Diff: components/subresource_filter/content/browser/subresource_filter_activation_navigation_throttle.cc

Issue 2645283007: Add the client for accessing Subresource Filter only list. (Closed)
Patch Set: fix unittest Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/subresource_filter/content/browser/subresource_filter_activation_navigation_throttle.cc
diff --git a/components/subresource_filter/content/browser/subresource_filter_activation_navigation_throttle.cc b/components/subresource_filter/content/browser/subresource_filter_activation_navigation_throttle.cc
new file mode 100644
index 0000000000000000000000000000000000000000..aa50ea085b0e88ff8d72883a8cbee58f581cbd1c
--- /dev/null
+++ b/components/subresource_filter/content/browser/subresource_filter_activation_navigation_throttle.cc
@@ -0,0 +1,106 @@
+// Copyright (c) 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/subresource_filter/content/browser/subresource_filter_activation_navigation_throttle.h"
+
+#include "components/safe_browsing_db/v4_local_database_manager.h"
+#include "components/subresource_filter/content/browser/content_subresource_filter_driver_factory.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/navigation_handle.h"
+#include "content/public/browser/web_contents.h"
+
+namespace {
+
+// Maximum time in milliseconds to wait for the safe browsing service to
+// verify a URL. After this amount of time the outstanding check will be
+// aborted, and the URL will be treated as if it doesn't belong to the
+// Subresource Filter only list.
+const int kCheckUrlTimeoutMs = 5000;
+
+} // namespace
+
+namespace subresource_filter {
+
+SubresourceFilterActivationNavigationThrottle::
+ SubresourceFilterActivationNavigationThrottle(
+ content::NavigationHandle* handle,
+ const scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager>&
+ database_manager)
+ : NavigationThrottle(handle), database_manager_(database_manager) {}
+
+SubresourceFilterActivationNavigationThrottle::
+ ~SubresourceFilterActivationNavigationThrottle() {}
+
+content::NavigationThrottle::ThrottleCheckResult
+SubresourceFilterActivationNavigationThrottle::WillProcessResponse() {
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO, FROM_HERE,
+ base::Bind(&SubresourceFilterActivationNavigationThrottle::CheckUrlOnIO,
+ base::Unretained(this), navigation_handle()->GetURL()));
+ return content::NavigationThrottle::ThrottleCheckResult::DEFER;
+}
+
+void SubresourceFilterActivationNavigationThrottle::CheckUrlOnIO(
+ const GURL& url) {
+ if (database_manager_->CheckUrlForSubresourceFilter(url, this)) {
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&SubresourceFilterActivationNavigationThrottle::
+ OnCheckUrlResultOnUI,
+ AsWeakPtr(), url, safe_browsing::SB_THREAT_TYPE_SAFE,
+ safe_browsing::ThreatPatternType::NONE));
+ }
+ defer_start_time_ = base::TimeTicks::Now();
+}
+
+// SafeBrowsingService::Client implementation, called on the IO thread once
+// the URL has been classified.
+void SubresourceFilterActivationNavigationThrottle::OnCheckBrowseUrlResult(
+ const GURL& url,
+ safe_browsing::SBThreatType threat_type,
+ const safe_browsing::ThreatMetadata& metadata) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
+ timer_.Stop(); // Cancel the timeout timer.
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(
+ &SubresourceFilterActivationNavigationThrottle::OnCheckUrlResultOnUI,
+ AsWeakPtr(), url, threat_type, metadata.threat_pattern_type));
+}
+
+void SubresourceFilterActivationNavigationThrottle::OnCheckUrlResultOnUI(
+ const GURL& url,
+ safe_browsing::SBThreatType threat_type,
+ safe_browsing::ThreatPatternType pattern_type) {
+ content::WebContents* web_contents = navigation_handle()->GetWebContents();
+ if (web_contents) {
+ using subresource_filter::ContentSubresourceFilterDriverFactory;
+ ContentSubresourceFilterDriverFactory* driver_factory =
+ ContentSubresourceFilterDriverFactory::FromWebContents(web_contents);
+ DCHECK(driver_factory);
+
+ driver_factory->OnMainResourceMatchedSafeBrowsingBlacklist(
+ url, std::vector<GURL>(), threat_type, pattern_type);
+ }
+ navigation_handle()->Resume();
+}
+
+bool SubresourceFilterActivationNavigationThrottle::CheckUrl(const GURL& url) {
+ if (database_manager_->CheckUrlForSubresourceFilter(url, this))
+ return true;
+
+ timer_.Start(
+ FROM_HERE, base::TimeDelta::FromMilliseconds(kCheckUrlTimeoutMs), this,
+ &SubresourceFilterActivationNavigationThrottle::OnCheckUrlTimeout);
+ return false;
+}
+
+void SubresourceFilterActivationNavigationThrottle::OnCheckUrlTimeout() {
+ database_manager_->CancelCheck(this);
+
+ OnCheckBrowseUrlResult(GURL::EmptyGURL(), safe_browsing::SB_THREAT_TYPE_SAFE,
vakh (use Gerrit instead) 2017/02/10 03:00:12 This should be the url for which the request timed
melandory 2017/02/14 17:40:34 Done.
+ safe_browsing::ThreatMetadata());
+}
+
+} // namespace subresource_filter

Powered by Google App Engine
This is Rietveld 408576698