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.
5 #ifndef IOS_WEB_NAVIGATION_NAVIGATION_ITEM_IMPL_H_
6 #define IOS_WEB_NAVIGATION_NAVIGATION_ITEM_IMPL_H_
8 #import <Foundation/Foundation.h>
10 #include "base/basictypes.h"
11 #include "base/mac/scoped_nsobject.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string16.h"
14 #include "ios/web/navigation/navigation_item_facade_delegate.h"
15 #include "ios/web/public/favicon_status.h"
16 #include "ios/web/public/navigation_item.h"
17 #include "ios/web/public/referrer.h"
18 #include "ios/web/public/ssl_status.h"
23 class NavigationItemFacadeDelegate
;
25 // Implementation of NavigationItem.
26 class NavigationItemImpl
: public web::NavigationItem
{
28 // Creates a default NavigationItemImpl.
30 ~NavigationItemImpl() override
;
32 // Since NavigationItemImpls own their facade delegates, there is no implicit
33 // copy constructor (scoped_ptrs can't be copied), so one is defined here.
34 NavigationItemImpl(const NavigationItemImpl
& item
);
36 // Accessors for the delegate used to drive the navigation entry facade.
37 // NOTE: to minimize facade synchronization code, NavigationItems take
38 // ownership of their facade delegates.
39 void SetFacadeDelegate(
40 scoped_ptr
<NavigationItemFacadeDelegate
> facade_delegate
);
41 NavigationItemFacadeDelegate
* GetFacadeDelegate() const;
43 // NavigationItem implementation:
44 int GetUniqueID() const override
;
45 void SetURL(const GURL
& url
) override
;
46 const GURL
& GetURL() const override
;
47 void SetReferrer(const web::Referrer
& referrer
) override
;
48 const web::Referrer
& GetReferrer() const override
;
49 void SetVirtualURL(const GURL
& url
) override
;
50 const GURL
& GetVirtualURL() const override
;
51 void SetTitle(const base::string16
& title
) override
;
52 const base::string16
& GetTitle() const override
;
53 void SetPageDisplayState(const PageDisplayState
& display_state
) override
;
54 const PageDisplayState
& GetPageDisplayState() const override
;
55 const base::string16
& GetTitleForDisplay(
56 const std::string
& languages
) const override
;
57 void SetTransitionType(ui::PageTransition transition_type
) override
;
58 ui::PageTransition
GetTransitionType() const override
;
59 const FaviconStatus
& GetFavicon() const override
;
60 FaviconStatus
& GetFavicon() override
;
61 const SSLStatus
& GetSSL() const override
;
62 SSLStatus
& GetSSL() override
;
63 void SetTimestamp(base::Time timestamp
) override
;
64 base::Time
GetTimestamp() const override
;
65 void SetUnsafe(bool is_unsafe
) override
;
66 bool IsUnsafe() const override
;
67 void SetIsOverridingUserAgent(bool is_overriding_user_agent
) override
;
68 bool IsOverridingUserAgent() const override
;
69 bool HasPostData() const override
;
70 NSDictionary
* GetHttpRequestHeaders() const override
;
71 void AddHttpRequestHeaders(NSDictionary
* additional_headers
) override
;
73 // Serialized representation of the state object that was used in conjunction
74 // with a JavaScript window.history.pushState() or
75 // window.history.replaceState() call that created or modified this
76 // CRWSessionEntry. Intended to be used for JavaScript history operations and
77 // will be nil in most cases.
78 void SetSerializedStateObject(NSString
* serialized_state_object
);
79 NSString
* GetSerializedStateObject() const;
81 // Whether or not this item was created by calling history.pushState().
82 void SetIsCreatedFromPushState(bool push_state
);
83 bool IsCreatedFromPushState() const;
85 // Whether or not to bypass showing the resubmit data confirmation when
86 // loading a POST request. Set to YES for browser-generated POST requests.
87 void SetShouldSkipResubmitDataConfirmation(bool skip
);
88 bool ShouldSkipResubmitDataConfirmation() const;
90 // Data submitted with a POST request, persisted for resubmits.
91 void SetPostData(NSData
* post_data
);
92 NSData
* GetPostData() const;
94 // Removes the header for |key| from |http_request_headers_|.
95 void RemoveHttpRequestHeaderForKey(NSString
* key
);
97 // Removes all http headers from |http_request_headers_|.
98 void ResetHttpRequestHeaders();
100 // Once a navigation item is committed, we should no longer track
101 // non-persisted state, as documented on the members below.
102 void ResetForCommit();
104 // Whether this (pending) navigation is renderer-initiated. Resets to false
105 // for all types of navigations after commit.
106 void set_is_renderer_initiated(bool is_renderer_initiated
) {
107 is_renderer_initiated_
= is_renderer_initiated
;
109 bool is_renderer_initiated() const { return is_renderer_initiated_
; }
116 base::string16 title_
;
117 PageDisplayState page_display_state_
;
118 ui::PageTransition transition_type_
;
119 FaviconStatus favicon_
;
121 base::Time timestamp_
;
122 bool is_overriding_user_agent_
;
123 base::scoped_nsobject
<NSMutableDictionary
> http_request_headers_
;
125 base::scoped_nsobject
<NSString
> serialized_state_object_
;
126 bool is_created_from_push_state_
;
127 bool should_skip_resubmit_data_confirmation_
;
128 base::scoped_nsobject
<NSData
> post_data_
;
130 // Whether the item, while loading, was created for a renderer-initiated
131 // navigation. This dictates whether the URL should be displayed before the
132 // navigation commits. It is cleared in |ResetForCommit| and not persisted.
133 bool is_renderer_initiated_
;
135 // Whether the navigation contains unsafe resources.
138 // This is a cached version of the result of GetTitleForDisplay. When the URL,
139 // virtual URL, or title is set, this should be cleared to force a refresh.
140 mutable base::string16 cached_display_title_
;
142 // Weak pointer to the facade delegate.
143 scoped_ptr
<NavigationItemFacadeDelegate
> facade_delegate_
;
145 // Copy and assignment is explicitly allowed for this class.
150 #endif // IOS_WEB_NAVIGATION_NAVIGATION_ITEM_IMPL_H_