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 SetPageID(int page_id
) override
;
54 int32
GetPageID() const override
;
55 void SetPageScrollState(const PageScrollState
& scroll_state
) override
;
56 const PageScrollState
& GetPageScrollState() const override
;
57 const base::string16
& GetTitleForDisplay(
58 const std::string
& languages
) const override
;
59 void SetTransitionType(ui::PageTransition transition_type
) override
;
60 ui::PageTransition
GetTransitionType() const override
;
61 const FaviconStatus
& GetFavicon() const override
;
62 FaviconStatus
& GetFavicon() override
;
63 const SSLStatus
& GetSSL() const override
;
64 SSLStatus
& GetSSL() override
;
65 void SetTimestamp(base::Time timestamp
) override
;
66 base::Time
GetTimestamp() const override
;
67 void SetUnsafe(bool is_unsafe
) override
;
68 bool IsUnsafe() const override
;
69 void SetIsOverridingUserAgent(bool is_overriding_user_agent
) override
;
70 bool IsOverridingUserAgent() const override
;
71 bool HasPostData() const override
;
72 NSDictionary
* GetHttpRequestHeaders() const override
;
73 void AddHttpRequestHeaders(NSDictionary
* additional_headers
) override
;
75 // Serialized representation of the state object that was used in conjunction
76 // with a JavaScript window.history.pushState() or
77 // window.history.replaceState() call that created or modified this
78 // CRWSessionEntry. Intended to be used for JavaScript history operations and
79 // will be nil in most cases.
80 void SetSerializedStateObject(NSString
* serialized_state_object
);
81 NSString
* GetSerializedStateObject() const;
83 // Whether or not this item was created by calling history.pushState().
84 void SetIsCreatedFromPushState(bool push_state
);
85 bool IsCreatedFromPushState() const;
87 // Whether or not to bypass showing the resubmit data confirmation when
88 // loading a POST request. Set to YES for browser-generated POST requests.
89 void SetShouldSkipResubmitDataConfirmation(bool skip
);
90 bool ShouldSkipResubmitDataConfirmation() const;
92 // Data submitted with a POST request, persisted for resubmits.
93 void SetPostData(NSData
* post_data
);
94 NSData
* GetPostData() const;
96 // Removes the header for |key| from |http_request_headers_|.
97 void RemoveHttpRequestHeaderForKey(NSString
* key
);
99 // Removes all http headers from |http_request_headers_|.
100 void ResetHttpRequestHeaders();
102 // Once a navigation item is committed, we should no longer track
103 // non-persisted state, as documented on the members below.
104 void ResetForCommit();
106 // Whether this (pending) navigation is renderer-initiated. Resets to false
107 // for all types of navigations after commit.
108 void set_is_renderer_initiated(bool is_renderer_initiated
) {
109 is_renderer_initiated_
= is_renderer_initiated
;
111 bool is_renderer_initiated() const { return is_renderer_initiated_
; }
118 base::string16 title_
;
120 PageScrollState page_scroll_state_
;
121 ui::PageTransition transition_type_
;
122 FaviconStatus favicon_
;
124 base::Time timestamp_
;
125 bool is_overriding_user_agent_
;
126 base::scoped_nsobject
<NSMutableDictionary
> http_request_headers_
;
128 base::scoped_nsobject
<NSString
> serialized_state_object_
;
129 bool is_created_from_push_state_
;
130 bool should_skip_resubmit_data_confirmation_
;
131 base::scoped_nsobject
<NSData
> post_data_
;
133 // Whether the item, while loading, was created for a renderer-initiated
134 // navigation. This dictates whether the URL should be displayed before the
135 // navigation commits. It is cleared in |ResetForCommit| and not persisted.
136 bool is_renderer_initiated_
;
138 // Whether the navigation contains unsafe resources.
141 // This is a cached version of the result of GetTitleForDisplay. When the URL,
142 // virtual URL, or title is set, this should be cleared to force a refresh.
143 mutable base::string16 cached_display_title_
;
145 // Weak pointer to the facade delegate.
146 scoped_ptr
<NavigationItemFacadeDelegate
> facade_delegate_
;
148 // Copy and assignment is explicitly allowed for this class.
153 #endif // IOS_WEB_NAVIGATION_NAVIGATION_ITEM_IMPL_H_