Don't register for Lookup notifications until needed
authorconrad_shultz@apple.com <conrad_shultz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 May 2015 04:23:41 +0000 (04:23 +0000)
committerconrad_shultz@apple.com <conrad_shultz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 May 2015 04:23:41 +0000 (04:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=144783

Reviewed by Tim Horton.

* UIProcess/API/mac/WKView.mm:
Add a WKViewData ivar to track whether we've already registered for popover notifications.
(-[WKView _prepareForDictionaryLookup]):
Added; moved notification registration from -[WKView initWithFrame:processPool:configuration:webView:.
(-[WKView initWithFrame:processPool:configuration:webView:]):
Move notification registration to -_prepareForDictionaryLookup.

* UIProcess/API/mac/WKViewInternal.h:
Expose -_prepareForDictionaryLookup.

* UIProcess/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::didPerformDictionaryLookup):
Send -[WKView _prepareForDictionaryLookup].

* UIProcess/mac/WKImmediateActionController.mm:
(-[WKImmediateActionController _animationControllerForText]):
Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183978 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/API/mac/WKViewInternal.h
Source/WebKit2/UIProcess/mac/PageClientImpl.mm
Source/WebKit2/UIProcess/mac/WKImmediateActionController.mm

index 23286f7..5336651 100644 (file)
@@ -1,3 +1,28 @@
+2015-05-07  Conrad Shultz  <conrad_shultz@apple.com>
+
+        Don't register for Lookup notifications until needed
+        https://bugs.webkit.org/show_bug.cgi?id=144783
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/API/mac/WKView.mm:
+        Add a WKViewData ivar to track whether we've already registered for popover notifications.
+        (-[WKView _prepareForDictionaryLookup]):
+        Added; moved notification registration from -[WKView initWithFrame:processPool:configuration:webView:.
+        (-[WKView initWithFrame:processPool:configuration:webView:]):
+        Move notification registration to -_prepareForDictionaryLookup.
+
+        * UIProcess/API/mac/WKViewInternal.h:
+        Expose -_prepareForDictionaryLookup.
+
+        * UIProcess/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::didPerformDictionaryLookup):
+        Send -[WKView _prepareForDictionaryLookup].
+
+        * UIProcess/mac/WKImmediateActionController.mm:
+        (-[WKImmediateActionController _animationControllerForText]):
+        Ditto.
+
 2015-05-07  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r183961.
index e04540b..f3a0158 100644 (file)
@@ -280,6 +280,8 @@ struct WKViewInterpretKeyEventsParameters {
 
     CGFloat _overrideDeviceScaleFactor;
 
+    BOOL _didRegisterForLookupPopoverCloseNotifications;
+
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
     BOOL _automaticallyAdjustsContentInsets;
     RetainPtr<WKActionMenuController> _actionMenuController;
@@ -2888,6 +2890,17 @@ static void* keyValueObservingContext = &keyValueObservingContext;
     _data->_page->viewStateDidChange(ViewState::IsVisible);
 }
 
+- (void)_prepareForDictionaryLookup
+{
+    if (_data->_didRegisterForLookupPopoverCloseNotifications)
+        return;
+
+    _data->_didRegisterForLookupPopoverCloseNotifications = YES;
+
+    if (canLoadLUNotificationPopoverWillClose())
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_dictionaryLookupPopoverWillClose:) name:getLUNotificationPopoverWillClose() object:nil];
+}
+
 - (void)_dictionaryLookupPopoverWillClose:(NSNotification *)notification
 {
     [self _clearTextIndicatorWithAnimation:TextIndicatorDismissalAnimation::None];
@@ -3832,9 +3845,6 @@ static NSString *pathWithUniqueFilenameForPath(NSString *path)
     NSNotificationCenter* workspaceNotificationCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
     [workspaceNotificationCenter addObserver:self selector:@selector(_activeSpaceDidChange:) name:NSWorkspaceActiveSpaceDidChangeNotification object:nil];
 
-    if (canLoadLUNotificationPopoverWillClose())
-        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_dictionaryLookupPopoverWillClose:) name:getLUNotificationPopoverWillClose() object:nil];
-
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
     if ([self respondsToSelector:@selector(_setActionMenu:)]) {
         RetainPtr<NSMenu> menu = adoptNS([[NSMenu alloc] init]);
index bde41c4..d03d375 100644 (file)
@@ -140,6 +140,8 @@ struct WebPageConfiguration;
 @property (readonly) WKFullScreenWindowController *_fullScreenWindowController;
 - (void)_closeFullScreenWindowController;
 
+- (void)_prepareForDictionaryLookup;
+
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
 - (void)_didPerformActionMenuHitTest:(const WebKit::WebHitTestResult::Data&)hitTestResult forImmediateAction:(BOOL)forImmediateAction contentPreventsDefault:(BOOL)contentPreventsDefault userData:(API::Object*)userData;
 #endif
index da40923..0769050 100644 (file)
@@ -593,6 +593,8 @@ void PageClientImpl::didPerformDictionaryLookup(const DictionaryPopupInfo& dicti
 
     RetainPtr<NSMutableDictionary> mutableOptions = adoptNS([(NSDictionary *)dictionaryPopupInfo.options.get() mutableCopy]);
 
+    [m_wkView _prepareForDictionaryLookup];
+
     if (canLoadLUTermOptionDisableSearchTermIndicator() && dictionaryPopupInfo.textIndicator.contentImage) {
         [m_wkView _setTextIndicator:*TextIndicator::create(dictionaryPopupInfo.textIndicator) withLifetime:TextIndicatorLifetime::Permanent];
         [mutableOptions setObject:@YES forKey:getLUTermOptionDisableSearchTermIndicator()];
index ca715d1..77ab69c 100644 (file)
@@ -467,6 +467,8 @@ using namespace WebKit;
     if (!dictionaryPopupInfo.attributedString.string)
         return nil;
 
+    [_wkView _prepareForDictionaryLookup];
+
     // Convert baseline to screen coordinates.
     NSPoint textBaselineOrigin = dictionaryPopupInfo.origin;
     textBaselineOrigin = [_wkView convertPoint:textBaselineOrigin toView:nil];