content_serialized_navigation_driver.cc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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
  3. // found in the LICENSE file.
  4. #include "components/sessions/content/content_serialized_navigation_driver.h"
  5. #include <utility>
  6. #include "base/memory/singleton.h"
  7. #include "components/sessions/core/serialized_navigation_entry.h"
  8. #include "services/network/public/mojom/referrer_policy.mojom.h"
  9. #include "third_party/blink/public/common/page_state/page_state.h"
  10. namespace sessions {
  11. namespace {
  12. ContentSerializedNavigationDriver* g_instance = nullptr;
  13. } // namespace
  14. // static
  15. SerializedNavigationDriver* SerializedNavigationDriver::Get() {
  16. return ContentSerializedNavigationDriver::GetInstance();
  17. }
  18. // static
  19. ContentSerializedNavigationDriver*
  20. ContentSerializedNavigationDriver::GetInstance() {
  21. if (g_instance)
  22. return g_instance;
  23. auto* instance = base::Singleton<
  24. ContentSerializedNavigationDriver,
  25. base::LeakySingletonTraits<ContentSerializedNavigationDriver>>::get();
  26. g_instance = instance;
  27. return instance;
  28. }
  29. // static
  30. void ContentSerializedNavigationDriver::SetInstance(
  31. ContentSerializedNavigationDriver* instance) {
  32. DCHECK(!g_instance || !instance);
  33. g_instance = instance;
  34. }
  35. ContentSerializedNavigationDriver::ContentSerializedNavigationDriver() {
  36. }
  37. ContentSerializedNavigationDriver::~ContentSerializedNavigationDriver() {
  38. }
  39. int ContentSerializedNavigationDriver::GetDefaultReferrerPolicy() const {
  40. return static_cast<int>(network::mojom::ReferrerPolicy::kDefault);
  41. }
  42. std::string
  43. ContentSerializedNavigationDriver::GetSanitizedPageStateForPickle(
  44. const SerializedNavigationEntry* navigation) const {
  45. if (!navigation->has_post_data())
  46. return navigation->encoded_page_state();
  47. blink::PageState page_state =
  48. blink::PageState::CreateFromEncodedData(navigation->encoded_page_state());
  49. return page_state.RemovePasswordData().ToEncodedData();
  50. }
  51. void ContentSerializedNavigationDriver::Sanitize(
  52. SerializedNavigationEntry* navigation) const {
  53. }
  54. std::string ContentSerializedNavigationDriver::StripReferrerFromPageState(
  55. const std::string& page_state) const {
  56. return blink::PageState::CreateFromEncodedData(page_state)
  57. .RemoveReferrer()
  58. .ToEncodedData();
  59. }
  60. void ContentSerializedNavigationDriver::RegisterExtendedInfoHandler(
  61. const std::string& key,
  62. std::unique_ptr<ExtendedInfoHandler> handler) {
  63. DCHECK(!key.empty());
  64. DCHECK(!extended_info_handler_map_.count(key));
  65. DCHECK(handler);
  66. extended_info_handler_map_[key] = std::move(handler);
  67. }
  68. const ContentSerializedNavigationDriver::ExtendedInfoHandlerMap&
  69. ContentSerializedNavigationDriver::GetAllExtendedInfoHandlers() const {
  70. return extended_info_handler_map_;
  71. }
  72. } // namespace sessions