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_Resource
GetFontFileWithFallback(
21 const PP_BrowserFont_Trusted_Description
* description
,
22 PP_PrivateFontCharset charset
) {
23 // TODO(raymes): Eventually we should replace the use of this function with
24 // either PPB_Flash_Font_File or PPB_TrueType_Font directly in the PDF code.
25 // For now just call into PPB_Flash_Font_File which has the exact same API.
26 EnterResourceCreation
enter(instance
);
29 return enter
.functions()->CreateFlashFontFile(instance
, description
, charset
);
32 bool GetFontTableForPrivateFontFile(PP_Resource font_file
,
35 uint32_t* output_length
) {
36 // TODO(raymes): Eventually we should replace the use of this function with
37 // either PPB_Flash_Font_File or PPB_TrueType_Font directly in the PDF code.
38 // For now just call into PPB_Flash_Font_File which has the exact same API.
39 EnterResource
<PPB_Flash_FontFile_API
> enter(font_file
, true);
42 return PP_ToBool(enter
.object()->GetFontTable(table
, output
, output_length
));
45 void SearchString(PP_Instance instance
,
46 const unsigned short* string
,
47 const unsigned short* term
,
49 PP_PrivateFindResult
** results
,
51 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
54 enter
.functions()->SearchString(string
, term
, case_sensitive
, results
, count
);
57 void DidStartLoading(PP_Instance instance
) {
58 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
59 if (enter
.succeeded())
60 enter
.functions()->DidStartLoading();
63 void DidStopLoading(PP_Instance instance
) {
64 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
65 if (enter
.succeeded())
66 enter
.functions()->DidStopLoading();
69 void SetContentRestriction(PP_Instance instance
, int restrictions
) {
70 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
71 if (enter
.succeeded())
72 enter
.functions()->SetContentRestriction(restrictions
);
75 void UserMetricsRecordAction(PP_Instance instance
, PP_Var action
) {
76 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
77 if (enter
.succeeded())
78 enter
.functions()->UserMetricsRecordAction(action
);
81 void HasUnsupportedFeature(PP_Instance instance
) {
82 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
83 if (enter
.succeeded())
84 enter
.functions()->HasUnsupportedFeature();
87 void SaveAs(PP_Instance instance
) {
88 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
89 if (enter
.succeeded())
90 enter
.functions()->SaveAs();
93 void Print(PP_Instance instance
) {
94 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
95 if (enter
.succeeded())
96 enter
.functions()->Print();
99 PP_Bool
IsFeatureEnabled(PP_Instance instance
, PP_PDFFeature feature
) {
100 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
103 return enter
.functions()->IsFeatureEnabled(feature
);
106 void SetSelectedText(PP_Instance instance
,
107 const char* selected_text
) {
108 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
109 if (enter
.succeeded())
110 enter
.functions()->SetSelectedText(selected_text
);
113 void SetLinkUnderCursor(PP_Instance instance
, const char* url
) {
114 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
117 enter
.functions()->SetLinkUnderCursor(url
);
120 void GetV8ExternalSnapshotData(PP_Instance instance
,
121 const char** natives_data_out
,
122 int* natives_size_out
,
123 const char** snapshot_data_out
,
124 int* snapshot_size_out
) {
125 EnterInstanceAPI
<PPB_PDF_API
> enter(instance
);
128 enter
.functions()->GetV8ExternalSnapshotData(natives_data_out
,
129 natives_size_out
, snapshot_data_out
, snapshot_size_out
);
132 const PPB_PDF g_ppb_pdf_thunk
= {
133 &GetFontFileWithFallback
,
134 &GetFontTableForPrivateFontFile
,
138 &SetContentRestriction
,
139 &UserMetricsRecordAction
,
140 &HasUnsupportedFeature
,
146 &GetV8ExternalSnapshotData
,
151 const PPB_PDF
* GetPPB_PDF_Thunk() {
152 return &g_ppb_pdf_thunk
;