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

Side by Side Diff: chrome/browser/ssl/captive_portal_blocking_page.cc

Issue 318213002: Add custom interstitial for captive portals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix trybot errors (memory leak + unused code) Created 6 years 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
(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 + "\"") {
felt 2014/12/28 15:40:52 Why is one of these std::string("\"") and the othe
meacer 2015/01/08 14:29:16 The first one needs to be a string so that the exp
felt 2015/01/08 16:47:44 Ahhh, that makes sense, thanks!
98 RecordUMA(OPEN_LOGIN_PAGE);
99 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
100 CaptivePortalTabHelper::OpenLoginTabForWebContents(web_contents(), true);
101 #endif
102 }
103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698