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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 void NavigationManagerImpl::AddPendingItem( | 178 void NavigationManagerImpl::AddPendingItem( |
178 const GURL& url, | 179 const GURL& url, |
179 const web::Referrer& referrer, | 180 const web::Referrer& referrer, |
180 ui::PageTransition navigation_type, | 181 ui::PageTransition navigation_type, |
181 NavigationInitiationType initiation_type) { | 182 NavigationInitiationType initiation_type) { |
182 [session_controller_ addPendingItem:url | 183 [session_controller_ addPendingItem:url |
183 referrer:referrer | 184 referrer:referrer |
184 transition:navigation_type | 185 transition:navigation_type |
185 initiationType:initiation_type]; | 186 initiationType:initiation_type]; |
186 | 187 |
187 // Do nothing if pending item is the same as last committed item. | 188 // Set the user agent type for web URLs. |
188 if (GetPendingItem()) { | 189 NavigationItem* pending_item = GetPendingItem(); |
| 190 if (!pending_item) |
| 191 return; |
| 192 |
| 193 // |override_desktop_user_agent_for_next_pending_item_| must be false if |
| 194 // |pending_item|'s UserAgentType is NONE, as requesting a desktop user |
| 195 // agent should be disabled for app-specific URLs. |
| 196 DCHECK(pending_item->GetUserAgentType() != UserAgentType::NONE || |
| 197 !override_desktop_user_agent_for_next_pending_item_); |
| 198 |
| 199 if (pending_item->GetUserAgentType() != UserAgentType::NONE) { |
| 200 NavigationItem* last_non_native_item = GetLastCommittedNonAppSpecificItem(); |
| 201 DCHECK(!last_non_native_item || |
| 202 last_non_native_item->GetUserAgentType() != UserAgentType::NONE); |
| 203 bool last_web_item_uses_desktop_user_agent = |
| 204 last_non_native_item && |
| 205 last_non_native_item->GetUserAgentType() == UserAgentType::DESKTOP; |
189 bool use_desktop_user_agent = | 206 bool use_desktop_user_agent = |
190 override_desktop_user_agent_for_next_pending_item_ || | 207 override_desktop_user_agent_for_next_pending_item_ || |
191 (GetLastCommittedItem() && | 208 last_web_item_uses_desktop_user_agent; |
192 GetLastCommittedItem()->IsOverridingUserAgent()); | 209 if (use_desktop_user_agent) |
193 GetPendingItem()->SetIsOverridingUserAgent(use_desktop_user_agent); | 210 pending_item->SetUserAgentType(UserAgentType::DESKTOP); |
194 override_desktop_user_agent_for_next_pending_item_ = false; | |
195 } | 211 } |
| 212 override_desktop_user_agent_for_next_pending_item_ = false; |
196 } | 213 } |
197 | 214 |
198 NavigationItem* NavigationManagerImpl::GetLastUserItem() const { | 215 NavigationItem* NavigationManagerImpl::GetLastUserItem() const { |
199 return [session_controller_ lastUserItem]; | 216 return [session_controller_ lastUserItem]; |
200 } | 217 } |
201 | 218 |
202 NavigationItem* NavigationManagerImpl::GetPreviousItem() const { | 219 NavigationItem* NavigationManagerImpl::GetPreviousItem() const { |
203 return [session_controller_ previousItem]; | 220 return [session_controller_ previousItem]; |
204 } | 221 } |
205 | 222 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 // simply add the remainder. | 418 // simply add the remainder. |
402 result += offset; | 419 result += offset; |
403 if (result < 0 /* overflow */) | 420 if (result < 0 /* overflow */) |
404 result = INT_MAX; | 421 result = INT_MAX; |
405 } | 422 } |
406 | 423 |
407 return result; | 424 return result; |
408 } | 425 } |
409 | 426 |
410 void NavigationManagerImpl::OverrideDesktopUserAgentForNextPendingItem() { | 427 void NavigationManagerImpl::OverrideDesktopUserAgentForNextPendingItem() { |
411 if (GetPendingItem()) | 428 NavigationItem* pending_item = GetPendingItem(); |
412 GetPendingItem()->SetIsOverridingUserAgent(true); | 429 if (pending_item) { |
413 else | 430 // The desktop user agent cannot be used for a pending navigation to an |
| 431 // app-specific URL. |
| 432 DCHECK_NE(pending_item->GetUserAgentType(), UserAgentType::NONE); |
| 433 pending_item->SetUserAgentType(UserAgentType::DESKTOP); |
| 434 } else { |
414 override_desktop_user_agent_for_next_pending_item_ = true; | 435 override_desktop_user_agent_for_next_pending_item_ = true; |
| 436 } |
415 } | 437 } |
416 | 438 |
417 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { | 439 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { |
418 DCHECK_GT(index, 0); | 440 DCHECK_GT(index, 0); |
419 DCHECK_LT(index, GetItemCount()); | 441 DCHECK_LT(index, GetItemCount()); |
420 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); | 442 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); |
421 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; | 443 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; |
422 } | 444 } |
423 | 445 |
| 446 NavigationItem* NavigationManagerImpl::GetLastCommittedNonAppSpecificItem() |
| 447 const { |
| 448 int index = GetCurrentItemIndex(); |
| 449 if (index == -1) |
| 450 return nullptr; |
| 451 WebClient* client = GetWebClient(); |
| 452 NavigationItemList items = [session_controller_ items]; |
| 453 while (index >= 0) { |
| 454 NavigationItem* item = items[index--]; |
| 455 if (!client->IsAppSpecificURL(item->GetVirtualURL())) |
| 456 return item; |
| 457 } |
| 458 return nullptr; |
| 459 } |
| 460 |
424 } // namespace web | 461 } // namespace web |
OLD | NEW |