Title: [137637] trunk/Source/WebKit2
Revision
137637
Author
[email protected]
Date
2012-12-13 12:44:22 -0800 (Thu, 13 Dec 2012)

Log Message

[WebKit2] Only register NSNotificationCenter observers once per WebContext
https://bugs.webkit.org/show_bug.cgi?id=104879

Reviewed by Alexey Proskuryakov.

WebContext was mistakenly registering NSNotificationCenter observers
every time a new web process was created. In a multi-WebProcess world,
this caused duplicate observers to be needlessly registered. Fix this
by registering observers at WebContext creation time (and fix a related
bug where two of the observers were never unregistered).

* UIProcess/WebContext.h:
* UIProcess/mac/WebContextMac.mm:
(WebKit::WebContext::platformInitialize): Register observers when initializing the context.
(WebKit::WebContext::platformInitializeWebProcess): Don't register observers here.
(WebKit::WebContext::platformInvalidateContext): Unregister observers when invalidating the context.
(WebKit::WebContext::registerNotificationObservers):
(WebKit::WebContext::unregisterNotificationObservers):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (137636 => 137637)


--- trunk/Source/WebKit2/ChangeLog	2012-12-13 20:11:46 UTC (rev 137636)
+++ trunk/Source/WebKit2/ChangeLog	2012-12-13 20:44:22 UTC (rev 137637)
@@ -1,3 +1,24 @@
+2012-12-12  Andy Estes  <[email protected]>
+
+        [WebKit2] Only register NSNotificationCenter observers once per WebContext
+        https://bugs.webkit.org/show_bug.cgi?id=104879
+
+        Reviewed by Alexey Proskuryakov.
+
+        WebContext was mistakenly registering NSNotificationCenter observers
+        every time a new web process was created. In a multi-WebProcess world,
+        this caused duplicate observers to be needlessly registered. Fix this
+        by registering observers at WebContext creation time (and fix a related
+        bug where two of the observers were never unregistered).
+
+        * UIProcess/WebContext.h:
+        * UIProcess/mac/WebContextMac.mm:
+        (WebKit::WebContext::platformInitialize): Register observers when initializing the context.
+        (WebKit::WebContext::platformInitializeWebProcess): Don't register observers here.
+        (WebKit::WebContext::platformInvalidateContext): Unregister observers when invalidating the context.
+        (WebKit::WebContext::registerNotificationObservers):
+        (WebKit::WebContext::unregisterNotificationObservers):
+
 2012-12-13  Anders Carlsson  <[email protected]>
 
         Download objects should keep track of their associated DownloadManager object

Modified: trunk/Source/WebKit2/UIProcess/WebContext.h (137636 => 137637)


--- trunk/Source/WebKit2/UIProcess/WebContext.h	2012-12-13 20:11:46 UTC (rev 137636)
+++ trunk/Source/WebKit2/UIProcess/WebContext.h	2012-12-13 20:44:22 UTC (rev 137637)
@@ -319,6 +319,8 @@
     static void applicationBecameOccluded(uint32_t, void*, uint32_t, void*, uint32_t);
     static void initializeProcessSuppressionSupport();
     static void registerOcclusionNotificationHandlers();
+    void registerNotificationObservers();
+    void unregisterNotificationObservers();
 #endif
 
     void addPlugInAutoStartOriginHash(const String& pageOrigin, unsigned plugInOriginHash);

Modified: trunk/Source/WebKit2/UIProcess/mac/WebContextMac.mm (137636 => 137637)


--- trunk/Source/WebKit2/UIProcess/mac/WebContextMac.mm	2012-12-13 20:11:46 UTC (rev 137636)
+++ trunk/Source/WebKit2/UIProcess/mac/WebContextMac.mm	2012-12-13 20:44:22 UTC (rev 137637)
@@ -79,6 +79,7 @@
 void WebContext::platformInitialize()
 {
     registerUserDefaultsIfNeeded();
+    registerNotificationObservers();
 }
 
 String WebContext::applicationCacheDirectory()
