Bug 1028588 - Fix dangerous public destructors in uriloader - r=smaug
authorBenoit Jacob <bjacob@mozilla.com>
Mon, 23 Jun 2014 14:49:09 -0400
changeset 190298 31aa508e8c6d2a72bcf4406b034ba4432da0e898
parent 190297 4ccc78ad6d2ac2d92684501ee74d11e4d52135f8
child 190299 611283da02bfdc691c3dda2ae4b4a31c1c2eba9b
push id7428
push useremorley@mozilla.com
push dateTue, 24 Jun 2014 16:25:20 +0000
treeherderfx-team@309b677152d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1028588
milestone33.0a1
Bug 1028588 - Fix dangerous public destructors in uriloader - r=smaug
uriloader/base/nsURILoader.h
uriloader/exthandler/ExternalHelperAppChild.h
uriloader/exthandler/nsDBusHandlerApp.h
uriloader/exthandler/nsExternalHelperAppService.h
uriloader/exthandler/nsExternalProtocolHandler.cpp
uriloader/exthandler/nsExternalProtocolHandler.h
uriloader/exthandler/nsLocalHandlerApp.h
uriloader/exthandler/nsMIMEInfoImpl.h
uriloader/prefetch/OfflineCacheUpdateChild.h
uriloader/prefetch/OfflineCacheUpdateGlue.h
uriloader/prefetch/OfflineCacheUpdateParent.h
uriloader/prefetch/nsOfflineCacheUpdate.cpp
uriloader/prefetch/nsOfflineCacheUpdate.h
uriloader/prefetch/nsOfflineCacheUpdateService.cpp
uriloader/prefetch/nsPrefetchService.cpp
uriloader/prefetch/nsPrefetchService.h
--- a/uriloader/base/nsURILoader.h
+++ b/uriloader/base/nsURILoader.h
@@ -26,19 +26,20 @@ class nsDocumentOpenInfo;
 
 class nsURILoader MOZ_FINAL : public nsIURILoader
 {
 public:
   NS_DECL_NSIURILOADER
   NS_DECL_ISUPPORTS
 
   nsURILoader();
+
+protected:
   ~nsURILoader();
 
-protected:
   /**
    * Equivalent to nsIURILoader::openChannel, but allows specifying whether the
    * channel is opened already.
    */
   nsresult OpenChannel(nsIChannel* channel,
                                    uint32_t aFlags,
                                    nsIInterfaceRequestor* aWindowContext,
                                    bool aChannelOpen,
--- a/uriloader/exthandler/ExternalHelperAppChild.h
+++ b/uriloader/exthandler/ExternalHelperAppChild.h
@@ -20,24 +20,24 @@ class ExternalHelperAppChild : public PE
                              , public nsIStreamListener
 {
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSISTREAMLISTENER
     NS_DECL_NSIREQUESTOBSERVER
 
     ExternalHelperAppChild();
-    virtual ~ExternalHelperAppChild();
 
     // Give the listener a real nsExternalAppHandler to complete processing on
     // the child.
     void SetHandler(nsExternalAppHandler *handler) { mHandler = handler; }
 
     virtual bool RecvCancel(const nsresult& aStatus) MOZ_OVERRIDE;
 private:
+    virtual ~ExternalHelperAppChild();
     nsresult DivertToParent(nsIDivertableChannel *divertable, nsIRequest *request);
 
     nsRefPtr<nsExternalAppHandler> mHandler;
     nsresult mStatus;
 };
 
 } // namespace dom
 } // namespace mozilla
--- a/uriloader/exthandler/nsDBusHandlerApp.h
+++ b/uriloader/exthandler/nsDBusHandlerApp.h
@@ -14,19 +14,19 @@ class nsDBusHandlerApp : public nsIDBusH
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIHANDLERAPP
   NS_DECL_NSIDBUSHANDLERAPP
 
   nsDBusHandlerApp() { }
 
+protected:
   virtual ~nsDBusHandlerApp() { }
 
-protected:
   nsString mName;
   nsString mDetailedDescription;
   nsCString mService;
   nsCString mMethod;
   nsCString mInterface;
   nsCString mObjpath;
 
 };
