Skip to content

Commit

Permalink
Bug 1756728 part 1: Make it possible to retrieve a BrowsingContext fr…
Browse files Browse the repository at this point in the history
…om a DocAccessibleParent. r=morgan

Previously, even for remote in-process iframes, it was only possible to retrieve the top level BrowsingContext for the remote process by getting the managing BrowserParent.
This makes it possible to get the correct BrowsingContext even for in-process iframes.

Differential Revision: https://phabricator.services.mozilla.com/D147716
  • Loading branch information
jcsteh committed Jun 1, 2022
1 parent c89a938 commit 4d3f66b
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 45 deletions.
4 changes: 3 additions & 1 deletion accessible/base/NotificationController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,9 @@ void NotificationController::WillRefresh(mozilla::TimeStamp aTime) {
do_GetInterface(mDocument->DocumentNode()->GetDocShell());
if (browserChild) {
static_cast<BrowserChild*>(browserChild.get())
->SendPDocAccessibleConstructor(ipcDoc, parentIPCDoc, id, 0, 0);
->SendPDocAccessibleConstructor(
ipcDoc, parentIPCDoc, id,
childDoc->DocumentNode()->GetBrowsingContext(), 0, 0);
ipcDoc->SendPDocAccessiblePlatformExtConstructor();
}
#endif
Expand Down
5 changes: 3 additions & 2 deletions accessible/generic/DocAccessible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1549,8 +1549,9 @@ void DocAccessible::DoInitialUpdate() {
#else
int32_t holder = 0, childID = 0;
#endif
browserChild->SendPDocAccessibleConstructor(ipcDoc, nullptr, 0,
childID, holder);
browserChild->SendPDocAccessibleConstructor(
ipcDoc, nullptr, 0, mDocumentNode->GetBrowsingContext(), childID,
holder);
#if !defined(XP_WIN)
ipcDoc->SendPDocAccessiblePlatformExtConstructor();
#endif
Expand Down
31 changes: 31 additions & 0 deletions accessible/ipc/DocAccessibleParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "mozilla/a11y/Platform.h"
#include "mozilla/dom/BrowserBridgeParent.h"
#include "mozilla/dom/BrowserParent.h"
#include "mozilla/dom/CanonicalBrowsingContext.h"
#include "mozilla/StaticPrefs_accessibility.h"
#include "xpcAccessibleDocument.h"
#include "xpcAccEvents.h"
Expand Down Expand Up @@ -53,6 +54,36 @@ struct VTableSizer<IAccessible> {
namespace a11y {
uint64_t DocAccessibleParent::sMaxDocID = 0;

DocAccessibleParent::DocAccessibleParent()
: RemoteAccessible(this),
mParentDoc(kNoParentDoc),
#if defined(XP_WIN)
mEmulatedWindowHandle(nullptr),
#endif // defined(XP_WIN)
mTopLevel(false),
mTopLevelInContentProcess(false),
mShutdown(false),
mFocus(0),
mCaretId(0),
mCaretOffset(-1),
mIsCaretAtEndOfLine(false) {
sMaxDocID++;
mActorID = sMaxDocID;
MOZ_ASSERT(!LiveDocs().Get(mActorID));
LiveDocs().InsertOrUpdate(mActorID, this);
}

DocAccessibleParent::~DocAccessibleParent() {
LiveDocs().Remove(mActorID);
MOZ_ASSERT(mChildDocs.Length() == 0);
MOZ_ASSERT(!ParentDoc());
}

void DocAccessibleParent::SetBrowsingContext(
dom::CanonicalBrowsingContext* aBrowsingContext) {
mBrowsingContext = aBrowsingContext;
}

mozilla::ipc::IPCResult DocAccessibleParent::RecvShowEvent(
const ShowEventData& aData, const bool& aFromUser) {
ACQUIRE_ANDROID_LOCK
Expand Down
36 changes: 13 additions & 23 deletions accessible/ipc/DocAccessibleParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include "nsISupportsImpl.h"

namespace mozilla {
namespace dom {
class CanonicalBrowsingContext;
}

namespace a11y {

class TextRange;
Expand All @@ -34,24 +38,7 @@ class DocAccessibleParent : public RemoteAccessible,
public:
NS_INLINE_DECL_REFCOUNTING(DocAccessibleParent);

DocAccessibleParent()
: RemoteAccessible(this),
mParentDoc(kNoParentDoc),
#if defined(XP_WIN)
mEmulatedWindowHandle(nullptr),
#endif // defined(XP_WIN)
mTopLevel(false),
mTopLevelInContentProcess(false),
mShutdown(false),
mFocus(0),
mCaretId(0),
mCaretOffset(-1),
mIsCaretAtEndOfLine(false) {
sMaxDocID++;
mActorID = sMaxDocID;
MOZ_ASSERT(!LiveDocs().Get(mActorID));
LiveDocs().InsertOrUpdate(mActorID, this);
}
DocAccessibleParent();

/**
* Set this as a top level document; i.e. it is not embedded by another remote
Expand Down Expand Up @@ -87,6 +74,12 @@ class DocAccessibleParent : public RemoteAccessible,
mShutdown = true;
}

void SetBrowsingContext(dom::CanonicalBrowsingContext* aBrowsingContext);

dom::CanonicalBrowsingContext* GetBrowsingContext() const {
return mBrowsingContext;
}

/*
* Called when a message from a document in a child process notifies the main
* process it is firing an event.
Expand Down Expand Up @@ -324,11 +317,7 @@ class DocAccessibleParent : public RemoteAccessible,
virtual void SelectionRanges(nsTArray<TextRange>* aRanges) const override;

private:
~DocAccessibleParent() {
LiveDocs().Remove(mActorID);
MOZ_ASSERT(mChildDocs.Length() == 0);
MOZ_ASSERT(!ParentDoc());
}
~DocAccessibleParent();

class ProxyEntry : public PLDHashEntryHdr {
public:
Expand Down Expand Up @@ -392,6 +381,7 @@ class DocAccessibleParent : public RemoteAccessible,
bool mTopLevel;
bool mTopLevelInContentProcess;
bool mShutdown;
RefPtr<dom::CanonicalBrowsingContext> mBrowsingContext;

nsTHashSet<RefPtr<dom::BrowserBridgeParent>> mPendingOOPChildDocs;

Expand Down
8 changes: 6 additions & 2 deletions accessible/ipc/win/DocAccessibleChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "LocalAccessible-inl.h"
#include "mozilla/a11y/PlatformChild.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/dom/Document.h"
#include "mozilla/StaticPrefs_accessibility.h"
#include "RootAccessible.h"

Expand Down Expand Up @@ -287,15 +288,18 @@ bool DocAccessibleChild::ConstructChildDocInParentProcess(
auto browserChild = static_cast<dom::BrowserChild*>(Manager());
MOZ_ASSERT(browserChild);
bool result = browserChild->SendPDocAccessibleConstructor(
aNewChildDoc, this, aUniqueID, aMsaaID, IAccessibleHolder());
aNewChildDoc, this, aUniqueID,
aNewChildDoc->mDoc->DocumentNode()->GetBrowsingContext(), aMsaaID,
IAccessibleHolder());
if (result) {
aNewChildDoc->SetConstructedInParentProcess();
}
return result;
}

PushDeferredEvent(MakeUnique<SerializedChildDocConstructor>(
aNewChildDoc, this, aUniqueID, aMsaaID));
aNewChildDoc, this, aUniqueID,
aNewChildDoc->mDoc->DocumentNode()->GetBrowsingContext(), aMsaaID));
return true;
}

Expand Down
13 changes: 11 additions & 2 deletions accessible/ipc/win/DocAccessibleChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include "mozilla/mscom/Ptr.h"

namespace mozilla {
namespace dom {
class BrowsingContext;
}

namespace a11y {

/*
Expand Down Expand Up @@ -309,23 +313,28 @@ class DocAccessibleChild : public DocAccessibleChildBase {
struct SerializedChildDocConstructor final : public DeferredEvent {
SerializedChildDocConstructor(DocAccessibleChild* aIPCDoc,
DocAccessibleChild* aParentIPCDoc,
uint64_t aUniqueID, uint32_t aMsaaID)
uint64_t aUniqueID,
dom::BrowsingContext* aBrowsingContext,
uint32_t aMsaaID)
: DeferredEvent(aParentIPCDoc),
mIPCDoc(aIPCDoc),
mUniqueID(aUniqueID),
mBrowsingContext(aBrowsingContext),
mMsaaID(aMsaaID) {}

void Dispatch(DocAccessibleChild* aParentIPCDoc) override {
auto browserChild =
static_cast<dom::BrowserChild*>(aParentIPCDoc->Manager());
MOZ_ASSERT(browserChild);
Unused << browserChild->SendPDocAccessibleConstructor(
mIPCDoc, aParentIPCDoc, mUniqueID, mMsaaID, IAccessibleHolder());
mIPCDoc, aParentIPCDoc, mUniqueID, mBrowsingContext, mMsaaID,
IAccessibleHolder());
mIPCDoc->SetConstructedInParentProcess();
}

DocAccessibleChild* mIPCDoc;
uint64_t mUniqueID;
dom::BrowsingContext* mBrowsingContext;
uint32_t mMsaaID;
};

Expand Down
4 changes: 2 additions & 2 deletions dom/ipc/BrowserChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2234,8 +2234,8 @@ mozilla::ipc::IPCResult BrowserChild::RecvPasteTransferable(

#ifdef ACCESSIBILITY
a11y::PDocAccessibleChild* BrowserChild::AllocPDocAccessibleChild(
PDocAccessibleChild*, const uint64_t&, const uint32_t&,
const IAccessibleHolder&) {
PDocAccessibleChild*, const uint64_t&, const MaybeDiscardedBrowsingContext&,
const uint32_t&, const IAccessibleHolder&) {
MOZ_ASSERT(false, "should never call this!");
return nullptr;
}
Expand Down
8 changes: 4 additions & 4 deletions dom/ipc/BrowserChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,10 @@ class BrowserChild final : public nsMessageManagerScriptExecutor,
const mozilla::ScreenIntMargin& aSafeAreaInsets);

#ifdef ACCESSIBILITY
PDocAccessibleChild* AllocPDocAccessibleChild(PDocAccessibleChild*,
const uint64_t&,
const uint32_t&,
const IAccessibleHolder&);
PDocAccessibleChild* AllocPDocAccessibleChild(
PDocAccessibleChild*, const uint64_t&,
const MaybeDiscardedBrowsingContext&, const uint32_t&,
const IAccessibleHolder&);
bool DeallocPDocAccessibleChild(PDocAccessibleChild*);
#endif

Expand Down
12 changes: 9 additions & 3 deletions dom/ipc/BrowserParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,8 @@ void BrowserParent::Deactivate(bool aWindowLowering, uint64_t aActionId) {

#ifdef ACCESSIBILITY
a11y::PDocAccessibleParent* BrowserParent::AllocPDocAccessibleParent(
PDocAccessibleParent* aParent, const uint64_t&, const uint32_t&,
PDocAccessibleParent* aParent, const uint64_t&,
const MaybeDiscardedBrowsingContext&, const uint32_t&,
const IAccessibleHolder&) {
// Reference freed in DeallocPDocAccessibleParent.
return do_AddRef(new a11y::DocAccessibleParent()).take();
Expand All @@ -1219,8 +1220,9 @@ bool BrowserParent::DeallocPDocAccessibleParent(PDocAccessibleParent* aParent) {

mozilla::ipc::IPCResult BrowserParent::RecvPDocAccessibleConstructor(
PDocAccessibleParent* aDoc, PDocAccessibleParent* aParentDoc,
const uint64_t& aParentID, const uint32_t& aMsaaID,
const IAccessibleHolder& aDocCOMProxy) {
const uint64_t& aParentID,
const MaybeDiscardedBrowsingContext& aBrowsingContext,
const uint32_t& aMsaaID, const IAccessibleHolder& aDocCOMProxy) {
# if defined(ANDROID)
MonitorAutoLock mal(nsAccessibilityService::GetAndroidMonitor());
# endif
Expand All @@ -1233,6 +1235,10 @@ mozilla::ipc::IPCResult BrowserParent::RecvPDocAccessibleConstructor(
return IPC_OK();
}

if (aBrowsingContext) {
doc->SetBrowsingContext(aBrowsingContext.get_canonical());
}

if (aParentDoc) {
// Iframe document rendered in the same process as its embedder.
// A document should never directly be the parent of another document.
Expand Down
13 changes: 7 additions & 6 deletions dom/ipc/BrowserParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,15 +432,16 @@ class BrowserParent final : public PBrowserParent,
bool DeallocPVsyncParent(PVsyncParent* aActor);

#ifdef ACCESSIBILITY
PDocAccessibleParent* AllocPDocAccessibleParent(PDocAccessibleParent*,
const uint64_t&,
const uint32_t&,
const IAccessibleHolder&);
PDocAccessibleParent* AllocPDocAccessibleParent(
PDocAccessibleParent*, const uint64_t&,
const MaybeDiscardedBrowsingContext&, const uint32_t&,
const IAccessibleHolder&);
bool DeallocPDocAccessibleParent(PDocAccessibleParent*);
virtual mozilla::ipc::IPCResult RecvPDocAccessibleConstructor(
PDocAccessibleParent* aDoc, PDocAccessibleParent* aParentDoc,
const uint64_t& aParentID, const uint32_t& aMsaaID,
const IAccessibleHolder& aDocCOMProxy) override;
const uint64_t& aParentID,
const MaybeDiscardedBrowsingContext& aBrowsingContext,
const uint32_t& aMsaaID, const IAccessibleHolder& aDocCOMProxy) override;
#endif

already_AddRefed<PSessionStoreParent> AllocPSessionStoreParent();
Expand Down
1 change: 1 addition & 0 deletions dom/ipc/PBrowser.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ parent:
* is also Windows-specific and should be set to 0 on other platforms.
*/
async PDocAccessible(nullable PDocAccessible aParentDoc, uint64_t aParentAcc,
MaybeDiscardedBrowsingContext aBrowsingContext,
uint32_t aMsaaID, IAccessibleHolder aDocCOMProxy);
#endif

Expand Down

0 comments on commit 4d3f66b

Please sign in to comment.