Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/ipc/FilePickerParent.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_dom_FilePickerParent_h
8
#define mozilla_dom_FilePickerParent_h
9
10
#include "nsIEventTarget.h"
11
#include "nsIFilePicker.h"
12
#include "nsCOMArray.h"
13
#include "nsThreadUtils.h"
14
#include "mozilla/dom/File.h"
15
#include "mozilla/dom/PFilePickerParent.h"
16
17
class nsIFile;
18
19
namespace mozilla {
20
namespace dom {
21
22
class FilePickerParent : public PFilePickerParent
23
{
24
 public:
25
  FilePickerParent(const nsString& aTitle,
26
                   const int16_t& aMode)
27
  : mTitle(aTitle)
28
  , mMode(aMode)
29
  , mResult(nsIFilePicker::returnOK)
30
0
  {}
31
32
  virtual ~FilePickerParent();
33
34
  void Done(int16_t aResult);
35
36
  struct BlobImplOrString
37
  {
38
    RefPtr<BlobImpl> mBlobImpl;
39
    nsString mDirectoryPath;
40
41
    enum {
42
      eBlobImpl,
43
      eDirectoryPath
44
    } mType;
45
  };
46
47
  void SendFilesOrDirectories(const nsTArray<BlobImplOrString>& aData);
48
49
  virtual mozilla::ipc::IPCResult RecvOpen(const int16_t& aSelectedType,
50
                                           const bool& aAddToRecentDocs,
51
                                           const nsString& aDefaultFile,
52
                                           const nsString& aDefaultExtension,
53
                                           InfallibleTArray<nsString>&& aFilters,
54
                                           InfallibleTArray<nsString>&& aFilterNames,
55
                                           const nsString& aDisplayDirectory,
56
                                           const nsString& aDisplaySpecialDirectory,
57
                                           const nsString& aOkButtonLabel) override;
58
59
  virtual void ActorDestroy(ActorDestroyReason aWhy) override;
60
61
  class FilePickerShownCallback : public nsIFilePickerShownCallback
62
  {
63
  public:
64
    explicit FilePickerShownCallback(FilePickerParent* aFilePickerParent)
65
      : mFilePickerParent(aFilePickerParent)
66
0
    { }
67
68
    NS_DECL_ISUPPORTS
69
    NS_DECL_NSIFILEPICKERSHOWNCALLBACK
70
71
    void Destroy();
72
73
  private:
74
0
    virtual ~FilePickerShownCallback() {}
75
    FilePickerParent* mFilePickerParent;
76
  };
77
78
 private:
79
  bool CreateFilePicker();
80
81
  // This runnable is used to do some I/O operation on a separate thread.
82
  class IORunnable : public Runnable
83
  {
84
    FilePickerParent* mFilePickerParent;
85
    nsTArray<nsCOMPtr<nsIFile>> mFiles;
86
    nsTArray<BlobImplOrString> mResults;
87
    nsCOMPtr<nsIEventTarget> mEventTarget;
88
    bool mIsDirectory;
89
90
  public:
91
    IORunnable(FilePickerParent *aFPParent,
92
               nsTArray<nsCOMPtr<nsIFile>>& aFiles,
93
               bool aIsDirectory);
94
95
    bool Dispatch();
96
    NS_IMETHOD Run() override;
97
    void Destroy();
98
  };
99
100
  RefPtr<IORunnable> mRunnable;
101
  RefPtr<FilePickerShownCallback> mCallback;
102
  nsCOMPtr<nsIFilePicker> mFilePicker;
103
104
  nsString mTitle;
105
  int16_t mMode;
106
  int16_t mResult;
107
};
108
109
} // namespace dom
110
} // namespace mozilla
111
112
#endif // mozilla_dom_FilePickerParent_h