--- a/uriloader/exthandler/nsExternalHelperAppService.h
+++ b/uriloader/exthandler/nsExternalHelperAppService.h
@@ -60,17 +60,16 @@ public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIEXTERNALHELPERAPPSERVICE
   NS_DECL_NSPIEXTERNALAPPLAUNCHER
   NS_DECL_NSIEXTERNALPROTOCOLSERVICE
   NS_DECL_NSIMIMESERVICE
   NS_DECL_NSIOBSERVER
 
   nsExternalHelperAppService();
-  virtual ~nsExternalHelperAppService();
 
   /**
    * Initializes internal state. Will be called automatically when
    * this service is first instantiated.
    */
   nsresult Init();
  
   /**
@@ -108,16 +107,18 @@ public:
    */
   virtual nsresult GetFileTokenForPath(const char16_t * platformAppPath,
                                        nsIFile ** aFile);
 
   virtual nsresult OSProtocolHandlerExists(const char *aScheme,
                                                        bool *aExists) = 0;
 
 protected:
+  virtual ~nsExternalHelperAppService();
+
   /**
    * Searches the "extra" array of MIMEInfo objects for an object
    * with a specific type. If found, it will modify the passed-in
    * MIMEInfo. Otherwise, it will return an error and the MIMEInfo
    * will be untouched.
    * @param aContentType The type to search for.
    * @param aMIMEInfo    [inout] The mime info, if found
    */
@@ -221,24 +222,24 @@ public:
    *                       why the request is handled by a helper app.
    */
   nsExternalAppHandler(nsIMIMEInfo * aMIMEInfo, const nsCSubstring& aFileExtension,
                        nsIInterfaceRequestor * aWindowContext,
                        nsExternalHelperAppService * aExtProtSvc,
                        const nsAString& aFilename,
                        uint32_t aReason, bool aForceSave);
 
-  ~nsExternalAppHandler();
-
   /**
    * Clean up after the request was diverted to the parent process.
    */
   void DidDivertRequest(nsIRequest *request);
 
 protected:
+  ~nsExternalAppHandler();
+
   nsCOMPtr<nsIFile> mTempFile;
   nsCOMPtr<nsIURI> mSourceUrl;
   nsString mTempFileExtension;
   nsString mTempLeafName;
 
   /**
    * The MIME Info for this load. Will never be null.
    */
