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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page.cc

Issue 18346: Adds support for multiple malware/phishing resources in a page (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/string_util.h"
9 #include "chrome/app/locales/locale_settings.h" 10 #include "chrome/app/locales/locale_settings.h"
10 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/browser_resources.h" 12 #include "chrome/browser/browser_resources.h"
12 #include "chrome/browser/dom_operation_notification_details.h" 13 #include "chrome/browser/dom_operation_notification_details.h"
13 #include "chrome/browser/dom_ui/new_tab_ui.h" 14 #include "chrome/browser/dom_ui/new_tab_ui.h"
14 #include "chrome/browser/google_util.h" 15 #include "chrome/browser/google_util.h"
15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 16 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
16 #include "chrome/browser/tab_contents/navigation_controller.h" 17 #include "chrome/browser/tab_contents/navigation_controller.h"
17 #include "chrome/browser/tab_contents/navigation_entry.h" 18 #include "chrome/browser/tab_contents/navigation_entry.h"
18 #include "chrome/browser/tab_contents/tab_util.h" 19 #include "chrome/browser/tab_contents/tab_util.h"
(...skipping 12 matching lines...) Expand all
31 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie nt=googlechrome"; 32 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie nt=googlechrome";
32 #else 33 #else
33 static const char* const kSbDiagnosticUrl = 34 static const char* const kSbDiagnosticUrl =
34 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie nt=chromium"; 35 "http://safebrowsing.clients.google.com/safebrowsing/diagnostic?site=%s&clie nt=chromium";
35 #endif 36 #endif
36 37
37 static const char* const kSbReportPhishingUrl = 38 static const char* const kSbReportPhishingUrl =
38 "http://www.google.com/safebrowsing/report_error/"; 39 "http://www.google.com/safebrowsing/report_error/";
39 40
40 static const wchar_t* const kSbDiagnosticHtml = 41 static const wchar_t* const kSbDiagnosticHtml =
41 L"<a href=\"\" onClick=\"sendCommand(4); return false;\" onMouseDown=\"retur n false;\">%ls</a>"; 42 L"<a href=\"\" onClick=\"sendCommand('showDiagnostic'); return false;\" onMo useDown=\"return false;\">%ls</a>";
43
44 // The commands returned by the page when the user performs an action.
45 static const char* const kShowDiagnosticCommand = "showDiagnostic";
46 static const char* const kReportErrorCommand = "reportError";
47 static const char* const kLearnMoreCommand = "learnMore";
48 static const char* const kProceedCommand = "proceed";
49 static const char* const kTakeMeBackCommand = "takeMeBack";
42 50
43 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage( 51 SafeBrowsingBlockingPage::SafeBrowsingBlockingPage(
44 SafeBrowsingService* sb_service, 52 SafeBrowsingService* sb_service,
45 const SafeBrowsingService::BlockingPageParam& param) 53 WebContents* web_contents,
46 : InterstitialPage(tab_util::GetWebContentsByID( 54 const UnsafeResourceList& unsafe_resources)
47 param.render_process_host_id, param.render_view_id), 55 : InterstitialPage(web_contents,
48 param.resource_type == ResourceType::MAIN_FRAME, 56 IsMainPage(unsafe_resources),
49 param.url), 57 unsafe_resources[0].url),
50 sb_service_(sb_service), 58 sb_service_(sb_service),
51 client_(param.client), 59 unsafe_resources_(unsafe_resources),
52 render_process_host_id_(param.render_process_host_id), 60 is_main_frame_(IsMainPage(unsafe_resources)) {
53 render_view_id_(param.render_view_id),
54 result_(param.result),
55 proceed_(false),
56 did_notify_(false),
57 is_main_frame_(param.resource_type == ResourceType::MAIN_FRAME) {
58 if (!is_main_frame_) { 61 if (!is_main_frame_) {
59 navigation_entry_index_to_remove_ = 62 navigation_entry_index_to_remove_ =
60 tab()->controller()->GetLastCommittedEntryIndex(); 63 tab()->controller()->GetLastCommittedEntryIndex();
61 } else { 64 } else {
62 navigation_entry_index_to_remove_ = -1; 65 navigation_entry_index_to_remove_ = -1;
63 } 66 }
64 } 67 }
65 68
66 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() { 69 SafeBrowsingBlockingPage::~SafeBrowsingBlockingPage() {
67 } 70 }
68 71
69 std::string SafeBrowsingBlockingPage::GetHTMLContents() { 72 std::string SafeBrowsingBlockingPage::GetHTMLContents() {
70 // Load the HTML page and create the template components. 73 // Load the HTML page and create the template components.
71 DictionaryValue strings; 74 DictionaryValue strings;
72 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 75 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
73 std::string html; 76 std::string html;
74 77
75 if (result_ == SafeBrowsingService::URL_MALWARE) { 78 if (unsafe_resources_.empty()) {
76 std::wstring link = StringPrintf(kSbDiagnosticHtml, 79 NOTREACHED();
77 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_DIAGNOSTIC_PAGE). 80 return std::string();
78 c_str()); 81 }
79 82
80 strings.SetString(L"badURL", UTF8ToWide(url().host())); 83 if (unsafe_resources_.size() > 1) {
81 strings.SetString(L"title", 84 PopulateMultipleThreatStringDictionary(&strings);
82 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_TITLE)); 85 html = rb.GetDataResource(IDR_SAFE_BROWSING_MULTIPLE_THREAT_BLOCK);
83 strings.SetString(L"headLine", 86 } else if (unsafe_resources_[0].threat_type ==
84 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_HEADLINE)); 87 SafeBrowsingService::URL_MALWARE) {
85 88 PopulateMalwareStringDictionary(&strings);
86 // Check to see if we're blocking the main page, or a sub-resource on the
87 // main page.
88 if (is_main_frame_) {
89 strings.SetString(L"description1",
90 l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION1,
91 UTF8ToWide(url().host())));
92 strings.SetString(L"description2",
93 l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION2,
94 link,
95 UTF8ToWide(url().host())));
96 } else {
97 strings.SetString(L"description1",
98 l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION4,
99 UTF8ToWide(tab()->GetURL().host()),
100 UTF8ToWide(url().host())));
101 strings.SetString(L"description2",
102 l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION5,
103 link,
104 UTF8ToWide(url().host())));
105 }
106
107 strings.SetString(L"description3",
108 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION3));
109 strings.SetString(L"confirm_text",
110 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION_AGREE));
111 strings.SetString(L"continue_button",
112 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_PROCEED_BUTTON));
113 strings.SetString(L"back_button",
114 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON));
115 strings.SetString(L"textdirection",
116 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
117 L"rtl" : L"ltr");
118 html = rb.GetDataResource(IDR_SAFE_BROWSING_MALWARE_BLOCK); 89 html = rb.GetDataResource(IDR_SAFE_BROWSING_MALWARE_BLOCK);
119 } else { // Phishing. 90 } else { // Phishing.
120 strings.SetString(L"title", 91 DCHECK(unsafe_resources_[0].threat_type ==
121 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_TITLE)); 92 SafeBrowsingService::URL_PHISHING);
122 strings.SetString(L"headLine", 93 PopulatePhishingStringDictionary(&strings);
123 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_HEADLINE));
124 strings.SetString(L"description1",
125 l10n_util::GetStringF(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION1,
126 UTF8ToWide(url().host())));
127 strings.SetString(L"description2",
128 l10n_util::GetStringF(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION2,
129 UTF8ToWide(url().host())));
130
131 strings.SetString(L"continue_button",
132 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_PROCEED_BUTTON));
133 strings.SetString(L"back_button",
134 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_BACK_BUTTON));
135 strings.SetString(L"report_error",
136 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_REPORT_ERROR));
137 strings.SetString(L"textdirection",
138 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
139 L"rtl" : L"ltr");
140 html = rb.GetDataResource(IDR_SAFE_BROWSING_PHISHING_BLOCK); 94 html = rb.GetDataResource(IDR_SAFE_BROWSING_PHISHING_BLOCK);
141 } 95 }
142 96
143 return jstemplate_builder::GetTemplateHtml(html, &strings, "template_root"); 97 return jstemplate_builder::GetTemplateHtml(html, &strings, "template_root");
144 } 98 }
145 99
146 void SafeBrowsingBlockingPage::CommandReceived(const std::string& command) { 100 void SafeBrowsingBlockingPage::PopulateStringDictionary(
147 if (command == "2") { 101 DictionaryValue* strings,
102 const std::wstring& title,
103 const std::wstring& headline,
104 const std::wstring& description1,
105 const std::wstring& description2,
106 const std::wstring& description3) {
107 strings->SetString(L"title", title);
108 strings->SetString(L"headLine", headline);
109 strings->SetString(L"description1", description1);
110 strings->SetString(L"description2", description2);
111 strings->SetString(L"description3", description3);
112 }
113
114 void SafeBrowsingBlockingPage::PopulateMultipleThreatStringDictionary(
115 DictionaryValue* strings) {
116 bool malware = false;
117 bool phishing = false;
118
119 std::wstring phishing_label =
120 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_LABEL);
121 std::wstring phishing_link =
122 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_REPORT_ERROR);
123 std::wstring malware_label =
124 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_LABEL);
125 std::wstring malware_link =
126 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_DIAGNOSTIC_PAGE);
127
128 ListValue* error_strings = new ListValue;
129 for (UnsafeResourceList::const_iterator iter = unsafe_resources_.begin();
130 iter != unsafe_resources_.end(); ++iter) {
131 const SafeBrowsingService::UnsafeResource& resource = *iter;
132 DictionaryValue* current_error_strings = new DictionaryValue;
133 if (resource.threat_type == SafeBrowsingService::URL_MALWARE) {
134 malware = true;
135 current_error_strings->SetString(L"type", L"malware");
136 current_error_strings->SetString(L"typeLabel", malware_label);
137 current_error_strings->SetString(L"errorLink", malware_link);
138 } else {
139 DCHECK(resource.threat_type == SafeBrowsingService::URL_PHISHING);
140 phishing = true;
141 current_error_strings->SetString(L"type", L"phishing");
142 current_error_strings->SetString(L"typeLabel", phishing_label);
143 current_error_strings->SetString(L"errorLink", phishing_link);
144 }
145 current_error_strings->SetString(L"url", UTF8ToWide(resource.url.spec()));
146 error_strings->Append(current_error_strings);
147 }
148 strings->Set(L"errors", error_strings);
149 DCHECK(phishing || malware);
150
151 if (malware && phishing) {
152 PopulateStringDictionary(
153 strings,
154 // Use the malware headline, it is the scariest one.
155 l10n_util::GetString(IDS_SAFE_BROWSING_MULTI_THREAT_TITLE),
156 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_HEADLINE),
157 l10n_util::GetStringF(IDS_SAFE_BROWSING_MULTI_THREAT_DESCRIPTION1,
158 UTF8ToWide(tab()->GetURL().host())),
159 l10n_util::GetString(IDS_SAFE_BROWSING_MULTI_THREAT_DESCRIPTION2),
160 L"");
161 } else if (malware) {
162 // Just malware.
163 PopulateStringDictionary(
164 strings,
165 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_TITLE),
166 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_HEADLINE),
167 l10n_util::GetStringF(IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION1,
168 UTF8ToWide(tab()->GetURL().host())),
169 l10n_util::GetString(IDS_SAFE_BROWSING_MULTI_MALWARE_DESCRIPTION2),
170 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION3));
171 } else {
172 // Just phishing.
173 PopulateStringDictionary(
174 strings,
175 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_TITLE),
176 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_HEADLINE),
177 l10n_util::GetStringF(IDS_SAFE_BROWSING_MULTI_PHISHING_DESCRIPTION1,
178 UTF8ToWide(tab()->GetURL().host())),
179 L"", L"");
180 }
181
182 strings->SetString(L"confirm_text",
183 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION_AGREE));
184 strings->SetString(L"continue_button",
185 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_PROCEED_BUTTON));
186 strings->SetString(L"back_button",
187 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON));
188 strings->SetString(L"textdirection",
189 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
190 L"rtl" : L"ltr");
191 }
192
193 void SafeBrowsingBlockingPage::PopulateMalwareStringDictionary(
194 DictionaryValue* strings) {
195 std::wstring link = StringPrintf(kSbDiagnosticHtml,
196 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_DIAGNOSTIC_PAGE).c_str());
197
198 strings->SetString(L"badURL", UTF8ToWide(url().host()));
199 // Check to see if we're blocking the main page, or a sub-resource on the
200 // main page.
201 std::wstring description1, description2;
202 if (is_main_frame_) {
203 description1 = l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION1,
204 UTF8ToWide(url().host()));
205 description2 = l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION2,
206 link,
207 UTF8ToWide(url().host()));
208 } else {
209 description1 = l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION4,
210 UTF8ToWide(tab()->GetURL().host()),
211 UTF8ToWide(url().host()));
212 description2 = l10n_util::GetStringF(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION5,
213 link,
214 UTF8ToWide(url().host()));
215 }
216
217 PopulateStringDictionary(
218 strings,
219 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_TITLE),
220 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_HEADLINE),
221 description1, description2,
222 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION3));
223
224 strings->SetString(L"confirm_text",
225 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_DESCRIPTION_AGREE));
226 strings->SetString(L"continue_button",
227 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_PROCEED_BUTTON));
228 strings->SetString(L"back_button",
229 l10n_util::GetString(IDS_SAFE_BROWSING_MALWARE_BACK_BUTTON));
230 strings->SetString(L"textdirection",
231 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
232 L"rtl" : L"ltr");
233 }
234
235 void SafeBrowsingBlockingPage::PopulatePhishingStringDictionary(
236 DictionaryValue* strings) {
237 PopulateStringDictionary(
238 strings,
239 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_TITLE),
240 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_HEADLINE),
241 l10n_util::GetStringF(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION1,
242 UTF8ToWide(url().host())),
243 l10n_util::GetStringF(IDS_SAFE_BROWSING_PHISHING_DESCRIPTION2,
244 UTF8ToWide(url().host())),
245 L"");
246
247 strings->SetString(L"continue_button",
248 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_PROCEED_BUTTON));
249 strings->SetString(L"back_button",
250 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_BACK_BUTTON));
251 strings->SetString(L"report_error",
252 l10n_util::GetString(IDS_SAFE_BROWSING_PHISHING_REPORT_ERROR));
253 strings->SetString(L"textdirection",
254 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
255 L"rtl" : L"ltr");
256 }
257
258 void SafeBrowsingBlockingPage::CommandReceived(const std::string& cmd) {
259 std::string command(cmd); // Make a local copy so we can modify it.
260 // The Jasonified response has quotes, remove them.
261 if (command.length() > 1 && command[0] == '"') {
262 command = command.substr(1, command.length() - 2);
263 }
264
265 if (command == kLearnMoreCommand) {
148 // User pressed "Learn more". 266 // User pressed "Learn more".
149 GURL url; 267 GURL url;
150 if (result_ == SafeBrowsingService::URL_MALWARE) { 268 if (unsafe_resources_[0].threat_type == SafeBrowsingService::URL_MALWARE) {
151 url = GURL(l10n_util::GetString(IDS_LEARN_MORE_MALWARE_URL)); 269 url = GURL(l10n_util::GetString(IDS_LEARN_MORE_MALWARE_URL));
152 } else if (result_ == SafeBrowsingService::URL_PHISHING) { 270 } else if (unsafe_resources_[0].threat_type ==
271 SafeBrowsingService::URL_PHISHING) {
153 url = GURL(l10n_util::GetString(IDS_LEARN_MORE_PHISHING_URL)); 272 url = GURL(l10n_util::GetString(IDS_LEARN_MORE_PHISHING_URL));
154 } else { 273 } else {
155 NOTREACHED(); 274 NOTREACHED();
156 } 275 }
157 tab()->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::LINK); 276 tab()->OpenURL(url, GURL(), CURRENT_TAB, PageTransition::LINK);
158 return; 277 return;
159 } 278 }
160 if (command == "3") { 279
280 if (command == kProceedCommand) {
281 Proceed();
282 // We are deleted after this.
283 return;
284 }
285
286 if (command == kTakeMeBackCommand) {
287 DontProceed();
288 // We are deleted after this.
289 return;
290 }
291
292 // The "report error" and "show diagnostic" commands can have a number
293 // appended to them, which is the index of the element they apply to.
294 int element_index = 0;
295 size_t colon_index = command.find(':');
296 if (colon_index != std::string::npos) {
297 DCHECK(colon_index < command.size() - 1);
298 std::string index_str = command.substr(colon_index + 1);
299 command = command.substr(0, colon_index);
300 bool result = StringToInt(index_str, &element_index);
301 DCHECK(result);
302 }
303
304 if (element_index >= static_cast<int>(unsafe_resources_.size())) {
305 NOTREACHED();
306 return;
307 }
308
309 std::string bad_url_spec = unsafe_resources_[element_index].url.spec();
310 if (command == kReportErrorCommand) {
161 // User pressed "Report error" for a phishing site. 311 // User pressed "Report error" for a phishing site.
162 // Note that we cannot just put a link in the interstitial at this point. 312 // Note that we cannot just put a link in the interstitial at this point.
163 // It is not OK to navigate in the context of an interstitial page. 313 // It is not OK to navigate in the context of an interstitial page.
164 DCHECK(result_ == SafeBrowsingService::URL_PHISHING); 314 DCHECK(unsafe_resources_[element_index].threat_type ==
315 SafeBrowsingService::URL_PHISHING);
165 GURL report_url = 316 GURL report_url =
166 safe_browsing_util::GeneratePhishingReportUrl(kSbReportPhishingUrl, 317 safe_browsing_util::GeneratePhishingReportUrl(kSbReportPhishingUrl,
167 url().spec()); 318 bad_url_spec);
168 Hide();
169 tab()->OpenURL(report_url, GURL(), CURRENT_TAB, PageTransition::LINK); 319 tab()->OpenURL(report_url, GURL(), CURRENT_TAB, PageTransition::LINK);
170 return; 320 return;
171 } 321 }
172 if (command == "4") { 322
323 if (command == kShowDiagnosticCommand) {
173 // We're going to take the user to Google's SafeBrowsing diagnostic page. 324 // We're going to take the user to Google's SafeBrowsing diagnostic page.
174 std::string diagnostic = 325 std::string diagnostic =
175 StringPrintf(kSbDiagnosticUrl, 326 StringPrintf(kSbDiagnosticUrl,
176 EscapeQueryParamValue(url().spec()).c_str()); 327 EscapeQueryParamValue(bad_url_spec).c_str());
177 GURL diagnostic_url(diagnostic); 328 GURL diagnostic_url(diagnostic);
178 diagnostic_url = google_util::AppendGoogleLocaleParam(diagnostic_url); 329 diagnostic_url = google_util::AppendGoogleLocaleParam(diagnostic_url);
179 DCHECK(result_ == SafeBrowsingService::URL_MALWARE); 330 DCHECK(unsafe_resources_[element_index].threat_type ==
331 SafeBrowsingService::URL_MALWARE);
180 tab()->OpenURL(diagnostic_url, GURL(), CURRENT_TAB, PageTransition::LINK); 332 tab()->OpenURL(diagnostic_url, GURL(), CURRENT_TAB, PageTransition::LINK);
181 return; 333 return;
182 } 334 }
183 335
184 proceed_ = command == "1"; 336 NOTREACHED() << "Unexpected command: " << command;
337 }
185 338
186 if (proceed_) 339 void SafeBrowsingBlockingPage::Proceed() {
187 Proceed(); 340 NotifySafeBrowsingService(sb_service_, unsafe_resources_, true);
188 else
189 DontProceed();
190 341
191 NotifyDone(); 342 // Check to see if some new notifications of unsafe resources have been
343 // received while we were showing the interstitial.
344 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
345 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab());
346 SafeBrowsingBlockingPage* blocking_page = NULL;
347 if (iter != unsafe_resource_map->end() && !iter->second.empty()) {
348 // Build an interstitial for all the unsafe resources notifications.
349 // Don't show it now as showing an interstitial while an interstitial is
350 // already showing would cause DontProceed() to be invoked.
351 blocking_page = new SafeBrowsingBlockingPage(sb_service_, tab(),
352 iter->second);
353 unsafe_resource_map->erase(iter);
354 }
355
356 InterstitialPage::Proceed();
357 // We are now deleted.
358
359 // Now that this interstitial is gone, we can show the new one.
360 if (blocking_page)
361 blocking_page->Show();
192 } 362 }
193 363
194 void SafeBrowsingBlockingPage::DontProceed() { 364 void SafeBrowsingBlockingPage::DontProceed() {
195 if (navigation_entry_index_to_remove_ != -1) { 365 NotifySafeBrowsingService(sb_service_, unsafe_resources_, false);
366
367 // The user does not want to proceed, clear the queued unsafe resources
368 // notifications we received while the interstitial was showing.
369 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
370 UnsafeResourceMap::iterator iter = unsafe_resource_map->find(tab());
371 if (iter != unsafe_resource_map->end() && !iter->second.empty()) {
372 NotifySafeBrowsingService(sb_service_, iter->second, false);
373 unsafe_resource_map->erase(iter);
374 }
375
376 // We don't remove the navigation entry if the tab is being destroyed as this
377 // would trigger a navigation that would cause trouble as the render view host
378 // for the tab has by then already been destroyed.
379 if (navigation_entry_index_to_remove_ != -1 && !tab()->is_being_destroyed()) {
196 tab()->controller()->RemoveEntryAtIndex(navigation_entry_index_to_remove_, 380 tab()->controller()->RemoveEntryAtIndex(navigation_entry_index_to_remove_,
197 NewTabUIURL()); 381 NewTabUIURL());
382 navigation_entry_index_to_remove_ = -1;
198 } 383 }
199 InterstitialPage::DontProceed(); 384 InterstitialPage::DontProceed();
200 // We are now deleted. 385 // We are now deleted.
201 } 386 }
202 387
203 void SafeBrowsingBlockingPage::NotifyDone() { 388 // static
204 if (did_notify_) 389 void SafeBrowsingBlockingPage::NotifySafeBrowsingService(
205 return; 390 SafeBrowsingService* sb_service,
206 391 const UnsafeResourceList& unsafe_resources,
207 did_notify_ = true; 392 bool proceed) {
208
209 base::Thread* io_thread = g_browser_process->io_thread(); 393 base::Thread* io_thread = g_browser_process->io_thread();
210 if (!io_thread) 394 if (!io_thread)
211 return; 395 return;
212 396
213 SafeBrowsingService::BlockingPageParam param;
214 param.url = url();
215 param.result = result_;
216 param.client = client_;
217 param.render_process_host_id = render_process_host_id_;
218 param.render_view_id = render_view_id_;
219 param.proceed = proceed_;
220 io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( 397 io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
221 sb_service_, 398 sb_service, &SafeBrowsingService::OnBlockingPageDone, unsafe_resources,
222 &SafeBrowsingService::OnBlockingPageDone, 399 proceed));
223 param));
224 } 400 }
401
402 // static
403 SafeBrowsingBlockingPage::UnsafeResourceMap*
404 SafeBrowsingBlockingPage::GetUnsafeResourcesMap() {
405 return Singleton<UnsafeResourceMap>::get();
406 }
407
408 // static
409 void SafeBrowsingBlockingPage::ShowBlockingPage(
410 SafeBrowsingService* sb_service,
411 const SafeBrowsingService::UnsafeResource& unsafe_resource) {
412 WebContents* web_contents = tab_util::GetWebContentsByID(
413 unsafe_resource.render_process_host_id, unsafe_resource.render_view_id);
414
415 if (!InterstitialPage::GetInterstitialPage(web_contents)) {
416 // There are no interstitial currently showing in that tab, go ahead and
417 // show this interstitial.
418 std::vector<SafeBrowsingService::UnsafeResource> resources;
419 resources.push_back(unsafe_resource);
420 SafeBrowsingBlockingPage* blocking_page =
421 new SafeBrowsingBlockingPage(sb_service, web_contents, resources);
422 blocking_page->Show();
423 return;
424 }
425
426 // Let's queue the interstitial.
427 // Note we only expect resources from the page at this point.
428 DCHECK(unsafe_resource.resource_type != ResourceType::MAIN_FRAME);
429 UnsafeResourceMap* unsafe_resource_map = GetUnsafeResourcesMap();
430 (*unsafe_resource_map)[web_contents].push_back(unsafe_resource);
431 }
432
433 // static
434 bool SafeBrowsingBlockingPage::IsMainPage(
435 const UnsafeResourceList& unsafe_resources) {
436 return unsafe_resources.size() == 1 &&
437 unsafe_resources[0].resource_type == ResourceType::MAIN_FRAME;
438 }
439
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_blocking_page.h ('k') | chrome/browser/safe_browsing/safe_browsing_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698