ozone: DCHECK page_flip_request instead of page_flip_request_
[chromium-blink-merge.git] / ppapi / thunk / ppb_pdf_thunk.cc
blob05c397ce8f9f708bdb51ab2b7c1a60c7424a351a
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"
14 namespace ppapi {
15 namespace thunk {
17 namespace {
19 PP_Var GetLocalizedString(PP_Instance instance, PP_ResourceString string_id) {
20 EnterInstanceAPI<PPB_PDF_API> enter(instance);
21 if (enter.failed())
22 return PP_MakeUndefined();
23 return enter.functions()->GetLocalizedString(string_id);
26 PP_Resource GetFontFileWithFallback(
27 PP_Instance instance,
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);
34 if (enter.failed())
35 return 0;
36 return enter.functions()->CreateFlashFontFile(instance, description, charset);
39 bool GetFontTableForPrivateFontFile(PP_Resource font_file,
40 uint32_t table,
41 void* output,
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);
47 if (enter.failed())
48 return PP_FALSE;
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,
55 bool case_sensitive,
56 PP_PrivateFindResult** results,
57 int* count) {
58 EnterInstanceAPI<PPB_PDF_API> enter(instance);
59 if (enter.failed())
60 return;
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);
108 if (enter.failed())
109 return PP_FALSE;
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);
122 if (enter.failed())
123 return;
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);
133 if (enter.failed())
134 return;
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 = {
140 &GetLocalizedString,
141 &GetFontFileWithFallback,
142 &GetFontTableForPrivateFontFile,
143 &SearchString,
144 &DidStartLoading,
145 &DidStopLoading,
146 &SetContentRestriction,
147 &UserMetricsRecordAction,
148 &HasUnsupportedFeature,
149 &SaveAs,
150 &Print,
151 &IsFeatureEnabled,
152 &SetSelectedText,
153 &SetLinkUnderCursor,
154 &GetV8ExternalSnapshotData,
157 } // namespace
159 const PPB_PDF* GetPPB_PDF_Thunk() {
160 return &g_ppb_pdf_thunk;
163 } // namespace thunk
164 } // namespace ppapi