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.
5 #include "chrome/browser/interstitials/security_interstitial_page.h"
7 #include "base/i18n/rtl.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/grit/browser_resources.h"
12 #include "content/public/browser/interstitial_page.h"
13 #include "content/public/browser/web_contents.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/base/webui/jstemplate_builder.h"
16 #include "ui/base/webui/web_ui_util.h"
18 SecurityInterstitialPage::SecurityInterstitialPage(
19 content::WebContents
* web_contents
,
20 const GURL
& request_url
)
21 : web_contents_(web_contents
),
22 request_url_(request_url
),
23 interstitial_page_(NULL
),
25 // Creating interstitial_page_ without showing it leaks memory, so don't
29 SecurityInterstitialPage::~SecurityInterstitialPage() {
32 content::InterstitialPage
* SecurityInterstitialPage::interstitial_page() const {
33 return interstitial_page_
;
36 content::WebContents
* SecurityInterstitialPage::web_contents() const {
40 GURL
SecurityInterstitialPage::request_url() const {
44 void SecurityInterstitialPage::DontCreateViewForTesting() {
48 void SecurityInterstitialPage::Show() {
49 DCHECK(!interstitial_page_
);
50 interstitial_page_
= content::InterstitialPage::Create(
51 web_contents_
, ShouldCreateNewNavigation(), request_url_
, this);
53 interstitial_page_
->DontCreateViewForTesting();
54 interstitial_page_
->Show();
57 base::string16
SecurityInterstitialPage::GetFormattedHostName() const {
58 base::string16
host(base::UTF8ToUTF16(request_url_
.host()));
59 if (base::i18n::IsRTL())
60 base::i18n::WrapStringWithLTRFormatting(&host
);
64 std::string
SecurityInterstitialPage::GetHTMLContents() {
65 base::DictionaryValue load_time_data
;
66 PopulateInterstitialStrings(&load_time_data
);
67 const std::string
& app_locale
= g_browser_process
->GetApplicationLocale();
68 webui::SetLoadTimeDataDefaults(app_locale
, &load_time_data
);
69 std::string html
= ResourceBundle::GetSharedInstance()
70 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML
)
72 webui::AppendWebUiCssTextDefaults(&html
);
73 return webui::GetI18nTemplateHtml(html
, &load_time_data
);