Bug 1164292 - Re-implement dumpImpl in terms of GetScriptLocation. r=gabor
authorBobby Holley <bobbyholley@gmail.com>
Mon, 11 May 2015 14:17:07 -0700
changeset 264914 2444ca5b01948e383ff4c34b32e533e31da323a0
parent 264913 d99fd0b0a9734668292428d20163eea2e02789a6
child 264915 f9583ef3d16b1b1e29b0fa4388e02799d4ff0bd4
push id2087
push userwcosta@mozilla.com
push dateSun, 17 May 2015 13:14:37 +0000
reviewersgabor
bugs1164292
milestone41.0a1
Bug 1164292 - Re-implement dumpImpl in terms of GetScriptLocation. r=gabor The existing setup adds a lot of complication and not a lot of value.
caps/nsJSPrincipals.cpp
caps/nsJSPrincipals.h
caps/nsNullPrincipal.cpp
caps/nsNullPrincipal.h
caps/nsPrincipal.cpp
caps/nsPrincipal.h
caps/nsSystemPrincipal.cpp
caps/nsSystemPrincipal.h
--- a/caps/nsJSPrincipals.cpp
+++ b/caps/nsJSPrincipals.cpp
@@ -78,17 +78,19 @@ nsJSPrincipals::Destroy(JSPrincipals *js
 
 #ifdef DEBUG
 
 // Defined here so one can do principals->dump() in the debugger
 JS_EXPORT_API(void)
 JSPrincipals::dump()
 {
     if (debugToken == nsJSPrincipals::DEBUG_TOKEN) {
-        static_cast<nsJSPrincipals *>(this)->dumpImpl();
+      nsAutoCString str;
+      static_cast<nsJSPrincipals *>(this)->GetScriptLocation(str);
+      fprintf(stderr, "nsIPrincipal (%p) = %s\n", static_cast<void*>(this), str.get());
     } else if (debugToken == mozilla::dom::workers::kJSPrincipalsDebugToken) {
         fprintf(stderr, "Web Worker principal singleton (%p)\n", this);
     } else {
         fprintf(stderr,
                 "!!! JSPrincipals (%p) is not nsJSPrincipals instance - bad token: "
                 "actual=0x%x expected=0x%x\n",
                 this, unsigned(debugToken), unsigned(nsJSPrincipals::DEBUG_TOKEN));
     }
--- a/caps/nsJSPrincipals.h
+++ b/caps/nsJSPrincipals.h
@@ -38,21 +38,16 @@ public:
     refcount = 0;
     setDebugToken(DEBUG_TOKEN);
   }
 
   /**
    * Return a string that can be used as JS script filename in error reports.
    */
   virtual void GetScriptLocation(nsACString &aStr) = 0;
-
-#ifdef DEBUG
-  virtual void dumpImpl() = 0;
-#endif
-
   static const uint32_t DEBUG_TOKEN = 0x0bf41760;
 
 protected:
   virtual ~nsJSPrincipals() {
     setDebugToken(0);
   }
 
 };
--- a/caps/nsNullPrincipal.cpp
+++ b/caps/nsNullPrincipal.cpp
@@ -70,25 +70,16 @@ nsNullPrincipal::Init(uint32_t aAppId, b
 }
 
 void
 nsNullPrincipal::GetScriptLocation(nsACString &aStr)
 {
   mURI->GetSpec(aStr);
 }
 
-#ifdef DEBUG
-void nsNullPrincipal::dumpImpl()
-{
-  nsAutoCString str;
-  mURI->GetSpec(str);
-  fprintf(stderr, "nsNullPrincipal (%p) = %s\n", this, str.get());
-}
-#endif 
-
 /**
  * nsIPrincipal implementation
  */
 
 NS_IMETHODIMP
 nsNullPrincipal::Equals(nsIPrincipal *aOther, bool *aResult)
 {
   // Just equal to ourselves.  Note that nsPrincipal::Equals will return false
--- a/caps/nsNullPrincipal.h
+++ b/caps/nsNullPrincipal.h
@@ -47,20 +47,16 @@ public:
     Create(uint32_t aAppId = nsIScriptSecurityManager::NO_APP_ID,
            bool aInMozBrowser = false);
 
   nsresult Init(uint32_t aAppId = nsIScriptSecurityManager::NO_APP_ID,
                 bool aInMozBrowser = false);
 
   virtual void GetScriptLocation(nsACString &aStr) override;
 
-#ifdef DEBUG
-  virtual void dumpImpl() override;
-#endif 
-
  protected:
   virtual ~nsNullPrincipal() {}
 
   nsCOMPtr<nsIURI> mURI;
   nsCOMPtr<nsIContentSecurityPolicy> mCSP;
   uint32_t mAppId;
   bool mInMozBrowser;
 };
--- a/caps/nsPrincipal.cpp
+++ b/caps/nsPrincipal.cpp
@@ -63,25 +63,16 @@ nsBasePrincipal::SetCsp(nsIContentSecuri
   // get set anew when a new principal is created.
   if (mCSP)
     return NS_ERROR_ALREADY_INITIALIZED;
 
   mCSP = aCsp;
   return NS_OK;
 }
 
