OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 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/i18n/rtl.h" | |
8 #include "base/metrics/histogram.h" | |
9 #include "base/prefs/pref_service.h" | |
10 #include "base/values.h" | |
11 #include "chrome/browser/browser_process.h" | |
12 #include "chrome/browser/profiles/profile.h" | |
13 #include "chrome/common/localized_error.h" | |
14 #include "chrome/common/pref_names.h" | |
15 #include "content/public/browser/interstitial_page.h" | |
16 #include "content/public/browser/web_contents.h" | |
17 #include "grit/browser_resources.h" | |
mmenke
2014/06/24 18:09:26
I don't think this is used.
meacer
2014/10/22 23:04:28
Not referred from this class anymore.
| |
18 #include "grit/generated_resources.h" | |
19 #include "net/base/net_errors.h" | |
mmenke
2014/06/24 18:09:26
I don't think this is used.
meacer
2014/10/22 23:04:28
Done.
| |
20 #include "net/base/net_util.h" | |
21 #include "ui/base/l10n/l10n_util.h" | |
22 #include "ui/base/resource/resource_bundle.h" | |
23 #include "ui/base/webui/jstemplate_builder.h" | |
24 #include "ui/base/webui/web_ui_util.h" | |
25 | |
26 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
27 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" | |
28 #endif | |
29 | |
30 namespace { | |
31 | |
32 // These represent the commands sent by captive_portal.html. | |
33 enum CaptivePortalBlockingPageCommands { | |
34 CMD_OPEN_LOGIN_PAGE = 1, | |
35 CMD_SHOW_DETAILS = 2 | |
36 }; | |
37 | |
38 // Events for UMA. | |
39 enum CaptivePortalBlockingPageEvent { | |
40 SHOW_ALL, | |
41 OPEN_LOGIN_PAGE, | |
42 SHOW_DETAILS, | |
43 CAPTIVE_PORTAL_BLOCKING_PAGE_EVENT_COUNT | |
44 }; | |
45 | |
46 void RecordUMA(CaptivePortalBlockingPageEvent event) { | |
47 UMA_HISTOGRAM_ENUMERATION("interstitial.captive_portal", | |
48 event, | |
49 CAPTIVE_PORTAL_BLOCKING_PAGE_EVENT_COUNT); | |
50 } | |
51 | |
52 void GetStrings(base::DictionaryValue* strings, | |
53 const GURL& request_url, | |
54 const std::string& accept_languages) { | |
55 webui::SetFontAndTextDirection(strings); | |
56 strings->SetString("iconClass", "icon-offline"); | |
57 base::string16 url_string(net::FormatUrl( | |
58 request_url, accept_languages, net::kFormatUrlOmitNothing, | |
59 net::UnescapeRule::NORMAL, NULL, NULL, NULL)); | |
60 // URLs are always LTR. | |
61 if (base::i18n::IsRTL()) | |
62 base::i18n::WrapStringWithLTRFormatting(&url_string); | |
63 strings->SetString("title", | |
64 l10n_util::GetStringFUTF16(IDS_CAPTIVE_PORTAL_TITLE, url_string)); | |
65 strings->SetString("heading", | |
66 l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_HEADING)); | |
67 strings->SetString( | |
68 "primaryButtonText", | |
69 l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_BUTTON_OPEN_LOGIN_PAGE)); | |
70 strings->SetString( | |
71 "openDetails", | |
72 l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_BUTTON_MORE)); | |
73 strings->SetString( | |
74 "closeDetails", | |
75 l10n_util::GetStringUTF16(IDS_CAPTIVE_PORTAL_BUTTON_LESS)); | |
76 strings->SetString( | |
77 "primaryParagraph", | |
78 l10n_util::GetStringFUTF16(IDS_CAPTIVE_PORTAL_PRIMARY_PARAGRAPH, | |
79 url_string)); | |
80 strings->SetString( | |
81 "explanationParagraph", | |
82 l10n_util::GetStringFUTF16(IDS_CAPTIVE_PORTAL_DETAILS, | |
83 url_string)); | |
84 } | |
85 | |
86 } // namespace | |
87 | |
88 CaptivePortalBlockingPage::CaptivePortalBlockingPage( | |
89 content::WebContents* web_contents, | |
90 const GURL& request_url) | |
91 : web_contents_(web_contents), | |
92 request_url_(request_url) { | |
93 interstitial_page_ = content::InterstitialPage::Create( | |
94 web_contents_, true, request_url, this); | |
95 interstitial_page_->Show(); | |
96 RecordUMA(SHOW_ALL); | |
97 } | |
98 | |
99 CaptivePortalBlockingPage::~CaptivePortalBlockingPage() { | |
100 } | |
101 | |
102 std::string CaptivePortalBlockingPage::GetHTMLContents() { | |
103 int resource_id = IDR_CAPTIVE_PORTAL_HTML; | |
104 const base::StringPiece template_html( | |
105 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); | |
106 | |
107 Profile* profile = Profile::FromBrowserContext( | |
108 web_contents_->GetBrowserContext()); | |
109 const std::string accept_languages = | |
110 profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | |
111 const std::string locale = g_browser_process->GetApplicationLocale(); | |
112 | |
113 base::DictionaryValue strings; | |
114 GetStrings(&strings, request_url_, accept_languages); | |
115 webui::UseVersion2 version; | |
116 return webui::GetI18nTemplateHtml(template_html, &strings); | |
117 } | |
118 | |
119 void CaptivePortalBlockingPage::CommandReceived(const std::string& command) { | |
120 int cmd = atoi(command.c_str()); | |
mmenke
2014/06/24 18:09:26
Need the header for atoi.
meacer
2014/10/22 23:04:28
Code not used anymore.
| |
121 if (cmd == CMD_OPEN_LOGIN_PAGE) { | |
122 RecordUMA(OPEN_LOGIN_PAGE); | |
123 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
124 CaptivePortalTabHelper::OpenLoginTabForWebContents(web_contents_, true); | |
125 #endif | |
126 } else if (cmd == CMD_SHOW_DETAILS) { | |
127 RecordUMA(SHOW_DETAILS); | |
128 } | |
129 } | |
OLD | NEW |