OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/web/navigation/crw_session_controller.h" | 5 #import "ios/web/navigation/crw_session_controller.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 #if !defined(__has_feature) || !__has_feature(objc_arc) | 31 #if !defined(__has_feature) || !__has_feature(objc_arc) |
32 #error "This file requires ARC support." | 32 #error "This file requires ARC support." |
33 #endif | 33 #endif |
34 | 34 |
35 @interface CRWSessionController () { | 35 @interface CRWSessionController () { |
36 // Weak pointer back to the owning NavigationManager. This is to facilitate | 36 // Weak pointer back to the owning NavigationManager. This is to facilitate |
37 // the incremental merging of the two classes. | 37 // the incremental merging of the two classes. |
38 web::NavigationManagerImpl* _navigationManager; | 38 web::NavigationManagerImpl* _navigationManager; |
39 | 39 |
40 NSString* _openerId; // Id of tab who opened this tab, empty/nil if none. | |
41 // Navigation index of the tab which opened this tab. Do not rely on the | |
42 // value of this member variable to indicate whether or not this tab has | |
43 // an opener, as both 0 and -1 are used as navigationIndex values. | |
44 NSInteger _openerNavigationIndex; | |
45 // Identifies the index of the current navigation in the CRWSessionEntry | 40 // Identifies the index of the current navigation in the CRWSessionEntry |
46 // array. | 41 // array. |
47 NSInteger _currentNavigationIndex; | 42 NSInteger _currentNavigationIndex; |
48 // Identifies the index of the previous navigation in the CRWSessionEntry | 43 // Identifies the index of the previous navigation in the CRWSessionEntry |
49 // array. | 44 // array. |
50 NSInteger _previousNavigationIndex; | 45 NSInteger _previousNavigationIndex; |
51 // Ordered array of |CRWSessionEntry| objects, one for each site in session | 46 // Ordered array of |CRWSessionEntry| objects, one for each site in session |
52 // history. End of the list is the most recent load. | 47 // history. End of the list is the most recent load. |
53 NSMutableArray* _entries; | 48 NSMutableArray* _entries; |
54 | 49 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 82 |
88 // TODO(rohitrao): These properties must be redefined readwrite to work around a | 83 // TODO(rohitrao): These properties must be redefined readwrite to work around a |
89 // clang bug. crbug.com/228650 | 84 // clang bug. crbug.com/228650 |
90 @property(nonatomic, readwrite, strong) NSArray* entries; | 85 @property(nonatomic, readwrite, strong) NSArray* entries; |
91 @property(nonatomic, readwrite, strong) | 86 @property(nonatomic, readwrite, strong) |
92 CRWSessionCertificatePolicyManager* sessionCertificatePolicyManager; | 87 CRWSessionCertificatePolicyManager* sessionCertificatePolicyManager; |
93 | 88 |
94 // Expose setters for serialization properties. These are exposed in a category | 89 // Expose setters for serialization properties. These are exposed in a category |
95 // in SessionStorageBuilder, and will be removed as ownership of | 90 // in SessionStorageBuilder, and will be removed as ownership of |
96 // their backing ivars moves to NavigationManagerImpl. | 91 // their backing ivars moves to NavigationManagerImpl. |
97 @property(nonatomic, readwrite, copy) NSString* openerId; | |
98 @property(nonatomic, readwrite, getter=isOpenedByDOM) BOOL openedByDOM; | 92 @property(nonatomic, readwrite, getter=isOpenedByDOM) BOOL openedByDOM; |
99 @property(nonatomic, readwrite, assign) NSInteger openerNavigationIndex; | |
100 @property(nonatomic, readwrite, assign) NSInteger previousNavigationIndex; | 93 @property(nonatomic, readwrite, assign) NSInteger previousNavigationIndex; |
101 | 94 |
102 // Removes all entries after currentNavigationIndex_. | 95 // Removes all entries after currentNavigationIndex_. |
103 - (void)clearForwardItems; | 96 - (void)clearForwardItems; |
104 // Discards the transient entry, if any. | 97 // Discards the transient entry, if any. |
105 - (void)discardTransientItem; | 98 - (void)discardTransientItem; |
106 // Create a new autoreleased session entry. | 99 // Create a new autoreleased session entry. |
107 - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url | 100 - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url |
108 referrer:(const web::Referrer&)referrer | 101 referrer:(const web::Referrer&)referrer |
109 transition:(ui::PageTransition)transition | 102 transition:(ui::PageTransition)transition |
110 initiationType: | 103 initiationType: |
111 (web::NavigationInitiationType)initiationType; | 104 (web::NavigationInitiationType)initiationType; |
112 // Returns YES if the PageTransition for the underlying navigationItem at | 105 // Returns YES if the PageTransition for the underlying navigationItem at |
113 // |index| in |entries_| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK. | 106 // |index| in |entries_| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK. |
114 - (BOOL)isRedirectTransitionForItemAtIndex:(NSInteger)index; | 107 - (BOOL)isRedirectTransitionForItemAtIndex:(NSInteger)index; |
115 // Returns a NavigationItemList containing the NavigationItems from |entries|. | 108 // Returns a NavigationItemList containing the NavigationItems from |entries|. |
116 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries; | 109 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries; |
117 @end | 110 @end |
118 | 111 |
119 @implementation CRWSessionController | 112 @implementation CRWSessionController |
120 | 113 |
121 @synthesize currentNavigationIndex = _currentNavigationIndex; | 114 @synthesize currentNavigationIndex = _currentNavigationIndex; |
122 @synthesize previousNavigationIndex = _previousNavigationIndex; | 115 @synthesize previousNavigationIndex = _previousNavigationIndex; |
123 @synthesize pendingItemIndex = _pendingItemIndex; | 116 @synthesize pendingItemIndex = _pendingItemIndex; |
124 @synthesize entries = _entries; | 117 @synthesize entries = _entries; |
125 @synthesize windowName = _windowName; | 118 @synthesize windowName = _windowName; |
126 @synthesize lastVisitedTimestamp = _lastVisitedTimestamp; | 119 @synthesize lastVisitedTimestamp = _lastVisitedTimestamp; |
127 @synthesize openerId = _openerId; | |
128 @synthesize openedByDOM = _openedByDOM; | 120 @synthesize openedByDOM = _openedByDOM; |
129 @synthesize openerNavigationIndex = _openerNavigationIndex; | |
130 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; | 121 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; |
131 | 122 |
132 - (id)initWithWindowName:(NSString*)windowName | 123 - (instancetype)initWithWindowName:(NSString*)windowName |
133 openerId:(NSString*)openerId | 124 openedByDOM:(BOOL)openedByDOM |
134 openedByDOM:(BOOL)openedByDOM | 125 browserState:(web::BrowserState*)browserState { |
135 openerNavigationIndex:(NSInteger)openerIndex | |
136 browserState:(web::BrowserState*)browserState { | |
137 self = [super init]; | 126 self = [super init]; |
138 if (self) { | 127 if (self) { |
139 self.windowName = windowName; | 128 self.windowName = windowName; |
140 _openerId = [openerId copy]; | |
141 _openedByDOM = openedByDOM; | 129 _openedByDOM = openedByDOM; |
142 _openerNavigationIndex = openerIndex; | |
143 _browserState = browserState; | 130 _browserState = browserState; |
144 _entries = [NSMutableArray array]; | 131 _entries = [NSMutableArray array]; |
145 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; | 132 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; |
146 _currentNavigationIndex = -1; | 133 _currentNavigationIndex = -1; |
147 _previousNavigationIndex = -1; | 134 _previousNavigationIndex = -1; |
148 _pendingItemIndex = -1; | 135 _pendingItemIndex = -1; |
149 _sessionCertificatePolicyManager = | 136 _sessionCertificatePolicyManager = |
150 [[CRWSessionCertificatePolicyManager alloc] init]; | 137 [[CRWSessionCertificatePolicyManager alloc] init]; |
151 } | 138 } |
152 return self; | 139 return self; |
153 } | 140 } |
154 | 141 |
155 - (id)initWithNavigationItems: | 142 - (instancetype)initWithNavigationItems: |
156 (std::vector<std::unique_ptr<web::NavigationItem>>)items | 143 (std::vector<std::unique_ptr<web::NavigationItem>>)items |
157 currentIndex:(NSUInteger)currentIndex | 144 currentIndex:(NSUInteger)currentIndex |
158 browserState:(web::BrowserState*)browserState { | 145 browserState:(web::BrowserState*)browserState { |
159 self = [super init]; | 146 self = [super init]; |
160 if (self) { | 147 if (self) { |
161 _openerId = nil; | |
162 _browserState = browserState; | 148 _browserState = browserState; |
163 | 149 |
164 // Create entries array from list of navigations. | 150 // Create entries array from list of navigations. |
165 _entries = [[NSMutableArray alloc] initWithCapacity:items.size()]; | 151 _entries = [[NSMutableArray alloc] initWithCapacity:items.size()]; |
166 | 152 |
167 for (auto& item : items) { | 153 for (auto& item : items) { |
168 base::scoped_nsobject<CRWSessionEntry> entry( | 154 base::scoped_nsobject<CRWSessionEntry> entry( |
169 [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]); | 155 [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]); |
170 [_entries addObject:entry]; | 156 [_entries addObject:entry]; |
171 } | 157 } |
172 self.currentNavigationIndex = currentIndex; | 158 self.currentNavigationIndex = currentIndex; |
173 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that. | 159 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that. |
174 if (![_entries count]) | 160 if (![_entries count]) |
175 self.currentNavigationIndex = -1; | 161 self.currentNavigationIndex = -1; |
176 if (_currentNavigationIndex >= static_cast<NSInteger>(items.size())) { | 162 if (_currentNavigationIndex >= static_cast<NSInteger>(items.size())) { |
177 self.currentNavigationIndex = static_cast<NSInteger>(items.size()) - 1; | 163 self.currentNavigationIndex = static_cast<NSInteger>(items.size()) - 1; |
178 } | 164 } |
179 _previousNavigationIndex = -1; | 165 _previousNavigationIndex = -1; |
180 _pendingItemIndex = -1; | 166 _pendingItemIndex = -1; |
181 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; | 167 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; |
182 _sessionCertificatePolicyManager = | 168 _sessionCertificatePolicyManager = |
183 [[CRWSessionCertificatePolicyManager alloc] init]; | 169 [[CRWSessionCertificatePolicyManager alloc] init]; |
184 } | 170 } |
185 return self; | 171 return self; |
186 } | 172 } |
187 | 173 |
188 - (id)copyWithZone:(NSZone*)zone { | 174 - (id)copyWithZone:(NSZone*)zone { |
189 CRWSessionController* copy = [[[self class] alloc] init]; | 175 CRWSessionController* copy = [[[self class] alloc] init]; |
190 copy->_openerId = [_openerId copy]; | |
191 copy->_openedByDOM = _openedByDOM; | 176 copy->_openedByDOM = _openedByDOM; |
192 copy->_openerNavigationIndex = _openerNavigationIndex; | |
193 copy.windowName = self.windowName; | 177 copy.windowName = self.windowName; |
194 copy->_currentNavigationIndex = _currentNavigationIndex; | 178 copy->_currentNavigationIndex = _currentNavigationIndex; |
195 copy->_previousNavigationIndex = _previousNavigationIndex; | 179 copy->_previousNavigationIndex = _previousNavigationIndex; |
196 copy->_pendingItemIndex = _pendingItemIndex; | 180 copy->_pendingItemIndex = _pendingItemIndex; |
197 copy->_lastVisitedTimestamp = _lastVisitedTimestamp; | 181 copy->_lastVisitedTimestamp = _lastVisitedTimestamp; |
198 copy->_entries = | 182 copy->_entries = |
199 [[NSMutableArray alloc] initWithArray:_entries copyItems:YES]; | 183 [[NSMutableArray alloc] initWithArray:_entries copyItems:YES]; |
200 copy->_sessionCertificatePolicyManager = | 184 copy->_sessionCertificatePolicyManager = |
201 [_sessionCertificatePolicyManager copy]; | 185 [_sessionCertificatePolicyManager copy]; |
202 return copy; | 186 return copy; |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 } | 708 } |
725 | 709 |
726 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries { | 710 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries { |
727 web::NavigationItemList list(entries.count); | 711 web::NavigationItemList list(entries.count); |
728 for (size_t index = 0; index < entries.count; ++index) | 712 for (size_t index = 0; index < entries.count; ++index) |
729 list[index] = [entries[index] navigationItem]; | 713 list[index] = [entries[index] navigationItem]; |
730 return list; | 714 return list; |
731 } | 715 } |
732 | 716 |
733 @end | 717 @end |
OLD | NEW |