Reviewed and landed by Sam Weinig.
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 13 Feb 2011 17:39:12 +0000 (17:39 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 13 Feb 2011 17:39:12 +0000 (17:39 +0000)
Patch by Chris Fleizach <cfleizach@apple.com> on 2011-02-13
AX: Update WK2 usage of remote accessibility api
https://bugs.webkit.org/show_bug.cgi?id=54220

Rename some of the remote accessibility methods to be more accurate.
Make sure to unregister the AccessibilityWebPageObject on dealloc.
Send the window remote token along with the WKView remote token.

* UIProcess/API/mac/PageClientImpl.h:
* UIProcess/API/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::accessibilityWebProcessTokenReceived):
* UIProcess/API/mac/WKView.mm:
(-[WKView _updateRemoteAccessibilityRegistration:]):
(-[WKView initWithFrame:contextRef:pageGroupRef:]):
(-[WKView viewDidMoveToWindow]):
(-[WKView _processDidCrash]):
(-[WKView _pageClosed]):
(-[WKView _setAccessibilityWebProcessToken:]):
* UIProcess/API/mac/WKViewInternal.h:
* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::registerWebProcessAccessibilityToken):
(WebKit::WebPageProxy::registerUIProcessAccessibilityTokens):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/mac/AccessibilityWebPageObject.mm:
(-[AccessibilityWebPageObject dealloc]):
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::platformInitialize):
(WebKit::WebPage::registerUIProcessAccessibilityTokens):

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

13 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/mac/PageClientImpl.h
Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/API/mac/WKViewInternal.h
Source/WebKit2/UIProcess/PageClient.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
Source/WebKit2/WebProcess/WebPage/mac/AccessibilityWebPageObject.mm
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm

index ac54bc3..a004b68 100644 (file)
@@ -1,3 +1,39 @@
+2011-02-13  Chris Fleizach  <cfleizach@apple.com>
+
+        Reviewed and landed by Sam Weinig.
+
+        AX: Update WK2 usage of remote accessibility api
+        https://bugs.webkit.org/show_bug.cgi?id=54220
+
+        Rename some of the remote accessibility methods to be more accurate.
+        Make sure to unregister the AccessibilityWebPageObject on dealloc.
+        Send the window remote token along with the WKView remote token.
+
+        * UIProcess/API/mac/PageClientImpl.h:
+        * UIProcess/API/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::accessibilityWebProcessTokenReceived):
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView _updateRemoteAccessibilityRegistration:]):
+        (-[WKView initWithFrame:contextRef:pageGroupRef:]):
+        (-[WKView viewDidMoveToWindow]):
+        (-[WKView _processDidCrash]):
+        (-[WKView _pageClosed]):
+        (-[WKView _setAccessibilityWebProcessToken:]):
+        * UIProcess/API/mac/WKViewInternal.h:
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::registerWebProcessAccessibilityToken):
+        (WebKit::WebPageProxy::registerUIProcessAccessibilityTokens):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/mac/AccessibilityWebPageObject.mm:
+        (-[AccessibilityWebPageObject dealloc]):
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::platformInitialize):
+        (WebKit::WebPage::registerUIProcessAccessibilityTokens):
+
 2011-02-11  Alexey Proskuryakov  <ap@apple.com>
 
         Reviewed by Anders Carlsson.
index a90bedb..b557c1a 100644 (file)
@@ -91,7 +91,7 @@ private:
     virtual void pageDidLeaveAcceleratedCompositing();
 #endif
 
-    virtual void accessibilityChildTokenReceived(const CoreIPC::DataReference&);    
+    virtual void accessibilityWebProcessTokenReceived(const CoreIPC::DataReference&);    
     virtual void setComplexTextInputEnabled(uint64_t pluginComplexTextInputIdentifier, bool complexTextInputEnabled);
     virtual void setAutodisplay(bool);
 
index 73fed1a..fd70a67 100644 (file)
@@ -336,10 +336,10 @@ void PageClientImpl::setFindIndicator(PassRefPtr<FindIndicator> findIndicator, b
     [m_wkView _setFindIndicator:findIndicator fadeOut:fadeOut];
 }
 
-void PageClientImpl::accessibilityChildTokenReceived(const CoreIPC::DataReference& data)
+void PageClientImpl::accessibilityWebProcessTokenReceived(const CoreIPC::DataReference& data)
 {
     NSData* remoteToken = [NSData dataWithBytes:data.data() length:data.size()];
-    [m_wkView _setAccessibilityChildToken:remoteToken];
+    [m_wkView _setAccessibilityWebProcessToken:remoteToken];
 }
     
 #if USE(ACCELERATED_COMPOSITING)
index f3b2b1f..da29e04 100644 (file)
@@ -184,6 +184,24 @@ static bool useNewDrawingArea()
     [types release];
 }
 
