Add PPAPI C++ wrappers for PDF.
Add C++ wrappers for PDF. The wrappers aren't entirely idiomatic (e.g. there is a case where we just return a PP_Resource instead of wrapping it in an object). This is because of the weird way that the interface is used in the plugin which just makes it more convenient to return the raw resource ID. BUG= Review URL: https://chromiumcodereview.appspot.com/12527012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188909 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
ppapi
160
ppapi/cpp/private/pdf.cc
Normal file
160
ppapi/cpp/private/pdf.cc
Normal file
@ -0,0 +1,160 @@
|
||||
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "ppapi/cpp/private/pdf.h"
|
||||
|
||||
#include "ppapi/cpp/image_data.h"
|
||||
#include "ppapi/cpp/instance_handle.h"
|
||||
#include "ppapi/cpp/module_impl.h"
|
||||
#include "ppapi/cpp/var.h"
|
||||
|
||||
namespace pp {
|
||||
|
||||
namespace {
|
||||
|
||||
template <> const char* interface_name<PPB_PDF>() {
|
||||
return PPB_PDF_INTERFACE;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
bool PDF::IsAvailable() {
|
||||
return has_interface<PPB_PDF>();
|
||||
}
|
||||
|
||||
// static
|
||||
Var PDF::GetLocalizedString(const InstanceHandle& instance,
|
||||
PP_ResourceString string_id) {
|
||||
if (has_interface<PPB_PDF>()) {
|
||||
return Var(PASS_REF,
|
||||
get_interface<PPB_PDF>()->GetLocalizedString(
|
||||
instance.pp_instance(), string_id));
|
||||
}
|
||||
return Var();
|
||||
}
|
||||
|
||||
// static
|
||||
ImageData PDF::GetResourceImage(const InstanceHandle& instance,
|
||||
PP_ResourceImage image_id) {
|
||||
if (has_interface<PPB_PDF>()) {
|
||||
return ImageData(PASS_REF,
|
||||
get_interface<PPB_PDF>()->GetResourceImage(
|
||||
instance.pp_instance(), image_id));
|
||||
}
|
||||
return ImageData();
|
||||
}
|
||||
|
||||
// static
|
||||
PP_Resource PDF::GetFontFileWithFallback(
|
||||
const InstanceHandle& instance,
|
||||
const PP_FontDescription_Dev* description,
|
||||
PP_PrivateFontCharset charset) {
|
||||
if (has_interface<PPB_PDF>()) {
|
||||
return get_interface<PPB_PDF>()->GetFontFileWithFallback(
|
||||
instance.pp_instance(), description, charset);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// static
|
||||
bool PDF::GetFontTableForPrivateFontFile(const InstanceHandle& /*instance*/,
|
||||
PP_Resource font_file,
|
||||
uint32_t table,
|
||||
void* output,
|
||||
uint32_t* output_length) {
|
||||
if (has_interface<PPB_PDF>()) {
|
||||
return get_interface<PPB_PDF>()->GetFontTableForPrivateFontFile(font_file,
|
||||
table, output, output_length);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// static
|
||||
void PDF::SearchString(const InstanceHandle& instance,
|
||||
const unsigned short* string,
|
||||
const unsigned short* term,
|
||||
bool case_sensitive,
|
||||
PP_PrivateFindResult** results,
|
||||
int* count) {
|
||||
if (has_interface<PPB_PDF>()) {
|
||||
get_interface<PPB_PDF>()->SearchString(instance.pp_instance(), string,
|
||||
term, case_sensitive, results, count);
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
void PDF::DidStartLoading(const InstanceHandle& instance) {
|
||||
if (has_interface<PPB_PDF>())
|
||||
get_interface<PPB_PDF>()->DidStartLoading(instance.pp_instance());
|
||||
}
|
||||
|
||||
// static
|
||||
void PDF::DidStopLoading(const InstanceHandle& instance) {
|
||||
if (has_interface<PPB_PDF>())
|
||||
get_interface<PPB_PDF>()->DidStopLoading(instance.pp_instance());
|
||||
}
|
||||
|
||||
// static
|
||||
void PDF::SetContentRestriction(const InstanceHandle& instance,
|
||||
int restrictions) {
|
||||
if (has_interface<PPB_PDF>()) {
|
||||
get_interface<PPB_PDF>()->SetContentRestriction(instance.pp_instance(),
|
||||
restrictions);
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
void PDF::HistogramPDFPageCount(const InstanceHandle& /*instance*/,
|
||||
int count) {
|
||||
if (has_interface<PPB_PDF>())
|
||||
get_interface<PPB_PDF>()->HistogramPDFPageCount(count);
|
||||
}
|
||||
|
||||
// static
|
||||
void PDF::UserMetricsRecordAction(const InstanceHandle& /*instance*/,
|
||||
const Var& action) {
|
||||
if (has_interface<PPB_PDF>())
|
||||
get_interface<PPB_PDF>()->UserMetricsRecordAction(action.pp_var());
|
||||
}
|
||||
|
||||
// static
|
||||
void PDF::HasUnsupportedFeature(const InstanceHandle& instance) {
|
||||
if (has_interface<PPB_PDF>())
|
||||
get_interface<PPB_PDF>()->HasUnsupportedFeature(instance.pp_instance());
|
||||
}
|
||||
|
||||
// static
|
||||
void PDF::SaveAs(const InstanceHandle& instance) {
|
||||
if (has_interface<PPB_PDF>())
|
||||
get_interface<PPB_PDF>()->SaveAs(instance.pp_instance());
|
||||
}
|
||||
|
||||
// static
|
||||
void PDF::Print(const InstanceHandle& instance) {
|
||||
if (has_interface<PPB_PDF>())
|
||||
get_interface<PPB_PDF>()->Print(instance.pp_instance());
|
||||
}
|
||||
|
||||
// static
|
||||
bool PDF::IsFeatureEnabled(const InstanceHandle& /* instance, */,
|
||||
PP_PDFFeature feature) {
|
||||
if (has_interface<PPB_PDF>())
|
||||
return PP_ToBool(get_interface<PPB_PDF>()->IsFeatureEnabled(feature));
|
||||
return false;
|
||||
}
|
||||
|
||||
// static
|
||||
ImageData PDF::GetResourceImageForScale(const InstanceHandle& instance,
|
||||
PP_ResourceImage image_id,
|
||||
float scale) {
|
||||
if (has_interface<PPB_PDF>()) {
|
||||
return ImageData(PASS_REF,
|
||||
get_interface<PPB_PDF>()->GetResourceImageForScale(
|
||||
instance.pp_instance(), image_id, scale));
|
||||
}
|
||||
return ImageData();
|
||||
}
|
||||
|
||||
} // namespace pp
|
62
ppapi/cpp/private/pdf.h
Normal file
62
ppapi/cpp/private/pdf.h
Normal file
@ -0,0 +1,62 @@
|
||||
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef PPAPI_CPP_PRIVATE_PDF_H_
|
||||
#define PPAPI_CPP_PRIVATE_PDF_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ppapi/c/private/ppb_pdf.h"
|
||||
|
||||
namespace pp {
|
||||
|
||||
class ImageData;
|
||||
class InstanceHandle;
|
||||
class Var;
|
||||
|
||||
class PDF {
|
||||
public:
|
||||
// Returns true if the required interface is available.
|
||||
static bool IsAvailable();
|
||||
|
||||
static Var GetLocalizedString(const InstanceHandle& instance,
|
||||
PP_ResourceString string_id);
|
||||
static ImageData GetResourceImage(const InstanceHandle& instance,
|
||||
PP_ResourceImage image_id);
|
||||
static PP_Resource GetFontFileWithFallback(
|
||||
const InstanceHandle& instance,
|
||||
const PP_FontDescription_Dev* description,
|
||||
PP_PrivateFontCharset charset);
|
||||
static bool GetFontTableForPrivateFontFile(const InstanceHandle& instance,
|
||||
PP_Resource font_file,
|
||||
uint32_t table,
|
||||
void* output,
|
||||
uint32_t* output_length);
|
||||
static void SearchString(const InstanceHandle& instance,
|
||||
const unsigned short* string,
|
||||
const unsigned short* term,
|
||||
bool case_sensitive,
|
||||
PP_PrivateFindResult** results,
|
||||
int* count);
|
||||
static void DidStartLoading(const InstanceHandle& instance);
|
||||
static void DidStopLoading(const InstanceHandle& instance);
|
||||
static void SetContentRestriction(const InstanceHandle& instance,
|
||||
int restrictions);
|
||||
static void HistogramPDFPageCount(const InstanceHandle& instance,
|
||||
int count);
|
||||
static void UserMetricsRecordAction(const InstanceHandle& instance,
|
||||
const Var& action);
|
||||
static void HasUnsupportedFeature(const InstanceHandle& instance);
|
||||
static void SaveAs(const InstanceHandle& instance);
|
||||
static void Print(const InstanceHandle& instance);
|
||||
static bool IsFeatureEnabled(const InstanceHandle& instance,
|
||||
PP_PDFFeature feature);
|
||||
static ImageData GetResourceImageForScale(const InstanceHandle& instance,
|
||||
PP_ResourceImage image_id,
|
||||
float scale);
|
||||
};
|
||||
|
||||
} // namespace pp
|
||||
|
||||
#endif // PPAPI_CPP_PRIVATE_PDF_H_
|
@ -299,6 +299,8 @@
|
||||
'cpp/private/network_list_private.h',
|
||||
'cpp/private/network_monitor_private.cc',
|
||||
'cpp/private/network_monitor_private.h',
|
||||
'cpp/private/pdf.cc',
|
||||
'cpp/private/pdf.h',
|
||||
'cpp/private/tcp_server_socket_private.cc',
|
||||
'cpp/private/tcp_server_socket_private.h',
|
||||
'cpp/private/tcp_socket_private.cc',
|
||||
|
Reference in New Issue
Block a user