| 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/elapsed_timer.h" | 12 #include "base/timer/elapsed_timer.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "chrome/browser/permissions/permission_uma_util.h" | 14 #include "chrome/browser/permissions/permission_uma_util.h" |
| 15 #include "chrome/browser/permissions/permission_util.h" | 15 #include "chrome/browser/permissions/permission_util.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 19 | 19 |
| 20 // static | 20 // static |
| 21 void PermissionBlacklistClient::CheckSafeBrowsingBlacklist( | 21 void PermissionBlacklistClient::CheckSafeBrowsingBlacklist( |
| 22 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | 22 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, |
| 23 content::PermissionType permission_type, | 23 ContentSettingsType content_settings_type, |
| 24 const GURL& request_origin, | 24 const GURL& request_origin, |
| 25 content::WebContents* web_contents, | 25 content::WebContents* web_contents, |
| 26 int timeout, | 26 int timeout, |
| 27 base::Callback<void(bool)> callback) { | 27 base::Callback<void(bool)> callback) { |
| 28 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 28 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 29 | 29 |
| 30 new PermissionBlacklistClient(db_manager, permission_type, request_origin, | 30 new PermissionBlacklistClient(db_manager, content_settings_type, |
| 31 web_contents, timeout, callback); | 31 request_origin, web_contents, timeout, |
| 32 callback); |
| 32 } | 33 } |
| 33 | 34 |
| 34 PermissionBlacklistClient::PermissionBlacklistClient( | 35 PermissionBlacklistClient::PermissionBlacklistClient( |
| 35 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | 36 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, |
| 36 content::PermissionType permission_type, | 37 ContentSettingsType content_settings_type, |
| 37 const GURL& request_origin, | 38 const GURL& request_origin, |
| 38 content::WebContents* web_contents, | 39 content::WebContents* web_contents, |
| 39 int timeout, | 40 int timeout, |
| 40 base::Callback<void(bool)> callback) | 41 base::Callback<void(bool)> callback) |
| 41 : content::WebContentsObserver(web_contents), | 42 : content::WebContentsObserver(web_contents), |
| 42 db_manager_(db_manager), | 43 db_manager_(db_manager), |
| 43 permission_type_(permission_type), | 44 content_settings_type_(content_settings_type), |
| 44 callback_(callback), | 45 callback_(callback), |
| 45 timeout_(timeout), | 46 timeout_(timeout), |
| 46 is_active_(true) { | 47 is_active_(true) { |
| 47 // Balanced by a call to Release() in EvaluateBlacklistResultOnUiThread(). | 48 // Balanced by a call to Release() in EvaluateBlacklistResultOnUiThread(). |
| 48 AddRef(); | 49 AddRef(); |
| 49 content::BrowserThread::PostTask( | 50 content::BrowserThread::PostTask( |
| 50 content::BrowserThread::IO, FROM_HERE, | 51 content::BrowserThread::IO, FROM_HERE, |
| 51 base::Bind(&PermissionBlacklistClient::StartCheck, this, request_origin)); | 52 base::Bind(&PermissionBlacklistClient::StartCheck, this, request_origin)); |
| 52 } | 53 } |
| 53 | 54 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 82 if (timer_->IsRunning()) { | 83 if (timer_->IsRunning()) { |
| 83 timer_->Stop(); | 84 timer_->Stop(); |
| 84 } else { | 85 } else { |
| 85 db_manager_->CancelApiCheck(this); | 86 db_manager_->CancelApiCheck(this); |
| 86 response = SafeBrowsingResponse::TIMEOUT; | 87 response = SafeBrowsingResponse::TIMEOUT; |
| 87 } | 88 } |
| 88 | 89 |
| 89 timer_.reset(nullptr); | 90 timer_.reset(nullptr); |
| 90 bool permission_blocked = | 91 bool permission_blocked = |
| 91 metadata.api_permissions.find( | 92 metadata.api_permissions.find( |
| 92 PermissionUtil::ConvertPermissionTypeToSafeBrowsingName( | 93 PermissionUtil::ConvertContentSettingsTypeToSafeBrowsingName( |
| 93 permission_type_)) != metadata.api_permissions.end(); | 94 content_settings_type_)) != metadata.api_permissions.end(); |
| 94 if (permission_blocked) | 95 if (permission_blocked) |
| 95 response = SafeBrowsingResponse::BLACKLISTED; | 96 response = SafeBrowsingResponse::BLACKLISTED; |
| 96 | 97 |
| 97 PermissionUmaUtil::RecordSafeBrowsingResponse(response_time, response); | 98 PermissionUmaUtil::RecordSafeBrowsingResponse(response_time, response); |
| 98 content::BrowserThread::PostTask( | 99 content::BrowserThread::PostTask( |
| 99 content::BrowserThread::UI, FROM_HERE, | 100 content::BrowserThread::UI, FROM_HERE, |
| 100 base::Bind(&PermissionBlacklistClient::EvaluateBlacklistResultOnUiThread, | 101 base::Bind(&PermissionBlacklistClient::EvaluateBlacklistResultOnUiThread, |
| 101 this, permission_blocked)); | 102 this, permission_blocked)); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void PermissionBlacklistClient::EvaluateBlacklistResultOnUiThread( | 105 void PermissionBlacklistClient::EvaluateBlacklistResultOnUiThread( |
| 105 bool response) { | 106 bool response) { |
| 106 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 107 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 107 | 108 |
| 108 if (is_active_) | 109 if (is_active_) |
| 109 callback_.Run(response); | 110 callback_.Run(response); |
| 110 Release(); | 111 Release(); |
| 111 } | 112 } |
| 112 | 113 |
| 113 void PermissionBlacklistClient::WebContentsDestroyed() { | 114 void PermissionBlacklistClient::WebContentsDestroyed() { |
| 114 is_active_ = false; | 115 is_active_ = false; |
| 115 Observe(nullptr); | 116 Observe(nullptr); |
| 116 } | 117 } |
| OLD | NEW |