OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/c/dev/ppb_file_chooser_dev.h" | 5 #include "ppapi/c/dev/ppb_file_chooser_dev.h" |
6 #include "ppapi/c/pp_completion_callback.h" | 6 #include "ppapi/c/pp_completion_callback.h" |
7 #include "ppapi/c/pp_errors.h" | 7 #include "ppapi/c/pp_errors.h" |
8 #include "ppapi/c/trusted/ppb_file_chooser_trusted.h" | 8 #include "ppapi/c/trusted/ppb_file_chooser_trusted.h" |
9 #include "ppapi/shared_impl/var.h" | 9 #include "ppapi/shared_impl/var.h" |
10 #include "ppapi/thunk/common.h" | |
11 #include "ppapi/thunk/enter.h" | 10 #include "ppapi/thunk/enter.h" |
12 #include "ppapi/thunk/thunk.h" | 11 #include "ppapi/thunk/thunk.h" |
13 #include "ppapi/thunk/ppb_file_chooser_api.h" | 12 #include "ppapi/thunk/ppb_file_chooser_api.h" |
14 #include "ppapi/thunk/resource_creation_api.h" | 13 #include "ppapi/thunk/resource_creation_api.h" |
15 | 14 |
16 namespace ppapi { | 15 namespace ppapi { |
17 namespace thunk { | 16 namespace thunk { |
18 | 17 |
19 namespace { | 18 namespace { |
20 | 19 |
21 PP_Resource Create(PP_Instance instance, | 20 PP_Resource Create(PP_Instance instance, |
22 PP_FileChooserMode_Dev mode, | 21 PP_FileChooserMode_Dev mode, |
23 struct PP_Var accept_mime_types) { | 22 struct PP_Var accept_mime_types) { |
24 EnterFunction<ResourceCreationAPI> enter(instance, true); | 23 EnterResourceCreation enter(instance); |
25 if (enter.failed()) | 24 if (enter.failed()) |
26 return 0; | 25 return 0; |
27 scoped_refptr<StringVar> string_var = | 26 scoped_refptr<StringVar> string_var = |
28 StringVar::FromPPVar(accept_mime_types); | 27 StringVar::FromPPVar(accept_mime_types); |
29 std::string str = string_var ? string_var->value() : std::string(); | 28 std::string str = string_var ? string_var->value() : std::string(); |
30 return enter.functions()->CreateFileChooser(instance, mode, str.c_str()); | 29 return enter.functions()->CreateFileChooser(instance, mode, str.c_str()); |
31 } | 30 } |
32 | 31 |
33 PP_Bool IsFileChooser(PP_Resource resource) { | 32 PP_Bool IsFileChooser(PP_Resource resource) { |
34 EnterResource<PPB_FileChooser_API> enter(resource, false); | 33 EnterResource<PPB_FileChooser_API> enter(resource, false); |
35 return PP_FromBool(enter.succeeded()); | 34 return PP_FromBool(enter.succeeded()); |
36 } | 35 } |
37 | 36 |
38 int32_t Show(PP_Resource chooser, PP_CompletionCallback callback) { | 37 int32_t Show(PP_Resource chooser, PP_CompletionCallback callback) { |
39 EnterResource<PPB_FileChooser_API> enter(chooser, true); | 38 EnterResource<PPB_FileChooser_API> enter(chooser, callback, true); |
40 if (enter.failed()) | 39 if (enter.failed()) |
41 return MayForceCallback(callback, PP_ERROR_BADRESOURCE); | 40 return enter.retval(); |
42 int32_t result = enter.object()->Show(callback); | 41 return enter.SetResult(enter.object()->Show(callback)); |
43 return MayForceCallback(callback, result); | |
44 } | 42 } |
45 | 43 |
46 PP_Resource GetNextChosenFile(PP_Resource chooser) { | 44 PP_Resource GetNextChosenFile(PP_Resource chooser) { |
47 EnterResource<PPB_FileChooser_API> enter(chooser, true); | 45 EnterResource<PPB_FileChooser_API> enter(chooser, true); |
48 if (enter.failed()) | 46 if (enter.failed()) |
49 return 0; | 47 return 0; |
50 return enter.object()->GetNextChosenFile(); | 48 return enter.object()->GetNextChosenFile(); |
51 } | 49 } |
52 | 50 |
53 int32_t ShowWithoutUserGesture(PP_Resource chooser, | 51 int32_t ShowWithoutUserGesture(PP_Resource chooser, |
54 PP_Bool save_as, | 52 PP_Bool save_as, |
55 PP_Var suggested_file_name, | 53 PP_Var suggested_file_name, |
56 PP_CompletionCallback callback) { | 54 PP_CompletionCallback callback) { |
57 EnterResource<PPB_FileChooser_API> enter(chooser, true); | 55 EnterResource<PPB_FileChooser_API> enter(chooser, callback, true); |
58 if (enter.failed()) | 56 if (enter.failed()) |
59 return MayForceCallback(callback, PP_ERROR_BADRESOURCE); | 57 return enter.retval(); |
60 scoped_refptr<StringVar> string_var = | 58 scoped_refptr<StringVar> string_var = |
61 StringVar::FromPPVar(suggested_file_name); | 59 StringVar::FromPPVar(suggested_file_name); |
62 std::string str = string_var ? string_var->value() : std::string(); | 60 std::string str = string_var ? string_var->value() : std::string(); |
63 int32_t result = enter.object()->ShowWithoutUserGesture( | 61 return enter.SetResult(enter.object()->ShowWithoutUserGesture( |
64 save_as == PP_TRUE, str.c_str(), callback); | 62 save_as == PP_TRUE, str.c_str(), callback)); |
65 return MayForceCallback(callback, result); | |
66 } | 63 } |
67 | 64 |
68 const PPB_FileChooser_Dev g_ppb_file_chooser_thunk = { | 65 const PPB_FileChooser_Dev g_ppb_file_chooser_thunk = { |
69 &Create, | 66 &Create, |
70 &IsFileChooser, | 67 &IsFileChooser, |
71 &Show, | 68 &Show, |
72 &GetNextChosenFile | 69 &GetNextChosenFile |
73 }; | 70 }; |
74 | 71 |
75 const PPB_FileChooserTrusted g_ppb_file_chooser_trusted_thunk = { | 72 const PPB_FileChooserTrusted g_ppb_file_chooser_trusted_thunk = { |
76 &ShowWithoutUserGesture | 73 &ShowWithoutUserGesture |
77 }; | 74 }; |
78 | 75 |
79 } // namespace | 76 } // namespace |
80 | 77 |
81 const PPB_FileChooser_Dev_0_5* GetPPB_FileChooser_Dev_0_5_Thunk() { | 78 const PPB_FileChooser_Dev_0_5* GetPPB_FileChooser_Dev_0_5_Thunk() { |
82 return &g_ppb_file_chooser_thunk; | 79 return &g_ppb_file_chooser_thunk; |
83 } | 80 } |
84 | 81 |
85 const PPB_FileChooserTrusted_0_5* GetPPB_FileChooser_Trusted_0_5_Thunk() { | 82 const PPB_FileChooserTrusted_0_5* GetPPB_FileChooser_Trusted_0_5_Thunk() { |
86 return &g_ppb_file_chooser_trusted_thunk; | 83 return &g_ppb_file_chooser_trusted_thunk; |
87 } | 84 } |
88 | 85 |
89 } // namespace thunk | 86 } // namespace thunk |
90 } // namespace ppapi | 87 } // namespace ppapi |
OLD | NEW |