Bug 1525036 - Add CrossOriginPolicy to the browsing context r=nika
authorValentin Gosu <valentin.gosu@gmail.com>
Tue, 12 Mar 2019 08:04:01 +0000
changeset 524500 214ce4ef682ae8e113c3f5604770f05fb2fbb231
parent 524499 88a92eb3865e6482155111c684ba56bf73612ee3
child 524501 fb2aeeed63c7148e203528b929ff44b121b0f010
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnika
bugs1525036
milestone67.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 1525036 - Add CrossOriginPolicy to the browsing context r=nika Differential Revision: https://phabricator.services.mozilla.com/D21418
docshell/base/BrowsingContext.cpp
docshell/base/BrowsingContext.h
ipc/glue/IPCMessageUtils.h
netwerk/base/nsILoadInfo.idl
--- a/docshell/base/BrowsingContext.cpp
+++ b/docshell/base/BrowsingContext.cpp
@@ -172,22 +172,25 @@ BrowsingContext::BrowsingContext(Browsin
                                  uint64_t aBrowsingContextId, Type aType)
     : mName(aName),
       mClosed(false),
       mType(aType),
       mBrowsingContextId(aBrowsingContextId),
       mParent(aParent),
       mOpener(aOpener),
       mIsActivatedByUserGesture(false) {
+  mCrossOriginPolicy = nsILoadInfo::CROSS_ORIGIN_POLICY_NULL;
   // Specify our group in our constructor. We will explicitly join the group
   // when we are registered, as doing so will take a reference.
   if (mParent) {
     mGroup = mParent->Group();
+    mCrossOriginPolicy = mParent->CrossOriginPolicy();
   } else if (mOpener) {
     mGroup = mOpener->Group();
+    mCrossOriginPolicy = mOpener->CrossOriginPolicy();
   } else {
     // To ensure the group has a unique ID, we will use our ID, as the founder
     // of this BrowsingContextGroup.
     mGroup = new BrowsingContextGroup();
   }
 }
 
 void BrowsingContext::SetDocShell(nsIDocShell* aDocShell) {
--- a/docshell/base/BrowsingContext.h
+++ b/docshell/base/BrowsingContext.h
@@ -13,16 +13,17 @@
 #include "mozilla/WeakPtr.h"
 #include "mozilla/dom/BindingDeclarations.h"
 #include "nsCOMPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsIDocShell.h"
 #include "nsString.h"
 #include "nsTArray.h"
 #include "nsWrapperCache.h"
+#include "nsILoadInfo.h"
 
 class nsGlobalWindowOuter;
 class nsIPrincipal;
 class nsOuterWindowProxy;
 class PickleIterator;
 
 namespace IPC {
 class Message;
@@ -64,16 +65,17 @@ class WindowProxyHolder;
 //
 // At all times the last line below should be __VA_ARGS__, since that
 // acts as a sentinel for callers of MOZ_FOR_EACH_SYNCED_FIELD.
 
 // clang-format off
 #define MOZ_FOR_EACH_SYNCED_BC_FIELD(declare, ...)        \
   declare(Name, nsString, nsAString)                   \
   declare(Closed, bool, bool)                          \
+  declare(CrossOriginPolicy, nsILoadInfo::CrossOriginPolicy, nsILoadInfo::CrossOriginPolicy) \
   __VA_ARGS__
 // clang-format on
 
 #define MOZ_SYNCED_BC_FIELD_NAME(name, ...) m##name
 #define MOZ_SYNCED_BC_FIELD_ARGUMENT(name, type, atype) \
   transaction->MOZ_SYNCED_BC_FIELD_NAME(name),
 #define MOZ_SYNCED_BC_FIELD_GETTER(name, type, atype) \
   const type& Get##name() const { return MOZ_SYNCED_BC_FIELD_NAME(name); }
@@ -283,16 +285,20 @@ class BrowsingContext : public nsWrapper
                       const Sequence<JSObject*>& aTransfer,
                       nsIPrincipal& aSubjectPrincipal, ErrorResult& aError);
   void PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
                       const WindowPostMessageOptions& aOptions,
                       nsIPrincipal& aSubjectPrincipal, ErrorResult& aError);
 
   JSObject* WrapObject(JSContext* aCx);
 
+  nsILoadInfo::CrossOriginPolicy CrossOriginPolicy() {
+    return mCrossOriginPolicy;
+  }
+
  protected:
   virtual ~BrowsingContext();
   BrowsingContext(BrowsingContext* aParent, BrowsingContext* aOpener,
                   const nsAString& aName, uint64_t aBrowsingContextId,
                   Type aType);
 
  private:
   // Find the special browsing context if aName is '_self', '_parent',
--- a/ipc/glue/IPCMessageUtils.h
+++ b/ipc/glue/IPCMessageUtils.h
@@ -1084,11 +1084,24 @@ struct CrossOriginOpenerPolicyValidator 
   }
 };
 
 template <>
 struct ParamTraits<nsILoadInfo::CrossOriginOpenerPolicy>
     : EnumSerializer<nsILoadInfo::CrossOriginOpenerPolicy,
                      CrossOriginOpenerPolicyValidator> {};
 
+struct CrossOriginPolicyValidator {
+  static bool IsLegalValue(nsILoadInfo::CrossOriginPolicy e) {
+    return e == nsILoadInfo::CROSS_ORIGIN_POLICY_NULL ||
+           e == nsILoadInfo::CROSS_ORIGIN_POLICY_ANONYMOUS ||
+           e == nsILoadInfo::CROSS_ORIGIN_POLICY_USE_CREDENTIALS;
+  }
+};
+
+template <>
+struct ParamTraits<nsILoadInfo::CrossOriginPolicy>
+    : EnumSerializer<nsILoadInfo::CrossOriginPolicy,
+                     CrossOriginPolicyValidator> {};
+
 } /* namespace IPC */
 
 #endif /* __IPC_GLUE_IPCMESSAGEUTILS_H__ */
--- a/netwerk/base/nsILoadInfo.idl
+++ b/netwerk/base/nsILoadInfo.idl
@@ -1088,9 +1088,15 @@ interface nsILoadInfo : nsISupports
     OPENER_POLICY_SAME_ORIGIN    = 1,
     OPENER_POLICY_SAME_SITE      = 2,
     OPENER_POLICY_UNSAFE_ALLOW_OUTGOING_FLAG = 0x80,
     OPENER_POLICY_SAME_ORIGIN_ALLOW_OUTGOING = OPENER_POLICY_SAME_ORIGIN | OPENER_POLICY_UNSAFE_ALLOW_OUTGOING_FLAG,
     OPENER_POLICY_SAME_SITE_ALLOW_OUTGOING = OPENER_POLICY_SAME_SITE | OPENER_POLICY_UNSAFE_ALLOW_OUTGOING_FLAG
   };
 
   [infallible] attribute nsILoadInfo_CrossOriginOpenerPolicy openerPolicy;
+
+  cenum CrossOriginPolicy : 8 {
+    CROSS_ORIGIN_POLICY_NULL            = 0,
+    CROSS_ORIGIN_POLICY_ANONYMOUS       = 1,
+    CROSS_ORIGIN_POLICY_USE_CREDENTIALS = 2
+  };
 };