Browse Source

chore: call `ListenerDestroyed()` in `FileSelectHelper::RunFileChooserEnd()` (#37006)

chore: call ListenerDestroyed() in FileSelectHelper::RunFileChooserEnd()
Shelley Vohr 2 years ago
parent
commit
afca3ff965
1 changed files with 6 additions and 3 deletions
  1. 6 3
      shell/browser/file_select_helper.cc

+ 6 - 3
shell/browser/file_select_helper.cc

@@ -180,7 +180,7 @@ void FileSelectHelper::OnListDone(int error) {
   std::unique_ptr<ActiveDirectoryEnumeration> entry =
       std::move(directory_enumeration_);
   if (error) {
-    FileSelectionCanceled(NULL);
+    FileSelectionCanceled(nullptr);
     return;
   }
 
@@ -487,6 +487,11 @@ void FileSelectHelper::RunFileChooserEnd() {
     listener_->FileSelectionCanceled();
   render_frame_host_ = nullptr;
   web_contents_ = nullptr;
+  // If the dialog was actually opened, dispose of our reference.
+  if (select_file_dialog_) {
+    select_file_dialog_->ListenerDestroyed();
+    select_file_dialog_.reset();
+  }
   Release();
 }
 
@@ -525,8 +530,6 @@ void FileSelectHelper::RenderWidgetHostDestroyed(
 void FileSelectHelper::RenderFrameHostChanged(
     content::RenderFrameHost* old_host,
     content::RenderFrameHost* new_host) {
-  if (!render_frame_host_)
-    return;
   // The |old_host| and its children are now pending deletion. Do not give them
   // file access past this point.
   for (content::RenderFrameHost* host = render_frame_host_; host;