1 // Copyright (c) 2013 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 "base/logging.h"
6 #include "ppapi/c/pp_errors.h"
7 #include "ppapi/c/private/ppb_pdf.h"
8 #include "ppapi/thunk/enter.h"
9 #include "ppapi/thunk/ppb_flash_font_file_api.h"
10 #include "ppapi/thunk/ppb_pdf_api.h"
11 #include "ppapi/thunk/resource_creation_api.h"
12 #include "ppapi/thunk/thunk.h"
19 PP_Var
GetLocalizedString(PP_Instance instance
, PP_ResourceString string_id
) {
20 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
22 return PP_MakeUndefined();
23 return enter
.functions()->GetLocalizedString(string_id
);
26 PP_Resource
GetFontFileWithFallback(
28 const PP_BrowserFont_Trusted_Description
* description
,
29 PP_PrivateFontCharset charset
) {
30 // TODO(raymes): Eventually we should replace the use of this function with
31 // either PPB_Flash_Font_File or PPB_TrueType_Font directly in the PDF code.
32 // For now just call into PPB_Flash_Font_File which has the exact same API.
33 EnterResourceCreation
enter(instance
);
36 return enter
.functions()->CreateFlashFontFile(instance
, description
, charset
);
39 bool GetFontTableForPrivateFontFile(PP_Resource font_file
,
42 uint32_t* output_length
) {
43 // TODO(raymes): Eventually we should replace the use of this function with
44 // either PPB_Flash_Font_File or PPB_TrueType_Font directly in the PDF code.
45 // For now just call into PPB_Flash_Font_File which has the exact same API.
46 EnterResource
<PPB_Flash_FontFile_API
> enter(font_file
, true);
49 return PP_ToBool(enter
.object()->GetFontTable(table
, output
, output_length
));
52 void SearchString(PP_Instance instance
,
53 const unsigned short* string
,
54 const unsigned short* term
,
56 PP_PrivateFindResult
** results
,
58 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
61 enter
.functions()->SearchString(string
, term
, case_sensitive
, results
, count
);
64 void DidStartLoading(PP_Instance instance
) {
65 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
66 if (enter
.succeeded())
67 enter
.functions()->DidStartLoading();
70 void DidStopLoading(PP_Instance instance
) {
71 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
72 if (enter
.succeeded())
73 enter
.functions()->DidStopLoading();
76 void SetContentRestriction(PP_Instance instance
, int restrictions
) {
77 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
78 if (enter
.succeeded())
79 enter
.functions()->SetContentRestriction(restrictions
);
82 void UserMetricsRecordAction(PP_Instance instance
, PP_Var action
) {
83 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
84 if (enter
.succeeded())
85 enter
.functions()->UserMetricsRecordAction(action
);
88 void HasUnsupportedFeature(PP_Instance instance
) {
89 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
90 if (enter
.succeeded())
91 enter
.functions()->HasUnsupportedFeature();
94 void SaveAs(PP_Instance instance
) {
95 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
96 if (enter
.succeeded())
97 enter
.functions()->SaveAs();
100 void Print(PP_Instance instance
) {
101 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
102 if (enter
.succeeded())
103 enter
.functions()->Print();
106 PP_Bool
IsFeatureEnabled(PP_Instance instance
, PP_PDFFeature feature
) {
107 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
110 return enter
.functions()->IsFeatureEnabled(feature
);
113 void SetSelectedText(PP_Instance instance
,
114 const char* selected_text
) {
115 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
116 if (enter
.succeeded())
117 enter
.functions()->SetSelectedText(selected_text
);
120 void SetLinkUnderCursor(PP_Instance instance
, const char* url
) {
121 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
124 enter
.functions()->SetLinkUnderCursor(url
);
127 void GetV8ExternalSnapshotData(PP_Instance instance
,
128 const char** natives_data_out
,
129 int* natives_size_out
,
130 const char** snapshot_data_out
,
131 int* snapshot_size_out
) {
132 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
135 enter
.functions()->GetV8ExternalSnapshotData(natives_data_out
,
136 natives_size_out
, snapshot_data_out
, snapshot_size_out
);
139 const PPB_PDF g_ppb_pdf_thunk
= {
141 &GetFontFileWithFallback
,
142 &GetFontTableForPrivateFontFile
,
146 &SetContentRestriction
,
147 &UserMetricsRecordAction
,
148 &HasUnsupportedFeature
,
154 &GetV8ExternalSnapshotData
,
159 const PPB_PDF
* GetPPB_PDF_Thunk() {
160 return &g_ppb_pdf_thunk
;