ssl_error_controller_client.cc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2019 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. #include "weblayer/browser/ssl_error_controller_client.h"
  5. #include "base/task/thread_pool.h"
  6. #include "build/build_config.h"
  7. #include "components/security_interstitials/content/settings_page_helper.h"
  8. #include "components/security_interstitials/content/utils.h"
  9. #include "components/security_interstitials/core/metrics_helper.h"
  10. #include "content/public/browser/browser_context.h"
  11. #include "content/public/browser/browser_thread.h"
  12. #include "content/public/browser/ssl_host_state_delegate.h"
  13. #include "content/public/browser/web_contents.h"
  14. #include "weblayer/browser/i18n_util.h"
  15. #include "weblayer/browser/tab_impl.h"
  16. #include "weblayer/public/error_page_delegate.h"
  17. namespace weblayer {
  18. SSLErrorControllerClient::SSLErrorControllerClient(
  19. content::WebContents* web_contents,
  20. int cert_error,
  21. const net::SSLInfo& ssl_info,
  22. const GURL& request_url,
  23. std::unique_ptr<security_interstitials::MetricsHelper> metrics_helper,
  24. std::unique_ptr<security_interstitials::SettingsPageHelper>
  25. settings_page_helper)
  26. : security_interstitials::SecurityInterstitialControllerClient(
  27. web_contents,
  28. std::move(metrics_helper),
  29. nullptr /*prefs*/,
  30. i18n::GetApplicationLocale(),
  31. GURL("about:blank") /*default_safe_page*/,
  32. std::move(settings_page_helper)),
  33. cert_error_(cert_error),
  34. ssl_info_(ssl_info),
  35. request_url_(request_url) {}
  36. void SSLErrorControllerClient::GoBack() {
  37. ErrorPageDelegate* delegate =
  38. TabImpl::FromWebContents(web_contents_)->error_page_delegate();
  39. if (delegate && delegate->OnBackToSafety())
  40. return;
  41. SecurityInterstitialControllerClient::GoBackAfterNavigationCommitted();
  42. }
  43. void SSLErrorControllerClient::Proceed() {
  44. web_contents_->GetBrowserContext()->GetSSLHostStateDelegate()->AllowCert(
  45. request_url_.host(), *ssl_info_.cert.get(), cert_error_,
  46. web_contents_->GetPrimaryMainFrame()->GetStoragePartition());
  47. Reload();
  48. }
  49. void SSLErrorControllerClient::OpenUrlInNewForegroundTab(const GURL& url) {
  50. // For now WebLayer doesn't support multiple tabs, so just open the Learn
  51. // More link in the current tab.
  52. OpenUrlInCurrentTab(url);
  53. }
  54. bool SSLErrorControllerClient::CanLaunchDateAndTimeSettings() {
  55. return true;
  56. }
  57. void SSLErrorControllerClient::LaunchDateAndTimeSettings() {
  58. DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
  59. base::ThreadPool::PostTask(
  60. FROM_HERE, {base::TaskPriority::USER_VISIBLE, base::MayBlock()},
  61. base::BindOnce(&security_interstitials::LaunchDateAndTimeSettings));
  62. }
  63. } // namespace weblayer