Bug 1478742 - IPDLize nsDocShellLoadState; r=nika
authorKyle Machulis <kyle@nonpolynomial.com>
Wed, 19 Dec 2018 22:22:09 +0000
changeset 508875 3c3eb5325c17b2a93d4a587242fb5dd732415e9b
parent 508874 b3e637ea660bd45e53ef1f886c00a622b549d260
child 508876 b723ef9caca92c5b4635f352671eafc2737a3735
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnika
bugs1478742
milestone66.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
Bug 1478742 - IPDLize nsDocShellLoadState; r=nika Differential Revision: https://phabricator.services.mozilla.com/D13958
docshell/base/nsDocShellLoadState.cpp
docshell/base/nsDocShellLoadState.h
dom/ipc/DOMTypes.ipdlh
dom/ipc/DocShellMessageUtils.cpp
dom/ipc/DocShellMessageUtils.h
dom/ipc/PBrowser.ipdl
dom/ipc/PWindowGlobal.ipdl
dom/ipc/moz.build
--- a/docshell/base/nsDocShellLoadState.cpp
+++ b/docshell/base/nsDocShellLoadState.cpp
@@ -8,16 +8,18 @@
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeItem.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIWebNavigation.h"
 
 #include "mozilla/OriginAttributes.h"
 #include "mozilla/NullPrincipal.h"
 
+#include "mozilla/dom/PContent.h"
+
 nsDocShellLoadState::nsDocShellLoadState(nsIURI* aURI)
     : mURI(aURI),
       mResultPrincipalURIIsSome(false),
       mKeepResultPrincipalURIIfSet(false),
       mLoadReplace(false),
       mInheritPrincipal(false),
       mPrincipalIsExplicit(false),
       mForceAllowDataURI(false),
@@ -30,16 +32,43 @@ nsDocShellLoadState::nsDocShellLoadState
       mLoadFlags(0),
       mFirstParty(false),
       mTypeHint(VoidCString()),
       mFileName(VoidString()),
       mIsFromProcessingFrameAttributes(false) {
   MOZ_ASSERT(aURI, "Cannot create a LoadState with a null URI!");
 }
 
+nsDocShellLoadState::nsDocShellLoadState(DocShellLoadStateInit& aLoadState)
+{
+  MOZ_ASSERT(aLoadState.URI(), "Cannot create a LoadState with a null URI!");
+  mResultPrincipalURIIsSome = aLoadState.ResultPrincipalURIIsSome();
+  mKeepResultPrincipalURIIfSet = aLoadState.KeepResultPrincipalURIIfSet();
+  mLoadReplace = aLoadState.LoadReplace();
+  mInheritPrincipal = aLoadState.InheritPrincipal();
+  mPrincipalIsExplicit = aLoadState.PrincipalIsExplicit();
+  mForceAllowDataURI = aLoadState.ForceAllowDataURI();
+  mOriginalFrameSrc = aLoadState.OriginalFrameSrc();
+  mSendReferrer = aLoadState.SendReferrer();
+  mReferrerPolicy = (mozilla::net::ReferrerPolicy)aLoadState.ReferrerPolicy();
+  mLoadType = aLoadState.LoadType();
+  mTarget = aLoadState.Target();
+  mLoadFlags = aLoadState.LoadFlags();
+  mFirstParty = aLoadState.FirstParty();
+  mTypeHint = aLoadState.TypeHint();
+  mFileName = aLoadState.FileName();
+  mIsFromProcessingFrameAttributes = aLoadState.IsFromProcessingFrameAttributes();
+  mReferrer = aLoadState.Referrer();
+  mURI = aLoadState.URI();
+  mOriginalURI = aLoadState.OriginalURI();
+  mBaseURI = aLoadState.BaseURI();
+  mTriggeringPrincipal = aLoadState.TriggeringPrincipal();
+  mPrincipalToInherit = aLoadState.PrincipalToInherit();
+}
+
 nsDocShellLoadState::~nsDocShellLoadState() {}
 
 nsIURI* nsDocShellLoadState::Referrer() const { return mReferrer; }
 
 void nsDocShellLoadState::SetReferrer(nsIURI* aReferrer) {
   mReferrer = aReferrer;
 }
 
