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

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

Issue 2705293014: Created web::UserAgentType. (Closed)
Patch Set: self review 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
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
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();
189 bool use_desktop_user_agent = 190 if (pending_item) {
liaoyuke 2017/02/25 01:28:19 Can we change this to: if (!pending_item) ret
kkhorimoto 2017/02/25 01:35:05 Done.
190 override_desktop_user_agent_for_next_pending_item_ || 191 // |override_desktop_user_agent_for_next_pending_item_| must be false if
191 (GetLastCommittedItem() && 192 // |pending_item|'s UserAgentType is NONE, as requesting a desktop user
192 GetLastCommittedItem()->IsOverridingUserAgent()); 193 // agent should be disabled for app-specific URLs.
193 GetPendingItem()->SetIsOverridingUserAgent(use_desktop_user_agent); 194 DCHECK(pending_item->GetUserAgentType() != UserAgentType::NONE ||
195 !override_desktop_user_agent_for_next_pending_item_);
196
197 if (pending_item->GetUserAgentType() != UserAgentType::NONE) {
198 NavigationItem* last_web_item = GetLastCommittedWebItem();
199 DCHECK(!last_web_item ||
200 last_web_item->GetUserAgentType() != UserAgentType::NONE);
201 bool use_desktop_user_agent =
202 override_desktop_user_agent_for_next_pending_item_ ||
203 (last_web_item &&
204 last_web_item->GetUserAgentType() == UserAgentType::DESKTOP);
205 if (use_desktop_user_agent)
206 pending_item->SetUserAgentType(UserAgentType::DESKTOP);
207 }
194 override_desktop_user_agent_for_next_pending_item_ = false; 208 override_desktop_user_agent_for_next_pending_item_ = false;
195 } 209 }
196 } 210 }
197 211
198 NavigationItem* NavigationManagerImpl::GetLastUserItem() const { 212 NavigationItem* NavigationManagerImpl::GetLastUserItem() const {
199 return [session_controller_ lastUserItem]; 213 return [session_controller_ lastUserItem];
200 } 214 }
201 215
202 NavigationItem* NavigationManagerImpl::GetPreviousItem() const { 216 NavigationItem* NavigationManagerImpl::GetPreviousItem() const {
203 return [session_controller_ previousItem]; 217 return [session_controller_ previousItem];
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 // simply add the remainder. 415 // simply add the remainder.
402 result += offset; 416 result += offset;
403 if (result < 0 /* overflow */) 417 if (result < 0 /* overflow */)
404 result = INT_MAX; 418 result = INT_MAX;
405 } 419 }
406 420
407 return result; 421 return result;
408 } 422 }
409 423
410 void NavigationManagerImpl::OverrideDesktopUserAgentForNextPendingItem() { 424 void NavigationManagerImpl::OverrideDesktopUserAgentForNextPendingItem() {
411 if (GetPendingItem()) 425 NavigationItem* pending_item = GetPendingItem();
412 GetPendingItem()->SetIsOverridingUserAgent(true); 426 if (pending_item) {
413 else 427 // The desktop user agent cannot be used for a pending navigation to an
428 // app-specific URL.
429 DCHECK_NE(pending_item->GetUserAgentType(), UserAgentType::NONE);
430 pending_item->SetUserAgentType(UserAgentType::DESKTOP);
431 } else {
414 override_desktop_user_agent_for_next_pending_item_ = true; 432 override_desktop_user_agent_for_next_pending_item_ = true;
433 }
415 } 434 }
416 435
417 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { 436 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const {
418 DCHECK_GT(index, 0); 437 DCHECK_GT(index, 0);
419 DCHECK_LT(index, GetItemCount()); 438 DCHECK_LT(index, GetItemCount());
420 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); 439 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType();
421 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; 440 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK;
422 } 441 }
423 442
443 NavigationItem* NavigationManagerImpl::GetLastCommittedWebItem() const {
444 int index = GetCurrentItemIndex();
445 NavigationItemList items = [session_controller_ items];
446 if (index < 0 || index >= static_cast<int>(items.size()))
447 return nullptr;
448 WebClient* client = GetWebClient();
449 while (index >= 0) {
450 NavigationItem* item = items[index];
451 if (!client->IsAppSpecificURL(item->GetVirtualURL()))
452 return item;
453 }
454 return nullptr;
455 }
456
424 } // namespace web 457 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698