blob: 946fc9d0778f81c11c32303d6403215bec94feb2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/chrome/browser/interstitials/ios_security_interstitial_page.h"
#include "base/logging.h"
#include "components/grit/components_resources.h"
#include "components/prefs/pref_service.h"
#include "components/security_interstitials/core/common_string_util.h"
#include "components/security_interstitials/core/metrics_helper.h"
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/interstitials/ios_chrome_controller_client.h"
#include "ios/chrome/browser/pref_names.h"
#include "ios/web/public/interstitials/web_interstitial.h"
#include "ios/web/public/web_state/web_state.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/webui/jstemplate_builder.h"
#include "ui/base/webui/web_ui_util.h"
IOSSecurityInterstitialPage::IOSSecurityInterstitialPage(
web::WebState* web_state,
const GURL& request_url)
: web_state_(web_state),
request_url_(request_url),
web_interstitial_(nullptr) {
// Creating web_interstitial_ without showing it leaks memory, so don't
// create it here.
}
IOSSecurityInterstitialPage::~IOSSecurityInterstitialPage() {}
void IOSSecurityInterstitialPage::Show() {
DCHECK(!web_interstitial_);
web_interstitial_ = web::WebInterstitial::CreateHtmlInterstitial(
web_state_, ShouldCreateNewNavigation(), request_url_,
scoped_ptr<web::HtmlWebInterstitialDelegate>(this));
web_interstitial_->Show();
AfterShow();
}
std::string IOSSecurityInterstitialPage::GetHtmlContents() const {
base::DictionaryValue load_time_data;
PopulateInterstitialStrings(&load_time_data);
webui::SetLoadTimeDataDefaults(
GetApplicationContext()->GetApplicationLocale(), &load_time_data);
std::string html = ResourceBundle::GetSharedInstance()
.GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML)
.as_string();
webui::AppendWebUiCssTextDefaults(&html);
return webui::GetI18nTemplateHtml(html, &load_time_data);
}
base::string16 IOSSecurityInterstitialPage::GetFormattedHostName() const {
ios::ChromeBrowserState* browser_state =
ios::ChromeBrowserState::FromBrowserState(web_state_->GetBrowserState());
std::string languages =
browser_state->GetPrefs()->GetString(prefs::kAcceptLanguages);
return security_interstitials::common_string_util::GetFormattedHostName(
request_url_, languages);
}
bool IOSSecurityInterstitialPage::IsPrefEnabled(const char* pref_name) const {
ios::ChromeBrowserState* browser_state =
ios::ChromeBrowserState::FromBrowserState(web_state_->GetBrowserState());
return browser_state->GetPrefs()->GetBoolean(pref_name);
}
|