insecure_form_controller_client.cc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2020 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/insecure_form_controller_client.h"
  5. #include "components/security_interstitials/content/insecure_form_tab_storage.h"
  6. #include "components/security_interstitials/content/settings_page_helper.h"
  7. #include "content/public/browser/web_contents.h"
  8. #include "weblayer/browser/i18n_util.h"
  9. namespace weblayer {
  10. // static
  11. std::unique_ptr<security_interstitials::MetricsHelper>
  12. InsecureFormControllerClient::GetMetricsHelper(const GURL& url) {
  13. security_interstitials::MetricsHelper::ReportDetails settings;
  14. settings.metric_prefix = "insecure_form";
  15. return std::make_unique<security_interstitials::MetricsHelper>(url, settings,
  16. nullptr);
  17. }
  18. // static
  19. std::unique_ptr<security_interstitials::SettingsPageHelper>
  20. InsecureFormControllerClient::GetSettingsPageHelper() {
  21. // Return nullptr since there is no enhanced protection message in insecure
  22. // form interstitials.
  23. return nullptr;
  24. }
  25. InsecureFormControllerClient::InsecureFormControllerClient(
  26. content::WebContents* web_contents,
  27. const GURL& form_target_url)
  28. : SecurityInterstitialControllerClient(
  29. web_contents,
  30. GetMetricsHelper(form_target_url),
  31. nullptr, /* prefs */
  32. i18n::GetApplicationLocale(),
  33. GURL("about:blank") /* default_safe_page */,
  34. GetSettingsPageHelper()),
  35. web_contents_(web_contents) {}
  36. InsecureFormControllerClient::~InsecureFormControllerClient() = default;
  37. void InsecureFormControllerClient::GoBack() {
  38. SecurityInterstitialControllerClient::GoBackAfterNavigationCommitted();
  39. }
  40. void InsecureFormControllerClient::Proceed() {
  41. // Set the is_proceeding flag on the tab storage so reload doesn't trigger
  42. // another interstitial.
  43. security_interstitials::InsecureFormTabStorage* tab_storage =
  44. security_interstitials::InsecureFormTabStorage::GetOrCreate(
  45. web_contents_);
  46. tab_storage->SetIsProceeding(true);
  47. // We don't check for repost on the proceed reload since the interstitial
  48. // explains this will submit the form.
  49. web_contents_->GetController().Reload(content::ReloadType::NORMAL, false);
  50. }
  51. } // namespace weblayer