From 9dd61a8f4ce901b93256f213e537ce0403127332 Mon Sep 17 00:00:00 2001 From: Andrew Sutherland Date: Tue, 31 Jan 2017 03:42:38 -0500 Subject: [PATCH] Bug 1285898 - [e10s-multi] fixup PContent ordering via immediate event dispatch. r=baku --- dom/ipc/ContentChild.cpp | 2 +- dom/storage/Storage.cpp | 12 +++++++++--- dom/storage/Storage.h | 10 +++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index d165b6b5e43c..2134466e8d79 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -3046,7 +3046,7 @@ ContentChild::RecvDispatchLocalStorageChange(const nsString& aDocumentURI, { Storage::DispatchStorageEvent(Storage::LocalStorage, aDocumentURI, aKey, aOldValue, aNewValue, - aPrincipal, aIsPrivate, nullptr); + aPrincipal, aIsPrivate, nullptr, true); return IPC_OK(); } diff --git a/dom/storage/Storage.cpp b/dom/storage/Storage.cpp index 47c4f8bbd981..cbd62cda01ad 100644 --- a/dom/storage/Storage.cpp +++ b/dom/storage/Storage.cpp @@ -231,7 +231,7 @@ Storage::BroadcastChangeNotification(const nsSubstring& aKey, } DispatchStorageEvent(GetType(), mDocumentURI, aKey, aOldValue, aNewValue, - mPrincipal, mIsPrivate, this); + mPrincipal, mIsPrivate, this, false); } /* static */ void @@ -242,7 +242,8 @@ Storage::DispatchStorageEvent(StorageType aStorageType, const nsAString& aNewValue, nsIPrincipal* aPrincipal, bool aIsPrivate, - Storage* aStorage) + Storage* aStorage, + bool aImmediateDispatch) { StorageEventInit dict; dict.mBubbles = false; @@ -266,7 +267,12 @@ Storage::DispatchStorageEvent(StorageType aStorageType, ? u"localStorage" : u"sessionStorage", aIsPrivate); - NS_DispatchToMainThread(r); + + if (aImmediateDispatch) { + Unused << r->Run(); + } else { + NS_DispatchToMainThread(r); + } // If we are in the parent process and we have the principal, we want to // broadcast this event to every other process. diff --git a/dom/storage/Storage.h b/dom/storage/Storage.h index 62361f669ee3..462c9b9877dd 100644 --- a/dom/storage/Storage.h +++ b/dom/storage/Storage.h @@ -131,6 +131,13 @@ public: } // aStorage can be null if this method is called by ContentChild. + // + // aImmediateDispatch is for use by (main-thread) IPC code so that PContent + // ordering can be maintained. Without this, the event would be enqueued and + // run in a future turn of the event loop, potentially allowing other PContent + // Recv* methods to trigger script that wants to assume our localstorage + // changes have already been applied. This is the case for message manager + // messages which are used by ContentTask testing logic and webextensions. static void DispatchStorageEvent(StorageType aStorageType, const nsAString& aDocumentURI, @@ -139,7 +146,8 @@ public: const nsAString& aNewValue, nsIPrincipal* aPrincipal, bool aIsPrivate, - Storage* aStorage); + Storage* aStorage, + bool aImmediateDispatch); void ApplyEvent(StorageEvent* aStorageEvent);