aw_safe_browsing_ui_manager.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright (c) 2017 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. #ifndef ANDROID_WEBVIEW_BROWSER_SAFE_BROWSING_AW_SAFE_BROWSING_UI_MANAGER_H_
  5. #define ANDROID_WEBVIEW_BROWSER_SAFE_BROWSING_AW_SAFE_BROWSING_UI_MANAGER_H_
  6. #include <memory>
  7. #include <string>
  8. #include "components/safe_browsing/content/browser/base_ui_manager.h"
  9. #include "components/security_interstitials/core/unsafe_resource.h"
  10. #include "content/public/browser/web_contents.h"
  11. #include "mojo/public/cpp/bindings/pending_receiver.h"
  12. #include "mojo/public/cpp/bindings/remote.h"
  13. #include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
  14. namespace network {
  15. class SharedURLLoaderFactory;
  16. }
  17. namespace safe_browsing {
  18. class BaseBlockingPage;
  19. class SafeBrowsingNetworkContext;
  20. } // namespace safe_browsing
  21. namespace android_webview {
  22. // The Safe Browsing service is responsible for checking URLs against
  23. // anti-phishing and anti-malware tables. This is an Android WebView-specific UI
  24. // manager.
  25. class AwSafeBrowsingUIManager : public safe_browsing::BaseUIManager {
  26. public:
  27. class UIManagerClient {
  28. public:
  29. static UIManagerClient* FromWebContents(content::WebContents* web_contents);
  30. // Whether this web contents can show any sort of interstitial
  31. virtual bool CanShowInterstitial() = 0;
  32. // Returns the appropriate BaseBlockingPage::ErrorUiType
  33. virtual int GetErrorUiType() = 0;
  34. };
  35. // Construction needs to happen on the UI thread.
  36. AwSafeBrowsingUIManager();
  37. AwSafeBrowsingUIManager(const AwSafeBrowsingUIManager&) = delete;
  38. AwSafeBrowsingUIManager& operator=(const AwSafeBrowsingUIManager&) = delete;
  39. // Gets the correct ErrorUiType for the web contents
  40. int GetErrorUiType(content::WebContents* web_contents) const;
  41. // BaseUIManager methods:
  42. void DisplayBlockingPage(const UnsafeResource& resource) override;
  43. // Called on the UI thread by the ThreatDetails with the report, so the
  44. // service can send it over.
  45. void SendThreatDetails(
  46. content::BrowserContext* browser_context,
  47. std::unique_ptr<safe_browsing::ClientSafeBrowsingReportRequest> report)
  48. override;
  49. scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory();
  50. // Called on the IO thread to get a SharedURLLoaderFactory that can be used on
  51. // the IO thread.
  52. scoped_refptr<network::SharedURLLoaderFactory>
  53. GetURLLoaderFactoryOnIOThread();
  54. protected:
  55. ~AwSafeBrowsingUIManager() override;
  56. private:
  57. safe_browsing::BaseBlockingPage* CreateBlockingPageForSubresource(
  58. content::WebContents* contents,
  59. const GURL& blocked_url,
  60. const UnsafeResource& unsafe_resource) override;
  61. // Called on the UI thread to create a URLLoaderFactory interface ptr for
  62. // the IO thread.
  63. void CreateURLLoaderFactoryForIO(
  64. mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver);
  65. // This is what owns the URLRequestContext inside the network service. This is
  66. // used by SimpleURLLoader for Safe Browsing requests.
  67. std::unique_ptr<safe_browsing::SafeBrowsingNetworkContext> network_context_;
  68. // A SharedURLLoaderFactory and its interfaceptr used on the IO thread.
  69. mojo::Remote<network::mojom::URLLoaderFactory> url_loader_factory_on_io_;
  70. scoped_refptr<network::WeakWrapperSharedURLLoaderFactory>
  71. shared_url_loader_factory_on_io_;
  72. };
  73. } // namespace android_webview
  74. #endif // ANDROID_WEBVIEW_BROWSER_SAFE_BROWSING_AW_SAFE_BROWSING_UI_MANAGER_H_