summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp/dev/file_chooser_dev.h
blob: ec0a6d5625ebfb96019299388e9158b779fe26ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PPAPI_CPP_DEV_FILE_CHOOSER_DEV_H_
#define PPAPI_CPP_DEV_FILE_CHOOSER_DEV_H_

#include "ppapi/c/dev/ppb_file_chooser_dev.h"
#include "ppapi/cpp/resource.h"

namespace pp {

class CompletionCallback;
class FileRef;
class Instance;
class Var;

class FileChooser_Dev : public Resource {
 public:
  /// Creates an is_null() FileChooser object.
  FileChooser_Dev() {}

  /// This function creates a file chooser dialog resource.  The chooser is
  /// associated with a particular instance, so that it may be positioned on the
  /// screen relative to the tab containing the instance.  Returns 0 if passed
  /// an invalid instance.
  ///
  /// @param mode A PPB_FileChooser_Dev instance can be used to select a single
  /// file (PP_FILECHOOSERMODE_OPEN) or multiple files
  /// (PP_FILECHOOSERMODE_OPENMULTIPLE). Unlike the HTML5 <input type="file">
  /// tag, a PPB_FileChooser_Dev instance cannot be used to select a directory.
  /// In order to get the list of files in a directory, the
  /// PPB_DirectoryReader_Dev interface must be used.
  ///
  /// @param accept_mime_types A comma-separated list of MIME types such as
  /// "audio/ *,text/plain" (note there should be no space between the '/' and
  /// the '*', but one is added to avoid confusing C++ comments).  The dialog
  /// may restrict selectable files to the specified MIME types. An empty string
  /// or an undefined var may be given to indicate that all types should be
  /// accepted.
  ///
  /// TODO(darin): What if the mime type is unknown to the system?  The plugin
  /// may wish to describe the mime type and provide a matching file extension.
  /// It is more webby to use mime types here instead of file extensions.
  FileChooser_Dev(const Instance* instance,
                  PP_FileChooserMode_Dev mode,
                  const Var& accept_mime_types);

  FileChooser_Dev(const FileChooser_Dev& other);

  /// This function displays a previously created file chooser resource as a
  /// dialog box, prompting the user to choose a file or files. The callback is
  /// called with PP_OK on successful completion with a file (or files) selected
  /// or PP_ERROR_USERCANCEL if the user selected no file.
  ///
  /// @return PP_OK_COMPLETIONPENDING if request to show the dialog was
  /// successful, another error code from pp_errors.h on failure.
  virtual int32_t Show(const CompletionCallback& cc);

  /// After a successful completion callback call from Show, this method may be
  /// used to query the chosen files.  It should be called in a loop until it
  /// returns an is_null() FileRef.  Depending on the PP_ChooseFileMode
  /// requested when the FileChooser was created, the file refs will either
  /// be readable or writable.  Their file system type will be
  /// PP_FileSystemType_External.  If the user chose no files or cancelled the
  /// dialog, then this method will simply return an is_null() FileRef the
  /// first time it is called.
  virtual FileRef GetNextChosenFile() const;
};

}  // namespace pp

#endif  // PPAPI_CPP_DEV_FILE_CHOOSER_DEV_H_