| 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 } |
| 156 if (base::FieldTrialList::FindFullName("MalwareInterstitialVersion") |
| 157 == "V3") { |
| 158 return true; |
| 159 } |
| 160 return false; |
| 161 } |
| 162 |
| 163 class SafeBrowsingBlockingPageV3 : public SafeBrowsingBlockingPage { |
| 164 public: |
| 165 SafeBrowsingBlockingPageV3(SafeBrowsingUIManager* ui_manager, |
| 166 content::WebContents* web_contents, |
| 167 const UnsafeResourceList& unsafe_resources); |
| 168 |
| 169 // InterstitialPageDelegate method: |
| 170 virtual std::string GetHTMLContents() OVERRIDE; |
| 171 |
| 172 private: |
| 173 // Fills the passed dictionary with the values to be passed to the template |
| 174 // when creating the HTML. |
| 175 void PopulateMalwareLoadTimeData(base::DictionaryValue* load_time_data); |
| 176 void PopulatePhishingLoadTimeData(base::DictionaryValue* load_time_data); |
| 177 |
| 178 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingBlockingPageV3); |
| 179 }; |
| 180 |
| 149 } // namespace | 181 } // namespace |
| 150 | 182 |
| 151 // static | 183 // static |
| 152 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; | 184 SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; |
| 153 | 185 |
| 154 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we | 186 // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we |
| 155 // don't leak it. | 187 // don't leak it. |
| 156 class SafeBrowsingBlockingPageFactoryImpl | 188 class SafeBrowsingBlockingPageFactoryImpl |
| 157 : public SafeBrowsingBlockingPageFactory { | 189 : public SafeBrowsingBlockingPageFactory { |
| 158 public: | 190 public: |
| 159 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( | 191 virtual SafeBrowsingBlockingPage* CreateSafeBrowsingPage( |
| 160 SafeBrowsingUIManager* ui_manager, | 192 SafeBrowsingUIManager* ui_manager, |
| 161 WebContents* web_contents, | 193 WebContents* web_contents, |
| 162 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) | 194 const SafeBrowsingBlockingPage::UnsafeResourceList& unsafe_resources) |
| 163 OVERRIDE { | 195 OVERRIDE { |
| 164 // Only use the V2 page if the interstitial is for a single malware or | 196 // 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 | 197 // phishing resource, the multi-threat interstitial has not been updated to |
| 166 // V2 yet. | 198 // V2 yet. |
| 167 if (unsafe_resources.size() == 1 && | 199 if (unsafe_resources.size() == 1 && |
| 168 (unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE || | 200 (unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_MALWARE || |
| 169 unsafe_resources[0].threat_type == | 201 unsafe_resources[0].threat_type == |
| 170 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL || | 202 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL || |
| 171 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_PHISHING || | 203 unsafe_resources[0].threat_type == SB_THREAT_TYPE_URL_PHISHING || |
| 172 unsafe_resources[0].threat_type == | 204 unsafe_resources[0].threat_type == |
| 173 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL)) { | 205 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL)) { |
| 174 return new SafeBrowsingBlockingPageV2(ui_manager, web_contents, | 206 if (Version3Enabled()) { |
| 175 unsafe_resources); | 207 return new SafeBrowsingBlockingPageV3(ui_manager, web_contents, |
| 208 unsafe_resources); |
| 209 } else { |
| 210 return new SafeBrowsingBlockingPageV2(ui_manager, web_contents, |
| 211 unsafe_resources); |
| 212 } |
| 176 } | 213 } |
| 177 return new SafeBrowsingBlockingPageV1(ui_manager, web_contents, | 214 return new SafeBrowsingBlockingPageV1(ui_manager, web_contents, |
| 178 unsafe_resources); | 215 unsafe_resources); |
| 179 } | 216 } |
| 180 | 217 |
| 181 private: | 218 private: |
| 182 friend struct base::DefaultLazyInstanceTraits< | 219 friend struct base::DefaultLazyInstanceTraits< |
| 183 SafeBrowsingBlockingPageFactoryImpl>; | 220 SafeBrowsingBlockingPageFactoryImpl>; |
| 184 | 221 |
| 185 SafeBrowsingBlockingPageFactoryImpl() { } | 222 SafeBrowsingBlockingPageFactoryImpl() { } |
| (...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 strings->SetString("details", std::string()); | 1222 strings->SetString("details", std::string()); |
| 1186 strings->SetString("confirm_text", std::string()); | 1223 strings->SetString("confirm_text", std::string()); |
| 1187 strings->SetString(kBoxChecked, std::string()); | 1224 strings->SetString(kBoxChecked, std::string()); |
| 1188 strings->SetString( | 1225 strings->SetString( |
| 1189 "report_error", | 1226 "report_error", |
| 1190 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_REPORT_ERROR)); | 1227 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_REPORT_ERROR)); |
| 1191 strings->SetBoolean(kDisplayCheckBox, false); | 1228 strings->SetBoolean(kDisplayCheckBox, false); |
| 1192 strings->SetString("learnMore", | 1229 strings->SetString("learnMore", |
| 1193 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_LEARN_MORE)); | 1230 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_LEARN_MORE)); |
| 1194 } | 1231 } |
| 1232 |
| 1233 SafeBrowsingBlockingPageV3::SafeBrowsingBlockingPageV3( |
| 1234 SafeBrowsingUIManager* ui_manager, |
| 1235 WebContents* web_contents, |
| 1236 const UnsafeResourceList& unsafe_resources) |
| 1237 : SafeBrowsingBlockingPage(ui_manager, web_contents, unsafe_resources) { |
| 1238 } |
| 1239 |
| 1240 std::string SafeBrowsingBlockingPageV3::GetHTMLContents() { |
| 1241 if (unsafe_resources_.empty() || unsafe_resources_.size() > 1) { |
| 1242 // TODO(felt): Implement new multi-threat interstitial. crbug.com/160336 |
| 1243 NOTIMPLEMENTED(); |
| 1244 return std::string(); |
| 1245 } |
| 1246 |
| 1247 // Fill in the shared values. |
| 1248 base::DictionaryValue load_time_data; |
| 1249 webui::SetFontAndTextDirection(&load_time_data); |
| 1250 load_time_data.SetBoolean("ssl", false); |
| 1251 load_time_data.SetString( |
| 1252 "openDetails", |
| 1253 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_SEE_MORE)); |
| 1254 load_time_data.SetString( |
| 1255 "closeDetails", |
| 1256 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_SEE_MORE)); |
| 1257 load_time_data.SetString( |
| 1258 "primaryButtonText", |
| 1259 l10n_util::GetStringUTF16(IDS_SSL_OVERRIDABLE_SAFETY_BUTTON)); |
| 1260 load_time_data.SetString( |
| 1261 "proceedText", |
| 1262 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_PROCEED_LINK)); |
| 1263 load_time_data.SetBoolean( |
| 1264 "overridable", |
| 1265 !IsPrefEnabled(prefs::kSafeBrowsingProceedAnywayDisabled)); |
| 1266 |
| 1267 // Fill in the values that are specific to malware or phishing. |
| 1268 SBThreatType threat_type = unsafe_resources_[0].threat_type; |
| 1269 switch (threat_type) { |
| 1270 case SB_THREAT_TYPE_URL_MALWARE: |
| 1271 case SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL: |
| 1272 PopulateMalwareLoadTimeData(&load_time_data); |
| 1273 break; |
| 1274 case SB_THREAT_TYPE_URL_PHISHING: |
| 1275 case SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL: |
| 1276 PopulatePhishingLoadTimeData(&load_time_data); |
| 1277 break; |
| 1278 case SB_THREAT_TYPE_SAFE: |
| 1279 case SB_THREAT_TYPE_BINARY_MALWARE_URL: |
| 1280 case SB_THREAT_TYPE_EXTENSION: |
| 1281 NOTREACHED(); |
| 1282 } |
| 1283 |
| 1284 interstitial_show_time_ = base::TimeTicks::Now(); |
| 1285 |
| 1286 base::StringPiece html( |
| 1287 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 1288 IRD_SSL_INTERSTITIAL_V2_HTML)); |
| 1289 webui::UseVersion2 version; |
| 1290 return webui::GetI18nTemplateHtml(html, &load_time_data); |
| 1291 } |
| 1292 |
| 1293 void SafeBrowsingBlockingPageV3::PopulateMalwareLoadTimeData( |
| 1294 base::DictionaryValue* load_time_data) { |
| 1295 load_time_data->SetBoolean("phishing", false); |
| 1296 load_time_data->SetString( |
| 1297 "tabTitle", |
| 1298 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_TITLE)); |
| 1299 load_time_data->SetString( |
| 1300 "heading", |
| 1301 l10n_util::GetStringUTF16(is_main_frame_load_blocked_ ? |
| 1302 IDS_SAFE_BROWSING_MALWARE_V2_HEADLINE : |
| 1303 IDS_SAFE_BROWSING_MALWARE_V2_HEADLINE_SUBRESOURCE)); |
| 1304 load_time_data->SetString( |
| 1305 "primaryParagraph", |
| 1306 l10n_util::GetStringFUTF16( |
| 1307 is_main_frame_load_blocked_ ? |
| 1308 IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION1 : |
| 1309 IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION1_SUBRESOURCE, |
| 1310 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), |
| 1311 base::UTF8ToUTF16(is_main_frame_load_blocked_ ? |
| 1312 url_.host() : web_contents_->GetURL().host()))); |
| 1313 load_time_data->SetString( |
| 1314 "secondParagraph", |
| 1315 is_main_frame_load_blocked_ ? |
| 1316 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION2) : |
| 1317 l10n_util::GetStringFUTF16( |
| 1318 IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION2_SUBRESOURCE, |
| 1319 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), |
| 1320 base::UTF8ToUTF16(url_.host()))); |
| 1321 load_time_data->SetString( |
| 1322 "thirdParagraph", |
| 1323 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION3)); |
| 1324 load_time_data->SetString( |
| 1325 "detailsText", |
| 1326 is_main_frame_load_blocked_ ? |
| 1327 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_DETAILS) : |
| 1328 l10n_util::GetStringFUTF16( |
| 1329 IDS_SAFE_BROWSING_MALWARE_V2_DETAILS_SUBRESOURCE, |
| 1330 base::UTF8ToUTF16(url_.host()))); |
| 1331 } |
| 1332 |
| 1333 void SafeBrowsingBlockingPageV3::PopulatePhishingLoadTimeData( |
| 1334 base::DictionaryValue* load_time_data) { |
| 1335 load_time_data->SetBoolean("phishing", true); |
| 1336 load_time_data->SetString( |
| 1337 "tabTitle", |
| 1338 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_TITLE)); |
| 1339 load_time_data->SetString( |
| 1340 "heading", |
| 1341 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_HEADLINE)); |
| 1342 load_time_data->SetString( |
| 1343 "primaryParagraph", |
| 1344 l10n_util::GetStringFUTF16( |
| 1345 IDS_SAFE_BROWSING_PHISHING_V2_DESCRIPTION1, |
| 1346 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), |
| 1347 base::UTF8ToUTF16(url_.host()))); |
| 1348 load_time_data->SetString( |
| 1349 "secondParagraph", |
| 1350 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_MALWARE_V2_DESCRIPTION2)); |
| 1351 load_time_data->SetString( |
| 1352 "detailsText", |
| 1353 l10n_util::GetStringUTF16(IDS_SAFE_BROWSING_PHISHING_V2_REPORT_ERROR)); |
| 1354 } |
| OLD | NEW |