Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ios / web / navigation / crw_session_controller.h
blob5e0d583954975ca8f0f7501e051f0ba3fa1e6150
1 // Copyright 2012 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_CRW_SESSION_CONTROLLER_H_
6 #define IOS_WEB_NAVIGATION_CRW_SESSION_CONTROLLER_H_
8 #import <Foundation/Foundation.h>
9 #include <vector>
11 #include "ui/base/page_transition_types.h"
12 #include "url/gurl.h"
14 @class CRWSessionEntry;
15 @class CRWSessionCertificatePolicyManager;
16 @class XCallbackParameters;
18 namespace web {
19 class NavigationManagerImpl;
20 struct Referrer;
21 struct SSLStatus;
24 // A CRWSessionController is similar to a NavigationController object in desktop
25 // Chrome. It maintains information needed to save/restore a tab with its
26 // complete session history. There is one of these for each tab.
27 // TODO(stuartmorgan): Move under NavigationManager, and consider merging into
28 // NavigationManager.
29 @interface CRWSessionController : NSObject<NSCoding, NSCopying>
31 @property(nonatomic, readonly, retain) NSString* tabId;
32 @property(nonatomic, readonly, assign) NSInteger currentNavigationIndex;
33 @property(nonatomic, readonly, assign) NSInteger previousNavigationIndex;
34 @property(nonatomic, readonly, retain) NSArray* entries;
35 @property(nonatomic, copy) NSString* windowName;
36 // Indicates whether the page was opened by DOM (e.g. with |window.open|
37 // JavaScript call or by clicking a link with |_blank| target).
38 @property(nonatomic, readonly, getter=isOpenedByDOM) BOOL openedByDOM;
39 @property(nonatomic, readonly, retain)
40 CRWSessionCertificatePolicyManager* sessionCertificatePolicyManager;
41 // Returns the current entry in the session list, or the pending entry if there
42 // is a navigation in progress.
43 @property(nonatomic, readonly) CRWSessionEntry* currentEntry;
44 // Returns the entry that should be displayed to users (e.g., in the omnibox).
45 @property(nonatomic, readonly) CRWSessionEntry* visibleEntry;
46 // Returns the pending entry, if any.
47 @property(nonatomic, readonly) CRWSessionEntry* pendingEntry;
48 // Returns the transient entry, if any.
49 @property(nonatomic, readonly) CRWSessionEntry* transientEntry;
50 // Returns the last committed entry.
51 @property(nonatomic, readonly) CRWSessionEntry* lastCommittedEntry;
52 // Returns the previous entry in the session list, or nil if there isn't any.
53 @property(nonatomic, readonly) CRWSessionEntry* previousEntry;
54 @property(nonatomic, assign) NSTimeInterval lastVisitedTimestamp;
55 @property(nonatomic, readonly, copy) NSString* openerId;
56 @property(nonatomic, readonly, assign) NSInteger openerNavigationIndex;
57 @property(nonatomic, retain) XCallbackParameters* xCallbackParameters;
59 // CRWSessionController doesn't have public constructors. New
60 // CRWSessionControllers are created by deserialization, or via a
61 // NavigationManager.
63 // Sets the corresponding NavigationManager.
64 - (void)setNavigationManager:(web::NavigationManagerImpl*)navigationManager;
66 // Add a new entry with the given url, referrer, and navigation type, making it
67 // the current entry. If |url| is the same as the current entry's url, this
68 // does nothing. |referrer| may be nil if there isn't one. The entry starts
69 // out as pending, and will be lost unless |-commitPendingEntry| is called.
70 - (void)addPendingEntry:(const GURL&)url
71 referrer:(const web::Referrer&)referrer
72 transition:(ui::PageTransition)type
73 rendererInitiated:(BOOL)rendererInitiated;
75 // Updates the URL of the yet to be committed pending entry. Useful for page
76 // redirects. Does nothing if there is no pending entry.
77 - (void)updatePendingEntry:(const GURL&)url;
79 // Commits the current pending entry. No changes are made to the entry during
80 // this process, it is just moved from pending to committed.
81 // TODO(pinkerton): Desktop Chrome broadcasts a notification here, should we?
82 - (void)commitPendingEntry;
84 // Adds a transient entry with the given information. A transient entry will be
85 // discarded on any navigation.
86 // TODO(stuartmorgan): Make this work more like upstream, where the entry can
87 // be made from outside and then handed in, instead of having to pass a bunch
88 // of construction params here.
89 - (void)addTransientEntry:(const GURL&)url
90 title:(const base::string16&)title
91 sslStatus:(const web::SSLStatus*)status;
93 // Creates a new CRWSessionEntry with the given URL and state object. A state
94 // object is a serialized generic JavaScript object that contains details of the
95 // UI's state for a given CRWSessionEntry/URL. The current entry's URL is the
96 // new entry's referrer.
97 - (void)pushNewEntryWithURL:(const GURL&)URL
98 stateObject:(NSString*)stateObject
99 transition:(ui::PageTransition)transition;
101 // Updates the URL and state object for the current entry.
102 - (void)updateCurrentEntryWithURL:(const GURL&)url
103 stateObject:(NSString*)stateObject;
105 - (void)discardNonCommittedEntries;
107 // Returns YES if there is a pending entry.
108 - (BOOL)hasPendingEntry;
110 // Copies history state from the given CRWSessionController and adds it to this
111 // controller. If |replaceState|, replaces the state of this controller with
112 // the state of |otherSession|, instead of appending.
113 - (void)copyStateFromAndPrune:(CRWSessionController*)otherSession
114 replaceState:(BOOL)replaceState;
116 // Returns YES if there are entries to go back or forward to, given the
117 // current entry.
118 - (BOOL)canGoBack;
119 - (BOOL)canGoForward;
120 // Adjusts the current entry to reflect the navigation in the corresponding
121 // direction in history.
122 - (void)goBack;
123 - (void)goForward;
124 // Calls goBack or goForward the appropriate number of times to adjust
125 // currentNavigationIndex_ by delta.
126 - (void)goDelta:(int)delta;
127 // Sets |currentNavigationIndex_| to the index of |entry| if |entries_| contains
128 // |entry|.
129 - (void)goToEntry:(CRWSessionEntry*)entry;
131 // Removes the entry at |index| after discarding any noncomitted entries.
132 // |index| must not be the index of the last committed entry, or a noncomitted
133 // entry.
134 - (void)removeEntryAtIndex:(NSInteger)index;
136 // Returns an array containing all of the non-redirected CRWSessionEntry objects
137 // whose index in |entries_| is less than |currentNavigationIndex_|.
138 - (NSArray*)backwardEntries;
140 // Returns an array containing all of the non-redirected CRWSessionEntry objects
141 // whose index in |entries_| is greater than |currentNavigationIndex_|.
142 - (NSArray*)forwardEntries;
144 // Returns the URLs in the entries that are redirected to the current entry.
145 - (std::vector<GURL>)currentRedirectedUrls;
147 // Determines if navigation between the two given entries is a push state
148 // navigation. Entries can be passed in in any order.
149 - (BOOL)isPushStateNavigationBetweenEntry:(CRWSessionEntry*)firstEntry
150 andEntry:(CRWSessionEntry*)secondEntry;
152 // Find the most recent session entry that is not a redirect. Returns nil if
153 // |entries_| is empty.
154 - (CRWSessionEntry*)lastUserEntry;
156 // Set |useDesktopUserAgentForNextPendingEntry_| to YES if there is no pending
157 // entry, otherwise set |useDesktopUserAgent| in the pending entry.
158 - (void)useDesktopUserAgentForNextPendingEntry;
160 @end
162 #endif // IOS_WEB_NAVIGATION_CRW_SESSION_CONTROLLER_H_