• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/c/pp_var.h"
6 #include "ppapi/shared_impl/private/ppb_char_set_shared.h"
7 #include "ppapi/thunk/thunk.h"
8 #include "ppapi/thunk/enter.h"
9 
10 namespace ppapi {
11 namespace thunk {
12 
13 namespace {
14 
UTF16ToCharSetDeprecated(PP_Instance instance,const uint16_t * utf16,uint32_t utf16_len,const char * output_char_set,PP_CharSet_ConversionError on_error,uint32_t * output_length)15 char* UTF16ToCharSetDeprecated(PP_Instance instance,
16                                const uint16_t* utf16, uint32_t utf16_len,
17                                const char* output_char_set,
18                                PP_CharSet_ConversionError on_error,
19                                uint32_t* output_length) {
20   // We validate the instance just to make sure we can make changes in the
21   // future and assume people pass proper instances.
22   EnterInstance enter(instance);
23   if (enter.failed())
24     return NULL;
25 
26   return PPB_CharSet_Shared::UTF16ToCharSetDeprecated(
27       utf16, utf16_len, output_char_set, on_error, output_length);
28 }
29 
UTF16ToCharSet(const uint16_t utf16[],uint32_t utf16_len,const char * output_char_set,PP_CharSet_Trusted_ConversionError on_error,char * output_buffer,uint32_t * output_length)30 PP_Bool UTF16ToCharSet(const uint16_t utf16[],
31                        uint32_t utf16_len,
32                        const char* output_char_set,
33                        PP_CharSet_Trusted_ConversionError on_error,
34                        char* output_buffer,
35                        uint32_t* output_length) {
36   // This interface is a bit odd because it contains a function
37   // (GetDefaultCharSet) that must be called on the instance object and
38   // proxied, but the rest of the functions are implemented in the plugin
39   // process by just calling base functions.
40   //
41   // We could have PPB_Instance_API functions for the two charset conversion
42   // functions, and then have the instance impl and proxy call through to the
43   // shared_impl. That would be more consistent, and we may want to do that if
44   // this file is autogenerated in the future. For now, however, it's less code
45   // to just call the shared_impl code directly here.
46   return PPB_CharSet_Shared::UTF16ToCharSet(
47       utf16, utf16_len, output_char_set, on_error,
48       output_buffer, output_length);
49 }
50 
CharSetToUTF16Deprecated(PP_Instance instance,const char * input,uint32_t input_len,const char * input_char_set,PP_CharSet_ConversionError on_error,uint32_t * output_length)51 uint16_t* CharSetToUTF16Deprecated(PP_Instance instance,
52                                    const char* input, uint32_t input_len,
53                                    const char* input_char_set,
54                                    PP_CharSet_ConversionError on_error,
55                                    uint32_t* output_length) {
56   // We validate the instance just to make sure we can make changes in the
57   // future and assume people pass proper instances.
58   EnterInstance enter(instance);
59   if (enter.failed())
60     return NULL;
61 
62   return PPB_CharSet_Shared::CharSetToUTF16Deprecated(
63       input, input_len, input_char_set, on_error, output_length);
64 }
65 
CharSetToUTF16(const char * input,uint32_t input_len,const char * input_char_set,PP_CharSet_Trusted_ConversionError on_error,uint16_t * output_buffer,uint32_t * output_utf16_length)66 PP_Bool CharSetToUTF16(const char* input,
67                        uint32_t input_len,
68                        const char* input_char_set,
69                        PP_CharSet_Trusted_ConversionError on_error,
70                        uint16_t* output_buffer,
71                        uint32_t* output_utf16_length) {
72   return PPB_CharSet_Shared::CharSetToUTF16(
73       input, input_len, input_char_set, on_error,
74       output_buffer, output_utf16_length);
75 }
76 
GetDefaultCharSet(PP_Instance instance)77 PP_Var GetDefaultCharSet(PP_Instance instance) {
78   EnterInstance enter(instance);
79   if (enter.failed())
80     return PP_MakeUndefined();
81   return enter.functions()->GetDefaultCharSet(instance);
82 }
83 
84 const PPB_CharSet_Dev g_ppb_char_set_thunk = {
85   &UTF16ToCharSetDeprecated,
86   &CharSetToUTF16Deprecated,
87   &GetDefaultCharSet
88 };
89 
90 const PPB_CharSet_Trusted_1_0 g_ppb_char_set_trusted_thunk = {
91   &UTF16ToCharSet,
92   &CharSetToUTF16,
93   &GetDefaultCharSet
94 };
95 
96 }  // namespace
97 
GetPPB_CharSet_Dev_0_4_Thunk()98 const PPB_CharSet_Dev_0_4* GetPPB_CharSet_Dev_0_4_Thunk() {
99   return &g_ppb_char_set_thunk;
100 }
101 
GetPPB_CharSet_Trusted_1_0_Thunk()102 const PPB_CharSet_Trusted_1_0* GetPPB_CharSet_Trusted_1_0_Thunk() {
103   return &g_ppb_char_set_trusted_thunk;
104 }
105 
106 }  // namespace thunk
107 }  // namespace ppapi
108