Bug 1164292 - Rebrand nsBasePrincipal into mozilla::BasePrincipal and give it its own file. r=gabor
authorBobby Holley <bobbyholley@gmail.com>
Mon, 11 May 2015 14:25:59 -0700
changeset 264915 f9583ef3d16b1b1e29b0fa4388e02799d4ff0bd4
parent 264914 2444ca5b01948e383ff4c34b32e533e31da323a0
child 264916 1f283549fee9060c305c98333fd091c472874898
push id2087
push userwcosta@mozilla.com
push dateSun, 17 May 2015 13:14:37 +0000
reviewersgabor
bugs1164292
milestone41.0a1
Bug 1164292 - Rebrand nsBasePrincipal into mozilla::BasePrincipal and give it its own file. r=gabor The goal here is to provide a common superclass for _all_ the principal implementations, rather than just nsPrincipal and nsExpandedPrincipal.
caps/BasePrincipal.cpp
caps/BasePrincipal.h
caps/moz.build
caps/nsPrincipal.cpp
caps/nsPrincipal.h
new file mode 100644
--- /dev/null
+++ b/caps/BasePrincipal.cpp
@@ -0,0 +1,30 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 sw=2 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/BasePrincipal.h"
+
+namespace mozilla {
+
+NS_IMETHODIMP
+BasePrincipal::GetCsp(nsIContentSecurityPolicy** aCsp)
+{
+  NS_IF_ADDREF(*aCsp = mCSP);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+BasePrincipal::SetCsp(nsIContentSecurityPolicy* aCsp)
+{
+  // If CSP was already set, it should not be destroyed!  Instead, it should
+  // get set anew when a new principal is created.
+  if (mCSP)
+    return NS_ERROR_ALREADY_INITIALIZED;
+
+  mCSP = aCsp;
+  return NS_OK;
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/caps/BasePrincipal.h
@@ -0,0 +1,37 @@
+/* -*- 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_BasePrincipal_h
+#define mozilla_BasePrincipal_h
+
+#include "nsIPrincipal.h"
+#include "nsJSPrincipals.h"
+
+namespace mozilla {
+
+/*
+ * Base class from which all nsIPrincipal implementations inherit. Use this for
+ * default implementations and other commonalities between principal
+ * implementations.
+ *
+ * We should merge nsJSPrincipals into this class at some point.
+ */
+class BasePrincipal : public nsJSPrincipals
+{
+public:
+  BasePrincipal() {}
+  NS_IMETHOD GetCsp(nsIContentSecurityPolicy** aCsp);
+  NS_IMETHOD SetCsp(nsIContentSecurityPolicy* aCsp);
+
+protected:
+  virtual ~BasePrincipal() {}
+
+  nsCOMPtr<nsIContentSecurityPolicy> mCSP;
+};
+
+} // namespace mozilla
+
+#endif /* mozilla_BasePrincipal_h */
--- a/caps/moz.build
+++ b/caps/moz.build
@@ -15,17 +15,22 @@ XPIDL_SOURCES += [
 XPIDL_MODULE = 'caps'
 
 EXPORTS += [
     'nsJSPrincipals.h',
     'nsNullPrincipal.h',
     'nsNullPrincipalURI.h',
 ]
 
+EXPORTS.mozilla = [
+    'BasePrincipal.h'
+]
+
 UNIFIED_SOURCES += [
+    'BasePrincipal.cpp',
     'DomainPolicy.cpp',
     'nsJSPrincipals.cpp',
     'nsNullPrincipal.cpp',
     'nsNullPrincipalURI.cpp',
     'nsPrincipal.cpp',
     'nsScriptSecurityManager.cpp',
     'nsSystemPrincipal.cpp',
 ]
--- a/caps/nsPrincipal.cpp
+++ b/caps/nsPrincipal.cpp
@@ -41,38 +41,16 @@ static bool URIIsImmutable(nsIURI* aURI)
   nsCOMPtr<nsIMutable> mutableObj(do_QueryInterface(aURI));
   bool isMutable;
   return
     mutableObj &&
     NS_SUCCEEDED(mutableObj->GetMutable(&isMutable)) &&
     !isMutable;
 }
 
-// Static member variables
-const char nsBasePrincipal::sInvalid[] = "Invalid";
-
-NS_IMETHODIMP
-nsBasePrincipal::GetCsp(nsIContentSecurityPolicy** aCsp)
-{
-  NS_IF_ADDREF(*aCsp = mCSP);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsBasePrincipal::SetCsp(nsIContentSecurityPolicy* aCsp)
-{
-  // If CSP was already set, it should not be destroyed!  Instead, it should
-  // get set anew when a new principal is created.
-  if (mCSP)
-    return NS_ERROR_ALREADY_INITIALIZED;
-
-  mCSP = aCsp;
-  return NS_OK;
-}
-
 NS_IMPL_CLASSINFO(nsPrincipal, nullptr, nsIClassInfo::MAIN_THREAD_ONLY,
                   NS_PRINCIPAL_CID)
 NS_IMPL_QUERY_INTERFACE_CI(nsPrincipal,
                            nsIPrincipal,
                            nsISerializable)
 NS_IMPL_CI_INTERFACE_GETTER(nsPrincipal,
                             nsIPrincipal,
                             nsISerializable)
--- a/caps/nsPrincipal.h
+++ b/caps/nsPrincipal.h
@@ -10,37 +10,19 @@
 #include "nsCOMPtr.h"
 #include "nsJSPrincipals.h"
 #include "nsTArray.h"
 #include "nsAutoPtr.h"
 #include "nsIContentSecurityPolicy.h"
 #include "nsIProtocolHandler.h"
 #include "nsNetUtil.h"
 #include "nsScriptSecurityManager.h"
-
-class nsBasePrincipal : public nsJSPrincipals
-{
-public:
-  nsBasePrincipal() {}
-
-protected:
-  virtual ~nsBasePrincipal() {}
+#include "mozilla/BasePrincipal.h"
 
-public:
-  NS_IMETHOD GetCsp(nsIContentSecurityPolicy** aCsp);
-  NS_IMETHOD SetCsp(nsIContentSecurityPolicy* aCsp);
-public:
-
-  static const char sInvalid[];
-
-protected:
-  nsCOMPtr<nsIContentSecurityPolicy> mCSP;
-};
-
-class nsPrincipal final : public nsBasePrincipal
+class nsPrincipal final : public mozilla::BasePrincipal
 {
 public:
   NS_DECL_NSISERIALIZABLE
   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
   NS_IMETHOD Equals(nsIPrincipal* other, bool* _retval) override;
   NS_IMETHOD EqualsConsideringDomain(nsIPrincipal* other, bool* _retval) override;
   NS_IMETHOD GetHashValue(uint32_t* aHashValue) override;
   NS_IMETHOD GetURI(nsIURI** aURI) override;
@@ -110,17 +92,17 @@ protected:
   virtual ~nsPrincipal();
 
   /**
    * Returns the app status of the principal based on mAppId and mInMozBrowser.
    */
   uint16_t GetAppStatus();
 };
 
-class nsExpandedPrincipal : public nsIExpandedPrincipal, public nsBasePrincipal
+class nsExpandedPrincipal : public nsIExpandedPrincipal, public mozilla::BasePrincipal
 {
 public:
   explicit nsExpandedPrincipal(nsTArray< nsCOMPtr<nsIPrincipal> > &aWhiteList);
 
 protected:
   virtual ~nsExpandedPrincipal();
 
 public: