Skip to content

Commit

Permalink
Bug 1743439 - Part 4: Mark callers in layout as MOZ_CAN_RUN_SCRIPT_BO…
Browse files Browse the repository at this point in the history
…UNDARY r=masayuki

Differential Revision: https://phabricator.services.mozilla.com/D133363
  • Loading branch information
saschanaz committed Dec 9, 2021
1 parent d5bdee4 commit 459cd4e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
12 changes: 8 additions & 4 deletions layout/base/nsDocumentViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,15 +1281,17 @@ nsDocumentViewer::PermitUnload(PermitUnloadAction aAction,
return NS_OK;
}

PermitUnloadResult nsDocumentViewer::DispatchBeforeUnload() {
MOZ_CAN_RUN_SCRIPT_BOUNDARY PermitUnloadResult
nsDocumentViewer::DispatchBeforeUnload() {
AutoDontWarnAboutSyncXHR disableSyncXHRWarning;

if (!mDocument || mInPermitUnload || mInPermitUnloadPrompt) {
return eAllowNavigation;
}

// First, get the script global object from the document...
auto* window = nsGlobalWindowOuter::Cast(mDocument->GetWindow());
RefPtr<nsGlobalWindowOuter> window =
nsGlobalWindowOuter::Cast(mDocument->GetWindow());
if (!window) {
// This is odd, but not fatal
NS_WARNING("window not set for document!");
Expand Down Expand Up @@ -1334,8 +1336,10 @@ PermitUnloadResult nsDocumentViewer::DispatchBeforeUnload() {
Document::PageUnloadingEventTimeStamp timestamp(mDocument);

mInPermitUnload = true;
EventDispatcher::DispatchDOMEvent(ToSupports(window), nullptr, event,
mPresContext, nullptr);
RefPtr<nsPresContext> presContext = mPresContext;
// TODO: Bug 1506441
EventDispatcher::DispatchDOMEvent(MOZ_KnownLive(ToSupports(window)),
nullptr, event, presContext, nullptr);
mInPermitUnload = false;
}

Expand Down
6 changes: 4 additions & 2 deletions layout/base/nsPresContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -934,8 +934,10 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
TransactionId aTransactionId = TransactionId{0},
const mozilla::TimeStamp& aTimeStamp = mozilla::TimeStamp());
void NotifyRevokingDidPaint(TransactionId aTransactionId);
void FireDOMPaintEvent(nsTArray<nsRect>* aList, TransactionId aTransactionId,
mozilla::TimeStamp aTimeStamp = mozilla::TimeStamp());
// TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
MOZ_CAN_RUN_SCRIPT_BOUNDARY void FireDOMPaintEvent(
nsTArray<nsRect>* aList, TransactionId aTransactionId,
mozilla::TimeStamp aTimeStamp = mozilla::TimeStamp());

bool IsDOMPaintEventPending();

Expand Down
7 changes: 4 additions & 3 deletions layout/xul/nsMenuFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class nsMenuActivateEvent : public Runnable {
mPresContext(aPresContext),
mIsActivate(aIsActivate) {}

NS_IMETHOD Run() override {
// TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230, bug 1535398)
MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD Run() override {
nsAutoString domEventToFire;

if (mIsActivate) {
Expand Down Expand Up @@ -99,8 +100,8 @@ class nsMenuActivateEvent : public Runnable {
}

private:
RefPtr<Element> mMenu;
RefPtr<nsPresContext> mPresContext;
const RefPtr<Element> mMenu;
const RefPtr<nsPresContext> mPresContext;
bool mIsActivate;
};

Expand Down

0 comments on commit 459cd4e

Please sign in to comment.