Commit 0cb448e8 authored by edchin's avatar edchin Committed by Chromium LUCI CQ

[ios][PhishGuard] Cleanup PasswordProtectionRequest

* Moves some platform-specific includes behind build flag
* Cleans up imports
* Deletes copy constructor and assignment operator (removes old macro)

Bug: 1147967
Change-Id: I4c7a69ed7999b66f0d3ae4b63542103f96a5293c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2560532Reviewed-by: default avatarAli Juma <ajuma@chromium.org>
Reviewed-by: default avatarBettina Dea <bdea@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832112}
parent 9dafc144
...@@ -5,43 +5,37 @@ ...@@ -5,43 +5,37 @@
#include "components/safe_browsing/content/password_protection/password_protection_request.h" #include "components/safe_browsing/content/password_protection/password_protection_request.h"
#include <cstddef> #include <cstddef>
#include <memory>
#include "base/bind.h" #include "base/bind.h"
#include "base/containers/flat_set.h" #include "base/containers/flat_set.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/task/thread_pool.h" #include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "components/password_manager/core/browser/password_reuse_detector.h"
#include "components/safe_browsing/content/common/safe_browsing.mojom.h"
#include "components/safe_browsing/content/password_protection/password_protection_navigation_throttle.h" #include "components/safe_browsing/content/password_protection/password_protection_navigation_throttle.h"
#include "components/safe_browsing/content/web_ui/safe_browsing_ui.h" #include "components/safe_browsing/content/web_ui/safe_browsing_ui.h"
#include "components/safe_browsing/core/common/thread_utils.h" #include "components/safe_browsing/core/common/thread_utils.h"
#include "components/safe_browsing/core/common/visual_utils.h"
#include "components/safe_browsing/core/db/allowlist_checker_client.h" #include "components/safe_browsing/core/db/allowlist_checker_client.h"
#include "components/safe_browsing/core/db/database_manager.h"
#include "components/safe_browsing/core/features.h" #include "components/safe_browsing/core/features.h"
#include "components/safe_browsing/core/password_protection/metrics_util.h"
#include "components/safe_browsing/core/proto/csd.pb.h"
#include "components/url_formatter/url_formatter.h" #include "components/url_formatter/url_formatter.h"
#include "components/zoom/zoom_controller.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/navigation_throttle.h"
#include "content/public/browser/web_contents.h"
#include "net/base/escape.h" #include "net/base/escape.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/http/http_status_code.h" #include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation.h" #include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/simple_url_loader.h" #include "services/network/public/cpp/simple_url_loader.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "url/gurl.h" #include "url/gurl.h"
#include "url/origin.h"
using content::BrowserThread; #if BUILDFLAG(SAFE_BROWSING_AVAILABLE) || BUILDFLAG(FULL_SAFE_BROWSING)
using content::WebContents; #include "content/public/browser/web_contents.h"
#endif // BUILDFLAG(SAFE_BROWSING_AVAILABLE) || BUILDFLAG(FULL_SAFE_BROWSING)
#if BUILDFLAG(FULL_SAFE_BROWSING)
#include "components/safe_browsing/core/common/visual_utils.h"
#include "components/zoom/zoom_controller.h"
#include "content/public/browser/render_widget_host_view.h"
#endif // BUILDFLAG(FULL_SAFE_BROWSING)
namespace safe_browsing { namespace safe_browsing {
...@@ -57,7 +51,7 @@ const int kMaxReusedDomains = 200; ...@@ -57,7 +51,7 @@ const int kMaxReusedDomains = 200;
#if BUILDFLAG(SAFE_BROWSING_AVAILABLE) #if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
// The maximum time to wait for DOM features to be collected, in milliseconds. // The maximum time to wait for DOM features to be collected, in milliseconds.
const int kDomFeatureTimeoutMs = 3000; const int kDomFeatureTimeoutMs = 3000;
#endif #endif // BUILDFLAG(SAFE_BROWSING_AVAILABLE)
#if BUILDFLAG(FULL_SAFE_BROWSING) #if BUILDFLAG(FULL_SAFE_BROWSING)
// Parameters chosen to ensure privacy is preserved by visual features. // Parameters chosen to ensure privacy is preserved by visual features.
...@@ -73,7 +67,7 @@ std::unique_ptr<VisualFeatures> ExtractVisualFeatures( ...@@ -73,7 +67,7 @@ std::unique_ptr<VisualFeatures> ExtractVisualFeatures(
visual_utils::GetBlurredImage(screenshot, features->mutable_image()); visual_utils::GetBlurredImage(screenshot, features->mutable_image());
return features; return features;
} }
#endif #endif // BUILDFLAG(FULL_SAFE_BROWSING)
std::vector<std::string> GetMatchingDomains( std::vector<std::string> GetMatchingDomains(
const std::vector<password_manager::MatchingReusedCredential>& const std::vector<password_manager::MatchingReusedCredential>&
...@@ -102,13 +96,13 @@ bool IsClientSideDetectionEnabled() { ...@@ -102,13 +96,13 @@ bool IsClientSideDetectionEnabled() {
#else #else
return base::FeatureList::IsEnabled( return base::FeatureList::IsEnabled(
safe_browsing::kClientSideDetectionForAndroid); safe_browsing::kClientSideDetectionForAndroid);
#endif #endif // BUILDFLAG(FULL_SAFE_BROWSING)
} }
} // namespace } // namespace
PasswordProtectionRequest::PasswordProtectionRequest( PasswordProtectionRequest::PasswordProtectionRequest(
WebContents* web_contents, content::WebContents* web_contents,
const GURL& main_frame_url, const GURL& main_frame_url,
const GURL& password_form_action, const GURL& password_form_action,
const GURL& password_form_frame_url, const GURL& password_form_frame_url,
...@@ -281,7 +275,7 @@ void PasswordProtectionRequest::FillRequestProto(bool is_sampled_ping) { ...@@ -281,7 +275,7 @@ void PasswordProtectionRequest::FillRequestProto(bool is_sampled_ping) {
request_proto_->set_content_area_height(content_area_size.height()); request_proto_->set_content_area_height(content_area_size.height());
request_proto_->set_content_area_width(content_area_size.width()); request_proto_->set_content_area_width(content_area_size.width());
} }
#endif #endif // BUILDFLAG(FULL_SAFE_BROWSING)
switch (trigger_type_) { switch (trigger_type_) {
case LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE: { case LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE: {
...@@ -477,7 +471,7 @@ void PasswordProtectionRequest::OnVisualFeatureCollectionDone( ...@@ -477,7 +471,7 @@ void PasswordProtectionRequest::OnVisualFeatureCollectionDone(
SendRequest(); SendRequest();
} }
#endif #endif // BUILDFLAG(FULL_SAFE_BROWSING)
void PasswordProtectionRequest::SendRequest() { void PasswordProtectionRequest::SendRequest() {
DCHECK(CurrentlyOnThread(ThreadID::UI)); DCHECK(CurrentlyOnThread(ThreadID::UI));
......
...@@ -5,23 +5,32 @@ ...@@ -5,23 +5,32 @@
#ifndef COMPONENTS_SAFE_BROWSING_CONTENT_PASSWORD_PROTECTION_PASSWORD_PROTECTION_REQUEST_H_ #ifndef COMPONENTS_SAFE_BROWSING_CONTENT_PASSWORD_PROTECTION_PASSWORD_PROTECTION_REQUEST_H_
#define COMPONENTS_SAFE_BROWSING_CONTENT_PASSWORD_PROTECTION_PASSWORD_PROTECTION_REQUEST_H_ #define COMPONENTS_SAFE_BROWSING_CONTENT_PASSWORD_PROTECTION_PASSWORD_PROTECTION_REQUEST_H_
#include <memory>
#include <string>
#include <vector> #include <vector>
#include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner_helpers.h"
#include "base/task/cancelable_task_tracker.h" #include "base/task/cancelable_task_tracker.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h" #include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "components/password_manager/core/browser/password_reuse_detector.h" #include "components/password_manager/core/browser/password_reuse_detector.h"
#include "components/safe_browsing/buildflags.h" #include "components/safe_browsing/buildflags.h"
#include "components/safe_browsing/content/common/safe_browsing.mojom.h"
#include "components/safe_browsing/content/password_protection/password_protection_service.h" #include "components/safe_browsing/content/password_protection/password_protection_service.h"
#include "components/safe_browsing/core/password_protection/metrics_util.h" #include "components/safe_browsing/core/password_protection/metrics_util.h"
#include "components/safe_browsing/core/password_protection/request_canceler.h" #include "components/safe_browsing/core/password_protection/request_canceler.h"
#include "components/safe_browsing/core/proto/csd.pb.h" #include "components/safe_browsing/core/proto/csd.pb.h"
#if BUILDFLAG(SAFE_BROWSING_AVAILABLE)
#include "components/safe_browsing/content/common/safe_browsing.mojom.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
#endif // BUILDFLAG(SAFE_BROWSING_AVAILABLE)
#if BUILDFLAG(FULL_SAFE_BROWSING)
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#endif // BUILDFLAG(FULL_SAFE_BROWSING)
#if defined(OS_IOS) #if defined(OS_IOS)
// TODO(crbug.com/1147967): Enable in iOS once this file is moved to /core. // TODO(crbug.com/1147967): Enable in iOS once this file is moved to /core.
...@@ -35,6 +44,10 @@ namespace network { ...@@ -35,6 +44,10 @@ namespace network {
class SimpleURLLoader; class SimpleURLLoader;
} }
namespace content {
class WebContents;
}
namespace safe_browsing { namespace safe_browsing {
class PasswordProtectionNavigationThrottle; class PasswordProtectionNavigationThrottle;
...@@ -68,9 +81,9 @@ using DeleteOnUIThread = ...@@ -68,9 +81,9 @@ using DeleteOnUIThread =
// | | On request timeout, cancel request. // | | On request timeout, cancel request.
// | | On deletion of |password_protection_service_|, cancel request. // | | On deletion of |password_protection_service_|, cancel request.
class PasswordProtectionRequest class PasswordProtectionRequest
: public base::RefCountedThreadSafe<PasswordProtectionRequest, : public CancelableRequest,
DeleteOnUIThread>, public base::RefCountedThreadSafe<PasswordProtectionRequest,
public CancelableRequest { DeleteOnUIThread> {
public: public:
PasswordProtectionRequest( PasswordProtectionRequest(
content::WebContents* web_contents, content::WebContents* web_contents,
...@@ -87,6 +100,11 @@ class PasswordProtectionRequest ...@@ -87,6 +100,11 @@ class PasswordProtectionRequest
PasswordProtectionService* pps, PasswordProtectionService* pps,
int request_timeout_in_ms); int request_timeout_in_ms);
// Not copyable or movable
PasswordProtectionRequest(const PasswordProtectionRequest&) = delete;
PasswordProtectionRequest& operator=(const PasswordProtectionRequest&) =
delete;
base::WeakPtr<PasswordProtectionRequest> GetWeakPtr() { base::WeakPtr<PasswordProtectionRequest> GetWeakPtr() {
return weakptr_factory_.GetWeakPtr(); return weakptr_factory_.GetWeakPtr();
} }
...@@ -192,7 +210,7 @@ class PasswordProtectionRequest ...@@ -192,7 +210,7 @@ class PasswordProtectionRequest
// If appropriate, collects visual features, otherwise continues on to sending // If appropriate, collects visual features, otherwise continues on to sending
// the request. // the request.
void MaybeCollectVisualFeatures(); void MaybeCollectVisualFeatures();
#endif #endif // BUILDFLAG(SAFE_BROWSING_AVAILABLE)
#if BUILDFLAG(FULL_SAFE_BROWSING) #if BUILDFLAG(FULL_SAFE_BROWSING)
// Collects visual features from the current login page. // Collects visual features from the current login page.
...@@ -204,7 +222,7 @@ class PasswordProtectionRequest ...@@ -204,7 +222,7 @@ class PasswordProtectionRequest
// Called when the visual feature extraction is complete. // Called when the visual feature extraction is complete.
void OnVisualFeatureCollectionDone( void OnVisualFeatureCollectionDone(
std::unique_ptr<VisualFeatures> visual_features); std::unique_ptr<VisualFeatures> visual_features);
#endif #endif // BUILDFLAG(FULL_SAFE_BROWSING)
// Initiates network request to Safe Browsing backend. // Initiates network request to Safe Browsing backend.
void SendRequest(); void SendRequest();
...@@ -304,13 +322,12 @@ class PasswordProtectionRequest ...@@ -304,13 +322,12 @@ class PasswordProtectionRequest
// Whether the DOM features collection is finished, either by timeout or by // Whether the DOM features collection is finished, either by timeout or by
// successfully gathering the features. // successfully gathering the features.
bool dom_features_collection_complete_; bool dom_features_collection_complete_;
#endif #endif // BUILDFLAG(SAFE_BROWSING_AVAILABLE)
// Cancels the request when it is no longer valid. // Cancels the request when it is no longer valid.
std::unique_ptr<RequestCanceler> request_canceler_; std::unique_ptr<RequestCanceler> request_canceler_;
base::WeakPtrFactory<PasswordProtectionRequest> weakptr_factory_{this}; base::WeakPtrFactory<PasswordProtectionRequest> weakptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(PasswordProtectionRequest);
}; };
} // namespace safe_browsing } // namespace safe_browsing
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment