Bug 1310833: Modify PContentParent::SendActivateA11y to accept the content process's MSAA ID as a parameter; r=tbsaunde
authorAaron Klotz <aklotz@mozilla.com>
Thu, 20 Oct 2016 12:34:16 -0600
changeset 319857 e8d74a682eeaebecb0cf31625add0a92821fbb1c
parent 319856 0694957ec0945847f3b73e222051a91641031666
child 319858 3f15ff10cb267d4289655b2e3cf0a0dee48e7c0b
push id20749
push userryanvm@gmail.com
push dateSat, 29 Oct 2016 13:21:21 +0000
treeherderfx-team@1b170b39ed6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstbsaunde
bugs1310833
milestone52.0a1
Bug 1310833: Modify PContentParent::SendActivateA11y to accept the content process's MSAA ID as a parameter; r=tbsaunde MozReview-Commit-ID: DCnYvWQRA5W
accessible/windows/msaa/MsaaIdGenerator.cpp
accessible/windows/msaa/MsaaIdGenerator.h
dom/ipc/ContentChild.cpp
dom/ipc/ContentChild.h
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/ipc/PContent.ipdl
--- a/accessible/windows/msaa/MsaaIdGenerator.cpp
+++ b/accessible/windows/msaa/MsaaIdGenerator.cpp
@@ -80,36 +80,34 @@ public:
 private:
   MsaaID  mID;
 };
 
 } // namespace detail
 
 constexpr MsaaIdGenerator::MsaaIdGenerator()
   : mIDSet(kNumUniqueIDBits)
-  , mContentProcessID(0)
 {}
 
 uint32_t
 MsaaIdGenerator::GetID()
 {
-  static const uint32_t kContentProcessId = ResolveContentProcessID();
   uint32_t id = mIDSet.GetID();
   MOZ_ASSERT(id <= ((1UL << kNumUniqueIDBits) - 1UL));
-  return detail::BuildMsaaID(id, kContentProcessId);
+  return detail::BuildMsaaID(id, ResolveContentProcessID());
 }
 
 void
 MsaaIdGenerator::ReleaseID(AccessibleWrap* aAccWrap)
 {
   MOZ_ASSERT(aAccWrap);
   uint32_t id = aAccWrap->GetExistingID();
   MOZ_ASSERT(id != AccessibleWrap::kNoID);
   detail::MsaaIDCracker cracked(id);
-  if (cracked.GetContentProcessId() != mContentProcessID) {
+  if (cracked.GetContentProcessId() != ResolveContentProcessID()) {
     // This may happen if chrome holds a proxy whose ID was originally generated
     // by a content process. Since ReleaseID only has meaning in the process
     // that originally generated that ID, we ignore ReleaseID calls for any ID
     // that did not come from the current process.
     MOZ_ASSERT(aAccWrap->IsProxy());
     return;
   }
   mIDSet.ReleaseID(cracked.GetUniqueId());
@@ -121,19 +119,18 @@ MsaaIdGenerator::IsChromeID(uint32_t aID
   detail::MsaaIDCracker cracked(aID);
   return cracked.GetContentProcessId() == 0;
 }
 
 bool
 MsaaIdGenerator::IsIDForThisContentProcess(uint32_t aID)
 {
   MOZ_ASSERT(XRE_IsContentProcess());
-  static const uint32_t kContentProcessId = ResolveContentProcessID();
   detail::MsaaIDCracker cracked(aID);
-  return cracked.GetContentProcessId() == kContentProcessId;
+  return cracked.GetContentProcessId() == ResolveContentProcessID();
 }
 
 bool
 MsaaIdGenerator::IsIDForContentProcess(uint32_t aID,
                                        dom::ContentParentId aIPCContentProcessId)
 {
   MOZ_ASSERT(XRE_IsParentProcess());
   detail::MsaaIDCracker cracked(aID);
@@ -153,20 +150,20 @@ MsaaIdGenerator::IsSameContentProcessFor
 uint32_t
 MsaaIdGenerator::ResolveContentProcessID()
 {
   if (XRE_IsParentProcess()) {
     return 0;
   }
 
   dom::ContentChild* contentChild = dom::ContentChild::GetSingleton();
-  Unused << contentChild->SendGetA11yContentId(&mContentProcessID);
+  uint32_t result = contentChild->GetMsaaID();
 
-  MOZ_ASSERT(mContentProcessID);
-  return mContentProcessID;
+  MOZ_ASSERT(result);
+  return result;
 }
 
 /**
  * Each dom::ContentParent has a 64-bit ID. This ID is monotonically increasing
  * with each new content process, so those IDs are effectively single-use. OTOH,
  * MSAA requires 32-bit IDs. Since we only allocate kNumContentProcessIDBits for
  * the content process ID component, the MSAA content process ID value must be
  * reusable. sContentParentIdMap holds the current associations between
--- a/accessible/windows/msaa/MsaaIdGenerator.h
+++ b/accessible/windows/msaa/MsaaIdGenerator.h
@@ -43,15 +43,14 @@ public:
   uint32_t GetContentProcessIDFor(dom::ContentParentId aIPCContentProcessID);
   void ReleaseContentProcessIDFor(dom::ContentParentId aIPCContentProcessID);
 
 private:
   uint32_t ResolveContentProcessID();
 
 private:
   IDSet     mIDSet;
-  uint32_t  mContentProcessID;
 };
 
 } // namespace a11y
 } // namespace mozilla
 
 #endif // mozilla_a11y_MsaaIdGenerator_h
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -497,16 +497,19 @@ private:
 };
 
 NS_IMPL_ISUPPORTS(BackgroundChildPrimer, nsIIPCBackgroundChildCreateCallback)
 
 ContentChild* ContentChild::sSingleton;
 
 ContentChild::ContentChild()
  : mID(uint64_t(-1))
+#if defined(XP_WIN) && defined(ACCESSIBILITY)
+ , mMsaaID(0)
+#endif
  , mCanOverrideProcessName(true)
  , mIsAlive(true)
  , mShuttingDown(false)
 {
   // This process is a content process, so it's clearly running in
   // multiprocess mode!
   nsDebugImpl::SetMultiprocessMode("Child");
 }
@@ -2410,23 +2413,28 @@ ContentChild::RecvFlushMemory(const nsSt
     mozilla::services::GetObserverService();
   if (os) {
     os->NotifyObservers(nullptr, "memory-pressure", reason.get());
   }
   return true;
 }
 
 bool
-ContentChild::RecvActivateA11y()
+ContentChild::RecvActivateA11y(const uint32_t& aMsaaID)
 {
 #ifdef ACCESSIBILITY
+#ifdef XP_WIN
+  MOZ_ASSERT(aMsaaID != 0);
+  mMsaaID = aMsaaID;
+#endif // XP_WIN
+
   // Start accessibility in content process if it's running in chrome
   // process.
   GetOrCreateAccService(nsAccessibilityService::eMainProcess);
-#endif
+#endif // ACCESSIBILITY
   return true;
 }
 
 bool
 ContentChild::RecvShutdownA11y()
 {
 #ifdef ACCESSIBILITY
   // Try to shutdown accessibility in content process if it's shutting down in
--- a/dom/ipc/ContentChild.h
+++ b/dom/ipc/ContentChild.h
@@ -429,17 +429,17 @@ public:
   virtual bool RecvGeolocationError(const uint16_t& errorCode) override;
 
   virtual bool RecvUpdateDictionaryList(InfallibleTArray<nsString>&& aDictionaries) override;
 
   virtual bool RecvAddPermission(const IPC::Permission& permission) override;
 
   virtual bool RecvFlushMemory(const nsString& reason) override;
 
-  virtual bool RecvActivateA11y() override;
+  virtual bool RecvActivateA11y(const uint32_t& aMsaaID) override;
   virtual bool RecvShutdownA11y() override;
 
   virtual bool RecvGarbageCollect() override;
   virtual bool RecvCycleCollect() override;
 
   virtual bool RecvAppInfo(const nsCString& version, const nsCString& buildID,
                            const nsCString& name, const nsCString& UAName,
                            const nsCString& ID, const nsCString& vendor) override;
@@ -550,16 +550,20 @@ public:
                                               const IPC::Principal& aPrincipal) override;
 
   // Get the directory for IndexedDB files. We query the parent for this and
   // cache the value
   nsString &GetIndexedDBPath();
 
   ContentParentId GetID() const { return mID; }
 
+#if defined(XP_WIN) && defined(ACCESSIBILITY)
+  uint32_t GetMsaaID() const { return mMsaaID; }
+#endif
+
   bool IsForApp() const { return mIsForApp; }
   bool IsForBrowser() const { return mIsForBrowser; }
 
   virtual PBlobChild*
   SendPBlobConstructor(PBlobChild* actor,
                        const BlobConstructorParams& params) override;
 
   virtual PFileDescriptorSetChild*
@@ -670,16 +674,24 @@ private:
    * An ID unique to the process containing our corresponding
    * content parent.
    *
    * We expect our content parent to set this ID immediately after opening a
    * channel to us.
    */
   ContentParentId mID;
 
+#if defined(XP_WIN) && defined(ACCESSIBILITY)
+  /**
+   * This is an a11y-specific unique id for the content process that is
+   * generated by the chrome process.
+   */
+  uint32_t mMsaaID;
+#endif
+
   AppInfo mAppInfo;
 
   bool mIsForApp;
   bool mIsForBrowser;
   bool mCanOverrideProcessName;
   bool mIsAlive;
   nsString mProcessName;
 
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -1351,20 +1351,21 @@ ContentParent::Init()
   }
 
 #ifdef ACCESSIBILITY
   // If accessibility is running in chrome process then start it in content
   // process.
   if (nsIPresShell::IsAccessibilityActive()) {
 #if defined(XP_WIN)
     if (IsVistaOrLater()) {
-      Unused << SendActivateA11y();
+      Unused <<
+        SendActivateA11y(a11y::AccessibleWrap::GetContentProcessIdFor(ChildID()));
     }
 #else
-    Unused << SendActivateA11y();
+    Unused << SendActivateA11y(0);
 #endif
   }
 #endif
 
 #ifdef MOZ_ENABLE_PROFILER_SPS
   nsCOMPtr<nsIProfiler> profiler(do_GetService("@mozilla.org/tools/profiler;1"));
   bool profilerActive = false;
   DebugOnly<nsresult> rv = profiler->IsActive(&profilerActive);
@@ -2776,20 +2777,21 @@ ContentParent::Observe(nsISupports* aSub
 #endif
 #ifdef ACCESSIBILITY
   else if (aData && !strcmp(aTopic, "a11y-init-or-shutdown")) {
     if (*aData == '1') {
       // Make sure accessibility is running in content process when
       // accessibility gets initiated in chrome process.
 #if defined(XP_WIN)
       if (IsVistaOrLater()) {
-        Unused << SendActivateA11y();
+        Unused <<
+          SendActivateA11y(a11y::AccessibleWrap::GetContentProcessIdFor(ChildID()));
       }
 #else
-      Unused << SendActivateA11y();
+      Unused << SendActivateA11y(0);
 #endif
     } else {
       // If possible, shut down accessibility in content process when
       // accessibility gets shutdown in chrome process.
       Unused << SendShutdownA11y();
     }
   }
 #endif
@@ -5139,28 +5141,16 @@ ContentParent::RecvUnstoreAndBroadcastBl
   nsHostObjectProtocolHandler::RemoveDataEntry(aURI,
                                                false /* Don't broadcast */);
   BroadcastBlobURLUnregistration(aURI, this);
   mBlobURLs.RemoveElement(aURI);
 
   return true;
 }
 
-bool
-ContentParent::RecvGetA11yContentId(uint32_t* aContentId)
-{
-#if defined(XP_WIN32) && defined(ACCESSIBILITY)
-  *aContentId = a11y::AccessibleWrap::GetContentProcessIdFor(ChildID());
-  MOZ_ASSERT(*aContentId);
-  return true;
-#else
-  return false;
-#endif
-}
-
 } // namespace dom
 } // namespace mozilla
 
 NS_IMPL_ISUPPORTS(ParentIdleListener, nsIObserver)
 
 NS_IMETHODIMP
 ParentIdleListener::Observe(nsISupports*, const char* aTopic, const char16_t* aData)
 {
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -547,19 +547,16 @@ public:
   virtual bool
   RecvStoreAndBroadcastBlobURLRegistration(const nsCString& aURI,
                                            PBlobParent* aBlobParent,
                                            const Principal& aPrincipal) override;
 
   virtual bool
   RecvUnstoreAndBroadcastBlobURLUnregistration(const nsCString& aURI) override;
 
-  virtual bool
-  RecvGetA11yContentId(uint32_t* aContentId) override;
-
   virtual int32_t Pid() const override;
 
   // Use the PHangMonitor channel to ask the child to repaint a tab.
   void ForceTabPaint(TabParent* aTabParent, uint64_t aLayerObserverEpoch);
 
 protected:
   void OnChannelConnected(int32_t pid) override;
 
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -500,18 +500,21 @@ child:
 
     async FlushMemory(nsString reason);
 
     async GarbageCollect();
     async CycleCollect();
 
     /**
      * Start accessibility engine in content process.
+     * @param aMsaaID is an a11y-specific unique id for the content process
+     *                that is generated by the chrome process. Only used on
+     *                Windows; pass 0 on other platforms.
      */
-    async ActivateA11y();
+    async ActivateA11y(uint32_t aMsaaID);
 
     /**
      * Shutdown accessibility engine in content process (if not in use).
      */
     async ShutdownA11y();
 
     async AppInfo(nsCString version, nsCString buildID, nsCString name, nsCString UAName,
                   nsCString ID, nsCString vendor);
@@ -1170,18 +1173,16 @@ parent:
      async UnstoreAndBroadcastBlobURLUnregistration(nsCString url);
 
     /**
      * Messages for communicating child Telemetry to the parent process
      */
     async AccumulateChildHistogram(Accumulation[] accumulations);
     async AccumulateChildKeyedHistogram(KeyedAccumulation[] accumulations);
 
-     sync GetA11yContentId() returns (uint32_t aContentId);
-
 both:
      async AsyncMessage(nsString aMessage, CpowEntry[] aCpows,
                         Principal aPrincipal, ClonedMessageData aData);
 
     /**
      * Notify `push-subscription-modified` observers in the parent and child.
      */
     async NotifyPushSubscriptionModifiedObservers(nsCString scope,