navigation_item_impl.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. #ifndef IOS_WEB_NAVIGATION_NAVIGATION_ITEM_IMPL_H_
  5. #define IOS_WEB_NAVIGATION_NAVIGATION_ITEM_IMPL_H_
  6. #import <Foundation/Foundation.h>
  7. #include <memory>
  8. #include <string>
  9. #include "base/time/time.h"
  10. #include "ios/web/public/favicon/favicon_status.h"
  11. #import "ios/web/public/navigation/navigation_item.h"
  12. #include "ios/web/public/navigation/referrer.h"
  13. #include "ios/web/public/security/ssl_status.h"
  14. #include "url/gurl.h"
  15. namespace web {
  16. class NavigationItemStorageBuilder;
  17. enum class NavigationInitiationType;
  18. // Implementation of NavigationItem.
  19. class NavigationItemImpl : public web::NavigationItem {
  20. public:
  21. // Creates a default NavigationItemImpl.
  22. NavigationItemImpl();
  23. ~NavigationItemImpl() override;
  24. // Since NavigationItemImpls own their facade delegates, there is no implicit
  25. // copy constructor (scoped_ptrs can't be copied), so one is defined here.
  26. NavigationItemImpl(const NavigationItemImpl& item);
  27. // NavigationItem implementation:
  28. int GetUniqueID() const override;
  29. void SetOriginalRequestURL(const GURL& url) override;
  30. const GURL& GetOriginalRequestURL() const override;
  31. void SetURL(const GURL& url) override;
  32. const GURL& GetURL() const override;
  33. void SetReferrer(const web::Referrer& referrer) override;
  34. const web::Referrer& GetReferrer() const override;
  35. void SetVirtualURL(const GURL& url) override;
  36. const GURL& GetVirtualURL() const override;
  37. void SetTitle(const std::u16string& title) override;
  38. const std::u16string& GetTitle() const override;
  39. void SetPageDisplayState(const PageDisplayState& display_state) override;
  40. const PageDisplayState& GetPageDisplayState() const override;
  41. const std::u16string& GetTitleForDisplay() const override;
  42. void SetTransitionType(ui::PageTransition transition_type) override;
  43. ui::PageTransition GetTransitionType() const override;
  44. const FaviconStatus& GetFaviconStatus() const override;
  45. void SetFaviconStatus(const FaviconStatus& favicon_status) override;
  46. const SSLStatus& GetSSL() const override;
  47. SSLStatus& GetSSL() override;
  48. void SetTimestamp(base::Time timestamp) override;
  49. base::Time GetTimestamp() const override;
  50. void SetUserAgentType(UserAgentType type) override;
  51. UserAgentType GetUserAgentType() const override;
  52. bool HasPostData() const override;
  53. NSDictionary* GetHttpRequestHeaders() const override;
  54. void AddHttpRequestHeaders(NSDictionary* additional_headers) override;
  55. void SetHttpsUpgradeType(HttpsUpgradeType https_upgrade_type) override;
  56. HttpsUpgradeType GetHttpsUpgradeType() const override;
  57. // Serialized representation of the state object that was used in conjunction
  58. // with a JavaScript window.history.pushState() or
  59. // window.history.replaceState() call that created or modified this
  60. // NavigationItem. Intended to be used for JavaScript history operations and
  61. // will be nil in most cases.
  62. void SetSerializedStateObject(NSString* serialized_state_object);
  63. NSString* GetSerializedStateObject() const;
  64. // Whether this navigation is the result of a hash change.
  65. void SetIsCreatedFromHashChange(bool hash_change);
  66. bool IsCreatedFromHashChange() const;
  67. // Initiation type of this pending navigation. Resets to NONE after commit.
  68. void SetNavigationInitiationType(
  69. web::NavigationInitiationType navigation_initiation_type);
  70. web::NavigationInitiationType NavigationInitiationType() const;
  71. // Whether or not to bypass showing the repost form confirmation when loading
  72. // a POST request. Set to YES for browser-generated POST requests.
  73. void SetShouldSkipRepostFormConfirmation(bool skip);
  74. bool ShouldSkipRepostFormConfirmation() const;
  75. // Whether or not to bypass serializing this item to session storage. Set to
  76. // YES to skip saving this page (and therefore restoring this page).
  77. void SetShouldSkipSerialization(bool skip);
  78. bool ShouldSkipSerialization() const;
  79. // Data submitted with a POST request, persisted for resubmits.
  80. void SetPostData(NSData* post_data);
  81. NSData* GetPostData() const;
  82. // Removes the header for |key| from |http_request_headers_|.
  83. void RemoveHttpRequestHeaderForKey(NSString* key);
  84. // Removes all http headers from |http_request_headers_|.
  85. void ResetHttpRequestHeaders();
  86. // Once a navigation item is committed, we should no longer track
  87. // non-persisted state, as documented on the members below.
  88. void ResetForCommit();
  89. // Returns the title string to be used for a page with |url| if that page
  90. // doesn't specify a title.
  91. static std::u16string GetDisplayTitleForURL(const GURL& url);
  92. // Used only by NavigationManagerImpl. SetUntrusted() is only used for
  93. // Visible or LastCommitted NavigationItems where the |url_| may be incorrect
  94. // due to timining problems or bugs in WKWebView.
  95. void SetUntrusted();
  96. bool IsUntrusted();
  97. // Restores the state of the |other| navigation item in this item.
  98. void RestoreStateFromItem(NavigationItem* other);
  99. #ifndef NDEBUG
  100. // Returns a human-readable description of the state for debugging purposes.
  101. NSString* GetDescription() const;
  102. #endif
  103. private:
  104. // The NavigationManItemStorageBuilder functions require access to
  105. // private variables of NavigationItemImpl.
  106. friend NavigationItemStorageBuilder;
  107. int unique_id_;
  108. GURL original_request_url_;
  109. GURL url_;
  110. Referrer referrer_;
  111. GURL virtual_url_;
  112. std::u16string title_;
  113. PageDisplayState page_display_state_;
  114. ui::PageTransition transition_type_;
  115. FaviconStatus favicon_status_;
  116. SSLStatus ssl_;
  117. base::Time timestamp_;
  118. UserAgentType user_agent_type_;
  119. NSMutableDictionary* http_request_headers_;
  120. NSString* serialized_state_object_;
  121. bool is_created_from_hash_change_;
  122. bool should_skip_repost_form_confirmation_;
  123. bool should_skip_serialization_;
  124. NSData* post_data_;
  125. // The navigation initiation type of the item. This decides whether the URL
  126. // should be displayed before the navigation commits. It is cleared in
  127. // |ResetForCommit| and not persisted.
  128. web::NavigationInitiationType navigation_initiation_type_;
  129. // Used only by NavigationManagerImpl. |is_untrusted_| is only |true| for
  130. // Visible or LastCommitted NavigationItems where the |url_| may be incorrect
  131. // due to timining problems or bugs in WKWebView.
  132. bool is_untrusted_;
  133. // This is a cached version of the result of GetTitleForDisplay. When the URL,
  134. // virtual URL, or title is set, this should be cleared to force a refresh.
  135. mutable std::u16string cached_display_title_;
  136. // Type of the HTTPS upgrade applied to this navigation, if any.
  137. HttpsUpgradeType https_upgrade_type_;
  138. // Copy and assignment is explicitly allowed for this class.
  139. };
  140. } // namespace web
  141. #endif // IOS_WEB_NAVIGATION_NAVIGATION_ITEM_IMPL_H_