Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(779)

Side by Side Diff: chrome/browser/interstitials/security_interstitial_page.cc

Issue 2603433002: Move SecurityInterstitialPage into component (Closed)
Patch Set: missed some changes in rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/interstitials/security_interstitial_page.h"
6
7 #include <utility>
8
9 #include "base/i18n/rtl.h"
10 #include "base/metrics/histogram_macros.h"
11 #include "base/strings/utf_string_conversions.h"
12 #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"
19 #include "components/safe_browsing_db/safe_browsing_prefs.h"
20 #include "components/security_interstitials/core/common_string_util.h"
21 #include "components/security_interstitials/core/metrics_helper.h"
22 #include "content/public/browser/interstitial_page.h"
23 #include "content/public/browser/page_navigator.h"
24 #include "content/public/browser/web_contents.h"
25 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/base/webui/jstemplate_builder.h"
27 #include "ui/base/webui/web_ui_util.h"
28
29 SecurityInterstitialPage::SecurityInterstitialPage(
30 content::WebContents* web_contents,
31 const GURL& request_url,
32 std::unique_ptr<security_interstitials::MetricsHelper> metrics_helper)
33 : web_contents_(web_contents),
34 request_url_(request_url),
35 interstitial_page_(NULL),
36 create_view_(true),
37 controller_(
38 new ChromeControllerClient(web_contents, std::move(metrics_helper))) {
39 // Creating interstitial_page_ without showing it leaks memory, so don't
40 // create it here.
41 }
42
43 SecurityInterstitialPage::~SecurityInterstitialPage() {
44 }
45
46 content::InterstitialPage* SecurityInterstitialPage::interstitial_page() const {
47 return interstitial_page_;
48 }
49
50 content::WebContents* SecurityInterstitialPage::web_contents() const {
51 return web_contents_;
52 }
53
54 GURL SecurityInterstitialPage::request_url() const {
55 return request_url_;
56 }
57
58 void SecurityInterstitialPage::DontCreateViewForTesting() {
59 create_view_ = false;
60 }
61
62 void SecurityInterstitialPage::Show() {
63 DCHECK(!interstitial_page_);
64 interstitial_page_ = content::InterstitialPage::Create(
65 web_contents_, ShouldCreateNewNavigation(), request_url_, this);
66 if (!create_view_)
67 interstitial_page_->DontCreateViewForTesting();
68
69 // Determine if any prefs need to be updated prior to showing the security
70 // interstitial.
71 safe_browsing::UpdatePrefsBeforeSecurityInterstitial(profile()->GetPrefs());
72 interstitial_page_->Show();
73
74 controller_->set_interstitial_page(interstitial_page_);
75 AfterShow();
76 }
77
78 Profile* SecurityInterstitialPage::profile() {
79 return Profile::FromBrowserContext(web_contents()->GetBrowserContext());
80 }
81
82 bool SecurityInterstitialPage::IsPrefEnabled(const char* pref) {
83 return profile()->GetPrefs()->GetBoolean(pref);
84 }
85
86 ChromeControllerClient* SecurityInterstitialPage::controller() {
87 return controller_.get();
88 }
89
90 security_interstitials::MetricsHelper*
91 SecurityInterstitialPage::metrics_helper() {
92 return controller_->metrics_helper();
93 }
94
95 base::string16 SecurityInterstitialPage::GetFormattedHostName() const {
96 return security_interstitials::common_string_util::GetFormattedHostName(
97 request_url_);
98 }
99
100 std::string SecurityInterstitialPage::GetHTMLContents() {
101 base::DictionaryValue load_time_data;
102 PopulateInterstitialStrings(&load_time_data);
103 const std::string& app_locale = g_browser_process->GetApplicationLocale();
104 webui::SetLoadTimeDataDefaults(app_locale, &load_time_data);
105 std::string html = ResourceBundle::GetSharedInstance()
106 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_HTML)
107 .as_string();
108 webui::AppendWebUiCssTextDefaults(&html);
109 return webui::GetI18nTemplateHtml(html, &load_time_data);
110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698