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

Unified Diff: ios/web/web_state/ui/crw_wk_navigation_states.mm

Issue 2835463002: Store NavigationIntext in CRWWKNavigationStates. (Closed)
Patch Set: Rebased Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: ios/web/web_state/ui/crw_wk_navigation_states.mm
diff --git a/ios/web/web_state/ui/crw_wk_navigation_states.mm b/ios/web/web_state/ui/crw_wk_navigation_states.mm
index cd7a97a884c7922df19d68c85e00e2115315ed27..117a7ead22435698827df8dd6c50d1c30a8313e0 100644
--- a/ios/web/web_state/ui/crw_wk_navigation_states.mm
+++ b/ios/web/web_state/ui/crw_wk_navigation_states.mm
@@ -5,6 +5,7 @@
#import "ios/web/web_state/ui/crw_wk_navigation_states.h"
#include "base/logging.h"
+#include "ios/web/web_state/navigation_context_impl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
@@ -24,16 +25,31 @@
- (instancetype)initWithState:(web::WKNavigationState)state
index:(NSUInteger)index NS_DESIGNATED_INITIALIZER;
+// Initializes record with context and index values.
+- (instancetype)initWithContext:
+ (std::unique_ptr<web::NavigationContextImpl>)context
+ index:(NSUInteger)index NS_DESIGNATED_INITIALIZER;
+
+// |_context| setter and getter.
+- (void)setContext:(std::unique_ptr<web::NavigationContextImpl>)context;
+- (web::NavigationContextImpl*)context;
kkhorimoto 2017/04/25 13:29:55 Optional: Personally I prefer classes have readonl
Eugene But (OOO till 7-30) 2017/04/25 21:02:58 Done.
Eugene But (OOO till 7-30) 2017/05/08 18:30:51 Turns out property does not work on bots: ../../
+
@end
-@implementation CRWWKNavigationsStateRecord
+@implementation CRWWKNavigationsStateRecord {
+ // web::NavigationContextImpl for this navigation.
+ std::unique_ptr<web::NavigationContextImpl> _context;
+}
kkhorimoto 2017/04/25 13:29:55 Can you move the ivars to the @interface?
Eugene But (OOO till 7-30) 2017/04/25 21:02:58 Done.
@synthesize state = _state;
@synthesize index = _index;
+#ifndef NDEBUG
- (NSString*)description {
- return [NSString stringWithFormat:@"state: %d, index: %ld", _state,
- static_cast<long>(_index)];
+ return [NSString stringWithFormat:@"state: %d, index: %ld, context: %@",
+ _state, static_cast<long>(_index),
+ _context->GetDescription()];
}
+#endif // NDEBUG
- (instancetype)initWithState:(web::WKNavigationState)state
index:(NSUInteger)index {
@@ -44,6 +60,24 @@
return self;
}
+- (instancetype)initWithContext:
+ (std::unique_ptr<web::NavigationContextImpl>)context
+ index:(NSUInteger)index {
+ if ((self = [super init])) {
+ _context = std::move(context);
+ _index = index;
+ }
+ return self;
+}
+
+- (void)setContext:(std::unique_ptr<web::NavigationContextImpl>)context {
+ _context = std::move(context);
+}
+
+- (web::NavigationContextImpl*)context {
+ return _context.get();
+}
+
@end
@interface CRWWKNavigationStates () {
@@ -100,6 +134,32 @@
[_records removeObjectForKey:navigation];
}
+- (void)setContext:(std::unique_ptr<web::NavigationContextImpl>)context
+ forNavigation:(WKNavigation*)navigation {
+ if (!navigation) {
+ // WKWebView may call WKNavigationDelegate callbacks with nil.
+ return;
+ }
+ CRWWKNavigationsStateRecord* record = [_records objectForKey:navigation];
+ if (!record) {
+ record =
+ [[CRWWKNavigationsStateRecord alloc] initWithContext:std::move(context)
+ index:++_lastStateIndex];
+ } else {
+ [record setContext:std::move(context)];
+ }
+ [_records setObject:record forKey:navigation];
+}
+
+- (web::NavigationContextImpl*)contextForNavigation:(WKNavigation*)navigation {
+ if (!navigation) {
+ // WKWebView may call WKNavigationDelegate callbacks with nil.
+ return nullptr;
+ }
+ CRWWKNavigationsStateRecord* record = [_records objectForKey:navigation];
+ return record.context;
+}
+
- (WKNavigation*)lastAddedNavigation {
WKNavigation* result = nil;
NSUInteger lastAddedIndex = 0; // record indices start with 1.

Powered by Google App Engine
This is Rietveld 408576698