OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
raymes
2017/01/11 00:00:36
nit: 2017
meredithl
2017/01/11 02:24:52
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/permissions/permission_blacklist_client.h" | |
6 | |
7 #include <set> | |
8 #include <string> | |
9 | |
10 #include "base/memory/ptr_util.h" | |
11 #include "components/safe_browsing_db/database_manager.h" | |
raymes
2017/01/11 00:00:36
this is in the header, so not needed here
meredithl
2017/01/11 02:24:52
Done.
| |
12 #include "content/public/browser/browser_thread.h" | |
13 #include "content/public/browser/web_contents.h" | |
14 #include "url/gurl.h" | |
15 | |
16 // static | |
17 void PermissionBlacklistClient::CheckSafeBrowsingBlacklist( | |
18 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | |
19 content::PermissionType permission_type, | |
20 const GURL& request_origin, | |
21 content::WebContents* web_contents, | |
22 int timeout, | |
23 base::Callback<void(bool)> callback) { | |
24 new PermissionBlacklistClient(db_manager, permission_type, request_origin, | |
25 web_contents, timeout, callback); | |
26 } | |
27 | |
28 PermissionBlacklistClient::PermissionBlacklistClient( | |
29 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | |
30 content::PermissionType permission_type, | |
31 const GURL& request_origin, | |
32 content::WebContents* web_contents, | |
33 int timeout, | |
34 base::Callback<void(bool)> callback) | |
35 : content::WebContentsObserver(web_contents), | |
36 db_manager_(db_manager), | |
37 permission_type_(permission_type), | |
38 callback_(callback), | |
39 timeout_(timeout), | |
40 is_active_(true) /* Web Contents is active upon construction */ { | |
raymes
2017/01/11 00:00:36
nit: don't use an inline comment here. I think it'
meredithl
2017/01/11 02:24:52
Sorry raymes - yes, I had already pulled most of t
| |
41 // Balanced by a call to Release() in OnCheckApiBlacklistUrlResult(). | |
42 AddRef(); | |
43 content::BrowserThread::PostTask( | |
44 content::BrowserThread::IO, FROM_HERE, | |
45 base::Bind(&PermissionBlacklistClient::StartCheck, this, request_origin)); | |
46 } | |
47 | |
48 PermissionBlacklistClient::~PermissionBlacklistClient() {} | |
49 | |
50 void PermissionBlacklistClient::StartCheck(const GURL& request_origin) { | |
51 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
raymes
2017/01/11 00:00:36
#include base/logging.h
dominickn
2017/01/11 01:47:38
Why do we need base/logging.h? DCHECK_CURRENTLY_ON
raymes
2017/01/11 01:56:30
You're right, ignore me :)
meredithl
2017/01/11 02:24:52
Acknowledged.
| |
52 | |
53 // Start the timer to interrupt into the client callback method with an | |
54 // empty response if Safe Browsing times out. | |
55 safe_browsing::ThreatMetadata empty_metadata; | |
56 timer_ = base::MakeUnique<base::OneShotTimer>(); | |
raymes
2017/01/11 00:00:36
#include base/timer.h
meredithl
2017/01/11 02:24:52
Done.
| |
57 timer_->Start( | |
58 FROM_HERE, base::TimeDelta::FromMilliseconds(timeout_), | |
59 base::Bind(&PermissionBlacklistClient::OnCheckApiBlacklistUrlResult, this, | |
60 request_origin, empty_metadata)); | |
61 db_manager_->CheckApiBlacklistUrl(request_origin, this); | |
62 } | |
63 | |
64 void PermissionBlacklistClient::OnCheckApiBlacklistUrlResult( | |
65 const GURL& url, | |
66 const safe_browsing::ThreatMetadata& metadata) { | |
67 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
68 | |
69 if (timer_->IsRunning()) | |
70 timer_->Stop(); | |
71 else | |
72 db_manager_->CancelApiCheck(this); | |
73 timer_.reset(nullptr); | |
74 | |
75 // TODO(meredithl): Convert the strings returned from Safe Browsing to the | |
76 // ones used by PermissionUtil for comparison. | |
77 bool permission_blocked = | |
78 metadata.api_permissions.find(PermissionUtil::GetPermissionString( | |
79 permission_type_)) != metadata.api_permissions.end(); | |
80 | |
81 content::BrowserThread::PostTask( | |
82 content::BrowserThread::UI, FROM_HERE, | |
83 base::Bind(&PermissionBlacklistClient::EvaluateBlacklistResultOnUiThread, | |
84 this, permission_blocked)); | |
85 } | |
86 | |
87 void PermissionBlacklistClient::EvaluateBlacklistResultOnUiThread( | |
88 bool permission_blocked) { | |
89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
90 | |
91 if (is_active_) | |
92 callback_.Run(permission_blocked); | |
93 Release(); | |
94 } | |
95 | |
96 void PermissionBlacklistClient::WebContentsDestroyed() { | |
97 is_active_ = false; | |
98 Observe(nullptr); | |
99 } | |
OLD | NEW |