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 <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" | 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 "components/grit/components_resources.h" | 17 #include "components/grit/components_resources.h" |
18 #include "components/prefs/pref_service.h" | 18 #include "components/prefs/pref_service.h" |
19 #include "components/security_interstitials/core/common_string_util.h" | 19 #include "components/security_interstitials/core/common_string_util.h" |
20 #include "components/security_interstitials/core/metrics_helper.h" | 20 #include "components/security_interstitials/core/metrics_helper.h" |
21 #include "content/public/browser/interstitial_page.h" | 21 #include "content/public/browser/interstitial_page.h" |
22 #include "content/public/browser/page_navigator.h" | 22 #include "content/public/browser/page_navigator.h" |
23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
24 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
25 #include "ui/base/webui/jstemplate_builder.h" | 25 #include "ui/base/webui/jstemplate_builder.h" |
26 #include "ui/base/webui/web_ui_util.h" | 26 #include "ui/base/webui/web_ui_util.h" |
27 | 27 |
28 SecurityInterstitialPage::SecurityInterstitialPage( | 28 SecurityInterstitialPage::SecurityInterstitialPage( |
29 content::WebContents* web_contents, | 29 content::WebContents* web_contents, |
30 const GURL& request_url) | 30 const GURL& request_url, |
| 31 std::unique_ptr<security_interstitials::MetricsHelper> metrics_helper) |
31 : web_contents_(web_contents), | 32 : web_contents_(web_contents), |
32 request_url_(request_url), | 33 request_url_(request_url), |
33 interstitial_page_(NULL), | 34 interstitial_page_(NULL), |
34 create_view_(true), | 35 create_view_(true), |
35 controller_(new ChromeControllerClient(web_contents)) { | 36 controller_( |
| 37 new ChromeControllerClient(web_contents, std::move(metrics_helper))) { |
36 // Creating interstitial_page_ without showing it leaks memory, so don't | 38 // Creating interstitial_page_ without showing it leaks memory, so don't |
37 // create it here. | 39 // create it here. |
38 } | 40 } |
39 | 41 |
40 SecurityInterstitialPage::~SecurityInterstitialPage() { | 42 SecurityInterstitialPage::~SecurityInterstitialPage() { |
41 } | 43 } |
42 | 44 |
43 content::InterstitialPage* SecurityInterstitialPage::interstitial_page() const { | 45 content::InterstitialPage* SecurityInterstitialPage::interstitial_page() const { |
44 return interstitial_page_; | 46 return interstitial_page_; |
45 } | 47 } |
(...skipping 21 matching lines...) Expand all Loading... |
67 controller_->set_interstitial_page(interstitial_page_); | 69 controller_->set_interstitial_page(interstitial_page_); |
68 AfterShow(); | 70 AfterShow(); |
69 } | 71 } |
70 | 72 |
71 bool SecurityInterstitialPage::IsPrefEnabled(const char* pref) { | 73 bool SecurityInterstitialPage::IsPrefEnabled(const char* pref) { |
72 Profile* profile = | 74 Profile* profile = |
73 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 75 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
74 return profile->GetPrefs()->GetBoolean(pref); | 76 return profile->GetPrefs()->GetBoolean(pref); |
75 } | 77 } |
76 | 78 |
| 79 ChromeControllerClient* SecurityInterstitialPage::controller() { |
| 80 return controller_.get(); |
| 81 } |
| 82 |
| 83 security_interstitials::MetricsHelper* |
| 84 SecurityInterstitialPage::metrics_helper() { |
| 85 return controller_->metrics_helper(); |
| 86 } |
| 87 |
77 base::string16 SecurityInterstitialPage::GetFormattedHostName() const { | 88 base::string16 SecurityInterstitialPage::GetFormattedHostName() const { |
78 return security_interstitials::common_string_util::GetFormattedHostName( | 89 return security_interstitials::common_string_util::GetFormattedHostName( |
79 request_url_); | 90 request_url_); |
80 } | 91 } |
81 | 92 |
82 std::string SecurityInterstitialPage::GetHTMLContents() { | 93 std::string SecurityInterstitialPage::GetHTMLContents() { |
83 base::DictionaryValue load_time_data; | 94 base::DictionaryValue load_time_data; |
84 PopulateInterstitialStrings(&load_time_data); | 95 PopulateInterstitialStrings(&load_time_data); |
85 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 96 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
86 webui::SetLoadTimeDataDefaults(app_locale, &load_time_data); | 97 webui::SetLoadTimeDataDefaults(app_locale, &load_time_data); |
87 std::string html = ResourceBundle::GetSharedInstance() | 98 std::string html = ResourceBundle::GetSharedInstance() |
88 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML) | 99 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML) |
89 .as_string(); | 100 .as_string(); |
90 webui::AppendWebUiCssTextDefaults(&html); | 101 webui::AppendWebUiCssTextDefaults(&html); |
91 return webui::GetI18nTemplateHtml(html, &load_time_data); | 102 return webui::GetI18nTemplateHtml(html, &load_time_data); |
92 } | 103 } |
93 | |
94 security_interstitials::MetricsHelper* | |
95 SecurityInterstitialPage::metrics_helper() { | |
96 return controller_->metrics_helper(); | |
97 } | |
98 | |
99 void SecurityInterstitialPage::set_metrics_helper( | |
100 std::unique_ptr<security_interstitials::MetricsHelper> metrics_helper) { | |
101 controller_->set_metrics_helper(std::move(metrics_helper)); | |
102 } | |
103 | |
104 ChromeControllerClient* SecurityInterstitialPage::controller() { | |
105 return controller_.get(); | |
106 } | |
OLD | NEW |