unsafe_resource.cc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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
  3. // found in the LICENSE file.
  4. #include "components/security_interstitials/core/unsafe_resource.h"
  5. #include "components/safe_browsing/core/browser/db/util.h"
  6. namespace security_interstitials {
  7. constexpr UnsafeResource::RenderProcessId UnsafeResource::kNoRenderProcessId;
  8. constexpr UnsafeResource::RenderFrameId UnsafeResource::kNoRenderFrameId;
  9. constexpr UnsafeResource::FrameTreeNodeId UnsafeResource::kNoFrameTreeNodeId;
  10. UnsafeResource::UnsafeResource()
  11. : is_subresource(false),
  12. is_subframe(false),
  13. threat_type(safe_browsing::SB_THREAT_TYPE_SAFE),
  14. request_destination(network::mojom::RequestDestination::kDocument),
  15. is_delayed_warning(false) {}
  16. UnsafeResource::UnsafeResource(const UnsafeResource& other) = default;
  17. UnsafeResource::~UnsafeResource() = default;
  18. bool UnsafeResource::IsMainPageLoadBlocked() const {
  19. // Subresource hits cannot happen until after main page load is committed.
  20. if (is_subresource)
  21. return false;
  22. switch (threat_type) {
  23. // Client-side phishing/malware detection interstitials never block the main
  24. // frame load, since they happen after the page is finished loading.
  25. case safe_browsing::SB_THREAT_TYPE_URL_CLIENT_SIDE_PHISHING:
  26. case safe_browsing::SB_THREAT_TYPE_URL_CLIENT_SIDE_MALWARE:
  27. // Malicious ad activity reporting happens in the background.
  28. case safe_browsing::SB_THREAT_TYPE_BLOCKED_AD_POPUP:
  29. case safe_browsing::SB_THREAT_TYPE_BLOCKED_AD_REDIRECT:
  30. // Ad sampling happens in the background.
  31. case safe_browsing::SB_THREAT_TYPE_AD_SAMPLE:
  32. // Chrome SAVED password reuse warning happens after the page is finished
  33. // loading.
  34. case safe_browsing::SB_THREAT_TYPE_SAVED_PASSWORD_REUSE:
  35. // Chrome GAIA signed in and syncing password reuse warning happens after
  36. // the page is finished loading.
  37. case safe_browsing::SB_THREAT_TYPE_SIGNED_IN_SYNC_PASSWORD_REUSE:
  38. // Chrome GAIA signed in and non-syncing password reuse warning happens
  39. // after the page is finished loading.
  40. case safe_browsing::SB_THREAT_TYPE_SIGNED_IN_NON_SYNC_PASSWORD_REUSE:
  41. // Enterprise password reuse warning happens after the page is finished
  42. // loading.
  43. case safe_browsing::SB_THREAT_TYPE_ENTERPRISE_PASSWORD_REUSE:
  44. // Suspicious site collection happens in the background
  45. case safe_browsing::SB_THREAT_TYPE_SUSPICIOUS_SITE:
  46. return false;
  47. default:
  48. break;
  49. }
  50. return true;
  51. }
  52. void UnsafeResource::DispatchCallback(const base::Location& from_here,
  53. bool proceed,
  54. bool showed_interstitial) const {
  55. if (callback.is_null())
  56. return;
  57. DCHECK(callback_sequence);
  58. callback_sequence->PostTask(
  59. from_here, base::BindOnce(callback, proceed, showed_interstitial));
  60. }
  61. } // namespace security_interstitials