OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui_manager.h" | 5 #include "chrome/browser/safe_browsing/ui_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/debug/leak_tracker.h" | 10 #include "base/debug/leak_tracker.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
38 using content::BrowserThread; | 38 using content::BrowserThread; |
39 using content::NavigationEntry; | 39 using content::NavigationEntry; |
40 using content::WebContents; | 40 using content::WebContents; |
41 using safe_browsing::HitReport; | 41 using safe_browsing::HitReport; |
42 | 42 |
43 namespace { | 43 namespace { |
44 | 44 |
45 const void* const kWhitelistKey = &kWhitelistKey; | 45 const void* const kWhitelistKey = &kWhitelistKey; |
46 | 46 |
47 // A WhitelistUrlSet holds the set of URLs that have been whitelisted for a | 47 // A WhitelistUrlSet holds the set of URLs that have been whitelisted for a |
48 // specific WebContents, along with pending entries that are still undecided. | 48 // specific WebContents, along with pending entries that are still undecided. |
Nathan Parker
2016/10/27 18:31:02
Add a comment that the URLs here should come from
estark
2016/10/28 17:57:47
Done.
| |
49 class WhitelistUrlSet : public base::SupportsUserData::Data { | 49 class WhitelistUrlSet : public base::SupportsUserData::Data { |
50 public: | 50 public: |
51 WhitelistUrlSet() {} | 51 WhitelistUrlSet() {} |
52 | 52 |
53 bool Contains(const GURL url) { | 53 bool Contains(const GURL url) { |
54 return set_.find(url.GetWithEmptyPath()) != set_.end(); | 54 return set_.find(url.GetWithEmptyPath()) != set_.end(); |
55 } | 55 } |
56 | 56 |
57 void RemovePending(const GURL url) { pending_.erase(url.GetWithEmptyPath()); } | |
Nathan Parker
2016/10/27 18:31:02
const GURL&
Though maybe the compiler would do tha
estark
2016/10/28 17:57:47
Done.
| |
58 | |
57 void Insert(const GURL url) { | 59 void Insert(const GURL url) { |
58 set_.insert(url.GetWithEmptyPath()); | 60 set_.insert(url.GetWithEmptyPath()); |
59 pending_.erase(url.GetWithEmptyPath()); | 61 RemovePending(url); |
60 } | 62 } |
61 | 63 |
62 bool ContainsPending(const GURL url) { | 64 bool ContainsPending(const GURL url) { |
63 return pending_.find(url.GetWithEmptyPath()) != pending_.end(); | 65 return pending_.find(url.GetWithEmptyPath()) != pending_.end(); |
64 } | 66 } |
65 | 67 |
66 void InsertPending(const GURL url) { | 68 void InsertPending(const GURL url) { |
67 pending_.insert(url.GetWithEmptyPath()); | 69 pending_.insert(url.GetWithEmptyPath()); |
68 } | 70 } |
69 | 71 |
70 private: | 72 private: |
71 std::set<GURL> set_; | 73 std::set<GURL> set_; |
72 std::set<GURL> pending_; | 74 std::set<GURL> pending_; |
73 | 75 |
74 DISALLOW_COPY_AND_ASSIGN(WhitelistUrlSet); | 76 DISALLOW_COPY_AND_ASSIGN(WhitelistUrlSet); |
75 }; | 77 }; |
76 | 78 |
79 GURL GetWhitelistUrl( | |
80 const safe_browsing::SafeBrowsingUIManager::UnsafeResource& resource) { | |
81 if (resource.is_subresource) { | |
82 NavigationEntry* entry = resource.GetNavigationEntryForResource(); | |
83 if (!entry) | |
84 return GURL(); | |
85 return entry->GetURL(); | |
Nathan Parker
2016/10/27 18:31:02
How about returning .GetWithEmptyPath() so you don
estark
2016/10/28 17:57:47
Done.
| |
86 } | |
87 return resource.url; | |
88 } | |
89 | |
77 } // namespace | 90 } // namespace |
78 | 91 |
79 namespace safe_browsing { | 92 namespace safe_browsing { |
80 | 93 |
81 // SafeBrowsingUIManager::UnsafeResource --------------------------------------- | 94 // SafeBrowsingUIManager::UnsafeResource --------------------------------------- |
82 | 95 |
83 SafeBrowsingUIManager::UnsafeResource::UnsafeResource() | 96 SafeBrowsingUIManager::UnsafeResource::UnsafeResource() |
84 : is_subresource(false), | 97 : is_subresource(false), |
85 threat_type(SB_THREAT_TYPE_SAFE), | 98 threat_type(SB_THREAT_TYPE_SAFE), |
86 threat_source(safe_browsing::ThreatSource::UNKNOWN) {} | 99 threat_source(safe_browsing::ThreatSource::UNKNOWN) {} |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 169 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
157 for (const auto& resource : resources) { | 170 for (const auto& resource : resources) { |
158 if (!resource.callback.is_null()) { | 171 if (!resource.callback.is_null()) { |
159 DCHECK(resource.callback_thread); | 172 DCHECK(resource.callback_thread); |
160 resource.callback_thread->PostTask( | 173 resource.callback_thread->PostTask( |
161 FROM_HERE, base::Bind(resource.callback, proceed)); | 174 FROM_HERE, base::Bind(resource.callback, proceed)); |
162 } | 175 } |
163 | 176 |
164 if (proceed) | 177 if (proceed) |
165 AddToWhitelistUrlSet(resource, false /* Pending -> permanent */); | 178 AddToWhitelistUrlSet(resource, false /* Pending -> permanent */); |
179 else | |
180 RemoveFromPendingWhitelistUrlSet(resource); | |
166 } | 181 } |
167 } | 182 } |
168 | 183 |
169 void SafeBrowsingUIManager::DisplayBlockingPage( | 184 void SafeBrowsingUIManager::DisplayBlockingPage( |
170 const UnsafeResource& resource) { | 185 const UnsafeResource& resource) { |
171 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 186 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
172 if (resource.is_subresource && !resource.is_subframe) { | 187 if (resource.is_subresource && !resource.is_subframe) { |
173 // Sites tagged as serving Unwanted Software should only show a warning for | 188 // Sites tagged as serving Unwanted Software should only show a warning for |
174 // main-frame or sub-frame resource. Similar warning restrictions should be | 189 // main-frame or sub-frame resource. Similar warning restrictions should be |
175 // applied to malware sites tagged as "landing sites" (see "Types of | 190 // applied to malware sites tagged as "landing sites" (see "Types of |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 382 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
368 | 383 |
369 WebContents* web_contents = resource.web_contents_getter.Run(); | 384 WebContents* web_contents = resource.web_contents_getter.Run(); |
370 WhitelistUrlSet* site_list = | 385 WhitelistUrlSet* site_list = |
371 static_cast<WhitelistUrlSet*>(web_contents->GetUserData(kWhitelistKey)); | 386 static_cast<WhitelistUrlSet*>(web_contents->GetUserData(kWhitelistKey)); |
372 if (!site_list) { | 387 if (!site_list) { |
373 site_list = new WhitelistUrlSet; | 388 site_list = new WhitelistUrlSet; |
374 web_contents->SetUserData(kWhitelistKey, site_list); | 389 web_contents->SetUserData(kWhitelistKey, site_list); |
375 } | 390 } |
376 | 391 |
377 GURL whitelisted_url; | 392 GURL whitelisted_url = GetWhitelistUrl(resource); |
378 if (resource.is_subresource) { | 393 if (whitelisted_url.is_empty()) |
379 NavigationEntry* entry = resource.GetNavigationEntryForResource(); | 394 return; |
380 if (!entry) | |
381 return; | |
382 whitelisted_url = entry->GetURL(); | |
383 } else { | |
384 whitelisted_url = resource.url; | |
385 } | |
386 | 395 |
387 if (pending) { | 396 if (pending) { |
388 site_list->InsertPending(whitelisted_url); | 397 site_list->InsertPending(whitelisted_url); |
389 } else { | 398 } else { |
390 site_list->Insert(whitelisted_url); | 399 site_list->Insert(whitelisted_url); |
391 } | 400 } |
392 | 401 |
393 // Notify security UI that security state has changed. | 402 // Notify security UI that security state has changed. |
394 web_contents->DidChangeVisibleSecurityState(); | 403 web_contents->DidChangeVisibleSecurityState(); |
395 } | 404 } |
396 | 405 |
406 void SafeBrowsingUIManager::RemoveFromPendingWhitelistUrlSet( | |
407 const UnsafeResource& resource) { | |
408 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
409 WebContents* web_contents = resource.web_contents_getter.Run(); | |
410 WhitelistUrlSet* site_list = | |
411 static_cast<WhitelistUrlSet*>(web_contents->GetUserData(kWhitelistKey)); | |
412 GURL whitelisted_url = GetWhitelistUrl(resource); | |
413 if (whitelisted_url.is_empty()) | |
414 return; | |
415 DCHECK(site_list->ContainsPending(whitelisted_url)); | |
416 site_list->RemovePending(whitelisted_url); | |
417 // Notify security UI that security state has changed. | |
418 web_contents->DidChangeVisibleSecurityState(); | |
419 } | |
420 | |
397 bool SafeBrowsingUIManager::IsWhitelisted(const UnsafeResource& resource) { | 421 bool SafeBrowsingUIManager::IsWhitelisted(const UnsafeResource& resource) { |
398 NavigationEntry* entry = nullptr; | 422 NavigationEntry* entry = nullptr; |
399 if (resource.is_subresource) { | 423 if (resource.is_subresource) { |
400 entry = resource.GetNavigationEntryForResource(); | 424 entry = resource.GetNavigationEntryForResource(); |
401 } | 425 } |
402 return IsUrlWhitelistedOrPendingForWebContents( | 426 return IsUrlWhitelistedOrPendingForWebContents( |
403 resource.url, resource.is_subresource, entry, | 427 resource.url, resource.is_subresource, entry, |
404 resource.web_contents_getter.Run(), true); | 428 resource.web_contents_getter.Run(), true); |
405 } | 429 } |
406 | 430 |
(...skipping 23 matching lines...) Expand all Loading... | |
430 | 454 |
431 bool whitelisted = site_list->Contains(lookup_url); | 455 bool whitelisted = site_list->Contains(lookup_url); |
432 if (whitelist_only) { | 456 if (whitelist_only) { |
433 return whitelisted; | 457 return whitelisted; |
434 } else { | 458 } else { |
435 return whitelisted || site_list->ContainsPending(lookup_url); | 459 return whitelisted || site_list->ContainsPending(lookup_url); |
436 } | 460 } |
437 } | 461 } |
438 | 462 |
439 } // namespace safe_browsing | 463 } // namespace safe_browsing |
OLD | NEW |