Bug 580450 - Clean up IPC::URI. r=dwitte
authorJosh Matthews <josh@joshmatthews.net>
Mon, 26 Jul 2010 15:59:34 -0400
changeset 48842 caec0c83740f1785c8e0f05c58a5fae32ab770eb
parent 48841 6d75d4e390b707a173311581aa68042ff6b5b1fa
child 48843 767706ccb547952b3555063b3b487a97d9f30b6c
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersdwitte
bugs580450
milestone2.0b4pre
Bug 580450 - Clean up IPC::URI. r=dwitte
dom/ipc/ContentChild.cpp
dom/ipc/ContentParent.cpp
extensions/cookie/nsPermissionManager.cpp
netwerk/cookie/CookieServiceParent.cpp
netwerk/ipc/NeckoMessageUtils.h
netwerk/protocol/http/HttpChannelParent.cpp
toolkit/components/places/src/History.cpp
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -346,15 +346,15 @@ ContentChild::RecvNotifyRemotePrefObserv
         ++i;
     }
     return true;
 }
 
 bool
 ContentChild::RecvNotifyVisited(const IPC::URI& aURI)
 {
-    nsCOMPtr<nsIURI> newURI = aURI;
+    nsCOMPtr<nsIURI> newURI(aURI);
     History::GetService()->NotifyVisited(newURI);
     return true;
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -272,17 +272,17 @@ ContentParent::RecvGetChildList(const ns
 bool
 ContentParent::RecvTestPermission(const IPC::URI&  aUri,
                                    const nsCString& aType,
                                    const PRBool&    aExact,
                                    PRUint32*        retValue)
 {
     EnsurePermissionService();
 
-    nsCOMPtr<nsIURI> uri = aUri;
+    nsCOMPtr<nsIURI> uri(aUri);
     if (aExact) {
         mPermissionService->TestExactPermission(uri, aType.get(), retValue);
     } else {
         mPermissionService->TestPermission(uri, aType.get(), retValue);
     }
     return true;
 }
 
@@ -430,41 +430,41 @@ ContentParent::RequestRunToCompletion()
         mShouldCallUnblockChild = true;
     }
     return !!mRunToCompletionDepth;
 }
 
 bool
 ContentParent::RecvStartVisitedQuery(const IPC::URI& aURI)
 {
-    nsCOMPtr<nsIURI> newURI = aURI;
+    nsCOMPtr<nsIURI> newURI(aURI);
     IHistory *history = nsContentUtils::GetHistory(); 
     history->RegisterVisitedCallback(newURI, nsnull);
     return true;
 }
 
 
 bool
 ContentParent::RecvVisitURI(const IPC::URI& uri,
                                    const IPC::URI& referrer,
                                    const PRUint32& flags)
 {
-    nsCOMPtr<nsIURI> ourURI = uri;
-    nsCOMPtr<nsIURI> ourReferrer = referrer;
+    nsCOMPtr<nsIURI> ourURI(uri);
+    nsCOMPtr<nsIURI> ourReferrer(referrer);
     IHistory *history = nsContentUtils::GetHistory(); 
     history->VisitURI(ourURI, ourReferrer, flags);
     return true;
 }
 
 
 bool
 ContentParent::RecvSetURITitle(const IPC::URI& uri,
                                       const nsString& title)
 {
-    nsCOMPtr<nsIURI> ourURI = uri;
+    nsCOMPtr<nsIURI> ourURI(uri);
     IHistory *history = nsContentUtils::GetHistory(); 
     history->SetURITitle(ourURI, title);
     return true;
 }
 
 /* void onDispatchedEvent (in nsIThreadInternal thread); */
 NS_IMETHODIMP
 ContentParent::OnDispatchedEvent(nsIThreadInternal *thread)
