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

Side by Side Diff: ios/web/navigation/navigation_manager_impl.mm

Issue 2698773002: [iOS] Refactoring web CRWSessionController user agent code. (Closed)
Patch Set: Update NavigationItemImpl to use NavigationInitiationType Created 3 years, 10 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 unified diff | Download patch
OLDNEW
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
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
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 bool renderer_initiated =
185 initiation_type == NavigationInitiationType::RENDERER_INITIATED;
186 [session_controller_ addPendingItem:url
187 referrer:referrer
188 transition:navigation_type
189 rendererInitiated:renderer_initiated];
190
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
176 NavigationItem* NavigationManagerImpl::GetLastUserItem() const { 199 NavigationItem* NavigationManagerImpl::GetLastUserItem() const {
177 CRWSessionEntry* entry = [session_controller_ lastUserEntry]; 200 CRWSessionEntry* entry = [session_controller_ lastUserEntry];
178 return [entry navigationItem]; 201 return [entry navigationItem];
179 } 202 }
180 203
181 NavigationItem* NavigationManagerImpl::GetPreviousItem() const { 204 NavigationItem* NavigationManagerImpl::GetPreviousItem() const {
182 CRWSessionEntry* entry = [session_controller_ previousEntry]; 205 CRWSessionEntry* entry = [session_controller_ previousEntry];
183 return [entry navigationItem]; 206 return [entry navigationItem];
184 } 207 }
185 208
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // Result may be out of bounds, so stop trying to skip redirect items and 412 // Result may be out of bounds, so stop trying to skip redirect items and
390 // simply add the remainder. 413 // simply add the remainder.
391 result += offset; 414 result += offset;
392 if (result < 0 /* overflow */) 415 if (result < 0 /* overflow */)
393 result = INT_MAX; 416 result = INT_MAX;
394 } 417 }
395 418
396 return result; 419 return result;
397 } 420 }
398 421
422 void NavigationManagerImpl::OverrideDesktopUserAgentForNextPendingItem() {
423 if (GetPendingItem())
424 GetPendingItem()->SetIsOverridingUserAgent(true);
425 else
426 override_desktop_user_agent_for_next_pending_item_ = true;
427 }
428
399 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { 429 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const {
400 DCHECK_GT(index, 0); 430 DCHECK_GT(index, 0);
401 DCHECK_LT(index, GetItemCount()); 431 DCHECK_LT(index, GetItemCount());
402 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); 432 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType();
403 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; 433 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK;
404 } 434 }
405 435
406 } // namespace web 436 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698