@@ -131,30 +132,11 @@
     NSArray *schemes = [[WKBrowsingContextController customSchemes] allObjects];
     for (size_t i = 0; i < [schemes count]; ++i)
         parameters.urlSchemesRegisteredForCustomProtocols.append([schemes objectAtIndex:i]);
-
-    // FIXME(Multi-WebProcess): We register observers for every process that is created, which makes no sense.
-
-    m_customSchemeRegisteredObserver = [[NSNotificationCenter defaultCenter] addObserverForName:WebKit::SchemeForCustomProtocolRegisteredNotificationName object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
-        NSString *scheme = [notification object];
-        ASSERT([scheme isKindOfClass:[NSString class]]);
-        sendToAllProcesses(Messages::WebProcess::RegisterSchemeForCustomProtocol(scheme));
-    }];
-    
-    m_customSchemeUnregisteredObserver = [[NSNotificationCenter defaultCenter] addObserverForName:WebKit::SchemeForCustomProtocolUnregisteredNotificationName object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
-        NSString *scheme = [notification object];
-        ASSERT([scheme isKindOfClass:[NSString class]]);
-        sendToAllProcesses(Messages::WebProcess::UnregisterSchemeForCustomProtocol(scheme));
-    }];
-    
-    // Listen for enhanced accessibility changes and propagate them to the WebProcess.
-    m_enhancedAccessibilityObserver = [[NSNotificationCenter defaultCenter] addObserverForName:WebKitApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *note) {
-        setEnhancedAccessibility([[[note userInfo] objectForKey:@"AXEnhancedUserInterface"] boolValue]);
-    }];
 }
 
 void WebContext::platformInvalidateContext()
 {
-    [[NSNotificationCenter defaultCenter] removeObserver:(id)m_enhancedAccessibilityObserver.get()];
+    unregisterNotificationObservers();
 }
 
 String WebContext::platformDefaultDiskCacheDirectory() const
@@ -352,5 +334,32 @@
         WTFLogAlways("Registeration of \"App Became Occluded\" notification handler failed.\n");
 #endif
 }
+    
+void WebContext::registerNotificationObservers()
+{
+    m_customSchemeRegisteredObserver = [[NSNotificationCenter defaultCenter] addObserverForName:WebKit::SchemeForCustomProtocolRegisteredNotificationName object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
+        NSString *scheme = [notification object];
+        ASSERT([scheme isKindOfClass:[NSString class]]);
+        sendToAllProcesses(Messages::WebProcess::RegisterSchemeForCustomProtocol(scheme));
+    }];
+    
+    m_customSchemeUnregisteredObserver = [[NSNotificationCenter defaultCenter] addObserverForName:WebKit::SchemeForCustomProtocolUnregisteredNotificationName object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
+        NSString *scheme = [notification object];
+        ASSERT([scheme isKindOfClass:[NSString class]]);
+        sendToAllProcesses(Messages::WebProcess::UnregisterSchemeForCustomProtocol(scheme));
+    }];
+    
+    // Listen for enhanced accessibility changes and propagate them to the WebProcess.
+    m_enhancedAccessibilityObserver = [[NSNotificationCenter defaultCenter] addObserverForName:WebKitApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *note) {
+        setEnhancedAccessibility([[[note userInfo] objectForKey:@"AXEnhancedUserInterface"] boolValue]);
+    }];
+}
 
+void WebContext::unregisterNotificationObservers()
+{
+    [[NSNotificationCenter defaultCenter] removeObserver:(id)m_customSchemeRegisteredObserver.get()];
+    [[NSNotificationCenter defaultCenter] removeObserver:(id)m_customSchemeUnregisteredObserver.get()];
+    [[NSNotificationCenter defaultCenter] removeObserver:(id)m_enhancedAccessibilityObserver.get()];
+}
+
 } // namespace WebKit
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to