OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/interstitials/security_interstitial_page.h" | 5 #include "chrome/browser/interstitials/security_interstitial_page.h" |
6 | 6 |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 | 8 |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/interstitials/chrome_controller_client.h" | 14 #include "chrome/browser/interstitials/chrome_controller_client.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
17 #include "chrome/grit/browser_resources.h" | 17 #include "chrome/grit/browser_resources.h" |
18 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
19 #include "components/grit/components_resources.h" | 19 #include "components/grit/components_resources.h" |
| 20 #include "components/security_interstitials/core/common_string_util.h" |
20 #include "components/security_interstitials/core/metrics_helper.h" | 21 #include "components/security_interstitials/core/metrics_helper.h" |
21 #include "components/url_formatter/url_formatter.h" | |
22 #include "content/public/browser/interstitial_page.h" | 22 #include "content/public/browser/interstitial_page.h" |
23 #include "content/public/browser/page_navigator.h" | 23 #include "content/public/browser/page_navigator.h" |
24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
25 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
26 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
27 #include "ui/base/webui/jstemplate_builder.h" | 27 #include "ui/base/webui/jstemplate_builder.h" |
28 #include "ui/base/webui/web_ui_util.h" | 28 #include "ui/base/webui/web_ui_util.h" |
29 | 29 |
30 SecurityInterstitialPage::SecurityInterstitialPage( | 30 SecurityInterstitialPage::SecurityInterstitialPage( |
31 content::WebContents* web_contents, | 31 content::WebContents* web_contents, |
(...skipping 26 matching lines...) Expand all Loading... |
58 create_view_ = false; | 58 create_view_ = false; |
59 } | 59 } |
60 | 60 |
61 void SecurityInterstitialPage::Show() { | 61 void SecurityInterstitialPage::Show() { |
62 DCHECK(!interstitial_page_); | 62 DCHECK(!interstitial_page_); |
63 interstitial_page_ = content::InterstitialPage::Create( | 63 interstitial_page_ = content::InterstitialPage::Create( |
64 web_contents_, ShouldCreateNewNavigation(), request_url_, this); | 64 web_contents_, ShouldCreateNewNavigation(), request_url_, this); |
65 if (!create_view_) | 65 if (!create_view_) |
66 interstitial_page_->DontCreateViewForTesting(); | 66 interstitial_page_->DontCreateViewForTesting(); |
67 interstitial_page_->Show(); | 67 interstitial_page_->Show(); |
| 68 |
| 69 controller_->set_interstitial_page(interstitial_page_); |
| 70 AfterShow(); |
68 } | 71 } |
69 | 72 |
70 bool SecurityInterstitialPage::IsPrefEnabled(const char* pref) { | 73 bool SecurityInterstitialPage::IsPrefEnabled(const char* pref) { |
71 Profile* profile = | 74 Profile* profile = |
72 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 75 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
73 return profile->GetPrefs()->GetBoolean(pref); | 76 return profile->GetPrefs()->GetBoolean(pref); |
74 } | 77 } |
75 | 78 |
76 base::string16 SecurityInterstitialPage::GetFormattedHostName() const { | 79 base::string16 SecurityInterstitialPage::GetFormattedHostName() const { |
77 std::string languages; | 80 std::string languages; |
78 Profile* profile = | 81 Profile* profile = |
79 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 82 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
80 if (profile) | 83 if (profile) |
81 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 84 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
82 base::string16 host = | 85 return security_interstitials::common_string_util::GetFormattedHostName( |
83 url_formatter::IDNToUnicode(request_url_.host(), languages); | 86 request_url_, languages); |
84 if (base::i18n::IsRTL()) | |
85 base::i18n::WrapStringWithLTRFormatting(&host); | |
86 return host; | |
87 } | 87 } |
88 | 88 |
89 std::string SecurityInterstitialPage::GetHTMLContents() { | 89 std::string SecurityInterstitialPage::GetHTMLContents() { |
90 base::DictionaryValue load_time_data; | 90 base::DictionaryValue load_time_data; |
91 PopulateInterstitialStrings(&load_time_data); | 91 PopulateInterstitialStrings(&load_time_data); |
92 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 92 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
93 webui::SetLoadTimeDataDefaults(app_locale, &load_time_data); | 93 webui::SetLoadTimeDataDefaults(app_locale, &load_time_data); |
94 std::string html = ResourceBundle::GetSharedInstance() | 94 std::string html = ResourceBundle::GetSharedInstance() |
95 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML) | 95 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML) |
96 .as_string(); | 96 .as_string(); |
(...skipping 11 matching lines...) Expand all Loading... |
108 | 108 |
109 security_interstitials::MetricsHelper* | 109 security_interstitials::MetricsHelper* |
110 SecurityInterstitialPage::metrics_helper() { | 110 SecurityInterstitialPage::metrics_helper() { |
111 return controller_->metrics_helper(); | 111 return controller_->metrics_helper(); |
112 } | 112 } |
113 | 113 |
114 void SecurityInterstitialPage::set_metrics_helper( | 114 void SecurityInterstitialPage::set_metrics_helper( |
115 scoped_ptr<security_interstitials::MetricsHelper> metrics_helper) { | 115 scoped_ptr<security_interstitials::MetricsHelper> metrics_helper) { |
116 controller_->set_metrics_helper(metrics_helper.Pass()); | 116 controller_->set_metrics_helper(metrics_helper.Pass()); |
117 } | 117 } |
OLD | NEW |