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

Side by Side Diff: components/safe_browsing/base_ui_manager.cc

Issue 2623733002: Componentize SafeBrowsingBlockingPage for WebView use (Closed)
Patch Set: address comments from ntfischer Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/safe_browsing/base_ui_manager.h" 5 #include "components/safe_browsing/base_ui_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/macros.h" 9 #include "base/i18n/rtl.h"
10 #include "base/metrics/histogram_macros.h"
11 #include "base/supports_user_data.h"
12 #include "components/safe_browsing/base_safe_browsing_blocking_page.h"
13 #include "components/safe_browsing_db/metadata.pb.h"
10 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/navigation_entry.h" 15 #include "content/public/browser/navigation_entry.h"
12 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
13 17
14 using content::BrowserThread; 18 using content::BrowserThread;
15 using content::NavigationEntry; 19 using content::NavigationEntry;
16 using content::WebContents; 20 using content::WebContents;
17 using safe_browsing::HitReport; 21 using safe_browsing::HitReport;
18 using safe_browsing::SBThreatType; 22 using safe_browsing::SBThreatType;
19 23
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 return site_list; 92 return site_list;
89 } 93 }
90 94
91 } // namespace 95 } // namespace
92 96
93 namespace safe_browsing { 97 namespace safe_browsing {
94 98
95 BaseSafeBrowsingUIManager::BaseSafeBrowsingUIManager() {} 99 BaseSafeBrowsingUIManager::BaseSafeBrowsingUIManager() {}
96 100
97 void BaseSafeBrowsingUIManager::StopOnIOThread(bool shutdown) { 101 void BaseSafeBrowsingUIManager::StopOnIOThread(bool shutdown) {
102 LOG(ERROR) << "This should not be called";
meacer 2017/01/10 21:18:21 Forgot to remove? :)
Jialiu Lin 2017/01/11 00:50:06 ye..s....I forgot...
98 DCHECK_CURRENTLY_ON(BrowserThread::IO); 103 DCHECK_CURRENTLY_ON(BrowserThread::IO);
99 // TODO(ntfschr): implement this once SafeBrowsingService is componentized 104 // TODO(ntfschr): implement this once SafeBrowsingService is componentized
100 return; 105 return;
101 } 106 }
102 107
103 BaseSafeBrowsingUIManager::~BaseSafeBrowsingUIManager() {} 108 BaseSafeBrowsingUIManager::~BaseSafeBrowsingUIManager() {}
104 109
105 bool BaseSafeBrowsingUIManager::IsWhitelisted(const UnsafeResource& resource) { 110 bool BaseSafeBrowsingUIManager::IsWhitelisted(const UnsafeResource& resource) {
106 NavigationEntry* entry = nullptr; 111 NavigationEntry* entry = nullptr;
107 if (resource.is_subresource) { 112 if (resource.is_subresource) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } else if (web_contents) { 169 } else if (web_contents) {
165 // |web_contents| doesn't exist if the tab has been closed. 170 // |web_contents| doesn't exist if the tab has been closed.
166 RemoveFromPendingWhitelistUrlSet(whitelist_url, web_contents); 171 RemoveFromPendingWhitelistUrlSet(whitelist_url, web_contents);
167 } 172 }
168 } 173 }
169 } 174 }
170 175
171 void BaseSafeBrowsingUIManager::DisplayBlockingPage( 176 void BaseSafeBrowsingUIManager::DisplayBlockingPage(
172 const UnsafeResource& resource) { 177 const UnsafeResource& resource) {
173 DCHECK_CURRENTLY_ON(BrowserThread::UI); 178 DCHECK_CURRENTLY_ON(BrowserThread::UI);
174 // TODO(ntfschr): implement this once SafeBrowsingBlockingPage is 179 if (resource.is_subresource && !resource.is_subframe) {
175 // componentized 180 // Sites tagged as serving Unwanted Software should only show a warning for
176 return; 181 // main-frame or sub-frame resource. Similar warning restrictions should be
182 // applied to malware sites tagged as "landing sites" (see "Types of
183 // Malware sites" under
184 // https://developers.google.com/safe-browsing/developers_guide_v3#UserWarni ngs).
185 MalwarePatternType proto;
meacer 2017/01/10 21:18:21 This doesn't seem to be used, remove?
Jialiu Lin 2017/01/11 00:50:06 Hmm.. I wonder what's the story of this line. I co
186 if (resource.threat_type == SB_THREAT_TYPE_URL_UNWANTED ||
187 (resource.threat_type == SB_THREAT_TYPE_URL_MALWARE &&
188 resource.threat_metadata.threat_pattern_type ==
189 ThreatPatternType::MALWARE_LANDING)) {
190 if (!resource.callback.is_null()) {
191 DCHECK(resource.callback_thread);
192 resource.callback_thread->PostTask(FROM_HERE,
193 base::Bind(resource.callback, true));
194 }
195
196 return;
197 }
198 }
199
200 // The tab might have been closed. If it was closed, just act as if "Don't
201 // Proceed" had been chosen.
202 WebContents* web_contents = resource.web_contents_getter.Run();
203 if (!web_contents) {
204 std::vector<UnsafeResource> resources;
meacer 2017/01/10 21:18:21 nit: Maybe inline this? OnBlockingPageDone(std::v
Jialiu Lin 2017/01/11 00:50:06 Done.
205 resources.push_back(resource);
206 OnBlockingPageDone(resources, false, web_contents,
207 GetMainFrameWhitelistUrlForResource(resource));
208 return;
209 }
210
211 // Check if the user has already ignored a SB warning for the same WebContents
212 // and top-level domain.
213 if (IsWhitelisted(resource)) {
214 if (!resource.callback.is_null()) {
215 DCHECK(resource.callback_thread);
216 resource.callback_thread->PostTask(FROM_HERE,
217 base::Bind(resource.callback, true));
218 }
219 return;
220 }
221
222 // TODO(jialiul): BaseUIManager currently don't send HitReport.
meacer 2017/01/10 21:18:21 nit: The todo seemed a bit abstract, perhaps file
Jialiu Lin 2017/01/11 00:50:06 I probably should make it a comment instead of TOD
223
224 AddToWhitelistUrlSet(GetMainFrameWhitelistUrlForResource(resource),
225 resource.web_contents_getter.Run(),
226 true /* A decision is now pending */,
227 resource.threat_type);
228 BaseSafeBrowsingBlockingPage::ShowBlockingPage(this, resource);
177 } 229 }
178 230
179 void BaseSafeBrowsingUIManager::EnsureWhitelistCreated( 231 void BaseSafeBrowsingUIManager::EnsureWhitelistCreated(
180 WebContents* web_contents) { 232 WebContents* web_contents) {
181 GetOrCreateWhitelist(web_contents); 233 GetOrCreateWhitelist(web_contents);
182 } 234 }
183 235
184 void BaseSafeBrowsingUIManager::LogPauseDelay(base::TimeDelta time) { 236 void BaseSafeBrowsingUIManager::LogPauseDelay(base::TimeDelta time) {
237 UMA_HISTOGRAM_LONG_TIMES("SB2.Delay", time);
185 return; 238 return;
186 } 239 }
187 240
188 // A safebrowsing hit is sent after a blocking page for malware/phishing 241 // A safebrowsing hit is sent after a blocking page for malware/phishing
189 // or after the warning dialog for download urls, only for 242 // or after the warning dialog for download urls, only for
190 // UMA || extended_reporting users. 243 // UMA || extended_reporting users.
191 void BaseSafeBrowsingUIManager::MaybeReportSafeBrowsingHit( 244 void BaseSafeBrowsingUIManager::MaybeReportSafeBrowsingHit(
192 const HitReport& hit_report) { 245 const HitReport& hit_report) {
246 LOG(ERROR) << "This should not be called: "
247 "BaseSafeBrowsingUIManager::MaybeReportSafeBrowsingHit";
meacer 2017/01/10 21:18:21 nit: Remove?
Jialiu Lin 2017/01/11 00:50:06 Done.
193 DCHECK_CURRENTLY_ON(BrowserThread::UI); 248 DCHECK_CURRENTLY_ON(BrowserThread::UI);
194 // TODO(ntfschr): implement this once we support reporting in WebView 249 // TODO(ntfschr): implement this once we support reporting in WebView
195 return; 250 return;
196 } 251 }
197 252
198 void BaseSafeBrowsingUIManager::ReportSafeBrowsingHitOnIOThread( 253 void BaseSafeBrowsingUIManager::ReportSafeBrowsingHitOnIOThread(
199 const HitReport& hit_report) { 254 const HitReport& hit_report) {
200 DCHECK_CURRENTLY_ON(BrowserThread::IO); 255 DCHECK_CURRENTLY_ON(BrowserThread::IO);
201 // TODO(ntfschr): implement this once we support reporting in WebView 256 // TODO(ntfschr): implement this once we support reporting in WebView
202 return; 257 return;
(...skipping 29 matching lines...) Expand all
232 if (pending) { 287 if (pending) {
233 site_list->InsertPending(whitelist_url, threat_type); 288 site_list->InsertPending(whitelist_url, threat_type);
234 } else { 289 } else {
235 site_list->Insert(whitelist_url, threat_type); 290 site_list->Insert(whitelist_url, threat_type);
236 } 291 }
237 292
238 // Notify security UI that security state has changed. 293 // Notify security UI that security state has changed.
239 web_contents->DidChangeVisibleSecurityState(); 294 web_contents->DidChangeVisibleSecurityState();
240 } 295 }
241 296
242 void BaseSafeBrowsingUIManager::AddObserver(Observer* observer) { 297 const std::string BaseSafeBrowsingUIManager::app_locale() {
243 DCHECK_CURRENTLY_ON(BrowserThread::UI); 298 return base::i18n::GetConfiguredLocale();
244 observer_list_.AddObserver(observer);
245 } 299 }
246 300
247 void BaseSafeBrowsingUIManager::RemoveObserver(Observer* observer) { 301 history::HistoryService* BaseSafeBrowsingUIManager::history_service(
248 DCHECK_CURRENTLY_ON(BrowserThread::UI); 302 content::WebContents* web_contents) {
249 observer_list_.RemoveObserver(observer); 303 // TODO(jialiul): figure out how to get HistoryService from webview.
304 return nullptr;
305 }
306
307 const GURL BaseSafeBrowsingUIManager::default_safe_page() {
308 return GURL(url::kAboutBlankURL);
250 } 309 }
251 310
252 void BaseSafeBrowsingUIManager::RemoveFromPendingWhitelistUrlSet( 311 void BaseSafeBrowsingUIManager::RemoveFromPendingWhitelistUrlSet(
253 const GURL& whitelist_url, 312 const GURL& whitelist_url,
254 WebContents* web_contents) { 313 WebContents* web_contents) {
255 DCHECK_CURRENTLY_ON(BrowserThread::UI); 314 DCHECK_CURRENTLY_ON(BrowserThread::UI);
256 315
257 // A WebContents might not exist if the tab has been closed. 316 // A WebContents might not exist if the tab has been closed.
258 if (!web_contents) 317 if (!web_contents)
259 return; 318 return;
(...skipping 19 matching lines...) Expand all
279 // remove the main-frame URL from the pending whitelist, so the 338 // remove the main-frame URL from the pending whitelist, so the
280 // main-frame URL will have already been removed when the subsequent 339 // main-frame URL will have already been removed when the subsequent
281 // blocking pages are dismissed. 340 // blocking pages are dismissed.
282 if (site_list->ContainsPending(whitelist_url, nullptr)) 341 if (site_list->ContainsPending(whitelist_url, nullptr))
283 site_list->RemovePending(whitelist_url); 342 site_list->RemovePending(whitelist_url);
284 343
285 // Notify security UI that security state has changed. 344 // Notify security UI that security state has changed.
286 web_contents->DidChangeVisibleSecurityState(); 345 web_contents->DidChangeVisibleSecurityState();
287 } 346 }
288 347
348 // static
349 GURL BaseSafeBrowsingUIManager::GetMainFrameWhitelistUrlForResource(
350 const security_interstitials::UnsafeResource& resource) {
351 if (resource.is_subresource) {
352 NavigationEntry* entry = resource.GetNavigationEntryForResource();
353 if (!entry)
354 return GURL();
355 return entry->GetURL().GetWithEmptyPath();
356 }
357 return resource.url.GetWithEmptyPath();
358 }
359
289 } // namespace safe_browsing 360 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698