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

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

Issue 2693523003: Moved TabID implementation to SerializableUserData. (Closed)
Patch Set: fix compile Created 3 years, 10 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 19 matching lines...) Expand all
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* _tabId; // Unique id of the tab.
41 NSString* _openerId; // Id of tab who opened this tab, empty/nil if none. 40 NSString* _openerId; // Id of tab who opened this tab, empty/nil if none.
42 // Navigation index of the tab which opened this tab. Do not rely on the 41 // Navigation index of the tab which opened this tab. Do not rely on the
43 // value of this member variable to indicate whether or not this tab has 42 // value of this member variable to indicate whether or not this tab has
44 // an opener, as both 0 and -1 are used as navigationIndex values. 43 // an opener, as both 0 and -1 are used as navigationIndex values.
45 NSInteger _openerNavigationIndex; 44 NSInteger _openerNavigationIndex;
46 // Identifies the index of the current navigation in the CRWSessionEntry 45 // Identifies the index of the current navigation in the CRWSessionEntry
47 // array. 46 // array.
48 NSInteger _currentNavigationIndex; 47 NSInteger _currentNavigationIndex;
49 // Identifies the index of the previous navigation in the CRWSessionEntry 48 // Identifies the index of the previous navigation in the CRWSessionEntry
50 // array. 49 // array.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // Time smoother for navigation entry timestamps; see comment in 84 // Time smoother for navigation entry timestamps; see comment in
86 // navigation_controller_impl.h 85 // navigation_controller_impl.h
87 web::TimeSmoother _timeSmoother; 86 web::TimeSmoother _timeSmoother;
88 } 87 }
89 88
90 // Redefine as readwrite. 89 // Redefine as readwrite.
91 @property(nonatomic, readwrite, assign) NSInteger currentNavigationIndex; 90 @property(nonatomic, readwrite, assign) NSInteger currentNavigationIndex;
92 91
93 // TODO(rohitrao): These properties must be redefined readwrite to work around a 92 // TODO(rohitrao): These properties must be redefined readwrite to work around a
94 // clang bug. crbug.com/228650 93 // clang bug. crbug.com/228650
95 @property(nonatomic, readwrite, copy) NSString* tabId;
96 @property(nonatomic, readwrite, strong) NSArray* entries; 94 @property(nonatomic, readwrite, strong) NSArray* entries;
97 @property(nonatomic, readwrite, strong) 95 @property(nonatomic, readwrite, strong)
98 CRWSessionCertificatePolicyManager* sessionCertificatePolicyManager; 96 CRWSessionCertificatePolicyManager* sessionCertificatePolicyManager;
99 97
100 // Expose setters for serialization properties. These are exposed in a category 98 // Expose setters for serialization properties. These are exposed in a category
101 // in SessionStorageBuilder, and will be removed as ownership of 99 // in SessionStorageBuilder, and will be removed as ownership of
102 // their backing ivars moves to NavigationManagerImpl. 100 // their backing ivars moves to NavigationManagerImpl.
103 @property(nonatomic, readwrite, copy) NSString* openerId; 101 @property(nonatomic, readwrite, copy) NSString* openerId;
104 @property(nonatomic, readwrite, getter=isOpenedByDOM) BOOL openedByDOM; 102 @property(nonatomic, readwrite, getter=isOpenedByDOM) BOOL openedByDOM;
105 @property(nonatomic, readwrite, assign) NSInteger openerNavigationIndex; 103 @property(nonatomic, readwrite, assign) NSInteger openerNavigationIndex;
106 @property(nonatomic, readwrite, assign) NSInteger previousNavigationIndex; 104 @property(nonatomic, readwrite, assign) NSInteger previousNavigationIndex;
107 105
108 - (NSString*)uniqueID;
109 // Removes all entries after currentNavigationIndex_. 106 // Removes all entries after currentNavigationIndex_.
110 - (void)clearForwardItems; 107 - (void)clearForwardItems;
111 // Discards the transient entry, if any. 108 // Discards the transient entry, if any.
112 - (void)discardTransientItem; 109 - (void)discardTransientItem;
113 // Create a new autoreleased session entry. 110 // Create a new autoreleased session entry.
114 - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url 111 - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url
115 referrer:(const web::Referrer&)referrer 112 referrer:(const web::Referrer&)referrer
116 transition:(ui::PageTransition)transition 113 transition:(ui::PageTransition)transition
117 useDesktopUserAgent:(BOOL)useDesktopUserAgent 114 useDesktopUserAgent:(BOOL)useDesktopUserAgent
118 rendererInitiated:(BOOL)rendererInitiated; 115 rendererInitiated:(BOOL)rendererInitiated;
119 // Returns YES if the PageTransition for the underlying navigationItem at 116 // Returns YES if the PageTransition for the underlying navigationItem at
120 // |index| in |entries_| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK. 117 // |index| in |entries_| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK.
121 - (BOOL)isRedirectTransitionForItemAtIndex:(NSInteger)index; 118 - (BOOL)isRedirectTransitionForItemAtIndex:(NSInteger)index;
122 // Returns a NavigationItemList containing the NavigationItems from |entries|. 119 // Returns a NavigationItemList containing the NavigationItems from |entries|.
123 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries; 120 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries;
124 @end 121 @end
125 122
126 @implementation CRWSessionController 123 @implementation CRWSessionController
127 124
128 @synthesize tabId = _tabId;
129 @synthesize currentNavigationIndex = _currentNavigationIndex; 125 @synthesize currentNavigationIndex = _currentNavigationIndex;
130 @synthesize previousNavigationIndex = _previousNavigationIndex; 126 @synthesize previousNavigationIndex = _previousNavigationIndex;
131 @synthesize pendingItemIndex = _pendingItemIndex; 127 @synthesize pendingItemIndex = _pendingItemIndex;
132 @synthesize entries = _entries; 128 @synthesize entries = _entries;
133 @synthesize windowName = _windowName; 129 @synthesize windowName = _windowName;
134 @synthesize lastVisitedTimestamp = _lastVisitedTimestamp; 130 @synthesize lastVisitedTimestamp = _lastVisitedTimestamp;
135 @synthesize openerId = _openerId; 131 @synthesize openerId = _openerId;
136 @synthesize openedByDOM = _openedByDOM; 132 @synthesize openedByDOM = _openedByDOM;
137 @synthesize openerNavigationIndex = _openerNavigationIndex; 133 @synthesize openerNavigationIndex = _openerNavigationIndex;
138 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager; 134 @synthesize sessionCertificatePolicyManager = _sessionCertificatePolicyManager;
139 135
140 - (id)initWithWindowName:(NSString*)windowName 136 - (id)initWithWindowName:(NSString*)windowName
141 openerId:(NSString*)openerId 137 openerId:(NSString*)openerId
142 openedByDOM:(BOOL)openedByDOM 138 openedByDOM:(BOOL)openedByDOM
143 openerNavigationIndex:(NSInteger)openerIndex 139 openerNavigationIndex:(NSInteger)openerIndex
144 browserState:(web::BrowserState*)browserState { 140 browserState:(web::BrowserState*)browserState {
145 self = [super init]; 141 self = [super init];
146 if (self) { 142 if (self) {
147 self.windowName = windowName; 143 self.windowName = windowName;
148 _tabId = [[self uniqueID] copy];
149 _openerId = [openerId copy]; 144 _openerId = [openerId copy];
150 _openedByDOM = openedByDOM; 145 _openedByDOM = openedByDOM;
151 _openerNavigationIndex = openerIndex; 146 _openerNavigationIndex = openerIndex;
152 _browserState = browserState; 147 _browserState = browserState;
153 _entries = [NSMutableArray array]; 148 _entries = [NSMutableArray array];
154 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; 149 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970];
155 _currentNavigationIndex = -1; 150 _currentNavigationIndex = -1;
156 _previousNavigationIndex = -1; 151 _previousNavigationIndex = -1;
157 _pendingItemIndex = -1; 152 _pendingItemIndex = -1;
158 _sessionCertificatePolicyManager = 153 _sessionCertificatePolicyManager =
159 [[CRWSessionCertificatePolicyManager alloc] init]; 154 [[CRWSessionCertificatePolicyManager alloc] init];
160 } 155 }
161 return self; 156 return self;
162 } 157 }
163 158
164 - (id)initWithNavigationItems: 159 - (id)initWithNavigationItems:
165 (std::vector<std::unique_ptr<web::NavigationItem>>)items 160 (std::vector<std::unique_ptr<web::NavigationItem>>)items
166 currentIndex:(NSUInteger)currentIndex 161 currentIndex:(NSUInteger)currentIndex
167 browserState:(web::BrowserState*)browserState { 162 browserState:(web::BrowserState*)browserState {
168 self = [super init]; 163 self = [super init];
169 if (self) { 164 if (self) {
170 _tabId = [[self uniqueID] copy];
171 _openerId = nil; 165 _openerId = nil;
172 _browserState = browserState; 166 _browserState = browserState;
173 167
174 // Create entries array from list of navigations. 168 // Create entries array from list of navigations.
175 _entries = [[NSMutableArray alloc] initWithCapacity:items.size()]; 169 _entries = [[NSMutableArray alloc] initWithCapacity:items.size()];
176 170
177 for (auto& item : items) { 171 for (auto& item : items) {
178 base::scoped_nsobject<CRWSessionEntry> entry( 172 base::scoped_nsobject<CRWSessionEntry> entry(
179 [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]); 173 [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)]);
180 [_entries addObject:entry]; 174 [_entries addObject:entry];
181 } 175 }
182 self.currentNavigationIndex = currentIndex; 176 self.currentNavigationIndex = currentIndex;
183 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that. 177 // Prior to M34, 0 was used as "no index" instead of -1; adjust for that.
184 if (![_entries count]) 178 if (![_entries count])
185 self.currentNavigationIndex = -1; 179 self.currentNavigationIndex = -1;
186 if (_currentNavigationIndex >= static_cast<NSInteger>(items.size())) { 180 if (_currentNavigationIndex >= static_cast<NSInteger>(items.size())) {
187 self.currentNavigationIndex = static_cast<NSInteger>(items.size()) - 1; 181 self.currentNavigationIndex = static_cast<NSInteger>(items.size()) - 1;
188 } 182 }
189 _previousNavigationIndex = -1; 183 _previousNavigationIndex = -1;
190 _pendingItemIndex = -1; 184 _pendingItemIndex = -1;
191 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970]; 185 _lastVisitedTimestamp = [[NSDate date] timeIntervalSince1970];
192 _sessionCertificatePolicyManager = 186 _sessionCertificatePolicyManager =
193 [[CRWSessionCertificatePolicyManager alloc] init]; 187 [[CRWSessionCertificatePolicyManager alloc] init];
194 } 188 }
195 return self; 189 return self;
196 } 190 }
197 191
198 - (id)copyWithZone:(NSZone*)zone { 192 - (id)copyWithZone:(NSZone*)zone {
199 CRWSessionController* copy = [[[self class] alloc] init]; 193 CRWSessionController* copy = [[[self class] alloc] init];
200 copy->_tabId = [_tabId copy];
201 copy->_openerId = [_openerId copy]; 194 copy->_openerId = [_openerId copy];
202 copy->_openedByDOM = _openedByDOM; 195 copy->_openedByDOM = _openedByDOM;
203 copy->_openerNavigationIndex = _openerNavigationIndex; 196 copy->_openerNavigationIndex = _openerNavigationIndex;
204 copy.windowName = self.windowName; 197 copy.windowName = self.windowName;
205 copy->_currentNavigationIndex = _currentNavigationIndex; 198 copy->_currentNavigationIndex = _currentNavigationIndex;
206 copy->_previousNavigationIndex = _previousNavigationIndex; 199 copy->_previousNavigationIndex = _previousNavigationIndex;
207 copy->_pendingItemIndex = _pendingItemIndex; 200 copy->_pendingItemIndex = _pendingItemIndex;
208 copy->_lastVisitedTimestamp = _lastVisitedTimestamp; 201 copy->_lastVisitedTimestamp = _lastVisitedTimestamp;
209 copy->_entries = 202 copy->_entries =
210 [[NSMutableArray alloc] initWithArray:_entries copyItems:YES]; 203 [[NSMutableArray alloc] initWithArray:_entries copyItems:YES];
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 237 }
245 238
246 - (void)setBrowserState:(web::BrowserState*)browserState { 239 - (void)setBrowserState:(web::BrowserState*)browserState {
247 _browserState = browserState; 240 _browserState = browserState;
248 DCHECK(!_navigationManager || 241 DCHECK(!_navigationManager ||
249 _navigationManager->GetBrowserState() == _browserState); 242 _navigationManager->GetBrowserState() == _browserState);
250 } 243 }
251 244
252 - (NSString*)description { 245 - (NSString*)description {
253 return [NSString 246 return [NSString
254 stringWithFormat: 247 stringWithFormat:@"name: %@\nlast visit: %f\ncurrent index: %" PRIdNS
255 @"id: %@\nname: %@\nlast visit: %f\ncurrent index: %" PRIdNS 248 @"\nprevious index: %" PRIdNS
256 @"\nprevious index: %" PRIdNS @"\npending index: %" PRIdNS 249 @"\npending index: %" PRIdNS
257 @"\n%@\npending: %@\ntransient: %@\n", 250 @"\n%@\npending: %@\ntransient: %@\n",
258 _tabId, self.windowName, _lastVisitedTimestamp, 251 self.windowName, _lastVisitedTimestamp,
259 _currentNavigationIndex, _previousNavigationIndex, _pendingItemIndex, 252 _currentNavigationIndex, _previousNavigationIndex,
260 _entries, _pendingEntry.get(), _transientEntry.get()]; 253 _pendingItemIndex, _entries, _pendingEntry.get(),
254 _transientEntry.get()];
261 } 255 }
262 256
263 - (web::NavigationItemList)items { 257 - (web::NavigationItemList)items {
264 return [self itemListForEntryList:self.entries]; 258 return [self itemListForEntryList:self.entries];
265 } 259 }
266 260
267 - (web::NavigationItemImpl*)currentItem { 261 - (web::NavigationItemImpl*)currentItem {
268 return self.currentEntry.navigationItemImpl; 262 return self.currentEntry.navigationItemImpl;
269 } 263 }
270 264
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 for (NSInteger i = 0; i < static_cast<NSInteger>(items.size()); ++i) { 685 for (NSInteger i = 0; i < static_cast<NSInteger>(items.size()); ++i) {
692 if (items[i] == item) 686 if (items[i] == item)
693 return i; 687 return i;
694 } 688 }
695 return NSNotFound; 689 return NSNotFound;
696 } 690 }
697 691
698 #pragma mark - 692 #pragma mark -
699 #pragma mark Private methods 693 #pragma mark Private methods
700 694
701 - (NSString*)uniqueID {
702 CFUUIDRef uuidRef = CFUUIDCreate(NULL);
703 CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef);
704 CFRelease(uuidRef);
705
706 NSString* uuid =
707 [NSString stringWithString:base::mac::ObjCCastStrict<NSString>(
708 CFBridgingRelease(uuidStringRef))];
709 return uuid;
710 }
711
712 - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url 695 - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url
713 referrer:(const web::Referrer&)referrer 696 referrer:(const web::Referrer&)referrer
714 transition:(ui::PageTransition)transition 697 transition:(ui::PageTransition)transition
715 useDesktopUserAgent:(BOOL)useDesktopUserAgent 698 useDesktopUserAgent:(BOOL)useDesktopUserAgent
716 rendererInitiated:(BOOL)rendererInitiated { 699 rendererInitiated:(BOOL)rendererInitiated {
717 GURL loaded_url(url); 700 GURL loaded_url(url);
718 BOOL urlWasRewritten = NO; 701 BOOL urlWasRewritten = NO;
719 if (_navigationManager) { 702 if (_navigationManager) {
720 std::unique_ptr<std::vector<web::BrowserURLRewriter::URLRewriter>> 703 std::unique_ptr<std::vector<web::BrowserURLRewriter::URLRewriter>>
721 transientRewriters = _navigationManager->GetTransientURLRewriters(); 704 transientRewriters = _navigationManager->GetTransientURLRewriters();
(...skipping 23 matching lines...) Expand all
745 } 728 }
746 729
747 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries { 730 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries {
748 web::NavigationItemList list(entries.count); 731 web::NavigationItemList list(entries.count);
749 for (size_t index = 0; index < entries.count; ++index) 732 for (size_t index = 0; index < entries.count; ++index)
750 list[index] = [entries[index] navigationItem]; 733 list[index] = [entries[index] navigationItem];
751 return list; 734 return list;
752 } 735 }
753 736
754 @end 737 @end
OLDNEW
« no previous file with comments | « ios/web/navigation/crw_session_controller.h ('k') | ios/web/navigation/serializable_user_data_manager_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698