Bug 1022229 - Let Null Principals have App IDs and mozBrowser status. r=bz
☠☠ backed out by d735d53ecce2 ☠ ☠
authorBobby Holley <bobbyholley@gmail.com>
Mon, 28 Jul 2014 10:37:54 -0700
changeset 219331 d6111b0603f590ab5c1d023850a47d8c1c1f365d
parent 219330 154922edf5fed823253f52053f1edd2677e42c9e
child 219332 37fbaf69c6e0767fe9b892dac03f9c5f8477b327
push id583
push userbhearsum@mozilla.com
push dateMon, 24 Nov 2014 19:04:58 +0000
treeherdermozilla-release@c107e74250f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1022229
milestone34.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 1022229 - Let Null Principals have App IDs and mozBrowser status. r=bz
caps/nsNullPrincipal.cpp
caps/nsNullPrincipal.h
--- a/caps/nsNullPrincipal.cpp
+++ b/caps/nsNullPrincipal.cpp
@@ -64,18 +64,22 @@ nsNullPrincipal::nsNullPrincipal()
 
 nsNullPrincipal::~nsNullPrincipal()
 {
 }
 
 #define NS_NULLPRINCIPAL_PREFIX NS_NULLPRINCIPAL_SCHEME ":"
 
 nsresult
-nsNullPrincipal::Init()
+nsNullPrincipal::Init(uint32_t aAppId, bool aInMozBrowser)
 {
+  MOZ_ASSERT(aAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID);
+  mAppId = aAppId;
+  mInMozBrowser = aInMozBrowser;
+
   // FIXME: bug 327161 -- make sure the uuid generator is reseeding-resistant.
   nsresult rv;
   nsCOMPtr<nsIUUIDGenerator> uuidgen =
     do_GetService("@mozilla.org/uuid-generator;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsID id;
   rv = uuidgen->GenerateUUIDInPlace(&id);
@@ -251,31 +255,31 @@ nsNullPrincipal::GetJarPrefix(nsACString
 {
   aJarPrefix.Truncate();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNullPrincipal::GetAppStatus(uint16_t* aAppStatus)
 {
-  *aAppStatus = nsIPrincipal::APP_STATUS_NOT_INSTALLED;
+  *aAppStatus = nsScriptSecurityManager::AppStatusForPrincipal(this);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNullPrincipal::GetAppId(uint32_t* aAppId)
 {
-  *aAppId = nsIScriptSecurityManager::NO_APP_ID;
+  *aAppId = mAppId;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNullPrincipal::GetIsInBrowserElement(bool* aIsInBrowserElement)
 {
-  *aIsInBrowserElement = false;
+  *aIsInBrowserElement = mInMozBrowser;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNullPrincipal::GetUnknownAppId(bool* aUnknownAppId)
 {
   *aUnknownAppId = false;
   return NS_OK;
@@ -296,21 +300,29 @@ nsNullPrincipal::GetBaseDomain(nsACStrin
 }
 
 /**
  * nsISerializable implementation
  */
 NS_IMETHODIMP
 nsNullPrincipal::Read(nsIObjectInputStream* aStream)
 {
-  // no-op: CID is sufficient to create a useful nsNullPrincipal, since the URI
-  // is not really relevant.
+  // Note - nsNullPrincipal use NS_GENERIC_FACTORY_CONSTRUCTOR_INIT, which means
+  // that the Init() method has already been invoked by the time we deserialize.
+  // This is in contrast to nsPrincipal, which uses NS_GENERIC_FACTORY_CONSTRUCTOR,
+  // in which case ::Read needs to invoke Init().
+  nsresult rv = aStream->Read32(&mAppId);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  rv = aStream->ReadBoolean(&mInMozBrowser);
+  NS_ENSURE_SUCCESS(rv, rv);
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNullPrincipal::Write(nsIObjectOutputStream* aStream)
 {
-  // no-op: CID is sufficient to create a useful nsNullPrincipal, since the URI
-  // is not really relevant.
+  aStream->Write32(mAppId);
+  aStream->WriteBoolean(mInMozBrowser);
   return NS_OK;
 }
 
--- a/caps/nsNullPrincipal.h
+++ b/caps/nsNullPrincipal.h
@@ -9,24 +9,25 @@
  * same-origin with anything but themselves.
  */
 
 #ifndef nsNullPrincipal_h__
 #define nsNullPrincipal_h__
 
 #include "nsIPrincipal.h"
 #include "nsJSPrincipals.h"
+#include "nsIScriptSecurityManager.h"
 #include "nsCOMPtr.h"
 #include "nsIContentSecurityPolicy.h"
 
 class nsIURI;
 
 #define NS_NULLPRINCIPAL_CID \
-{ 0xdd156d62, 0xd26f, 0x4441, \
- { 0x9c, 0xdb, 0xe8, 0xf0, 0x91, 0x07, 0xc2, 0x73 } }
+{ 0xa0bd8b42, 0xf6bf, 0x4fb9, \
+  { 0x93, 0x42, 0x90, 0xbf, 0xc9, 0xb7, 0xa1, 0xab } }
 #define NS_NULLPRINCIPAL_CONTRACTID "@mozilla.org/nullprincipal;1"
 
 #define NS_NULLPRINCIPAL_SCHEME "moz-nullprincipal"
 
 class nsNullPrincipal : public nsJSPrincipals
 {
 public:
   nsNullPrincipal();
@@ -36,24 +37,27 @@ public:
 
   // FIXME: bug 327245 -- I sorta wish there were a clean way to share the
   // nsJSPrincipals munging code between the various principal classes without
   // giving up the NS_DECL_NSIPRINCIPAL goodness.
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIPRINCIPAL
   NS_DECL_NSISERIALIZABLE
 
-  nsresult Init();
+  nsresult Init(uint32_t aAppId = nsIScriptSecurityManager::NO_APP_ID,
+                bool aInMozBrowser = false);
 
   virtual void GetScriptLocation(nsACString &aStr) MOZ_OVERRIDE;
 
 #ifdef DEBUG
   virtual void dumpImpl() MOZ_OVERRIDE;
 #endif 
 
  protected:
   virtual ~nsNullPrincipal();
 
   nsCOMPtr<nsIURI> mURI;
   nsCOMPtr<nsIContentSecurityPolicy> mCSP;
+  uint32_t mAppId;
+  bool mInMozBrowser;
 };
 
 #endif // nsNullPrincipal_h__