| 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/net/referrer.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/google/core/browser/google_util.h" | |
| 20 #include "components/grit/components_resources.h" | 19 #include "components/grit/components_resources.h" |
| 21 #include "components/security_interstitials/core/metrics_helper.h" | 20 #include "components/security_interstitials/core/metrics_helper.h" |
| 22 #include "components/url_formatter/url_formatter.h" | 21 #include "components/url_formatter/url_formatter.h" |
| 23 #include "content/public/browser/interstitial_page.h" | 22 #include "content/public/browser/interstitial_page.h" |
| 24 #include "content/public/browser/page_navigator.h" | 23 #include "content/public/browser/page_navigator.h" |
| 25 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
| 28 #include "ui/base/webui/jstemplate_builder.h" | 27 #include "ui/base/webui/jstemplate_builder.h" |
| 29 #include "ui/base/webui/web_ui_util.h" | 28 #include "ui/base/webui/web_ui_util.h" |
| 30 | 29 |
| 31 namespace interstitials { | |
| 32 const char kBoxChecked[] = "boxchecked"; | |
| 33 const char kDisplayCheckBox[] = "displaycheckbox"; | |
| 34 const char kOptInLink[] = "optInLink"; | |
| 35 const char kPrivacyLinkHtml[] = | |
| 36 "<a id=\"privacy-link\" href=\"\" onclick=\"sendCommand(%d); " | |
| 37 "return false;\" onmousedown=\"return false;\">%s</a>"; | |
| 38 } | |
| 39 | |
| 40 using content::OpenURLParams; | |
| 41 using content::Referrer; | |
| 42 | |
| 43 SecurityInterstitialPage::SecurityInterstitialPage( | 30 SecurityInterstitialPage::SecurityInterstitialPage( |
| 44 content::WebContents* web_contents, | 31 content::WebContents* web_contents, |
| 45 const GURL& request_url) | 32 const GURL& request_url) |
| 46 : web_contents_(web_contents), | 33 : web_contents_(web_contents), |
| 47 request_url_(request_url), | 34 request_url_(request_url), |
| 48 interstitial_page_(NULL), | 35 interstitial_page_(NULL), |
| 49 create_view_(true) { | 36 create_view_(true), |
| 37 controller_(new ChromeControllerClient(web_contents)) { |
| 50 // Creating interstitial_page_ without showing it leaks memory, so don't | 38 // Creating interstitial_page_ without showing it leaks memory, so don't |
| 51 // create it here. | 39 // create it here. |
| 52 } | 40 } |
| 53 | 41 |
| 54 SecurityInterstitialPage::~SecurityInterstitialPage() { | 42 SecurityInterstitialPage::~SecurityInterstitialPage() { |
| 55 } | 43 } |
| 56 | 44 |
| 57 content::InterstitialPage* SecurityInterstitialPage::interstitial_page() const { | 45 content::InterstitialPage* SecurityInterstitialPage::interstitial_page() const { |
| 58 return interstitial_page_; | 46 return interstitial_page_; |
| 59 } | 47 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 PopulateInterstitialStrings(&load_time_data); | 91 PopulateInterstitialStrings(&load_time_data); |
| 104 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 92 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
| 105 webui::SetLoadTimeDataDefaults(app_locale, &load_time_data); | 93 webui::SetLoadTimeDataDefaults(app_locale, &load_time_data); |
| 106 std::string html = ResourceBundle::GetSharedInstance() | 94 std::string html = ResourceBundle::GetSharedInstance() |
| 107 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML) | 95 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML) |
| 108 .as_string(); | 96 .as_string(); |
| 109 webui::AppendWebUiCssTextDefaults(&html); | 97 webui::AppendWebUiCssTextDefaults(&html); |
| 110 return webui::GetI18nTemplateHtml(html, &load_time_data); | 98 return webui::GetI18nTemplateHtml(html, &load_time_data); |
| 111 } | 99 } |
| 112 | 100 |
| 113 void SecurityInterstitialPage::OpenUrlInCurrentTab(const GURL& url) { | 101 void SecurityInterstitialPage::SetReportingPreference(bool report) { |
| 114 OpenURLParams params(url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_LINK, | 102 controller_->SetReportingPreference(report); |
| 115 false); | |
| 116 web_contents()->OpenURL(params); | |
| 117 } | 103 } |
| 118 | 104 |
| 119 const std::string& SecurityInterstitialPage::GetApplicationLocale() { | 105 void SecurityInterstitialPage::OpenExtendedReportingPrivacyPolicy() { |
| 120 return g_browser_process->GetApplicationLocale(); | 106 controller_->OpenExtendedReportingPrivacyPolicy(); |
| 121 } | 107 } |
| 122 | 108 |
| 123 PrefService* SecurityInterstitialPage::GetPrefService() { | 109 security_interstitials::MetricsHelper* |
| 124 Profile* profile = | 110 SecurityInterstitialPage::metrics_helper() { |
| 125 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 111 return controller_->metrics_helper(); |
| 126 return profile->GetPrefs(); | |
| 127 } | 112 } |
| 128 | 113 |
| 129 const std::string SecurityInterstitialPage::GetExtendedReportingPrefName() { | 114 void SecurityInterstitialPage::set_metrics_helper( |
| 130 return prefs::kSafeBrowsingExtendedReportingEnabled; | 115 scoped_ptr<security_interstitials::MetricsHelper> metrics_helper) { |
| 116 controller_->set_metrics_helper(metrics_helper.Pass()); |
| 131 } | 117 } |
| OLD | NEW |