--- a/uriloader/exthandler/nsExternalProtocolHandler.cpp
+++ b/uriloader/exthandler/nsExternalProtocolHandler.cpp
@@ -33,21 +33,22 @@
 class nsExtProtocolChannel : public nsIChannel
 {
 public:
     NS_DECL_THREADSAFE_ISUPPORTS
     NS_DECL_NSICHANNEL
     NS_DECL_NSIREQUEST
 
     nsExtProtocolChannel();
-    virtual ~nsExtProtocolChannel();
 
     nsresult SetURI(nsIURI*);
 
 private:
+    virtual ~nsExtProtocolChannel();
+
     nsresult OpenURL();
     void Finish(nsresult aResult);
     
     nsCOMPtr<nsIURI> mUrl;
     nsCOMPtr<nsIURI> mOriginalURI;
     nsresult mStatus;
     nsLoadFlags mLoadFlags;
     bool mWasOpened;
--- a/uriloader/exthandler/nsExternalProtocolHandler.h
+++ b/uriloader/exthandler/nsExternalProtocolHandler.h
@@ -20,18 +20,19 @@ class nsIURI;
 class nsExternalProtocolHandler MOZ_FINAL : public nsIExternalProtocolHandler, public nsSupportsWeakReference
 {
 public:
 	NS_DECL_THREADSAFE_ISUPPORTS
 	NS_DECL_NSIPROTOCOLHANDLER
 	NS_DECL_NSIEXTERNALPROTOCOLHANDLER
 
 	nsExternalProtocolHandler();
-	~nsExternalProtocolHandler();
 
 protected:
+  ~nsExternalProtocolHandler();
+
   // helper function
   bool HaveExternalProtocolHandler(nsIURI * aURI);
 	nsCString	m_schemeName;
 };
 
 #endif // nsExternalProtocolHandler_h___
 
--- a/uriloader/exthandler/nsLocalHandlerApp.h
+++ b/uriloader/exthandler/nsLocalHandlerApp.h
@@ -21,19 +21,20 @@ public:
 
   nsLocalHandlerApp() { }
 
   nsLocalHandlerApp(const char16_t *aName, nsIFile *aExecutable) 
     : mName(aName), mExecutable(aExecutable) { }
 
   nsLocalHandlerApp(const nsAString & aName, nsIFile *aExecutable) 
     : mName(aName), mExecutable(aExecutable) { }
+
+protected:
   virtual ~nsLocalHandlerApp() { }
 
-protected:
   nsString mName;
   nsString mDetailedDescription;
   nsTArray<nsString> mParameters;
   nsCOMPtr<nsIFile> mExecutable;
   
   /**
    * Launches this application with a single argument (typically either
    * a file path or a URI spec).  This is meant as a helper method for
--- a/uriloader/exthandler/nsMIMEInfoImpl.h
+++ b/uriloader/exthandler/nsMIMEInfoImpl.h
@@ -65,17 +65,16 @@ class nsMIMEInfoBase : public nsIMIMEInf
       eMIMEInfo,
       eProtocolInfo
     };
 
     // nsMIMEInfoBase methods
     nsMIMEInfoBase(const char *aMIMEType = "");
     nsMIMEInfoBase(const nsACString& aMIMEType);
     nsMIMEInfoBase(const nsACString& aType, HandlerClass aClass);
-    virtual ~nsMIMEInfoBase();        // must be virtual, as the the base class's Release should call the subclass's destructor
 
     void SetMIMEType(const nsACString & aMIMEType) { mSchemeOrType = aMIMEType; }
 
     void SetDefaultDescription(const nsString& aDesc) { mDefaultAppDescription = aDesc; }
 
     /**
      * Copies basic data of this MIME Info Implementation to the given other
      * MIME Info. The data consists of the MIME Type, the (default) description,
@@ -87,16 +86,18 @@ class nsMIMEInfoBase : public nsIMIMEInf
     void CopyBasicDataTo(nsMIMEInfoBase* aOther);
 
     /**
      * Return whether this MIMEInfo has any extensions
      */
     bool HasExtensions() const { return mExtensions.Length() != 0; }
 
   protected:
+    virtual ~nsMIMEInfoBase();        // must be virtual, as the the base class's Release should call the subclass's destructor
+
     /**
      * Launch the default application for the given file.
      * For even more control over the launching, override launchWithFile.
      * Also see the comment about nsIMIMEInfo in general, above.
      *
      * @param aFile The file that should be opened
      */
     virtual nsresult LaunchDefaultWithFile(nsIFile* aFile) = 0;
--- a/uriloader/prefetch/OfflineCacheUpdateChild.h
+++ b/uriloader/prefetch/OfflineCacheUpdateChild.h
@@ -37,21 +37,22 @@ public:
             const nsCString& cacheGroupId,
             const nsCString& cacheClientId) MOZ_OVERRIDE;
 
     virtual bool
     RecvFinish(const bool& succeeded,
                const bool& isUpgrade) MOZ_OVERRIDE;
 
     OfflineCacheUpdateChild(nsIDOMWindow* aWindow);
-    ~OfflineCacheUpdateChild();
 
     void SetDocument(nsIDOMDocument *aDocument);
 
 private:
+    ~OfflineCacheUpdateChild();
+
     nsresult AssociateDocument(nsIDOMDocument *aDocument,
                                nsIApplicationCache *aApplicationCache);
     void GatherObservers(nsCOMArray<nsIOfflineCacheUpdateObserver> &aObservers);
     nsresult Finish();
 
     enum {
         STATE_UNINITIALIZED,
         STATE_INITIALIZED,
--- a/uriloader/prefetch/OfflineCacheUpdateGlue.h
+++ b/uriloader/prefetch/OfflineCacheUpdateGlue.h
@@ -55,21 +55,22 @@ public:
                     nsIDOMDocument *aDocument,
                     nsIFile *aCustomProfileDir,
                     uint32_t aAppID,
                     bool aInBrowser);
 
     NS_DECL_NSIOFFLINECACHEUPDATEOBSERVER
 
     OfflineCacheUpdateGlue();
-    ~OfflineCacheUpdateGlue();
 
     void SetDocument(nsIDOMDocument *aDocument);
 
 private:
+    ~OfflineCacheUpdateGlue();
+
     nsRefPtr<nsOfflineCacheUpdate> mUpdate;
 
     /* Document that requested this update */
     nsCOMPtr<nsIDOMDocument> mDocument;
     nsCOMPtr<nsIURI> mDocumentURI;
 };
 
 }
