| 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/permissions/permission_blacklist_client.h" | 5 #include "chrome/browser/permissions/permission_blacklist_client.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 16 | 16 |
| 17 // static | 17 // static |
| 18 void PermissionBlacklistClient::CheckSafeBrowsingBlacklist( | 18 void PermissionBlacklistClient::CheckSafeBrowsingBlacklist( |
| 19 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | 19 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, |
| 20 content::PermissionType permission_type, | 20 ContentSettingsType content_settings_type, |
| 21 const GURL& request_origin, | 21 const GURL& request_origin, |
| 22 content::WebContents* web_contents, | 22 content::WebContents* web_contents, |
| 23 int timeout, | 23 int timeout, |
| 24 base::Callback<void(bool)> callback) { | 24 base::Callback<void(bool)> callback) { |
| 25 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 25 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 26 | 26 |
| 27 new PermissionBlacklistClient(db_manager, permission_type, request_origin, | 27 new PermissionBlacklistClient(db_manager, content_settings_type, |
| 28 web_contents, timeout, callback); | 28 request_origin, web_contents, timeout, |
| 29 callback); |
| 29 } | 30 } |
| 30 | 31 |
| 31 PermissionBlacklistClient::PermissionBlacklistClient( | 32 PermissionBlacklistClient::PermissionBlacklistClient( |
| 32 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | 33 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, |
| 33 content::PermissionType permission_type, | 34 ContentSettingsType content_settings_type, |
| 34 const GURL& request_origin, | 35 const GURL& request_origin, |
| 35 content::WebContents* web_contents, | 36 content::WebContents* web_contents, |
| 36 int timeout, | 37 int timeout, |
| 37 base::Callback<void(bool)> callback) | 38 base::Callback<void(bool)> callback) |
| 38 : content::WebContentsObserver(web_contents), | 39 : content::WebContentsObserver(web_contents), |
| 39 db_manager_(db_manager), | 40 db_manager_(db_manager), |
| 40 permission_type_(permission_type), | 41 content_settings_type_(content_settings_type), |
| 41 callback_(callback), | 42 callback_(callback), |
| 42 timeout_(timeout), | 43 timeout_(timeout), |
| 43 is_active_(true) { | 44 is_active_(true) { |
| 44 // Balanced by a call to Release() in EvaluateBlacklistResultOnUiThread(). | 45 // Balanced by a call to Release() in EvaluateBlacklistResultOnUiThread(). |
| 45 AddRef(); | 46 AddRef(); |
| 46 content::BrowserThread::PostTask( | 47 content::BrowserThread::PostTask( |
| 47 content::BrowserThread::IO, FROM_HERE, | 48 content::BrowserThread::IO, FROM_HERE, |
| 48 base::Bind(&PermissionBlacklistClient::StartCheck, this, request_origin)); | 49 base::Bind(&PermissionBlacklistClient::StartCheck, this, request_origin)); |
| 49 } | 50 } |
| 50 | 51 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 72 const safe_browsing::ThreatMetadata& metadata) { | 73 const safe_browsing::ThreatMetadata& metadata) { |
| 73 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 74 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 74 if (timer_->IsRunning()) | 75 if (timer_->IsRunning()) |
| 75 timer_->Stop(); | 76 timer_->Stop(); |
| 76 else | 77 else |
| 77 db_manager_->CancelApiCheck(this); | 78 db_manager_->CancelApiCheck(this); |
| 78 timer_.reset(nullptr); | 79 timer_.reset(nullptr); |
| 79 | 80 |
| 80 bool permission_blocked = | 81 bool permission_blocked = |
| 81 metadata.api_permissions.find( | 82 metadata.api_permissions.find( |
| 82 PermissionUtil::ConvertPermissionTypeToSafeBrowsingName( | 83 PermissionUtil::ConvertContentSettingsTypeToSafeBrowsingName( |
| 83 permission_type_)) != metadata.api_permissions.end(); | 84 content_settings_type_)) != metadata.api_permissions.end(); |
| 84 | 85 |
| 85 content::BrowserThread::PostTask( | 86 content::BrowserThread::PostTask( |
| 86 content::BrowserThread::UI, FROM_HERE, | 87 content::BrowserThread::UI, FROM_HERE, |
| 87 base::Bind(&PermissionBlacklistClient::EvaluateBlacklistResultOnUiThread, | 88 base::Bind(&PermissionBlacklistClient::EvaluateBlacklistResultOnUiThread, |
| 88 this, permission_blocked)); | 89 this, permission_blocked)); |
| 89 } | 90 } |
| 90 | 91 |
| 91 void PermissionBlacklistClient::EvaluateBlacklistResultOnUiThread( | 92 void PermissionBlacklistClient::EvaluateBlacklistResultOnUiThread( |
| 92 bool permission_blocked) { | 93 bool permission_blocked) { |
| 93 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 94 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 94 | 95 |
| 95 if (is_active_) | 96 if (is_active_) |
| 96 callback_.Run(permission_blocked); | 97 callback_.Run(permission_blocked); |
| 97 Release(); | 98 Release(); |
| 98 } | 99 } |
| 99 | 100 |
| 100 void PermissionBlacklistClient::WebContentsDestroyed() { | 101 void PermissionBlacklistClient::WebContentsDestroyed() { |
| 101 is_active_ = false; | 102 is_active_ = false; |
| 102 Observe(nullptr); | 103 Observe(nullptr); |
| 103 } | 104 } |
| OLD | NEW |