Modified: trunk/Source/WebCore/PAL/ChangeLog (234119 => 234120)
--- trunk/Source/WebCore/PAL/ChangeLog 2018-07-23 23:25:42 UTC (rev 234119)
+++ trunk/Source/WebCore/PAL/ChangeLog 2018-07-23 23:27:28 UTC (rev 234120)
@@ -1,3 +1,14 @@
+2018-07-23 Tim Horton <[email protected]>
+
+ Creating and loading content in a WKWebView triggers Main Thread Checker warnings under ServicesController
+ https://bugs.webkit.org/show_bug.cgi?id=186963
+ <rdar://problem/41393682>
+
+ Reviewed by Timothy Hatcher.
+
+ * pal/spi/mac/NSSharingServiceSPI.h:
+ Add the new SPI.
+
2018-07-18 Per Arne Vollan <[email protected]>
The WebContent process does not suspend when MiniBrowser is minimized.
Modified: trunk/Source/WebCore/PAL/pal/spi/mac/NSSharingServiceSPI.h (234119 => 234120)
--- trunk/Source/WebCore/PAL/pal/spi/mac/NSSharingServiceSPI.h 2018-07-23 23:25:42 UTC (rev 234119)
+++ trunk/Source/WebCore/PAL/pal/spi/mac/NSSharingServiceSPI.h 2018-07-23 23:27:28 UTC (rev 234120)
@@ -45,8 +45,9 @@
NSSharingServiceMaskAllTypes = 0xFFFF
} NS_ENUM_AVAILABLE_MAC(10_10);
-@interface NSSharingService (Private)
+@interface NSSharingService ()
+ (NSArray *)sharingServicesForItems:(NSArray *)items mask:(NSSharingServiceMask)maskForFiltering;
++ (void)sharingServicesForItems:(NSArray *)items mask:(NSSharingServiceMask)maskForFiltering completion:(void(^)(NSArray *))completion;
@property (readonly) NSSharingServiceType type;
@property (readwrite, copy) NSString *name;
@end
Modified: trunk/Source/WebKit/ChangeLog (234119 => 234120)
--- trunk/Source/WebKit/ChangeLog 2018-07-23 23:25:42 UTC (rev 234119)
+++ trunk/Source/WebKit/ChangeLog 2018-07-23 23:27:28 UTC (rev 234120)
@@ -1,3 +1,19 @@
+2018-07-23 Tim Horton <[email protected]>
+
+ Creating and loading content in a WKWebView triggers Main Thread Checker warnings under ServicesController
+ https://bugs.webkit.org/show_bug.cgi?id=186963
+ <rdar://problem/41393682>
+
+ Reviewed by Timothy Hatcher.
+
+ * UIProcess/mac/ServicesController.h:
+ * UIProcess/mac/ServicesController.mm:
+ (WebKit::hasCompatibleServicesForItems):
+ (WebKit::ServicesController::refreshExistingServices):
+ Adopt async ShareKit SPI that is actually thread-safe instead of the not-quite-safe
+ synchronous API. Request all three sets of services immediately, and dispatch
+ to the Web Content processes when all three have returned.
+
2018-07-23 Chris Dumez <[email protected]>
WebResourceLoadStatisticsStore fails to unregister itself as a MessageReceiver in its destructor
Modified: trunk/Source/WebKit/UIProcess/mac/ServicesController.h (234119 => 234120)
--- trunk/Source/WebKit/UIProcess/mac/ServicesController.h 2018-07-23 23:25:42 UTC (rev 234119)
+++ trunk/Source/WebKit/UIProcess/mac/ServicesController.h 2018-07-23 23:27:28 UTC (rev 234120)
@@ -52,10 +52,14 @@
dispatch_queue_t m_refreshQueue;
std::atomic_bool m_hasPendingRefresh;
- bool m_hasImageServices;
- bool m_hasSelectionServices;
- bool m_hasRichContentServices;
+ std::atomic<bool> m_hasImageServices;
+ std::atomic<bool> m_hasSelectionServices;
+ std::atomic<bool> m_hasRichContentServices;
+ bool m_lastSentHasImageServices;
+ bool m_lastSentHasSelectionServices;
+ bool m_lastSentHasRichContentServices;
+
RetainPtr<id> m_extensionWatcher;
RetainPtr<id> m_uiExtensionWatcher;
};
Modified: trunk/Source/WebKit/UIProcess/mac/ServicesController.mm (234119 => 234120)
--- trunk/Source/WebKit/UIProcess/mac/ServicesController.mm 2018-07-23 23:25:42 UTC (rev 234119)
+++ trunk/Source/WebKit/UIProcess/mac/ServicesController.mm 2018-07-23 23:27:28 UTC (rev 234120)
@@ -33,6 +33,7 @@
#import <pal/spi/cocoa/NSExtensionSPI.h>
#import <pal/spi/mac/NSSharingServicePickerSPI.h>
#import <pal/spi/mac/NSSharingServiceSPI.h>
+#import <wtf/BlockPtr.h>
#import <wtf/NeverDestroyed.h>
namespace WebKit {
@@ -65,9 +66,20 @@
#endif // __LP64__
}
-static bool hasCompatibleServicesForItems(NSArray *items)
+static void hasCompatibleServicesForItems(dispatch_group_t group, NSArray *items, WTF::Function<void(bool)>&& completionHandler)
{
- return [NSSharingService sharingServicesForItems:items mask:NSSharingServiceMaskViewer | NSSharingServiceMaskEditor].count;
+ NSSharingServiceMask servicesMask = NSSharingServiceMaskViewer | NSSharingServiceMaskEditor;
+
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+ dispatch_group_enter(group);
+ [NSSharingService sharingServicesForItems:items mask:servicesMask completion:BlockPtr<void(NSArray *)>::fromCallable([completionHandler = WTFMove(completionHandler), group](NSArray *services) {
+ completionHandler(services.count);
+ dispatch_group_leave(group);
+ }).get()];
+#else
+ UNUSED_PARAM(group);
+ completionHandler([NSSharingService sharingServicesForItems:items mask:servicesMask].count);
+#endif
}
void ServicesController::refreshExistingServices(bool refreshImmediately)
@@ -79,11 +91,17 @@
auto refreshTime = dispatch_time(DISPATCH_TIME_NOW, refreshImmediately ? 0 : (int64_t)(1 * NSEC_PER_SEC));
dispatch_after(refreshTime, m_refreshQueue, ^{
+ auto serviceLookupGroup = adoptOSObject(dispatch_group_create());
+
static NeverDestroyed<NSImage *> image([[NSImage alloc] init]);
- bool hasImageServices = hasCompatibleServicesForItems(@[ image ]);
+ hasCompatibleServicesForItems(serviceLookupGroup.get(), @[ image ], [this] (bool hasServices) {
+ m_hasImageServices = hasServices;
+ });
static NeverDestroyed<NSAttributedString *> attributedString([[NSAttributedString alloc] initWithString:@"a"]);
- bool hasSelectionServices = hasCompatibleServicesForItems(@[ attributedString ]);
+ hasCompatibleServicesForItems(serviceLookupGroup.get(), @[ attributedString ], [this] (bool hasServices) {
+ m_hasSelectionServices = hasServices;
+ });
static NSAttributedString *attributedStringWithRichContent;
if (!attributedStringWithRichContent) {
@@ -97,15 +115,17 @@
});
}
- bool hasRichContentServices = hasCompatibleServicesForItems(@[ attributedStringWithRichContent ]);
-
- dispatch_async(dispatch_get_main_queue(), ^{
- bool availableServicesChanged = (hasImageServices != m_hasImageServices) || (hasSelectionServices != m_hasSelectionServices) || (hasRichContentServices != m_hasRichContentServices);
+ hasCompatibleServicesForItems(serviceLookupGroup.get(), @[ attributedStringWithRichContent ], [this] (bool hasServices) {
+ m_hasRichContentServices = hasServices;
+ });
- m_hasSelectionServices = hasSelectionServices;
- m_hasImageServices = hasImageServices;
- m_hasRichContentServices = hasRichContentServices;
+ dispatch_group_notify(serviceLookupGroup.get(), dispatch_get_main_queue(), BlockPtr<void(void)>::fromCallable([this] {
+ bool availableServicesChanged = (m_lastSentHasImageServices != m_hasImageServices) || (m_lastSentHasSelectionServices != m_hasSelectionServices) || (m_lastSentHasRichContentServices != m_hasRichContentServices);
+ m_lastSentHasSelectionServices = m_hasSelectionServices;
+ m_lastSentHasImageServices = m_hasImageServices;
+ m_lastSentHasRichContentServices = m_hasRichContentServices;
+
if (availableServicesChanged) {
for (auto& processPool : WebProcessPool::allProcessPools())
processPool->sendToAllProcesses(Messages::WebProcess::SetEnabledServices(m_hasImageServices, m_hasSelectionServices, m_hasRichContentServices));
@@ -112,7 +132,7 @@
}
m_hasPendingRefresh = false;
- });
+ }).get());
});
}