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

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

Issue 2698773002: [iOS] Refactoring web CRWSessionController user agent code. (Closed)
Patch Set: Update NavigationItemImpl to use NavigationInitiationType 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
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 aa98921e620a5bc72c68361aaeca35d56bf95462..e1d0a31f7bd424bea5be64a5887233ab4553bf92 100644
--- a/ios/web/navigation/crw_session_controller.mm
+++ b/ios/web/navigation/crw_session_controller.mm
@@ -114,7 +114,6 @@ - (void)discardTransientItem;
- (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url
referrer:(const web::Referrer&)referrer
transition:(ui::PageTransition)transition
- useDesktopUserAgent:(BOOL)useDesktopUserAgent
rendererInitiated:(BOOL)rendererInitiated;
kkhorimoto 2017/02/17 20:51:35 Let's update this API to use web::NavigationInitia
liaoyuke 2017/02/17 22:15:40 Done.
// Returns YES if the PageTransition for the underlying navigationItem at
// |index| in |entries_| has ui::PAGE_TRANSITION_IS_REDIRECT_MASK.
@@ -318,8 +317,7 @@ - (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() &&
+ bool safeToShowPending = pendingItem && !pendingItem->IsRendererInitiated() &&
_pendingItemIndex == -1;
if (safeToShowPending) {
return _pendingEntry.get();
@@ -367,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
@@ -382,15 +387,9 @@ - (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]);
if (_navigationManager && _navigationManager->GetFacadeDelegate()) {
@@ -484,7 +483,6 @@ - (void)addTransientItemWithURL:(const GURL&)URL {
sessionEntryWithURL:URL
referrer:web::Referrer()
transition:ui::PAGE_TRANSITION_CLIENT_REDIRECT
- useDesktopUserAgent:NO
rendererInitiated:NO]);
web::NavigationItem* navigationItem = [_transientEntry navigationItem];
@@ -498,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]);
+
web::NavigationItemImpl* pushedItem = [pushedEntry navigationItemImpl];
+ pushedItem->SetIsOverridingUserAgent(currentItem->IsOverridingUserAgent());
pushedItem->SetSerializedStateObject(stateObject);
pushedItem->SetIsCreatedFromPushState(true);
web::SSLStatus& sslStatus = [self currentEntry].navigationItem->GetSSL();
@@ -679,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) {
@@ -712,7 +703,6 @@ - (NSString*)uniqueID {
- (CRWSessionEntry*)sessionEntryWithURL:(const GURL&)url
referrer:(const web::Referrer&)referrer
transition:(ui::PageTransition)transition
- useDesktopUserAgent:(BOOL)useDesktopUserAgent
rendererInitiated:(BOOL)rendererInitiated {
GURL loaded_url(url);
BOOL urlWasRewritten = NO;
@@ -728,13 +718,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->SetIsRendererInitiated(rendererInitiated);
return [[CRWSessionEntry alloc] initWithNavigationItem:std::move(item)];
}

Powered by Google App Engine
This is Rietveld 408576698