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

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

Issue 2779383002: implement user agent override option. (Closed)
Patch Set: Created 3 years, 9 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 a9e42e85157e6e0aab693ee103ae6ee809afc2b3..7337811b517521ccf7653cab4db94af31696afd3 100644
--- a/ios/web/navigation/navigation_manager_impl.mm
+++ b/ios/web/navigation/navigation_manager_impl.mm
@@ -44,6 +44,7 @@ bool AreURLsInPageNavigation(const GURL& existing_url, const GURL& new_url) {
NavigationManager::WebLoadParams::WebLoadParams(const GURL& url)
: url(url),
transition_type(ui::PAGE_TRANSITION_LINK),
+ user_agent_override_option(UserAgentOverrideOption::INHERIT),
is_renderer_initiated(false),
post_data(nil) {}
@@ -53,6 +54,7 @@ bool AreURLsInPageNavigation(const GURL& existing_url, const GURL& new_url) {
: url(other.url),
referrer(other.referrer),
transition_type(other.transition_type),
+ user_agent_override_option(other.user_agent_override_option),
is_renderer_initiated(other.is_renderer_initiated),
extra_headers([other.extra_headers copy]),
post_data([other.post_data copy]) {}
@@ -63,6 +65,7 @@ bool AreURLsInPageNavigation(const GURL& existing_url, const GURL& new_url) {
referrer = other.referrer;
is_renderer_initiated = other.is_renderer_initiated;
transition_type = other.transition_type;
+ user_agent_override_option = other.user_agent_override_option;
extra_headers.reset([other.extra_headers copy]);
post_data.reset([other.post_data copy]);
@@ -70,10 +73,7 @@ bool AreURLsInPageNavigation(const GURL& existing_url, const GURL& new_url) {
}
NavigationManagerImpl::NavigationManagerImpl()
- : override_desktop_user_agent_for_next_pending_item_(false),
- delegate_(nullptr),
- browser_state_(nullptr),
- facade_delegate_(nullptr) {}
+ : delegate_(nullptr), browser_state_(nullptr), facade_delegate_(nullptr) {}
NavigationManagerImpl::~NavigationManagerImpl() {
// The facade layer should be deleted before this object.
@@ -174,7 +174,8 @@ bool AreURLsInPageNavigation(const GURL& existing_url, const GURL& new_url) {
const GURL& url,
const web::Referrer& referrer,
ui::PageTransition navigation_type,
- NavigationInitiationType initiation_type) {
+ NavigationInitiationType initiation_type,
+ UserAgentOverrideOption user_agent_override_option) {
[session_controller_ addPendingItem:url
referrer:referrer
transition:navigation_type
@@ -185,35 +186,32 @@ bool AreURLsInPageNavigation(const GURL& existing_url, const GURL& new_url) {
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.
+ // |user_agent_override_option| must be INHERIT if |pending_item|'s
+ // UserAgentType is NONE, as requesting a desktop or mobile user agent should
+ // be disabled for app-specific URLs.
DCHECK(pending_item->GetUserAgentType() != UserAgentType::NONE ||
- !override_desktop_user_agent_for_next_pending_item_);
+ user_agent_override_option == UserAgentOverrideOption::INHERIT);
// Newly created pending items are created with UserAgentType::NONE for native
// pages or UserAgentType::MOBILE for non-native pages. If the pending item's
- // URL is non-native, check whether it should be created with
- // UserAgentType::DESKTOP.
+ // URL is non-native, check which user agent type it should be created with
+ // based on |user_agent_override_option|.
DCHECK_NE(UserAgentType::DESKTOP, pending_item->GetUserAgentType());
- if (pending_item->GetUserAgentType() != UserAgentType::NONE) {
- bool use_desktop_user_agent =
- override_desktop_user_agent_for_next_pending_item_;
- if (!use_desktop_user_agent) {
- // If the flag is not set, propagate the last non-native item's
- // UserAgentType.
- NavigationItem* last_non_native_item =
- GetLastCommittedNonAppSpecificItem();
- DCHECK(!last_non_native_item ||
- last_non_native_item->GetUserAgentType() != UserAgentType::NONE);
- use_desktop_user_agent =
- last_non_native_item &&
- last_non_native_item->GetUserAgentType() == UserAgentType::DESKTOP;
- }
- if (use_desktop_user_agent)
- pending_item->SetUserAgentType(UserAgentType::DESKTOP);
+ if (pending_item->GetUserAgentType() == UserAgentType::NONE)
+ return;
+
+ if (user_agent_override_option == UserAgentOverrideOption::DESKTOP) {
kkhorimoto 2017/03/30 02:30:28 NIT: Should we just use a switch statement here?
liaoyuke 2017/03/30 19:56:25 Done.
+ pending_item->SetUserAgentType(UserAgentType::DESKTOP);
+ } else if (user_agent_override_option == UserAgentOverrideOption::MOBILE) {
+ pending_item->SetUserAgentType(UserAgentType::MOBILE);
+ } else {
+ // If INHERIT, propagate the last non-native item's UserAgentType.
+ NavigationItem* last_non_native_item = GetLastCommittedNonAppSpecificItem();
+ DCHECK(!last_non_native_item ||
+ last_non_native_item->GetUserAgentType() != UserAgentType::NONE);
+ if (last_non_native_item)
+ pending_item->SetUserAgentType(last_non_native_item->GetUserAgentType());
}
- override_desktop_user_agent_for_next_pending_item_ = false;
}
NavigationItemList NavigationManagerImpl::GetItems() const {
@@ -445,18 +443,6 @@ bool AreURLsInPageNavigation(const GURL& existing_url, const GURL& new_url) {
return result;
}
-void NavigationManagerImpl::OverrideDesktopUserAgentForNextPendingItem() {
- 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 {
DCHECK_GE(index, 0);
DCHECK_LT(index, GetItemCount());

Powered by Google App Engine
This is Rietveld 408576698