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

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

Issue 2705293014: Created web::UserAgentType. (Closed)
Patch Set: simplify UA type setter, added TODO 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/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) {
Eugene But (OOO till 7-30) 2017/03/02 03:36:34 What if |pending_item->GetUserAgentType()| has DES
kkhorimoto 2017/03/02 04:12:55 pending_item->GetUserAgentType() will never be DES
+ 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_ ||
Eugene But (OOO till 7-30) 2017/03/02 03:36:34 Can you restructure the code, so if |override_desk
kkhorimoto 2017/03/02 04:12:55 Done.
- (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

Powered by Google App Engine
This is Rietveld 408576698