| 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 "components/security_interstitials/content/security_interstitial_page.h
" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/strings/utf_string_conversions.h" | |
| 12 #include "base/values.h" | 11 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | |
| 14 #include "chrome/browser/interstitials/chrome_controller_client.h" | |
| 15 #include "chrome/browser/profiles/profile.h" | |
| 16 #include "chrome/common/pref_names.h" | |
| 17 #include "components/grit/components_resources.h" | |
| 18 #include "components/prefs/pref_service.h" | 12 #include "components/prefs/pref_service.h" |
| 19 #include "components/safe_browsing_db/safe_browsing_prefs.h" | 13 #include "components/safe_browsing_db/safe_browsing_prefs.h" |
| 14 #include "components/security_interstitials/content/security_interstitial_contro
ller_client.h" |
| 20 #include "components/security_interstitials/core/common_string_util.h" | 15 #include "components/security_interstitials/core/common_string_util.h" |
| 21 #include "components/security_interstitials/core/metrics_helper.h" | 16 #include "components/security_interstitials/core/metrics_helper.h" |
| 22 #include "content/public/browser/interstitial_page.h" | 17 #include "content/public/browser/interstitial_page.h" |
| 23 #include "content/public/browser/page_navigator.h" | 18 #include "content/public/browser/page_navigator.h" |
| 24 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "grit/components_resources.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 26 #include "ui/base/webui/jstemplate_builder.h" | 22 #include "ui/base/webui/jstemplate_builder.h" |
| 27 #include "ui/base/webui/web_ui_util.h" | 23 #include "ui/base/webui/web_ui_util.h" |
| 28 | 24 |
| 25 namespace security_interstitials { |
| 26 |
| 29 SecurityInterstitialPage::SecurityInterstitialPage( | 27 SecurityInterstitialPage::SecurityInterstitialPage( |
| 30 content::WebContents* web_contents, | 28 content::WebContents* web_contents, |
| 31 const GURL& request_url, | 29 const GURL& request_url, |
| 32 std::unique_ptr<security_interstitials::MetricsHelper> metrics_helper) | 30 std::unique_ptr<SecurityInterstitialControllerClient> controller) |
| 33 : web_contents_(web_contents), | 31 : web_contents_(web_contents), |
| 34 request_url_(request_url), | 32 request_url_(request_url), |
| 35 interstitial_page_(NULL), | 33 interstitial_page_(NULL), |
| 36 create_view_(true), | 34 create_view_(true), |
| 37 controller_( | 35 controller_(std::move(controller)) { |
| 38 new ChromeControllerClient(web_contents, std::move(metrics_helper))) { | |
| 39 // Creating interstitial_page_ without showing it leaks memory, so don't | 36 // Creating interstitial_page_ without showing it leaks memory, so don't |
| 40 // create it here. | 37 // create it here. |
| 41 } | 38 } |
| 42 | 39 |
| 43 SecurityInterstitialPage::~SecurityInterstitialPage() { | 40 SecurityInterstitialPage::~SecurityInterstitialPage() { |
| 44 } | 41 } |
| 45 | 42 |
| 46 content::InterstitialPage* SecurityInterstitialPage::interstitial_page() const { | 43 content::InterstitialPage* SecurityInterstitialPage::interstitial_page() const { |
| 47 return interstitial_page_; | 44 return interstitial_page_; |
| 48 } | 45 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 61 | 58 |
| 62 void SecurityInterstitialPage::Show() { | 59 void SecurityInterstitialPage::Show() { |
| 63 DCHECK(!interstitial_page_); | 60 DCHECK(!interstitial_page_); |
| 64 interstitial_page_ = content::InterstitialPage::Create( | 61 interstitial_page_ = content::InterstitialPage::Create( |
| 65 web_contents_, ShouldCreateNewNavigation(), request_url_, this); | 62 web_contents_, ShouldCreateNewNavigation(), request_url_, this); |
| 66 if (!create_view_) | 63 if (!create_view_) |
| 67 interstitial_page_->DontCreateViewForTesting(); | 64 interstitial_page_->DontCreateViewForTesting(); |
| 68 | 65 |
| 69 // Determine if any prefs need to be updated prior to showing the security | 66 // Determine if any prefs need to be updated prior to showing the security |
| 70 // interstitial. | 67 // interstitial. |
| 71 safe_browsing::UpdatePrefsBeforeSecurityInterstitial(profile()->GetPrefs()); | 68 safe_browsing::UpdatePrefsBeforeSecurityInterstitial( |
| 69 controller_->GetPrefService()); |
| 70 |
| 72 interstitial_page_->Show(); | 71 interstitial_page_->Show(); |
| 73 | 72 |
| 74 controller_->set_interstitial_page(interstitial_page_); | 73 controller_->set_interstitial_page(interstitial_page_); |
| 75 AfterShow(); | 74 AfterShow(); |
| 76 } | 75 } |
| 77 | 76 |
| 78 Profile* SecurityInterstitialPage::profile() { | 77 bool SecurityInterstitialPage::IsPrefEnabled(const char* pref) { |
| 79 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 78 return controller_->GetPrefService()->GetBoolean(pref); |
| 80 } | 79 } |
| 81 | 80 |
| 82 bool SecurityInterstitialPage::IsPrefEnabled(const char* pref) { | 81 SecurityInterstitialControllerClient* SecurityInterstitialPage::controller() { |
| 83 return profile()->GetPrefs()->GetBoolean(pref); | |
| 84 } | |
| 85 | |
| 86 ChromeControllerClient* SecurityInterstitialPage::controller() { | |
| 87 return controller_.get(); | 82 return controller_.get(); |
| 88 } | 83 } |
| 89 | 84 |
| 90 security_interstitials::MetricsHelper* | 85 security_interstitials::MetricsHelper* |
| 91 SecurityInterstitialPage::metrics_helper() { | 86 SecurityInterstitialPage::metrics_helper() { |
| 92 return controller_->metrics_helper(); | 87 return controller_->metrics_helper(); |
| 93 } | 88 } |
| 94 | 89 |
| 95 base::string16 SecurityInterstitialPage::GetFormattedHostName() const { | 90 base::string16 SecurityInterstitialPage::GetFormattedHostName() const { |
| 96 return security_interstitials::common_string_util::GetFormattedHostName( | 91 return security_interstitials::common_string_util::GetFormattedHostName( |
| 97 request_url_); | 92 request_url_); |
| 98 } | 93 } |
| 99 | 94 |
| 100 std::string SecurityInterstitialPage::GetHTMLContents() { | 95 std::string SecurityInterstitialPage::GetHTMLContents() { |
| 101 base::DictionaryValue load_time_data; | 96 base::DictionaryValue load_time_data; |
| 102 PopulateInterstitialStrings(&load_time_data); | 97 PopulateInterstitialStrings(&load_time_data); |
| 103 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 98 webui::SetLoadTimeDataDefaults( |
| 104 webui::SetLoadTimeDataDefaults(app_locale, &load_time_data); | 99 controller()->GetApplicationLocale(), &load_time_data); |
| 105 std::string html = ResourceBundle::GetSharedInstance() | 100 std::string html = ResourceBundle::GetSharedInstance() |
| 106 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML) | 101 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML) |
| 107 .as_string(); | 102 .as_string(); |
| 108 webui::AppendWebUiCssTextDefaults(&html); | 103 webui::AppendWebUiCssTextDefaults(&html); |
| 109 return webui::GetI18nTemplateHtml(html, &load_time_data); | 104 return webui::GetI18nTemplateHtml(html, &load_time_data); |
| 110 } | 105 } |
| 106 |
| 107 } // security_interstitials |
| OLD | NEW |