| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Implementation of the ThreatDetails class. | 5 // Implementation of the ThreatDetails class. |
| 6 | 6 |
| 7 #include "chrome/browser/safe_browsing/threat_details.h" | 7 #include "chrome/browser/safe_browsing/threat_details.h" |
| 8 | 8 |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| 11 #include <unordered_set> | 11 #include <unordered_set> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "chrome/browser/history/history_service_factory.h" | |
| 19 #include "chrome/browser/profiles/profile.h" | |
| 20 #include "chrome/browser/safe_browsing/threat_details_cache.h" | 18 #include "chrome/browser/safe_browsing/threat_details_cache.h" |
| 21 #include "chrome/browser/safe_browsing/threat_details_history.h" | 19 #include "chrome/browser/safe_browsing/threat_details_history.h" |
| 22 #include "components/history/core/browser/history_service.h" | 20 #include "components/history/core/browser/history_service.h" |
| 23 #include "components/safe_browsing/common/safebrowsing_messages.h" | 21 #include "components/safe_browsing/common/safebrowsing_messages.h" |
| 24 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/navigation_controller.h" | 23 #include "content/public/browser/navigation_controller.h" |
| 26 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
| 27 #include "content/public/browser/render_frame_host.h" | 25 #include "content/public/browser/render_frame_host.h" |
| 28 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 29 #include "net/url_request/url_request_context_getter.h" | 27 #include "net/url_request/url_request_context_getter.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 131 |
| 134 } // namespace | 132 } // namespace |
| 135 | 133 |
| 136 // The default ThreatDetailsFactory. Global, made a singleton so we | 134 // The default ThreatDetailsFactory. Global, made a singleton so we |
| 137 // don't leak it. | 135 // don't leak it. |
| 138 class ThreatDetailsFactoryImpl : public ThreatDetailsFactory { | 136 class ThreatDetailsFactoryImpl : public ThreatDetailsFactory { |
| 139 public: | 137 public: |
| 140 ThreatDetails* CreateThreatDetails( | 138 ThreatDetails* CreateThreatDetails( |
| 141 BaseUIManager* ui_manager, | 139 BaseUIManager* ui_manager, |
| 142 WebContents* web_contents, | 140 WebContents* web_contents, |
| 143 const security_interstitials::UnsafeResource& unsafe_resource) override { | 141 const security_interstitials::UnsafeResource& unsafe_resource, |
| 144 return new ThreatDetails(ui_manager, web_contents, unsafe_resource); | 142 net::URLRequestContextGetter* request_context_getter, |
| 143 history::HistoryService* history_service) override { |
| 144 return new ThreatDetails(ui_manager, web_contents, unsafe_resource, |
| 145 request_context_getter, history_service); |
| 145 } | 146 } |
| 146 | 147 |
| 147 private: | 148 private: |
| 148 friend struct base::LazyInstanceTraitsBase<ThreatDetailsFactoryImpl>; | 149 friend struct base::LazyInstanceTraitsBase<ThreatDetailsFactoryImpl>; |
| 149 | 150 |
| 150 ThreatDetailsFactoryImpl() {} | 151 ThreatDetailsFactoryImpl() {} |
| 151 | 152 |
| 152 DISALLOW_COPY_AND_ASSIGN(ThreatDetailsFactoryImpl); | 153 DISALLOW_COPY_AND_ASSIGN(ThreatDetailsFactoryImpl); |
| 153 }; | 154 }; |
| 154 | 155 |
| 155 static base::LazyInstance<ThreatDetailsFactoryImpl>::DestructorAtExit | 156 static base::LazyInstance<ThreatDetailsFactoryImpl>::DestructorAtExit |
| 156 g_threat_details_factory_impl = LAZY_INSTANCE_INITIALIZER; | 157 g_threat_details_factory_impl = LAZY_INSTANCE_INITIALIZER; |
| 157 | 158 |
| 158 // Create a ThreatDetails for the given tab. | 159 // Create a ThreatDetails for the given tab. |
| 159 /* static */ | 160 /* static */ |
| 160 ThreatDetails* ThreatDetails::NewThreatDetails( | 161 ThreatDetails* ThreatDetails::NewThreatDetails( |
| 161 BaseUIManager* ui_manager, | 162 BaseUIManager* ui_manager, |
| 162 WebContents* web_contents, | 163 WebContents* web_contents, |
| 163 const UnsafeResource& resource) { | 164 const UnsafeResource& resource, |
| 165 net::URLRequestContextGetter* request_context_getter, |
| 166 history::HistoryService* history_service) { |
| 164 // Set up the factory if this has not been done already (tests do that | 167 // Set up the factory if this has not been done already (tests do that |
| 165 // before this method is called). | 168 // before this method is called). |
| 166 if (!factory_) | 169 if (!factory_) |
| 167 factory_ = g_threat_details_factory_impl.Pointer(); | 170 factory_ = g_threat_details_factory_impl.Pointer(); |
| 168 return factory_->CreateThreatDetails(ui_manager, web_contents, resource); | 171 return factory_->CreateThreatDetails(ui_manager, web_contents, resource, |
| 172 request_context_getter, history_service); |
| 169 } | 173 } |
| 170 | 174 |
| 171 // Create a ThreatDetails for the given tab. Runs in the UI thread. | 175 // Create a ThreatDetails for the given tab. Runs in the UI thread. |
| 172 ThreatDetails::ThreatDetails(BaseUIManager* ui_manager, | 176 ThreatDetails::ThreatDetails( |
| 173 content::WebContents* web_contents, | 177 BaseUIManager* ui_manager, |
| 174 const UnsafeResource& resource) | 178 content::WebContents* web_contents, |
| 179 const UnsafeResource& resource, |
| 180 net::URLRequestContextGetter* request_context_getter, |
| 181 history::HistoryService* history_service) |
| 175 : content::WebContentsObserver(web_contents), | 182 : content::WebContentsObserver(web_contents), |
| 176 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 183 request_context_getter_(request_context_getter), |
| 177 request_context_getter_(profile_->GetRequestContext()), | |
| 178 ui_manager_(ui_manager), | 184 ui_manager_(ui_manager), |
| 179 resource_(resource), | 185 resource_(resource), |
| 180 cache_result_(false), | 186 cache_result_(false), |
| 181 did_proceed_(false), | 187 did_proceed_(false), |
| 182 num_visits_(0), | 188 num_visits_(0), |
| 183 ambiguous_dom_(false), | 189 ambiguous_dom_(false), |
| 184 cache_collector_(new ThreatDetailsCacheCollector) { | 190 cache_collector_(new ThreatDetailsCacheCollector) { |
| 185 history::HistoryService* history_service = | |
| 186 HistoryServiceFactory::GetForProfile(profile_, | |
| 187 ServiceAccessType::EXPLICIT_ACCESS); | |
| 188 redirects_collector_ = new ThreatDetailsRedirectsCollector( | 191 redirects_collector_ = new ThreatDetailsRedirectsCollector( |
| 189 history_service ? history_service->AsWeakPtr() | 192 history_service ? history_service->AsWeakPtr() |
| 190 : base::WeakPtr<history::HistoryService>()); | 193 : base::WeakPtr<history::HistoryService>()); |
| 191 StartCollection(); | 194 StartCollection(); |
| 192 } | 195 } |
| 193 | 196 |
| 194 ThreatDetails::~ThreatDetails() {} | 197 ThreatDetails::~ThreatDetails() {} |
| 195 | 198 |
| 196 bool ThreatDetails::OnMessageReceived(const IPC::Message& message, | 199 bool ThreatDetails::OnMessageReceived(const IPC::Message& message, |
| 197 RenderFrameHost* render_frame_host) { | 200 RenderFrameHost* render_frame_host) { |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 // Send the report, using the SafeBrowsingService. | 593 // Send the report, using the SafeBrowsingService. |
| 591 std::string serialized; | 594 std::string serialized; |
| 592 if (!report_->SerializeToString(&serialized)) { | 595 if (!report_->SerializeToString(&serialized)) { |
| 593 DLOG(ERROR) << "Unable to serialize the threat report."; | 596 DLOG(ERROR) << "Unable to serialize the threat report."; |
| 594 return; | 597 return; |
| 595 } | 598 } |
| 596 ui_manager_->SendSerializedThreatDetails(serialized); | 599 ui_manager_->SendSerializedThreatDetails(serialized); |
| 597 } | 600 } |
| 598 | 601 |
| 599 } // namespace safe_browsing | 602 } // namespace safe_browsing |
| OLD | NEW |