--- a/uriloader/prefetch/OfflineCacheUpdateParent.h
+++ b/uriloader/prefetch/OfflineCacheUpdateParent.h
@@ -42,21 +42,22 @@ public:
 
     void
     StopSendingMessagesToChild()
     {
       mIPCClosed = true;
     }
 
     OfflineCacheUpdateParent(uint32_t aAppId, bool aIsInBrowser);
-    ~OfflineCacheUpdateParent();
 
     virtual void ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
 
 private:
+    ~OfflineCacheUpdateParent();
+
     bool mIPCClosed;
 
     bool     mIsInBrowserElement;
     uint32_t mAppId;
 };
 
 } // namespace docshell
 } // namespace mozilla
--- a/uriloader/prefetch/nsOfflineCacheUpdate.cpp
+++ b/uriloader/prefetch/nsOfflineCacheUpdate.cpp
@@ -137,16 +137,18 @@ public:
     NS_DECL_NSISTREAMLISTENER
     NS_DECL_NSICHANNELEVENTSINK
     NS_DECL_NSIINTERFACEREQUESTOR
 
     nsresult Begin();
 
 private:
 
+    ~nsManifestCheck() {}
+
     static NS_METHOD ReadManifest(nsIInputStream *aInputStream,
                                   void *aClosure,
                                   const char *aFromSegment,
                                   uint32_t aOffset,
                                   uint32_t aCount,
                                   uint32_t *aBytesConsumed);
 
     nsRefPtr<nsOfflineCacheUpdate> mUpdate;
--- a/uriloader/prefetch/nsOfflineCacheUpdate.h
+++ b/uriloader/prefetch/nsOfflineCacheUpdate.h
@@ -53,17 +53,16 @@ public:
     NS_DECL_NSIINTERFACEREQUESTOR
     NS_DECL_NSICHANNELEVENTSINK
 
     nsOfflineCacheUpdateItem(nsIURI *aURI,
                              nsIURI *aReferrerURI,
                              nsIApplicationCache *aApplicationCache,
                              nsIApplicationCache *aPreviousApplicationCache,
                              uint32_t aType);
-    virtual ~nsOfflineCacheUpdateItem();
 
     nsCOMPtr<nsIURI>           mURI;
     nsCOMPtr<nsIURI>           mReferrerURI;
     nsCOMPtr<nsIApplicationCache> mApplicationCache;
     nsCOMPtr<nsIApplicationCache> mPreviousApplicationCache;
     nsCString                  mCacheKey;
     uint32_t                   mItemType;
 
@@ -85,16 +84,18 @@ private:
       LOADED = 3U
     };
 
     nsRefPtr<nsOfflineCacheUpdate> mUpdate;
     nsCOMPtr<nsIChannel>           mChannel;
     uint16_t                       mState;
 
 protected:
