From 28f2b1959fa79715c6341379e6b68605d3072ff8 Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Sun, 5 Jan 2020 06:03:43 +0000 Subject: [PATCH] Bug 1603187 - P1. Add IPDL serialiser for nsDOMNavigationTiming object. r=mattwoodrow,smaug Differential Revision: https://phabricator.services.mozilla.com/D57770 --HG-- extra : moz-landing-system : lando --- dom/base/nsDOMNavigationTiming.cpp | 80 ++++++++++++++++++++++++++++-- dom/base/nsDOMNavigationTiming.h | 35 ++++++++++++- 2 files changed, 110 insertions(+), 5 deletions(-) diff --git a/dom/base/nsDOMNavigationTiming.cpp b/dom/base/nsDOMNavigationTiming.cpp index 27dd43e91f4c..3e0c1bbe6632 100644 --- a/dom/base/nsDOMNavigationTiming.cpp +++ b/dom/base/nsDOMNavigationTiming.cpp @@ -7,17 +7,18 @@ #include "nsDOMNavigationTiming.h" #include "GeckoProfiler.h" +#include "mozilla/Telemetry.h" +#include "mozilla/TimeStamp.h" +#include "mozilla/dom/PerformanceNavigation.h" +#include "mozilla/ipc/IPDLParamTraits.h" #include "nsCOMPtr.h" #include "nsContentUtils.h" #include "nsDocShell.h" #include "nsHttp.h" #include "nsIScriptSecurityManager.h" -#include "prtime.h" #include "nsIURI.h" #include "nsPrintfCString.h" -#include "mozilla/dom/PerformanceNavigation.h" -#include "mozilla/TimeStamp.h" -#include "mozilla/Telemetry.h" +#include "prtime.h" #ifdef MOZ_GECKO_PROFILER # include "ProfilerMarkerPayload.h" #endif @@ -533,3 +534,74 @@ bool nsDOMNavigationTiming::IsTopLevelContentDocumentInContentProcess() const { } return mDocShell->GetBrowsingContext()->IsTopContent(); } + +/* static */ +void mozilla::ipc::IPDLParamTraits::Write( + IPC::Message* aMsg, IProtocol* aActor, nsDOMNavigationTiming* aParam) { + RefPtr unloadedURI = aParam->mUnloadedURI.get(); + RefPtr loadedURI = aParam->mLoadedURI.get(); + WriteIPDLParam(aMsg, aActor, unloadedURI ? Some(unloadedURI) : Nothing()); + WriteIPDLParam(aMsg, aActor, loadedURI ? Some(loadedURI) : Nothing()); + WriteIPDLParam(aMsg, aActor, uint32_t(aParam->mNavigationType)); + WriteIPDLParam(aMsg, aActor, aParam->mNavigationStartHighRes); + WriteIPDLParam(aMsg, aActor, aParam->mNavigationStart); + WriteIPDLParam(aMsg, aActor, aParam->mNonBlankPaint); + WriteIPDLParam(aMsg, aActor, aParam->mContentfulPaint); + WriteIPDLParam(aMsg, aActor, aParam->mDOMContentFlushed); + WriteIPDLParam(aMsg, aActor, aParam->mBeforeUnloadStart); + WriteIPDLParam(aMsg, aActor, aParam->mUnloadStart); + WriteIPDLParam(aMsg, aActor, aParam->mUnloadEnd); + WriteIPDLParam(aMsg, aActor, aParam->mLoadEventStart); + WriteIPDLParam(aMsg, aActor, aParam->mLoadEventEnd); + WriteIPDLParam(aMsg, aActor, aParam->mDOMLoading); + WriteIPDLParam(aMsg, aActor, aParam->mDOMInteractive); + WriteIPDLParam(aMsg, aActor, aParam->mDOMContentLoadedEventStart); + WriteIPDLParam(aMsg, aActor, aParam->mDOMContentLoadedEventEnd); + WriteIPDLParam(aMsg, aActor, aParam->mDOMComplete); + WriteIPDLParam(aMsg, aActor, aParam->mTTFI); + WriteIPDLParam(aMsg, aActor, + aParam->mDocShellHasBeenActiveSinceNavigationStart); +} + +/* static */ +bool mozilla::ipc::IPDLParamTraits::Read( + const IPC::Message* aMsg, PickleIterator* aIter, IProtocol* aActor, + RefPtr* aResult) { + auto timing = MakeRefPtr(nullptr); + uint32_t type; + Maybe> unloadedURI; + Maybe> loadedURI; + if (!ReadIPDLParam(aMsg, aIter, aActor, &unloadedURI) || + !ReadIPDLParam(aMsg, aIter, aActor, &loadedURI) || + !ReadIPDLParam(aMsg, aIter, aActor, &type) || + !ReadIPDLParam(aMsg, aIter, aActor, &timing->mNavigationStartHighRes) || + !ReadIPDLParam(aMsg, aIter, aActor, &timing->mNavigationStart) || + !ReadIPDLParam(aMsg, aIter, aActor, &timing->mNonBlankPaint) || + !ReadIPDLParam(aMsg, aIter, aActor, &timing->mContentfulPaint) || + !ReadIPDLParam(aMsg, aIter, aActor, &timing->mDOMContentFlushed) || + !ReadIPDLParam(aMsg, aIter, aActor, &timing->mBeforeUnloadStart) || + !ReadIPDLParam(aMsg, aIter, aActor, &timing->mUnloadStart) || + !ReadIPDLParam(aMsg, aIter, aActor, &timing->mUnloadEnd) || + !ReadIPDLParam(aMsg, aIter, aActor, &timing->mLoadEventStart) || + !ReadIPDLParam(aMsg, aIter, aActor, &timing->mLoadEventEnd) || + !ReadIPDLParam(aMsg, aIter, aActor, &timing->mDOMLoading) || + !ReadIPDLParam(aMsg, aIter, aActor, &timing->mDOMInteractive) || + !ReadIPDLParam(aMsg, aIter, aActor, + &timing->mDOMContentLoadedEventStart) || + !ReadIPDLParam(aMsg, aIter, aActor, &timing->mDOMContentLoadedEventEnd) || + !ReadIPDLParam(aMsg, aIter, aActor, &timing->mDOMComplete) || + !ReadIPDLParam(aMsg, aIter, aActor, &timing->mTTFI) || + !ReadIPDLParam(aMsg, aIter, aActor, + &timing->mDocShellHasBeenActiveSinceNavigationStart)) { + return false; + } + timing->mNavigationType = nsDOMNavigationTiming::Type(type); + if (unloadedURI) { + timing->mUnloadedURI = unloadedURI->forget(); + } + if (loadedURI) { + timing->mLoadedURI = loadedURI->forget(); + } + *aResult = timing.forget(); + return true; +} diff --git a/dom/base/nsDOMNavigationTiming.h b/dom/base/nsDOMNavigationTiming.h index 2ce3c89f24e0..bd1c8c72453e 100644 --- a/dom/base/nsDOMNavigationTiming.h +++ b/dom/base/nsDOMNavigationTiming.h @@ -20,6 +20,18 @@ class nsIURI; typedef unsigned long long DOMTimeMilliSec; typedef double DOMHighResTimeStamp; +class PickleIterator; +namespace IPC { +class Message; +} // namespace IPC +namespace mozilla { +namespace ipc { +class IProtocol; +template +struct IPDLParamTraits; +} // namespace ipc +} // namespace mozilla + class nsDOMNavigationTiming final : public mozilla::RelativeTimeline { public: enum Type { @@ -173,6 +185,8 @@ class nsDOMNavigationTiming final : public mozilla::RelativeTimeline { bool IsTopLevelContentDocumentInContentProcess() const; +// Should those be amended, the IPC serializer should be updated +// accordingly. mozilla::WeakPtr mDocShell; nsCOMPtr mUnloadedURI; @@ -200,7 +214,26 @@ class nsDOMNavigationTiming final : public mozilla::RelativeTimeline { mozilla::TimeStamp mTTFI; - bool mDocShellHasBeenActiveSinceNavigationStart : 1; + bool mDocShellHasBeenActiveSinceNavigationStart; + + friend struct mozilla::ipc::IPDLParamTraits; }; +// IPDL serializer. Please be aware of the caveats in sending across +// the information and the potential resulting data leakage. +// For now, this serializer is to only be used under a very narrowed scope +// so that only the starting times are ever set. +namespace mozilla { +namespace ipc { +template <> +struct IPDLParamTraits { + static void Write(IPC::Message* aMsg, IProtocol* aActor, + nsDOMNavigationTiming* aParam); + static bool Read(const IPC::Message* aMsg, PickleIterator* aIter, + IProtocol* aActor, RefPtr* aResult); +}; + +} // namespace ipc +} // namespace mozilla + #endif /* nsDOMNavigationTiming_h___ */