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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 // URL for the "Learn more" link on the multi threat malware blocking page. | 52 // URL for the "Learn more" link on the multi threat malware blocking page. |
53 static const char* const kLearnMoreMalwareUrl = | 53 static const char* const kLearnMoreMalwareUrl = |
54 "http://www.google.com/support/bin/answer.py?answer=45449&topic=360" | 54 "http://www.google.com/support/bin/answer.py?answer=45449&topic=360" |
55 "&sa=X&oi=malwarewarninglink&resnum=1&ct=help"; | 55 "&sa=X&oi=malwarewarninglink&resnum=1&ct=help"; |
56 | 56 |
57 // URL for the "Learn more" link on the phishing blocking page. | 57 // URL for the "Learn more" link on the phishing blocking page. |
58 static const char* const kLearnMorePhishingUrl = | 58 static const char* const kLearnMorePhishingUrl = |
59 "http://www.google.com/support/bin/answer.py?answer=106318"; | 59 "http://www.google.com/support/bin/answer.py?answer=106318"; |
60 | 60 |
61 static const wchar_t* const kSbDiagnosticHtml = | 61 static const char* const kSbDiagnosticHtml = |
62 L"<a href=\"\" onclick=\"sendCommand('showDiagnostic'); return false;\" " | 62 "<a href=\"\" onclick=\"sendCommand('showDiagnostic'); return false;\" " |
63 L"onmousedown=\"return false;\">%ls</a>"; | 63 "onmousedown=\"return false;\">%s</a>"; |
64 | 64 |
65 static const wchar_t* const kPLinkHtml = | 65 static const char* const kPLinkHtml = |
66 L"<a href=\"\" onclick=\"sendCommand('proceed'); return false;\" " | 66 "<a href=\"\" onclick=\"sendCommand('proceed'); return false;\" " |
67 L"onmousedown=\"return false;\">%ls</a>"; | 67 "onmousedown=\"return false;\">%s</a>"; |
68 | 68 |
69 // The commands returned by the page when the user performs an action. | 69 // The commands returned by the page when the user performs an action. |
70 static const char* const kShowDiagnosticCommand = "showDiagnostic"; | 70 static const char* const kShowDiagnosticCommand = "showDiagnostic"; |
71 static const char* const kReportErrorCommand = "reportError"; | 71 static const char* const kReportErrorCommand = "reportError"; |
72 static const char* const kLearnMoreCommand = "learnMore"; | 72 static const char* const kLearnMoreCommand = "learnMore"; |
73 static const char* const kProceedCommand = "proceed"; | 73 static const char* const kProceedCommand = "proceed"; |
74 static const char* const kTakeMeBackCommand = "takeMeBack"; | 74 static const char* const kTakeMeBackCommand = "takeMeBack"; |
75 | 75 |
76 // static | 76 // static |
77 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; | 77 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 SafeBrowsingService::URL_PHISHING); | 168 SafeBrowsingService::URL_PHISHING); |
169 PopulatePhishingStringDictionary(&strings); | 169 PopulatePhishingStringDictionary(&strings); |
170 html = rb.GetRawDataResource(IDR_SAFE_BROWSING_PHISHING_BLOCK).as_string(); | 170 html = rb.GetRawDataResource(IDR_SAFE_BROWSING_PHISHING_BLOCK).as_string(); |
171 } | 171 } |
172 | 172 |
173 return jstemplate_builder::GetTemplatesHtml(html, &strings, "template_root"); | 173 return jstemplate_builder::GetTemplatesHtml(html, &strings, "template_root"); |
174 } | 174 } |
175 | 175 |
176 void SafeBrowsingBlockingPage::PopulateStringDictionary( | 176 void SafeBrowsingBlockingPage::PopulateStringDictionary( |
177 DictionaryValue* strings, | 177 DictionaryValue* strings, |
178 const std::wstring& title, | 178 const string16& title, |
179 const std::wstring& headline, | 179 const string16& headline, |
180 const std::wstring& description1, | 180 const string16& description1, |
181 const std::wstring& description2, | 181 const string16& description2, |
182 const std::wstring& description3) { | 182 const string16& description3) { |
183 strings->SetString("title", WideToUTF16Hack(title)); | 183 strings->SetString("title", title); |
184 strings->SetString("headLine", WideToUTF16Hack(headline)); | 184 strings->SetString("headLine", headline); |
185 strings->SetString("description1", WideToUTF16Hack(description1)); | 185 strings->SetString("description1", description1); |
186 strings->SetString("description2", WideToUTF16Hack(description2)); | 186 strings->SetString("description2", description2); |
187 strings->SetString("description3", WideToUTF16Hack(description3)); | 187 strings->SetString("description3", description3); |
188 } | 188 } |
189 | 189 |
190 void SafeBrowsingBlockingPage::PopulateMultipleThreatStringDictionary( | 190 void SafeBrowsingBlockingPage::PopulateMultipleThreatStringDictionary( |
191 DictionaryValue* strings) { | 191 DictionaryValue* strings) { |
192 bool malware = false; | 192 bool malware = false; |
193 bool phishing = false; | 193 bool phishing = false; |
194 | 194 |
195 string16 malware_label = | 195 string16 malware_label = |
196 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_LABEL); | 196 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_LABEL); |
197 string16 malware_link = | 197 string16 malware_link = |
(...skipping 23 matching lines...) Expand all Loading... |
221 current_error_strings->SetString("url", resource.url.spec()); | 221 current_error_strings->SetString("url", resource.url.spec()); |
222 error_strings->Append(current_error_strings); | 222 error_strings->Append(current_error_strings); |
223 } | 223 } |
224 strings->Set("errors", error_strings); | 224 strings->Set("errors", error_strings); |
225 DCHECK(phishing || malware); | 225 DCHECK(phishing || malware); |
226 | 226 |
227 if (malware && phishing) { | 227 if (malware && phishing) { |
228 PopulateStringDictionary( | 228 PopulateStringDictionary( |
229 strings, | 229 strings, |
230 // Use the malware headline, it is the scariest one. | 230 // Use the malware headline, it is the scariest one. |
231 l10n_util::GetString(IDS_SAFE_BROWSING_MULTI_THREAT_TITLE), | 231 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MULTI_THREAT_TITLE), |
232 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_HEADLINE), | 232 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_HEADLINE), |
233 l10n_util::GetStringF(IDS_SAFE_BROWSING_MULTI_THREAT_DESCRIPTION1, | 233 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MULTI_THREAT_DESCRIPTION1, |
234 UTF8ToWide(tab()->GetURL().host())), | 234 UTF8ToUTF16(tab()->GetURL().host())), |
235 l10n_util::GetString(IDS_SAFE_BROWSING_MULTI_THREAT_DESCRIPTION2), | 235 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MULTI_THREAT_DESCRIPTION2), |
236 L""); | 236 string16()); |
237 } else if (malware) { | 237 } else if (malware) { |
238 // Just malware. | 238 // Just malware. |
239 PopulateStringDictionary( | 239 PopulateStringDictionary( |
240 strings, | 240 strings, |
241 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_TITLE), | 241 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_TITLE), |
242 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_HEADLINE), | 242 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_HEADLINE), |
243 l10n_util::GetStringF(IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION1, | 243 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION1, |
244 UTF8ToWide(tab()->GetURL().host())), | 244 UTF8ToUTF16(tab()->GetURL().host())), |
245 l10n_util::GetString(IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION2), | 245 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION2), |
246 l10n_util::GetString(IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION3)); | 246 l10n_util::GetStringUTF16( |
| 247 IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION3)); |
247 } else { | 248 } else { |
248 // Just phishing. | 249 // Just phishing. |
249 PopulateStringDictionary( | 250 PopulateStringDictionary( |
250 strings, | 251 strings, |
251 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_TITLE), | 252 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_TITLE), |
252 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_HEADLINE), | 253 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_HEADLINE), |
253 l10n_util::GetStringF(IDS_SAFE_BROWSING_MULTI_PHISHING_DESCRIPTION1, | 254 l10n_util::GetStringFUTF16( |
254 UTF8ToWide(tab()->GetURL().host())), | 255 IDS_SAFE_BROWSING_MULTI_PHISHING_DESCRIPTION1, |
255 L"", L""); | 256 UTF8ToUTF16(tab()->GetURL().host())), |
| 257 string16(), |
| 258 string16()); |
256 } | 259 } |
257 | 260 |
258 strings->SetString("confirm_text", | 261 strings->SetString("confirm_text", |
259 l10n_util::GetStringUTF16( | 262 l10n_util::GetStringUTF16( |
260 IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION_AGREE)); | 263 IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION_AGREE)); |
261 strings->SetString("continue_button", | 264 strings->SetString("continue_button", |
262 l10n_util::GetStringUTF16( | 265 l10n_util::GetStringUTF16( |
263 IDS_SAFE_BROWSING_MULTI_MALWARE_PROCEED_BUTTON)); | 266 IDS_SAFE_BROWSING_MULTI_MALWARE_PROCEED_BUTTON)); |
264 strings->SetString("back_button", | 267 strings->SetString("back_button", |
265 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); | 268 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); |
266 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | 269 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
267 } | 270 } |
268 | 271 |
269 void SafeBrowsingBlockingPage::PopulateMalwareStringDictionary( | 272 void SafeBrowsingBlockingPage::PopulateMalwareStringDictionary( |
270 DictionaryValue* strings) { | 273 DictionaryValue* strings) { |
271 std::wstring diagnostic_link = StringPrintf(kSbDiagnosticHtml, | 274 std::string diagnostic_link = StringPrintf(kSbDiagnosticHtml, |
272 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_DIAGNOSTIC_PAGE).c_str()); | 275 l10n_util::GetStringUTF8( |
| 276 IDS_SAFE_BROWSING_MALWARE_DIAGNOSTIC_PAGE).c_str()); |
273 | 277 |
274 strings->SetString("badURL", url().host()); | 278 strings->SetString("badURL", url().host()); |
275 // Check to see if we're blocking the main page, or a sub-resource on the | 279 // Check to see if we're blocking the main page, or a sub-resource on the |
276 // main page. | 280 // main page. |
277 std::wstring description1, description3, description5; | 281 string16 description1, description3, description5; |
278 if (is_main_frame_) { | 282 if (is_main_frame_) { |
279 description1 = l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION1, | 283 description1 = l10n_util::GetStringFUTF16( |
280 UTF8ToWide(url().host())); | 284 IDS_SAFE_BROWSING_MALWARE_DESCRIPTION1, UTF8ToUTF16(url().host())); |
281 } else { | 285 } else { |
282 description1 = l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION4, | 286 description1 = l10n_util::GetStringFUTF16( |
283 UTF8ToWide(tab()->GetURL().host()), | 287 IDS_SAFE_BROWSING_MALWARE_DESCRIPTION4, |
284 UTF8ToWide(url().host())); | 288 UTF8ToUTF16(tab()->GetURL().host()), |
| 289 UTF8ToUTF16(url().host())); |
285 } | 290 } |
286 | 291 |
287 std::wstring proceed_link = StringPrintf(kPLinkHtml, | 292 std::string proceed_link = StringPrintf(kPLinkHtml, |
288 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_PROCEED_LINK).c_str()); | 293 l10n_util::GetStringUTF8(IDS_SAFE_BROWSING_MALWARE_PROCEED_LINK).c_str()); |
289 description3 = l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION3, | 294 description3 = |
290 proceed_link); | 295 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION3, |
| 296 UTF8ToUTF16(proceed_link)); |
291 | 297 |
292 PopulateStringDictionary( | 298 PopulateStringDictionary( |
293 strings, | 299 strings, |
294 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_TITLE), | 300 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_TITLE), |
295 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_HEADLINE), | 301 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_HEADLINE), |
296 description1, | 302 description1, |
297 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION2), | 303 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION2), |
298 description3); | 304 description3); |
299 | 305 |
300 description5 = l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION5, | 306 description5 = |
301 UTF8ToWide(url().host()), | 307 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION5, |
302 UTF8ToWide(url().host()), | 308 UTF8ToUTF16(url().host()), |
303 diagnostic_link); | 309 UTF8ToUTF16(url().host()), |
| 310 UTF8ToUTF16(diagnostic_link)); |
304 | 311 |
305 strings->SetString("description5", WideToUTF16Hack(description5)); | 312 strings->SetString("description5", description5); |
306 | 313 |
307 strings->SetString("back_button", | 314 strings->SetString("back_button", |
308 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); | 315 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON)); |
309 strings->SetString("proceed_link", | 316 strings->SetString("proceed_link", |
310 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_PROCEED_LINK)); | 317 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_PROCEED_LINK)); |
311 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | 318 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
312 } | 319 } |
313 | 320 |
314 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( | 321 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary( |
315 DictionaryValue* strings) { | 322 DictionaryValue* strings) { |
316 std::wstring proceed_link = StringPrintf( | 323 std::string proceed_link = StringPrintf(kPLinkHtml, l10n_util::GetStringUTF8( |
317 kPLinkHtml, | 324 IDS_SAFE_BROWSING_PHISHING_PROCEED_LINK).c_str()); |
318 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_PROCEED_LINK).c_str()); | 325 string16 description3 = l10n_util::GetStringFUTF16( |
319 std::wstring description3 = l10n_util::GetStringF( | |
320 IDS_SAFE_BROWSING_PHISHING_DESCRIPTION3, | 326 IDS_SAFE_BROWSING_PHISHING_DESCRIPTION3, |
321 proceed_link); | 327 UTF8ToUTF16(proceed_link)); |
322 | 328 |
323 PopulateStringDictionary( | 329 PopulateStringDictionary( |
324 strings, | 330 strings, |
325 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_TITLE), | 331 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_TITLE), |
326 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_HEADLINE), | 332 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_HEADLINE), |
327 l10n_util::GetStringF(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION1, | 333 l10n_util::GetStringFUTF16(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION1, |
328 UTF8ToWide(url().host())), | 334 UTF8ToUTF16(url().host())), |
329 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION2), | 335 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION2), |
330 description3); | 336 description3); |
331 | 337 |
332 strings->SetString("back_button", | 338 strings->SetString("back_button", |
333 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_BACK_BUTTON)); | 339 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_BACK_BUTTON)); |
334 strings->SetString("report_error", | 340 strings->SetString("report_error", |
335 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_REPORT_ERROR)); | 341 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_REPORT_ERROR)); |
336 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | 342 strings->SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
337 } | 343 } |
338 | 344 |
339 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { | 345 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); | 604 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap(); |
599 (*unsafe_resource_map)[tab_contents].push_back(unsafe_resource); | 605 (*unsafe_resource_map)[tab_contents].push_back(unsafe_resource); |
600 } | 606 } |
601 | 607 |
602 // static | 608 // static |
603 bool SafeBrowsingBlockingPage::IsMainPage( | 609 bool SafeBrowsingBlockingPage::IsMainPage( |
604 const UnsafeResourceList& unsafe_resources) { | 610 const UnsafeResourceList& unsafe_resources) { |
605 return unsafe_resources.size() == 1 && | 611 return unsafe_resources.size() == 1 && |
606 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; | 612 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME; |
607 } | 613 } |
OLD | NEW |