@@ -380,8 +409,35 @@ void nsDocShellLoadState::CalculateLoadU
   if (mForceAllowDataURI) {
     mLoadFlags |= nsDocShell::INTERNAL_LOAD_FLAGS_FORCE_ALLOW_DATA_URI;
   }
 
   if (mOriginalFrameSrc) {
     mLoadFlags |= nsDocShell::INTERNAL_LOAD_FLAGS_ORIGINAL_FRAME_SRC;
   }
 }
+
+DocShellLoadStateInit nsDocShellLoadState::Serialize() {
+  DocShellLoadStateInit loadState;
+  loadState.ResultPrincipalURIIsSome() = mResultPrincipalURIIsSome;
+  loadState.KeepResultPrincipalURIIfSet() = mKeepResultPrincipalURIIfSet;
+  loadState.LoadReplace() = mLoadReplace;
+  loadState.InheritPrincipal() = mInheritPrincipal;
+  loadState.PrincipalIsExplicit() = mPrincipalIsExplicit;
+  loadState.ForceAllowDataURI() = mForceAllowDataURI;
+  loadState.OriginalFrameSrc() = mOriginalFrameSrc;
+  loadState.SendReferrer() = mSendReferrer;
+  loadState.ReferrerPolicy() = mReferrerPolicy;
+  loadState.LoadType() = mLoadType;
+  loadState.Target() = mTarget;
+  loadState.LoadFlags() = mLoadFlags;
+  loadState.FirstParty() = mFirstParty;
+  loadState.TypeHint() = mTypeHint;
+  loadState.FileName() = mFileName;
+  loadState.IsFromProcessingFrameAttributes() = mIsFromProcessingFrameAttributes;
+  loadState.Referrer() = mReferrer;
+  loadState.URI() = mURI;
+  loadState.OriginalURI() = mOriginalURI;
+  loadState.BaseURI() = mBaseURI;
+  loadState.TriggeringPrincipal() = mTriggeringPrincipal;
+  loadState.PrincipalToInherit() = mPrincipalToInherit;
+  return loadState;
+}
--- a/docshell/base/nsDocShellLoadState.h
+++ b/docshell/base/nsDocShellLoadState.h
@@ -13,26 +13,33 @@
 #include "nsDocShellLoadTypes.h"
 #include "mozilla/net/ReferrerPolicy.h"
 
 class nsIInputStream;
 class nsISHEntry;
 class nsIURI;
 class nsIDocShell;
 class OriginAttibutes;
