| 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 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/pref_names.h" |
| 10 #include "chrome/grit/browser_resources.h" | 13 #include "chrome/grit/browser_resources.h" |
| 11 #include "content/public/browser/interstitial_page.h" | 14 #include "content/public/browser/interstitial_page.h" |
| 12 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 16 #include "net/base/net_util.h" |
| 13 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 14 #include "ui/base/webui/jstemplate_builder.h" | 18 #include "ui/base/webui/jstemplate_builder.h" |
| 15 #include "ui/base/webui/web_ui_util.h" | 19 #include "ui/base/webui/web_ui_util.h" |
| 16 | 20 |
| 17 SecurityInterstitialPage::SecurityInterstitialPage( | 21 SecurityInterstitialPage::SecurityInterstitialPage( |
| 18 content::WebContents* web_contents, | 22 content::WebContents* web_contents, |
| 19 const GURL& request_url) | 23 const GURL& request_url) |
| 20 : web_contents_(web_contents), | 24 : web_contents_(web_contents), |
| 21 request_url_(request_url), | 25 request_url_(request_url), |
| 22 interstitial_page_(NULL), | 26 interstitial_page_(NULL), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 47 void SecurityInterstitialPage::Show() { | 51 void SecurityInterstitialPage::Show() { |
| 48 DCHECK(!interstitial_page_); | 52 DCHECK(!interstitial_page_); |
| 49 interstitial_page_ = content::InterstitialPage::Create( | 53 interstitial_page_ = content::InterstitialPage::Create( |
| 50 web_contents_, ShouldCreateNewNavigation(), request_url_, this); | 54 web_contents_, ShouldCreateNewNavigation(), request_url_, this); |
| 51 if (!create_view_) | 55 if (!create_view_) |
| 52 interstitial_page_->DontCreateViewForTesting(); | 56 interstitial_page_->DontCreateViewForTesting(); |
| 53 interstitial_page_->Show(); | 57 interstitial_page_->Show(); |
| 54 } | 58 } |
| 55 | 59 |
| 56 base::string16 SecurityInterstitialPage::GetFormattedHostName() const { | 60 base::string16 SecurityInterstitialPage::GetFormattedHostName() const { |
| 57 base::string16 host(base::UTF8ToUTF16(request_url_.host())); | 61 std::string languages; |
| 62 Profile* profile = Profile::FromBrowserContext( |
| 63 web_contents()->GetBrowserContext()); |
| 64 if (profile) |
| 65 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 66 base::string16 host = net::IDNToUnicode(request_url_.host(), languages); |
| 58 if (base::i18n::IsRTL()) | 67 if (base::i18n::IsRTL()) |
| 59 base::i18n::WrapStringWithLTRFormatting(&host); | 68 base::i18n::WrapStringWithLTRFormatting(&host); |
| 60 return host; | 69 return host; |
| 61 } | 70 } |
| 62 | 71 |
| 63 std::string SecurityInterstitialPage::GetHTMLContents() { | 72 std::string SecurityInterstitialPage::GetHTMLContents() { |
| 64 base::DictionaryValue load_time_data; | 73 base::DictionaryValue load_time_data; |
| 65 PopulateInterstitialStrings(&load_time_data); | 74 PopulateInterstitialStrings(&load_time_data); |
| 66 webui::SetFontAndTextDirection(&load_time_data); | 75 webui::SetFontAndTextDirection(&load_time_data); |
| 67 base::StringPiece html( | 76 base::StringPiece html( |
| 68 ResourceBundle::GetSharedInstance().GetRawDataResource( | 77 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 69 IDR_SECURITY_INTERSTITIAL_HTML)); | 78 IDR_SECURITY_INTERSTITIAL_HTML)); |
| 70 return webui::GetI18nTemplateHtml(html, &load_time_data); | 79 return webui::GetI18nTemplateHtml(html, &load_time_data); |
| 71 } | 80 } |
| OLD | NEW |