| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 return jstemplate_builder::GetTemplatesHtml(html, &strings, "template_root"); | 139 return jstemplate_builder::GetTemplatesHtml(html, &strings, "template_root"); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void SafeBrowsingBlockingPage::PopulateStringDictionary( | 142 void SafeBrowsingBlockingPage::PopulateStringDictionary( |
| 143 DictionaryValue* strings, | 143 DictionaryValue* strings, |
| 144 const std::wstring& title, | 144 const std::wstring& title, |
| 145 const std::wstring& headline, | 145 const std::wstring& headline, |
| 146 const std::wstring& description1, | 146 const std::wstring& description1, |
| 147 const std::wstring& description2, | 147 const std::wstring& description2, |
| 148 const std::wstring& description3) { | 148 const std::wstring& description3) { |
| 149 strings->SetString(L"title", title); | 149 strings->SetString("title", WideToUTF16Hack(title)); |
| 150 strings->SetString(L"headLine", headline); | 150 strings->SetString("headLine", WideToUTF16Hack(headline)); |
| 151 strings->SetString(L"description1", description1); | 151 strings->SetString("description1", WideToUTF16Hack(description1)); |
| 152 strings->SetString(L"description2", description2); | 152 strings->SetString("description2", WideToUTF16Hack(description2)); |
| 153 strings->SetString(L"description3", description3); | 153 strings->SetString("description3", WideToUTF16Hack(description3)); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void SafeBrowsingBlockingPage::PopulateMultipleThreatStringDictionary( | 156 void SafeBrowsingBlockingPage::PopulateMultipleThreatStringDictionary( |
| 157 DictionaryValue* strings) { | 157 DictionaryValue* strings) { |
| 158 bool malware = false; | 158 bool malware = false; |
| 159 bool phishing = false; | 159 bool phishing = false; |
| 160 | 160 |
| 161 std::wstring phishing_label = | 161 string16 malware_label = |
| 162 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_LABEL); | 162 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_LABEL); |
| 163 std::wstring phishing_link = | 163 string16 malware_link = |
| 164 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_REPORT_ERROR); | 164 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_DIAGNOSTIC_PAGE); |
| 165 std::wstring malware_label = | 165 string16 phishing_label = |
| 166 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_LABEL); | 166 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_LABEL); |
| 167 std::wstring malware_link = | 167 string16 phishing_link = |
| 168 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_DIAGNOSTIC_PAGE); | 168 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_REPORT_ERROR); |
| 169 | 169 |
| 170 ListValue* error_strings = new ListValue; | 170 ListValue* error_strings = new ListValue; |
| 171 for (UnsafeResourceList::const_iterator iter = unsafe_resources_.begin(); | 171 for (UnsafeResourceList::const_iterator iter = unsafe_resources_.begin(); |
| 172 iter != unsafe_resources_.end(); ++iter) { | 172 iter != unsafe_resources_.end(); ++iter) { |
| 173 const SafeBrowsingService::UnsafeResource& resource = *iter; | 173 const SafeBrowsingService::UnsafeResource& resource = *iter; |
| 174 DictionaryValue* current_error_strings = new DictionaryValue; | 174 DictionaryValue* current_error_strings = new DictionaryValue; |
| 175 if (resource.threat_type == SafeBrowsingService::URL_MALWARE) { | 175 if (resource.threat_type == SafeBrowsingService::URL_MALWARE) { |
| 176 malware = true; | 176 malware = true; |
| 177 current_error_strings->SetString(L"type", L"malware"); | 177 current_error_strings->SetString("type", "malware"); |
| 178 current_error_strings->SetString(L"typeLabel", malware_label); | 178 current_error_strings->SetString("typeLabel", malware_label); |
| 179 current_error_strings->SetString(L"errorLink", malware_link); | 179 current_error_strings->SetString("errorLink", malware_link); |
| 180 } else { | 180 } else { |
| 181 DCHECK(resource.threat_type == SafeBrowsingService::URL_PHISHING); | 181 DCHECK(resource.threat_type == SafeBrowsingService::URL_PHISHING); |
| 182 phishing = true; | 182 phishing = true; |
| 183 current_error_strings->SetString(L"type", L"phishing"); | 183 current_error_strings->SetString("type", "phishing"); |
| 184 current_error_strings->SetString(L"typeLabel", phishing_label); | 184 current_error_strings->SetString("typeLabel", phishing_label); |
| 185 current_error_strings->SetString(L"errorLink", phishing_link); | 185 current_error_strings->SetString("errorLink", phishing_link); |
| 186 } | 186 } |
| 187 current_error_strings->SetString(L"url", UTF8ToWide(resource.url.spec())); | 187 current_error_strings->SetString("url", resource.url.spec()); |
| 188 error_strings->Append(current_error_strings); | 188 error_strings->Append(current_error_strings); |
| 189 } | 189 } |
| 190 strings->Set(L"errors", error_strings); | 190 strings->Set("errors", error_strings); |
| 191 DCHECK(phishing || malware); | 191 DCHECK(phishing || malware); |
| 192 | 192 |
| 193 if (malware && phishing) { | 193 if (malware && phishing) { |
| 194 PopulateStringDictionary( | 194 PopulateStringDictionary( |
| 195 strings, | 195 strings, |
| 196 // Use the malware headline, it is the scariest one. | 196 // Use the malware headline, it is the scariest one. |
| 197 l10n_util::GetString(IDS_SAFE_BROWSING_MULTI_THREAT_TITLE), | 197 l10n_util::GetString(IDS_SAFE_BROWSING_MULTI_THREAT_TITLE), |
| 198 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_HEADLINE), | 198 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_HEADLINE), |
| 199 l10n_util::GetStringF(IDS_SAFE_BROWSING_MULTI_THREAT_DESCRIPTION1, | 199 l10n_util::GetStringF(IDS_SAFE_BROWSING_MULTI_THREAT_DESCRIPTION1, |
| 200 UTF8ToWide(tab()->GetURL().host())), | 200 UTF8ToWide(tab()->GetURL().host())), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 214 // Just phishing. | 214 // Just phishing. |
| 215 PopulateStringDictionary( | 215 PopulateStringDictionary( |
| 216 strings, | 216 strings, |
| 217 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_TITLE), | 217 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_TITLE), |
| 218 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_HEADLINE), | 218 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_HEADLINE), |
| 219 l10n_util::GetStringF(IDS_SAFE_BROWSING_MULTI_PHISHING_DESCRIPTION1, | 219 l10n_util::GetStringF(IDS_SAFE_BROWSING_MULTI_PHISHING_DESCRIPTION1, |
| 220 UTF8ToWide(tab()->GetURL().host())), | 220 UTF8ToWide(tab()->GetURL().host())), |
| 221 L"", L""); | 221 L"", L""); |
| 222 } | 222 } |
| 223 | 223 |
| 224 strings->SetString(L"confirm_text", | 224 strings->SetString("confirm_text", |
| 225 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION_AGREE)); | 225 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION_AGREE)); |
| 226 strings->SetString(L"continue_button", | 226 strings->SetString("continue_button", |
| 227 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_PROCEED_BUTTON)); | 227 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_PROCEED_BUTTON)); |
| 228 strings->SetString(L"back_button", | 228 strings->SetString("back_button", |
| 229 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); | 229 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); |
| 230 strings->SetString(L"textdirection", base::i18n::IsRTL() ? L"rtl" : L"ltr"); | 230 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
| 231 } | 231 } |
| 232 | 232 |
| 233 void SafeBrowsingBlockingPage::PopulateMalwareStringDictionary( | 233 void SafeBrowsingBlockingPage::PopulateMalwareStringDictionary( |
| 234 DictionaryValue* strings) { | 234 DictionaryValue* strings) { |
| 235 std::wstring link = StringPrintf(kSbDiagnosticHtml, | 235 std::wstring link = StringPrintf(kSbDiagnosticHtml, |
| 236 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_DIAGNOSTIC_PAGE).c_str()); | 236 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_DIAGNOSTIC_PAGE).c_str()); |
| 237 | 237 |
| 238 strings->SetString(L"badURL", UTF8ToWide(url().host())); | 238 strings->SetString("badURL", url().host()); |
| 239 // Check to see if we're blocking the main page, or a sub-resource on the | 239 // Check to see if we're blocking the main page, or a sub-resource on the |
| 240 // main page. | 240 // main page. |
| 241 std::wstring description1, description2; | 241 std::wstring description1, description2; |
| 242 if (is_main_frame_) { | 242 if (is_main_frame_) { |
| 243 description1 = l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION1, | 243 description1 = l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION1, |
| 244 UTF8ToWide(url().host())); | 244 UTF8ToWide(url().host())); |
| 245 description2 = l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION2, | 245 description2 = l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION2, |
| 246 link, | 246 link, |
| 247 UTF8ToWide(url().host())); | 247 UTF8ToWide(url().host())); |
| 248 } else { | 248 } else { |
| 249 description1 = l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION4, | 249 description1 = l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION4, |
| 250 UTF8ToWide(tab()->GetURL().host()), | 250 UTF8ToWide(tab()->GetURL().host()), |
| 251 UTF8ToWide(url().host())); | 251 UTF8ToWide(url().host())); |
| 252 description2 = l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION5, | 252 description2 = l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION5, |
| 253 link, | 253 link, |
| 254 UTF8ToWide(url().host())); | 254 UTF8ToWide(url().host())); |
| 255 } | 255 } |
| 256 | 256 |
| 257 PopulateStringDictionary( | 257 PopulateStringDictionary( |
| 258 strings, | 258 strings, |
| 259 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_TITLE), | 259 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_TITLE), |
| 260 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_HEADLINE), | 260 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_HEADLINE), |
| 261 description1, description2, | 261 description1, description2, |
| 262 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION3)); | 262 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION3)); |
| 263 | 263 |
| 264 strings->SetString(L"confirm_text", | 264 strings->SetString("confirm_text", |
| 265 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION_AGREE)); | 265 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION_AGREE)); |
| 266 strings->SetString(L"continue_button", | 266 strings->SetString("continue_button", |
| 267 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_PROCEED_BUTTON)); | 267 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_PROCEED_BUTTON)); |
| 268 strings->SetString(L"back_button", | 268 strings->SetString("back_button", |
| 269 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); | 269 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); |
| 270 strings->SetString(L"textdirection", base::i18n::IsRTL() ? L"rtl" : L"ltr"); | 270 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
| 271 } | 271 } |
| 272 | 272 |
| 273 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( | 273 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( |
| 274 DictionaryValue* strings) { | 274 DictionaryValue* strings) { |
| 275 PopulateStringDictionary( | 275 PopulateStringDictionary( |
| 276 strings, | 276 strings, |
| 277 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_TITLE), | 277 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_TITLE), |
| 278 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_HEADLINE), | 278 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_HEADLINE), |
| 279 l10n_util::GetStringF(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION1, | 279 l10n_util::GetStringF(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION1, |
| 280 UTF8ToWide(url().host())), | 280 UTF8ToWide(url().host())), |
| 281 l10n_util::GetStringF(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION2, | 281 l10n_util::GetStringF(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION2, |
| 282 UTF8ToWide(url().host())), | 282 UTF8ToWide(url().host())), |
| 283 L""); | 283 L""); |
| 284 | 284 |
| 285 strings->SetString(L"continue_button", | 285 strings->SetString("continue_button", |
| 286 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_PROCEED_BUTTON)); | 286 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_PROCEED_BUTTON)); |
| 287 strings->SetString(L"back_button", | 287 strings->SetString("back_button", |
| 288 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_BACK_BUTTON)); | 288 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_BACK_BUTTON)); |
| 289 strings->SetString(L"report_error", | 289 strings->SetString("report_error", |
| 290 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_REPORT_ERROR)); | 290 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_REPORT_ERROR)); |
| 291 strings->SetString(L"textdirection", base::i18n::IsRTL() ? L"rtl" : L"ltr"); | 291 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
| 292 } | 292 } |
| 293 | 293 |
| 294 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { | 294 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { |
| 295 std::string command(cmd); // Make a local copy so we can modify it. | 295 std::string command(cmd); // Make a local copy so we can modify it. |
| 296 // The Jasonified response has quotes, remove them. | 296 // The Jasonified response has quotes, remove them. |
| 297 if (command.length() > 1 && command[0] == '"') { | 297 if (command.length() > 1 && command[0] == '"') { |
| 298 command = command.substr(1, command.length() - 2); | 298 command = command.substr(1, command.length() - 2); |
| 299 } | 299 } |
| 300 | 300 |
| 301 if (command == kLearnMoreCommand) { | 301 if (command == kLearnMoreCommand) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 } | 436 } |
| 437 | 437 |
| 438 void SafeBrowsingBlockingPage::RecordUserAction(BlockingPageEvent event) { | 438 void SafeBrowsingBlockingPage::RecordUserAction(BlockingPageEvent event) { |
| 439 // Determine the interstitial type from the blocked resources. | 439 // Determine the interstitial type from the blocked resources. |
| 440 // This is the same logic that is used to actually construct the | 440 // This is the same logic that is used to actually construct the |
| 441 // page contents; we can look at the title to see which type of | 441 // page contents; we can look at the title to see which type of |
| 442 // interstitial is being displayed. | 442 // interstitial is being displayed. |
| 443 DictionaryValue strings; | 443 DictionaryValue strings; |
| 444 PopulateMultipleThreatStringDictionary(&strings); | 444 PopulateMultipleThreatStringDictionary(&strings); |
| 445 | 445 |
| 446 std::wstring title; | 446 string16 title; |
| 447 DCHECK(strings.GetString(L"title", &title)); | 447 DCHECK(strings.GetString("title", &title)); |
| 448 | 448 |
| 449 std::string action = "SBInterstitial"; | 449 std::string action = "SBInterstitial"; |
| 450 if (title == l10n_util::GetString(IDS_SAFE_BROWSING_MULTI_THREAT_TITLE)) { | 450 if (title == |
| 451 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MULTI_THREAT_TITLE)) { |
| 451 action.append("Multiple"); | 452 action.append("Multiple"); |
| 452 } else if (title == l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_TITLE)) { | 453 } else if (title == |
| 454 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_TITLE)) { |
| 453 action.append("Malware"); | 455 action.append("Malware"); |
| 454 } else { | 456 } else { |
| 455 DCHECK_EQ(title, l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_TITLE)); | 457 DCHECK_EQ(title, |
| 458 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_TITLE)); |
| 456 action.append("Phishing"); | 459 action.append("Phishing"); |
| 457 } | 460 } |
| 458 | 461 |
| 459 switch (event) { | 462 switch (event) { |
| 460 case SHOW: | 463 case SHOW: |
| 461 action.append("Show"); | 464 action.append("Show"); |
| 462 break; | 465 break; |
| 463 case PROCEED: | 466 case PROCEED: |
| 464 action.append("Proceed"); | 467 action.append("Proceed"); |
| 465 break; | 468 break; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 531 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
| 529 (*unsafe_resource_map)[tab_contents].push_back(unsafe_resource); | 532 (*unsafe_resource_map)[tab_contents].push_back(unsafe_resource); |
| 530 } | 533 } |
| 531 | 534 |
| 532 // static | 535 // static |
| 533 bool SafeBrowsingBlockingPage::IsMainPage( | 536 bool SafeBrowsingBlockingPage::IsMainPage( |
| 534 const UnsafeResourceList& unsafe_resources) { | 537 const UnsafeResourceList& unsafe_resources) { |
| 535 return unsafe_resources.size() == 1 && | 538 return unsafe_resources.size() == 1 && |
| 536 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; | 539 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; |
| 537 } | 540 } |
| OLD | NEW |