+    virtual ~nsOfflineCacheUpdateItem();
+
     int64_t                        mBytesRead;
 };
 
 
 class nsOfflineManifestItem : public nsOfflineCacheUpdateItem
 {
 public:
     NS_DECL_NSISTREAMLISTENER
@@ -201,17 +202,16 @@ class nsOfflineCacheUpdate MOZ_FINAL : p
 public:
     MOZ_DECLARE_REFCOUNTED_TYPENAME(nsOfflineCacheUpdate)
     NS_DECL_ISUPPORTS
     NS_DECL_NSIOFFLINECACHEUPDATE
     NS_DECL_NSIOFFLINECACHEUPDATEOBSERVER
     NS_DECL_NSIRUNNABLE
 
     nsOfflineCacheUpdate();
-    ~nsOfflineCacheUpdate();
 
     static nsresult GetCacheKey(nsIURI *aURI, nsACString &aKey);
 
     nsresult Init();
 
     nsresult Begin();
 
     void LoadCompleted(nsOfflineCacheUpdateItem *aItem);
@@ -221,16 +221,18 @@ public:
 
     void SetOwner(nsOfflineCacheUpdateOwner *aOwner);
 
     bool IsForGroupID(const nsCSubstring &groupID);
 
     virtual nsresult UpdateFinished(nsOfflineCacheUpdate *aUpdate);
 
 protected:
+    ~nsOfflineCacheUpdate();
+
     friend class nsOfflineCacheUpdateItem;
     void OnByteProgress(uint64_t byteIncrement);
 
 private:
     nsresult InitInternal(nsIURI *aManifestURI);
     nsresult HandleManifest(bool *aDoUpdate);
     nsresult AddURI(nsIURI *aURI, uint32_t aItemType);
 
@@ -323,17 +325,16 @@ class nsOfflineCacheUpdateService MOZ_FI
                                             , public nsSupportsWeakReference
 {
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIOFFLINECACHEUPDATESERVICE
     NS_DECL_NSIOBSERVER
 
     nsOfflineCacheUpdateService();
-    ~nsOfflineCacheUpdateService();
 
     nsresult Init();
 
     nsresult ScheduleUpdate(nsOfflineCacheUpdate *aUpdate);
     nsresult FindUpdate(nsIURI *aManifestURI,
                         uint32_t aAppID,
                         bool aInBrowser,
                         nsOfflineCacheUpdate **aUpdate);
@@ -360,16 +361,18 @@ public:
 
     static nsresult OfflineAppPinnedForURI(nsIURI *aDocumentURI,
                                            nsIPrefBranch *aPrefBranch,
                                            bool *aPinned);
 
     static nsTHashtable<nsCStringHashKey>* AllowedDomains();
 
 private:
+    ~nsOfflineCacheUpdateService();
+
     nsresult ProcessNextUpdate();
 
     nsTArray<nsRefPtr<nsOfflineCacheUpdate> > mUpdates;
     static nsTHashtable<nsCStringHashKey>* mAllowedDomains;
 
     bool mDisabled;
     bool mUpdateRunning;
     bool mLowFreeSpace;
--- a/uriloader/prefetch/nsOfflineCacheUpdateService.cpp
+++ b/uriloader/prefetch/nsOfflineCacheUpdateService.cpp
@@ -145,16 +145,18 @@ public:
         , mManifestURI(aManifestURI)
         , mDocumentURI(aDocumentURI)
         , mDidReleaseThis(false)
         {
             mDocument = do_GetWeakReference(aDocument);
         }
 
 private:
+    ~nsOfflineCachePendingUpdate() {}
+
     nsRefPtr<nsOfflineCacheUpdateService> mService;
     nsCOMPtr<nsIURI> mManifestURI;
     nsCOMPtr<nsIURI> mDocumentURI;
     nsCOMPtr<nsIWeakReference> mDocument;
     bool mDidReleaseThis;
 };
 
 NS_IMPL_ISUPPORTS(nsOfflineCachePendingUpdate,
--- a/uriloader/prefetch/nsPrefetchService.cpp
+++ b/uriloader/prefetch/nsPrefetchService.cpp
@@ -70,19 +70,20 @@ PRTimeToSeconds(PRTime t_usec)
 // nsPrefetchQueueEnumerator
 //-----------------------------------------------------------------------------
 class nsPrefetchQueueEnumerator MOZ_FINAL : public nsISimpleEnumerator
 {
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSISIMPLEENUMERATOR
     nsPrefetchQueueEnumerator(nsPrefetchService *aService);
+
+private:
     ~nsPrefetchQueueEnumerator();
 
-private:
     void Increment();
 
     nsRefPtr<nsPrefetchService> mService;
     nsRefPtr<nsPrefetchNode> mCurrent;
     bool mStarted;
 };
 
 //-----------------------------------------------------------------------------
--- a/uriloader/prefetch/nsPrefetchService.h
+++ b/uriloader/prefetch/nsPrefetchService.h
@@ -94,26 +94,26 @@ public:
     NS_DECL_NSICHANNELEVENTSINK
     NS_DECL_NSIREDIRECTRESULTLISTENER
 
     nsPrefetchNode(nsPrefetchService *aPrefetchService,
                    nsIURI *aURI,
                    nsIURI *aReferrerURI,
                    nsIDOMNode *aSource);
 
-    ~nsPrefetchNode() {}
-
     nsresult OpenChannel();
     nsresult CancelChannel(nsresult error);
 
     nsPrefetchNode             *mNext;
     nsCOMPtr<nsIURI>            mURI;
     nsCOMPtr<nsIURI>            mReferrerURI;
     nsCOMPtr<nsIWeakReference>  mSource;
 
 private:
+    ~nsPrefetchNode() {}
+
     nsRefPtr<nsPrefetchService> mService;
     nsCOMPtr<nsIChannel>        mChannel;
     nsCOMPtr<nsIChannel>        mRedirectChannel;
     int64_t                     mBytesRead;
 };
 
 #endif // !nsPrefetchService_h__