1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/cpp/trusted/file_chooser_trusted.h"
7 #include "ppapi/c/pp_bool.h"
8 #include "ppapi/cpp/completion_callback.h"
9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/cpp/module_impl.h"
11 #include "ppapi/cpp/var.h"
12 #include "ppapi/c/trusted/ppb_file_chooser_trusted.h"
18 template <> const char* interface_name
<PPB_FileChooserTrusted_0_5
>() {
19 return PPB_FILECHOOSER_TRUSTED_INTERFACE_0_5
;
22 template <> const char* interface_name
<PPB_FileChooserTrusted_0_6
>() {
23 return PPB_FILECHOOSER_TRUSTED_INTERFACE_0_6
;
28 FileChooser_Trusted::FileChooser_Trusted() : save_as_(false) {
31 FileChooser_Trusted::FileChooser_Trusted(const InstanceHandle
& instance
,
32 PP_FileChooserMode_Dev mode
,
33 const Var
& accept_types
,
35 const std::string
& suggested_file_name
)
36 : FileChooser_Dev(instance
, mode
, accept_types
),
38 suggested_file_name_(suggested_file_name
) {
41 FileChooser_Trusted::FileChooser_Trusted(const FileChooser_Trusted
& other
)
42 : FileChooser_Dev(other
),
43 save_as_(other
.save_as_
),
44 suggested_file_name_(other
.suggested_file_name_
) {
47 FileChooser_Trusted
& FileChooser_Trusted::operator=(
48 const FileChooser_Trusted
& other
) {
49 FileChooser_Dev::operator=(other
);
50 save_as_
= other
.save_as_
;
51 suggested_file_name_
= other
.suggested_file_name_
;
55 int32_t FileChooser_Trusted::Show(
56 const CompletionCallbackWithOutput
< std::vector
<FileRef
> >& callback
) {
57 if (has_interface
<PPB_FileChooserTrusted_0_6
>()) {
58 return get_interface
<PPB_FileChooserTrusted_0_6
>()->ShowWithoutUserGesture(
60 PP_FromBool(save_as_
),
61 Var(suggested_file_name_
).pp_var(),
63 callback
.pp_completion_callback());
65 if (has_interface
<PPB_FileChooserTrusted_0_5
>()) {
66 // Data for our callback. The callback handler will delete it.
67 ChooseCallbackData0_5
* data
= new ChooseCallbackData0_5
;
68 data
->file_chooser
= pp_resource();
69 data
->output
= callback
.output();
70 data
->original_callback
= callback
.pp_completion_callback();
72 return get_interface
<PPB_FileChooserTrusted_0_5
>()->ShowWithoutUserGesture(
74 PP_FromBool(save_as_
),
75 Var(suggested_file_name_
).pp_var(),
76 PP_MakeCompletionCallback(&CallbackConverter
, data
));
78 return callback
.MayForce(PP_ERROR_NOINTERFACE
);