Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: ios/web/navigation/crw_session_controller.mm

Issue 2720983002: Remove windowName from CRWSessionController. (Closed)
Patch Set: Address comments. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 // displayed tab is. It backs the property of the same name and should only 52 // displayed tab is. It backs the property of the same name and should only
53 // be set through its setter. 53 // be set through its setter.
54 base::scoped_nsobject<CRWSessionEntry> _pendingEntry; 54 base::scoped_nsobject<CRWSessionEntry> _pendingEntry;
55 55
56 // The transient entry, if any. A transient entry is discarded on any 56 // The transient entry, if any. A transient entry is discarded on any
57 // navigation, and is used for representing interstitials that need to be 57 // navigation, and is used for representing interstitials that need to be
58 // represented in the session. It backs the property of the same name and 58 // represented in the session. It backs the property of the same name and
59 // should only be set through its setter. 59 // should only be set through its setter.
60 base::scoped_nsobject<CRWSessionEntry> _transientEntry; 60 base::scoped_nsobject<CRWSessionEntry> _transientEntry;
61 61
62 // The window name associated with the session.
63 NSString* _windowName;
64
65 // Stores the certificate policies decided by the user. 62 // Stores the certificate policies decided by the user.
66 CRWSessionCertificatePolicyManager* _sessionCertificatePolicyManager; 63 CRWSessionCertificatePolicyManager* _sessionCertificatePolicyManager;
67 64
68 // The timestamp of the last time this tab is visited, represented in time 65 // The timestamp of the last time this tab is visited, represented in time
69 // interval since 1970. 66 // interval since 1970.
70 NSTimeInterval _lastVisitedTimestamp; 67 NSTimeInterval _lastVisitedTimestamp;
71 68
72 // The browser state associated with this CRWSessionController; 69 // The browser state associated with this CRWSessionController;
73 web::BrowserState* _browserState; // weak 70 web::BrowserState* _browserState; // weak
74 71
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // Returns a NavigationItemList containing the NavigationItems from |entries|. 105 // Returns a NavigationItemList containing the NavigationItems from |entries|.
109 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries; 106 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries;
110 @end 107 @end
111 108
112 @implementation CRWSessionController 109 @implementation CRWSessionController
113 110
114 @synthesize currentNavigationIndex = _currentNavigationIndex; 111 @synthesize currentNavigationIndex = _currentNavigationIndex;
115 @synthesize previousNavigationIndex = _previousNavigationIndex; 112 @synthesize previousNavigationIndex = _previousNavigationIndex;
116 @synthesize pendingItemIndex = _pendingItemIndex; 113 @synthesize pendingItemIndex = _pendingItemIndex;
117 @synthesize entries = _entries; 114 @synthesize entries = _entries;
118 @synthesize windowName = _windowName;
119 @synthesize lastVisitedTimestamp = _lastVisitedTimestamp; 115 @synthesize lastVisitedTimestamp = _lastVisitedTimestamp;
120 @synthesize openedByDOM = _openedByDOM; 116 @synthesize openedByDOM = _openedByDOM;
121 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; 117 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager;
122 118
123 - (instancetype)initWithWindowName:(NSString*)windowName 119 - (instancetype)initWithBrowserState:(web::BrowserState*)browserState
124 openedByDOM:(BOOL)openedByDOM 120 openedByDOM:(BOOL)openedByDOM {
125 browserState:(web::BrowserState*)browserState {
126 self = [super init]; 121 self = [super init];
127 if (self) { 122 if (self) {
128 self.windowName = windowName;
129 _openedByDOM = openedByDOM; 123 _openedByDOM = openedByDOM;
130 _browserState = browserState; 124 _browserState = browserState;
131 _entries = [NSMutableArray array]; 125 _entries = [NSMutableArray array];
132 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; 126 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970];
133 _currentNavigationIndex = -1; 127 _currentNavigationIndex = -1;
134 _previousNavigationIndex = -1; 128 _previousNavigationIndex = -1;
135 _pendingItemIndex = -1; 129 _pendingItemIndex = -1;
136 _sessionCertificatePolicyManager = 130 _sessionCertificatePolicyManager =
137 [[CRWSessionCertificatePolicyManager alloc] init]; 131 [[CRWSessionCertificatePolicyManager alloc] init];
138 } 132 }
139 return self; 133 return self;
140 } 134 }
141 135
142 - (instancetype)initWithNavigationItems: 136 - (instancetype)initWithBrowserState:(web::BrowserState*)browserState
143 (std::vector<std::unique_ptr<web::NavigationItem>>)items 137 navigationItems:(web::ScopedNavigationItemList)items
144 currentIndex:(NSUInteger)currentIndex 138 currentIndex:(NSUInteger)currentIndex {
145 browserState:(web::BrowserState*)browserState {
146 self = [super init]; 139 self = [super init];
147 if (self) { 140 if (self) {
148 _browserState = browserState; 141 _browserState = browserState;
149 142
150 // Create entries array from list of navigations. 143 // Create entries array from list of navigations.
151 _entries = [[NSMutableArray alloc] initWithCapacity:items.size()]; 144 _entries = [[NSMutableArray alloc] initWithCapacity:items.size()];
152
153 for (auto& item : items) { 145 for (auto& item : items) {
154 base::scoped_nsobject<CRWSessionEntry> entry( 146 base::scoped_nsobject<CRWSessionEntry> entry(
155 [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]); 147 [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]);
156 [_entries addObject:entry]; 148 [_entries addObject:entry];
157 } 149 }
158 self.currentNavigationIndex = currentIndex; 150 self.currentNavigationIndex = currentIndex;
159 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that. 151 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that.
160 if (![_entries count]) 152 if (![_entries count])
161 self.currentNavigationIndex = -1; 153 self.currentNavigationIndex = -1;
162 if (_currentNavigationIndex >= static_cast<NSInteger>(items.size())) { 154 if (_currentNavigationIndex >= static_cast<NSInteger>(items.size())) {
163 self.currentNavigationIndex = static_cast<NSInteger>(items.size()) - 1; 155 self.currentNavigationIndex = static_cast<NSInteger>(items.size()) - 1;
164 } 156 }
165 _previousNavigationIndex = -1; 157 _previousNavigationIndex = -1;
166 _pendingItemIndex = -1; 158 _pendingItemIndex = -1;
167 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; 159 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970];
168 _sessionCertificatePolicyManager = 160 _sessionCertificatePolicyManager =
169 [[CRWSessionCertificatePolicyManager alloc] init]; 161 [[CRWSessionCertificatePolicyManager alloc] init];
170 } 162 }
171 return self; 163 return self;
172 } 164 }
173 165
174 - (id)copyWithZone:(NSZone*)zone { 166 - (id)copyWithZone:(NSZone*)zone {
175 CRWSessionController* copy = [[[self class] alloc] init]; 167 CRWSessionController* copy = [[[self class] alloc] init];
176 copy->_openedByDOM = _openedByDOM; 168 copy->_openedByDOM = _openedByDOM;
177 copy.windowName = self.windowName;
178 copy->_currentNavigationIndex = _currentNavigationIndex; 169 copy->_currentNavigationIndex = _currentNavigationIndex;
179 copy->_previousNavigationIndex = _previousNavigationIndex; 170 copy->_previousNavigationIndex = _previousNavigationIndex;
180 copy->_pendingItemIndex = _pendingItemIndex; 171 copy->_pendingItemIndex = _pendingItemIndex;
181 copy->_lastVisitedTimestamp = _lastVisitedTimestamp; 172 copy->_lastVisitedTimestamp = _lastVisitedTimestamp;
182 copy->_entries = 173 copy->_entries =
183 [[NSMutableArray alloc] initWithArray:_entries copyItems:YES]; 174 [[NSMutableArray alloc] initWithArray:_entries copyItems:YES];
184 copy->_sessionCertificatePolicyManager = 175 copy->_sessionCertificatePolicyManager =
185 [_sessionCertificatePolicyManager copy]; 176 [_sessionCertificatePolicyManager copy];
186 return copy; 177 return copy;
187 } 178 }
(...skipping 29 matching lines...) Expand all
217 } 208 }
218 209
219 - (void)setBrowserState:(web::BrowserState*)browserState { 210 - (void)setBrowserState:(web::BrowserState*)browserState {
220 _browserState = browserState; 211 _browserState = browserState;
221 DCHECK(!_navigationManager || 212 DCHECK(!_navigationManager ||
222 _navigationManager->GetBrowserState() == _browserState); 213 _navigationManager->GetBrowserState() == _browserState);
223 } 214 }
224 215
225 - (NSString*)description { 216 - (NSString*)description {
226 return [NSString 217 return [NSString
227 stringWithFormat:@"name: %@\nlast visit: %f\ncurrent index: %" PRIdNS 218 stringWithFormat:@"last visit: %f\ncurrent index: %" PRIdNS
228 @"\nprevious index: %" PRIdNS 219 @"\nprevious index: %" PRIdNS
229 @"\npending index: %" PRIdNS 220 @"\npending index: %" PRIdNS
230 @"\n%@\npending: %@\ntransient: %@\n", 221 @"\n%@\npending: %@\ntransient: %@\n",
231 self.windowName, _lastVisitedTimestamp, 222 _lastVisitedTimestamp, _currentNavigationIndex,
232 _currentNavigationIndex, _previousNavigationIndex, 223 _previousNavigationIndex, _pendingItemIndex, _entries,
233 _pendingItemIndex, _entries, _pendingEntry.get(), 224 _pendingEntry.get(), _transientEntry.get()];
234 _transientEntry.get()];
235 } 225 }
236 226
237 - (web::NavigationItemList)items { 227 - (web::NavigationItemList)items {
238 return [self itemListForEntryList:self.entries]; 228 return [self itemListForEntryList:self.entries];
239 } 229 }
240 230
241 - (web::NavigationItemImpl*)currentItem { 231 - (web::NavigationItemImpl*)currentItem {
242 return self.currentEntry.navigationItemImpl; 232 return self.currentEntry.navigationItemImpl;
243 } 233 }
244 234
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 // Keep the entry alive temporarily. There are flows that get the current 522 // Keep the entry alive temporarily. There are flows that get the current
533 // entry, do some navigation operation, and then try to use that old current 523 // entry, do some navigation operation, and then try to use that old current
534 // entry; since navigations clear the transient entry, these flows might 524 // entry; since navigations clear the transient entry, these flows might
535 // crash. (This should be removable once more session management is handled 525 // crash. (This should be removable once more session management is handled
536 // within this class and/or NavigationManager). 526 // within this class and/or NavigationManager).
537 _transientEntry.reset(); 527 _transientEntry.reset();
538 } 528 }
539 529
540 - (void)insertStateFromSessionController:(CRWSessionController*)sourceSession { 530 - (void)insertStateFromSessionController:(CRWSessionController*)sourceSession {
541 DCHECK(sourceSession); 531 DCHECK(sourceSession);
542 self.windowName = sourceSession.windowName;
543
544 // The other session may not have any entries, in which case there is nothing 532 // The other session may not have any entries, in which case there is nothing
545 // to insert. The other session's currentNavigationEntry will be bogus 533 // to insert. The other session's currentNavigationEntry will be bogus
546 // in such cases, so ignore it and return early. 534 // in such cases, so ignore it and return early.
547 NSArray* sourceEntries = sourceSession.entries; 535 NSArray* sourceEntries = sourceSession.entries;
548 if (!sourceEntries.count) 536 if (!sourceEntries.count)
549 return; 537 return;
550 538
551 // Cycle through the entries from the other session and insert them before any 539 // Cycle through the entries from the other session and insert them before any
552 // entries from this session. Do not copy anything that comes after the other 540 // entries from this session. Do not copy anything that comes after the other
553 // session's current entry. 541 // session's current entry.
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 } 696 }
709 697
710 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries { 698 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries {
711 web::NavigationItemList list(entries.count); 699 web::NavigationItemList list(entries.count);
712 for (size_t index = 0; index < entries.count; ++index) 700 for (size_t index = 0; index < entries.count; ++index)
713 list[index] = [entries[index] navigationItem]; 701 list[index] = [entries[index] navigationItem];
714 return list; 702 return list;
715 } 703 }
716 704
717 @end 705 @end
OLDNEW
« no previous file with comments | « ios/web/navigation/crw_session_controller.h ('k') | ios/web/navigation/crw_session_controller+private_constructors.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698