Index: ios/web/navigation/navigation_manager_impl.mm |
diff --git a/ios/web/navigation/navigation_manager_impl.mm b/ios/web/navigation/navigation_manager_impl.mm |
index bb16cba464bb1a3689eeca3a77fd606ca20e5cfe..52ea0ec29f16e272650c32062a80f8af8f52c53d 100644 |
--- a/ios/web/navigation/navigation_manager_impl.mm |
+++ b/ios/web/navigation/navigation_manager_impl.mm |
@@ -16,6 +16,7 @@ |
#include "ios/web/navigation/navigation_manager_facade_delegate.h" |
#include "ios/web/public/load_committed_details.h" |
#import "ios/web/public/navigation_item.h" |
+#import "ios/web/public/web_client.h" |
#import "ios/web/public/web_state/web_state.h" |
#include "ui/base/page_transition_types.h" |
@@ -184,13 +185,26 @@ bool AreURLsInPageNavigation(const GURL& existing_url, const GURL& new_url) { |
transition:navigation_type |
initiationType:initiation_type]; |
- // Do nothing if pending item is the same as last committed item. |
- if (GetPendingItem()) { |
- bool use_desktop_user_agent = |
- override_desktop_user_agent_for_next_pending_item_ || |
- (GetLastCommittedItem() && |
- GetLastCommittedItem()->IsOverridingUserAgent()); |
- GetPendingItem()->SetIsOverridingUserAgent(use_desktop_user_agent); |
+ // Set the user agent type for web URLs. |
+ NavigationItem* pending_item = GetPendingItem(); |
+ if (pending_item) { |
+ // |override_desktop_user_agent_for_next_pending_item_| must be false if |
+ // |pending_item|'s UserAgentType is NONE, as requesting a desktop user |
+ // agent should be disabled for app-specific URLs. |
+ DCHECK(pending_item->GetUserAgentType() != UserAgentType::NONE || |
+ !override_desktop_user_agent_for_next_pending_item_); |
+ |
+ if (pending_item->GetUserAgentType() != UserAgentType::NONE) { |
+ NavigationItem* last_web_item = GetLastCommittedWebItem(); |
+ DCHECK(!last_web_item || |
+ last_web_item->GetUserAgentType() != UserAgentType::NONE); |
+ bool use_desktop_user_agent = |
+ override_desktop_user_agent_for_next_pending_item_ || |
+ (last_web_item && |
+ last_web_item->GetUserAgentType() == UserAgentType::DESKTOP); |
Eugene But (OOO till 7-30)
2017/02/25 01:51:52
How about adding one more local variable for "(las
kkhorimoto
2017/02/27 23:29:04
Done.
|
+ if (use_desktop_user_agent) |
+ pending_item->SetUserAgentType(UserAgentType::DESKTOP); |
+ } |
override_desktop_user_agent_for_next_pending_item_ = false; |
} |
} |
@@ -408,10 +422,15 @@ bool AreURLsInPageNavigation(const GURL& existing_url, const GURL& new_url) { |
} |
void NavigationManagerImpl::OverrideDesktopUserAgentForNextPendingItem() { |
- if (GetPendingItem()) |
- GetPendingItem()->SetIsOverridingUserAgent(true); |
- else |
+ NavigationItem* pending_item = GetPendingItem(); |
+ if (pending_item) { |
+ // The desktop user agent cannot be used for a pending navigation to an |
+ // app-specific URL. |
+ DCHECK_NE(pending_item->GetUserAgentType(), UserAgentType::NONE); |
+ pending_item->SetUserAgentType(UserAgentType::DESKTOP); |
+ } else { |
override_desktop_user_agent_for_next_pending_item_ = true; |
+ } |
} |
bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { |
@@ -421,4 +440,18 @@ bool AreURLsInPageNavigation(const GURL& existing_url, const GURL& new_url) { |
return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; |
} |
+NavigationItem* NavigationManagerImpl::GetLastCommittedWebItem() const { |
Eugene But (OOO till 7-30)
2017/02/25 01:51:52
From this name I would think that it returns the l
kkhorimoto
2017/02/27 23:29:04
Done.
|
+ int index = GetCurrentItemIndex(); |
+ NavigationItemList items = [session_controller_ items]; |
+ if (index < 0 || index >= static_cast<int>(items.size())) |
Eugene But (OOO till 7-30)
2017/02/25 01:51:52
Can index even be larger than size?
kkhorimoto
2017/02/27 23:29:04
No, it would have DCHECKED when we set it to an in
|
+ return nullptr; |
+ WebClient* client = GetWebClient(); |
+ while (index >= 0) { |
Eugene But (OOO till 7-30)
2017/02/25 01:51:52
Do you want to use for-loop here?:
WebClient* cli
kkhorimoto
2017/02/27 23:29:04
Since we already fetch the current index when perf
Eugene But (OOO till 7-30)
2017/03/02 03:36:34
You actually don't need that check above. You can
|
+ NavigationItem* item = items[index--]; |
+ if (!client->IsAppSpecificURL(item->GetVirtualURL())) |
+ return item; |
+ } |
+ return nullptr; |
+} |
+ |
} // namespace web |