--- a/extensions/cookie/nsPermissionManager.cpp
+++ b/extensions/cookie/nsPermissionManager.cpp
@@ -589,32 +589,32 @@ nsPermissionManager::RemoveAllInternal()
 NS_IMETHODIMP
 nsPermissionManager::TestExactPermission(nsIURI     *aURI,
                                          const char *aType,
                                          PRUint32   *aPermission)
 {
 #ifdef MOZ_IPC
   ContentChild* cpc = ChildProcess();
   if (cpc) {
-    return cpc->SendTestPermission(IPC::URI(aURI), nsDependentCString(aType), PR_TRUE,
+    return cpc->SendTestPermission(aURI, nsDependentCString(aType), PR_TRUE,
       aPermission) ? NS_OK : NS_ERROR_FAILURE;
   }
 #endif
   return CommonTestPermission(aURI, aType, aPermission, PR_TRUE);
 }
 
 NS_IMETHODIMP
 nsPermissionManager::TestPermission(nsIURI     *aURI,
                                     const char *aType,
                                     PRUint32   *aPermission)
 {
 #ifdef MOZ_IPC
   ContentChild* cpc = ChildProcess();
   if (cpc) {
-    return cpc->SendTestPermission(IPC::URI(aURI), nsDependentCString(aType), PR_FALSE,
+    return cpc->SendTestPermission(aURI, nsDependentCString(aType), PR_FALSE,
       aPermission) ? NS_OK : NS_ERROR_FAILURE;
   }
 #endif
   return CommonTestPermission(aURI, aType, aPermission, PR_FALSE);
 }
 
 nsresult
 nsPermissionManager::CommonTestPermission(nsIURI     *aURI,
--- a/netwerk/cookie/CookieServiceParent.cpp
+++ b/netwerk/cookie/CookieServiceParent.cpp
@@ -65,18 +65,18 @@ CookieServiceParent::RecvGetCookieString
                                          const bool& aFromHttp,
                                          nsCString* aResult)
 {
   if (!mCookieService)
     return true;
 
   // Deserialize URIs. Having a host URI is mandatory and should always be
   // provided by the child; thus we consider failure fatal.
-  nsCOMPtr<nsIURI> hostURI = aHost;
-  nsCOMPtr<nsIURI> originatingURI = aOriginating;
+  nsCOMPtr<nsIURI> hostURI(aHost);
+  nsCOMPtr<nsIURI> originatingURI(aOriginating);
   if (!hostURI)
     return false;
 
   mCookieService->GetCookieInternal(hostURI, originatingURI,
                                     aFromHttp, *aResult);
   return true;
 }
 
@@ -87,18 +87,18 @@ CookieServiceParent::RecvSetCookieString
                                          const nsCString& aServerTime,
                                          const bool& aFromHttp)
 {
   if (!mCookieService)
     return true;
 
   // Deserialize URIs. Having a host URI is mandatory and should always be
   // provided by the child; thus we consider failure fatal.
-  nsCOMPtr<nsIURI> hostURI = aHost;
-  nsCOMPtr<nsIURI> originatingURI = aOriginating;
+  nsCOMPtr<nsIURI> hostURI(aHost);
+  nsCOMPtr<nsIURI> originatingURI(aOriginating);
   if (!hostURI)
     return false;
 
   mCookieService->SetCookieStringInternal(hostURI, originatingURI,
                                           aCookieString, aServerTime,
                                           aFromHttp);
   return true;
 }
--- a/netwerk/ipc/NeckoMessageUtils.h
+++ b/netwerk/ipc/NeckoMessageUtils.h
@@ -52,25 +52,25 @@ namespace IPC {
 // Since IPDL doesn't have any knowledge of pointers, there's no easy way to
 // pass around nsIURI pointers.  This is a very thin wrapper that IPDL can
 // easily work with, allowing for conversion to and from an nsIURI pointer.
 
 class URI {
  public:
   URI() : mURI(nsnull) {}
   URI(nsIURI* aURI) : mURI(aURI) {}
-  // The contained URI is already addrefed on creation. We don't want another
-  // addref when passing it off to its actual owner.
-  operator nsCOMPtr<nsIURI>() const { return already_AddRefed<nsIURI>(mURI); }
+  operator nsIURI*() const { return mURI.get(); }
 
   friend struct ParamTraits<URI>;
   
  private:
+  // Unimplemented
   URI& operator=(URI&);
-  nsIURI* mURI;
+
+  nsCOMPtr<nsIURI> mURI;
 };
   
 template<>
 struct ParamTraits<URI>
 {
   typedef URI paramType;
   
   static void Write(Message* aMsg, const paramType& aParam)
@@ -131,34 +131,34 @@ struct ParamTraits<URI>
           !ReadParam(aMsg, aIter, &charset))
         return false;
       
       nsCOMPtr<nsIURI> uri;
       nsresult rv = NS_NewURI(getter_AddRefs(uri), spec, charset.get());
       if (NS_FAILED(rv))
         return false;
       
-      uri.forget(&aResult->mURI);
+      uri.swap(aResult->mURI);
       return true;
     }
     
     nsCAutoString cidStr;
     nsCID cid;
     if (!ReadParam(aMsg, aIter, &cidStr) ||
         !cid.Parse(cidStr.get()))
       return false;
 
     nsCOMPtr<nsIURI> uri = do_CreateInstance(cid);
     if (!uri)
       return false;
     nsCOMPtr<nsIIPCSerializable> serializable = do_QueryInterface(uri);
     if (!serializable || !serializable->Read(aMsg, aIter))
       return false;
 
-    uri.forget(&aResult->mURI);
+    uri.swap(aResult->mURI);
     return true;
   }
 
   static void Log(const paramType& aParam, std::wstring* aLog)
   {
     nsIURI* uri = aParam.mURI;
     if (uri) {
       nsCString spec;
--- a/netwerk/protocol/http/HttpChannelParent.cpp
+++ b/netwerk/protocol/http/HttpChannelParent.cpp
@@ -102,21 +102,21 @@ HttpChannelParent::RecvAsyncOpen(const I
                                  const nsHttpAtom&          requestMethod,
                                  const nsCString&           uploadStreamData,
                                  const PRInt32&             uploadStreamInfo,
                                  const PRUint16&            priority,
                                  const PRUint8&             redirectionLimit,
                                  const PRBool&              allowPipelining,
                                  const PRBool&              forceAllowThirdPartyCookie)
 {
-  nsCOMPtr<nsIURI> uri = aURI;
-  nsCOMPtr<nsIURI> originalUri = aOriginalURI;
-  nsCOMPtr<nsIURI> docUri = aDocURI;
-  nsCOMPtr<nsIURI> referrerUri = aReferrerURI;
-  
+  nsCOMPtr<nsIURI> uri(aURI);
+  nsCOMPtr<nsIURI> originalUri(aOriginalURI);
+  nsCOMPtr<nsIURI> docUri(aDocURI);
+  nsCOMPtr<nsIURI> referrerUri(aReferrerURI);
+
   nsCString uriSpec;
   uri->GetSpec(uriSpec);
   LOG(("HttpChannelParent RecvAsyncOpen [this=%x uri=%s]\n", 
        this, uriSpec.get()));
 
   nsresult rv;
 
   nsCOMPtr<nsIIOService> ios(do_GetIOService(&rv));
--- a/toolkit/components/places/src/History.cpp
+++ b/toolkit/components/places/src/History.cpp
@@ -168,17 +168,17 @@ public:
 
 #ifdef MOZ_IPC
   // If we are a content process, always remote the request to the
   // parent process.
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     mozilla::dom::ContentChild * cpc = 
       mozilla::dom::ContentChild::GetSingleton();
     NS_ASSERTION(cpc, "Content Protocol is NULL!");
-    (void)cpc->SendStartVisitedQuery(IPC::URI(aURI));
+    (void)cpc->SendStartVisitedQuery(aURI);
     return NS_OK;
   }
 #endif
 
     nsNavHistory* navHist = nsNavHistory::GetHistoryService();
     NS_ENSURE_TRUE(navHist, NS_ERROR_FAILURE);
     mozIStorageStatement* stmt = navHist->GetStatementById(DB_IS_PAGE_VISITED);
     NS_ENSURE_STATE(stmt);
@@ -979,17 +979,17 @@ History::NotifyVisited(nsIURI* aURI)
 {
   NS_ASSERTION(aURI, "Ruh-roh!  A NULL URI was passed to us!");
 
 #ifdef MOZ_IPC
   if (XRE_GetProcessType() == GeckoProcessType_Default) {
     mozilla::dom::ContentParent* cpp = 
       mozilla::dom::ContentParent::GetSingleton(PR_FALSE);
     if (cpp)
-      (void)cpp->SendNotifyVisited(IPC::URI(aURI));
+      (void)cpp->SendNotifyVisited(aURI);
   }
 #endif
 
   // If the hash table has not been initialized, then we have nothing to notify
   // about.
   if (!mObservers.IsInitialized()) {
     return;
   }
@@ -1084,17 +1084,17 @@ History::VisitURI(nsIURI* aURI,
     return NS_OK;
   }
 
 #ifdef MOZ_IPC
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     mozilla::dom::ContentChild * cpc = 
       mozilla::dom::ContentChild::GetSingleton();
     NS_ASSERTION(cpc, "Content Protocol is NULL!");
-    (void)cpc->SendVisitURI(IPC::URI(aURI), IPC::URI(aLastVisitedURI), aFlags);
+    (void)cpc->SendVisitURI(aURI, aLastVisitedURI, aFlags);
     return NS_OK;
   } 
 #endif /* MOZ_IPC */
 
   nsNavHistory* history = nsNavHistory::GetHistoryService();
   NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
 
   // Silently return if URI is something we shouldn't add to DB.
@@ -1263,17 +1263,17 @@ History::SetURITitle(nsIURI* aURI, const
     return NS_OK;
   }
 
 #ifdef MOZ_IPC
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     mozilla::dom::ContentChild * cpc = 
       mozilla::dom::ContentChild::GetSingleton();
     NS_ASSERTION(cpc, "Content Protocol is NULL!");
-    (void)cpc->SendSetURITitle(IPC::URI(aURI), nsDependentString(aTitle));
+    (void)cpc->SendSetURITitle(aURI, nsDependentString(aTitle));
     return NS_OK;
   } 
 #endif /* MOZ_IPC */
 
   nsNavHistory* history = nsNavHistory::GetHistoryService();
 
   // At first, it seems like nav history should always be available here, no
   // matter what.