| 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 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 referrer = other.referrer; | 61 referrer = other.referrer; |
| 62 is_renderer_initiated = other.is_renderer_initiated; | 62 is_renderer_initiated = other.is_renderer_initiated; |
| 63 transition_type = other.transition_type; | 63 transition_type = other.transition_type; |
| 64 extra_headers.reset([other.extra_headers copy]); | 64 extra_headers.reset([other.extra_headers copy]); |
| 65 post_data.reset([other.post_data copy]); | 65 post_data.reset([other.post_data copy]); |
| 66 | 66 |
| 67 return *this; | 67 return *this; |
| 68 } | 68 } |
| 69 | 69 |
| 70 NavigationManagerImpl::NavigationManagerImpl() | 70 NavigationManagerImpl::NavigationManagerImpl() |
| 71 : delegate_(nullptr), browser_state_(nullptr), facade_delegate_(nullptr) {} | 71 : override_desktop_user_agent_for_next_pending_item_(false), |
| 72 delegate_(nullptr), |
| 73 browser_state_(nullptr), |
| 74 facade_delegate_(nullptr) {} |
| 72 | 75 |
| 73 NavigationManagerImpl::~NavigationManagerImpl() { | 76 NavigationManagerImpl::~NavigationManagerImpl() { |
| 74 // The facade layer should be deleted before this object. | 77 // The facade layer should be deleted before this object. |
| 75 DCHECK(!facade_delegate_); | 78 DCHECK(!facade_delegate_); |
| 76 | 79 |
| 77 [session_controller_ setNavigationManager:nullptr]; | 80 [session_controller_ setNavigationManager:nullptr]; |
| 78 } | 81 } |
| 79 | 82 |
| 80 void NavigationManagerImpl::SetDelegate(NavigationManagerDelegate* delegate) { | 83 void NavigationManagerImpl::SetDelegate(NavigationManagerDelegate* delegate) { |
| 81 delegate_ = delegate; | 84 delegate_ = delegate; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 } | 169 } |
| 167 | 170 |
| 168 void NavigationManagerImpl::LoadURL(const GURL& url, | 171 void NavigationManagerImpl::LoadURL(const GURL& url, |
| 169 const web::Referrer& referrer, | 172 const web::Referrer& referrer, |
| 170 ui::PageTransition type) { | 173 ui::PageTransition type) { |
| 171 WebState::OpenURLParams params(url, referrer, | 174 WebState::OpenURLParams params(url, referrer, |
| 172 WindowOpenDisposition::CURRENT_TAB, type, NO); | 175 WindowOpenDisposition::CURRENT_TAB, type, NO); |
| 173 delegate_->GetWebState()->OpenURL(params); | 176 delegate_->GetWebState()->OpenURL(params); |
| 174 } | 177 } |
| 175 | 178 |
| 179 void NavigationManagerImpl::AddPendingItem(const GURL& url, |
| 180 const web::Referrer& referrer, |
| 181 ui::PageTransition navigation_type, |
| 182 ItemInitiationType initiation_type) { |
| 183 bool renderer_initiated = |
| 184 initiation_type == ItemInitiationType::RENDERER_INITIATED; |
| 185 [session_controller_ addPendingItem:url |
| 186 referrer:referrer |
| 187 transition:navigation_type |
| 188 rendererInitiated:renderer_initiated]; |
| 189 |
| 190 bool use_desktop_user_agent = |
| 191 override_desktop_user_agent_for_next_pending_item_ || |
| 192 (GetLastCommittedItem() && |
| 193 GetLastCommittedItem()->IsOverridingUserAgent()); |
| 194 GetPendingItem()->SetIsOverridingUserAgent(use_desktop_user_agent); |
| 195 override_desktop_user_agent_for_next_pending_item_ = false; |
| 196 } |
| 197 |
| 176 NavigationItem* NavigationManagerImpl::GetLastUserItem() const { | 198 NavigationItem* NavigationManagerImpl::GetLastUserItem() const { |
| 177 CRWSessionEntry* entry = [session_controller_ lastUserEntry]; | 199 CRWSessionEntry* entry = [session_controller_ lastUserEntry]; |
| 178 return [entry navigationItem]; | 200 return [entry navigationItem]; |
| 179 } | 201 } |
| 180 | 202 |
| 181 NavigationItem* NavigationManagerImpl::GetPreviousItem() const { | 203 NavigationItem* NavigationManagerImpl::GetPreviousItem() const { |
| 182 CRWSessionEntry* entry = [session_controller_ previousEntry]; | 204 CRWSessionEntry* entry = [session_controller_ previousEntry]; |
| 183 return [entry navigationItem]; | 205 return [entry navigationItem]; |
| 184 } | 206 } |
| 185 | 207 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 // Result may be out of bounds, so stop trying to skip redirect items and | 411 // Result may be out of bounds, so stop trying to skip redirect items and |
| 390 // simply add the remainder. | 412 // simply add the remainder. |
| 391 result += offset; | 413 result += offset; |
| 392 if (result < 0 /* overflow */) | 414 if (result < 0 /* overflow */) |
| 393 result = INT_MAX; | 415 result = INT_MAX; |
| 394 } | 416 } |
| 395 | 417 |
| 396 return result; | 418 return result; |
| 397 } | 419 } |
| 398 | 420 |
| 421 void NavigationManagerImpl::OverrideDesktopUserAgentForNextPendingItem() { |
| 422 if (GetPendingItem()) |
| 423 GetPendingItem()->SetIsOverridingUserAgent(true); |
| 424 else |
| 425 override_desktop_user_agent_for_next_pending_item_ = true; |
| 426 } |
| 427 |
| 399 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { | 428 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { |
| 400 DCHECK_GT(index, 0); | 429 DCHECK_GT(index, 0); |
| 401 DCHECK_LT(index, GetItemCount()); | 430 DCHECK_LT(index, GetItemCount()); |
| 402 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); | 431 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); |
| 403 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; | 432 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; |
| 404 } | 433 } |
| 405 | 434 |
| 406 } // namespace web | 435 } // namespace web |
| OLD | NEW |