author | Simon Giesecke <sgiesecke@mozilla.com> |
Mon, 23 Nov 2020 16:07:01 +0000 | |
changeset 558369 | d55236e0b03ce5d6e7119c8d81bc244490c64c53 |
parent 558368 | c15be3f697413364c3c3078388b494f891002495 |
child 558370 | de2efe85ed497d61254ee567e3c4d64f3bc16973 |
push id | 131543 |
push user | malexandru@mozilla.com |
push date | Mon, 23 Nov 2020 17:03:38 +0000 |
treeherder | autoland@49f2070cdd63 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
bugs | 1673424 |
milestone | 85.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/dom/base/ContentProcessMessageManager.h +++ b/dom/base/ContentProcessMessageManager.h @@ -4,25 +4,27 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef mozilla_dom_ContentProcessMessageManager_h #define mozilla_dom_ContentProcessMessageManager_h #include "mozilla/Attributes.h" #include "mozilla/dom/MessageManagerGlobal.h" +#include "mozilla/dom/MessageManagerCallback.h" #include "nsCOMPtr.h" -#include "nsFrameMessageManager.h" #include "nsIScriptContext.h" #include "nsIScriptContext.h" #include "nsServiceManagerUtils.h" #include "nsWeakReference.h" #include "nsWrapperCache.h" #include "xpcpublic.h" +class nsFrameMessageManager; + namespace mozilla { namespace dom { namespace ipc { class SharedMap; } /**
--- a/dom/base/InProcessBrowserChildMessageManager.h +++ b/dom/base/InProcessBrowserChildMessageManager.h @@ -6,25 +6,27 @@ #ifndef nsInProcessBrowserChildGlobal_h #define nsInProcessBrowserChildGlobal_h #include "mozilla/Attributes.h" #include "mozilla/DOMEventTargetHelper.h" #include "mozilla/RefPtr.h" #include "mozilla/dom/ContentFrameMessageManager.h" +#include "mozilla/dom/MessageManagerCallback.h" #include "nsCOMPtr.h" -#include "nsFrameMessageManager.h" #include "nsIScriptContext.h" #include "nsIScriptObjectPrincipal.h" #include "nsIScriptContext.h" #include "nsDocShell.h" #include "nsCOMArray.h" #include "nsWeakReference.h" +class nsFrameMessageManager; + namespace mozilla { class EventChainPreVisitor; namespace dom { /** * This class implements a ContentFrameMessageManager for use by frame loaders * in the parent process. It is bound to a DocShell rather than a BrowserChild,
copy from dom/base/nsFrameMessageManager.h copy to dom/base/MessageManagerCallback.h --- a/dom/base/nsFrameMessageManager.h +++ b/dom/base/MessageManagerCallback.h @@ -1,83 +1,28 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef nsFrameMessageManager_h__ -#define nsFrameMessageManager_h__ +#ifndef dom_base_MessageManagerCallback_h__ +#define dom_base_MessageManagerCallback_h__ -#include "nsIMessageManager.h" -#include "nsIObserver.h" -#include "nsCOMPtr.h" -#include "nsCOMArray.h" -#include "nsTArray.h" -#include "nsAtom.h" -#include "nsCycleCollectionParticipant.h" -#include "nsTArray.h" -#include "nsIPrincipal.h" -#include "nsDataHashtable.h" -#include "nsClassHashtable.h" -#include "mozilla/Services.h" -#include "mozilla/StaticPtr.h" -#include "nsIObserverService.h" -#include "nsThreadUtils.h" -#include "nsIWeakReferenceUtils.h" -#include "mozilla/Attributes.h" -#include "js/RootingAPI.h" -#include "nsTObserverArray.h" -#include "mozilla/TypedEnumBits.h" -#include "mozilla/UniquePtr.h" -#include "mozilla/dom/CallbackObject.h" -#include "mozilla/dom/SameProcessMessageQueue.h" -#include "mozilla/dom/ipc/StructuredCloneData.h" - -class nsFrameLoader; +#include "nsStringFwd.h" +#include "nsTArrayForwardDeclare.h" namespace mozilla { - -namespace ipc { -class FileDescriptor; -} - namespace dom { -class ContentParent; -class ContentChild; -class ChildProcessMessageManager; -class ChromeMessageBroadcaster; -class ClonedMessageData; -class MessageBroadcaster; -class MessageListener; -class MessageListenerManager; -class MessageManagerReporter; -template <typename T> -class Optional; -class ParentProcessMessageManager; class ProcessMessageManager; namespace ipc { -class WritableSharedMap; - -// Note: we round the time we spend to the nearest millisecond. So a min value -// of 1 ms actually captures from 500us and above. -static const uint32_t kMinTelemetrySyncMessageManagerLatencyMs = 1; - -enum class MessageManagerFlags { - MM_NONE = 0, - MM_CHROME = 1, - MM_GLOBAL = 2, - MM_PROCESSMANAGER = 4, - MM_BROADCASTER = 8, - MM_OWNSCALLBACK = 16 -}; -MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(MessageManagerFlags); +class StructuredCloneData; class MessageManagerCallback { public: virtual ~MessageManagerCallback() = default; virtual bool DoLoadMessageManagerScript(const nsAString& aURL, bool aRunInGlobalScope) { return true; @@ -116,303 +61,9 @@ void UnpackClonedMessageDataForParent(co void UnpackClonedMessageDataForChild(const ClonedMessageData& aClonedData, StructuredCloneData& aData); } // namespace ipc } // namespace dom } // namespace mozilla -struct nsMessageListenerInfo { - bool operator==(const nsMessageListenerInfo& aOther) const { - return &aOther == this; - } - - // If mWeakListener is null then mStrongListener holds a MessageListener. - // If mWeakListener is non-null then mStrongListener contains null. - RefPtr<mozilla::dom::MessageListener> mStrongListener; - nsWeakPtr mWeakListener; - bool mListenWhenClosed; -}; - -class nsFrameMessageManager : public nsIMessageSender { - friend class mozilla::dom::MessageManagerReporter; - typedef mozilla::dom::ipc::StructuredCloneData StructuredCloneData; - - protected: - typedef mozilla::dom::ipc::MessageManagerFlags MessageManagerFlags; - - nsFrameMessageManager(mozilla::dom::ipc::MessageManagerCallback* aCallback, - MessageManagerFlags aFlags); - - virtual ~nsFrameMessageManager(); - - public: - explicit nsFrameMessageManager( - mozilla::dom::ipc::MessageManagerCallback* aCallback) - : nsFrameMessageManager(aCallback, MessageManagerFlags::MM_NONE) {} - - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsFrameMessageManager) - - void MarkForCC(); - - // MessageListenerManager - void AddMessageListener(const nsAString& aMessageName, - mozilla::dom::MessageListener& aListener, - bool aListenWhenClosed, mozilla::ErrorResult& aError); - void RemoveMessageListener(const nsAString& aMessageName, - mozilla::dom::MessageListener& aListener, - mozilla::ErrorResult& aError); - void AddWeakMessageListener(const nsAString& aMessageName, - mozilla::dom::MessageListener& aListener, - mozilla::ErrorResult& aError); - void RemoveWeakMessageListener(const nsAString& aMessageName, - mozilla::dom::MessageListener& aListener, - mozilla::ErrorResult& aError); - - // MessageSender - void SendAsyncMessage(JSContext* aCx, const nsAString& aMessageName, - JS::Handle<JS::Value> aObj, - JS::Handle<JS::Value> aTransfers, - mozilla::ErrorResult& aError) { - DispatchAsyncMessage(aCx, aMessageName, aObj, aTransfers, aError); - } - already_AddRefed<mozilla::dom::ProcessMessageManager> - GetProcessMessageManager(mozilla::ErrorResult& aError); - void GetRemoteType(nsACString& aRemoteType, - mozilla::ErrorResult& aError) const; - - // SyncMessageSender - void SendSyncMessage(JSContext* aCx, const nsAString& aMessageName, - JS::Handle<JS::Value> aObj, nsTArray<JS::Value>& aResult, - mozilla::ErrorResult& aError); - - // GlobalProcessScriptLoader - void GetInitialProcessData(JSContext* aCx, - JS::MutableHandle<JS::Value> aInitialProcessData, - mozilla::ErrorResult& aError); - - mozilla::dom::ipc::WritableSharedMap* SharedData(); - - NS_DECL_NSIMESSAGESENDER - - static mozilla::dom::ProcessMessageManager* NewProcessMessageManager( - bool aIsRemote); - - void ReceiveMessage(nsISupports* aTarget, nsFrameLoader* aTargetFrameLoader, - const nsAString& aMessage, bool aIsSync, - StructuredCloneData* aCloneData, - nsTArray<StructuredCloneData>* aRetVal, - mozilla::ErrorResult& aError) { - ReceiveMessage(aTarget, aTargetFrameLoader, mClosed, aMessage, aIsSync, - aCloneData, aRetVal, aError); - } - - void Disconnect(bool aRemoveFromParent = true); - void Close(); - - void SetCallback(mozilla::dom::ipc::MessageManagerCallback* aCallback); - - mozilla::dom::ipc::MessageManagerCallback* GetCallback() { return mCallback; } - - nsresult DispatchAsyncMessageInternal(JSContext* aCx, - const nsAString& aMessage, - StructuredCloneData& aData); - bool IsGlobal() { return mGlobal; } - bool IsBroadcaster() { return mIsBroadcaster; } - bool IsChrome() { return mChrome; } - - // GetGlobalMessageManager creates the global message manager if it hasn't - // been yet. - static already_AddRefed<mozilla::dom::ChromeMessageBroadcaster> - GetGlobalMessageManager(); - static mozilla::dom::ParentProcessMessageManager* GetParentProcessManager() { - return sParentProcessManager; - } - static mozilla::dom::ChildProcessMessageManager* GetChildProcessManager() { - return sChildProcessManager; - } - static void SetChildProcessManager( - mozilla::dom::ChildProcessMessageManager* aManager) { - sChildProcessManager = aManager; - } - - static bool GetParamsForMessage(JSContext* aCx, const JS::Value& aValue, - const JS::Value& aTransfer, - StructuredCloneData& aData); - - void SetInitialProcessData(JS::HandleValue aInitialData); - - void LoadPendingScripts(); - - protected: - friend class MMListenerRemover; - - virtual mozilla::dom::MessageBroadcaster* GetParentManager() { - return nullptr; - } - virtual void ClearParentManager(bool aRemove) {} - - void DispatchAsyncMessage(JSContext* aCx, const nsAString& aMessageName, - JS::Handle<JS::Value> aObj, - JS::Handle<JS::Value> aTransfers, - mozilla::ErrorResult& aError); - - void ReceiveMessage(nsISupports* aTarget, nsFrameLoader* aTargetFrameLoader, - bool aTargetClosed, const nsAString& aMessage, - bool aIsSync, StructuredCloneData* aCloneData, - nsTArray<StructuredCloneData>* aRetVal, - mozilla::ErrorResult& aError); - - void LoadScript(const nsAString& aURL, bool aAllowDelayedLoad, - bool aRunInGlobalScope, mozilla::ErrorResult& aError); - void RemoveDelayedScript(const nsAString& aURL); - void GetDelayedScripts(JSContext* aCx, nsTArray<nsTArray<JS::Value>>& aList, - mozilla::ErrorResult& aError); - - // We keep the message listeners as arrays in a hastable indexed by the - // message name. That gives us fast lookups in ReceiveMessage(). - nsClassHashtable<nsStringHashKey, - nsAutoTObserverArray<nsMessageListenerInfo, 1>> - mListeners; - nsTArray<RefPtr<mozilla::dom::MessageListenerManager>> mChildManagers; - bool mChrome; // true if we're in the chrome process - bool mGlobal; // true if we're the global frame message manager - bool mIsProcessManager; // true if the message manager belongs to the process - // realm - bool mIsBroadcaster; // true if the message manager is a broadcaster - bool mOwnsCallback; - bool mHandlingMessage; - bool mClosed; // true if we can no longer send messages - bool mDisconnected; - mozilla::dom::ipc::MessageManagerCallback* mCallback; - mozilla::UniquePtr<mozilla::dom::ipc::MessageManagerCallback> mOwnedCallback; - nsTArray<nsString> mPendingScripts; - nsTArray<bool> mPendingScriptsGlobalStates; - JS::Heap<JS::Value> mInitialProcessData; - RefPtr<mozilla::dom::ipc::WritableSharedMap> mSharedData; - - void LoadPendingScripts(nsFrameMessageManager* aManager, - nsFrameMessageManager* aChildMM); - - public: - static mozilla::dom::ParentProcessMessageManager* sParentProcessManager; - static nsFrameMessageManager* sSameProcessParentManager; - static nsTArray<nsCOMPtr<nsIRunnable>>* sPendingSameProcessAsyncMessages; - - private: - static mozilla::dom::ChildProcessMessageManager* sChildProcessManager; -}; - -/* A helper class for taking care of many details for async message sending - within a single process. Intended to be used like so: - - class MyAsyncMessage : public nsSameProcessAsyncMessageBase, public Runnable - { - NS_IMETHOD Run() { - ReceiveMessage(..., ...); - return NS_OK; - } - }; - - - RefPtr<nsSameProcessAsyncMessageBase> ev = new MyAsyncMessage(); - nsresult rv = ev->Init(...); - if (NS_SUCCEEDED(rv)) { - NS_DispatchToMainThread(ev); - } -*/ -class nsSameProcessAsyncMessageBase { - public: - typedef mozilla::dom::ipc::StructuredCloneData StructuredCloneData; - - nsSameProcessAsyncMessageBase(); - nsresult Init(const nsAString& aMessage, StructuredCloneData& aData); - - void ReceiveMessage(nsISupports* aTarget, nsFrameLoader* aTargetFrameLoader, - nsFrameMessageManager* aManager); - - private: - nsSameProcessAsyncMessageBase(const nsSameProcessAsyncMessageBase&); - - nsString mMessage; - StructuredCloneData mData; -#ifdef DEBUG - bool mCalledInit; #endif -}; - -class nsScriptCacheCleaner; - -struct nsMessageManagerScriptHolder { - nsMessageManagerScriptHolder(JSContext* aCx, JSScript* aScript) - : mScript(aCx, aScript) { - MOZ_COUNT_CTOR(nsMessageManagerScriptHolder); - } - - MOZ_COUNTED_DTOR(nsMessageManagerScriptHolder) - - JS::PersistentRooted<JSScript*> mScript; -}; - -class nsMessageManagerScriptExecutor { - public: - static void PurgeCache(); - static void Shutdown(); - - void MarkScopesForCC(); - - protected: - friend class nsMessageManagerScriptCx; - nsMessageManagerScriptExecutor() { - MOZ_COUNT_CTOR(nsMessageManagerScriptExecutor); - } - MOZ_COUNTED_DTOR(nsMessageManagerScriptExecutor) - - void DidCreateScriptLoader(); - void LoadScriptInternal(JS::Handle<JSObject*> aMessageManager, - const nsAString& aURL, bool aRunInUniqueScope); - void TryCacheLoadAndCompileScript(const nsAString& aURL, - bool aRunInUniqueScope, bool aShouldCache, - JS::Handle<JSObject*> aMessageManager, - JS::MutableHandle<JSScript*> aScriptp); - bool Init(); - void Trace(const TraceCallbacks& aCallbacks, void* aClosure); - void Unlink(); - AutoTArray<JS::Heap<JSObject*>, 2> mAnonymousGlobalScopes; - - // Returns true if this is a process message manager. There should only be a - // single process message manager per session, so instances of this type will - // optimize their script loading to avoid unnecessary duplication. - virtual bool IsProcessScoped() const { return false; } - - static nsDataHashtable<nsStringHashKey, nsMessageManagerScriptHolder*>* - sCachedScripts; - static mozilla::StaticRefPtr<nsScriptCacheCleaner> sScriptCacheCleaner; -}; - -class nsScriptCacheCleaner final : public nsIObserver { - ~nsScriptCacheCleaner() = default; - - NS_DECL_ISUPPORTS - - nsScriptCacheCleaner() { - nsCOMPtr<nsIObserverService> obsSvc = - mozilla::services::GetObserverService(); - if (obsSvc) { - obsSvc->AddObserver(this, "message-manager-flush-caches", false); - obsSvc->AddObserver(this, "xpcom-shutdown", false); - } - } - - NS_IMETHOD Observe(nsISupports* aSubject, const char* aTopic, - const char16_t* aData) override { - if (strcmp("message-manager-flush-caches", aTopic) == 0) { - nsMessageManagerScriptExecutor::PurgeCache(); - } else if (strcmp("xpcom-shutdown", aTopic) == 0) { - nsMessageManagerScriptExecutor::Shutdown(); - } - return NS_OK; - } -}; - -#endif
--- a/dom/base/PostMessageEvent.cpp +++ b/dom/base/PostMessageEvent.cpp @@ -2,39 +2,32 @@ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "PostMessageEvent.h" #include "MessageEvent.h" -#include "mozilla/dom/BlobBinding.h" #include "mozilla/dom/BrowsingContext.h" #include "mozilla/dom/BrowsingContextGroup.h" #include "mozilla/dom/DocGroup.h" #include "mozilla/dom/DocumentInlines.h" -#include "mozilla/dom/File.h" -#include "mozilla/dom/FileList.h" -#include "mozilla/dom/FileListBinding.h" #include "mozilla/dom/MessageEventBinding.h" #include "mozilla/dom/MessagePort.h" -#include "mozilla/dom/MessagePortBinding.h" -#include "mozilla/dom/PMessagePort.h" -#include "mozilla/dom/StructuredCloneTags.h" -#include "mozilla/dom/UnionConversions.h" +#include "mozilla/dom/RootedDictionary.h" #include "mozilla/BasePrincipal.h" #include "mozilla/EventDispatcher.h" #include "mozilla/StaticPrefs_dom.h" #include "nsDocShell.h" -#include "nsGlobalWindow.h" +#include "nsGlobalWindowInner.h" +#include "nsGlobalWindowOuter.h" #include "nsIConsoleService.h" #include "nsIPrincipal.h" #include "nsIScriptError.h" -#include "nsNetUtil.h" #include "nsPresContext.h" #include "nsQueryObject.h" #include "nsServiceManagerUtils.h" namespace mozilla::dom { PostMessageEvent::PostMessageEvent(BrowsingContext* aSource, const nsAString& aCallerOrigin,
--- a/dom/base/PostMessageEvent.h +++ b/dom/base/PostMessageEvent.h @@ -2,35 +2,40 @@ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef mozilla_dom_PostMessageEvent_h #define mozilla_dom_PostMessageEvent_h +#include "js/StructuredClone.h" +#include "js/TypeDecls.h" #include "mozilla/dom/DOMTypes.h" -#include "mozilla/dom/Event.h" #include "mozilla/dom/ipc/StructuredCloneData.h" #include "mozilla/dom/StructuredCloneHolder.h" #include "nsCOMPtr.h" +#include "mozilla/Maybe.h" #include "mozilla/MaybeOneOf.h" #include "mozilla/RefPtr.h" -#include "nsContentUtils.h" -#include "nsTArray.h" #include "nsThreadUtils.h" class nsGlobalWindowOuter; class nsGlobalWindowInner; class nsIPrincipal; +class nsIURI; namespace mozilla { +class ErrorResult; + namespace dom { class BrowsingContext; +class Event; +class EventTarget; /** * Class used to represent events generated by calls to Window.postMessage, * which asynchronously creates and dispatches events. */ class PostMessageEvent final : public Runnable { public: NS_DECL_NSIRUNNABLE
--- a/dom/base/moz.build +++ b/dom/base/moz.build @@ -197,16 +197,17 @@ EXPORTS.mozilla.dom += [ "IntlUtils.h", "Link.h", "LinkStyle.h", "Location.h", "LocationBase.h", "MaybeCrossOriginObject.h", "MessageBroadcaster.h", "MessageListenerManager.h", + "MessageManagerCallback.h", "MessageManagerGlobal.h", "MessageSender.h", "MimeType.h", "MozQueryInterface.h", "MutationObservers.h", "NameSpaceConstants.h", "Navigator.h", "NodeInfo.h",
--- a/dom/base/nsFrameLoader.h +++ b/dom/base/nsFrameLoader.h @@ -25,17 +25,17 @@ #include "mozilla/dom/Element.h" #include "mozilla/dom/Nullable.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/WindowProxyHolder.h" #include "mozilla/layers/LayersTypes.h" #include "nsCOMPtr.h" #include "nsCycleCollectionParticipant.h" #include "nsDocShell.h" -#include "nsFrameMessageManager.h" +#include "mozilla/dom/MessageManagerCallback.h" #include "nsID.h" #include "nsIFrame.h" #include "nsIMutationObserver.h" #include "nsISupports.h" #include "nsRect.h" #include "nsStringFwd.h" #include "nsStubMutationObserver.h" #include "nsWrapperCache.h"
--- a/dom/base/nsFrameMessageManager.cpp +++ b/dom/base/nsFrameMessageManager.cpp @@ -1,67 +1,117 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "base/basictypes.h" - #include "nsFrameMessageManager.h" +#include <algorithm> +#include <cmath> +#include <cstddef> +#include <cstdint> +#include <new> +#include <utility> #include "ContentChild.h" +#include "ErrorList.h" #include "GeckoProfiler.h" -#include "nsASCIIMask.h" -#include "nsContentUtils.h" -#include "nsError.h" -#include "nsIXPConnect.h" -#include "jsapi.h" -#include "jsfriendapi.h" -#include "nsJSUtils.h" -#include "nsJSPrincipals.h" -#include "nsNetUtil.h" -#include "mozilla/dom/ScriptLoader.h" -#include "nsFrameLoader.h" -#include "nsIInputStream.h" -#include "nsIScriptError.h" -#include "nsIConsoleService.h" -#include "nsIMemoryReporter.h" -#include "nsIProtocolHandler.h" -#include "xpcpublic.h" +#include "base/process_util.h" +#include "chrome/common/ipc_channel.h" #include "js/CompilationAndEvaluation.h" #include "js/JSON.h" #include "js/SourceText.h" +#include "js/StructuredClone.h" +#include "js/Wrapper.h" +#include "jsapi.h" +#include "jsfriendapi.h" +#include "mozilla/AlreadyAddRefed.h" +#include "mozilla/Assertions.h" #include "mozilla/ClearOnShutdown.h" -#include "mozilla/CycleCollectedJSContext.h" -#include "mozilla/Preferences.h" +#include "mozilla/ErrorResult.h" +#include "mozilla/MacroForEach.h" +#include "mozilla/NotNull.h" +#include "mozilla/OwningNonNull.h" +#include "mozilla/RefPtr.h" #include "mozilla/ScriptPreloader.h" +#include "mozilla/Services.h" +#include "mozilla/StaticPtr.h" #include "mozilla/Telemetry.h" +#include "mozilla/TelemetryHistogramEnums.h" +#include "mozilla/TimeStamp.h" +#include "mozilla/TypedEnumBits.h" +#include "mozilla/UniquePtr.h" +#include "mozilla/dom/BindingDeclarations.h" +#include "mozilla/dom/CallbackObject.h" #include "mozilla/dom/ChildProcessMessageManager.h" #include "mozilla/dom/ChromeMessageBroadcaster.h" -#include "mozilla/dom/File.h" +#include "mozilla/dom/ContentProcessMessageManager.h" +#include "mozilla/dom/DOMTypes.h" +#include "mozilla/dom/MessageBroadcaster.h" +#include "mozilla/dom/MessageListenerManager.h" #include "mozilla/dom/MessageManagerBinding.h" #include "mozilla/dom/MessagePort.h" -#include "mozilla/dom/ContentParent.h" -#include "mozilla/dom/ContentProcessMessageManager.h" #include "mozilla/dom/ParentProcessMessageManager.h" -#include "mozilla/dom/PermissionMessageUtils.h" #include "mozilla/dom/ProcessMessageManager.h" +#include "mozilla/dom/RootedDictionary.h" #include "mozilla/dom/SameProcessMessageQueue.h" +#include "mozilla/dom/ScriptLoader.h" #include "mozilla/dom/ScriptSettings.h" #include "mozilla/dom/ToJSValue.h" +#include "mozilla/dom/MessageManagerCallback.h" #include "mozilla/dom/ipc/SharedMap.h" #include "mozilla/dom/ipc/StructuredCloneData.h" -#include "mozilla/dom/DOMStringList.h" +#include "nsASCIIMask.h" +#include "nsBaseHashtable.h" +#include "nsCOMPtr.h" +#include "nsClassHashtable.h" +#include "nsComponentManagerUtils.h" +#include "nsContentUtils.h" +#include "nsCycleCollectionNoteChild.h" +#include "nsCycleCollectionParticipant.h" +#include "nsDataHashtable.h" +#include "nsDebug.h" +#include "nsError.h" +#include "nsFrameMessageManager.h" +#include "nsHashKeys.h" +#include "nsIChannel.h" +#include "nsIConsoleService.h" +#include "nsIContentPolicy.h" +#include "nsIInputStream.h" +#include "nsILoadInfo.h" +#include "nsIMemoryReporter.h" +#include "nsIMessageManager.h" +#include "nsIObserver.h" +#include "nsIObserverService.h" +#include "nsIProtocolHandler.h" +#include "nsIScriptError.h" +#include "nsISupports.h" +#include "nsISupportsUtils.h" +#include "nsIURI.h" +#include "nsIWeakReferenceUtils.h" +#include "nsIXPConnect.h" +#include "nsJSUtils.h" +#include "nsLiteralString.h" +#include "nsNetUtil.h" #include "nsPrintfCString.h" -#include "nsXULAppAPI.h" #include "nsQueryObject.h" -#include "xpcprivate.h" -#include <algorithm> -#include "chrome/common/ipc_channel.h" // for IPC::Channel::kMaximumMessageSize +#include "nsServiceManagerUtils.h" +#include "nsString.h" +#include "nsStringFlags.h" +#include "nsStringFwd.h" +#include "nsTArray.h" +#include "nsTLiteralString.h" +#include "nsTObserverArray.h" +#include "nsTPromiseFlatString.h" +#include "nsTStringRepr.h" +#include "nsThreadUtils.h" +#include "nsXULAppAPI.h" +#include "nscore.h" +#include "xpcpublic.h" #ifdef XP_WIN # if defined(SendMessage) # undef SendMessage # endif #endif #ifdef FUZZING
--- a/dom/base/nsFrameMessageManager.h +++ b/dom/base/nsFrameMessageManager.h @@ -2,120 +2,84 @@ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef nsFrameMessageManager_h__ #define nsFrameMessageManager_h__ -#include "nsIMessageManager.h" -#include "nsIObserver.h" -#include "nsCOMPtr.h" -#include "nsCOMArray.h" -#include "nsTArray.h" -#include "nsAtom.h" -#include "nsCycleCollectionParticipant.h" -#include "nsTArray.h" -#include "nsIPrincipal.h" -#include "nsDataHashtable.h" -#include "nsClassHashtable.h" +#include <cstdint> +#include <string.h> +#include <utility> +#include "ErrorList.h" +#include "js/RootingAPI.h" +#include "js/TypeDecls.h" +#include "js/Value.h" +#include "mozilla/AlreadyAddRefed.h" +#include "mozilla/Assertions.h" +#include "mozilla/RefPtr.h" #include "mozilla/Services.h" #include "mozilla/StaticPtr.h" -#include "nsIObserverService.h" -#include "nsThreadUtils.h" -#include "nsIWeakReferenceUtils.h" -#include "mozilla/Attributes.h" -#include "js/RootingAPI.h" -#include "nsTObserverArray.h" #include "mozilla/TypedEnumBits.h" #include "mozilla/UniquePtr.h" -#include "mozilla/dom/CallbackObject.h" -#include "mozilla/dom/SameProcessMessageQueue.h" #include "mozilla/dom/ipc/StructuredCloneData.h" +#include "nsCOMPtr.h" +#include "nsClassHashtable.h" +#include "nsCycleCollectionParticipant.h" +#include "nsDataHashtable.h" +#include "nsHashKeys.h" +#include "nsIMessageManager.h" +#include "nsIObserver.h" +#include "nsIObserverService.h" +#include "nsISupports.h" +#include "nsIWeakReferenceUtils.h" +#include "nsStringFwd.h" +#include "nsTArray.h" +#include "nsTObserverArray.h" +#include "nscore.h" class nsFrameLoader; +class nsIRunnable; namespace mozilla { -namespace ipc { -class FileDescriptor; -} +class ErrorResult; namespace dom { -class ContentParent; -class ContentChild; class ChildProcessMessageManager; class ChromeMessageBroadcaster; class ClonedMessageData; class MessageBroadcaster; class MessageListener; class MessageListenerManager; class MessageManagerReporter; -template <typename T> -class Optional; class ParentProcessMessageManager; class ProcessMessageManager; namespace ipc { +class MessageManagerCallback; class WritableSharedMap; // Note: we round the time we spend to the nearest millisecond. So a min value // of 1 ms actually captures from 500us and above. static const uint32_t kMinTelemetrySyncMessageManagerLatencyMs = 1; enum class MessageManagerFlags { MM_NONE = 0, MM_CHROME = 1, MM_GLOBAL = 2, MM_PROCESSMANAGER = 4, MM_BROADCASTER = 8, MM_OWNSCALLBACK = 16 }; MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(MessageManagerFlags); -class MessageManagerCallback { - public: - virtual ~MessageManagerCallback() = default; - - virtual bool DoLoadMessageManagerScript(const nsAString& aURL, - bool aRunInGlobalScope) { - return true; - } - - virtual bool DoSendBlockingMessage(const nsAString& aMessage, - StructuredCloneData& aData, - nsTArray<StructuredCloneData>* aRetVal) { - return true; - } - - virtual nsresult DoSendAsyncMessage(const nsAString& aMessage, - StructuredCloneData& aData) { - return NS_OK; - } - - virtual mozilla::dom::ProcessMessageManager* GetProcessMessageManager() - const { - return nullptr; - } - - virtual void DoGetRemoteType(nsACString& aRemoteType, - ErrorResult& aError) const; - - protected: - bool BuildClonedMessageDataForParent(ContentParent* aParent, - StructuredCloneData& aData, - ClonedMessageData& aClonedData); - bool BuildClonedMessageDataForChild(ContentChild* aChild, - StructuredCloneData& aData, - ClonedMessageData& aClonedData); -}; - void UnpackClonedMessageDataForParent(const ClonedMessageData& aClonedData, StructuredCloneData& aData); void UnpackClonedMessageDataForChild(const ClonedMessageData& aClonedData, StructuredCloneData& aData); } // namespace ipc } // namespace dom
--- a/dom/base/nsStructuredCloneContainer.cpp +++ b/dom/base/nsStructuredCloneContainer.cpp @@ -1,27 +1,34 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsStructuredCloneContainer.h" +#include <cstddef> +#include <utility> +#include "ErrorList.h" +#include "js/RootingAPI.h" +#include "js/StructuredClone.h" +#include "js/Value.h" +#include "mozilla/Assertions.h" +#include "mozilla/Base64.h" +#include "mozilla/DebugOnly.h" +#include "mozilla/ErrorResult.h" +#include "mozilla/fallible.h" #include "nsCOMPtr.h" -#include "nsIGlobalObject.h" +#include "nsDebug.h" +#include "nsError.h" #include "nsIVariant.h" #include "nsIXPConnect.h" -#include "nsServiceManagerUtils.h" -#include "nsContentUtils.h" -#include "jsapi.h" -#include "xpcpublic.h" - -#include "mozilla/Base64.h" -#include "mozilla/dom/ScriptSettings.h" +#include "nsString.h" +#include "nscore.h" using namespace mozilla; using namespace mozilla::dom; NS_IMPL_ADDREF(nsStructuredCloneContainer) NS_IMPL_RELEASE(nsStructuredCloneContainer) NS_INTERFACE_MAP_BEGIN(nsStructuredCloneContainer)
--- a/dom/base/nsStructuredCloneContainer.h +++ b/dom/base/nsStructuredCloneContainer.h @@ -2,19 +2,22 @@ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef nsStructuredCloneContainer_h__ #define nsStructuredCloneContainer_h__ +#include <cstdint> +#include "mozilla/dom/ipc/StructuredCloneData.h" #include "nsIStructuredCloneContainer.h" -#include "mozilla/Attributes.h" -#include "mozilla/dom/ipc/StructuredCloneData.h" +#include "nsISupports.h" + +class nsIVariant; #define NS_STRUCTUREDCLONECONTAINER_CONTRACTID \ "@mozilla.org/docshell/structured-clone-container;1" #define NS_STRUCTUREDCLONECONTAINER_CID \ { /* 38bd0634-0fd4-46f0-b85f-13ced889eeec */ \ 0x38bd0634, 0x0fd4, 0x46f0, { \ 0xb8, 0x5f, 0x13, 0xce, 0xd8, 0x89, 0xee, 0xec \ } \
--- a/dom/ipc/BrowserChild.h +++ b/dom/ipc/BrowserChild.h @@ -14,26 +14,26 @@ #include "nsIWebBrowserChrome.h" #include "nsIEmbeddingSiteWindow.h" #include "nsIWebBrowserChromeFocus.h" #include "nsIDOMEventListener.h" #include "nsIInterfaceRequestor.h" #include "nsIWindowProvider.h" #include "nsIDocShell.h" #include "nsIInterfaceRequestorUtils.h" -#include "nsFrameMessageManager.h" #include "nsWeakReference.h" #include "nsIBrowserChild.h" #include "nsITooltipListener.h" #include "nsIWebProgressListener.h" #include "nsIWebProgressListener2.h" #include "mozilla/Attributes.h" #include "mozilla/dom/TabContext.h" #include "mozilla/dom/CoalescedMouseData.h" #include "mozilla/dom/CoalescedWheelData.h" +#include "mozilla/dom/MessageManagerCallback.h" #include "mozilla/DOMEventTargetHelper.h" #include "mozilla/EventDispatcher.h" #include "mozilla/EventForwards.h" #include "mozilla/layers/CompositorTypes.h" #include "mozilla/layers/APZCCallbackHelper.h" #include "mozilla/layers/CompositorOptions.h" #include "mozilla/layers/GeckoContentControllerTypes.h" #include "nsIWebBrowserChrome3.h"
--- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -4,16 +4,17 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef mozilla_dom_ContentParent_h #define mozilla_dom_ContentParent_h #include "mozilla/dom/PContentParent.h" #include "mozilla/dom/ipc/IdType.h" +#include "mozilla/dom/MessageManagerCallback.h" #include "mozilla/dom/MediaSessionBinding.h" #include "mozilla/dom/RemoteBrowser.h" #include "mozilla/dom/RemoteType.h" #include "mozilla/dom/JSProcessActorParent.h" #include "mozilla/dom/ProcessActor.h" #include "mozilla/gfx/gfxVarReceiver.h" #include "mozilla/gfx/GPUProcessListener.h" #include "mozilla/ipc/BackgroundUtils.h" @@ -29,17 +30,16 @@ #include "mozilla/MemoryReportingProcess.h" #include "mozilla/MozPromise.h" #include "mozilla/TimeStamp.h" #include "mozilla/UniquePtr.h" #include "nsClassHashtable.h" #include "nsDataHashtable.h" #include "nsPluginTags.h" -#include "nsFrameMessageManager.h" #include "nsHashKeys.h" #include "nsIAsyncShutdown.h" #include "nsIDOMProcessParent.h" #include "nsIInterfaceRequestor.h" #include "nsIObserver.h" #include "nsIRemoteTab.h" #include "nsIDOMGeoPositionCallback.h" #include "nsIDOMGeoPositionErrorCallback.h"
--- a/dom/ipc/RefMessageBodyService.cpp +++ b/dom/ipc/RefMessageBodyService.cpp @@ -129,16 +129,18 @@ void RefMessageBodyService::ForgetPort(c RefMessageBody::RefMessageBody(const nsID& aPortID, UniquePtr<ipc::StructuredCloneData>&& aCloneData) : mPortID(aPortID), mMutex("RefMessageBody::mMutex"), mCloneData(std::move(aCloneData)), mMaxCount(Nothing()), mCount(0) {} +RefMessageBody::~RefMessageBody() = default; + void RefMessageBody::Read(JSContext* aCx, JS::MutableHandle<JS::Value> aValue, const JS::CloneDataPolicy& aCloneDataPolicy, ErrorResult& aRv) { MutexAutoLock lock(mMutex); mCloneData->Read(aCx, aValue, aCloneDataPolicy, aRv); } bool RefMessageBody::TakeTransferredPortsAsSequence(
--- a/dom/ipc/RefMessageBodyService.h +++ b/dom/ipc/RefMessageBodyService.h @@ -63,17 +63,17 @@ class RefMessageBody final { const JS::CloneDataPolicy& aCloneDataPolicy, ErrorResult& aRv); // This method can be called only if the RefMessageBody is not supposed to be // ref-counted (see mMaxCount). bool TakeTransferredPortsAsSequence( Sequence<OwningNonNull<mozilla::dom::MessagePort>>& aPorts); private: - ~RefMessageBody() = default; + ~RefMessageBody(); const nsID mPortID; // In case the RefMessageBody is shared and refcounted (see mCount/mMaxCount), // we must enforce that the reading does not happen simultaneously on // different threads. Mutex mMutex;
--- a/dom/ipc/jsactor/JSActor.cpp +++ b/dom/ipc/jsactor/JSActor.cpp @@ -17,16 +17,17 @@ #include "mozilla/dom/JSActorManager.h" #include "mozilla/dom/MessageManagerBinding.h" #include "mozilla/dom/PWindowGlobal.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/RootedDictionary.h" #include "mozilla/dom/ipc/StructuredCloneData.h" #include "js/Promise.h" #include "xpcprivate.h" +#include "nsFrameMessageManager.h" #include "nsICrashReporter.h" namespace mozilla::dom { NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JSActor) NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END
--- a/dom/serviceworkers/ServiceWorkerCloneData.cpp +++ b/dom/serviceworkers/ServiceWorkerCloneData.cpp @@ -1,18 +1,23 @@ /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "ServiceWorkerCloneData.h" +#include <utility> +#include "mozilla/RefPtr.h" #include "mozilla/dom/DOMTypes.h" +#include "mozilla/dom/StructuredCloneHolder.h" +#include "nsISerialEventTarget.h" #include "nsProxyRelease.h" +#include "nsThreadUtils.h" namespace mozilla { namespace dom { ServiceWorkerCloneData::~ServiceWorkerCloneData() { RefPtr<ipc::SharedJSAllocatedData> sharedData = TakeSharedData(); if (sharedData) { NS_ProxyRelease(__func__, mEventTarget, sharedData.forget());
--- a/dom/serviceworkers/ServiceWorkerCloneData.h +++ b/dom/serviceworkers/ServiceWorkerCloneData.h @@ -2,17 +2,21 @@ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef mozilla_dom_ServiceWorkerCloneData_h__ #define mozilla_dom_ServiceWorkerCloneData_h__ +#include "mozilla/Assertions.h" +#include "mozilla/dom/DOMTypes.h" #include "mozilla/dom/ipc/StructuredCloneData.h" +#include "nsCOMPtr.h" +#include "nsISupports.h" class nsISerialEventTarget; namespace mozilla { namespace ipc { class PBackgroundChild; class PBackgroundParent; } // namespace ipc
--- a/xpcom/threads/nsThreadUtils.cpp +++ b/xpcom/threads/nsThreadUtils.cpp @@ -30,17 +30,17 @@ #elif defined(XP_MACOSX) # include <sys/resource.h> #endif #if defined(ANDROID) # include <sys/prctl.h> #endif -static LazyLogModule sEventDispatchAndRunLog("events"); +static mozilla::LazyLogModule sEventDispatchAndRunLog("events"); #ifdef LOG1 # undef LOG1 #endif #define LOG1(args) \ MOZ_LOG(sEventDispatchAndRunLog, mozilla::LogLevel::Error, args) #define LOG1_ENABLED() \ MOZ_LOG_TEST(sEventDispatchAndRunLog, mozilla::LogLevel::Error)