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
GetResourceImage(PP_Instance instance
,
27 PP_ResourceImage image_id
) {
28 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
31 return enter
.functions()->GetResourceImage(image_id
);
34 PP_Resource
GetFontFileWithFallback(
36 const PP_BrowserFont_Trusted_Description
* description
,
37 PP_PrivateFontCharset charset
) {
38 // TODO(raymes): Eventually we should replace the use of this function with
39 // either PPB_Flash_Font_File or PPB_TrueType_Font directly in the PDF code.
40 // For now just call into PPB_Flash_Font_File which has the exact same API.
41 EnterResourceCreation
enter(instance
);
44 return enter
.functions()->CreateFlashFontFile(instance
, description
, charset
);
47 bool GetFontTableForPrivateFontFile(PP_Resource font_file
,
50 uint32_t* output_length
) {
51 // TODO(raymes): Eventually we should replace the use of this function with
52 // either PPB_Flash_Font_File or PPB_TrueType_Font directly in the PDF code.
53 // For now just call into PPB_Flash_Font_File which has the exact same API.
54 EnterResource
<PPB_Flash_FontFile_API
> enter(font_file
, true);
57 return PP_ToBool(enter
.object()->GetFontTable(table
, output
, output_length
));
60 void SearchString(PP_Instance instance
,
61 const unsigned short* string
,
62 const unsigned short* term
,
64 PP_PrivateFindResult
** results
,
66 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
69 enter
.functions()->SearchString(string
, term
, case_sensitive
, results
, count
);
72 void DidStartLoading(PP_Instance instance
) {
73 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
74 if (enter
.succeeded())
75 enter
.functions()->DidStartLoading();
78 void DidStopLoading(PP_Instance instance
) {
79 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
80 if (enter
.succeeded())
81 enter
.functions()->DidStopLoading();
84 void SetContentRestriction(PP_Instance instance
, int restrictions
) {
85 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
86 if (enter
.succeeded())
87 enter
.functions()->SetContentRestriction(restrictions
);
90 void HistogramPDFPageCount(PP_Instance instance
, int count
) {
91 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
92 if (enter
.succeeded())
93 enter
.functions()->HistogramPDFPageCount(count
);
96 void UserMetricsRecordAction(PP_Instance instance
, PP_Var action
) {
97 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
98 if (enter
.succeeded())
99 enter
.functions()->UserMetricsRecordAction(action
);
102 void HasUnsupportedFeature(PP_Instance instance
) {
103 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
104 if (enter
.succeeded())
105 enter
.functions()->HasUnsupportedFeature();
108 void SaveAs(PP_Instance instance
) {
109 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
110 if (enter
.succeeded())
111 enter
.functions()->SaveAs();
114 void Print(PP_Instance instance
) {
115 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
116 if (enter
.succeeded())
117 enter
.functions()->Print();
120 PP_Bool
IsFeatureEnabled(PP_Instance instance
, PP_PDFFeature feature
) {
121 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
124 return enter
.functions()->IsFeatureEnabled(feature
);
127 PP_Resource
GetResourceImageForScale(PP_Instance instance
,
128 PP_ResourceImage image_id
,
130 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
133 return enter
.functions()->GetResourceImageForScale(image_id
, scale
);
136 PP_Var
ModalPromptForPassword(PP_Instance instance_id
,
138 // TODO(raymes): Implement or remove this function.
140 return PP_MakeUndefined();
143 PP_Bool
IsOutOfProcess(PP_Instance instance
) {
144 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
147 return enter
.functions()->IsOutOfProcess();
150 void SetSelectedText(PP_Instance instance
,
151 const char* selected_text
) {
152 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
153 if (enter
.succeeded())
154 enter
.functions()->SetSelectedText(selected_text
);
157 void SetLinkUnderCursor(PP_Instance instance
, const char* url
) {
158 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
161 enter
.functions()->SetLinkUnderCursor(url
);
164 void GetV8ExternalSnapshotData(PP_Instance instance
,
165 const char** natives_data_out
,
166 int* natives_size_out
,
167 const char** snapshot_data_out
,
168 int* snapshot_size_out
) {
169 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
172 enter
.functions()->GetV8ExternalSnapshotData(natives_data_out
,
173 natives_size_out
, snapshot_data_out
, snapshot_size_out
);
176 const PPB_PDF g_ppb_pdf_thunk
= {
179 &GetFontFileWithFallback
,
180 &GetFontTableForPrivateFontFile
,
184 &SetContentRestriction
,
185 &HistogramPDFPageCount
,
186 &UserMetricsRecordAction
,
187 &HasUnsupportedFeature
,
191 &GetResourceImageForScale
,
192 &ModalPromptForPassword
,
196 &GetV8ExternalSnapshotData
,
201 const PPB_PDF
* GetPPB_PDF_Thunk() {
202 return &g_ppb_pdf_thunk
;