Chromium Code Reviews| 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..348ebe589a0163632298ae6a3c9f9d9a859f9cd4 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) { |
|
liaoyuke
2017/02/25 01:28:19
Can we change this to:
if (!pending_item)
ret
kkhorimoto
2017/02/25 01:35:05
Done.
|
| + // |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); |
| + 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 { |
| + int index = GetCurrentItemIndex(); |
| + NavigationItemList items = [session_controller_ items]; |
| + if (index < 0 || index >= static_cast<int>(items.size())) |
| + return nullptr; |
| + WebClient* client = GetWebClient(); |
| + while (index >= 0) { |
| + NavigationItem* item = items[index]; |
| + if (!client->IsAppSpecificURL(item->GetVirtualURL())) |
| + return item; |
| + } |
| + return nullptr; |
| +} |
| + |
| } // namespace web |