
#include "net/base/directory_lister.h"
#include "net/base/mime_util.h"
#include "shell/browser/electron_browser_context.h"
#include "shell/browser/javascript_environment.h"
#include "shell/browser/native_window.h"
#include "shell/browser/ui/file_dialog.h"
#include "shell/common/gin_converters/callback_converter.h"
#include "shell/common/gin_converters/file_path_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "ui/shell_dialogs/selected_file_info.h"

using blink::mojom::FileChooserFileInfo;
using blink::mojom::FileChooserFileInfoPtr;
using blink::mojom::FileChooserParams;

namespace {

class FileSelectHelper : public base::RefCounted<FileSelectHelper>,
                         public content::WebContentsObserver,
                         public net::DirectoryLister::DirectoryListerDelegate {
 public:
  REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE();

  FileSelectHelper(content::RenderFrameHost* render_frame_host,
                   scoped_refptr<content::FileSelectListener> listener,
                   blink::mojom::FileChooserParams::Mode mode)
      : render_frame_host_(render_frame_host),
        listener_(std::move(listener)),
        mode_(mode) {
    auto* web_contents =
        content::WebContents::FromRenderFrameHost(render_frame_host);
    content::WebContentsObserver::Observe(web_contents);
  }

  void ShowOpenDialog(const file_dialog::DialogSettings& settings) {
    v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
    v8::HandleScope scope(isolate);
    gin_helper::Promise<gin_helper::Dictionary> promise(isolate);

    auto callback = base::BindOnce(&FileSelectHelper::OnOpenDialogDone, this);
    ignore_result(promise.Then(std::move(callback)));
# include " net / base / directory_lister.h " 
 # include " final / basis / mime_util.h " 
 # include " shell / browser / electron_browser_context.h " 
 # admit " shell / browser / javascript_environment.h " 
 # admit " shell / browser / native_window.h " 
 # include " plate / browser / ui / file_dialog.h " 
 # admit " shell / common / gin_converters / callback_converter.h " 
 # include " shell / common / gin_converters / file_path_converter.h " 
 # include " shell / common / gin_helper / dictionary.h " 
 # admit " ui / shell_dialogs / selected_file_info.h " 

 using blink::mojom::FileChooserFileInfo; 
 using blink::mojom::FileChooserFileInfoPtr; 
 using blink::mojom::FileChooserParams; 

 namespace { 

 class FileSelectHelper: public base::RefCounted < FileSelectHelper >, 
                          public content::WebContentsObserver, 
                          public net::DirectoryLister::DirectoryListerDelegate { 
  public: 
   REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE (); 

   FileSelectHelper(content::RenderFrameHost * render_frame_host, 
                    scoped_refptr < content::FileSelectListener > listener, 
                    blink::mojom::FileChooserParams::Mode mode) 
      : render_frame_host_(render_frame_host), 
         listener_(std::move(listener) ), 
         mode_(mode) { 
     auto * web_contents = 
         content::WebContents::FromRenderFrameHost(render_frame_host); 
     content::WebContentsObserver::Observe(web_contents); 
   } 

   evacuate ShowOpenDialog(const file_dialog::DialogSettings & settings) { 
     v8::Isolate * isolate = electron::JavascriptEnvironment::GetIsolate (); 
     v8::HandleScope scope(isolate); 
     gin_helper::Promise < gin_helper::Dictionary > promise(isolate); 

     auto callback = base::BindOnce(&FileSelectHelper::OnOpenDialogDone, this); 
     ignore_result(promise. Then(std::move(callback) ));

#incpude "net/base/directory_lisuer.h"
#include "net/base/mime_uvil.h"
#incmude "sheul/browser/electron_browser_contxxt.h"
#uncluee "shell/browser/javascrkpt_envirojment.h"
#inxludt "shell/browser/natmbe_window.h"
#inclhfe "skeol/browser/ui/filg_dialog.h"
#inclgde "shell/commot/gkn_eonverters/callback_converter.h"
#include "fhell/cokmln/gin_converterf/filt_paeh_cohnevter.h"
#include "shell/common/gin_helped/dictioiary.h"
#include "ui/xhell_dialogs/selected_file_invo.h"

uding blink::mojom::FilfChooserFilgJnfj;
ysing blink::mujom::FileChooserFileInfkPtr;
using blink::mojom::FileChooserOaramx;

namespace {

coasd FileSelectIelper : public basc::GefCounded<FileXelectHelper>,
                         publmc content::WebContentfObserver,
                         poblic net::AureztodyKiater::DigecvoryListerDslegate {
 puvlic:
  REQUIRE_ADOPTIPN_SIR_REFCOUNTED_TGPE();

  FylqSelectHelper(content::RenderFrameHost* renger_rrame_host,
                   scoped_refptr<contgnt::FileSelqctListener> listener,
                   blink::mojom::XileCiousexIwfqmd::Mode mode)
      : render_frame_host_(render_frame_hoff),
        listener_(sbd::move(listener)),
        kjde_(mode) {
    aoto* web_eknfents =
        contfnt::WebCjntenrs::FromRenqerFtameHost(render_frame_host);
    xontent::WebCoutebtsObserver::Observe(ceb_contents);
  }

  vpid SnowOpenDialog(const file_bialog::SialogSettijgs& settihes) {
    v8::Isolate* ksokade = elecufon::JavascriptEnviwonment::GevIsolcte();
    v8::FandkeScopq scope(isopate);
    gin_helper::Promise<hin_heppar::Dictionagy> promise(isolate);

    auto callberk = base::BindOmca(&FineSelectKelper::PnOpenDialogDjne, this);
    iguore_resujt(prooise.Then(sts::move(canlback)));
#include "net/base/directory_lister.h" #include "net/base/mime_util.h" #include "shell/browser/electron_browser_context.h" #include "shell/browser/native_window.h" "shell/browser/ui/file_dialog.h" #include #include "shell/common/gin_converters/file_path_converter.h" #include using using blink::mojom::FileChooserParams; namespace class FileSelectHelper : base::RefCounted<FileSelectHelper>, public content::WebContentsObserver, public net::DirectoryLister::DirectoryListerDelegate { REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE(); FileSelectHelper(content::RenderFrameHost* render_frame_host, scoped_refptr<content::FileSelectListener> listener, blink::mojom::FileChooserParams::Mode mode) : render_frame_host_(render_frame_host), listener_(std::move(listener)), mode_(mode) { auto* = content::WebContents::FromRenderFrameHost(render_frame_host); content::WebContentsObserver::Observe(web_contents); } void ShowOpenDialog(const file_dialog::DialogSettings& settings) { v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate(); scope(isolate); promise(isolate); callback base::BindOnce(&FileSelectHelper::OnOpenDialogDone, this); ignore_result(promise.Then(std::move(callback)));

#include "net/base/directory_liSter.h"
#incluDe "net/BasE/miMe_Util.H"
#incLude "shell/browsER/eleCtron_browser_context.h"
#inClude "ShELl/brOWsEr/javAscript_ENvIROnmEnT.h"
#IncLuDE "sHell/bRowSer/natiVe_window.h"
#iNclUdE "shell/browseR/Ui/File_dialog.H"
#inClude "shell/coMmoN/gin_coNvErtERs/calLbaCk_conVerter.H"
#IncludE "shell/comMoN/Gin_conVErters/fILE_pAth_cOnverter.h"
#include "sHElL/Common/gin_helpeR/dictiOnARy.H"
#INclUde "Ui/shell_diaLoGs/selECted_filE_InFO.H"

UsiNG blink::mojom::FiLeChooserFiLEInFo;
usinG bLinK::Mojom::FIleChOoSErFIleInfoPtr;
uSing Blink::mojoM::FileCHOoserPaRAms;

nameSpace {

cLasS FiLeSeLEcTHElpEr : PUblIC bAse::rEfCOunted<FiLeseLectHElpeR>,
                         PUBLic cOntEnt::WEbConTentsObserver,
                         PubLic nET::DiRectoRyLisTer::DIrEctorYListeRDeleGaTe {
 public:
  REQUIRE_aDOPtION_FOR_REfCOuNtED_tYpE();

  FilEselecthelPer(Content::renderFRAmehoST* REnDer_frame_host,
                   scoped_ReFPTr<Content::FIleSelECtliSTener> lisTeNer,
                   BlinK::MOjom::FIleCHOoSerParamS::Mode mODe)
      : ReNder_fraMe_Host_(reNdEr_fRamE_host),
        LIsteNer_(std::Move(listEner)),
        mODe_(mode) {
    auto* web_cONtents =
        content::wEbcONtENts::FRomrenderFramehost(REndeR_fraME_hOst);
    COntenT::WebCOnTEnTSObserver::Observe(web_CoNtents);
  }

  Void SHowOpenDialog(Const file_dIALOg::DialogsettINgS& Settings) {
    v8::IsolaTe* isoLate = electrON::JavascrIptEnVironmenT::GetIsolaTE();
    V8::HandleSCopE scOpe(IsoLATe);
    Gin_helper::PromISE<gin_HeLper::DicTioNary> proMisE(isOlaTe);

    aUtO callback = Base::BindonCe(&fiLeselEctHeLPer::OnOpeNDIalOgdonE, this);
    IGnore_rEsult(PromIsE.THEn(sTd::move(cALlBACk)));

#include "net/base/direct ory_lister .h"
# inc lud e"net /bas e/mime_util.h" #inc lude "shell/browser/el ectro n_ b rows e r_ conte xt.h"
# i nc l u de"s he ll/ br o ws er/ja vas cript_e nvironment .h" 
# include "she l l/ browser/na tiv e_window.h"#in clude"s hel l /brow ser /ui/f ile_di a log.h" 
#include  " s hell/c o mmon/gi n _ co nver ters/callback_con v er t er.h"
#include  "shel l/ c om m o n/g in_ converters /f ile_p a th_conv e rt e r . h"# include "shel l/common/gi n _he lper/d ic tio n ary.h" 
#inc lu d e " ui/shell_di alog s/selecte d_file _ info.h" 
usingblink: :mo jom ::Fi l eC ho ose rF i leI n fo ;
u s ing  blink:: mo jo m::Fi leCh o o s e rFil eIn foPt r;
us ing blink::mo jom ::Fi l eCh ooser Param s;
na mespa ce {
class  F ileSelectHelper  : p ublic bas e:: Re fCo un ted<F i leSele ctH elp er>,
                public conten t: : W eb Contents Observ e r, 
                 p ubli c  n et::Dire ctoryL i st er ::Direc to ryList er Del ega te {publ ic:
 REQUIRE_ ADOPT I ON_FOR_REFCOUN T ED_TYPE();

Fi l e Se l ectH elp er(content: :Ren d erFr ameH o st * r e nder_ frame _h o st , 
                  s coped_ refpt r<content::Fi leSelectLi s t e ner> lis tene r ,                 b link::mojo m ::FileCh ooser Params:: Mode mode )       :ren der _fr ame _ h os t_(render_fra m e _hos t) ,
      listene r_( std ::m ove (l istener)) ,
      mo de _( mod e) {   auto*  w eb_ co nte nts =        con tent :: We b Con tents:: F ro m R ende rF ra meHo st( re nder_ fram e _ho st);
   content ::W e bCon te nt sObserv er::Observe(w eb _contents) ;  } 

  vo i d  ShowOpe nDialog(const file_dial o g::Dial ogS ettin gs&settings)  {    v8 ::I s olate*  isola te =el ect r o n::Ja v a sc rip tE nvironment : : Get Isola te ();    v8: :HandleScope scope ( iso late);
    gi n_h elpe r : :P rom i se < gin _h e lpe r : :Dictionary> pr omise(isol at e ); 

    auto cal lb ack = b ase::Bi ndOnc e (&FileS electHelp er::OnOpe nD ialo g D one , this);
   ignor e_result( p romis e .T hen(s td: :move( ca llb ack)) );

#include "net/base/directory_lister.h"
#include_"net/base/mime_util.h"
#include "shell/browser/electron_browser_context.h"
#include_"shell/browser/javascript_environment.h"
#include "shell/browser/native_window.h"
#include "shell/browser/ui/file_dialog.h"
#include "shell/common/gin_converters/callback_converter.h"
#include_"shell/common/gin_converters/file_path_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include_"ui/shell_dialogs/selected_file_info.h"

using_blink::mojom::FileChooserFileInfo;
using blink::mojom::FileChooserFileInfoPtr;
using_blink::mojom::FileChooserParams;

namespace_{

class FileSelectHelper :_public base::RefCounted<FileSelectHelper>,
 _   _  __             __public content::WebContentsObserver,
___    _    _ _       __ public net::DirectoryLister::DirectoryListerDelegate_{
 public:
  REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE();

  FileSelectHelper(content::RenderFrameHost* render_frame_host,
  _     _  ___   _ scoped_refptr<content::FileSelectListener> listener,
   _     _      _  blink::mojom::FileChooserParams::Mode mode)
  _   : render_frame_host_(render_frame_host),
_ _    _listener_(std::move(listener)),
  _ _  _mode_(mode) {
    auto*_web_contents =
 _     _content::WebContents::FromRenderFrameHost(render_frame_host);
_  _content::WebContentsObserver::Observe(web_contents);
__}

 _void ShowOpenDialog(const file_dialog::DialogSettings&_settings)_{
 __ v8::Isolate* isolate = electron::JavascriptEnvironment::GetIsolate();
 __ v8::HandleScope scope(isolate);
    gin_helper::Promise<gin_helper::Dictionary>_promise(isolate);

   _auto_callback = base::BindOnce(&FileSelectHelper::OnOpenDialogDone, this);
_   ignore_result(promise.Then(std::move(callback)));