| 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..71bc8cf56262d87a21cc214e86bf8c28bed4a58f 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,15 +185,31 @@ 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()) {
|
| + // Set the user agent type for web URLs.
|
| + NavigationItem* pending_item = GetPendingItem();
|
| + if (!pending_item)
|
| + return;
|
| +
|
| + // |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_non_native_item = GetLastCommittedNonAppSpecificItem();
|
| + DCHECK(!last_non_native_item ||
|
| + last_non_native_item->GetUserAgentType() != UserAgentType::NONE);
|
| + bool last_web_item_uses_desktop_user_agent =
|
| + last_non_native_item &&
|
| + last_non_native_item->GetUserAgentType() == UserAgentType::DESKTOP;
|
| bool use_desktop_user_agent =
|
| override_desktop_user_agent_for_next_pending_item_ ||
|
| - (GetLastCommittedItem() &&
|
| - GetLastCommittedItem()->IsOverridingUserAgent());
|
| - GetPendingItem()->SetIsOverridingUserAgent(use_desktop_user_agent);
|
| - override_desktop_user_agent_for_next_pending_item_ = false;
|
| + last_web_item_uses_desktop_user_agent;
|
| + if (use_desktop_user_agent)
|
| + pending_item->SetUserAgentType(UserAgentType::DESKTOP);
|
| }
|
| + override_desktop_user_agent_for_next_pending_item_ = false;
|
| }
|
|
|
| NavigationItem* NavigationManagerImpl::GetLastUserItem() const {
|
| @@ -408,10 +425,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 +443,19 @@ bool AreURLsInPageNavigation(const GURL& existing_url, const GURL& new_url) {
|
| return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK;
|
| }
|
|
|
| +NavigationItem* NavigationManagerImpl::GetLastCommittedNonAppSpecificItem()
|
| + const {
|
| + int index = GetCurrentItemIndex();
|
| + if (index == -1)
|
| + return nullptr;
|
| + WebClient* client = GetWebClient();
|
| + NavigationItemList items = [session_controller_ items];
|
| + while (index >= 0) {
|
| + NavigationItem* item = items[index--];
|
| + if (!client->IsAppSpecificURL(item->GetVirtualURL()))
|
| + return item;
|
| + }
|
| + return nullptr;
|
| +}
|
| +
|
| } // namespace web
|
|
|