Bug 1107516 - Part 1: Add LoadContext constructor taking an nsIPrincipal. r=smaug
authorBen Kelly <ben@wanderview.com>
Fri, 12 Dec 2014 11:05:00 -0500
changeset 219789 e29791c42832f560e7ad0d52bf7071ef2fd28768
parent 219788 8ff55dfa36070e3dbc36a4dff794197e44ec6f84
child 219790 6ec85c7c9b5f96753fa266e58d74dc2c7cbe12f5
push id10419
push usercbook@mozilla.com
push dateTue, 16 Dec 2014 12:45:27 +0000
treeherderfx-team@ec87657146eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1107516
milestone37.0a1
Bug 1107516 - Part 1: Add LoadContext constructor taking an nsIPrincipal. r=smaug
docshell/base/LoadContext.cpp
docshell/base/LoadContext.h
--- a/docshell/base/LoadContext.cpp
+++ b/docshell/base/LoadContext.cpp
@@ -1,20 +1,36 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set sw=2 ts=8 et 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/Assertions.h"
 #include "mozilla/LoadContext.h"
 
 namespace mozilla {
 
 NS_IMPL_ISUPPORTS(LoadContext, nsILoadContext, nsIInterfaceRequestor)
 
+LoadContext::LoadContext(nsIPrincipal* aPrincipal)
+  : mTopFrameElement(nullptr)
+  , mNestedFrameId(0)
+  , mIsContent(true)
+  , mUsePrivateBrowsing(false)
+  , mUseRemoteTabs(false)
+#ifdef DEBUG
+  , mIsNotNull(true)
+#endif
+{
+  MOZ_ALWAYS_TRUE(NS_SUCCEEDED(aPrincipal->GetAppId(&mAppId)));
+  MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
+    aPrincipal->GetIsInBrowserElement(&mIsInBrowserElement)));
+}
+
 //-----------------------------------------------------------------------------
 // LoadContext::nsILoadContext
 //-----------------------------------------------------------------------------
 
 NS_IMETHODIMP
 LoadContext::GetAssociatedWindow(nsIDOMWindow**)
 {
   MOZ_ASSERT(mIsNotNull);
--- a/docshell/base/LoadContext.h
+++ b/docshell/base/LoadContext.h
@@ -100,16 +100,20 @@ public:
     , mUsePrivateBrowsing(false)
     , mUseRemoteTabs(false)
     , mIsInBrowserElement(false)
 #ifdef DEBUG
     , mIsNotNull(true)
 #endif
   {}
 
+  // Constructor for creating a LoadContext with a given principal's appId and
+  // browser flag.
+  LoadContext(nsIPrincipal* aPrincipal);
+
 private:
   ~LoadContext() {}
 
   nsWeakPtr     mTopFrameElement;
   uint64_t      mNestedFrameId;
   uint32_t      mAppId;
   bool          mIsContent;
   bool          mUsePrivateBrowsing;