OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 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/ui/webui/interstitials/interstitial_ui.h" | 5 #include "chrome/browser/ui/webui/interstitials/interstitial_ui.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
22 #include "net/base/url_util.h" | 22 #include "net/base/url_util.h" |
23 #include "net/cert/x509_certificate.h" | 23 #include "net/cert/x509_certificate.h" |
24 #include "net/ssl/ssl_info.h" | 24 #include "net/ssl/ssl_info.h" |
25 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 class InterstitialHTMLSource : public content::URLDataSource { | 29 class InterstitialHTMLSource : public content::URLDataSource { |
30 public: | 30 public: |
31 InterstitialHTMLSource(Profile* profile, | 31 explicit InterstitialHTMLSource(content::WebContents* web_contents); |
32 content::WebContents* web_contents); | |
33 ~InterstitialHTMLSource() override; | 32 ~InterstitialHTMLSource() override; |
34 | 33 |
35 // content::URLDataSource: | 34 // content::URLDataSource: |
36 std::string GetMimeType(const std::string& mime_type) const override; | 35 std::string GetMimeType(const std::string& mime_type) const override; |
37 std::string GetSource() const override; | 36 std::string GetSource() const override; |
38 bool ShouldAddContentSecurityPolicy() const override; | 37 bool ShouldAddContentSecurityPolicy() const override; |
39 void StartDataRequest( | 38 void StartDataRequest( |
40 const std::string& path, | 39 const std::string& path, |
41 int render_process_id, | 40 int render_process_id, |
42 int render_frame_id, | 41 int render_frame_id, |
43 const content::URLDataSource::GotDataCallback& callback) override; | 42 const content::URLDataSource::GotDataCallback& callback) override; |
44 | 43 |
45 private: | 44 private: |
46 Profile* profile_; | |
47 content::WebContents* web_contents_; | 45 content::WebContents* web_contents_; |
48 DISALLOW_COPY_AND_ASSIGN(InterstitialHTMLSource); | 46 DISALLOW_COPY_AND_ASSIGN(InterstitialHTMLSource); |
49 }; | 47 }; |
50 | 48 |
51 SSLBlockingPage* CreateSSLBlockingPage(content::WebContents* web_contents) { | 49 SSLBlockingPage* CreateSSLBlockingPage(content::WebContents* web_contents) { |
52 // Random parameters for SSL blocking page. | 50 // Random parameters for SSL blocking page. |
53 int cert_error = net::ERR_CERT_CONTAINS_ERRORS; | 51 int cert_error = net::ERR_CERT_CONTAINS_ERRORS; |
54 GURL request_url("https://example.com"); | 52 GURL request_url("https://example.com"); |
55 bool overridable = false; | 53 bool overridable = false; |
56 bool strict_enforcement = false; | 54 bool strict_enforcement = false; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 return SafeBrowsingBlockingPage::CreateBlockingPage( | 136 return SafeBrowsingBlockingPage::CreateBlockingPage( |
139 g_browser_process->safe_browsing_service()->ui_manager().get(), | 137 g_browser_process->safe_browsing_service()->ui_manager().get(), |
140 web_contents, | 138 web_contents, |
141 resource); | 139 resource); |
142 } | 140 } |
143 | 141 |
144 } // namespace | 142 } // namespace |
145 | 143 |
146 InterstitialUI::InterstitialUI(content::WebUI* web_ui) | 144 InterstitialUI::InterstitialUI(content::WebUI* web_ui) |
147 : WebUIController(web_ui) { | 145 : WebUIController(web_ui) { |
| 146 scoped_ptr<InterstitialHTMLSource> html_source( |
| 147 new InterstitialHTMLSource(web_ui->GetWebContents())); |
148 Profile* profile = Profile::FromWebUI(web_ui); | 148 Profile* profile = Profile::FromWebUI(web_ui); |
149 scoped_ptr<InterstitialHTMLSource> html_source( | |
150 new InterstitialHTMLSource(profile->GetOriginalProfile(), | |
151 web_ui->GetWebContents())); | |
152 content::URLDataSource::Add(profile, html_source.release()); | 149 content::URLDataSource::Add(profile, html_source.release()); |
153 } | 150 } |
154 | 151 |
155 InterstitialUI::~InterstitialUI() { | 152 InterstitialUI::~InterstitialUI() { |
156 } | 153 } |
157 | 154 |
158 // InterstitialHTMLSource | 155 // InterstitialHTMLSource |
159 | 156 |
160 InterstitialHTMLSource::InterstitialHTMLSource( | 157 InterstitialHTMLSource::InterstitialHTMLSource( |
161 Profile* profile, | |
162 content::WebContents* web_contents) | 158 content::WebContents* web_contents) |
163 : profile_(profile), | 159 : web_contents_(web_contents) { |
164 web_contents_(web_contents) { | |
165 } | 160 } |
166 | 161 |
167 InterstitialHTMLSource::~InterstitialHTMLSource() { | 162 InterstitialHTMLSource::~InterstitialHTMLSource() { |
168 } | 163 } |
169 | 164 |
170 std::string InterstitialHTMLSource::GetMimeType( | 165 std::string InterstitialHTMLSource::GetMimeType( |
171 const std::string& mime_type) const { | 166 const std::string& mime_type) const { |
172 return "text/html"; | 167 return "text/html"; |
173 } | 168 } |
174 | 169 |
(...skipping 23 matching lines...) Expand all Loading... |
198 html = interstitial_delegate.get()->GetHTMLContents(); | 193 html = interstitial_delegate.get()->GetHTMLContents(); |
199 } else { | 194 } else { |
200 html = ResourceBundle::GetSharedInstance() | 195 html = ResourceBundle::GetSharedInstance() |
201 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) | 196 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) |
202 .as_string(); | 197 .as_string(); |
203 } | 198 } |
204 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; | 199 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; |
205 html_bytes->data().assign(html.begin(), html.end()); | 200 html_bytes->data().assign(html.begin(), html.end()); |
206 callback.Run(html_bytes.get()); | 201 callback.Run(html_bytes.get()); |
207 } | 202 } |
OLD | NEW |