Changeset 258949 in webkit
- Timestamp:
- Mar 24, 2020 3:41:13 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r258915 r258949 1 2020-03-24 Per Arne Vollan <pvollan@apple.com> 2 3 [Cocoa] Fix launch time regression with CF prefs direct mode enabled 4 https://bugs.webkit.org/show_bug.cgi?id=209244 5 6 Reviewed by Darin Adler. 7 8 Re-enable CF prefs direct mode. 9 10 * wtf/PlatformEnable.h: 11 * wtf/PlatformEnableCocoa.h: 12 1 13 2020-03-24 Per Arne Vollan <pvollan@apple.com> 2 14 -
trunk/Source/WTF/wtf/PlatformEnable.h
r258557 r258949 554 554 #endif 555 555 556 #if !defined(ENABLE_CFPREFS_DIRECT_MODE) 557 #define ENABLE_CFPREFS_DIRECT_MODE 0 558 #endif 556 559 557 560 … … 871 874 #error "ENABLE(WEBGL2) requires ENABLE(WEBGL)" 872 875 #endif 873 874 #define ENABLE_CFPREFS_DIRECT_MODE 0 -
trunk/Source/WTF/wtf/PlatformEnableCocoa.h
r258772 r258949 281 281 #define ENABLE_TAKE_UNBOUNDED_NETWORKING_ASSERTION 1 282 282 #endif 283 284 #if !defined(ENABLE_CFPREFS_DIRECT_MODE) 285 #define ENABLE_CFPREFS_DIRECT_MODE 1 286 #endif -
trunk/Source/WebKit/ChangeLog
r258945 r258949 1 2020-03-24 Per Arne Vollan <pvollan@apple.com> 2 3 [Cocoa] Fix launch time regression with CF prefs direct mode enabled 4 https://bugs.webkit.org/show_bug.cgi?id=209244 5 <rdar://problem/60542149> 6 7 Reviewed by Darin Adler. 8 9 When CF prefs direct mode was enabled in https://trac.webkit.org/changeset/258064/webkit, it introduced 10 a significant launch time regression. This patch addresses this regression. The number of observed domains 11 is reduced and domain observation is initiated later when Safari is first activated. Swizzling code is 12 removed, since that has a performance cost in the Objective-C runtime. Normal priority instead of 13 QOS_CLASS_BACKGROUND is used in the thread which starts the observing, since using a background priority 14 class can lead to priority inversion. Finally, a dictionary comparison is removed when a notification 15 about a preference change is received, since this check is redundant and doubles the cost of this method. 16 17 * UIProcess/Cocoa/PreferenceObserver.mm: 18 (-[WKPreferenceObserver init]): 19 * UIProcess/Cocoa/WebProcessPoolCocoa.mm: 20 (WebKit::WebProcessPool::platformInitialize): 21 (WebKit::WebProcessPool::registerNotificationObservers): 22 (WebKit::WebProcessPool::unregisterNotificationObservers): 23 * UIProcess/WebProcessPool.h: 24 1 25 2020-03-24 Daniel Bates <dabates@apple.com> 2 26 -
trunk/Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb
r258915 r258949 535 535 (global-name "com.apple.logd") 536 536 (global-name "com.apple.logd.events") 537 (global-name "com.apple.cfprefsd.daemon")538 537 ) 539 538 -
trunk/Source/WebKit/UIProcess/Cocoa/PreferenceObserver.h
r258119 r258949 47 47 } 48 48 + (id)sharedInstance; 49 + (void)swizzleRegisterDefaults;50 49 - (void)preferenceDidChange:(NSString *)domain key:(NSString *)key encodedValue:(NSString *)encodedValue; 51 50 @end -
trunk/Source/WebKit/UIProcess/Cocoa/PreferenceObserver.mm
r258557 r258949 29 29 #import "WebProcessPool.h" 30 30 31 #import <wtf/ObjCRuntimeExtras.h>32 33 static IMP registerDefaultsOriginal = nil;34 static bool registeringDefaults = false;35 36 static void registerDefaultsOverride(id self, SEL selector, NSDictionary<NSString *, id> *dictionary)37 {38 registeringDefaults = true;39 if (registerDefaultsOriginal)40 wtfCallIMP<void>(registerDefaultsOriginal, self, selector, dictionary);41 registeringDefaults = false;42 }43 44 31 @implementation WKUserDefaults 45 32 46 33 - (void)_notifyObserversOfChangeFromValuesForKeys:(NSDictionary<NSString *, id> *)oldValues toValuesForKeys:(NSDictionary<NSString *, id> *)newValues 47 34 { 48 if (registeringDefaults)49 return;50 51 35 [super _notifyObserversOfChangeFromValuesForKeys:oldValues toValuesForKeys:newValues]; 52 53 if ([oldValues isEqualToDictionary:newValues])54 return;55 36 56 37 for (NSString *key in oldValues) { … … 102 83 } 103 84 104 + (void)swizzleRegisterDefaults105 {106 static std::once_flag onceFlag;107 std::call_once(onceFlag, [] {108 Method registerDefaultsMethod = class_getInstanceMethod(objc_getClass("NSUserDefaults"), @selector(registerDefaults:));109 registerDefaultsOriginal = method_setImplementation(registerDefaultsMethod, (IMP)registerDefaultsOverride);110 });111 }112 113 85 - (instancetype)init 114 86 { 115 87 std::initializer_list<NSString*> domains = { 88 #if PLATFORM(IOS_FAMILY) 116 89 @"com.apple.Accessibility", 117 #if PLATFORM(IOS_FAMILY)118 90 @"com.apple.AdLib", 119 @"com.apple.CFNetwork",120 @"com.apple.EmojiPreferences",121 @"com.apple.FontParser",122 @"com.apple.ImageIO",123 @"com.apple.InputModePreferences",124 #else125 @"com.apple.ATS",126 @"com.apple.CoreGraphics",127 @"com.apple.DownloadAssessment",128 @"com.apple.HIToolbox",129 #endif130 @"com.apple.LaunchServices",131 #if PLATFORM(IOS_FAMILY)132 @"com.apple.Metal",133 @"com.apple.MobileAsset",134 91 @"com.apple.Preferences", 135 92 @"com.apple.SpeakSelection", 136 93 @"com.apple.UIKit", 137 @"com.apple.VoiceOverTouch", 94 @"com.apple.WebUI", 95 @"com.apple.avfaudio", 96 @"com.apple.itunesstored", 97 @"com.apple.mediaremote", 98 @"com.apple.preferences.sounds", 99 @"com.apple.voiceservices", 100 @"kCFPreferencesAnyApplication", 138 101 #else 139 @"com.apple.MultitouchSupport" 140 @"com.apple.ServicesMenu.Services" 141 @"com.apple.ViewBridge" 142 #endif 143 @"com.apple.WebFoundation", 144 #if PLATFORM(IOS_FAMILY) 145 @"com.apple.WebKit.WebContent", 146 @"com.apple.WebUI", 147 @"com.apple.airplay", 148 @"com.apple.applejpeg", 149 @"com.apple.audio.virtualaudio", 150 @"com.apple.avfaudio", 151 #endif 102 @"com.apple.CoreGraphics", 103 @"com.apple.HIToolbox", 104 @"com.apple.ServicesMenu.Services", 105 @"com.apple.ViewBridge", 152 106 @"com.apple.avfoundation", 153 @"com.apple.avfoundation.frecents",154 107 @"com.apple.avfoundation.videoperformancehud", 155 #if PLATFORM(IOS_FAMILY)156 @"com.apple.avkit",157 @"com.apple.coreanimation",158 @"com.apple.coreaudio",159 #endif160 @"com.apple.coremedia",161 #if PLATFORM(IOS_FAMILY)162 @"com.apple.corevideo",163 @"com.apple.da",164 @"com.apple.hangtracer",165 @"com.apple.indigo",166 @"com.apple.iokit.IOMobileGraphicsFamily",167 @"com.apple.itunesstored",168 @"com.apple.keyboard",169 #else170 @"com.apple.crypto",171 108 @"com.apple.driver.AppleBluetoothMultitouch.mouse", 172 109 @"com.apple.driver.AppleBluetoothMultitouch.trackpad", 173 @"com.apple.driver.AppleHIDMouse"174 #endif175 @"com.apple.lookup.shared",176 110 @"com.apple.mediaaccessibility", 177 #if PLATFORM(IOS_FAMILY)178 @"com.apple.mediaaccessibility.public",179 @"com.apple.mediaremote",180 @"com.apple.mobileipod",181 @"com.apple.mt",182 #else183 @"com.apple.networkConnect"184 #endif185 @"com.apple.opengl",186 #if PLATFORM(IOS_FAMILY)187 @"com.apple.preferences.sounds",188 @"com.apple.security",189 @"com.apple.voiceservices",190 @"com.apple.voiceservices.logging",191 #else192 111 @"com.apple.speech.voice.prefs", 193 @"com.apple.systemsound",194 112 @"com.apple.universalaccess", 195 @"com.nvidia.OpenGL",196 @"edu.mit.Kerberos",197 #endif198 113 @"kCFPreferencesAnyApplication", 199 #if !PLATFORM(IOS_FAMILY)200 @"pbs",201 114 #endif 202 115 }; -
trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm
r258915 r258949 174 174 175 175 setLegacyCustomProtocolManagerClient(makeUnique<LegacyCustomProtocolManagerClient>()); 176 177 #if ENABLE(CFPREFS_DIRECT_MODE)178 [WKPreferenceObserver swizzleRegisterDefaults];179 dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{180 // Start observing preference changes.181 [WKPreferenceObserver sharedInstance];182 });183 #endif184 176 } 185 177 … … 612 604 #endif 613 605 606 #if ENABLE(CFPREFS_DIRECT_MODE) 607 void WebProcessPool::startObservingPreferenceChanges() 608 { 609 static dispatch_once_t onceToken; 610 dispatch_once(&onceToken, ^{ 611 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 612 // Start observing preference changes. 613 [WKPreferenceObserver sharedInstance]; 614 }); 615 }); 616 } 617 #endif 618 614 619 void WebProcessPool::registerNotificationObservers() 615 620 { … … 656 661 657 662 m_activationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSApplicationDidBecomeActiveNotification object:NSApp queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) { 663 #if ENABLE(CFPREFS_DIRECT_MODE) 664 startObservingPreferenceChanges(); 665 #endif 658 666 setApplicationIsActive(true); 659 667 }]; … … 677 685 } 678 686 }]; 687 #if ENABLE(CFPREFS_DIRECT_MODE) 688 m_activationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:@"UIApplicationDidBecomeActiveNotification" object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) { 689 startObservingPreferenceChanges(); 690 }]; 691 #endif 679 692 #endif // !PLATFORM(IOS_FAMILY) 680 693 } … … 692 705 [[NSNotificationCenter defaultCenter] removeObserver:m_scrollerStyleNotificationObserver.get()]; 693 706 #endif 694 [[NSNotificationCenter defaultCenter] removeObserver:m_activationObserver.get()];695 707 [[NSNotificationCenter defaultCenter] removeObserver:m_deactivationObserver.get()]; 696 708 #elif !PLATFORM(MACCATALYST) … … 702 714 #endif // PLATFORM(IOS) 703 715 [[NSNotificationCenter defaultCenter] removeObserver:m_accessibilityEnabledObserver.get()]; 716 [[NSNotificationCenter defaultCenter] removeObserver:m_activationObserver.get()]; 704 717 #endif // !PLATFORM(IOS_FAMILY) 705 718 } -
trunk/Source/WebKit/UIProcess/WebProcessPool.h
r258734 r258949 612 612 #endif 613 613 614 #if ENABLE(CFPREFS_DIRECT_MODE) 615 void startObservingPreferenceChanges(); 616 #endif 617 614 618 Ref<API::ProcessPoolConfiguration> m_configuration; 615 619 … … 692 696 RetainPtr<NSObject> m_scrollerStyleNotificationObserver; 693 697 #endif 694 RetainPtr<NSObject> m_activationObserver;695 698 RetainPtr<NSObject> m_deactivationObserver; 696 699 … … 700 703 701 704 #if PLATFORM(COCOA) 705 RetainPtr<NSObject> m_activationObserver; 702 706 RetainPtr<NSObject> m_accessibilityEnabledObserver; 703 707 #endif … … 803 807 #endif 804 808 bool m_useSeparateServiceWorkerProcess { false }; 805 806 #if PLATFORM(COCOA)807 RetainPtr<WKPreferenceObserver> m_preferenceObserver;808 #endif809 809 }; 810 810 -
trunk/Source/WebKit/WebProcess/com.apple.WebProcess.sb.in
r258915 r258949 678 678 #endif 679 679 (global-name "com.apple.PowerManagement.control") 680 (global-name "com.apple.cfprefsd.daemon")681 680 (global-name "com.apple.coreservices.launchservicesd") 682 681 (global-name "com.apple.lsd.mapdb") -
trunk/Tools/ChangeLog
r258947 r258949 1 2020-03-24 Per Arne Vollan <pvollan@apple.com> 2 3 [Cocoa] Fix launch time regression with CF prefs direct mode enabled 4 https://bugs.webkit.org/show_bug.cgi?id=209244 5 6 Reviewed by Darin Adler. 7 8 * TestWebKitAPI/Tests/WebKit/PreferenceChanges.mm: 9 (TEST): 10 (sharedInstanceMethodOverride): 11 1 12 2020-03-24 Jonathan Bedard <jbedard@apple.com> 2 13 -
trunk/Tools/TestWebKitAPI/Tests/WebKit/PreferenceChanges.mm
r258495 r258949 32 32 #import <WebKit/PreferenceObserver.h> 33 33 34 #import <wtf/ObjCRuntimeExtras.h> 35 34 36 static bool done = false; 35 37 … … 45 47 @end 46 48 49 static const CFStringRef testKey = CFSTR("testkey"); 50 static const CFStringRef testDomain = CFSTR("kCFPreferencesAnyApplication"); 51 47 52 TEST(WebKit, PreferenceObserver) 48 53 { 49 54 done = false; 50 55 51 CFPreferencesSetAppValue( CFSTR("testkey"), CFSTR("1"), CFSTR("com.apple.coremedia"));56 CFPreferencesSetAppValue(testKey, CFSTR("1"), testDomain); 52 57 53 58 auto observer = adoptNS([[WKTestPreferenceObserver alloc] init]); 54 59 55 CFPreferencesSetAppValue( CFSTR("testkey"), CFSTR("2"), CFSTR("com.apple.coremedia"));60 CFPreferencesSetAppValue(testKey, CFSTR("2"), testDomain); 56 61 57 62 TestWebKitAPI::Util::run(&done); … … 64 69 NSArray *array = @[@1, @2, @3]; 65 70 66 auto userDefaults = adoptNS([[NSUserDefaults alloc] initWithSuiteName: @"com.apple.coremedia"]);67 [userDefaults.get() setObject:array forKey: @"testkey"];71 auto userDefaults = adoptNS([[NSUserDefaults alloc] initWithSuiteName:(NSString *)testDomain]); 72 [userDefaults.get() setObject:array forKey:(NSString *)testKey]; 68 73 69 74 auto observer = adoptNS([[WKTestPreferenceObserver alloc] init]); 70 75 71 76 NSArray *changedArray = @[@3, @2, @1]; 72 [userDefaults.get() setObject:changedArray forKey: @"testkey"];77 [userDefaults.get() setObject:changedArray forKey:(NSString *)testKey]; 73 78 74 79 TestWebKitAPI::Util::run(&done); … … 77 82 TEST(WebKit, PreferenceChanges) 78 83 { 79 CFPreferencesSetAppValue(CFSTR("testkey"), CFSTR("1"), CFSTR("com.apple.coremedia")); 80 81 EXPECT_EQ(1, CFPreferencesGetAppIntegerValue(CFSTR("testkey"), CFSTR("com.apple.coremedia"), nullptr)); 82 83 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 84 WKRetainPtr<WKContextRef> context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest")); 85 configuration.get().processPool = (WKProcessPool *)context.get(); 86 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]); 87 88 auto preferenceValue = [&] { 89 return [webView stringByEvaluatingJavaScript:@"window.internals.readPreferenceInteger(\"com.apple.coremedia\", \"testkey\")"].intValue; 84 CFPreferencesSetAppValue(testKey, CFSTR("1"), testDomain); 85 86 EXPECT_EQ(1, CFPreferencesGetAppIntegerValue(testKey, testDomain, nullptr)); 87 88 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 89 WKRetainPtr<WKContextRef> context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest")); 90 configuration.get().processPool = (WKProcessPool *)context.get(); 91 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]); 92 93 auto preferenceValue = [&] { 94 NSString *js = [NSString stringWithFormat:@"window.internals.readPreferenceInteger(\"%@\",\"%@\")", (NSString *)testDomain, (NSString *)testKey]; 95 return [webView stringByEvaluatingJavaScript:js].intValue; 90 96 }; 91 97 92 98 EXPECT_EQ(preferenceValue(), 1); 93 99 94 CFPreferencesSetAppValue( CFSTR("testkey"), CFSTR("2"), CFSTR("com.apple.coremedia"));100 CFPreferencesSetAppValue(testKey, CFSTR("2"), testDomain); 95 101 96 102 EXPECT_EQ(preferenceValue(), 2); … … 101 107 NSArray *array = @[@1, @2, @3]; 102 108 103 auto userDefaults = adoptNS([[NSUserDefaults alloc] initWithSuiteName:@"com.apple.coremedia"]); 104 [userDefaults.get() setObject:array forKey:@"testkey"]; 105 106 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 107 WKRetainPtr<WKContextRef> context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest")); 108 configuration.get().processPool = (WKProcessPool *)context.get(); 109 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]); 110 111 auto preferenceValue = [&] { 112 return [webView stringByEvaluatingJavaScript:@"window.internals.encodedPreferenceValue(\"com.apple.coremedia\", \"testkey\")"]; 109 auto userDefaults = adoptNS([[NSUserDefaults alloc] initWithSuiteName:(NSString *)testDomain]); 110 [userDefaults.get() setObject:array forKey:(NSString *)testKey]; 111 112 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 113 WKRetainPtr<WKContextRef> context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest")); 114 configuration.get().processPool = (WKProcessPool *)context.get(); 115 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]); 116 117 auto preferenceValue = [&] { 118 NSString *js = [NSString stringWithFormat:@"window.internals.encodedPreferenceValue(\"%@\",\"%@\")", (NSString *)testDomain, (NSString *)testKey]; 119 return [webView stringByEvaluatingJavaScript:js]; 113 120 }; 114 121 … … 116 123 117 124 NSArray *changedArray = @[@3, @2, @1]; 118 [userDefaults.get() setObject:changedArray forKey: @"testkey"];125 [userDefaults.get() setObject:changedArray forKey:(NSString *)testKey]; 119 126 120 127 auto encodedString = preferenceValue(); … … 135 142 }; 136 143 137 auto userDefaults = adoptNS([[NSUserDefaults alloc] initWithSuiteName:@"com.apple.coremedia"]); 138 [userDefaults.get() setObject:dict forKey:@"testkey"]; 139 140 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 141 WKRetainPtr<WKContextRef> context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest")); 142 configuration.get().processPool = (WKProcessPool *)context.get(); 143 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]); 144 145 auto preferenceValue = [&] { 146 return [webView stringByEvaluatingJavaScript:@"window.internals.encodedPreferenceValue(\"com.apple.coremedia\", \"testkey\")"]; 144 auto userDefaults = adoptNS([[NSUserDefaults alloc] initWithSuiteName:(NSString *)testDomain]); 145 [userDefaults.get() setObject:dict forKey:(NSString *)testKey]; 146 147 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 148 WKRetainPtr<WKContextRef> context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest")); 149 configuration.get().processPool = (WKProcessPool *)context.get(); 150 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]); 151 152 auto preferenceValue = [&] { 153 NSString *js = [NSString stringWithFormat:@"window.internals.encodedPreferenceValue(\"%@\",\"%@\")", (NSString *)testDomain, (NSString *)testKey]; 154 return [webView stringByEvaluatingJavaScript:js]; 147 155 }; 148 156 … … 154 162 @"c" : @3, 155 163 }; 156 [userDefaults.get() setObject:changedDict forKey: @"testkey"];164 [userDefaults.get() setObject:changedDict forKey:(NSString *)testKey]; 157 165 158 166 auto encodedString = preferenceValue(); … … 170 178 NSData *data = [NSData dataWithBytes:"abc" length:3]; 171 179 172 auto userDefaults = adoptNS([[NSUserDefaults alloc] initWithSuiteName:@"com.apple.coremedia"]); 173 [userDefaults.get() setObject:data forKey:@"testkey"]; 174 175 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 176 WKRetainPtr<WKContextRef> context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest")); 177 configuration.get().processPool = (WKProcessPool *)context.get(); 178 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]); 179 180 auto preferenceValue = [&] { 181 return [webView stringByEvaluatingJavaScript:@"window.internals.encodedPreferenceValue(\"com.apple.coremedia\", \"testkey\")"]; 180 auto userDefaults = adoptNS([[NSUserDefaults alloc] initWithSuiteName:(NSString *)testDomain]); 181 [userDefaults.get() setObject:data forKey:(NSString *)testKey]; 182 183 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 184 WKRetainPtr<WKContextRef> context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest")); 185 configuration.get().processPool = (WKProcessPool *)context.get(); 186 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]); 187 188 auto preferenceValue = [&] { 189 NSString *js = [NSString stringWithFormat:@"window.internals.encodedPreferenceValue(\"%@\",\"%@\")", (NSString *)testDomain, (NSString *)testKey]; 190 return [webView stringByEvaluatingJavaScript:js]; 182 191 }; 183 192 … … 185 194 186 195 NSData *changedData = [NSData dataWithBytes:"abcd" length:4]; 187 [userDefaults.get() setObject:changedData forKey: @"testkey"];196 [userDefaults.get() setObject:changedData forKey:(NSString *)testKey]; 188 197 189 198 auto encodedString = preferenceValue(); … … 201 210 NSDate *date = [NSDate dateWithTimeIntervalSinceNow:0]; 202 211 203 auto userDefaults = adoptNS([[NSUserDefaults alloc] initWithSuiteName:@"com.apple.coremedia"]); 204 [userDefaults.get() setObject:date forKey:@"testkey"]; 205 206 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 207 WKRetainPtr<WKContextRef> context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest")); 208 configuration.get().processPool = (WKProcessPool *)context.get(); 209 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]); 210 211 auto preferenceValue = [&] { 212 return [webView stringByEvaluatingJavaScript:@"window.internals.encodedPreferenceValue(\"com.apple.coremedia\", \"testkey\")"]; 212 auto userDefaults = adoptNS([[NSUserDefaults alloc] initWithSuiteName:(NSString *)testDomain]); 213 [userDefaults.get() setObject:date forKey:(NSString *)testKey]; 214 215 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 216 WKRetainPtr<WKContextRef> context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest")); 217 configuration.get().processPool = (WKProcessPool *)context.get(); 218 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]); 219 220 auto preferenceValue = [&] { 221 NSString *js = [NSString stringWithFormat:@"window.internals.encodedPreferenceValue(\"%@\",\"%@\")", (NSString *)testDomain, (NSString *)testKey]; 222 return [webView stringByEvaluatingJavaScript:js]; 213 223 }; 214 224 … … 216 226 217 227 NSDate *changedDate = [NSDate dateWithTimeIntervalSinceNow:10]; 218 [userDefaults.get() setObject:changedDate forKey: @"testkey"];228 [userDefaults.get() setObject:changedDate forKey:(NSString *)testKey]; 219 229 220 230 auto encodedString = preferenceValue(); … … 228 238 } 229 239 240 static IMP sharedInstanceMethodOriginal = nil; 241 242 static WKPreferenceObserver *sharedInstanceMethodOverride(id self, SEL selector) 243 { 244 done = true; 245 return wtfCallIMP<WKPreferenceObserver *>(sharedInstanceMethodOriginal, self, selector); 246 } 247 248 TEST(WebKit, PreferenceObserverStartedOnActivation) 249 { 250 done = false; 251 Method sharedInstanceMethod = class_getClassMethod(objc_getClass("WKPreferenceObserver"), @selector(sharedInstance)); 252 ASSERT(sharedInstanceMethod); 253 sharedInstanceMethodOriginal = method_setImplementation(sharedInstanceMethod, (IMP)sharedInstanceMethodOverride); 254 ASSERT(sharedInstanceMethodOriginal); 255 256 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 257 WKRetainPtr<WKContextRef> context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest")); 258 configuration.get().processPool = (WKProcessPool *)context.get(); 259 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]); 260 261 [webView synchronouslyLoadTestPageNamed:@"simple"]; 262 263 [[NSNotificationCenter defaultCenter] postNotificationName:NSApplicationDidBecomeActiveNotification object:NSApp userInfo:nil]; 264 265 TestWebKitAPI::Util::run(&done); 266 } 267 230 268 #endif // WK_HAVE_C_SPI
Note: See TracChangeset
for help on using the changeset viewer.