OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ssl/captive_portal_blocking_page.h" |
| 6 |
| 7 #include "base/metrics/histogram.h" |
| 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/values.h" |
| 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "content/public/browser/web_contents.h" |
| 12 #include "grit/generated_resources.h" |
| 13 #include "ui/base/l10n/l10n_util.h" |
| 14 |
| 15 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 16 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
| 17 #endif |
| 18 |
| 19 namespace { |
| 20 |
| 21 // Events for UMA. |
| 22 enum CaptivePortalBlockingPageEvent { |
| 23 SHOW_ALL, |
| 24 OPEN_LOGIN_PAGE, |
| 25 CAPTIVE_PORTAL_BLOCKING_PAGE_EVENT_COUNT |
| 26 }; |
| 27 |
| 28 void RecordUMA(CaptivePortalBlockingPageEvent event) { |
| 29 UMA_HISTOGRAM_ENUMERATION("interstitial.captive_portal", |
| 30 event, |
| 31 CAPTIVE_PORTAL_BLOCKING_PAGE_EVENT_COUNT); |
| 32 } |
| 33 |
| 34 const char kOpenLoginPageCommand[] = "openLoginPage"; |
| 35 |
| 36 } // namespace |
| 37 |
| 38 // static |
| 39 const void* CaptivePortalBlockingPage::kTypeForTesting = |
| 40 &CaptivePortalBlockingPage::kTypeForTesting; |
| 41 |
| 42 CaptivePortalBlockingPage::CaptivePortalBlockingPage( |
| 43 content::WebContents* web_contents, |
| 44 const GURL& request_url, |
| 45 const base::Callback<void(bool)>& callback) |
| 46 : SecurityInterstitialPage(web_contents, request_url), |
| 47 callback_(callback) { |
| 48 #if !defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 49 NOTREACHED(); |
| 50 #endif |
| 51 RecordUMA(SHOW_ALL); |
| 52 } |
| 53 |
| 54 CaptivePortalBlockingPage::~CaptivePortalBlockingPage() { |
| 55 // Need to explicity deny the certificate via the callback, otherwise memory |
| 56 // is leaked. |
| 57 if (!callback_.is_null()) { |
| 58 callback_.Run(false); |
| 59 callback_.Reset(); |
| 60 } |
| 61 } |
| 62 |
| 63 const void* CaptivePortalBlockingPage::GetTypeForTesting() const { |
| 64 return CaptivePortalBlockingPage::kTypeForTesting; |
| 65 } |
| 66 |
| 67 bool CaptivePortalBlockingPage::ShouldCreateNewNavigation() const { |
| 68 return true; |
| 69 } |
| 70 |
| 71 void CaptivePortalBlockingPage::PopulateInterstitialStrings( |
| 72 base::DictionaryValue* load_time_data) { |
| 73 load_time_data->SetString("iconClass", "icon-offline"); |
| 74 load_time_data->SetString("type", "CAPTIVE_PORTAL"); |
| 75 load_time_data->SetBoolean("overridable", false); |
| 76 |
| 77 load_time_data->SetString( |
| 78 "primaryButtonText", |
| 79 l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_BUTTON_OPEN_LOGIN_PAGE)); |
| 80 load_time_data->SetString("tabTitle", |
| 81 l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_TITLE)); |
| 82 load_time_data->SetString( |
| 83 "primaryParagraph", |
| 84 l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH)); |
| 85 load_time_data->SetString("heading", |
| 86 l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_HEADING)); |
| 87 |
| 88 // Fill the empty strings to avoid getting debug warnings. |
| 89 load_time_data->SetString("openDetails", base::string16()); |
| 90 load_time_data->SetString("closeDetails", base::string16()); |
| 91 load_time_data->SetString("explanationParagraph", base::string16()); |
| 92 load_time_data->SetString("finalParagraph", base::string16()); |
| 93 } |
| 94 |
| 95 void CaptivePortalBlockingPage::CommandReceived(const std::string& command) { |
| 96 // The response has quotes around it. |
| 97 if (command == std::string("\"") + kOpenLoginPageCommand + "\"") { |
| 98 RecordUMA(OPEN_LOGIN_PAGE); |
| 99 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 100 CaptivePortalTabHelper::OpenLoginTabForWebContents(web_contents(), true); |
| 101 #endif |
| 102 } |
| 103 } |
OLD | NEW |