-#ifdef DEBUG
-void nsPrincipal::dumpImpl()
-{
-  nsAutoCString str;
-  GetScriptLocation(str);
-  fprintf(stderr, "nsPrincipal (%p) = %s\n", static_cast<void*>(this), str.get());
-}
-#endif 
-
 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)
@@ -992,23 +983,16 @@ nsExpandedPrincipal::GetScriptLocation(n
     nsJSPrincipals::get(mPrincipals.ElementAt(i))->GetScriptLocation(spec);
 
     aStr.Append(spec);
 
   }
   aStr.Append(")");
 }
 
-#ifdef DEBUG
-void nsExpandedPrincipal::dumpImpl()
-{
-  fprintf(stderr, "nsExpandedPrincipal (%p)\n", static_cast<void*>(this));
-}
-#endif 
-
 //////////////////////////////////////////
 // Methods implementing nsISerializable //
 //////////////////////////////////////////
 
 NS_IMETHODIMP
 nsExpandedPrincipal::Read(nsIObjectInputStream* aStream)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
--- a/caps/nsPrincipal.h
+++ b/caps/nsPrincipal.h
@@ -27,21 +27,16 @@ protected:
 public:
   NS_IMETHOD GetCsp(nsIContentSecurityPolicy** aCsp);
   NS_IMETHOD SetCsp(nsIContentSecurityPolicy* aCsp);
 public:
 
   static const char sInvalid[];
 
 protected:
-
-#ifdef DEBUG
-  virtual void dumpImpl() = 0;
-#endif
-
   nsCOMPtr<nsIContentSecurityPolicy> mCSP;
 };
 
 class nsPrincipal final : public nsBasePrincipal
 {
 public:
   NS_DECL_NSISERIALIZABLE
   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
@@ -58,19 +53,16 @@ public:
   NS_IMETHOD GetJarPrefix(nsACString& aJarPrefix) override;
   NS_IMETHOD GetAppStatus(uint16_t* aAppStatus) override;
   NS_IMETHOD GetAppId(uint32_t* aAppStatus) override;
   NS_IMETHOD GetIsInBrowserElement(bool* aIsInBrowserElement) override;
   NS_IMETHOD GetUnknownAppId(bool* aUnknownAppId) override;
   NS_IMETHOD GetIsNullPrincipal(bool* aIsNullPrincipal) override;
   NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
   virtual bool IsOnCSSUnprefixingWhitelist() override;
-#ifdef DEBUG
-  virtual void dumpImpl() override;
-#endif
 
   nsPrincipal();
 
   // Init() must be called before the principal is in a usable state.
   nsresult Init(nsIURI* aCodebase,
                 uint32_t aAppId,
                 bool aInMozBrowser);
 
@@ -150,20 +142,16 @@ public:
   NS_IMETHOD GetJarPrefix(nsACString& aJarPrefix) override;
   NS_IMETHOD GetAppStatus(uint16_t* aAppStatus) override;
   NS_IMETHOD GetAppId(uint32_t* aAppStatus) override;
   NS_IMETHOD GetIsInBrowserElement(bool* aIsInBrowserElement) override;
   NS_IMETHOD GetUnknownAppId(bool* aUnknownAppId) override;
   NS_IMETHOD GetIsNullPrincipal(bool* aIsNullPrincipal) override;
   NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
   virtual bool IsOnCSSUnprefixingWhitelist() override;
-#ifdef DEBUG
-  virtual void dumpImpl() override;
-#endif
-  
   virtual void GetScriptLocation(nsACString &aStr) override;
 
 private:
   nsTArray< nsCOMPtr<nsIPrincipal> > mPrincipals;
 };
 
 #define NS_PRINCIPAL_CONTRACTID "@mozilla.org/principal;1"
 #define NS_PRINCIPAL_CID \
--- a/caps/nsSystemPrincipal.cpp
+++ b/caps/nsSystemPrincipal.cpp
@@ -32,24 +32,16 @@ NS_IMPL_CI_INTERFACE_GETTER(nsSystemPrin
 static const char SYSTEM_PRINCIPAL_SPEC[] = "[System Principal]";
 
 void
 nsSystemPrincipal::GetScriptLocation(nsACString &aStr)
 {
     aStr.Assign(SYSTEM_PRINCIPAL_SPEC);
 }
 
-#ifdef DEBUG
-void nsSystemPrincipal::dumpImpl()
-{
-  fprintf(stderr, "nsSystemPrincipal (%p)\n", this);
-}
-#endif 
-
-
 ///////////////////////////////////////
 // Methods implementing nsIPrincipal //
 ///////////////////////////////////////
 
 NS_IMETHODIMP
 nsSystemPrincipal::Equals(nsIPrincipal *other, bool *result)
 {
     *result = (other == this);
--- a/caps/nsSystemPrincipal.h
+++ b/caps/nsSystemPrincipal.h
@@ -23,17 +23,13 @@ public:
     NS_DECL_NSIPRINCIPAL
     NS_DECL_NSISERIALIZABLE
     NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
 
     nsSystemPrincipal() {}
 
     virtual void GetScriptLocation(nsACString &aStr) override;
 
-#ifdef DEBUG
-    virtual void dumpImpl() override;
-#endif 
-
 protected:
     virtual ~nsSystemPrincipal(void) {}
 };
 
 #endif // nsSystemPrincipal_h__