| 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/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/grit/browser_resources.h" | |
| 11 #include "content/public/browser/interstitial_page.h" | 10 #include "content/public/browser/interstitial_page.h" |
| 12 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 13 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
| 14 #include "ui/base/webui/jstemplate_builder.h" | 13 #include "ui/base/webui/jstemplate_builder.h" |
| 15 #include "ui/base/webui/web_ui_util.h" | 14 #include "ui/base/webui/web_ui_util.h" |
| 16 | 15 |
| 17 SecurityInterstitialPage::SecurityInterstitialPage( | 16 SecurityInterstitialPage::SecurityInterstitialPage( |
| 18 content::WebContents* web_contents, | 17 content::WebContents* web_contents, |
| 19 const GURL& request_url) | 18 const GURL& request_url) |
| 20 : web_contents_(web_contents), | 19 : web_contents_(web_contents), |
| 21 request_url_(request_url), | 20 request_url_(request_url), |
| 22 interstitial_page_(NULL), | 21 interstitial_page_(NULL), |
| 23 create_view_(true) { | 22 create_view_(true) { |
| 24 // Creating interstitial_page_ without showing it leaks memory, so don't | 23 // Creating interstitial_page_ without showing it leaks memory, so don't |
| 25 // create it here. | 24 // create it here. |
| 26 } | 25 } |
| 27 | 26 |
| 28 SecurityInterstitialPage::~SecurityInterstitialPage() { | |
| 29 } | |
| 30 | |
| 31 content::InterstitialPage* SecurityInterstitialPage::interstitial_page() const { | 27 content::InterstitialPage* SecurityInterstitialPage::interstitial_page() const { |
| 32 return interstitial_page_; | 28 return interstitial_page_; |
| 33 } | 29 } |
| 34 | 30 |
| 35 content::WebContents* SecurityInterstitialPage::web_contents() const { | 31 content::WebContents* SecurityInterstitialPage::web_contents() const { |
| 36 return web_contents_; | 32 return web_contents_; |
| 37 } | 33 } |
| 38 | 34 |
| 39 GURL SecurityInterstitialPage::request_url() const { | 35 GURL SecurityInterstitialPage::request_url() const { |
| 40 return request_url_; | 36 return request_url_; |
| 41 } | 37 } |
| 42 | 38 |
| 43 void SecurityInterstitialPage::DontCreateViewForTesting() { | 39 void SecurityInterstitialPage::DontCreateViewForTesting() { |
| 44 create_view_ = false; | 40 create_view_ = false; |
| 45 } | 41 } |
| 46 | 42 |
| 47 void SecurityInterstitialPage::Show() { | 43 void SecurityInterstitialPage::Show() { |
| 48 DCHECK(!interstitial_page_); | 44 DCHECK(!interstitial_page_); |
| 49 interstitial_page_ = content::InterstitialPage::Create( | 45 interstitial_page_ = content::InterstitialPage::Create( |
| 50 web_contents_, ShouldCreateNewNavigation(), request_url_, this); | 46 web_contents_, ShouldCreateNewNavigation(), request_url_, this); |
| 51 if (!create_view_) | 47 if (!create_view_) |
| 52 interstitial_page_->DontCreateViewForTesting(); | 48 interstitial_page_->DontCreateViewForTesting(); |
| 53 interstitial_page_->Show(); | 49 interstitial_page_->Show(); |
| 54 } | 50 } |
| 55 | 51 |
| 56 base::string16 SecurityInterstitialPage::GetFormattedHostName() const { | 52 base::string16 SecurityInterstitialPage::GetFormattedHostName() { |
| 57 base::string16 host(base::UTF8ToUTF16(request_url_.host())); | 53 base::string16 host(base::UTF8ToUTF16(request_url_.host())); |
| 58 if (base::i18n::IsRTL()) | 54 if (base::i18n::IsRTL()) |
| 59 base::i18n::WrapStringWithLTRFormatting(&host); | 55 base::i18n::WrapStringWithLTRFormatting(&host); |
| 60 return host; | 56 return host; |
| 61 } | 57 } |
| 62 | 58 |
| 63 std::string SecurityInterstitialPage::GetHTMLContents() { | 59 std::string SecurityInterstitialPage::GetHTMLContents() { |
| 64 base::DictionaryValue load_time_data; | 60 base::DictionaryValue load_time_data; |
| 65 PopulateInterstitialStrings(&load_time_data); | 61 PopulateInterstitialStrings(&load_time_data); |
| 66 webui::SetFontAndTextDirection(&load_time_data); | 62 webui::SetFontAndTextDirection(&load_time_data); |
| 67 base::StringPiece html( | 63 base::StringPiece html( |
| 68 ResourceBundle::GetSharedInstance().GetRawDataResource( | 64 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 69 IDR_SECURITY_INTERSTITIAL_HTML)); | 65 IDR_SECURITY_INTERSTITIAL_HTML)); |
| 70 return webui::GetI18nTemplateHtml(html, &load_time_data); | 66 return webui::GetI18nTemplateHtml(html, &load_time_data); |
| 71 } | 67 } |
| OLD | NEW |