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 // Implementation of the SafeBrowsingBlockingPage class. | 5 // Implementation of the SafeBrowsingBlockingPage class. |
6 | 6 |
7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 7 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "base/string_piece.h" | 15 #include "base/string_piece.h" |
16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/google/google_util.h" | 20 #include "chrome/browser/google/google_util.h" |
21 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/renderer_preferences_util.h" |
23 #include "chrome/browser/safe_browsing/malware_details.h" | 24 #include "chrome/browser/safe_browsing/malware_details.h" |
24 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 25 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
25 #include "chrome/browser/tab_contents/tab_util.h" | 26 #include "chrome/browser/tab_contents/tab_util.h" |
26 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 27 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
27 #include "chrome/common/jstemplate_builder.h" | 28 #include "chrome/common/jstemplate_builder.h" |
28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
29 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
| 31 #include "content/browser/tab_contents/interstitial_page.h" |
30 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
31 #include "content/public/browser/navigation_controller.h" | 33 #include "content/public/browser/navigation_controller.h" |
32 #include "content/public/browser/user_metrics.h" | 34 #include "content/public/browser/user_metrics.h" |
33 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
34 #include "grit/browser_resources.h" | 36 #include "grit/browser_resources.h" |
35 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
36 #include "grit/locale_settings.h" | 38 #include "grit/locale_settings.h" |
37 #include "net/base/escape.h" | 39 #include "net/base/escape.h" |
38 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
39 #include "ui/base/resource/resource_bundle.h" | 41 #include "ui/base/resource/resource_bundle.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageFactoryImpl); | 131 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageFactoryImpl); |
130 }; | 132 }; |
131 | 133 |
132 static base::LazyInstance<SafeBrowsingBlockingPageFactoryImpl> | 134 static base::LazyInstance<SafeBrowsingBlockingPageFactoryImpl> |
133 g_safe_browsing_blocking_page_factory_impl = LAZY_INSTANCE_INITIALIZER; | 135 g_safe_browsing_blocking_page_factory_impl = LAZY_INSTANCE_INITIALIZER; |
134 | 136 |
135 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( | 137 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( |
136 SafeBrowsingService* sb_service, | 138 SafeBrowsingService* sb_service, |
137 WebContents* web_contents, | 139 WebContents* web_contents, |
138 const UnsafeResourceList& unsafe_resources) | 140 const UnsafeResourceList& unsafe_resources) |
139 : ChromeInterstitialPage(web_contents, | 141 : malware_details_proceed_delay_ms_( |
140 IsMainPageLoadBlocked(unsafe_resources), | |
141 unsafe_resources[0].url), | |
142 malware_details_proceed_delay_ms_( | |
143 kMalwareDetailsProceedDelayMilliSeconds), | 142 kMalwareDetailsProceedDelayMilliSeconds), |
144 sb_service_(sb_service), | 143 sb_service_(sb_service), |
145 report_loop_(NULL), | 144 report_loop_(NULL), |
146 is_main_frame_load_blocked_(IsMainPageLoadBlocked(unsafe_resources)), | 145 is_main_frame_load_blocked_(IsMainPageLoadBlocked(unsafe_resources)), |
147 unsafe_resources_(unsafe_resources) { | 146 unsafe_resources_(unsafe_resources), |
| 147 proceeded_(false), |
| 148 web_contents_(web_contents), |
| 149 url_(unsafe_resources[0].url) { |
148 RecordUserAction(SHOW); | 150 RecordUserAction(SHOW); |
149 if (!is_main_frame_load_blocked_) { | 151 if (!is_main_frame_load_blocked_) { |
150 navigation_entry_index_to_remove_ = | 152 navigation_entry_index_to_remove_ = |
151 tab()->GetController().GetLastCommittedEntryIndex(); | 153 web_contents->GetController().GetLastCommittedEntryIndex(); |
152 } else { | 154 } else { |
153 navigation_entry_index_to_remove_ = -1; | 155 navigation_entry_index_to_remove_ = -1; |
154 } | 156 } |
155 | 157 |
156 // Start computing malware details. They will be sent only | 158 // Start computing malware details. They will be sent only |
157 // if the user opts-in on the blocking page later. | 159 // if the user opts-in on the blocking page later. |
158 // If there's more than one malicious resources, it means the user | 160 // If there's more than one malicious resources, it means the user |
159 // clicked through the first warning, so we don't prepare additional | 161 // clicked through the first warning, so we don't prepare additional |
160 // reports. | 162 // reports. |
161 if (unsafe_resources.size() == 1 && | 163 if (unsafe_resources.size() == 1 && |
162 unsafe_resources[0].threat_type == SafeBrowsingService::URL_MALWARE && | 164 unsafe_resources[0].threat_type == SafeBrowsingService::URL_MALWARE && |
163 malware_details_ == NULL && | 165 malware_details_ == NULL && |
164 CanShowMalwareDetailsOption()) { | 166 CanShowMalwareDetailsOption()) { |
165 malware_details_ = MalwareDetails::NewMalwareDetails( | 167 malware_details_ = MalwareDetails::NewMalwareDetails( |
166 sb_service_, tab(), unsafe_resources[0]); | 168 sb_service_, web_contents, unsafe_resources[0]); |
167 } | 169 } |
| 170 |
| 171 interstitial_page_ = InterstitialPage::Create( |
| 172 web_contents, IsMainPageLoadBlocked(unsafe_resources), url_, this); |
168 } | 173 } |
169 | 174 |
170 bool SafeBrowsingBlockingPage::CanShowMalwareDetailsOption() { | 175 bool SafeBrowsingBlockingPage::CanShowMalwareDetailsOption() { |
171 return (!tab()->GetBrowserContext()->IsOffTheRecord() && | 176 return (!web_contents_->GetBrowserContext()->IsOffTheRecord() && |
172 tab()->GetURL().SchemeIs(chrome::kHttpScheme)); | 177 web_contents_->GetURL().SchemeIs(chrome::kHttpScheme)); |
173 } | 178 } |
174 | 179 |
175 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { | 180 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { |
176 } | 181 } |
177 | 182 |
178 std::string SafeBrowsingBlockingPage::GetHTMLContents() { | 183 std::string SafeBrowsingBlockingPage::GetHTMLContents() { |
179 // Load the HTML page and create the template components. | 184 // Load the HTML page and create the template components. |
180 DictionaryValue strings; | 185 DictionaryValue strings; |
181 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 186 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
182 std::string html; | 187 std::string html; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 strings->Set("errors", error_strings); | 267 strings->Set("errors", error_strings); |
263 DCHECK(phishing || malware); | 268 DCHECK(phishing || malware); |
264 | 269 |
265 if (malware && phishing) { | 270 if (malware && phishing) { |
266 PopulateStringDictionary( | 271 PopulateStringDictionary( |
267 strings, | 272 strings, |
268 // Use the malware headline, it is the scariest one. | 273 // Use the malware headline, it is the scariest one. |
269 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MULTI_THREAT_TITLE), | 274 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MULTI_THREAT_TITLE), |
270 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_HEADLINE), | 275 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_HEADLINE), |
271 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MULTI_THREAT_DESCRIPTION1, | 276 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MULTI_THREAT_DESCRIPTION1, |
272 UTF8ToUTF16(tab()->GetURL().host())), | 277 UTF8ToUTF16(web_contents_->GetURL().host())), |
273 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MULTI_THREAT_DESCRIPTION2), | 278 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MULTI_THREAT_DESCRIPTION2), |
274 string16()); | 279 string16()); |
275 } else if (malware) { | 280 } else if (malware) { |
276 // Just malware. | 281 // Just malware. |
277 PopulateStringDictionary( | 282 PopulateStringDictionary( |
278 strings, | 283 strings, |
279 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_TITLE), | 284 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_TITLE), |
280 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_HEADLINE), | 285 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_HEADLINE), |
281 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION1, | 286 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION1, |
282 UTF8ToUTF16(tab()->GetURL().host())), | 287 UTF8ToUTF16(web_contents_->GetURL().host())), |
283 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION2), | 288 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION2), |
284 l10n_util::GetStringUTF16( | 289 l10n_util::GetStringUTF16( |
285 IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION3)); | 290 IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION3)); |
286 } else { | 291 } else { |
287 // Just phishing. | 292 // Just phishing. |
288 PopulateStringDictionary( | 293 PopulateStringDictionary( |
289 strings, | 294 strings, |
290 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_TITLE), | 295 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_TITLE), |
291 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_HEADLINE), | 296 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_HEADLINE), |
292 l10n_util::GetStringFUTF16( | 297 l10n_util::GetStringFUTF16( |
293 IDS_SAFE_BROWSING_MULTI_PHISHING_DESCRIPTION1, | 298 IDS_SAFE_BROWSING_MULTI_PHISHING_DESCRIPTION1, |
294 UTF8ToUTF16(tab()->GetURL().host())), | 299 UTF8ToUTF16(web_contents_->GetURL().host())), |
295 string16(), | 300 string16(), |
296 string16()); | 301 string16()); |
297 } | 302 } |
298 | 303 |
299 strings->SetString("confirm_text", | 304 strings->SetString("confirm_text", |
300 l10n_util::GetStringUTF16( | 305 l10n_util::GetStringUTF16( |
301 IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION_AGREE)); | 306 IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION_AGREE)); |
302 strings->SetString("continue_button", | 307 strings->SetString("continue_button", |
303 l10n_util::GetStringUTF16( | 308 l10n_util::GetStringUTF16( |
304 IDS_SAFE_BROWSING_MULTI_MALWARE_PROCEED_BUTTON)); | 309 IDS_SAFE_BROWSING_MULTI_MALWARE_PROCEED_BUTTON)); |
305 strings->SetString("back_button", | 310 strings->SetString("back_button", |
306 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); | 311 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); |
307 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | 312 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
308 } | 313 } |
309 | 314 |
310 void SafeBrowsingBlockingPage::PopulateMalwareStringDictionary( | 315 void SafeBrowsingBlockingPage::PopulateMalwareStringDictionary( |
311 DictionaryValue* strings) { | 316 DictionaryValue* strings) { |
312 std::string diagnostic_link = base::StringPrintf(kSbDiagnosticHtml, | 317 std::string diagnostic_link = base::StringPrintf(kSbDiagnosticHtml, |
313 l10n_util::GetStringUTF8( | 318 l10n_util::GetStringUTF8( |
314 IDS_SAFE_BROWSING_MALWARE_DIAGNOSTIC_PAGE).c_str()); | 319 IDS_SAFE_BROWSING_MALWARE_DIAGNOSTIC_PAGE).c_str()); |
315 | 320 |
316 strings->SetString("badURL", url().host()); | 321 strings->SetString("badURL", url_.host()); |
317 // Check to see if we're blocking the main page, or a sub-resource on the | 322 // Check to see if we're blocking the main page, or a sub-resource on the |
318 // main page. | 323 // main page. |
319 string16 description1, description3, description5; | 324 string16 description1, description3, description5; |
320 if (is_main_frame_load_blocked_) { | 325 if (is_main_frame_load_blocked_) { |
321 description1 = l10n_util::GetStringFUTF16( | 326 description1 = l10n_util::GetStringFUTF16( |
322 IDS_SAFE_BROWSING_MALWARE_DESCRIPTION1, UTF8ToUTF16(url().host())); | 327 IDS_SAFE_BROWSING_MALWARE_DESCRIPTION1, UTF8ToUTF16(url_.host())); |
323 } else { | 328 } else { |
324 description1 = l10n_util::GetStringFUTF16( | 329 description1 = l10n_util::GetStringFUTF16( |
325 IDS_SAFE_BROWSING_MALWARE_DESCRIPTION4, | 330 IDS_SAFE_BROWSING_MALWARE_DESCRIPTION4, |
326 UTF8ToUTF16(tab()->GetURL().host()), | 331 UTF8ToUTF16(web_contents_->GetURL().host()), |
327 UTF8ToUTF16(url().host())); | 332 UTF8ToUTF16(url_.host())); |
328 } | 333 } |
329 | 334 |
330 std::string proceed_link = base::StringPrintf(kPLinkHtml, | 335 std::string proceed_link = base::StringPrintf(kPLinkHtml, |
331 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_MALWARE_PROCEED_LINK).c_str()); | 336 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_MALWARE_PROCEED_LINK).c_str()); |
332 description3 = | 337 description3 = |
333 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION3, | 338 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION3, |
334 UTF8ToUTF16(proceed_link)); | 339 UTF8ToUTF16(proceed_link)); |
335 | 340 |
336 PopulateStringDictionary( | 341 PopulateStringDictionary( |
337 strings, | 342 strings, |
338 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_TITLE), | 343 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_TITLE), |
339 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_HEADLINE), | 344 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_HEADLINE), |
340 description1, | 345 description1, |
341 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION2), | 346 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION2), |
342 description3); | 347 description3); |
343 | 348 |
344 description5 = | 349 description5 = |
345 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION5, | 350 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION5, |
346 UTF8ToUTF16(url().host()), | 351 UTF8ToUTF16(url_.host()), |
347 UTF8ToUTF16(url().host()), | 352 UTF8ToUTF16(url_.host()), |
348 UTF8ToUTF16(diagnostic_link)); | 353 UTF8ToUTF16(diagnostic_link)); |
349 | 354 |
350 strings->SetString("description5", description5); | 355 strings->SetString("description5", description5); |
351 | 356 |
352 strings->SetString("back_button", | 357 strings->SetString("back_button", |
353 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); | 358 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); |
354 strings->SetString("proceed_link", | 359 strings->SetString("proceed_link", |
355 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_PROCEED_LINK)); | 360 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_PROCEED_LINK)); |
356 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | 361 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
357 | 362 |
358 if (!CanShowMalwareDetailsOption()) { | 363 if (!CanShowMalwareDetailsOption()) { |
359 strings->SetBoolean(kDisplayCheckBox, false); | 364 strings->SetBoolean(kDisplayCheckBox, false); |
360 } else { | 365 } else { |
361 // Show the checkbox for sending malware details. | 366 // Show the checkbox for sending malware details. |
362 strings->SetBoolean(kDisplayCheckBox, true); | 367 strings->SetBoolean(kDisplayCheckBox, true); |
363 | 368 |
364 std::string privacy_link = base::StringPrintf( | 369 std::string privacy_link = base::StringPrintf( |
365 kPrivacyLinkHtml, | 370 kPrivacyLinkHtml, |
366 l10n_util::GetStringUTF8( | 371 l10n_util::GetStringUTF8( |
367 IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); | 372 IDS_SAFE_BROWSING_PRIVACY_POLICY_PAGE).c_str()); |
368 | 373 |
369 strings->SetString("confirm_text", | 374 strings->SetString("confirm_text", |
370 l10n_util::GetStringFUTF16( | 375 l10n_util::GetStringFUTF16( |
371 IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, | 376 IDS_SAFE_BROWSING_MALWARE_REPORTING_AGREE, |
372 UTF8ToUTF16(privacy_link))); | 377 UTF8ToUTF16(privacy_link))); |
373 | 378 |
374 Profile* profile = Profile::FromBrowserContext(tab()->GetBrowserContext()); | 379 Profile* profile = Profile::FromBrowserContext( |
| 380 web_contents_->GetBrowserContext()); |
375 const PrefService::Preference* pref = | 381 const PrefService::Preference* pref = |
376 profile->GetPrefs()->FindPreference( | 382 profile->GetPrefs()->FindPreference( |
377 prefs::kSafeBrowsingReportingEnabled); | 383 prefs::kSafeBrowsingReportingEnabled); |
378 | 384 |
379 bool value; | 385 bool value; |
380 if (pref && pref->GetValue()->GetAsBoolean(&value) && value) { | 386 if (pref && pref->GetValue()->GetAsBoolean(&value) && value) { |
381 strings->SetString(kBoxChecked, "yes"); | 387 strings->SetString(kBoxChecked, "yes"); |
382 } else { | 388 } else { |
383 strings->SetString(kBoxChecked, ""); | 389 strings->SetString(kBoxChecked, ""); |
384 } | 390 } |
385 } | 391 } |
386 } | 392 } |
387 | 393 |
388 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( | 394 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( |
389 DictionaryValue* strings) { | 395 DictionaryValue* strings) { |
390 std::string proceed_link = base::StringPrintf( | 396 std::string proceed_link = base::StringPrintf( |
391 kPLinkHtml, | 397 kPLinkHtml, |
392 l10n_util::GetStringUTF8( | 398 l10n_util::GetStringUTF8( |
393 IDS_SAFE_BROWSING_PHISHING_PROCEED_LINK).c_str()); | 399 IDS_SAFE_BROWSING_PHISHING_PROCEED_LINK).c_str()); |
394 string16 description3 = l10n_util::GetStringFUTF16( | 400 string16 description3 = l10n_util::GetStringFUTF16( |
395 IDS_SAFE_BROWSING_PHISHING_DESCRIPTION3, | 401 IDS_SAFE_BROWSING_PHISHING_DESCRIPTION3, |
396 UTF8ToUTF16(proceed_link)); | 402 UTF8ToUTF16(proceed_link)); |
397 | 403 |
398 PopulateStringDictionary( | 404 PopulateStringDictionary( |
399 strings, | 405 strings, |
400 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_TITLE), | 406 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_TITLE), |
401 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_HEADLINE), | 407 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_HEADLINE), |
402 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION1, | 408 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION1, |
403 UTF8ToUTF16(url().host())), | 409 UTF8ToUTF16(url_.host())), |
404 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION2), | 410 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION2), |
405 description3); | 411 description3); |
406 | 412 |
407 strings->SetString("back_button", | 413 strings->SetString("back_button", |
408 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_BACK_BUTTON)); | 414 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_BACK_BUTTON)); |
409 strings->SetString("report_error", | 415 strings->SetString("report_error", |
410 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_REPORT_ERROR)); | 416 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_REPORT_ERROR)); |
411 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | 417 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
412 } | 418 } |
413 | 419 |
(...skipping 23 matching lines...) Expand all Loading... |
437 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMoreMalwareUrl)); | 443 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMoreMalwareUrl)); |
438 } else if (threat_type == SafeBrowsingService::URL_PHISHING || | 444 } else if (threat_type == SafeBrowsingService::URL_PHISHING || |
439 threat_type == SafeBrowsingService::CLIENT_SIDE_PHISHING_URL) { | 445 threat_type == SafeBrowsingService::CLIENT_SIDE_PHISHING_URL) { |
440 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMorePhishingUrl)); | 446 url = google_util::AppendGoogleLocaleParam(GURL(kLearnMorePhishingUrl)); |
441 } else { | 447 } else { |
442 NOTREACHED(); | 448 NOTREACHED(); |
443 } | 449 } |
444 | 450 |
445 OpenURLParams params( | 451 OpenURLParams params( |
446 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); | 452 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); |
447 tab()->OpenURL(params); | 453 web_contents_->OpenURL(params); |
448 return; | 454 return; |
449 } | 455 } |
450 | 456 |
451 if (command == kShowPrivacyCommand) { | 457 if (command == kShowPrivacyCommand) { |
452 // User pressed "Safe Browsing privacy policy". | 458 // User pressed "Safe Browsing privacy policy". |
453 GURL url(kSbPrivacyPolicyUrl); | 459 GURL url(kSbPrivacyPolicyUrl); |
454 OpenURLParams params( | 460 OpenURLParams params( |
455 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); | 461 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); |
456 tab()->OpenURL(params); | 462 web_contents_->OpenURL(params); |
457 return; | 463 return; |
458 } | 464 } |
459 | 465 |
460 if (command == kProceedCommand) { | 466 if (command == kProceedCommand) { |
461 Proceed(); | 467 interstitial_page_->Proceed(); |
462 // We are deleted after this. | 468 // We are deleted after this. |
463 return; | 469 return; |
464 } | 470 } |
465 | 471 |
466 if (command == kTakeMeBackCommand) { | 472 if (command == kTakeMeBackCommand) { |
467 if (is_main_frame_load_blocked_) { | 473 if (is_main_frame_load_blocked_) { |
468 // If the load is blocked, we want to close the interstitial and discard | 474 // If the load is blocked, we want to close the interstitial and discard |
469 // the pending entry. | 475 // the pending entry. |
470 DontProceed(); | 476 interstitial_page_->DontProceed(); |
471 // We are deleted after this. | 477 // We are deleted after this. |
472 return; | 478 return; |
473 } | 479 } |
474 | 480 |
475 // Otherwise the offending entry has committed, and we need to go back or | 481 // Otherwise the offending entry has committed, and we need to go back or |
476 // to a safe page. We will close the interstitial when that page commits. | 482 // to a safe page. We will close the interstitial when that page commits. |
477 if (tab()->GetController().CanGoBack()) { | 483 if (web_contents_->GetController().CanGoBack()) { |
478 tab()->GetController().GoBack(); | 484 web_contents_->GetController().GoBack(); |
479 } else { | 485 } else { |
480 tab()->GetController().LoadURL(GURL(chrome::kChromeUINewTabURL), | 486 web_contents_->GetController().LoadURL( |
481 content::Referrer(), | 487 GURL(chrome::kChromeUINewTabURL), |
482 content::PAGE_TRANSITION_START_PAGE, | 488 content::Referrer(), |
483 std::string()); | 489 content::PAGE_TRANSITION_START_PAGE, |
| 490 std::string()); |
484 } | 491 } |
485 return; | 492 return; |
486 } | 493 } |
487 | 494 |
488 // The "report error" and "show diagnostic" commands can have a number | 495 // The "report error" and "show diagnostic" commands can have a number |
489 // appended to them, which is the index of the element they apply to. | 496 // appended to them, which is the index of the element they apply to. |
490 int element_index = 0; | 497 int element_index = 0; |
491 size_t colon_index = command.find(':'); | 498 size_t colon_index = command.find(':'); |
492 if (colon_index != std::string::npos) { | 499 if (colon_index != std::string::npos) { |
493 DCHECK(colon_index < command.size() - 1); | 500 DCHECK(colon_index < command.size() - 1); |
(...skipping 20 matching lines...) Expand all Loading... |
514 DCHECK(threat_type == SafeBrowsingService::URL_PHISHING || | 521 DCHECK(threat_type == SafeBrowsingService::URL_PHISHING || |
515 threat_type == SafeBrowsingService::CLIENT_SIDE_PHISHING_URL); | 522 threat_type == SafeBrowsingService::CLIENT_SIDE_PHISHING_URL); |
516 GURL report_url = | 523 GURL report_url = |
517 safe_browsing_util::GeneratePhishingReportUrl( | 524 safe_browsing_util::GeneratePhishingReportUrl( |
518 kSbReportPhishingErrorUrl, | 525 kSbReportPhishingErrorUrl, |
519 bad_url_spec, | 526 bad_url_spec, |
520 threat_type == SafeBrowsingService::CLIENT_SIDE_PHISHING_URL); | 527 threat_type == SafeBrowsingService::CLIENT_SIDE_PHISHING_URL); |
521 OpenURLParams params( | 528 OpenURLParams params( |
522 report_url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, | 529 report_url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, |
523 false); | 530 false); |
524 tab()->OpenURL(params); | 531 web_contents_->OpenURL(params); |
525 return; | 532 return; |
526 } | 533 } |
527 | 534 |
528 if (command == kShowDiagnosticCommand) { | 535 if (command == kShowDiagnosticCommand) { |
529 // We're going to take the user to Google's SafeBrowsing diagnostic page. | 536 // We're going to take the user to Google's SafeBrowsing diagnostic page. |
530 std::string diagnostic = | 537 std::string diagnostic = |
531 base::StringPrintf(kSbDiagnosticUrl, | 538 base::StringPrintf(kSbDiagnosticUrl, |
532 net::EscapeQueryParamValue(bad_url_spec, true).c_str()); | 539 net::EscapeQueryParamValue(bad_url_spec, true).c_str()); |
533 GURL diagnostic_url(diagnostic); | 540 GURL diagnostic_url(diagnostic); |
534 diagnostic_url = google_util::AppendGoogleLocaleParam(diagnostic_url); | 541 diagnostic_url = google_util::AppendGoogleLocaleParam(diagnostic_url); |
535 DCHECK(unsafe_resources_[element_index].threat_type == | 542 DCHECK(unsafe_resources_[element_index].threat_type == |
536 SafeBrowsingService::URL_MALWARE); | 543 SafeBrowsingService::URL_MALWARE); |
537 OpenURLParams params( | 544 OpenURLParams params( |
538 diagnostic_url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, | 545 diagnostic_url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_LINK, |
539 false); | 546 false); |
540 tab()->OpenURL(params); | 547 web_contents_->OpenURL(params); |
541 return; | 548 return; |
542 } | 549 } |
543 | 550 |
544 NOTREACHED() << "Unexpected command: " << command; | 551 NOTREACHED() << "Unexpected command: " << command; |
545 } | 552 } |
546 | 553 |
| 554 void SafeBrowsingBlockingPage::OverrideRendererPrefs( |
| 555 content::RendererPreferences* prefs) { |
| 556 Profile* profile = Profile::FromBrowserContext( |
| 557 web_contents_->GetBrowserContext()); |
| 558 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); |
| 559 } |
| 560 |
547 void SafeBrowsingBlockingPage::SetReportingPreference(bool report) { | 561 void SafeBrowsingBlockingPage::SetReportingPreference(bool report) { |
548 Profile* profile = Profile::FromBrowserContext(tab()->GetBrowserContext()); | 562 Profile* profile = Profile::FromBrowserContext( |
| 563 web_contents_->GetBrowserContext()); |
549 PrefService* pref = profile->GetPrefs(); | 564 PrefService* pref = profile->GetPrefs(); |
550 pref->SetBoolean(prefs::kSafeBrowsingReportingEnabled, report); | 565 pref->SetBoolean(prefs::kSafeBrowsingReportingEnabled, report); |
551 } | 566 } |
552 | 567 |
553 void SafeBrowsingBlockingPage::Proceed() { | 568 void SafeBrowsingBlockingPage::OnProceed() { |
| 569 proceeded_ = true; |
554 RecordUserAction(PROCEED); | 570 RecordUserAction(PROCEED); |
555 // Send the malware details, if we opted to. | 571 // Send the malware details, if we opted to. |
556 FinishMalwareDetails(malware_details_proceed_delay_ms_); | 572 FinishMalwareDetails(malware_details_proceed_delay_ms_); |
557 | 573 |
558 NotifySafeBrowsingService(sb_service_, unsafe_resources_, true); | 574 NotifySafeBrowsingService(sb_service_, unsafe_resources_, true); |
559 | 575 |
560 // Check to see if some new notifications of unsafe resources have been | 576 // Check to see if some new notifications of unsafe resources have been |
561 // received while we were showing the interstitial. | 577 // received while we were showing the interstitial. |
562 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 578 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
563 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); | 579 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents_); |
564 SafeBrowsingBlockingPage* blocking_page = NULL; | 580 SafeBrowsingBlockingPage* blocking_page = NULL; |
565 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { | 581 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { |
566 // Build an interstitial for all the unsafe resources notifications. | 582 // Build an interstitial for all the unsafe resources notifications. |
567 // Don't show it now as showing an interstitial while an interstitial is | 583 // Don't show it now as showing an interstitial while an interstitial is |
568 // already showing would cause DontProceed() to be invoked. | 584 // already showing would cause DontProceed() to be invoked. |
569 blocking_page = factory_->CreateSafeBrowsingPage(sb_service_, tab(), | 585 blocking_page = factory_->CreateSafeBrowsingPage(sb_service_, web_contents_, |
570 iter->second); | 586 iter->second); |
571 unsafe_resource_map->erase(iter); | 587 unsafe_resource_map->erase(iter); |
572 } | 588 } |
573 | 589 |
574 InterstitialPage::Proceed(); | |
575 // We are now deleted. | |
576 | |
577 // Now that this interstitial is gone, we can show the new one. | 590 // Now that this interstitial is gone, we can show the new one. |
578 if (blocking_page) | 591 if (blocking_page) |
579 blocking_page->Show(); | 592 blocking_page->interstitial_page_->Show(); |
580 } | 593 } |
581 | 594 |
582 void SafeBrowsingBlockingPage::DontProceed() { | 595 void SafeBrowsingBlockingPage::OnDontProceed() { |
583 DCHECK(action_taken() != DONT_PROCEED_ACTION); | |
584 // We could have already called Proceed(), in which case we must not notify | 596 // We could have already called Proceed(), in which case we must not notify |
585 // the SafeBrowsingService again, as the client has been deleted. | 597 // the SafeBrowsingService again, as the client has been deleted. |
586 if (action_taken() == PROCEED_ACTION) { | 598 if (proceeded_) |
587 // We still want to hide the interstitial page. | |
588 InterstitialPage::DontProceed(); | |
589 // We are now deleted. | |
590 return; | 599 return; |
591 } | |
592 | 600 |
593 RecordUserAction(DONT_PROCEED); | 601 RecordUserAction(DONT_PROCEED); |
594 // Send the malware details, if we opted to. | 602 // Send the malware details, if we opted to. |
595 FinishMalwareDetails(0); // No delay | 603 FinishMalwareDetails(0); // No delay |
596 | 604 |
597 NotifySafeBrowsingService(sb_service_, unsafe_resources_, false); | 605 NotifySafeBrowsingService(sb_service_, unsafe_resources_, false); |
598 | 606 |
599 // The user does not want to proceed, clear the queued unsafe resources | 607 // The user does not want to proceed, clear the queued unsafe resources |
600 // notifications we received while the interstitial was showing. | 608 // notifications we received while the interstitial was showing. |
601 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 609 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
602 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab()); | 610 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(web_contents_); |
603 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { | 611 if (iter != unsafe_resource_map->end() && !iter->second.empty()) { |
604 NotifySafeBrowsingService(sb_service_, iter->second, false); | 612 NotifySafeBrowsingService(sb_service_, iter->second, false); |
605 unsafe_resource_map->erase(iter); | 613 unsafe_resource_map->erase(iter); |
606 } | 614 } |
607 | 615 |
608 // We don't remove the navigation entry if the tab is being destroyed as this | 616 // We don't remove the navigation entry if the tab is being destroyed as this |
609 // would trigger a navigation that would cause trouble as the render view host | 617 // would trigger a navigation that would cause trouble as the render view host |
610 // for the tab has by then already been destroyed. We also don't delete the | 618 // for the tab has by then already been destroyed. We also don't delete the |
611 // current entry if it has been committed again, which is possible on a page | 619 // current entry if it has been committed again, which is possible on a page |
612 // that had a subresource warning. | 620 // that had a subresource warning. |
613 int last_committed_index = | 621 int last_committed_index = |
614 tab()->GetController().GetLastCommittedEntryIndex(); | 622 web_contents_->GetController().GetLastCommittedEntryIndex(); |
615 if (navigation_entry_index_to_remove_ != -1 && | 623 if (navigation_entry_index_to_remove_ != -1 && |
616 navigation_entry_index_to_remove_ != last_committed_index && | 624 navigation_entry_index_to_remove_ != last_committed_index && |
617 !tab()->IsBeingDestroyed()) { | 625 !web_contents_->IsBeingDestroyed()) { |
618 tab()->GetController().RemoveEntryAtIndex( | 626 web_contents_->GetController().RemoveEntryAtIndex( |
619 navigation_entry_index_to_remove_); | 627 navigation_entry_index_to_remove_); |
620 navigation_entry_index_to_remove_ = -1; | 628 navigation_entry_index_to_remove_ = -1; |
621 } | 629 } |
622 InterstitialPage::DontProceed(); | |
623 // We are now deleted. | |
624 } | 630 } |
625 | 631 |
626 void SafeBrowsingBlockingPage::RecordUserAction(BlockingPageEvent event) { | 632 void SafeBrowsingBlockingPage::RecordUserAction(BlockingPageEvent event) { |
627 // Determine the interstitial type from the blocked resources. | 633 // Determine the interstitial type from the blocked resources. |
628 // This is the same logic that is used to actually construct the | 634 // This is the same logic that is used to actually construct the |
629 // page contents; we can look at the title to see which type of | 635 // page contents; we can look at the title to see which type of |
630 // interstitial is being displayed. | 636 // interstitial is being displayed. |
631 DictionaryValue strings; | 637 DictionaryValue strings; |
632 PopulateMultipleThreatStringDictionary(&strings); | 638 PopulateMultipleThreatStringDictionary(&strings); |
633 | 639 |
(...skipping 28 matching lines...) Expand all Loading... |
662 NOTREACHED() << "Unexpected event: " << event; | 668 NOTREACHED() << "Unexpected event: " << event; |
663 } | 669 } |
664 | 670 |
665 content::RecordComputedAction(action); | 671 content::RecordComputedAction(action); |
666 } | 672 } |
667 | 673 |
668 void SafeBrowsingBlockingPage::FinishMalwareDetails(int64 delay_ms) { | 674 void SafeBrowsingBlockingPage::FinishMalwareDetails(int64 delay_ms) { |
669 if (malware_details_ == NULL) | 675 if (malware_details_ == NULL) |
670 return; // Not all interstitials have malware details (eg phishing). | 676 return; // Not all interstitials have malware details (eg phishing). |
671 | 677 |
672 Profile* profile = Profile::FromBrowserContext(tab()->GetBrowserContext()); | 678 Profile* profile = Profile::FromBrowserContext( |
| 679 web_contents_->GetBrowserContext()); |
673 const PrefService::Preference* pref = | 680 const PrefService::Preference* pref = |
674 profile->GetPrefs()->FindPreference(prefs::kSafeBrowsingReportingEnabled); | 681 profile->GetPrefs()->FindPreference(prefs::kSafeBrowsingReportingEnabled); |
675 | 682 |
676 bool value; | 683 bool value; |
677 if (pref && pref->GetValue()->GetAsBoolean(&value) && value) { | 684 if (pref && pref->GetValue()->GetAsBoolean(&value) && value) { |
678 // Finish the malware details collection, send it over. | 685 // Finish the malware details collection, send it over. |
679 BrowserThread::PostDelayedTask( | 686 BrowserThread::PostDelayedTask( |
680 BrowserThread::IO, FROM_HERE, | 687 BrowserThread::IO, FROM_HERE, |
681 base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()), | 688 base::Bind(&MalwareDetails::FinishCollection, malware_details_.get()), |
682 delay_ms); | 689 delay_ms); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 // There are no interstitial currently showing in that tab, go ahead and | 728 // There are no interstitial currently showing in that tab, go ahead and |
722 // show this interstitial. | 729 // show this interstitial. |
723 std::vector<SafeBrowsingService::UnsafeResource> resources; | 730 std::vector<SafeBrowsingService::UnsafeResource> resources; |
724 resources.push_back(unsafe_resource); | 731 resources.push_back(unsafe_resource); |
725 // Set up the factory if this has not been done already (tests do that | 732 // Set up the factory if this has not been done already (tests do that |
726 // before this method is called). | 733 // before this method is called). |
727 if (!factory_) | 734 if (!factory_) |
728 factory_ = g_safe_browsing_blocking_page_factory_impl.Pointer(); | 735 factory_ = g_safe_browsing_blocking_page_factory_impl.Pointer(); |
729 SafeBrowsingBlockingPage* blocking_page = | 736 SafeBrowsingBlockingPage* blocking_page = |
730 factory_->CreateSafeBrowsingPage(sb_service, web_contents, resources); | 737 factory_->CreateSafeBrowsingPage(sb_service, web_contents, resources); |
731 blocking_page->Show(); | 738 blocking_page->interstitial_page_->Show(); |
732 return; | 739 return; |
733 } | 740 } |
734 | 741 |
735 // This is an interstitial for a page's resource, let's queue it. | 742 // This is an interstitial for a page's resource, let's queue it. |
736 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 743 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
737 (*unsafe_resource_map)[web_contents].push_back(unsafe_resource); | 744 (*unsafe_resource_map)[web_contents].push_back(unsafe_resource); |
738 } | 745 } |
739 | 746 |
740 // static | 747 // static |
741 bool SafeBrowsingBlockingPage::IsMainPageLoadBlocked( | 748 bool SafeBrowsingBlockingPage::IsMainPageLoadBlocked( |
742 const UnsafeResourceList& unsafe_resources) { | 749 const UnsafeResourceList& unsafe_resources) { |
743 // Client-side phishing detection interstitials never block the main frame | 750 // Client-side phishing detection interstitials never block the main frame |
744 // load, since they happen after the page is finished loading. | 751 // load, since they happen after the page is finished loading. |
745 if (unsafe_resources[0].threat_type == | 752 if (unsafe_resources[0].threat_type == |
746 SafeBrowsingService::CLIENT_SIDE_PHISHING_URL) { | 753 SafeBrowsingService::CLIENT_SIDE_PHISHING_URL) { |
747 return false; | 754 return false; |
748 } | 755 } |
749 | 756 |
750 // Otherwise, check the threat type. | 757 // Otherwise, check the threat type. |
751 return unsafe_resources.size() == 1 && !unsafe_resources[0].is_subresource; | 758 return unsafe_resources.size() == 1 && !unsafe_resources[0].is_subresource; |
752 } | 759 } |
OLD | NEW |