OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "ios/chrome/browser/native_app_launcher/native_app_navigation_util.h" | 5 #include "ios/chrome/browser/native_app_launcher/native_app_navigation_util.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ios/web/public/navigation_item.h" | 8 #include "ios/web/public/navigation_item.h" |
9 #include "ios/web/public/navigation_manager.h" | 9 #include "ios/web/public/navigation_manager.h" |
10 #import "ios/web/public/web_state/web_state.h" | 10 #import "ios/web/public/web_state/web_state.h" |
11 | 11 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." |
| 14 #endif |
| 15 |
12 namespace native_app_launcher { | 16 namespace native_app_launcher { |
13 | 17 |
14 bool IsLinkNavigation(web::WebState* web_state) { | 18 bool IsLinkNavigation(web::WebState* web_state) { |
15 web::NavigationManager* navigationManager = web_state->GetNavigationManager(); | 19 web::NavigationManager* navigationManager = web_state->GetNavigationManager(); |
16 DCHECK(navigationManager); | 20 DCHECK(navigationManager); |
17 int index = navigationManager->GetCurrentItemIndex(); | 21 int index = navigationManager->GetCurrentItemIndex(); |
18 // Walks backward on the navigation items list looking for the first item | 22 // Walks backward on the navigation items list looking for the first item |
19 // that is not the result of a redirect. Check if user arrived at that | 23 // that is not the result of a redirect. Check if user arrived at that |
20 // via link click or a suggestion on the UI. | 24 // via link click or a suggestion on the UI. |
21 while (index >= 0) { | 25 while (index >= 0) { |
22 web::NavigationItem* item = navigationManager->GetItemAtIndex(index); | 26 web::NavigationItem* item = navigationManager->GetItemAtIndex(index); |
23 DCHECK(item); | 27 DCHECK(item); |
24 ui::PageTransition currentTransition = item->GetTransitionType(); | 28 ui::PageTransition currentTransition = item->GetTransitionType(); |
25 // Checks non-redirect entries for transitions that are either links or | 29 // Checks non-redirect entries for transitions that are either links or |
26 // bookmarks. | 30 // bookmarks. |
27 if ((currentTransition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0) { | 31 if ((currentTransition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0) { |
28 return PageTransitionCoreTypeIs(currentTransition, | 32 return PageTransitionCoreTypeIs(currentTransition, |
29 ui::PAGE_TRANSITION_LINK) || | 33 ui::PAGE_TRANSITION_LINK) || |
30 PageTransitionCoreTypeIs(currentTransition, | 34 PageTransitionCoreTypeIs(currentTransition, |
31 ui::PAGE_TRANSITION_AUTO_BOOKMARK); | 35 ui::PAGE_TRANSITION_AUTO_BOOKMARK); |
32 } | 36 } |
33 --index; | 37 --index; |
34 } | 38 } |
35 return false; | 39 return false; |
36 } | 40 } |
37 | 41 |
38 } // namespace native_app_launcher | 42 } // namespace native_app_launcher |
OLD | NEW |