Chromium Code Reviews| 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(); |
| 189 bool use_desktop_user_agent = | 190 if (pending_item) { |
| 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); | |
|
Eugene But (OOO till 7-30)
2017/02/25 01:51:52
How about adding one more local variable for "(las
kkhorimoto
2017/02/27 23:29:04
Done.
| |
| 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 Loading... | |
| 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 { | |
|
Eugene But (OOO till 7-30)
2017/02/25 01:51:52
From this name I would think that it returns the l
kkhorimoto
2017/02/27 23:29:04
Done.
| |
| 444 int index = GetCurrentItemIndex(); | |
| 445 NavigationItemList items = [session_controller_ items]; | |
| 446 if (index < 0 || index >= static_cast<int>(items.size())) | |
|
Eugene But (OOO till 7-30)
2017/02/25 01:51:52
Can index even be larger than size?
kkhorimoto
2017/02/27 23:29:04
No, it would have DCHECKED when we set it to an in
| |
| 447 return nullptr; | |
| 448 WebClient* client = GetWebClient(); | |
| 449 while (index >= 0) { | |
|
Eugene But (OOO till 7-30)
2017/02/25 01:51:52
Do you want to use for-loop here?:
WebClient* cli
kkhorimoto
2017/02/27 23:29:04
Since we already fetch the current index when perf
Eugene But (OOO till 7-30)
2017/03/02 03:36:34
You actually don't need that check above. You can
| |
| 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 |
| OLD | NEW |