| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "chrome/browser/safe_browsing/mojo_safe_browsing_impl.h" | 5 #include "chrome/browser/safe_browsing/mojo_safe_browsing_impl.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 if (!render_frame_host) | 37 if (!render_frame_host) |
| 38 return nullptr; | 38 return nullptr; |
| 39 | 39 |
| 40 return content::WebContents::FromRenderFrameHost(render_frame_host); | 40 return content::WebContents::FromRenderFrameHost(render_frame_host); |
| 41 } | 41 } |
| 42 | 42 |
| 43 // TODO(yzshen): Handle the case where SafeBrowsing is not enabled, or | 43 // TODO(yzshen): Handle the case where SafeBrowsing is not enabled, or |
| 44 // !database_manager()->IsSupported(). | 44 // !database_manager()->IsSupported(). |
| 45 // TODO(yzshen): Make sure it also works on Andorid. | 45 // TODO(yzshen): Make sure it also works on Andorid. |
| 46 // TODO(yzshen): Do all the logging like what BaseResourceThrottle does. | 46 // TODO(yzshen): Do all the logging like what BaseResourceThrottle does. |
| 47 class SafeBrowsingUrlCheckerImpl : public chrome::mojom::SafeBrowsingUrlChecker, | 47 class SafeBrowsingUrlCheckerImpl : public mojom::SafeBrowsingUrlChecker, |
| 48 public SafeBrowsingDatabaseManager::Client { | 48 public SafeBrowsingDatabaseManager::Client { |
| 49 public: | 49 public: |
| 50 SafeBrowsingUrlCheckerImpl( | 50 SafeBrowsingUrlCheckerImpl( |
| 51 int load_flags, | 51 int load_flags, |
| 52 content::ResourceType resource_type, | 52 content::ResourceType resource_type, |
| 53 scoped_refptr<SafeBrowsingDatabaseManager> database_manager, | 53 scoped_refptr<SafeBrowsingDatabaseManager> database_manager, |
| 54 scoped_refptr<SafeBrowsingUIManager> ui_manager, | 54 scoped_refptr<SafeBrowsingUIManager> ui_manager, |
| 55 int render_process_id, | 55 int render_process_id, |
| 56 int render_frame_id) | 56 int render_frame_id) |
| 57 : load_flags_(load_flags), | 57 : load_flags_(load_flags), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 68 ~SafeBrowsingUrlCheckerImpl() override { | 68 ~SafeBrowsingUrlCheckerImpl() override { |
| 69 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 69 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 70 | 70 |
| 71 if (state_ == STATE_CHECKING_URL) | 71 if (state_ == STATE_CHECKING_URL) |
| 72 database_manager_->CancelCheck(this); | 72 database_manager_->CancelCheck(this); |
| 73 | 73 |
| 74 for (size_t i = next_index_; i < callbacks_.size(); ++i) | 74 for (size_t i = next_index_; i < callbacks_.size(); ++i) |
| 75 std::move(callbacks_[i]).Run(false); | 75 std::move(callbacks_[i]).Run(false); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // chrome::mojom::SafeBrowsingUrlChecker implementation. | 78 // mojom::SafeBrowsingUrlChecker implementation. |
| 79 void CheckUrl(const GURL& url, CheckUrlCallback callback) override { | 79 void CheckUrl(const GURL& url, CheckUrlCallback callback) override { |
| 80 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 80 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 81 | 81 |
| 82 DVLOG(1) << "SafeBrowsingUrlCheckerImpl checks URL: " << url; | 82 DVLOG(1) << "SafeBrowsingUrlCheckerImpl checks URL: " << url; |
| 83 urls_.push_back(url); | 83 urls_.push_back(url); |
| 84 callbacks_.push_back(std::move(callback)); | 84 callbacks_.push_back(std::move(callback)); |
| 85 | 85 |
| 86 ProcessUrls(); | 86 ProcessUrls(); |
| 87 } | 87 } |
| 88 | 88 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 MojoSafeBrowsingImpl::~MojoSafeBrowsingImpl() { | 271 MojoSafeBrowsingImpl::~MojoSafeBrowsingImpl() { |
| 272 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 272 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 273 } | 273 } |
| 274 | 274 |
| 275 // static | 275 // static |
| 276 void MojoSafeBrowsingImpl::Create( | 276 void MojoSafeBrowsingImpl::Create( |
| 277 scoped_refptr<SafeBrowsingDatabaseManager> database_manager, | 277 scoped_refptr<SafeBrowsingDatabaseManager> database_manager, |
| 278 scoped_refptr<SafeBrowsingUIManager> ui_manager, | 278 scoped_refptr<SafeBrowsingUIManager> ui_manager, |
| 279 int render_process_id, | 279 int render_process_id, |
| 280 const service_manager::BindSourceInfo& source_info, | 280 const service_manager::BindSourceInfo& source_info, |
| 281 chrome::mojom::SafeBrowsingRequest request) { | 281 mojom::SafeBrowsingRequest request) { |
| 282 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 282 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 283 mojo::MakeStrongBinding(base::MakeUnique<MojoSafeBrowsingImpl>( | 283 mojo::MakeStrongBinding(base::MakeUnique<MojoSafeBrowsingImpl>( |
| 284 std::move(database_manager), | 284 std::move(database_manager), |
| 285 std::move(ui_manager), render_process_id), | 285 std::move(ui_manager), render_process_id), |
| 286 std::move(request)); | 286 std::move(request)); |
| 287 } | 287 } |
| 288 | 288 |
| 289 void MojoSafeBrowsingImpl::CreateCheckerAndCheck( | 289 void MojoSafeBrowsingImpl::CreateCheckerAndCheck( |
| 290 int32_t render_frame_id, | 290 int32_t render_frame_id, |
| 291 chrome::mojom::SafeBrowsingUrlCheckerRequest request, | 291 mojom::SafeBrowsingUrlCheckerRequest request, |
| 292 const GURL& url, | 292 const GURL& url, |
| 293 int32_t load_flags, | 293 int32_t load_flags, |
| 294 content::ResourceType resource_type, | 294 content::ResourceType resource_type, |
| 295 CreateCheckerAndCheckCallback callback) { | 295 CreateCheckerAndCheckCallback callback) { |
| 296 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 296 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 297 auto checker_impl = base::MakeUnique<SafeBrowsingUrlCheckerImpl>( | 297 auto checker_impl = base::MakeUnique<SafeBrowsingUrlCheckerImpl>( |
| 298 static_cast<int>(load_flags), resource_type, database_manager_, | 298 static_cast<int>(load_flags), resource_type, database_manager_, |
| 299 ui_manager_, render_process_id_, static_cast<int>(render_frame_id)); | 299 ui_manager_, render_process_id_, static_cast<int>(render_frame_id)); |
| 300 checker_impl->CheckUrl(url, std::move(callback)); | 300 checker_impl->CheckUrl(url, std::move(callback)); |
| 301 mojo::MakeStrongBinding(std::move(checker_impl), std::move(request)); | 301 mojo::MakeStrongBinding(std::move(checker_impl), std::move(request)); |
| 302 } | 302 } |
| 303 | 303 |
| 304 } // namespace safe_browsing | 304 } // namespace safe_browsing |
| OLD | NEW |