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

Side by Side Diff: ios/web/web_state/ui/crw_wk_navigation_states.mm

Issue 2950853002: Gracefully handle didCommitNavigation: call after didFinishNavigation: (Closed)
Patch Set: Updated comments Created 3 years, 6 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 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 #import "ios/web/web_state/navigation_context_impl.h" 8 #import "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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 id key = [self keyForNavigation:navigation]; 115 id key = [self keyForNavigation:navigation];
116 CRWWKNavigationsStateRecord* record = [_records objectForKey:key]; 116 CRWWKNavigationsStateRecord* record = [_records objectForKey:key];
117 if (!record) { 117 if (!record) {
118 DCHECK(state == web::WKNavigationState::REQUESTED || 118 DCHECK(state == web::WKNavigationState::REQUESTED ||
119 state == web::WKNavigationState::STARTED || 119 state == web::WKNavigationState::STARTED ||
120 state == web::WKNavigationState::COMMITTED); 120 state == web::WKNavigationState::COMMITTED);
121 record = 121 record =
122 [[CRWWKNavigationsStateRecord alloc] initWithState:state 122 [[CRWWKNavigationsStateRecord alloc] initWithState:state
123 index:++_lastStateIndex]; 123 index:++_lastStateIndex];
124 } else { 124 } else {
125 DCHECK( 125 DCHECK(record.state < state ||
126 record.state < state || 126 // Redirect can be called multiple times.
127 (record.state == state && state == web::WKNavigationState::REDIRECTED)); 127 (record.state == state &&
128 state == web::WKNavigationState::REDIRECTED) ||
129 // didFinishNavigation can be called before didCommitNvigation.
130 (record.state == web::WKNavigationState::FINISHED &&
131 state == web::WKNavigationState::COMMITTED));
128 record.state = state; 132 record.state = state;
129 } 133 }
130 [_records setObject:record forKey:key]; 134 [_records setObject:record forKey:key];
131 } 135 }
132 136
137 - (web::WKNavigationState)stateForNavigation:(WKNavigation*)navigation {
138 id key = [self keyForNavigation:navigation];
139 CRWWKNavigationsStateRecord* record = [_records objectForKey:key];
140 return record ? record.state : web::WKNavigationState::NONE;
141 }
142
133 - (void)removeNavigation:(WKNavigation*)navigation { 143 - (void)removeNavigation:(WKNavigation*)navigation {
134 id key = [self keyForNavigation:navigation]; 144 id key = [self keyForNavigation:navigation];
135 DCHECK([_records objectForKey:key]); 145 DCHECK([_records objectForKey:key]);
136 [_records removeObjectForKey:key]; 146 [_records removeObjectForKey:key];
137 } 147 }
138 148
139 - (void)setContext:(std::unique_ptr<web::NavigationContextImpl>)context 149 - (void)setContext:(std::unique_ptr<web::NavigationContextImpl>)context
140 forNavigation:(WKNavigation*)navigation { 150 forNavigation:(WKNavigation*)navigation {
141 id key = [self keyForNavigation:navigation]; 151 id key = [self keyForNavigation:navigation];
142 CRWWKNavigationsStateRecord* record = [_records objectForKey:key]; 152 CRWWKNavigationsStateRecord* record = [_records objectForKey:key];
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 209 }
200 } 210 }
201 211
202 if (*outNavigation == _nullNavigation) { 212 if (*outNavigation == _nullNavigation) {
203 // |_nullNavigation| is a key for storing null navigations. 213 // |_nullNavigation| is a key for storing null navigations.
204 *outNavigation = nil; 214 *outNavigation = nil;
205 } 215 }
206 } 216 }
207 217
208 @end 218 @end
OLDNEW
« no previous file with comments | « ios/web/web_state/ui/crw_wk_navigation_states.h ('k') | ios/web/web_state/ui/crw_wk_navigation_states_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698