+namespace mozilla {
+namespace dom {
+class DocShellLoadStateInit;
+}
+}
+
 
 /**
  * nsDocShellLoadState contains setup information used in a nsIDocShell::loadURI
  * call.
  */
 class nsDocShellLoadState final {
  public:
   NS_INLINE_DECL_REFCOUNTING(nsDocShellLoadState);
 
   explicit nsDocShellLoadState(nsIURI* aURI);
+  explicit nsDocShellLoadState(mozilla::dom::DocShellLoadStateInit& aLoadState);
 
   // Getters and Setters
 
   nsIURI* Referrer() const;
 
   void SetReferrer(nsIURI* aReferrer);
 
   nsIURI* URI() const;
@@ -167,26 +174,27 @@ class nsDocShellLoadState final {
   // If no triggering principal exists at the moment, create one using referrer
   // information and origin attributes.
   nsresult SetupTriggeringPrincipal(
       const mozilla::OriginAttributes& aOriginAttributes);
 
   void SetIsFromProcessingFrameAttributes() {
     mIsFromProcessingFrameAttributes = true;
   }
-  bool GetIsFromProcessingFrameAttributes() {
+  bool GetIsFromProcessingFrameAttributes() const {
     return mIsFromProcessingFrameAttributes;
   }
 
   // When loading a document through nsDocShell::LoadURI(), a special set of
   // flags needs to be set based on other values in nsDocShellLoadState. This
   // function calculates those flags, before the LoadState is passed to
   // nsDocShell::InternalLoad.
   void CalculateLoadURIFlags();
 
+  mozilla::dom::DocShellLoadStateInit Serialize();
  protected:
   // Destructor can't be defaulted or inlined, as header doesn't have all type
   // includes it needs to do so.
   ~nsDocShellLoadState();
 
  protected:
   // This is the referrer for the load.
   nsCOMPtr<nsIURI> mReferrer;
--- a/dom/ipc/DOMTypes.ipdlh
+++ b/dom/ipc/DOMTypes.ipdlh
@@ -23,17 +23,17 @@ using DesktopToLayoutDeviceScale from "U
 using CSSToLayoutDeviceScale from "Units.h";
 using CSSRect from "Units.h";
 using CSSSize from "Units.h";
 using mozilla::LayoutDeviceIntPoint from "Units.h";
 using hal::ScreenOrientation from "mozilla/HalScreenConfiguration.h";
 using mozilla::gfx::SurfaceFormat from "mozilla/gfx/Types.h";
 using refcounted class nsIPrincipal from "mozilla/dom/PermissionMessageUtils.h";
 using mozilla::dom::BrowsingContextId from "mozilla/dom/ipc/IdType.h";
-
+using refcounted class nsIURI from "mozilla/ipc/URIUtils.h";
 
 namespace mozilla {
 namespace dom {
 
 struct MessagePortIdentifier
 {
   nsID uuid;
   nsID destinationUuid;
@@ -180,18 +180,53 @@ struct PerformanceInfo
   // True if the document window is the top window
   bool isTopLevel;
   // Memory
   PerformanceMemoryInfo memory;
   // Counters per category. For workers, a single entry
   CategoryDispatch[] items;
 };
 
+
 struct WindowGlobalInit
 {
   nsIPrincipal principal;
   BrowsingContextId browsingContextId;
   uint64_t innerWindowId;
   uint64_t outerWindowId;
 };
 
+struct DocShellLoadStateInit
+{
+  nsIURI Referrer;
+  nsIURI URI;
+  nsIURI OriginalURI;
+  nsIURI ResultPrincipalURI;
+  bool ResultPrincipalURIIsSome;
+  nsIPrincipal TriggeringPrincipal;
+  bool KeepResultPrincipalURIIfSet;
+  bool LoadReplace;
+  bool InheritPrincipal;
+  bool PrincipalIsExplicit;
+  nsIPrincipal PrincipalToInherit;
+  bool ForceAllowDataURI;
+  bool OriginalFrameSrc;
+  bool SendReferrer;
+  uint32_t ReferrerPolicy;
+  uint32_t LoadType;
+  nsString Target;
+  nsIURI BaseURI;
+  uint32_t LoadFlags;
+  bool FirstParty;
+  nsCString TypeHint;
+  nsString FileName;
+  bool IsFromProcessingFrameAttributes;
+  // Fields missing due to lack of need or serialization
+  // nsCOMPtr<nsISHEntry> mSHEntry;
+  // nsCOMPtr<nsIDocShell> mSourceDocShell;
+  // bool mIsSrcDocLoad; // useless without sourcedocshell
+  // nsString mSrcdocData; // useless without sourcedocshell
+  // nsIInputStream PostDataStream; // will be used after IPC transaction
+  // nsIInputStream HeadersStream; // will be used after IPC transaction
+};
+
 } // namespace dom
 } // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/ipc/DocShellMessageUtils.cpp
@@ -0,0 +1,38 @@
+/* -*- 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 "mozilla/dom/DocShellMessageUtils.h"
+#include "nsISerializable.h"
+#include "nsSerializationHelper.h"
+
+namespace mozilla {
+namespace ipc {
+
+void IPDLParamTraits<nsDocShellLoadState>::Write(IPC::Message* aMsg, IProtocol* aActor, nsDocShellLoadState* aParam) {
+  MOZ_RELEASE_ASSERT(aParam);
+  WriteIPDLParam(aMsg, aActor, aParam->Serialize());
+}
+
+bool IPDLParamTraits<nsDocShellLoadState>::Read(const IPC::Message* aMsg, PickleIterator* aIter,
+                                                IProtocol* aActor, RefPtr<nsDocShellLoadState>* aResult) {
+  DocShellLoadStateInit loadState;
+  if (!ReadIPDLParam(aMsg, aIter, aActor, &loadState)) {
+    return false;
+  }
+
+  // Assert if we somehow don't have a URI in our IPDL type, because we can't
+  // construct anything out of it. This mimics the assertion in the constructor
+  // for nsDocShellLoadState, but makes it clearer that the
+  // DocShellLoadStateInit IPC object can't be clearly converted into a
+  // nsDocShellLoadState.
+  MOZ_ASSERT(loadState.URI());
+
+  *aResult = new nsDocShellLoadState(loadState);
+  return true;
+}
+
+}  // namespace ipc
+}  // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/ipc/DocShellMessageUtils.h
@@ -0,0 +1,27 @@
+/* -*- 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 mozilla_dom_docshell_message_utils_h__
+#define mozilla_dom_docshell_message_utils_h__
+
+#include "ipc/IPCMessageUtils.h"
+#include "nsCOMPtr.h"
+#include "nsDocShellLoadState.h"
+
+namespace mozilla {
+namespace ipc {
+
+template <>
+struct IPDLParamTraits<nsDocShellLoadState> {
+  static void Write(IPC::Message* aMsg, IProtocol* aActor, nsDocShellLoadState* aParam);
+  static bool Read(const IPC::Message* aMsg, PickleIterator* aIter,
+                   IProtocol* aActor, RefPtr<nsDocShellLoadState>* aResult);
+};
+
+}  // namespace ipc
+}  // namespace mozilla
+
+#endif  // mozilla_dom_docshell_message_utils_h__
--- a/dom/ipc/PBrowser.ipdl
+++ b/dom/ipc/PBrowser.ipdl
@@ -83,17 +83,16 @@ using nsEventStatus from "mozilla/EventF
 using mozilla::Modifiers from "mozilla/EventForwards.h";
 using nsSizeMode from "nsIWidgetListener.h";
 using mozilla::widget::CandidateWindowPosition from "ipc/nsGUIEventIPC.h";
 using class mozilla::NativeEventData from "ipc/nsGUIEventIPC.h";
 using mozilla::FontRange from "ipc/nsGUIEventIPC.h";
 using mozilla::a11y::IAccessibleHolder from "mozilla/a11y/IPCTypes.h";
 using mozilla::OriginAttributes from "mozilla/ipc/BackgroundUtils.h";
 using mozilla::dom::BrowsingContextId from "mozilla/dom/ipc/IdType.h";
-using refcounted class nsIURI from "mozilla/ipc/URIUtils.h";
 
 namespace mozilla {
 namespace dom {
 
 struct ShowInfo
 {
   nsString name;
   bool fullscreenAllowed;
--- a/dom/ipc/PWindowGlobal.ipdl
+++ b/dom/ipc/PWindowGlobal.ipdl
@@ -4,17 +4,16 @@
  * 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 protocol PBrowser;
 include protocol PInProcess;
 
 include DOMTypes;
 
-using refcounted class nsIURI from "mozilla/ipc/URIUtils.h";
 
 namespace mozilla {
 namespace dom {
 
 /**
  * A PWindowGlobal actor has a lifetime matching that of a single Window Global,
  * specifically a |nsGlobalWindowInner|. These actors will form a parent/child
  * link either between the chrome/content process, or will be in-process, for
--- a/dom/ipc/moz.build
+++ b/dom/ipc/moz.build
@@ -33,16 +33,17 @@ EXPORTS.mozilla.dom += [
     'CoalescedWheelData.h',
     'ContentBridgeChild.h',
     'ContentBridgeParent.h',
     'ContentChild.h',
     'ContentParent.h',
     'ContentProcess.h',
     'ContentProcessManager.h',
     'CPOWManagerGetter.h',
+    'DocShellMessageUtils.h',
     'FilePickerParent.h',
     'MemoryReportRequest.h',
     'nsIContentChild.h',
     'nsIContentParent.h',
     'PermissionMessageUtils.h',
     'TabChild.h',
     'TabContext.h',
     'TabMessageUtils.h',
@@ -64,16 +65,17 @@ UNIFIED_SOURCES += [
     'CoalescedMouseData.cpp',
     'CoalescedWheelData.cpp',
     'ColorPickerParent.cpp',
     'ContentBridgeChild.cpp',
     'ContentBridgeParent.cpp',
     'ContentParent.cpp',
     'ContentProcess.cpp',
     'ContentProcessManager.cpp',
+    'DocShellMessageUtils.cpp',
     'FilePickerParent.cpp',
     'MemMapSnapshot.cpp',
     'MemoryReportRequest.cpp',
     'MMPrinter.cpp',
     'nsIContentChild.cpp',
     'nsIContentParent.cpp',
     'PermissionMessageUtils.cpp',
     'PreallocatedProcessManager.cpp',