- add sources.
[platform/framework/web/crosswalk.git] / src / ppapi / cpp / trusted / file_chooser_trusted.cc
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.
4
5 #include "ppapi/cpp/trusted/file_chooser_trusted.h"
6
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"
13
14 namespace pp {
15
16 namespace {
17
18 template <> const char* interface_name<PPB_FileChooserTrusted_0_5>() {
19   return PPB_FILECHOOSER_TRUSTED_INTERFACE_0_5;
20 }
21
22 template <> const char* interface_name<PPB_FileChooserTrusted_0_6>() {
23   return PPB_FILECHOOSER_TRUSTED_INTERFACE_0_6;
24 }
25
26 }  // namespace
27
28 FileChooser_Trusted::FileChooser_Trusted() : save_as_(false) {
29 }
30
31 FileChooser_Trusted::FileChooser_Trusted(const InstanceHandle& instance,
32                                          PP_FileChooserMode_Dev mode,
33                                          const Var& accept_types,
34                                          bool save_as,
35                                          const std::string& suggested_file_name)
36     : FileChooser_Dev(instance, mode, accept_types),
37       save_as_(save_as),
38       suggested_file_name_(suggested_file_name) {
39 }
40
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_) {
45 }
46
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_;
52   return *this;
53 }
54
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(
59         pp_resource(),
60         PP_FromBool(save_as_),
61         Var(suggested_file_name_).pp_var(),
62         callback.output(),
63         callback.pp_completion_callback());
64   }
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();
71
72     return get_interface<PPB_FileChooserTrusted_0_5>()->ShowWithoutUserGesture(
73         pp_resource(),
74         PP_FromBool(save_as_),
75         Var(suggested_file_name_).pp_var(),
76         PP_MakeCompletionCallback(&CallbackConverter, data));
77   }
78   return callback.MayForce(PP_ERROR_NOINTERFACE);
79 }
80
81 }  // namespace pp