• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //    * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //    * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //    * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // ---------------------------------------------------------------------------
31 //
32 // The contents of this file must follow a specific format in order to
33 // support the CEF translator tool. See the translator.README.txt file in the
34 // tools directory for more information.
35 //
36 
37 #ifndef CEF_INCLUDE_CEF_DIALOG_HANDLER_H_
38 #define CEF_INCLUDE_CEF_DIALOG_HANDLER_H_
39 #pragma once
40 
41 #include "include/cef_base.h"
42 #include "include/cef_browser.h"
43 
44 ///
45 // Callback interface for asynchronous continuation of file dialog requests.
46 ///
47 /*--cef(source=library)--*/
48 class CefFileDialogCallback : public virtual CefBaseRefCounted {
49  public:
50   ///
51   // Continue the file selection. |selected_accept_filter| should be the 0-based
52   // index of the value selected from the accept filters array passed to
53   // CefDialogHandler::OnFileDialog. |file_paths| should be a single value or a
54   // list of values depending on the dialog mode. An empty |file_paths| value is
55   // treated the same as calling Cancel().
56   ///
57   /*--cef(capi_name=cont,index_param=selected_accept_filter,
58           optional_param=file_paths)--*/
59   virtual void Continue(int selected_accept_filter,
60                         const std::vector<CefString>& file_paths) = 0;
61 
62   ///
63   // Cancel the file selection.
64   ///
65   /*--cef()--*/
66   virtual void Cancel() = 0;
67 };
68 
69 ///
70 // Implement this interface to handle dialog events. The methods of this class
71 // will be called on the browser process UI thread.
72 ///
73 /*--cef(source=client)--*/
74 class CefDialogHandler : public virtual CefBaseRefCounted {
75  public:
76   typedef cef_file_dialog_mode_t FileDialogMode;
77 
78   ///
79   // Called to run a file chooser dialog. |mode| represents the type of dialog
80   // to display. |title| to the title to be used for the dialog and may be empty
81   // to show the default title ("Open" or "Save" depending on the mode).
82   // |default_file_path| is the path with optional directory and/or file name
83   // component that should be initially selected in the dialog. |accept_filters|
84   // are used to restrict the selectable file types and may any combination of
85   // (a) valid lower-cased MIME types (e.g. "text/*" or "image/*"),
86   // (b) individual file extensions (e.g. ".txt" or ".png"), or (c) combined
87   // description and file extension delimited using "|" and ";" (e.g.
88   // "Image Types|.png;.gif;.jpg"). |selected_accept_filter| is the 0-based
89   // index of the filter that should be selected by default. To display a custom
90   // dialog return true and execute |callback| either inline or at a later time.
91   // To display the default dialog return false.
92   ///
93   /*--cef(optional_param=title,optional_param=default_file_path,
94           optional_param=accept_filters,index_param=selected_accept_filter)--*/
OnFileDialog(CefRefPtr<CefBrowser> browser,FileDialogMode mode,const CefString & title,const CefString & default_file_path,const std::vector<CefString> & accept_filters,int selected_accept_filter,CefRefPtr<CefFileDialogCallback> callback)95   virtual bool OnFileDialog(CefRefPtr<CefBrowser> browser,
96                             FileDialogMode mode,
97                             const CefString& title,
98                             const CefString& default_file_path,
99                             const std::vector<CefString>& accept_filters,
100                             int selected_accept_filter,
101                             CefRefPtr<CefFileDialogCallback> callback) {
102     return false;
103   }
104 };
105 
106 #endif  // CEF_INCLUDE_CEF_DIALOG_HANDLER_H_
107