| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_ |
| 7 | 7 |
| 8 // A class that encapsulates the detailed threat reports sent when | 8 // A class that encapsulates the detailed threat reports sent when |
| 9 // users opt-in to do so from the safe browsing warning page. | 9 // users opt-in to do so from the safe browsing warning page. |
| 10 | 10 |
| 11 // An instance of this class is generated when a safe browsing warning page | 11 // An instance of this class is generated when a safe browsing warning page |
| 12 // is shown (SafeBrowsingBlockingPage). | 12 // is shown (SafeBrowsingBlockingPage). |
| 13 | 13 |
| 14 #include <memory> | 14 #include <memory> |
| 15 #include <string> | 15 #include <string> |
| 16 #include <unordered_set> | 16 #include <unordered_set> |
| 17 #include <vector> | 17 #include <vector> |
| 18 | 18 |
| 19 #include "base/containers/hash_tables.h" | 19 #include "base/containers/hash_tables.h" |
| 20 #include "base/gtest_prod_util.h" | 20 #include "base/gtest_prod_util.h" |
| 21 #include "base/macros.h" | 21 #include "base/macros.h" |
| 22 #include "base/memory/ref_counted.h" | 22 #include "base/memory/ref_counted.h" |
| 23 #include "chrome/browser/safe_browsing/ui_manager.h" | |
| 24 #include "components/safe_browsing/common/safebrowsing_types.h" | 23 #include "components/safe_browsing/common/safebrowsing_types.h" |
| 25 #include "components/safe_browsing/csd.pb.h" | 24 #include "components/safe_browsing/csd.pb.h" |
| 25 #include "components/security_interstitials/content/unsafe_resource.h" |
| 26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/web_contents_observer.h" | 27 #include "content/public/browser/web_contents_observer.h" |
| 28 #include "net/base/completion_callback.h" | 28 #include "net/base/completion_callback.h" |
| 29 | 29 |
| 30 namespace history { |
| 31 class HistoryService; |
| 32 } // namespace history |
| 33 |
| 30 namespace net { | 34 namespace net { |
| 31 class URLRequestContextGetter; | 35 class URLRequestContextGetter; |
| 32 } | 36 } // namespace net |
| 33 | 37 |
| 34 class Profile; | |
| 35 struct SafeBrowsingHostMsg_ThreatDOMDetails_Node; | 38 struct SafeBrowsingHostMsg_ThreatDOMDetails_Node; |
| 36 | 39 |
| 37 namespace safe_browsing { | 40 namespace safe_browsing { |
| 38 | 41 |
| 42 class BaseUIManager; |
| 43 |
| 39 // Maps a URL to its Resource. | 44 // Maps a URL to its Resource. |
| 40 class ThreatDetailsCacheCollector; | 45 class ThreatDetailsCacheCollector; |
| 41 class ThreatDetailsRedirectsCollector; | 46 class ThreatDetailsRedirectsCollector; |
| 42 class ThreatDetailsFactory; | 47 class ThreatDetailsFactory; |
| 43 | 48 |
| 44 using ResourceMap = | 49 using ResourceMap = |
| 45 base::hash_map<std::string, | 50 base::hash_map<std::string, |
| 46 std::unique_ptr<ClientSafeBrowsingReportRequest::Resource>>; | 51 std::unique_ptr<ClientSafeBrowsingReportRequest::Resource>>; |
| 47 | 52 |
| 48 // Maps a key of an HTML element to its corresponding HTMLElement proto message. | 53 // Maps a key of an HTML element to its corresponding HTMLElement proto message. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 65 using UrlToChildIdsMap = base::hash_map<std::string, std::unordered_set<int>>; | 70 using UrlToChildIdsMap = base::hash_map<std::string, std::unordered_set<int>>; |
| 66 | 71 |
| 67 class ThreatDetails : public base::RefCountedThreadSafe< | 72 class ThreatDetails : public base::RefCountedThreadSafe< |
| 68 ThreatDetails, | 73 ThreatDetails, |
| 69 content::BrowserThread::DeleteOnUIThread>, | 74 content::BrowserThread::DeleteOnUIThread>, |
| 70 public content::WebContentsObserver { | 75 public content::WebContentsObserver { |
| 71 public: | 76 public: |
| 72 typedef security_interstitials::UnsafeResource UnsafeResource; | 77 typedef security_interstitials::UnsafeResource UnsafeResource; |
| 73 | 78 |
| 74 // Constructs a new ThreatDetails instance, using the factory. | 79 // Constructs a new ThreatDetails instance, using the factory. |
| 75 static ThreatDetails* NewThreatDetails(BaseUIManager* ui_manager, | 80 static ThreatDetails* NewThreatDetails( |
| 76 content::WebContents* web_contents, | 81 BaseUIManager* ui_manager, |
| 77 const UnsafeResource& resource); | 82 content::WebContents* web_contents, |
| 83 const UnsafeResource& resource, |
| 84 net::URLRequestContextGetter* request_context_getter, |
| 85 history::HistoryService* history_service); |
| 78 | 86 |
| 79 // Makes the passed |factory| the factory used to instanciate | 87 // Makes the passed |factory| the factory used to instantiate |
| 80 // SafeBrowsingBlockingPage objects. Useful for tests. | 88 // SafeBrowsingBlockingPage objects. Useful for tests. |
| 81 static void RegisterFactory(ThreatDetailsFactory* factory) { | 89 static void RegisterFactory(ThreatDetailsFactory* factory) { |
| 82 factory_ = factory; | 90 factory_ = factory; |
| 83 } | 91 } |
| 84 | 92 |
| 85 // The SafeBrowsingBlockingPage calls this from the IO thread when | 93 // The SafeBrowsingBlockingPage calls this from the IO thread when |
| 86 // the user is leaving the blocking page and has opted-in to sending | 94 // the user is leaving the blocking page and has opted-in to sending |
| 87 // the report. We start the redirection urls collection from history service | 95 // the report. We start the redirection urls collection from history service |
| 88 // in UI thread; then do cache collection back in IO thread. We also record | 96 // in UI thread; then do cache collection back in IO thread. We also record |
| 89 // if the user did proceed with the warning page, and how many times user | 97 // if the user did proceed with the warning page, and how many times user |
| 90 // visited this page before. When we are done, we send the report. | 98 // visited this page before. When we are done, we send the report. |
| 91 void FinishCollection(bool did_proceed, int num_visits); | 99 void FinishCollection(bool did_proceed, int num_visits); |
| 92 | 100 |
| 93 void OnCacheCollectionReady(); | 101 void OnCacheCollectionReady(); |
| 94 | 102 |
| 95 void OnRedirectionCollectionReady(); | 103 void OnRedirectionCollectionReady(); |
| 96 | 104 |
| 97 // content::WebContentsObserver implementation. | 105 // content::WebContentsObserver implementation. |
| 98 bool OnMessageReceived(const IPC::Message& message, | 106 bool OnMessageReceived(const IPC::Message& message, |
| 99 content::RenderFrameHost* render_frame_host) override; | 107 content::RenderFrameHost* render_frame_host) override; |
| 100 | 108 |
| 101 protected: | 109 protected: |
| 102 friend class ThreatDetailsFactoryImpl; | 110 friend class ThreatDetailsFactoryImpl; |
| 103 friend class TestThreatDetailsFactory; | 111 friend class TestThreatDetailsFactory; |
| 104 | 112 |
| 105 ThreatDetails(BaseUIManager* ui_manager, | 113 ThreatDetails(BaseUIManager* ui_manager, |
| 106 content::WebContents* web_contents, | 114 content::WebContents* web_contents, |
| 107 const UnsafeResource& resource); | 115 const UnsafeResource& resource, |
| 116 net::URLRequestContextGetter* request_context_getter, |
| 117 history::HistoryService* history_service); |
| 108 | 118 |
| 109 ~ThreatDetails() override; | 119 ~ThreatDetails() override; |
| 110 | 120 |
| 111 // Called on the IO thread with the DOM details. | 121 // Called on the IO thread with the DOM details. |
| 112 virtual void AddDOMDetails( | 122 virtual void AddDOMDetails( |
| 113 const int frame_tree_node_id, | 123 const int frame_tree_node_id, |
| 114 const GURL& frame_last_committed_url, | 124 const GURL& frame_last_committed_url, |
| 115 const std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>& params); | 125 const std::vector<SafeBrowsingHostMsg_ThreatDOMDetails_Node>& params); |
| 116 | 126 |
| 117 Profile* profile_; | |
| 118 | |
| 119 // The report protocol buffer. | 127 // The report protocol buffer. |
| 120 std::unique_ptr<ClientSafeBrowsingReportRequest> report_; | 128 std::unique_ptr<ClientSafeBrowsingReportRequest> report_; |
| 121 | 129 |
| 122 // Used to get a pointer to the HTTP cache. | 130 // Used to get a pointer to the HTTP cache. |
| 123 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 131 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 124 | 132 |
| 125 private: | 133 private: |
| 126 friend class base::RefCountedThreadSafe<ThreatDetails>; | 134 friend class base::RefCountedThreadSafe<ThreatDetails>; |
| 127 friend struct content::BrowserThread::DeleteOnThread< | 135 friend struct content::BrowserThread::DeleteOnThread< |
| 128 content::BrowserThread::UI>; | 136 content::BrowserThread::UI>; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 }; | 245 }; |
| 238 | 246 |
| 239 // Factory for creating ThreatDetails. Useful for tests. | 247 // Factory for creating ThreatDetails. Useful for tests. |
| 240 class ThreatDetailsFactory { | 248 class ThreatDetailsFactory { |
| 241 public: | 249 public: |
| 242 virtual ~ThreatDetailsFactory() {} | 250 virtual ~ThreatDetailsFactory() {} |
| 243 | 251 |
| 244 virtual ThreatDetails* CreateThreatDetails( | 252 virtual ThreatDetails* CreateThreatDetails( |
| 245 BaseUIManager* ui_manager, | 253 BaseUIManager* ui_manager, |
| 246 content::WebContents* web_contents, | 254 content::WebContents* web_contents, |
| 247 const SafeBrowsingUIManager::UnsafeResource& unsafe_resource) = 0; | 255 const security_interstitials::UnsafeResource& unsafe_resource, |
| 256 net::URLRequestContextGetter* request_context_getter, |
| 257 history::HistoryService* history_service) = 0; |
| 248 }; | 258 }; |
| 249 | 259 |
| 250 } // namespace safe_browsing | 260 } // namespace safe_browsing |
| 251 | 261 |
| 252 #endif // CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_ | 262 #endif // CHROME_BROWSER_SAFE_BROWSING_THREAT_DETAILS_H_ |
| OLD | NEW |