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

Unified Diff: ios/web/navigation/crw_session_controller.mm

Issue 2698773002: [iOS] Refactoring web CRWSessionController user agent code. (Closed)
Patch Set: Fix unit tests and rebase 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/navigation/crw_session_controller.mm
diff --git a/ios/web/navigation/crw_session_controller.mm b/ios/web/navigation/crw_session_controller.mm
index 2afdc55e552a98ccc717ffb9644d09a09ba162ae..d03bf9481386425669ff7c8f9bbaf4f29a8a8796 100644
--- a/ios/web/navigation/crw_session_controller.mm
+++ b/ios/web/navigation/crw_session_controller.mm
@@ -111,8 +111,8 @@ - (void)discardTransientItem;
- (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url
referrer:(const web::Referrer&)referrer
transition:(ui::PageTransition)transition
- useDesktopUserAgent:(BOOL)useDesktopUserAgent
- rendererInitiated:(BOOL)rendererInitiated;
+ initiationType:
+ (web::NavigationInitiationType)initiationType;
// Returns YES if the PageTransition for the underlying navigationItem at
// |index| in |entries_| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK.
- (BOOL)isRedirectTransitionForItemAtIndex:(NSInteger)index;
@@ -312,12 +312,16 @@ - (CRWSessionEntry*)visibleEntry {
// Only return the pending_entry for new (non-history), browser-initiated
// navigations in order to prevent URL spoof attacks.
web::NavigationItemImpl* pendingItem = [_pendingEntry navigationItemImpl];
- bool safeToShowPending = pendingItem &&
- !pendingItem->is_renderer_initiated() &&
- _pendingItemIndex == -1;
- if (safeToShowPending) {
- return _pendingEntry.get();
+
+ if (pendingItem) {
+ bool isUserInitiated = pendingItem->NavigationInitiationType() ==
+ web::NavigationInitiationType::USER_INITIATED;
+ bool safeToShowPending = isUserInitiated && _pendingItemIndex == -1;
+
+ if (safeToShowPending)
+ return _pendingEntry.get();
}
+
return [self lastCommittedEntry];
}
@@ -345,7 +349,7 @@ - (CRWSessionEntry*)previousEntry {
- (void)addPendingItem:(const GURL&)url
referrer:(const web::Referrer&)ref
transition:(ui::PageTransition)trans
- rendererInitiated:(BOOL)rendererInitiated {
+ initiationType:(web::NavigationInitiationType)initiationType {
[self discardTransientItem];
_pendingItemIndex = -1;
@@ -361,10 +365,17 @@ - (void)addPendingItem:(const GURL&)url
CRWSessionEntry* currentEntry = self.currentEntry;
if (currentEntry) {
web::NavigationItem* item = [currentEntry navigationItem];
- if (item->GetURL() == url &&
- (!PageTransitionCoreTypeIs(trans, ui::PAGE_TRANSITION_FORM_SUBMIT) ||
- PageTransitionCoreTypeIs(item->GetTransitionType(),
- ui::PAGE_TRANSITION_FORM_SUBMIT))) {
+
+ BOOL hasSameURL = item->GetURL() == url;
+ BOOL isPendingTransitionFormSubmit =
+ PageTransitionCoreTypeIs(trans, ui::PAGE_TRANSITION_FORM_SUBMIT);
+ BOOL isCurrentTransitionFormSubmit = PageTransitionCoreTypeIs(
+ item->GetTransitionType(), ui::PAGE_TRANSITION_FORM_SUBMIT);
+ BOOL shouldCreatePendingItem =
+ !hasSameURL ||
+ (isPendingTransitionFormSubmit && !isCurrentTransitionFormSubmit);
+
+ if (!shouldCreatePendingItem) {
// Send the notification anyway, to preserve old behavior. It's unknown
// whether anything currently relies on this, but since both this whole
// hack and the content facade will both be going away, it's not worth
@@ -376,16 +387,10 @@ - (void)addPendingItem:(const GURL&)url
}
}
- BOOL useDesktopUserAgent =
- _useDesktopUserAgentForNextPendingItem ||
- (self.currentEntry.navigationItem &&
- self.currentEntry.navigationItem->IsOverridingUserAgent());
- _useDesktopUserAgentForNextPendingItem = NO;
_pendingEntry.reset([self sessionEntryWithURL:url
referrer:ref
transition:trans
- useDesktopUserAgent:useDesktopUserAgent
- rendererInitiated:rendererInitiated]);
+ initiationType:initiationType]);
if (_navigationManager && _navigationManager->GetFacadeDelegate()) {
_navigationManager->GetFacadeDelegate()->OnNavigationItemPending();
@@ -478,8 +483,7 @@ - (void)addTransientItemWithURL:(const GURL&)URL {
sessionEntryWithURL:URL
referrer:web::Referrer()
transition:ui::PAGE_TRANSITION_CLIENT_REDIRECT
- useDesktopUserAgent:NO
- rendererInitiated:NO]);
+ initiationType:web::NavigationInitiationType::USER_INITIATED]);
web::NavigationItem* navigationItem = [_transientEntry navigationItem];
DCHECK(navigationItem);
@@ -492,19 +496,19 @@ - (void)pushNewItemWithURL:(const GURL&)URL
transition:(ui::PageTransition)transition {
DCHECK(![self pendingEntry]);
DCHECK([self currentEntry]);
- web::NavigationItem* item = [self currentEntry].navigationItem;
- CHECK(
- web::history_state_util::IsHistoryStateChangeValid(item->GetURL(), URL));
- web::Referrer referrer(item->GetURL(), web::ReferrerPolicyDefault);
- bool overrideUserAgent =
- self.currentEntry.navigationItem->IsOverridingUserAgent();
+ web::NavigationItem* currentItem = [self currentEntry].navigationItem;
+ CHECK(web::history_state_util::IsHistoryStateChangeValid(
+ currentItem->GetURL(), URL));
+ web::Referrer referrer(currentItem->GetURL(), web::ReferrerPolicyDefault);
+
base::scoped_nsobject<CRWSessionEntry> pushedEntry([self
sessionEntryWithURL:URL
referrer:referrer
transition:transition
- useDesktopUserAgent:overrideUserAgent
- rendererInitiated:NO]);
+ initiationType:web::NavigationInitiationType::USER_INITIATED]);
+
web::NavigationItemImpl* pushedItem = [pushedEntry navigationItemImpl];
+ pushedItem->SetIsOverridingUserAgent(currentItem->IsOverridingUserAgent());
pushedItem->SetSerializedStateObject(stateObject);
pushedItem->SetIsCreatedFromPushState(true);
web::SSLStatus& sslStatus = [self currentEntry].navigationItem->GetSSL();
@@ -673,13 +677,6 @@ - (CRWSessionEntry*)lastUserEntry {
return [_entries objectAtIndex:index];
}
-- (void)useDesktopUserAgentForNextPendingItem {
- if (_pendingEntry)
- [_pendingEntry navigationItem]->SetIsOverridingUserAgent(true);
- else
- _useDesktopUserAgentForNextPendingItem = YES;
-}
-
- (NSInteger)indexOfItem:(const web::NavigationItem*)item {
web::NavigationItemList items = self.items;
for (NSInteger i = 0; i < static_cast<NSInteger>(items.size()); ++i) {
@@ -695,8 +692,8 @@ - (NSInteger)indexOfItem:(const web::NavigationItem*)item {
- (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url
referrer:(const web::Referrer&)referrer
transition:(ui::PageTransition)transition
- useDesktopUserAgent:(BOOL)useDesktopUserAgent
- rendererInitiated:(BOOL)rendererInitiated {
+ initiationType:
+ (web::NavigationInitiationType)initiationType {
GURL loaded_url(url);
BOOL urlWasRewritten = NO;
if (_navigationManager) {
@@ -711,13 +708,13 @@ - (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url
web::BrowserURLRewriter::GetInstance()->RewriteURLIfNecessary(
&loaded_url, _browserState);
}
+
std::unique_ptr<web::NavigationItemImpl> item(new web::NavigationItemImpl());
item->SetOriginalRequestURL(loaded_url);
item->SetURL(loaded_url);
item->SetReferrer(referrer);
item->SetTransitionType(transition);
- item->SetIsOverridingUserAgent(useDesktopUserAgent);
- item->set_is_renderer_initiated(rendererInitiated);
+ item->SetNavigationInitiationType(initiationType);
return [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)];
}
« 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