| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/web/navigation/navigation_manager_impl.h" | 5 #import "ios/web/navigation/navigation_manager_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #import "ios/web/navigation/crw_session_controller+private_constructors.h" | 12 #import "ios/web/navigation/crw_session_controller+private_constructors.h" |
| 13 #import "ios/web/navigation/crw_session_controller.h" | 13 #import "ios/web/navigation/crw_session_controller.h" |
| 14 #import "ios/web/navigation/navigation_item_impl.h" | 14 #import "ios/web/navigation/navigation_item_impl.h" |
| 15 #import "ios/web/navigation/navigation_manager_delegate.h" | 15 #import "ios/web/navigation/navigation_manager_delegate.h" |
| 16 #include "ios/web/navigation/navigation_manager_facade_delegate.h" | 16 #include "ios/web/navigation/navigation_manager_facade_delegate.h" |
| 17 #include "ios/web/public/load_committed_details.h" | 17 #include "ios/web/public/load_committed_details.h" |
| 18 #import "ios/web/public/navigation_item.h" | 18 #import "ios/web/public/navigation_item.h" |
| 19 #import "ios/web/public/web_client.h" |
| 19 #import "ios/web/public/web_state/web_state.h" | 20 #import "ios/web/public/web_state/web_state.h" |
| 20 #include "ui/base/page_transition_types.h" | 21 #include "ui/base/page_transition_types.h" |
| 21 | 22 |
| 22 #if !defined(__has_feature) || !__has_feature(objc_arc) | 23 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 23 #error "This file requires ARC support." | 24 #error "This file requires ARC support." |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 // Checks whether or not two URL are an in-page navigation (differing only | 29 // Checks whether or not two URL are an in-page navigation (differing only |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 void NavigationManagerImpl::AddPendingItem( | 172 void NavigationManagerImpl::AddPendingItem( |
| 172 const GURL& url, | 173 const GURL& url, |
| 173 const web::Referrer& referrer, | 174 const web::Referrer& referrer, |
| 174 ui::PageTransition navigation_type, | 175 ui::PageTransition navigation_type, |
| 175 NavigationInitiationType initiation_type) { | 176 NavigationInitiationType initiation_type) { |
| 176 [session_controller_ addPendingItem:url | 177 [session_controller_ addPendingItem:url |
| 177 referrer:referrer | 178 referrer:referrer |
| 178 transition:navigation_type | 179 transition:navigation_type |
| 179 initiationType:initiation_type]; | 180 initiationType:initiation_type]; |
| 180 | 181 |
| 181 // Do nothing if pending item is the same as last committed item. | 182 // Set the user agent type for web URLs. |
| 182 if (GetPendingItem()) { | 183 NavigationItem* pending_item = GetPendingItem(); |
| 184 if (!pending_item) |
| 185 return; |
| 186 |
| 187 // |override_desktop_user_agent_for_next_pending_item_| must be false if |
| 188 // |pending_item|'s UserAgentType is NONE, as requesting a desktop user |
| 189 // agent should be disabled for app-specific URLs. |
| 190 DCHECK(pending_item->GetUserAgentType() != UserAgentType::NONE || |
| 191 !override_desktop_user_agent_for_next_pending_item_); |
| 192 |
| 193 // Newly created pending items are created with UserAgentType::NONE for native |
| 194 // pages or UserAgentType::MOBILE for non-native pages. If the pending item's |
| 195 // URL is non-native, check whether it should be created with |
| 196 // UserAgentType::DESKTOP. |
| 197 DCHECK_NE(UserAgentType::DESKTOP, pending_item->GetUserAgentType()); |
| 198 if (pending_item->GetUserAgentType() != UserAgentType::NONE) { |
| 183 bool use_desktop_user_agent = | 199 bool use_desktop_user_agent = |
| 184 override_desktop_user_agent_for_next_pending_item_ || | 200 override_desktop_user_agent_for_next_pending_item_; |
| 185 (GetLastCommittedItem() && | 201 if (!use_desktop_user_agent) { |
| 186 GetLastCommittedItem()->IsOverridingUserAgent()); | 202 // If the flag is not set, propagate the last non-native item's |
| 187 GetPendingItem()->SetIsOverridingUserAgent(use_desktop_user_agent); | 203 // UserAgentType. |
| 188 override_desktop_user_agent_for_next_pending_item_ = false; | 204 NavigationItem* last_non_native_item = |
| 205 GetLastCommittedNonAppSpecificItem(); |
| 206 DCHECK(!last_non_native_item || |
| 207 last_non_native_item->GetUserAgentType() != UserAgentType::NONE); |
| 208 use_desktop_user_agent = |
| 209 last_non_native_item && |
| 210 last_non_native_item->GetUserAgentType() == UserAgentType::DESKTOP; |
| 211 } |
| 212 if (use_desktop_user_agent) |
| 213 pending_item->SetUserAgentType(UserAgentType::DESKTOP); |
| 189 } | 214 } |
| 215 override_desktop_user_agent_for_next_pending_item_ = false; |
| 190 } | 216 } |
| 191 | 217 |
| 192 NavigationItem* NavigationManagerImpl::GetLastUserItem() const { | 218 NavigationItem* NavigationManagerImpl::GetLastUserItem() const { |
| 193 return [session_controller_ lastUserItem]; | 219 return [session_controller_ lastUserItem]; |
| 194 } | 220 } |
| 195 | 221 |
| 196 NavigationItem* NavigationManagerImpl::GetPreviousItem() const { | 222 NavigationItem* NavigationManagerImpl::GetPreviousItem() const { |
| 197 return [session_controller_ previousItem]; | 223 return [session_controller_ previousItem]; |
| 198 } | 224 } |
| 199 | 225 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 // simply add the remainder. | 421 // simply add the remainder. |
| 396 result += offset; | 422 result += offset; |
| 397 if (result < 0 /* overflow */) | 423 if (result < 0 /* overflow */) |
| 398 result = INT_MAX; | 424 result = INT_MAX; |
| 399 } | 425 } |
| 400 | 426 |
| 401 return result; | 427 return result; |
| 402 } | 428 } |
| 403 | 429 |
| 404 void NavigationManagerImpl::OverrideDesktopUserAgentForNextPendingItem() { | 430 void NavigationManagerImpl::OverrideDesktopUserAgentForNextPendingItem() { |
| 405 if (GetPendingItem()) | 431 NavigationItem* pending_item = GetPendingItem(); |
| 406 GetPendingItem()->SetIsOverridingUserAgent(true); | 432 if (pending_item) { |
| 407 else | 433 // The desktop user agent cannot be used for a pending navigation to an |
| 434 // app-specific URL. |
| 435 DCHECK_NE(pending_item->GetUserAgentType(), UserAgentType::NONE); |
| 436 pending_item->SetUserAgentType(UserAgentType::DESKTOP); |
| 437 } else { |
| 408 override_desktop_user_agent_for_next_pending_item_ = true; | 438 override_desktop_user_agent_for_next_pending_item_ = true; |
| 439 } |
| 409 } | 440 } |
| 410 | 441 |
| 411 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { | 442 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { |
| 412 DCHECK_GT(index, 0); | 443 DCHECK_GT(index, 0); |
| 413 DCHECK_LT(index, GetItemCount()); | 444 DCHECK_LT(index, GetItemCount()); |
| 414 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); | 445 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); |
| 415 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; | 446 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; |
| 416 } | 447 } |
| 417 | 448 |
| 449 NavigationItem* NavigationManagerImpl::GetLastCommittedNonAppSpecificItem() |
| 450 const { |
| 451 int index = GetCurrentItemIndex(); |
| 452 if (index == -1) |
| 453 return nullptr; |
| 454 WebClient* client = GetWebClient(); |
| 455 NavigationItemList items = [session_controller_ items]; |
| 456 while (index >= 0) { |
| 457 NavigationItem* item = items[index--]; |
| 458 if (!client->IsAppSpecificURL(item->GetVirtualURL())) |
| 459 return item; |
| 460 } |
| 461 return nullptr; |
| 462 } |
| 463 |
| 418 } // namespace web | 464 } // namespace web |
| OLD | NEW |