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

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

Issue 2540563002: Move SafeBrowsingUIManager::UnsafeResource to security_interstitials namespace (Closed)
Patch Set: rebase update Created 4 years 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 private: 90 private:
91 std::map<GURL, SBThreatType> map_; 91 std::map<GURL, SBThreatType> map_;
92 std::map<GURL, SBThreatType> pending_; 92 std::map<GURL, SBThreatType> pending_;
93 93
94 DISALLOW_COPY_AND_ASSIGN(WhitelistUrlSet); 94 DISALLOW_COPY_AND_ASSIGN(WhitelistUrlSet);
95 }; 95 };
96 96
97 // Returns the URL that should be used in a WhitelistUrlSet for the given 97 // Returns the URL that should be used in a WhitelistUrlSet for the given
98 // |resource|. 98 // |resource|.
99 GURL GetMainFrameWhitelistUrlForResource( 99 GURL GetMainFrameWhitelistUrlForResource(
100 const safe_browsing::SafeBrowsingUIManager::UnsafeResource& resource) { 100 const security_interstitials::UnsafeResource& resource) {
101 if (resource.is_subresource) { 101 if (resource.is_subresource) {
102 NavigationEntry* entry = resource.GetNavigationEntryForResource(); 102 NavigationEntry* entry = resource.GetNavigationEntryForResource();
103 if (!entry) 103 if (!entry)
104 return GURL(); 104 return GURL();
105 return entry->GetURL().GetWithEmptyPath(); 105 return entry->GetURL().GetWithEmptyPath();
106 } 106 }
107 return resource.url.GetWithEmptyPath(); 107 return resource.url.GetWithEmptyPath();
108 } 108 }
109 109
110 // Returns the URL that should be used in a WhitelistUrlSet for the 110 // Returns the URL that should be used in a WhitelistUrlSet for the
(...skipping 16 matching lines...) Expand all
127 site_list = new WhitelistUrlSet; 127 site_list = new WhitelistUrlSet;
128 web_contents->SetUserData(kWhitelistKey, site_list); 128 web_contents->SetUserData(kWhitelistKey, site_list);
129 } 129 }
130 return site_list; 130 return site_list;
131 } 131 }
132 132
133 } // namespace 133 } // namespace
134 134
135 namespace safe_browsing { 135 namespace safe_browsing {
136 136
137 // SafeBrowsingUIManager::UnsafeResource ---------------------------------------
138
139 SafeBrowsingUIManager::UnsafeResource::UnsafeResource()
140 : is_subresource(false),
141 is_subframe(false),
142 threat_type(SB_THREAT_TYPE_SAFE),
143 threat_source(safe_browsing::ThreatSource::UNKNOWN) {}
144
145 SafeBrowsingUIManager::UnsafeResource::UnsafeResource(
146 const UnsafeResource& other) = default;
147
148 SafeBrowsingUIManager::UnsafeResource::~UnsafeResource() { }
149
150 bool SafeBrowsingUIManager::UnsafeResource::IsMainPageLoadBlocked() const {
151 // Subresource hits cannot happen until after main page load is committed.
152 if (is_subresource)
153 return false;
154
155 // Client-side phishing detection interstitials never block the main frame
156 // load, since they happen after the page is finished loading.
157 if (threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL ||
158 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) {
159 return false;
160 }
161
162 return true;
163 }
164
165 content::NavigationEntry*
166 SafeBrowsingUIManager::UnsafeResource::GetNavigationEntryForResource() const {
167 content::WebContents* web_contents = web_contents_getter.Run();
168 if (!web_contents)
169 return nullptr;
170 // If a safebrowsing hit occurs during main frame navigation, the navigation
171 // will not be committed, and the pending navigation entry refers to the hit.
172 if (IsMainPageLoadBlocked())
173 return web_contents->GetController().GetPendingEntry();
174 // If a safebrowsing hit occurs on a subresource load, or on a main frame
175 // after the navigation is committed, the last committed navigation entry
176 // refers to the page with the hit. Note that there may concurrently be an
177 // unrelated pending navigation to another site, so GetActiveEntry() would be
178 // wrong.
179 return web_contents->GetController().GetLastCommittedEntry();
180 }
181
182 // static
183 base::Callback<content::WebContents*(void)>
184 SafeBrowsingUIManager::UnsafeResource::GetWebContentsGetter(
185 int render_process_host_id,
186 int render_frame_id) {
187 return base::Bind(&tab_util::GetWebContentsByFrameID, render_process_host_id,
188 render_frame_id);
189 }
190
191 // SafeBrowsingUIManager -------------------------------------------------------
192
193 SafeBrowsingUIManager::SafeBrowsingUIManager( 137 SafeBrowsingUIManager::SafeBrowsingUIManager(
194 const scoped_refptr<SafeBrowsingService>& service) 138 const scoped_refptr<SafeBrowsingService>& service)
195 : sb_service_(service) {} 139 : sb_service_(service) {}
196 140
197 SafeBrowsingUIManager::~SafeBrowsingUIManager() {} 141 SafeBrowsingUIManager::~SafeBrowsingUIManager() {}
198 142
199 void SafeBrowsingUIManager::StopOnIOThread(bool shutdown) { 143 void SafeBrowsingUIManager::StopOnIOThread(bool shutdown) {
200 DCHECK_CURRENTLY_ON(BrowserThread::IO); 144 DCHECK_CURRENTLY_ON(BrowserThread::IO);
201 145
202 if (shutdown) 146 if (shutdown)
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 bool whitelisted = site_list->Contains(lookup_url, threat_type); 482 bool whitelisted = site_list->Contains(lookup_url, threat_type);
539 if (whitelist_only) { 483 if (whitelist_only) {
540 return whitelisted; 484 return whitelisted;
541 } else { 485 } else {
542 return whitelisted || site_list->ContainsPending(lookup_url, threat_type); 486 return whitelisted || site_list->ContainsPending(lookup_url, threat_type);
543 } 487 }
544 } 488 }
545 489
546 // Static. 490 // Static.
547 GURL SafeBrowsingUIManager::GetMainFrameWhitelistUrlForResourceForTesting( 491 GURL SafeBrowsingUIManager::GetMainFrameWhitelistUrlForResourceForTesting(
548 const safe_browsing::SafeBrowsingUIManager::UnsafeResource& resource) { 492 const security_interstitials::UnsafeResource& resource) {
549 return GetMainFrameWhitelistUrlForResource(resource); 493 return GetMainFrameWhitelistUrlForResource(resource);
550 } 494 }
551 495
552 } // namespace safe_browsing 496 } // 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