Bug 1343212 - FilePicker child actor must not send Open() if it has been already distroyed, r=mccr8
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 30 Mar 2017 19:55:55 +0200
changeset 553922 6f7b3c6fd947e8801f3742fddca2fc109b8690f8
parent 553921 e0f0467f930f5eb4ca1ec4cd1c5506fb96442aab
child 553923 40eb77a98bcfbf70cffac94581b0d4ad869b3ded
push id51823
push userbmo:tchiovoloni@mozilla.com
push dateFri, 31 Mar 2017 00:17:03 +0000
reviewersmccr8
bugs1343212
milestone55.0a1
Bug 1343212 - FilePicker child actor must not send Open() if it has been already distroyed, r=mccr8
widget/nsFilePickerProxy.cpp
widget/nsFilePickerProxy.h
--- a/widget/nsFilePickerProxy.cpp
+++ b/widget/nsFilePickerProxy.cpp
@@ -13,16 +13,17 @@
 #include "mozilla/dom/ipc/BlobChild.h"
 
 using namespace mozilla::dom;
 
 NS_IMPL_ISUPPORTS(nsFilePickerProxy, nsIFilePicker)
 
 nsFilePickerProxy::nsFilePickerProxy()
   : mSelectedType(0)
+  , mIPCActive(false)
 {
 }
 
 nsFilePickerProxy::~nsFilePickerProxy()
 {
 }
 
 NS_IMETHODIMP
@@ -35,16 +36,18 @@ nsFilePickerProxy::Init(mozIDOMWindowPro
   }
 
   mParent = nsPIDOMWindowOuter::From(aParent);
 
   mMode = aMode;
 
   NS_ADDREF_THIS();
   tabChild->SendPFilePickerConstructor(this, nsString(aTitle), aMode);
+
+  mIPCActive = true;
   return NS_OK;
 }
 
 void
 nsFilePickerProxy::InitNative(nsIWidget* aParent, const nsAString& aTitle)
 {
 }
 
@@ -131,16 +134,20 @@ nsFilePickerProxy::Open(nsIFilePickerSho
 {
   mCallback = aCallback;
 
   nsString displayDirectory;
   if (mDisplayDirectory) {
     mDisplayDirectory->GetPath(displayDirectory);
   }
 
+  if (!mIPCActive) {
+    return NS_ERROR_FAILURE;
+  }
+
   SendOpen(mSelectedType, mAddToRecentDocs, mDefault, mDefaultExtension,
            mFilters, mFilterNames, displayDirectory, mOkButtonLabel);
 
   return NS_OK;
 }
 
 mozilla::ipc::IPCResult
 nsFilePickerProxy::Recv__delete__(const MaybeInputData& aData,
@@ -266,8 +273,19 @@ NS_IMPL_ISUPPORTS(SimpleEnumerator, nsIS
 NS_IMETHODIMP
 nsFilePickerProxy::GetDomFileOrDirectoryEnumerator(nsISimpleEnumerator** aDomfiles)
 {
   RefPtr<SimpleEnumerator> enumerator =
     new SimpleEnumerator(mFilesOrDirectories);
   enumerator.forget(aDomfiles);
   return NS_OK;
 }
+
+void
+nsFilePickerProxy::ActorDestroy(ActorDestroyReason aWhy)
+{
+  mIPCActive = false;
+
+  if (mCallback) {
+    mCallback->Done(nsIFilePicker::returnCancel);
+    mCallback = nullptr;
+  }
+}
--- a/widget/nsFilePickerProxy.h
+++ b/widget/nsFilePickerProxy.h
@@ -55,21 +55,26 @@ public:
     // PFilePickerChild
     virtual mozilla::ipc::IPCResult
     Recv__delete__(const MaybeInputData& aData, const int16_t& aResult) override;
 
 private:
     ~nsFilePickerProxy();
     void InitNative(nsIWidget*, const nsAString&) override;
 
+    void
+    ActorDestroy(ActorDestroyReason aWhy) override;
+
     nsTArray<mozilla::dom::OwningFileOrDirectory> mFilesOrDirectories;
     nsCOMPtr<nsIFilePickerShownCallback> mCallback;
 
     int16_t   mSelectedType;
     nsString  mFile;
     nsString  mDefault;
     nsString  mDefaultExtension;
 
+    bool mIPCActive;
+
     InfallibleTArray<nsString> mFilters;
     InfallibleTArray<nsString> mFilterNames;
 };
 
 #endif // NSFILEPICKERPROXY_H