| 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/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 } | 58 } |
| 59 | 59 |
| 60 return net::X509Certificate::CreateFromBytes(cert_der.data(), | 60 return net::X509Certificate::CreateFromBytes(cert_der.data(), |
| 61 cert_der.size()); | 61 cert_der.size()); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // Implementation of chrome://interstitials demonstration pages. This code is | 64 // Implementation of chrome://interstitials demonstration pages. This code is |
| 65 // not used in displaying any real interstitials. | 65 // not used in displaying any real interstitials. |
| 66 class InterstitialHTMLSource : public content::URLDataSource { | 66 class InterstitialHTMLSource : public content::URLDataSource { |
| 67 public: | 67 public: |
| 68 explicit InterstitialHTMLSource(content::WebContents* web_contents); | 68 InterstitialHTMLSource() {} |
| 69 ~InterstitialHTMLSource() override; | 69 ~InterstitialHTMLSource() override {} |
| 70 | 70 |
| 71 // content::URLDataSource: | 71 // content::URLDataSource: |
| 72 std::string GetMimeType(const std::string& mime_type) const override; | 72 std::string GetMimeType(const std::string& mime_type) const override; |
| 73 std::string GetSource() const override; | 73 std::string GetSource() const override; |
| 74 std::string GetContentSecurityPolicyScriptSrc() const override; | 74 std::string GetContentSecurityPolicyScriptSrc() const override; |
| 75 std::string GetContentSecurityPolicyStyleSrc() const override; | 75 std::string GetContentSecurityPolicyStyleSrc() const override; |
| 76 std::string GetContentSecurityPolicyImgSrc() const override; | 76 std::string GetContentSecurityPolicyImgSrc() const override; |
| 77 void StartDataRequest( | 77 void StartDataRequest( |
| 78 const std::string& path, | 78 const std::string& path, |
| 79 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, | 79 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
| 80 const content::URLDataSource::GotDataCallback& callback) override; | 80 const content::URLDataSource::GotDataCallback& callback) override; |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 content::WebContents* web_contents_; | |
| 84 DISALLOW_COPY_AND_ASSIGN(InterstitialHTMLSource); | 83 DISALLOW_COPY_AND_ASSIGN(InterstitialHTMLSource); |
| 85 }; | 84 }; |
| 86 | 85 |
| 87 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | 86 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 88 // Provides fake connection information to the captive portal blocking page so | 87 // Provides fake connection information to the captive portal blocking page so |
| 89 // that both Wi-Fi and non Wi-Fi blocking pages can be displayed. | 88 // that both Wi-Fi and non Wi-Fi blocking pages can be displayed. |
| 90 class CaptivePortalBlockingPageWithNetInfo : public CaptivePortalBlockingPage { | 89 class CaptivePortalBlockingPageWithNetInfo : public CaptivePortalBlockingPage { |
| 91 public: | 90 public: |
| 92 CaptivePortalBlockingPageWithNetInfo( | 91 CaptivePortalBlockingPageWithNetInfo( |
| 93 content::WebContents* web_contents, | 92 content::WebContents* web_contents, |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 base::Callback<void(content::CertificateRequestResultType)>(), | 300 base::Callback<void(content::CertificateRequestResultType)>(), |
| 302 is_wifi_connection, wifi_ssid); | 301 is_wifi_connection, wifi_ssid); |
| 303 return blocking_page; | 302 return blocking_page; |
| 304 } | 303 } |
| 305 #endif | 304 #endif |
| 306 | 305 |
| 307 } // namespace | 306 } // namespace |
| 308 | 307 |
| 309 InterstitialUI::InterstitialUI(content::WebUI* web_ui) | 308 InterstitialUI::InterstitialUI(content::WebUI* web_ui) |
| 310 : WebUIController(web_ui) { | 309 : WebUIController(web_ui) { |
| 311 std::unique_ptr<InterstitialHTMLSource> html_source( | |
| 312 new InterstitialHTMLSource(web_ui->GetWebContents())); | |
| 313 Profile* profile = Profile::FromWebUI(web_ui); | 310 Profile* profile = Profile::FromWebUI(web_ui); |
| 314 content::URLDataSource::Add(profile, html_source.release()); | 311 content::URLDataSource::Add(profile, new InterstitialHTMLSource()); |
| 315 } | 312 } |
| 316 | 313 |
| 317 InterstitialUI::~InterstitialUI() { | 314 InterstitialUI::~InterstitialUI() { |
| 318 } | 315 } |
| 319 | 316 |
| 320 // InterstitialHTMLSource | 317 // InterstitialHTMLSource |
| 321 | 318 |
| 322 InterstitialHTMLSource::InterstitialHTMLSource( | |
| 323 content::WebContents* web_contents) | |
| 324 : web_contents_(web_contents) { | |
| 325 } | |
| 326 | |
| 327 InterstitialHTMLSource::~InterstitialHTMLSource() { | |
| 328 } | |
| 329 | |
| 330 std::string InterstitialHTMLSource::GetMimeType( | 319 std::string InterstitialHTMLSource::GetMimeType( |
| 331 const std::string& mime_type) const { | 320 const std::string& mime_type) const { |
| 332 return "text/html"; | 321 return "text/html"; |
| 333 } | 322 } |
| 334 | 323 |
| 335 std::string InterstitialHTMLSource::GetSource() const { | 324 std::string InterstitialHTMLSource::GetSource() const { |
| 336 return chrome::kChromeUIInterstitialHost; | 325 return chrome::kChromeUIInterstitialHost; |
| 337 } | 326 } |
| 338 | 327 |
| 339 std::string InterstitialHTMLSource::GetContentSecurityPolicyScriptSrc() const { | 328 std::string InterstitialHTMLSource::GetContentSecurityPolicyScriptSrc() const { |
| 340 // 'unsafe-inline' is added to script-src. | 329 // 'unsafe-inline' is added to script-src. |
| 341 return "script-src chrome://resources 'self' 'unsafe-eval' 'unsafe-inline';"; | 330 return "script-src chrome://resources 'self' 'unsafe-eval' 'unsafe-inline';"; |
| 342 } | 331 } |
| 343 | 332 |
| 344 std::string InterstitialHTMLSource::GetContentSecurityPolicyStyleSrc() const { | 333 std::string InterstitialHTMLSource::GetContentSecurityPolicyStyleSrc() const { |
| 345 return "style-src 'self' 'unsafe-inline';"; | 334 return "style-src 'self' 'unsafe-inline';"; |
| 346 } | 335 } |
| 347 | 336 |
| 348 std::string InterstitialHTMLSource::GetContentSecurityPolicyImgSrc() const { | 337 std::string InterstitialHTMLSource::GetContentSecurityPolicyImgSrc() const { |
| 349 return "img-src data:;"; | 338 return "img-src data:;"; |
| 350 } | 339 } |
| 351 | 340 |
| 352 void InterstitialHTMLSource::StartDataRequest( | 341 void InterstitialHTMLSource::StartDataRequest( |
| 353 const std::string& path, | 342 const std::string& path, |
| 354 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, | 343 const content::ResourceRequestInfo::WebContentsGetter& wc_getter, |
| 355 const content::URLDataSource::GotDataCallback& callback) { | 344 const content::URLDataSource::GotDataCallback& callback) { |
| 345 content::WebContents* web_contents = wc_getter.Run(); |
| 356 std::unique_ptr<content::InterstitialPageDelegate> interstitial_delegate; | 346 std::unique_ptr<content::InterstitialPageDelegate> interstitial_delegate; |
| 357 if (base::StartsWith(path, "ssl", base::CompareCase::SENSITIVE)) { | 347 if (base::StartsWith(path, "ssl", base::CompareCase::SENSITIVE)) { |
| 358 interstitial_delegate.reset(CreateSSLBlockingPage(web_contents_)); | 348 interstitial_delegate.reset(CreateSSLBlockingPage(web_contents)); |
| 359 } else if (base::StartsWith(path, "safebrowsing", | 349 } else if (base::StartsWith(path, "safebrowsing", |
| 360 base::CompareCase::SENSITIVE)) { | 350 base::CompareCase::SENSITIVE)) { |
| 361 interstitial_delegate.reset(CreateSafeBrowsingBlockingPage(web_contents_)); | 351 interstitial_delegate.reset(CreateSafeBrowsingBlockingPage(web_contents)); |
| 362 } else if (base::StartsWith(path, "clock", base::CompareCase::SENSITIVE)) { | 352 } else if (base::StartsWith(path, "clock", base::CompareCase::SENSITIVE)) { |
| 363 interstitial_delegate.reset(CreateBadClockBlockingPage(web_contents_)); | 353 interstitial_delegate.reset(CreateBadClockBlockingPage(web_contents)); |
| 364 } | 354 } |
| 365 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) | 355 #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 366 else if (base::StartsWith(path, "captiveportal", | 356 else if (base::StartsWith(path, "captiveportal", |
| 367 base::CompareCase::SENSITIVE)) | 357 base::CompareCase::SENSITIVE)) |
| 368 { | 358 { |
| 369 interstitial_delegate.reset(CreateCaptivePortalBlockingPage(web_contents_)); | 359 interstitial_delegate.reset(CreateCaptivePortalBlockingPage(web_contents)); |
| 370 } | 360 } |
| 371 #endif | 361 #endif |
| 372 std::string html; | 362 std::string html; |
| 373 if (interstitial_delegate.get()) { | 363 if (interstitial_delegate.get()) { |
| 374 html = interstitial_delegate.get()->GetHTMLContents(); | 364 html = interstitial_delegate.get()->GetHTMLContents(); |
| 375 } else { | 365 } else { |
| 376 html = ResourceBundle::GetSharedInstance() | 366 html = ResourceBundle::GetSharedInstance() |
| 377 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) | 367 .GetRawDataResource(IDR_SECURITY_INTERSTITIAL_UI_HTML) |
| 378 .as_string(); | 368 .as_string(); |
| 379 } | 369 } |
| 380 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; | 370 scoped_refptr<base::RefCountedString> html_bytes = new base::RefCountedString; |
| 381 html_bytes->data().assign(html.begin(), html.end()); | 371 html_bytes->data().assign(html.begin(), html.end()); |
| 382 callback.Run(html_bytes.get()); | 372 callback.Run(html_bytes.get()); |
| 383 } | 373 } |
| OLD | NEW |