| 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 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_BLACKLIST_CLIENT_H_ | 5 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_BLACKLIST_CLIENT_H_ |
| 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_BLACKLIST_CLIENT_H_ | 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_BLACKLIST_CLIENT_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "chrome/browser/permissions/permission_uma_util.h" |
| 10 #include "chrome/browser/permissions/permission_util.h" | 11 #include "chrome/browser/permissions/permission_util.h" |
| 11 #include "components/safe_browsing_db/database_manager.h" | 12 #include "components/safe_browsing_db/database_manager.h" |
| 12 #include "content/public/browser/permission_type.h" | 13 #include "content/public/browser/permission_type.h" |
| 13 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
| 14 | 15 |
| 15 class GURL; | 16 class GURL; |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 class WebContents; | 19 class WebContents; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 class OneShotTimer; | 23 class OneShotTimer; |
| 24 class ElapsedTimer; |
| 23 } | 25 } |
| 24 | 26 |
| 25 // The client used when checking whether a permission has been blacklisted by | 27 // The client used when checking whether a permission has been blacklisted by |
| 26 // Safe Browsing. The check is done asynchronously as no state can be stored in | 28 // Safe Browsing. The check is done asynchronously as no state can be stored in |
| 27 // PermissionContextBase (since additional permission requests may be made). | 29 // PermissionContextBase (since additional permission requests may be made). |
| 28 // This class must be created and destroyed on the UI thread. | 30 // This class must be created and destroyed on the UI thread. |
| 29 class PermissionBlacklistClient | 31 class PermissionBlacklistClient |
| 30 : public safe_browsing::SafeBrowsingDatabaseManager::Client, | 32 : public safe_browsing::SafeBrowsingDatabaseManager::Client, |
| 31 public base::RefCountedThreadSafe<PermissionBlacklistClient>, | 33 public base::RefCountedThreadSafe<PermissionBlacklistClient>, |
| 32 public content::WebContentsObserver { | 34 public content::WebContentsObserver { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 55 | 57 |
| 56 ~PermissionBlacklistClient() override; | 58 ~PermissionBlacklistClient() override; |
| 57 | 59 |
| 58 void StartCheck(const GURL& request_origin); | 60 void StartCheck(const GURL& request_origin); |
| 59 | 61 |
| 60 // SafeBrowsingDatabaseManager::Client implementation. | 62 // SafeBrowsingDatabaseManager::Client implementation. |
| 61 void OnCheckApiBlacklistUrlResult( | 63 void OnCheckApiBlacklistUrlResult( |
| 62 const GURL& url, | 64 const GURL& url, |
| 63 const safe_browsing::ThreatMetadata& metadata) override; | 65 const safe_browsing::ThreatMetadata& metadata) override; |
| 64 | 66 |
| 65 void EvaluateBlacklistResultOnUiThread(bool permission_blocked); | 67 void EvaluateBlacklistResultOnUiThread(bool response); |
| 66 | 68 |
| 67 // WebContentsObserver implementation. Sets a flag so that when the database | 69 // WebContentsObserver implementation. Sets a flag so that when the database |
| 68 // manager returns with a result, it won't attempt to run the callback with a | 70 // manager returns with a result, it won't attempt to run the callback with a |
| 69 // deleted WebContents. | 71 // deleted WebContents. |
| 70 void WebContentsDestroyed() override; | 72 void WebContentsDestroyed() override; |
| 71 | 73 |
| 72 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager_; | 74 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager_; |
| 73 content::PermissionType permission_type_; | 75 content::PermissionType permission_type_; |
| 74 | 76 |
| 75 // PermissionContextBase callback to run on the UI thread. | 77 // PermissionContextBase callback to run on the UI thread. |
| 76 base::Callback<void(bool)> callback_; | 78 base::Callback<void(bool)> callback_; |
| 77 | 79 |
| 78 // Timer to abort the Safe Browsing check if it takes too long. Created and | 80 // Timer to abort the Safe Browsing check if it takes too long. Created and |
| 79 // used on the IO Thread. | 81 // used on the IO Thread. |
| 80 std::unique_ptr<base::OneShotTimer> timer_; | 82 std::unique_ptr<base::OneShotTimer> timer_; |
| 83 std::unique_ptr<base::ElapsedTimer> elapsed_timer_; |
| 81 int timeout_; | 84 int timeout_; |
| 82 | 85 |
| 83 // True if |callback_| should be invoked, if web_contents() is destroyed, this | 86 // True if |callback_| should be invoked, if web_contents() is destroyed, this |
| 84 // is set to false. | 87 // is set to false. |
| 85 bool is_active_; | 88 bool is_active_; |
| 86 | 89 |
| 87 DISALLOW_COPY_AND_ASSIGN(PermissionBlacklistClient); | 90 DISALLOW_COPY_AND_ASSIGN(PermissionBlacklistClient); |
| 88 }; | 91 }; |
| 89 | 92 |
| 90 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_BLACKLIST_CLIENT_H_ | 93 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_BLACKLIST_CLIENT_H_ |
| OLD | NEW |