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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 "<a id=\"privacy-link\" href=\"\" onclick=\"sendCommand('showPrivacy'); " | 88 "<a id=\"privacy-link\" href=\"\" onclick=\"sendCommand('showPrivacy'); " |
87 "return false;\" onmousedown=\"return false;\">%s</a>"; | 89 "return false;\" onmousedown=\"return false;\">%s</a>"; |
88 | 90 |
89 // After a malware interstitial where the user opted-in to the report | 91 // After a malware interstitial where the user opted-in to the report |
90 // but clicked "proceed anyway", we delay the call to | 92 // but clicked "proceed anyway", we delay the call to |
91 // MalwareDetails::FinishCollection() by this much time (in | 93 // MalwareDetails::FinishCollection() by this much time (in |
92 // milliseconds). | 94 // milliseconds). |
93 const int64 kMalwareDetailsProceedDelayMilliSeconds = 3000; | 95 const int64 kMalwareDetailsProceedDelayMilliSeconds = 3000; |
94 | 96 |
95 // The commands returned by the page when the user performs an action. | 97 // The commands returned by the page when the user performs an action. |
96 const char kShowDiagnosticCommand[] = "showDiagnostic"; | 98 const char kBoxChecked[] = "boxchecked"; |
97 const char kReportErrorCommand[] = "reportError"; | |
98 const char kLearnMoreCommand[] = "learnMore"; | |
99 const char kLearnMoreCommandV2[] = "learnMore2"; | |
100 const char kShowPrivacyCommand[] = "showPrivacy"; | |
101 const char kProceedCommand[] = "proceed"; | |
102 const char kTakeMeBackCommand[] = "takeMeBack"; | |
103 const char kDoReportCommand[] = "doReport"; | 99 const char kDoReportCommand[] = "doReport"; |
104 const char kDontReportCommand[] = "dontReport"; | 100 const char kDontReportCommand[] = "dontReport"; |
105 const char kDisplayCheckBox[] = "displaycheckbox"; | 101 const char kDisplayCheckBox[] = "displaycheckbox"; |
106 const char kBoxChecked[] = "boxchecked"; | |
107 const char kExpandedSeeMore[] = "expandedSeeMore"; | 102 const char kExpandedSeeMore[] = "expandedSeeMore"; |
103 const char kLearnMoreCommand[] = "learnMore"; | |
104 const char kLearnMoreCommandV2[] = "learnMore2"; | |
105 const char kProceedCommand[] = "proceed"; | |
106 const char kReportErrorCommand[] = "reportError"; | |
107 const char kShowDiagnosticCommand[] = "showDiagnostic"; | |
108 const char kShowPrivacyCommand[] = "showPrivacy"; | |
109 const char kTakeMeBackCommand[] = "takeMeBack"; | |
108 // Special command that we use when the user navigated away from the | 110 // Special command that we use when the user navigated away from the |
109 // page. E.g., closed the tab or the window. This is only used by | 111 // page. E.g., closed the tab or the window. This is only used by |
110 // RecordUserReactionTime. | 112 // RecordUserReactionTime. |
111 const char kNavigatedAwayMetaCommand[] = "closed"; | 113 const char kNavigatedAwayMetaCommand[] = "closed"; |
112 | 114 |
113 base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap> | 115 base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap> |
114 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; | 116 g_unsafe_resource_map = LAZY_INSTANCE_INITIALIZER; |
115 | 117 |
116 // These are the conditions for the summer 2013 Finch experiment. | 118 // These are the conditions for the summer 2013 Finch experiment. |
117 // TODO(felt): Get rid of these now that experiment has ended. | 119 // TODO(felt): Get rid of these now that experiment has ended. |
(...skipping 21 matching lines...) Expand all 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 return true; | |
155 } else if (base::FieldTrialList::FindFullName("MalwareInterstitialVersion") | |
Bernhard Bauer
2014/06/09 14:45:42
Nit: else isn't necessary if you return in the if
felt
2014/06/09 15:24:02
Done.
| |
156 == "V3") { | |
157 return true; | |
158 } | |
159 return false; | |
160 } | |
161 | |
149 } // namespace | 162 } // namespace |
150 | 163 |
151 // static | 164 // static |
152 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; | 165 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; |
153 | 166 |
154 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we | 167 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we |
155 // don't leak it. | 168 // don't leak it. |
156 class SafeBrowsingBlockingPageFactoryImpl | 169 class SafeBrowsingBlockingPageFactoryImpl |
157 : public SafeBrowsingBlockingPageFactory { | 170 : public SafeBrowsingBlockingPageFactory { |
158 public: | 171 public: |
159 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 172 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
160 SafeBrowsingUIManager* ui_manager, | 173 SafeBrowsingUIManager* ui_manager, |
161 WebContents* web_contents, | 174 WebContents* web_contents, |
162 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) | 175 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) |
163 OVERRIDE { | 176 OVERRIDE { |
164 // Only use the V2 page if the interstitial is for a single malware or | 177 // 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 | 178 // phishing resource, the multi-threat interstitial has not been updated to |
166 // V2 yet. | 179 // V2 yet. |
167 if (unsafe_resources.size() == 1 && | 180 if (unsafe_resources.size() == 1 && |
168 (unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE || | 181 (unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE || |
169 unsafe_resources[0].threat_type == | 182 unsafe_resources[0].threat_type == |
170 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL || | 183 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL || |
171 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_PHISHING || | 184 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_PHISHING || |
172 unsafe_resources[0].threat_type == | 185 unsafe_resources[0].threat_type == |
173 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL)) { | 186 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL)) { |
174 return new SafeBrowsingBlockingPageV2(ui_manager, web_contents, | 187 if (Version3Enabled()) { |
175 unsafe_resources); | 188 return new SafeBrowsingBlockingPageV3(ui_manager, web_contents, |
189 unsafe_resources); | |
190 } else { | |
191 return new SafeBrowsingBlockingPageV2(ui_manager, web_contents, | |
192 unsafe_resources); | |
193 } | |
176 } | 194 } |
177 return new SafeBrowsingBlockingPageV1(ui_manager, web_contents, | 195 return new SafeBrowsingBlockingPageV1(ui_manager, web_contents, |
178 unsafe_resources); | 196 unsafe_resources); |
179 } | 197 } |
180 | 198 |
181 private: | 199 private: |
182 friend struct base::DefaultLazyInstanceTraits< | 200 friend struct base::DefaultLazyInstanceTraits< |
183 SafeBrowsingBlockingPageFactoryImpl>; | 201 SafeBrowsingBlockingPageFactoryImpl>; |
184 | 202 |
185 SafeBrowsingBlockingPageFactoryImpl() { } | 203 SafeBrowsingBlockingPageFactoryImpl() { } |
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1185 strings->SetString("details", std::string()); | 1203 strings->SetString("details", std::string()); |
1186 strings->SetString("confirm_text", std::string()); | 1204 strings->SetString("confirm_text", std::string()); |
1187 strings->SetString(kBoxChecked, std::string()); | 1205 strings->SetString(kBoxChecked, std::string()); |
1188 strings->SetString( | 1206 strings->SetString( |
1189 "report_error", | 1207 "report_error", |
1190 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_REPORT_ERROR)); | 1208 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_REPORT_ERROR)); |
1191 strings->SetBoolean(kDisplayCheckBox, false); | 1209 strings->SetBoolean(kDisplayCheckBox, false); |
1192 strings->SetString("learnMore", | 1210 strings->SetString("learnMore", |
1193 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_LEARN_MORE)); | 1211 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_LEARN_MORE)); |
1194 } | 1212 } |
1213 | |
1214 SafeBrowsingBlockingPageV3::SafeBrowsingBlockingPageV3( | |
1215 SafeBrowsingUIManager* ui_manager, | |
1216 WebContents* web_contents, | |
1217 const UnsafeResourceList& unsafe_resources) | |
1218 : SafeBrowsingBlockingPage(ui_manager, web_contents, unsafe_resources) { | |
1219 } | |
1220 | |
1221 std::string SafeBrowsingBlockingPageV3::GetHTMLContents() { | |
1222 if (unsafe_resources_.empty() || unsafe_resources_.size() > 1) { | |
1223 // TODO(felt): Implement new multi-threat interstitial. crbug.com/160336 | |
1224 NOTIMPLEMENTED(); | |
1225 return std::string(); | |
1226 } | |
1227 | |
1228 // Fill in the shared values. | |
1229 base::DictionaryValue load_time_data; | |
1230 bool rtl = base::i18n::IsRTL(); | |
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 switch (threat_type) { | |
1252 case SB_THREAT_TYPE_URL_MALWARE: | |
1253 case SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL: | |
1254 PopulateMalwareLoadTimeData(&load_time_data); | |
1255 break; | |
1256 case SB_THREAT_TYPE_URL_PHISHING: | |
1257 case SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL: | |
1258 PopulatePhishingLoadTimeData(&load_time_data); | |
1259 break; | |
1260 case SB_THREAT_TYPE_SAFE: | |
1261 case SB_THREAT_TYPE_BINARY_MALWARE_URL: | |
1262 case SB_THREAT_TYPE_EXTENSION: | |
1263 NOTREACHED(); | |
1264 } | |
1265 | |
1266 interstitial_show_time_ = base::TimeTicks::Now(); | |
1267 | |
1268 base::StringPiece html( | |
1269 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
1270 IRD_SSL_INTERSTITIAL_V2_HTML)); | |
1271 webui::UseVersion2 version; | |
1272 return webui::GetI18nTemplateHtml(html, &load_time_data); | |
1273 } | |
1274 | |
1275 void SafeBrowsingBlockingPageV3::PopulateMalwareLoadTimeData( | |
1276 base::DictionaryValue* load_time_data) { | |
1277 load_time_data->SetBoolean("phishing", false); | |
1278 load_time_data->SetString( | |
1279 "tabTitle", | |
1280 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_TITLE)); | |
1281 load_time_data->SetString( | |
1282 "heading", | |
1283 l10n_util::GetStringUTF16(is_main_frame_load_blocked_ ? | |
1284 IDS_SAFE_BROWSING_MALWARE_V2_HEADLINE : | |
1285 IDS_SAFE_BROWSING_MALWARE_V2_HEADLINE_SUBRESOURCE)); | |
1286 load_time_data->SetString( | |
1287 "primaryParagraph", | |
1288 l10n_util::GetStringFUTF16( | |
1289 is_main_frame_load_blocked_ ? | |
1290 IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION1 : | |
1291 IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION1_SUBRESOURCE, | |
1292 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), | |
1293 base::UTF8ToUTF16(is_main_frame_load_blocked_ ? | |
1294 url_.host() : web_contents_->GetURL().host()))); | |
1295 load_time_data->SetString( | |
1296 "secondParagraph", | |
1297 is_main_frame_load_blocked_ ? | |
1298 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION2) : | |
1299 l10n_util::GetStringFUTF16( | |
1300 IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION2_SUBRESOURCE, | |
1301 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), | |
1302 base::UTF8ToUTF16(url_.host()))); | |
1303 load_time_data->SetString( | |
1304 "thirdParagraph", | |
1305 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION3)); | |
1306 load_time_data->SetString( | |
1307 "detailsText", | |
1308 is_main_frame_load_blocked_ ? | |
1309 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_DETAILS) : | |
1310 l10n_util::GetStringFUTF16( | |
1311 IDS_SAFE_BROWSING_MALWARE_V2_DETAILS_SUBRESOURCE, | |
1312 base::UTF8ToUTF16(url_.host()))); | |
1313 } | |
1314 | |
1315 void SafeBrowsingBlockingPageV3::PopulatePhishingLoadTimeData( | |
1316 base::DictionaryValue* load_time_data) { | |
1317 load_time_data->SetBoolean("phishing", true); | |
1318 load_time_data->SetString( | |
1319 "tabTitle", | |
1320 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_TITLE)); | |
1321 load_time_data->SetString( | |
1322 "heading", | |
1323 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_HEADLINE)); | |
1324 load_time_data->SetString( | |
1325 "primaryParagraph", | |
1326 l10n_util::GetStringFUTF16( | |
1327 IDS_SAFE_BROWSING_PHISHING_V2_DESCRIPTION1, | |
1328 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), | |
1329 base::UTF8ToUTF16(url_.host()))); | |
1330 load_time_data->SetString( | |
1331 "secondParagraph", | |
1332 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION2)); | |
1333 load_time_data->SetString( | |
1334 "detailsText", | |
1335 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_REPORT_ERROR)); | |
1336 } | |
OLD | NEW |