My first firefox patch

So excited! – Just submitted my first patch for firefox. It was fairly easy, just had to tweak a few things around. Pumped up neverthless. And now there’s this long wait to get the patch reviewed and possibly get it rewritten too. But anyway, it felt good, and I hope to keep going on!.

   nsCOMPtr<nsIURI> uri(aURI);
 
   nsCString uriSpec;
   uri->GetSpec(uriSpec);
   LOG(("WyciwygChannelParent RecvInit [this=%x uri=%s]\n",
        this, uriSpec.get()));
 
+  if(!mChannel)
+	return SendCancelEarly(rv);
+
   nsCOMPtr<nsIIOService> ios(do_GetIOService(&rv));
   if (NS_FAILED(rv))
     return SendCancelEarly(rv);
 
   nsCOMPtr<nsIChannel> chan;
   rv = NS_NewChannel(getter_AddRefs(chan), uri, ios);
   if (NS_FAILED(rv))
     return SendCancelEarly(rv);
@@ -108,65 +111,76 @@ WyciwygChannelParent::RecvInit(const IPC
 
   return true;
 }
 
 bool
 WyciwygChannelParent::RecvAsyncOpen(const IPC::URI& aOriginal,
                                     const PRUint32& aLoadFlags)
 {
-  nsCOMPtr<nsIURI> original(aOriginal);
+  if(mChannel)
+  {
+  	nsCOMPtr<nsIURI> original(aOriginal);
 
-  LOG(("WyciwygChannelParent RecvAsyncOpen [this=%x]\n", this));
+  	LOG(("WyciwygChannelParent RecvAsyncOpen [this=%x]\n", this));
 
-  nsresult rv;
+  	nsresult rv;
 
-  rv = mChannel->SetOriginalURI(original);
-  if (NS_FAILED(rv))
-    return SendCancelEarly(rv);
+  	rv = mChannel->SetOriginalURI(original);
+  	if (NS_FAILED(rv))
+  	  return SendCancelEarly(rv);
 
-  rv = mChannel->SetLoadFlags(aLoadFlags);
-  if (NS_FAILED(rv))
-    return SendCancelEarly(rv);
+  	rv = mChannel->SetLoadFlags(aLoadFlags);
+  	if (NS_FAILED(rv))
+    	return SendCancelEarly(rv);
 
-  rv = mChannel->AsyncOpen(this, nsnull);
-  if (NS_FAILED(rv))
-    return SendCancelEarly(rv);
+  	rv = mChannel->AsyncOpen(this, nsnull);
+  	if (NS_FAILED(rv))
+    	return SendCancelEarly(rv);
 
-  return true;
+  }
+  return true;  
 }
 
 bool
 WyciwygChannelParent::RecvWriteToCacheEntry(const nsString& data)
 {
-  mChannel->WriteToCacheEntry(data);
+  if(mChannel)
+  	mChannel->WriteToCacheEntry(data);
+  	
   return true;
 }
 
 bool
 WyciwygChannelParent::RecvCloseCacheEntry(const nsresult& reason)
 {
-  mChannel->CloseCacheEntry(reason);
+  if(mChannel)
+  	mChannel->CloseCacheEntry(reason);
+  
   return true;
 }
 
 bool
 WyciwygChannelParent::RecvSetCharsetAndSource(const PRInt32& aCharsetSource,
                                               const nsCString& aCharset)
 {
-  mChannel->SetCharsetAndSource(aCharsetSource, aCharset);
+  if(mChannel)
+    mChannel->SetCharsetAndSource(aCharsetSource, aCharset);
+  
   return true;
 }
 
 bool
 WyciwygChannelParent::RecvSetSecurityInfo(const nsCString& aSecurityInfo)
 {
   nsCOMPtr<nsISupports> securityInfo;
   NS_DeserializeObject(aSecurityInfo, getter_AddRefs(securityInfo));
-  mChannel->SetSecurityInfo(securityInfo);
+  if(mChannel)
+  	mChannel->SetSecurityInfo(securityInfo);
+  
   return true;
 }
 
 bool
 WyciwygChannelParent::RecvCancel(const nsresult& aStatusCode)
 {
   if (mChannel)
     mChannel->Cancel(aStatusCode);

PS: The patch got accepted after a few modifications – so there you go – yet another Mozilla contributer.

Advertisements
Standard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s