Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: chrome/browser/safe_browsing/ui_manager.cc

Issue 2241673002: Make UnsafeResource hold a WebContents getter instead of RenderFrame ids (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 } // namespace 63 } // namespace
64 64
65 namespace safe_browsing { 65 namespace safe_browsing {
66 66
67 // SafeBrowsingUIManager::UnsafeResource --------------------------------------- 67 // SafeBrowsingUIManager::UnsafeResource ---------------------------------------
68 68
69 SafeBrowsingUIManager::UnsafeResource::UnsafeResource() 69 SafeBrowsingUIManager::UnsafeResource::UnsafeResource()
70 : is_subresource(false), 70 : is_subresource(false),
71 threat_type(SB_THREAT_TYPE_SAFE), 71 threat_type(SB_THREAT_TYPE_SAFE),
72 render_process_host_id(-1),
73 render_frame_id(MSG_ROUTING_NONE),
74 threat_source(safe_browsing::ThreatSource::UNKNOWN) {} 72 threat_source(safe_browsing::ThreatSource::UNKNOWN) {}
75 73
76 SafeBrowsingUIManager::UnsafeResource::UnsafeResource( 74 SafeBrowsingUIManager::UnsafeResource::UnsafeResource(
77 const UnsafeResource& other) = default; 75 const UnsafeResource& other) = default;
78 76
79 SafeBrowsingUIManager::UnsafeResource::~UnsafeResource() { } 77 SafeBrowsingUIManager::UnsafeResource::~UnsafeResource() { }
80 78
81 bool SafeBrowsingUIManager::UnsafeResource::IsMainPageLoadBlocked() const { 79 bool SafeBrowsingUIManager::UnsafeResource::IsMainPageLoadBlocked() const {
82 // Subresource hits cannot happen until after main page load is committed. 80 // Subresource hits cannot happen until after main page load is committed.
83 if (is_subresource) 81 if (is_subresource)
84 return false; 82 return false;
85 83
86 // Client-side phishing detection interstitials never block the main frame 84 // Client-side phishing detection interstitials never block the main frame
87 // load, since they happen after the page is finished loading. 85 // load, since they happen after the page is finished loading.
88 if (threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL || 86 if (threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL ||
89 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) { 87 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) {
90 return false; 88 return false;
91 } 89 }
92 90
93 return true; 91 return true;
94 } 92 }
95 93
96 content::NavigationEntry* 94 content::NavigationEntry*
97 SafeBrowsingUIManager::UnsafeResource::GetNavigationEntryForResource() const { 95 SafeBrowsingUIManager::UnsafeResource::GetNavigationEntryForResource() const {
98 WebContents* contents = tab_util::GetWebContentsByFrameID( 96 content::WebContents* web_contents = web_contents_getter.Run();
99 render_process_host_id, render_frame_id); 97 if (!web_contents)
100 if (!contents)
101 return nullptr; 98 return nullptr;
102 // If a safebrowsing hit occurs during main frame navigation, the navigation 99 // If a safebrowsing hit occurs during main frame navigation, the navigation
103 // will not be committed, and the pending navigation entry refers to the hit. 100 // will not be committed, and the pending navigation entry refers to the hit.
104 if (IsMainPageLoadBlocked()) 101 if (IsMainPageLoadBlocked())
105 return contents->GetController().GetPendingEntry(); 102 return web_contents->GetController().GetPendingEntry();
106 // If a safebrowsing hit occurs on a subresource load, or on a main frame 103 // If a safebrowsing hit occurs on a subresource load, or on a main frame
107 // after the navigation is committed, the last committed navigation entry 104 // after the navigation is committed, the last committed navigation entry
108 // refers to the page with the hit. Note that there may concurrently be an 105 // refers to the page with the hit. Note that there may concurrently be an
109 // unrelated pending navigation to another site, so GetActiveEntry() would be 106 // unrelated pending navigation to another site, so GetActiveEntry() would be
110 // wrong. 107 // wrong.
111 return contents->GetController().GetLastCommittedEntry(); 108 return web_contents->GetController().GetLastCommittedEntry();
109 }
110
111 // static
112 base::Callback<content::WebContents*(void)>
113 SafeBrowsingUIManager::UnsafeResource::GetWebContentsGetter(
114 int render_process_host_id,
115 int render_frame_id) {
116 return base::Bind(&tab_util::GetWebContentsByFrameID, render_process_host_id,
117 render_frame_id);
112 } 118 }
113 119
114 // SafeBrowsingUIManager ------------------------------------------------------- 120 // SafeBrowsingUIManager -------------------------------------------------------
115 121
116 SafeBrowsingUIManager::SafeBrowsingUIManager( 122 SafeBrowsingUIManager::SafeBrowsingUIManager(
117 const scoped_refptr<SafeBrowsingService>& service) 123 const scoped_refptr<SafeBrowsingService>& service)
118 : sb_service_(service) {} 124 : sb_service_(service) {}
119 125
120 SafeBrowsingUIManager::~SafeBrowsingUIManager() {} 126 SafeBrowsingUIManager::~SafeBrowsingUIManager() {}
121 127
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 resource.callback_thread->PostTask(FROM_HERE, 171 resource.callback_thread->PostTask(FROM_HERE,
166 base::Bind(resource.callback, true)); 172 base::Bind(resource.callback, true));
167 } 173 }
168 174
169 return; 175 return;
170 } 176 }
171 } 177 }
172 178
173 // The tab might have been closed. If it was closed, just act as if "Don't 179 // The tab might have been closed. If it was closed, just act as if "Don't
174 // Proceed" had been chosen. 180 // Proceed" had been chosen.
175 WebContents* web_contents = tab_util::GetWebContentsByFrameID( 181 WebContents* web_contents = resource.web_contents_getter.Run();
176 resource.render_process_host_id, resource.render_frame_id);
177 if (!web_contents) { 182 if (!web_contents) {
178 std::vector<UnsafeResource> resources; 183 std::vector<UnsafeResource> resources;
179 resources.push_back(resource); 184 resources.push_back(resource);
180 OnBlockingPageDone(resources, false); 185 OnBlockingPageDone(resources, false);
181 return; 186 return;
182 } 187 }
183 188
184 // Check if the user has already ignored a SB warning for the same WebContents 189 // Check if the user has already ignored a SB warning for the same WebContents
185 // and top-level domain. 190 // and top-level domain.
186 if (IsWhitelisted(resource)) { 191 if (IsWhitelisted(resource)) {
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 if (!serialized.empty()) { 351 if (!serialized.empty()) {
347 DVLOG(1) << "Sending serialized threat details."; 352 DVLOG(1) << "Sending serialized threat details.";
348 sb_service_->ping_manager()->ReportThreatDetails(serialized); 353 sb_service_->ping_manager()->ReportThreatDetails(serialized);
349 } 354 }
350 } 355 }
351 356
352 // Whitelist this domain in the current WebContents. Either add the 357 // Whitelist this domain in the current WebContents. Either add the
353 // domain to an existing WhitelistUrlSet, or create a new WhitelistUrlSet. 358 // domain to an existing WhitelistUrlSet, or create a new WhitelistUrlSet.
354 void SafeBrowsingUIManager::AddToWhitelist(const UnsafeResource& resource) { 359 void SafeBrowsingUIManager::AddToWhitelist(const UnsafeResource& resource) {
355 DCHECK_CURRENTLY_ON(BrowserThread::UI); 360 DCHECK_CURRENTLY_ON(BrowserThread::UI);
356 WebContents* web_contents = tab_util::GetWebContentsByFrameID(
357 resource.render_process_host_id, resource.render_frame_id);
358 361
362 WebContents* web_contents = resource.web_contents_getter.Run();
359 WhitelistUrlSet* site_list = 363 WhitelistUrlSet* site_list =
360 static_cast<WhitelistUrlSet*>(web_contents->GetUserData(kWhitelistKey)); 364 static_cast<WhitelistUrlSet*>(web_contents->GetUserData(kWhitelistKey));
361 if (!site_list) { 365 if (!site_list) {
362 site_list = new WhitelistUrlSet; 366 site_list = new WhitelistUrlSet;
363 web_contents->SetUserData(kWhitelistKey, site_list); 367 web_contents->SetUserData(kWhitelistKey, site_list);
364 } 368 }
365 369
366 GURL whitelisted_url; 370 GURL whitelisted_url;
367 if (resource.is_subresource) { 371 if (resource.is_subresource) {
368 NavigationEntry* entry = resource.GetNavigationEntryForResource(); 372 NavigationEntry* entry = resource.GetNavigationEntryForResource();
369 if (!entry) 373 if (!entry)
370 return; 374 return;
371 whitelisted_url = entry->GetURL(); 375 whitelisted_url = entry->GetURL();
372 } else { 376 } else {
373 whitelisted_url = resource.url; 377 whitelisted_url = resource.url;
374 } 378 }
375 379
376 site_list->Insert(whitelisted_url); 380 site_list->Insert(whitelisted_url);
377 } 381 }
378 382
379 // Check if the user has already ignored a SB warning for this WebContents and 383 // Check if the user has already ignored a SB warning for this WebContents and
380 // top-level domain. 384 // top-level domain.
381 bool SafeBrowsingUIManager::IsWhitelisted(const UnsafeResource& resource) { 385 bool SafeBrowsingUIManager::IsWhitelisted(const UnsafeResource& resource) {
382 DCHECK_CURRENTLY_ON(BrowserThread::UI); 386 DCHECK_CURRENTLY_ON(BrowserThread::UI);
383 WebContents* web_contents = tab_util::GetWebContentsByFrameID(
384 resource.render_process_host_id, resource.render_frame_id);
385 387
386 GURL maybe_whitelisted_url; 388 GURL maybe_whitelisted_url;
387 if (resource.is_subresource) { 389 if (resource.is_subresource) {
388 NavigationEntry* entry = resource.GetNavigationEntryForResource(); 390 NavigationEntry* entry = resource.GetNavigationEntryForResource();
389 if (!entry) 391 if (!entry)
390 return false; 392 return false;
391 maybe_whitelisted_url = entry->GetURL(); 393 maybe_whitelisted_url = entry->GetURL();
392 } else { 394 } else {
393 maybe_whitelisted_url = resource.url; 395 maybe_whitelisted_url = resource.url;
394 } 396 }
395 397
396 WhitelistUrlSet* site_list = 398 WhitelistUrlSet* site_list = static_cast<WhitelistUrlSet*>(
397 static_cast<WhitelistUrlSet*>(web_contents->GetUserData(kWhitelistKey)); 399 resource.web_contents_getter.Run()->GetUserData(kWhitelistKey));
398 if (!site_list) 400 if (!site_list)
399 return false; 401 return false;
400 return site_list->Contains(maybe_whitelisted_url); 402 return site_list->Contains(maybe_whitelisted_url);
401 } 403 }
402 404
403 } // namespace safe_browsing 405 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/ui_manager.h ('k') | chrome/browser/safe_browsing/ui_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698