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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 void NavigationManagerImpl::AddPendingItem( | 172 void NavigationManagerImpl::AddPendingItem( |
172 const GURL& url, | 173 const GURL& url, |
173 const web::Referrer& referrer, | 174 const web::Referrer& referrer, |
174 ui::PageTransition navigation_type, | 175 ui::PageTransition navigation_type, |
175 NavigationInitiationType initiation_type) { | 176 NavigationInitiationType initiation_type) { |
176 [session_controller_ addPendingItem:url | 177 [session_controller_ addPendingItem:url |
177 referrer:referrer | 178 referrer:referrer |
178 transition:navigation_type | 179 transition:navigation_type |
179 initiationType:initiation_type]; | 180 initiationType:initiation_type]; |
180 | 181 |
181 // Do nothing if pending item is the same as last committed item. | 182 // Set the user agent type for web URLs. |
182 if (GetPendingItem()) { | 183 NavigationItem* pending_item = GetPendingItem(); |
184 if (!pending_item) | |
185 return; | |
186 | |
187 // |override_desktop_user_agent_for_next_pending_item_| must be false if | |
188 // |pending_item|'s UserAgentType is NONE, as requesting a desktop user | |
189 // agent should be disabled for app-specific URLs. | |
190 DCHECK(pending_item->GetUserAgentType() != UserAgentType::NONE || | |
191 !override_desktop_user_agent_for_next_pending_item_); | |
192 | |
193 // Newly created pending items are created with UserAgentType::NONE for native | |
194 // pages or UserAgentType::MOBILE for non-native pages. If the pending item's | |
195 // URL is non-native, check whether it should be created with | |
196 // UserAgentType::DESKTOP. | |
Eugene But (OOO till 7-30)
2017/03/02 06:44:06
Would it make sense to DCHECK_NE(ending_item->GetU
kkhorimoto
2017/03/02 19:35:18
Done.
| |
197 if (pending_item->GetUserAgentType() != UserAgentType::NONE) { | |
183 bool use_desktop_user_agent = | 198 bool use_desktop_user_agent = |
184 override_desktop_user_agent_for_next_pending_item_ || | 199 override_desktop_user_agent_for_next_pending_item_; |
185 (GetLastCommittedItem() && | 200 if (!use_desktop_user_agent) { |
186 GetLastCommittedItem()->IsOverridingUserAgent()); | 201 // If the flag is not set, propagate the last non-native item's |
187 GetPendingItem()->SetIsOverridingUserAgent(use_desktop_user_agent); | 202 // UserAgentType. |
188 override_desktop_user_agent_for_next_pending_item_ = false; | 203 NavigationItem* last_non_native_item = |
204 GetLastCommittedNonAppSpecificItem(); | |
205 DCHECK(!last_non_native_item || | |
206 last_non_native_item->GetUserAgentType() != UserAgentType::NONE); | |
207 use_desktop_user_agent = | |
208 last_non_native_item && | |
209 last_non_native_item->GetUserAgentType() == UserAgentType::DESKTOP; | |
210 } | |
211 if (use_desktop_user_agent) | |
212 pending_item->SetUserAgentType(UserAgentType::DESKTOP); | |
189 } | 213 } |
214 override_desktop_user_agent_for_next_pending_item_ = false; | |
190 } | 215 } |
191 | 216 |
192 NavigationItem* NavigationManagerImpl::GetLastUserItem() const { | 217 NavigationItem* NavigationManagerImpl::GetLastUserItem() const { |
193 return [session_controller_ lastUserItem]; | 218 return [session_controller_ lastUserItem]; |
194 } | 219 } |
195 | 220 |
196 NavigationItem* NavigationManagerImpl::GetPreviousItem() const { | 221 NavigationItem* NavigationManagerImpl::GetPreviousItem() const { |
197 return [session_controller_ previousItem]; | 222 return [session_controller_ previousItem]; |
198 } | 223 } |
199 | 224 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 // simply add the remainder. | 420 // simply add the remainder. |
396 result += offset; | 421 result += offset; |
397 if (result < 0 /* overflow */) | 422 if (result < 0 /* overflow */) |
398 result = INT_MAX; | 423 result = INT_MAX; |
399 } | 424 } |
400 | 425 |
401 return result; | 426 return result; |
402 } | 427 } |
403 | 428 |
404 void NavigationManagerImpl::OverrideDesktopUserAgentForNextPendingItem() { | 429 void NavigationManagerImpl::OverrideDesktopUserAgentForNextPendingItem() { |
405 if (GetPendingItem()) | 430 NavigationItem* pending_item = GetPendingItem(); |
406 GetPendingItem()->SetIsOverridingUserAgent(true); | 431 if (pending_item) { |
407 else | 432 // The desktop user agent cannot be used for a pending navigation to an |
433 // app-specific URL. | |
434 DCHECK_NE(pending_item->GetUserAgentType(), UserAgentType::NONE); | |
435 pending_item->SetUserAgentType(UserAgentType::DESKTOP); | |
436 } else { | |
408 override_desktop_user_agent_for_next_pending_item_ = true; | 437 override_desktop_user_agent_for_next_pending_item_ = true; |
438 } | |
409 } | 439 } |
410 | 440 |
411 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { | 441 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { |
412 DCHECK_GT(index, 0); | 442 DCHECK_GT(index, 0); |
413 DCHECK_LT(index, GetItemCount()); | 443 DCHECK_LT(index, GetItemCount()); |
414 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); | 444 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); |
415 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; | 445 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; |
416 } | 446 } |
417 | 447 |
448 NavigationItem* NavigationManagerImpl::GetLastCommittedNonAppSpecificItem() | |
449 const { | |
450 int index = GetCurrentItemIndex(); | |
451 if (index == -1) | |
452 return nullptr; | |
453 WebClient* client = GetWebClient(); | |
454 NavigationItemList items = [session_controller_ items]; | |
455 while (index >= 0) { | |
456 NavigationItem* item = items[index--]; | |
457 if (!client->IsAppSpecificURL(item->GetVirtualURL())) | |
458 return item; | |
459 } | |
460 return nullptr; | |
461 } | |
462 | |
418 } // namespace web | 463 } // namespace web |
OLD | NEW |