OLD | NEW |
---|---|
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 Loading... | |
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"; | |
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 resource.threat_type); | 168 resource.threat_type); |
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) { |
178 LOG(ERROR) << "This should not be called: " | |
Nate Fischer
2017/01/10 01:21:29
Why is this log here?
Jialiu Lin
2017/01/10 01:54:29
Oops, for my local testing use. should not be here
| |
179 "BaseSafeBrowsingUIManager::DisplayBlockingPage"; | |
173 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 180 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
174 // TODO(ntfschr): implement this once SafeBrowsingBlockingPage is | 181 if (resource.is_subresource && !resource.is_subframe) { |
175 // componentized | 182 // Sites tagged as serving Unwanted Software should only show a warning for |
176 return; | 183 // main-frame or sub-frame resource. Similar warning restrictions should be |
184 // applied to malware sites tagged as "landing sites" (see "Types of | |
185 // Malware sites" under | |
186 // https://developers.google.com/safe-browsing/developers_guide_v3#UserWarni ngs). | |
187 MalwarePatternType proto; | |
188 if (resource.threat_type == SB_THREAT_TYPE_URL_UNWANTED || | |
189 (resource.threat_type == SB_THREAT_TYPE_URL_MALWARE && | |
190 resource.threat_metadata.threat_pattern_type == | |
191 ThreatPatternType::MALWARE_LANDING)) { | |
192 if (!resource.callback.is_null()) { | |
193 DCHECK(resource.callback_thread); | |
194 resource.callback_thread->PostTask(FROM_HERE, | |
195 base::Bind(resource.callback, true)); | |
196 } | |
197 | |
198 return; | |
199 } | |
200 } | |
201 | |
202 // The tab might have been closed. If it was closed, just act as if "Don't | |
203 // Proceed" had been chosen. | |
204 WebContents* web_contents = resource.web_contents_getter.Run(); | |
205 if (!web_contents) { | |
206 std::vector<UnsafeResource> resources; | |
207 resources.push_back(resource); | |
208 OnBlockingPageDone(resources, false, web_contents, | |
209 GetMainFrameWhitelistUrlForResource(resource)); | |
210 return; | |
211 } | |
212 | |
213 // Check if the user has already ignored a SB warning for the same WebContents | |
214 // and top-level domain. | |
215 if (IsWhitelisted(resource)) { | |
216 if (!resource.callback.is_null()) { | |
217 DCHECK(resource.callback_thread); | |
218 resource.callback_thread->PostTask(FROM_HERE, | |
219 base::Bind(resource.callback, true)); | |
220 } | |
221 return; | |
222 } | |
223 | |
224 // TODO(jialiul): BaseUIManager currently don't send HitReport. | |
225 | |
226 AddToWhitelistUrlSet(GetMainFrameWhitelistUrlForResource(resource), | |
227 resource.web_contents_getter.Run(), | |
228 true /* A decision is now pending */, | |
229 resource.threat_type); | |
230 BaseSafeBrowsingBlockingPage::ShowBlockingPage(this, resource); | |
177 } | 231 } |
178 | 232 |
179 void BaseSafeBrowsingUIManager::EnsureWhitelistCreated( | 233 void BaseSafeBrowsingUIManager::EnsureWhitelistCreated( |
180 WebContents* web_contents) { | 234 WebContents* web_contents) { |
181 GetOrCreateWhitelist(web_contents); | 235 GetOrCreateWhitelist(web_contents); |
182 } | 236 } |
183 | 237 |
184 void BaseSafeBrowsingUIManager::LogPauseDelay(base::TimeDelta time) { | 238 void BaseSafeBrowsingUIManager::LogPauseDelay(base::TimeDelta time) { |
239 UMA_HISTOGRAM_LONG_TIMES("SB2.Delay", time); | |
185 return; | 240 return; |
186 } | 241 } |
187 | 242 |
188 // A safebrowsing hit is sent after a blocking page for malware/phishing | 243 // A safebrowsing hit is sent after a blocking page for malware/phishing |
189 // or after the warning dialog for download urls, only for | 244 // or after the warning dialog for download urls, only for |
190 // UMA || extended_reporting users. | 245 // UMA || extended_reporting users. |
191 void BaseSafeBrowsingUIManager::MaybeReportSafeBrowsingHit( | 246 void BaseSafeBrowsingUIManager::MaybeReportSafeBrowsingHit( |
192 const HitReport& hit_report) { | 247 const HitReport& hit_report) { |
248 LOG(ERROR) << "This should not be called: " | |
249 "BaseSafeBrowsingUIManager::MaybeReportSafeBrowsingHit"; | |
193 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 250 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
194 // TODO(ntfschr): implement this once we support reporting in WebView | 251 // TODO(ntfschr): implement this once we support reporting in WebView |
195 return; | 252 return; |
196 } | 253 } |
197 | 254 |
198 void BaseSafeBrowsingUIManager::ReportSafeBrowsingHitOnIOThread( | 255 void BaseSafeBrowsingUIManager::ReportSafeBrowsingHitOnIOThread( |
199 const HitReport& hit_report) { | 256 const HitReport& hit_report) { |
200 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 257 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
201 // TODO(ntfschr): implement this once we support reporting in WebView | 258 // TODO(ntfschr): implement this once we support reporting in WebView |
202 return; | 259 return; |
(...skipping 29 matching lines...) Expand all Loading... | |
232 if (pending) { | 289 if (pending) { |
233 site_list->InsertPending(whitelist_url, threat_type); | 290 site_list->InsertPending(whitelist_url, threat_type); |
234 } else { | 291 } else { |
235 site_list->Insert(whitelist_url, threat_type); | 292 site_list->Insert(whitelist_url, threat_type); |
236 } | 293 } |
237 | 294 |
238 // Notify security UI that security state has changed. | 295 // Notify security UI that security state has changed. |
239 web_contents->DidChangeVisibleSecurityState(); | 296 web_contents->DidChangeVisibleSecurityState(); |
240 } | 297 } |
241 | 298 |
242 void BaseSafeBrowsingUIManager::AddObserver(Observer* observer) { | 299 const std::string BaseSafeBrowsingUIManager::app_locale() { |
243 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 300 return base::i18n::GetConfiguredLocale(); |
244 observer_list_.AddObserver(observer); | |
245 } | 301 } |
246 | 302 |
247 void BaseSafeBrowsingUIManager::RemoveObserver(Observer* observer) { | 303 history::HistoryService* BaseSafeBrowsingUIManager::history_service( |
248 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 304 content::WebContents* web_contents) { |
249 observer_list_.RemoveObserver(observer); | 305 // TODO(jialiul): figure out how to get HistoryService from webview. |
306 return nullptr; | |
307 } | |
308 | |
309 const GURL BaseSafeBrowsingUIManager::default_safe_page() { | |
310 return GURL(url::kAboutBlankURL); | |
250 } | 311 } |
251 | 312 |
252 void BaseSafeBrowsingUIManager::RemoveFromPendingWhitelistUrlSet( | 313 void BaseSafeBrowsingUIManager::RemoveFromPendingWhitelistUrlSet( |
253 const GURL& whitelist_url, | 314 const GURL& whitelist_url, |
254 WebContents* web_contents) { | 315 WebContents* web_contents) { |
255 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 316 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
256 | 317 |
257 // A WebContents might not exist if the tab has been closed. | 318 // A WebContents might not exist if the tab has been closed. |
258 if (!web_contents) | 319 if (!web_contents) |
259 return; | 320 return; |
(...skipping 19 matching lines...) Expand all Loading... | |
279 // remove the main-frame URL from the pending whitelist, so the | 340 // remove the main-frame URL from the pending whitelist, so the |
280 // main-frame URL will have already been removed when the subsequent | 341 // main-frame URL will have already been removed when the subsequent |
281 // blocking pages are dismissed. | 342 // blocking pages are dismissed. |
282 if (site_list->ContainsPending(whitelist_url, nullptr)) | 343 if (site_list->ContainsPending(whitelist_url, nullptr)) |
283 site_list->RemovePending(whitelist_url); | 344 site_list->RemovePending(whitelist_url); |
284 | 345 |
285 // Notify security UI that security state has changed. | 346 // Notify security UI that security state has changed. |
286 web_contents->DidChangeVisibleSecurityState(); | 347 web_contents->DidChangeVisibleSecurityState(); |
287 } | 348 } |
288 | 349 |
350 // static | |
351 GURL BaseSafeBrowsingUIManager::GetMainFrameWhitelistUrlForResource( | |
352 const security_interstitials::UnsafeResource& resource) { | |
353 if (resource.is_subresource) { | |
354 NavigationEntry* entry = resource.GetNavigationEntryForResource(); | |
355 if (!entry) | |
356 return GURL(); | |
357 return entry->GetURL().GetWithEmptyPath(); | |
358 } | |
359 return resource.url.GetWithEmptyPath(); | |
360 } | |
361 | |
289 } // namespace safe_browsing | 362 } // namespace safe_browsing |
OLD | NEW |