+- (void)_updateRemoteAccessibilityRegistration:(BOOL)registerProcess
+{
+#if !defined(BUILDING_ON_SNOW_LEOPARD)
+    // When the tree is connected/disconnected, the remote accessibility registration
+    // needs to be updated with the pid of the remote process. If the process is going
+    // away, that information is not present in WebProcess
+    pid_t pid = 0;
+    if (registerProcess && _data->_page->process())
+        pid = _data->_page->process()->processIdentifier();
+    else if (!registerProcess) {
+        pid = WKAXRemoteProcessIdentifier(_data->_remoteAccessibilityChild.get());
+        _data->_remoteAccessibilityChild = nil;
+    }
+    if (pid)
+        WKAXRegisterRemoteProcess(registerProcess, pid); 
+#endif
+}
+
 - (id)initWithFrame:(NSRect)frame contextRef:(WKContextRef)contextRef pageGroupRef:(WKPageGroupRef)pageGroupRef
 {
     self = [super initWithFrame:frame];
@@ -212,12 +230,6 @@ static bool useNewDrawingArea()
 
     WebContext::statistics().wkViewCount++;
 
-#if !defined(BUILDING_ON_SNOW_LEOPARD)
-    NSData *remoteToken = (NSData *)WKAXRemoteTokenForElement(self);
-    CoreIPC::DataReference dataToken = CoreIPC::DataReference(reinterpret_cast<const uint8_t*>([remoteToken bytes]), [remoteToken length]);
-    _data->_page->sendAccessibilityPresenterToken(dataToken);
-#endif
-    
     return self;
 }
 
@@ -300,13 +312,6 @@ static bool useNewDrawingArea()
     return YES;
 }
 
-- (void)_setRemoteAccessibilityWindow:(id)window
-{
-#if !defined(BUILDING_ON_SNOW_LEOPARD)
-    WKAXInitializeRemoteElementWithWindow(_data->_remoteAccessibilityChild.get(), window);    
-#endif
-}
-
 - (void)setFrame:(NSRect)rect andScrollBy:(NSSize)offset
 {
     ASSERT(NSEqualSizes(_data->_resizeScrollOffset, NSZeroSize));
@@ -1377,6 +1382,16 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde
         _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible | WebPageProxy::ViewIsInWindow);
         [self _updateWindowVisibility];
         [self _updateWindowAndViewFrames];
+        
+        // Initialize remote accessibility when the window connection has been established.
+#if !defined(BUILDING_ON_SNOW_LEOPARD)
+        NSData *remoteElementToken = WKAXRemoteTokenForElement(self);
+        NSData *remoteWindowToken = WKAXRemoteTokenForElement([self window]);
+        CoreIPC::DataReference elementToken = CoreIPC::DataReference(reinterpret_cast<const uint8_t*>([remoteElementToken bytes]), [remoteElementToken length]);
+        CoreIPC::DataReference windowToken = CoreIPC::DataReference(reinterpret_cast<const uint8_t*>([remoteWindowToken bytes]), [remoteWindowToken length]);
+        _data->_page->registerUIProcessAccessibilityTokens(elementToken, windowToken);
+#endif    
+            
     } else {
         _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible);
         _data->_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive | WebPageProxy::ViewIsInWindow);
@@ -1388,7 +1403,6 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde
         }
 #endif
     }
-    [self _setRemoteAccessibilityWindow:[self window]];
 }
 
 - (void)_windowDidBecomeKey:(NSNotification *)notification
@@ -1589,14 +1603,12 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
 - (void)_processDidCrash
 {
     [self setNeedsDisplay:YES];
-    [self _setRemoteAccessibilityWindow:nil];
+    [self _updateRemoteAccessibilityRegistration:NO];
 }
 
 - (void)_pageClosed
 {
-    // When the page closes, the references the accessibility child has to the window 
-    // need to be removed, otherwise it can leak.
-    [self _setRemoteAccessibilityWindow:nil];
+    [self _updateRemoteAccessibilityRegistration:NO];
 }
 
 - (void)_didRelaunchProcess
@@ -1925,11 +1937,11 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
 }
 #endif // USE(ACCELERATED_COMPOSITING)
 
-- (void)_setAccessibilityChildToken:(NSData *)data
+- (void)_setAccessibilityWebProcessToken:(NSData *)data
 {
 #if !defined(BUILDING_ON_SNOW_LEOPARD)
-    _data->_remoteAccessibilityChild = WKAXRemoteElementForToken((CFDataRef)data);
-    [self _setRemoteAccessibilityWindow:[self window]];
+    _data->_remoteAccessibilityChild = WKAXRemoteElementForToken(data);
+    [self _updateRemoteAccessibilityRegistration:YES];
 #endif
 }
 
