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

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

Issue 2794723002: Create new pending item if UserAgentOverrideOption is not INHERIT. (Closed)
Patch Set: Address comments Created 3 years, 8 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // Creates a NavigationItemImpl with the specified properties. 73 // Creates a NavigationItemImpl with the specified properties.
74 - (std::unique_ptr<web::NavigationItemImpl>) 74 - (std::unique_ptr<web::NavigationItemImpl>)
75 itemWithURL:(const GURL&)url 75 itemWithURL:(const GURL&)url
76 referrer:(const web::Referrer&)referrer 76 referrer:(const web::Referrer&)referrer
77 transition:(ui::PageTransition)transition 77 transition:(ui::PageTransition)transition
78 initiationType:(web::NavigationInitiationType)initiationType; 78 initiationType:(web::NavigationInitiationType)initiationType;
79 // Returns YES if the PageTransition for the underlying navigationItem at 79 // Returns YES if the PageTransition for the underlying navigationItem at
80 // |index| in |items| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK. 80 // |index| in |items| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK.
81 - (BOOL)isRedirectTransitionForItemAtIndex:(size_t)index; 81 - (BOOL)isRedirectTransitionForItemAtIndex:(size_t)index;
82 82
83 // Should create a new pending item if the new pending item is not a duplicate
84 // of the last added or commited item. Returns YES if one of the following rules
85 // apply:
86 // 1. There is no last added or committed item.
87 // 2. The new item has different url from the last added or commited item.
88 // 3. Url is the same, but the new item is a form submission resulted from the
89 // last added or committed item.
90 // 4. Url is the same, but new item is a reload with different user agent type
91 // resulted from last added or commited item.
92 - (BOOL)shouldCreatePendingItemWithURL:(const GURL&)url
93 transition:(ui::PageTransition)transition
94 userAgentOverrideOption:
95 (web::NavigationManager::UserAgentOverrideOption)
96 userAgentOverrideOption;
97
83 @end 98 @end
84 99
85 @implementation CRWSessionController 100 @implementation CRWSessionController
86 101
87 @synthesize lastCommittedItemIndex = _lastCommittedItemIndex; 102 @synthesize lastCommittedItemIndex = _lastCommittedItemIndex;
88 @synthesize previousItemIndex = _previousItemIndex; 103 @synthesize previousItemIndex = _previousItemIndex;
89 @synthesize pendingItemIndex = _pendingItemIndex; 104 @synthesize pendingItemIndex = _pendingItemIndex;
90 105
91 - (instancetype)initWithBrowserState:(web::BrowserState*)browserState { 106 - (instancetype)initWithBrowserState:(web::BrowserState*)browserState {
92 self = [super init]; 107 self = [super init];
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 276 }
262 } 277 }
263 278
264 - (void)setBrowserState:(web::BrowserState*)browserState { 279 - (void)setBrowserState:(web::BrowserState*)browserState {
265 _browserState = browserState; 280 _browserState = browserState;
266 DCHECK(!_navigationManager || 281 DCHECK(!_navigationManager ||
267 _navigationManager->GetBrowserState() == _browserState); 282 _navigationManager->GetBrowserState() == _browserState);
268 } 283 }
269 284
270 - (void)addPendingItem:(const GURL&)url 285 - (void)addPendingItem:(const GURL&)url
271 referrer:(const web::Referrer&)ref 286 referrer:(const web::Referrer&)ref
272 transition:(ui::PageTransition)trans 287 transition:(ui::PageTransition)trans
273 initiationType:(web::NavigationInitiationType)initiationType { 288 initiationType:(web::NavigationInitiationType)initiationType
289 userAgentOverrideOption:(web::NavigationManager::UserAgentOverrideOption)
290 userAgentOverrideOption {
274 // Server side redirects are handled by updating existing pending item instead 291 // Server side redirects are handled by updating existing pending item instead
275 // of adding a new item. 292 // of adding a new item.
276 DCHECK((trans & ui::PAGE_TRANSITION_SERVER_REDIRECT) == 0); 293 DCHECK((trans & ui::PAGE_TRANSITION_SERVER_REDIRECT) == 0);
277 294
278 [self discardTransientItem]; 295 [self discardTransientItem];
279 self.pendingItemIndex = -1; 296 self.pendingItemIndex = -1;
280 297
281 // Don't create a new item if it's already the same as the current item, 298 if (![self shouldCreatePendingItemWithURL:url
282 // allowing this routine to be called multiple times in a row without issue. 299 transition:trans
300 userAgentOverrideOption:userAgentOverrideOption]) {
301 // Send the notification anyway, to preserve old behavior. It's unknown
302 // whether anything currently relies on this, but since both this whole
303 // hack and the content facade will both be going away, it's not worth
304 // trying to unwind.
305 if (_navigationManager && _navigationManager->GetFacadeDelegate())
Eugene But (OOO till 7-30) 2017/04/07 16:16:40 Kurt, do we still have "FacadeDelegate"? I suspect
kkhorimoto 2017/04/07 17:18:11 Nope, I've been meaning to get rid of this code fo
liaoyuke 2017/04/07 17:33:04 Sounds good, and btw, OnNavigationItemPruned doesn
306 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending();
307 return;
308 }
309
310 _pendingItem = [self itemWithURL:url
311 referrer:ref
312 transition:trans
313 initiationType:initiationType];
314
315 if (_navigationManager && _navigationManager->GetFacadeDelegate())
316 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending();
317 DCHECK_EQ(-1, self.pendingItemIndex);
318 }
319
320 - (BOOL)shouldCreatePendingItemWithURL:(const GURL&)url
Eugene But (OOO till 7-30) 2017/04/07 16:16:40 s/url/URL
liaoyuke 2017/04/07 17:33:04 Done.
321 transition:(ui::PageTransition)transition
322 userAgentOverrideOption:
323 (web::NavigationManager::UserAgentOverrideOption)
324 userAgentOverrideOption {
283 // Note: CRWSessionController currently has the responsibility to distinguish 325 // Note: CRWSessionController currently has the responsibility to distinguish
284 // between new navigations and history stack navigation, hence the inclusion 326 // between new navigations and history stack navigation, hence the inclusion
285 // of specific transiton type logic here, in order to make it reliable with 327 // of specific transiton type logic here, in order to make it reliable with
286 // real-world observed behavior. 328 // real-world observed behavior.
287 // TODO(crbug.com/676129): Fix the way changes are detected/reported elsewhere 329 // TODO(crbug.com/676129): Fix the way changes are detected/reported elsewhere
288 // in the web layer so that this hack can be removed. 330 // in the web layer so that this hack can be removed.
289 // Remove the workaround code from -presentSafeBrowsingWarningForResource:. 331 // Remove the workaround code from -presentSafeBrowsingWarningForResource:.
290 web::NavigationItemImpl* currentItem = self.currentItem; 332 web::NavigationItemImpl* currentItem = self.currentItem;
291 if (currentItem) { 333 if (!currentItem)
292 BOOL hasSameURL = currentItem->GetURL() == url; 334 return YES;
293 BOOL isPendingTransitionFormSubmit =
294 PageTransitionCoreTypeIs(trans, ui::PAGE_TRANSITION_FORM_SUBMIT);
295 BOOL isCurrentTransitionFormSubmit = PageTransitionCoreTypeIs(
296 currentItem->GetTransitionType(), ui::PAGE_TRANSITION_FORM_SUBMIT);
297 BOOL shouldCreatePendingItem =
298 !hasSameURL ||
299 (isPendingTransitionFormSubmit && !isCurrentTransitionFormSubmit);
300 335
301 if (!shouldCreatePendingItem) { 336 // User agent override option should always be different from the user agent
302 // Send the notification anyway, to preserve old behavior. It's unknown 337 // type of the pending item, or the last committed item if pending doesn't
303 // whether anything currently relies on this, but since both this whole 338 // exist.
304 // hack and the content facade will both be going away, it's not worth 339 DCHECK(userAgentOverrideOption !=
305 // trying to unwind. 340 web::NavigationManager::UserAgentOverrideOption::DESKTOP ||
306 if (_navigationManager && _navigationManager->GetFacadeDelegate()) 341 currentItem->GetUserAgentType() != web::UserAgentType::DESKTOP);
307 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); 342 DCHECK(userAgentOverrideOption !=
308 return; 343 web::NavigationManager::UserAgentOverrideOption::MOBILE ||
309 } 344 currentItem->GetUserAgentType() != web::UserAgentType::MOBILE);
345
346 BOOL hasSameURL = self.currentItem->GetURL() == url;
347 if (!hasSameURL) {
348 // Different url indicates that it's not a duplicate item.
349 return YES;
310 } 350 }
311 351
312 _pendingItem = [self itemWithURL:url 352 BOOL isPendingTransitionFormSubmit =
313 referrer:ref 353 PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_FORM_SUBMIT);
314 transition:trans 354 BOOL isCurrentTransitionFormSubmit = PageTransitionCoreTypeIs(
315 initiationType:initiationType]; 355 currentItem->GetTransitionType(), ui::PAGE_TRANSITION_FORM_SUBMIT);
356 if (isPendingTransitionFormSubmit && !isCurrentTransitionFormSubmit) {
357 // |isPendingTransitionFormSubmit| indicates that the new item is a form
358 // submission resulted from the last added or commited item, and
359 // |!isCurrentTransitionFormSubmit| shows that the form submission is not
360 // counted multiple times.
361 return YES;
362 }
316 363
317 if (_navigationManager && _navigationManager->GetFacadeDelegate()) 364 BOOL isInheritingUserAgentType =
318 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); 365 userAgentOverrideOption ==
319 DCHECK_EQ(-1, self.pendingItemIndex); 366 web::NavigationManager::UserAgentOverrideOption::INHERIT;
367 if (!isInheritingUserAgentType) {
368 // Overriding user agent type to MOBILE or DESKTOP indicates that the new
369 // new item is a reload with different user agent type.
370 return YES;
371 }
372
373 return NO;
320 } 374 }
321 375
322 - (void)updatePendingItem:(const GURL&)url { 376 - (void)updatePendingItem:(const GURL&)url {
323 // If there is no pending item, navigation is probably happening within the 377 // If there is no pending item, navigation is probably happening within the
324 // session history. Don't modify the item list. 378 // session history. Don't modify the item list.
325 web::NavigationItemImpl* item = self.pendingItem; 379 web::NavigationItemImpl* item = self.pendingItem;
326 if (!item) 380 if (!item)
327 return; 381 return;
328 382
329 if (url != item->GetURL()) { 383 if (url != item->GetURL()) {
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 return item; 669 return item;
616 } 670 }
617 671
618 - (BOOL)isRedirectTransitionForItemAtIndex:(size_t)index { 672 - (BOOL)isRedirectTransitionForItemAtIndex:(size_t)index {
619 DCHECK_LT(index, self.items.size()); 673 DCHECK_LT(index, self.items.size());
620 ui::PageTransition transition = self.items[index]->GetTransitionType(); 674 ui::PageTransition transition = self.items[index]->GetTransitionType();
621 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; 675 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO;
622 } 676 }
623 677
624 @end 678 @end
OLDNEW
« no previous file with comments | « ios/web/navigation/crw_session_controller.h ('k') | ios/web/navigation/crw_session_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698