Changeset 197004 in webkit
- Timestamp:
- Feb 23, 2016 4:20:01 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r197003 r197004 1 2016-02-23 Anders Carlsson <andersca@apple.com> 2 3 WKWebView should implement NSCoding 4 https://bugs.webkit.org/show_bug.cgi?id=137160 5 rdar://problem/17380562 6 7 Reviewed by Dan Bernstein. 8 9 * UIProcess/API/Cocoa/WKUserContentController.mm: 10 (-[WKUserContentController initWithCoder:]): 11 We need to call [self init] here, so that the wrapper will be initialized. 12 13 * UIProcess/API/Cocoa/WKWebView.h: 14 -initWithCoder: shouldn't be unavailable, it should be a designated initializer. 15 16 * UIProcess/API/Cocoa/WKWebView.mm: 17 (-[WKWebView _initializeWithConfiguration:]): 18 Move initialization out into a common method. 19 20 (-[WKWebView initWithFrame:configuration:]): 21 Call -initializeWithConfiguration: here. 22 23 (-[WKWebView initWithCoder:]): 24 Decode everything. 25 26 (-[WKWebView encodeWithCoder:]): 27 Encode everything. 28 1 29 2016-02-23 Anders Carlsson <andersca@apple.com> 2 30 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUserContentController.mm
r197000 r197004 69 69 - (instancetype)initWithCoder:(NSCoder *)coder 70 70 { 71 if (!(self = [s uperinit]))71 if (!(self = [self init])) 72 72 return nil; 73 73 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h
r195963 r197004 84 84 - (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration NS_DESIGNATED_INITIALIZER; 85 85 86 - ( instancetype)initWithCoder:(NSCoder *)coder NS_UNAVAILABLE;86 - (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER; 87 87 88 88 /*! @abstract Navigates to a requested URL. -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
r196024 r197004 339 339 #endif 340 340 341 - (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration 342 { 343 if (!(self = [super initWithFrame:frame])) 344 return nil; 345 341 - (void)_initializeWithConfiguration:(WKWebViewConfiguration *)configuration 342 { 346 343 if (!configuration) 347 344 [NSException raise:NSInvalidArgumentException format:@"Configuration cannot be nil"]; … … 359 356 360 357 [_configuration _validate]; 361 362 358 363 359 WebKit::WebProcessPool& processPool = *[_configuration processPool]->_processPool; … … 470 466 471 467 pageToViewMap().add(_page.get(), self); 468 } 469 470 - (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration 471 { 472 if (!(self = [super initWithFrame:frame])) 473 return nil; 474 475 [self _initializeWithConfiguration:configuration]; 472 476 473 477 return self; … … 476 480 - (instancetype)initWithCoder:(NSCoder *)coder 477 481 { 478 [self release]; 479 return nil; 482 if (!(self = [super initWithCoder:coder])) 483 return nil; 484 485 WKWebViewConfiguration *configuration = [coder decodeObjectForKey:@"configuration"]; 486 [self _initializeWithConfiguration:configuration]; 487 488 self.allowsBackForwardNavigationGestures = [coder decodeBoolForKey:@"allowsBackForwardNavigationGestures"]; 489 self.customUserAgent = [coder decodeObjectForKey:@"customUserAgent"]; 490 self.allowsLinkPreview = [coder decodeBoolForKey:@"allowsLinkPreview"]; 491 492 #if PLATFORM(MAC) 493 self.allowsMagnification = [coder decodeBoolForKey:@"allowsMagnification"]; 494 self.magnification = [coder decodeDoubleForKey:@"magnification"]; 495 #endif 496 497 return self; 498 } 499 500 - (void)encodeWithCoder:(NSCoder *)coder 501 { 502 [coder encodeObject:_configuration.get() forKey:@"configuration"]; 503 504 [coder encodeBool:self.allowsBackForwardNavigationGestures forKey:@"allowsBackForwardNavigationGestures"]; 505 [coder encodeObject:self.customUserAgent forKey:@"customUserAgent"]; 506 [coder encodeBool:self.allowsLinkPreview forKey:@"allowsLinkPreview"]; 507 508 #if PLATFORM(MAC) 509 [coder encodeBool:self.allowsMagnification forKey:@"allowsMagnification"]; 510 [coder encodeDouble:self.magnification forKey:@"magnification"]; 511 #endif 480 512 } 481 513 -
trunk/Tools/ChangeLog
r196997 r197004 1 2016-02-23 Anders Carlsson <andersca@apple.com> 2 3 WKWebView should implement NSCoding 4 https://bugs.webkit.org/show_bug.cgi?id=137160 5 6 Reviewed by Dan Bernstein. 7 8 Add tests. 9 10 * TestWebKitAPI/Tests/WebKit2Cocoa/Coding.mm: 11 (TEST): 12 1 13 2016-02-23 Anders Carlsson <andersca@apple.com> 2 14 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/Coding.mm
r196997 r197004 121 121 #endif 122 122 } 123 124 TEST(Coding, WKWebView) 125 { 126 auto a = adoptNS([[WKWebView alloc] init]); 127 128 // Change all defaults to something else. 129 [a setAllowsBackForwardNavigationGestures:YES]; 130 [a setCustomUserAgent:@"CustomUserAgent"]; 131 132 #if PLATFORM(IOS) 133 [a setAllowsLinkPreview:YES]; 134 #else 135 [a setAllowsLinkPreview:NO]; 136 [a setAllowsMagnification:YES]; 137 [a setMagnification:2]; 123 138 #endif 139 140 auto b = encodeAndDecode(a.get()); 141 142 EXPECT_EQ([a allowsBackForwardNavigationGestures], [b allowsBackForwardNavigationGestures]); 143 EXPECT_TRUE([[a customUserAgent] isEqualToString:[b customUserAgent]]); 144 EXPECT_EQ([a allowsLinkPreview], [b allowsLinkPreview]); 145 146 #if PLATFORM(MAC) 147 EXPECT_EQ([a allowsMagnification], [b allowsMagnification]); 148 EXPECT_EQ([a magnification], [b magnification]); 149 #endif 150 } 151 152 TEST(Coding, WKWebView_SameConfiguration) 153 { 154 // First, encode two WKWebViews sharing the same configuration. 155 RetainPtr<NSData> data; 156 { 157 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 158 159 auto a = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]); 160 auto b = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]); 161 162 data = [NSKeyedArchiver archivedDataWithRootObject:@[a.get(), b.get()]]; 163 } 164 165 // Then, decode and verify that the important configuration properties are the same. 166 NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:data.get()]; 167 168 WKWebView *aView = array[0]; 169 WKWebView *bView = array[1]; 170 171 WKWebViewConfiguration *a = aView.configuration; 172 WKWebViewConfiguration *b = bView.configuration; 173 174 EXPECT_EQ(a.processPool, b.processPool); 175 EXPECT_EQ(a.preferences, b.preferences); 176 EXPECT_EQ(a.userContentController, b.userContentController); 177 EXPECT_EQ(a.websiteDataStore, b.websiteDataStore); 178 } 179 180 #endif
Note: See TracChangeset
for help on using the changeset viewer.