| 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( |
| 180 const GURL& url, |
| 181 const web::Referrer& referrer, |
| 182 ui::PageTransition navigation_type, |
| 183 NavigationInitiationType initiation_type) { |
| 184 [session_controller_ addPendingItem:url |
| 185 referrer:referrer |
| 186 transition:navigation_type |
| 187 initiationType:initiation_type]; |
| 188 |
| 189 // Do nothing if pending item is the same as last committed item. |
| 190 if (GetPendingItem()) { |
| 191 bool use_desktop_user_agent = |
| 192 override_desktop_user_agent_for_next_pending_item_ || |
| 193 (GetLastCommittedItem() && |
| 194 GetLastCommittedItem()->IsOverridingUserAgent()); |
| 195 GetPendingItem()->SetIsOverridingUserAgent(use_desktop_user_agent); |
| 196 override_desktop_user_agent_for_next_pending_item_ = false; |
| 197 } |
| 198 } |
| 199 |
| 176 NavigationItem* NavigationManagerImpl::GetLastUserItem() const { | 200 NavigationItem* NavigationManagerImpl::GetLastUserItem() const { |
| 177 CRWSessionEntry* entry = [session_controller_ lastUserEntry]; | 201 CRWSessionEntry* entry = [session_controller_ lastUserEntry]; |
| 178 return [entry navigationItem]; | 202 return [entry navigationItem]; |
| 179 } | 203 } |
| 180 | 204 |
| 181 NavigationItem* NavigationManagerImpl::GetPreviousItem() const { | 205 NavigationItem* NavigationManagerImpl::GetPreviousItem() const { |
| 182 CRWSessionEntry* entry = [session_controller_ previousEntry]; | 206 CRWSessionEntry* entry = [session_controller_ previousEntry]; |
| 183 return [entry navigationItem]; | 207 return [entry navigationItem]; |
| 184 } | 208 } |
| 185 | 209 |
| (...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 | 413 // Result may be out of bounds, so stop trying to skip redirect items and |
| 390 // simply add the remainder. | 414 // simply add the remainder. |
| 391 result += offset; | 415 result += offset; |
| 392 if (result < 0 /* overflow */) | 416 if (result < 0 /* overflow */) |
| 393 result = INT_MAX; | 417 result = INT_MAX; |
| 394 } | 418 } |
| 395 | 419 |
| 396 return result; | 420 return result; |
| 397 } | 421 } |
| 398 | 422 |
| 423 void NavigationManagerImpl::OverrideDesktopUserAgentForNextPendingItem() { |
| 424 if (GetPendingItem()) |
| 425 GetPendingItem()->SetIsOverridingUserAgent(true); |
| 426 else |
| 427 override_desktop_user_agent_for_next_pending_item_ = true; |
| 428 } |
| 429 |
| 399 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { | 430 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { |
| 400 DCHECK_GT(index, 0); | 431 DCHECK_GT(index, 0); |
| 401 DCHECK_LT(index, GetItemCount()); | 432 DCHECK_LT(index, GetItemCount()); |
| 402 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); | 433 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); |
| 403 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; | 434 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; |
| 404 } | 435 } |
| 405 | 436 |
| 406 } // namespace web | 437 } // namespace web |
| OLD | NEW |