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 ac54bc3d01c09fda8431fa1af57633dd7c5e3d52..a004b683ff70ff82de0d279b3ec208e0d390289f 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 a90bedb57d6497f9e5c29cbddc02ed5cfed04c18..b557c1af6d9cee779f7db73daa703bb69b9bf4c0 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 73fed1a840d984955d40ca8eb7406f0236954a35..fd70a6715de8c09fddf15b3730eb072d35efca5f 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 f3b2b1fd75920349ea44a27926afa4f51ec75daa..da29e04755c08819227004720b74fd89efdaa3ad 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 30ab25d01a150a879b93b9caf30d28fa184dd419..9e77e30a2edc6a971aef4e6d802880d56cd161ba 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 05476c052408b9b05d695580cc23c313d53474a1..4eb1860e85df337b2d98d3a39a1544a5e13db0e0 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 2edde9d04a9a9235266d76812fcb29070d05a5e1..25825471bda8842c4f6a3ea388d22fd82999d856 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 05c5abbf7571f9bedab56f28eb7213f8afc72bd1..46aa240c7e2cc5a3d2bc8ed02dad1b413ce8ae59 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 98cf22a0a3b69db8d54e9e4c4c2f2c46d145164d..e566d0270482fd23d72e512bfcf39ffc1dcb0bb8 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 90873594bc96c532b973ac6f6c00d62417ccf01c..89087b04da47219135ed3edfb47c021204a56b49 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 008f15774b9bc62a506a54a381d240cc0f4dc9b6..e47a01322d4cdd82e3a94547b4d0fdbcb7ca47a0 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 e73fb2cd031ef4824f9daaec6bb800813d2bb19f..c88ab7e26596b4f2c6d2683e3552dcf11e62b044 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 1a378bc5e642badae0bcd09f3f677dd76fa36bfd..71bbf783b5d11dd371f244681c9a1c8c64708bc8 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
 }