index 30ab25d..9e77e30 100644 (file)
@@ -59,7 +59,7 @@ namespace WebKit {
 - (void)_pageDidLeaveAcceleratedCompositing;
 #endif
 
-- (void)_setAccessibilityChildToken:(NSData *)data;
+- (void)_setAccessibilityWebProcessToken:(NSData *)data;
 - (void)_setComplexTextInputEnabled:(BOOL)complexTextInputEnabled pluginComplexTextInputIdentifier:(uint64_t)pluginComplexTextInputIdentifier;
 
 - (void)_setPageHasCustomRepresentation:(BOOL)pageHasCustomRepresentation;
index 05476c0..4eb1860 100644 (file)
@@ -99,7 +99,7 @@ public:
     virtual void clearAllEditCommands() = 0;
     virtual void setEditCommandState(const String& commandName, bool isEnabled, int state) = 0;
 #if PLATFORM(MAC)
-    virtual void accessibilityChildTokenReceived(const CoreIPC::DataReference&) = 0;
+    virtual void accessibilityWebProcessTokenReceived(const CoreIPC::DataReference&) = 0;
     virtual void interceptKeyEvent(const NativeWebKeyboardEvent&, Vector<WebCore::KeypressCommand>& commandName, uint32_t selectionStart, uint32_t selectionEnd, Vector<WebCore::CompositionUnderline>& underlines) = 0;
     virtual void setDragImage(const WebCore::IntPoint& clientPosition, const WebCore::IntSize& imageSize, PassRefPtr<ShareableBitmap> dragImage, bool isLinkDrag) = 0;
 #endif
index 2edde9d..2582547 100644 (file)
@@ -1537,13 +1537,6 @@ void WebPageProxy::didRunInsecureContentForFrame(uint64_t frameID, CoreIPC::Argu
     m_loaderClient.didRunInsecureContentForFrame(this, frame, userData.get());
 }
 
-void WebPageProxy::didReceiveAccessibilityPageToken(const CoreIPC::DataReference& data)
-{
-#if PLATFORM(MAC)
-    m_pageClient->accessibilityChildTokenReceived(data);
-#endif
-}
-    
 void WebPageProxy::frameDidBecomeFrameSet(uint64_t frameID, bool value)
 {
     WebFrameProxy* frame = process()->webFrame(frameID);
@@ -2417,12 +2410,18 @@ void WebPageProxy::computedPagesCallback(const Vector<WebCore::IntRect>& pageRec
 }
 
 #if PLATFORM(MAC)
-void WebPageProxy::sendAccessibilityPresenterToken(const CoreIPC::DataReference& token)
+    
+void WebPageProxy::registerWebProcessAccessibilityToken(const CoreIPC::DataReference& data)
+{
+    m_pageClient->accessibilityWebProcessTokenReceived(data);
+}    
+    
+void WebPageProxy::registerUIProcessAccessibilityTokens(const CoreIPC::DataReference& elementToken, const CoreIPC::DataReference& windowToken)
 {
     if (!isValid())
         return;
 
-    process()->send(Messages::WebPage::SendAccessibilityPresenterToken(token), m_pageID);
+    process()->send(Messages::WebPage::RegisterUIProcessAccessibilityTokens(elementToken, windowToken), m_pageID);
 }
 #endif
 
index 05c5abb..46aa240 100644 (file)
@@ -271,7 +271,10 @@ public:
     bool hasVerticalScrollbar() const { return m_mainFrameHasVerticalScrollbar; }
 
 #if PLATFORM(MAC)
-    void sendAccessibilityPresenterToken(const CoreIPC::DataReference&);
+    // Called by the web process through a message.
+    void registerWebProcessAccessibilityToken(const CoreIPC::DataReference&);
+    // Called by the UI process when it is ready to send its tokens to the web process.
+    void registerUIProcessAccessibilityTokens(const CoreIPC::DataReference& elemenToken, const CoreIPC::DataReference& windowToken);
 #endif
 
     void viewScaleFactorDidChange(double);
@@ -429,7 +432,6 @@ private:
     void didStartProgress();
     void didChangeProgress(double);
     void didFinishProgress();
-    void didReceiveAccessibilityPageToken(const CoreIPC::DataReference&);
     
     void decidePolicyForNavigationAction(uint64_t frameID, uint32_t navigationType, uint32_t modifiers, int32_t mouseButton, const WebCore::ResourceRequest&, uint64_t listenerID, CoreIPC::ArgumentDecoder*, bool& receivedPolicyAction, uint64_t& policyAction);
     void decidePolicyForNewWindowAction(uint64_t frameID, uint32_t navigationType, uint32_t modifiers, int32_t mouseButton, const WebCore::ResourceRequest&, const String& frameName, uint64_t listenerID, CoreIPC::ArgumentDecoder*);
index 98cf22a..e566d02 100644 (file)
@@ -120,13 +120,15 @@ messages -> WebPageProxy {
     StringCallback(WTF::String resultString, uint64_t callbackID)
     ComputedPagesCallback(Vector<WebCore::IntRect> pageRects, double totalScaleFactorForPrinting, uint64_t callbackID)
 
-    DidReceiveAccessibilityPageToken(CoreIPC::DataReference data)
 
     ViewScaleFactorDidChange(double scaleFactor)
 
 #if PLATFORM(MAC)
     # Keyboard support messages
     InterpretKeyEvent(uint32_t type) -> (Vector<WebCore::KeypressCommand> commandName, uint32_t selectionStart, uint32_t selectionEnd, Vector<WebCore::CompositionUnderline> underlines)
+    
+    # Remote accessibility messages
+    RegisterWebProcessAccessibilityToken(CoreIPC::DataReference data)
 #endif
     
     # BackForward messages
index 9087359..89087b0 100644 (file)
@@ -285,7 +285,7 @@ public:
     static void getLocationAndLengthFromRange(WebCore::Range*, uint64_t& location, uint64_t& length);
 
 #if PLATFORM(MAC)
-    void sendAccessibilityPresenterToken(const CoreIPC::DataReference&);
+    void registerUIProcessAccessibilityTokens(const CoreIPC::DataReference& elemenToken, const CoreIPC::DataReference& windowToken);
     AccessibilityWebPageObject* accessibilityRemoteObject();
     WebCore::IntPoint accessibilityPosition() const { return m_accessibilityPosition; }    
     
index 008f157..e47a013 100644 (file)
@@ -171,7 +171,7 @@ messages -> WebPage {
     GetMarkedRange() -> (uint64_t location, uint64_t length)
     CharacterIndexForPoint(WebCore::IntPoint point) -> (uint64_t result)
     FirstRectForCharacterRange(uint64_t location, uint64_t length) -> (WebCore::IntRect resultRect)
-    SendAccessibilityPresenterToken(CoreIPC::DataReference token)
+    RegisterUIProcessAccessibilityTokens(CoreIPC::DataReference elemenToken, CoreIPC::DataReference windowToken)
 #endif
 #if PLATFORM(WIN)
     ConfirmComposition(WTF::String compositionString)
index e73fb2c..c88ab7e 100644 (file)
@@ -33,6 +33,7 @@
 #import <WebCore/FrameView.h>
 #import <WebCore/ScrollView.h>
 #import <WebCore/Scrollbar.h>
+#import <WebKitSystemInterface.h>
 
 using namespace WebCore;
 using namespace WebKit;
@@ -71,6 +72,7 @@ using namespace WebKit;
 
 - (void)dealloc
 {
+    WKUnregisterUniqueIdForElement(self);
     [m_accessibilityChildren release];
     [m_attributeNames release];
     [m_parent release];
index 1a378bc..71bbf78 100644 (file)
@@ -66,7 +66,7 @@ void WebPage::platformInitialize()
     // send data back over
     NSData* remoteToken = (NSData *)WKAXRemoteTokenForElement(mockAccessibilityElement); 
     CoreIPC::DataReference dataToken = CoreIPC::DataReference(reinterpret_cast<const uint8_t*>([remoteToken bytes]), [remoteToken length]);
-    send(Messages::WebPageProxy::DidReceiveAccessibilityPageToken(dataToken));
+    send(Messages::WebPageProxy::RegisterWebProcessAccessibilityToken(dataToken));
     m_mockAccessibilityElement = mockAccessibilityElement;
 #endif
 }
@@ -336,11 +336,16 @@ bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboard
     return true;
 }
 
-void WebPage::sendAccessibilityPresenterToken(const CoreIPC::DataReference& data)
+void WebPage::registerUIProcessAccessibilityTokens(const CoreIPC::DataReference& elementToken, const CoreIPC::DataReference& windowToken)
 {
 #if !defined(BUILDING_ON_SNOW_LEOPARD)
-    NSData* tokenData = [NSData dataWithBytes:data.data() length:data.size()];
-    [m_mockAccessibilityElement.get() setRemoteParent:WKAXRemoteElementForToken((CFDataRef)tokenData)];
+    NSData* elementTokenData = [NSData dataWithBytes:elementToken.data() length:elementToken.size()];
+    NSData* windowTokenData = [NSData dataWithBytes:windowToken.data() length:windowToken.size()];
+    id remoteElement = WKAXRemoteElementForToken(elementTokenData);
+    id remoteWindow = WKAXRemoteElementForToken(windowTokenData);
+    WKAXSetWindowForRemoteElement(remoteWindow, remoteElement);
+    
+    [accessibilityRemoteObject() setRemoteParent:remoteElement];
 #endif
 }