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/command_line.h" | |
12 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
13 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
14 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
15 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
16 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
19 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
22 #include "base/values.h" | 23 #include "base/values.h" |
23 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
24 #include "chrome/browser/google/google_util.h" | 25 #include "chrome/browser/google/google_util.h" |
25 #include "chrome/browser/history/history_service_factory.h" | 26 #include "chrome/browser/history/history_service_factory.h" |
26 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/renderer_preferences_util.h" | 28 #include "chrome/browser/renderer_preferences_util.h" |
28 #include "chrome/browser/safe_browsing/malware_details.h" | 29 #include "chrome/browser/safe_browsing/malware_details.h" |
29 #include "chrome/browser/safe_browsing/ui_manager.h" | 30 #include "chrome/browser/safe_browsing/ui_manager.h" |
30 #include "chrome/browser/tab_contents/tab_util.h" | 31 #include "chrome/browser/tab_contents/tab_util.h" |
32 #include "chrome/common/chrome_switches.h" | |
31 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
32 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
33 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
34 #include "content/public/browser/interstitial_page.h" | 36 #include "content/public/browser/interstitial_page.h" |
35 #include "content/public/browser/navigation_controller.h" | 37 #include "content/public/browser/navigation_controller.h" |
36 #include "content/public/browser/user_metrics.h" | 38 #include "content/public/browser/user_metrics.h" |
37 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
38 #include "grit/browser_resources.h" | 40 #include "grit/browser_resources.h" |
39 #include "grit/chromium_strings.h" | 41 #include "grit/chromium_strings.h" |
40 #include "grit/generated_resources.h" | 42 #include "grit/generated_resources.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 PHISHING_PROCEED_CROSS_SITE, | 141 PHISHING_PROCEED_CROSS_SITE, |
140 MAX_DETAILED_ACTION | 142 MAX_DETAILED_ACTION |
141 }; | 143 }; |
142 | 144 |
143 void RecordDetailedUserAction(DetailedDecision decision) { | 145 void RecordDetailedUserAction(DetailedDecision decision) { |
144 UMA_HISTOGRAM_ENUMERATION("SB2.InterstitialActionDetails", | 146 UMA_HISTOGRAM_ENUMERATION("SB2.InterstitialActionDetails", |
145 decision, | 147 decision, |
146 MAX_DETAILED_ACTION); | 148 MAX_DETAILED_ACTION); |
147 } | 149 } |
148 | 150 |
151 bool Version3Enabled() { | |
152 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
153 switches::kMalwareInterstitialVersionV3) || | |
154 base::FieldTrialList::FindFullName("MalwareInterstitialVersion") | |
155 == "V3") { | |
156 return true; | |
Bernhard Bauer
2014/06/09 10:04:03
You could split these individual conditions up and
felt
2014/06/09 14:24:09
Done.
| |
157 } | |
158 return false; | |
159 } | |
160 | |
149 } // namespace | 161 } // namespace |
150 | 162 |
151 // static | 163 // static |
152 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; | 164 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; |
153 | 165 |
154 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we | 166 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we |
155 // don't leak it. | 167 // don't leak it. |
156 class SafeBrowsingBlockingPageFactoryImpl | 168 class SafeBrowsingBlockingPageFactoryImpl |
157 : public SafeBrowsingBlockingPageFactory { | 169 : public SafeBrowsingBlockingPageFactory { |
158 public: | 170 public: |
159 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 171 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
160 SafeBrowsingUIManager* ui_manager, | 172 SafeBrowsingUIManager* ui_manager, |
161 WebContents* web_contents, | 173 WebContents* web_contents, |
162 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) | 174 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) |
163 OVERRIDE { | 175 OVERRIDE { |
164 // Only use the V2 page if the interstitial is for a single malware or | 176 // Only use the V2 page if the interstitial is for a single malware or |
165 // phishing resource, the multi-threat interstitial has not been updated to | 177 // phishing resource, the multi-threat interstitial has not been updated to |
166 // V2 yet. | 178 // V2 yet. |
167 if (unsafe_resources.size() == 1 && | 179 if (unsafe_resources.size() == 1 && |
168 (unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE || | 180 (unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE || |
169 unsafe_resources[0].threat_type == | 181 unsafe_resources[0].threat_type == |
170 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL || | 182 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL || |
171 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_PHISHING || | 183 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_PHISHING || |
172 unsafe_resources[0].threat_type == | 184 unsafe_resources[0].threat_type == |
173 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL)) { | 185 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL)) { |
174 return new SafeBrowsingBlockingPageV2(ui_manager, web_contents, | 186 if (Version3Enabled()) { |
175 unsafe_resources); | 187 return new SafeBrowsingBlockingPageV3(ui_manager, web_contents, |
188 unsafe_resources); | |
189 } else { | |
190 return new SafeBrowsingBlockingPageV2(ui_manager, web_contents, | |
191 unsafe_resources); | |
192 } | |
176 } | 193 } |
177 return new SafeBrowsingBlockingPageV1(ui_manager, web_contents, | 194 return new SafeBrowsingBlockingPageV1(ui_manager, web_contents, |
178 unsafe_resources); | 195 unsafe_resources); |
179 } | 196 } |
180 | 197 |
181 private: | 198 private: |
182 friend struct base::DefaultLazyInstanceTraits< | 199 friend struct base::DefaultLazyInstanceTraits< |
183 SafeBrowsingBlockingPageFactoryImpl>; | 200 SafeBrowsingBlockingPageFactoryImpl>; |
184 | 201 |
185 SafeBrowsingBlockingPageFactoryImpl() { } | 202 SafeBrowsingBlockingPageFactoryImpl() { } |
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1185 strings->SetString("details", std::string()); | 1202 strings->SetString("details", std::string()); |
1186 strings->SetString("confirm_text", std::string()); | 1203 strings->SetString("confirm_text", std::string()); |
1187 strings->SetString(kBoxChecked, std::string()); | 1204 strings->SetString(kBoxChecked, std::string()); |
1188 strings->SetString( | 1205 strings->SetString( |
1189 "report_error", | 1206 "report_error", |
1190 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_REPORT_ERROR)); | 1207 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_REPORT_ERROR)); |
1191 strings->SetBoolean(kDisplayCheckBox, false); | 1208 strings->SetBoolean(kDisplayCheckBox, false); |
1192 strings->SetString("learnMore", | 1209 strings->SetString("learnMore", |
1193 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_LEARN_MORE)); | 1210 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_LEARN_MORE)); |
1194 } | 1211 } |
1212 | |
1213 SafeBrowsingBlockingPageV3::SafeBrowsingBlockingPageV3( | |
1214 SafeBrowsingUIManager* ui_manager, | |
1215 WebContents* web_contents, | |
1216 const UnsafeResourceList& unsafe_resources) | |
1217 : SafeBrowsingBlockingPage(ui_manager, web_contents, unsafe_resources) { | |
Bernhard Bauer
2014/06/09 10:04:03
Indent two more spaces.
felt
2014/06/09 14:24:09
Done.
| |
1218 } | |
1219 | |
1220 std::string SafeBrowsingBlockingPageV3::GetHTMLContents() { | |
1221 if (unsafe_resources_.empty() || unsafe_resources_.size() > 1) { | |
1222 // TODO(felt): Implement new multi-threat interstitial. crbug.com/160336 | |
1223 NOTREACHED(); | |
Bernhard Bauer
2014/06/09 10:04:03
When is this branch reached? If you want to expres
felt
2014/06/09 14:24:09
That can happen if a page is marked as both malwar
Bernhard Bauer
2014/06/09 14:45:41
OK... the usual way would be to DCHECK this instea
| |
1224 return std::string(); | |
1225 } | |
1226 | |
1227 // Fill in the shared values. | |
1228 base::DictionaryValue load_time_data; | |
1229 bool rtl = base::i18n::IsRTL(); | |
1230 load_time_data.SetString("textDirection", rtl ? "rtl" : "ltr"); | |
Bernhard Bauer
2014/06/09 10:04:03
Doesn't SetFontAndTextDirection already set this?
felt
2014/06/09 14:24:09
Done.
| |
1231 webui::SetFontAndTextDirection(&load_time_data); | |
1232 load_time_data.SetBoolean("ssl", false); | |
1233 load_time_data.SetString( | |
1234 "openDetails", | |
1235 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_SEE_MORE)); | |
1236 load_time_data.SetString( | |
1237 "closeDetails", | |
1238 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_SEE_MORE)); | |
1239 load_time_data.SetString( | |
1240 "primaryButtonText", | |
1241 l10n_util::GetStringUTF16(IDS_SSL_OVERRIDABLE_SAFETY_BUTTON)); | |
1242 load_time_data.SetString( | |
1243 "proceedText", | |
1244 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_PROCEED_LINK)); | |
1245 load_time_data.SetBoolean( | |
1246 "overridable", | |
1247 !IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)); | |
1248 | |
1249 // Fill in the values that are specific to malware or phishing. | |
1250 SBThreatType threat_type = unsafe_resources_[0].threat_type; | |
1251 if (threat_type == SB_THREAT_TYPE_URL_MALWARE || | |
1252 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL) { | |
1253 PopulateMalwareLoadTimeData(&load_time_data); | |
1254 } else { // Phishing. | |
1255 DCHECK(threat_type == SB_THREAT_TYPE_URL_PHISHING || | |
1256 threat_type == SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL); | |
Bernhard Bauer
2014/06/09 10:04:03
How many threat types are there? Could you replace
felt
2014/06/09 14:24:09
Done.
| |
1257 PopulatePhishingLoadTimeData(&load_time_data); | |
1258 } | |
1259 | |
1260 interstitial_show_time_ = base::TimeTicks::Now(); | |
1261 | |
1262 base::StringPiece html( | |
1263 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
1264 IRD_SSL_INTERSTITIAL_V2_HTML)); | |
1265 webui::UseVersion2 version; | |
1266 return webui::GetI18nTemplateHtml(html, &load_time_data); | |
1267 } | |
1268 | |
1269 void SafeBrowsingBlockingPageV3::PopulateMalwareLoadTimeData( | |
1270 base::DictionaryValue* load_time_data) { | |
1271 load_time_data->SetBoolean("phishing", false); | |
1272 load_time_data->SetString( | |
1273 "tabTitle", | |
1274 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_TITLE)); | |
1275 load_time_data->SetString( | |
1276 "heading", | |
1277 l10n_util::GetStringUTF16(is_main_frame_load_blocked_ ? | |
1278 IDS_SAFE_BROWSING_MALWARE_V2_HEADLINE : | |
1279 IDS_SAFE_BROWSING_MALWARE_V2_HEADLINE_SUBRESOURCE)); | |
1280 load_time_data->SetString( | |
1281 "primaryParagraph", | |
1282 l10n_util::GetStringFUTF16( | |
1283 is_main_frame_load_blocked_ ? | |
1284 IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION1 : | |
1285 IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION1_SUBRESOURCE, | |
1286 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), | |
1287 base::UTF8ToUTF16(is_main_frame_load_blocked_ ? | |
1288 url_.host() : web_contents_->GetURL().host()))); | |
1289 load_time_data->SetString( | |
1290 "secondParagraph", | |
1291 is_main_frame_load_blocked_ ? | |
1292 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION2) : | |
1293 l10n_util::GetStringFUTF16( | |
1294 IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION2_SUBRESOURCE, | |
1295 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), | |
1296 base::UTF8ToUTF16(url_.host()))); | |
1297 load_time_data->SetString( | |
1298 "thirdParagraph", | |
1299 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION3)); | |
1300 load_time_data->SetString( | |
1301 "detailsText", | |
1302 is_main_frame_load_blocked_ ? | |
1303 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_DETAILS) : | |
1304 l10n_util::GetStringFUTF16( | |
1305 IDS_SAFE_BROWSING_MALWARE_V2_DETAILS_SUBRESOURCE, | |
1306 base::UTF8ToUTF16(url_.host()))); | |
1307 } | |
1308 | |
1309 void SafeBrowsingBlockingPageV3::PopulatePhishingLoadTimeData( | |
1310 base::DictionaryValue* load_time_data) { | |
1311 load_time_data->SetBoolean("phishing", true); | |
1312 load_time_data->SetString( | |
1313 "tabTitle", | |
1314 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_TITLE)); | |
1315 load_time_data->SetString( | |
1316 "heading", | |
1317 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_HEADLINE)); | |
1318 load_time_data->SetString( | |
1319 "primaryParagraph", | |
1320 l10n_util::GetStringFUTF16( | |
1321 IDS_SAFE_BROWSING_PHISHING_V2_DESCRIPTION1, | |
1322 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), | |
1323 base::UTF8ToUTF16(url_.host()))); | |
1324 load_time_data->SetString( | |
1325 "secondParagraph", | |
1326 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION2)); | |
1327 load_time_data->SetString( | |
1328 "detailsText", | |
1329 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_REPORT_ERROR)); | |
1330 } | |
OLD | NEW |