| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/web_state/ui/crw_wk_navigation_states.h" | 5 #import "ios/web/web_state/ui/crw_wk_navigation_states.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ios/web/web_state/navigation_context_impl.h" | 8 #include "ios/web/web_state/navigation_context_impl.h" |
| 9 | 9 |
| 10 #if !defined(__has_feature) || !__has_feature(objc_arc) | 10 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 return result; | 163 return result; |
| 164 } | 164 } |
| 165 | 165 |
| 166 - (web::WKNavigationState)lastAddedNavigationState { | 166 - (web::WKNavigationState)lastAddedNavigationState { |
| 167 CRWWKNavigationsStateRecord* result = nil; | 167 CRWWKNavigationsStateRecord* result = nil; |
| 168 WKNavigation* unused = nil; | 168 WKNavigation* unused = nil; |
| 169 [self getLastAddedNavigation:&unused record:&result]; | 169 [self getLastAddedNavigation:&unused record:&result]; |
| 170 return result.state; | 170 return result.state; |
| 171 } | 171 } |
| 172 | 172 |
| 173 - (NSSet*)pendingNavigations { |
| 174 NSMutableSet* result = [NSMutableSet set]; |
| 175 for (id navigation in _records) { |
| 176 CRWWKNavigationsStateRecord* record = [_records objectForKey:navigation]; |
| 177 if (record.state == web::WKNavigationState::REQUESTED || |
| 178 record.state == web::WKNavigationState::STARTED || |
| 179 record.state == web::WKNavigationState::REDIRECTED) { |
| 180 [result addObject:navigation]; |
| 181 } |
| 182 } |
| 183 return [result copy]; |
| 184 } |
| 185 |
| 173 - (id)keyForNavigation:(WKNavigation*)navigation { | 186 - (id)keyForNavigation:(WKNavigation*)navigation { |
| 174 return navigation ? navigation : _nullNavigation; | 187 return navigation ? navigation : _nullNavigation; |
| 175 } | 188 } |
| 176 | 189 |
| 177 - (void)getLastAddedNavigation:(WKNavigation**)outNavigation | 190 - (void)getLastAddedNavigation:(WKNavigation**)outNavigation |
| 178 record:(CRWWKNavigationsStateRecord**)outRecord { | 191 record:(CRWWKNavigationsStateRecord**)outRecord { |
| 179 NSUInteger lastAddedIndex = 0; // record indices start with 1. | 192 NSUInteger lastAddedIndex = 0; // record indices start with 1. |
| 180 for (WKNavigation* navigation in _records) { | 193 for (WKNavigation* navigation in _records) { |
| 181 CRWWKNavigationsStateRecord* record = [_records objectForKey:navigation]; | 194 CRWWKNavigationsStateRecord* record = [_records objectForKey:navigation]; |
| 182 if (lastAddedIndex < record.index) { | 195 if (lastAddedIndex < record.index) { |
| 183 *outNavigation = navigation; | 196 *outNavigation = navigation; |
| 184 *outRecord = record; | 197 *outRecord = record; |
| 185 lastAddedIndex = record.index; | 198 lastAddedIndex = record.index; |
| 186 } | 199 } |
| 187 } | 200 } |
| 188 | 201 |
| 189 if (*outNavigation == _nullNavigation) { | 202 if (*outNavigation == _nullNavigation) { |
| 190 // |_nullNavigation| is a key for storing null navigations. | 203 // |_nullNavigation| is a key for storing null navigations. |
| 191 *outNavigation = nil; | 204 *outNavigation = nil; |
| 192 } | 205 } |
| 193 } | 206 } |
| 194 | 207 |
| 195 @end | 208 @end |
| OLD | NEW |