1 // Copyright (c) 2012 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 "ppapi/cpp/dev/printing_dev.h"
7 #include "ppapi/c/dev/ppb_printing_dev.h"
8 #include "ppapi/cpp/instance.h"
9 #include "ppapi/cpp/instance_handle.h"
10 #include "ppapi/cpp/module.h"
11 #include "ppapi/cpp/module_impl.h"
17 static const char kPPPPrintingInterface
[] = PPP_PRINTING_DEV_INTERFACE
;
19 template <> const char* interface_name
<PPB_Printing_Dev_0_7
>() {
20 return PPB_PRINTING_DEV_INTERFACE_0_7
;
23 uint32_t QuerySupportedFormats(PP_Instance instance
) {
25 Instance::GetPerInstanceObject(instance
, kPPPPrintingInterface
);
28 return static_cast<Printing_Dev
*>(object
)->QuerySupportedPrintOutputFormats();
31 int32_t Begin(PP_Instance instance
,
32 const struct PP_PrintSettings_Dev
* print_settings
) {
34 Instance::GetPerInstanceObject(instance
, kPPPPrintingInterface
);
37 return static_cast<Printing_Dev
*>(object
)->PrintBegin(*print_settings
);
40 PP_Resource
PrintPages(PP_Instance instance
,
41 const struct PP_PrintPageNumberRange_Dev
* page_ranges
,
42 uint32_t page_range_count
) {
44 pp::Instance::GetPerInstanceObject(instance
, kPPPPrintingInterface
);
47 return static_cast<Printing_Dev
*>(object
)->PrintPages(
48 page_ranges
, page_range_count
).detach();
51 void End(PP_Instance instance
) {
53 pp::Instance::GetPerInstanceObject(instance
, kPPPPrintingInterface
);
55 static_cast<Printing_Dev
*>(object
)->PrintEnd();
58 PP_Bool
IsScalingDisabled(PP_Instance instance
) {
60 pp::Instance::GetPerInstanceObject(instance
, kPPPPrintingInterface
);
64 static_cast<Printing_Dev
*>(object
)->IsPrintScalingDisabled();
65 return PP_FromBool(return_value
);
68 const PPP_Printing_Dev ppp_printing
= {
69 &QuerySupportedFormats
,
78 Printing_Dev::Printing_Dev(Instance
* instance
)
79 : associated_instance_(instance
) {
80 Module::Get()->AddPluginInterface(kPPPPrintingInterface
, &ppp_printing
);
81 instance
->AddPerInstanceObject(
82 kPPPPrintingInterface
, this);
83 if (has_interface
<PPB_Printing_Dev_0_7
>()) {
84 PassRefFromConstructor(get_interface
<PPB_Printing_Dev_0_7
>()->Create(
85 associated_instance_
.pp_instance()));
89 Printing_Dev::~Printing_Dev() {
90 Instance::RemovePerInstanceObject(associated_instance_
,
91 kPPPPrintingInterface
, this);
95 bool Printing_Dev::IsAvailable() {
96 return has_interface
<PPB_Printing_Dev_0_7
>();
99 int32_t Printing_Dev::GetDefaultPrintSettings(
100 const CompletionCallbackWithOutput
<PP_PrintSettings_Dev
>& callback
) const {
101 if (has_interface
<PPB_Printing_Dev_0_7
>()) {
102 return get_interface
<PPB_Printing_Dev_0_7
>()->GetDefaultPrintSettings(
103 pp_resource(), callback
.output(), callback
.pp_completion_callback());
105 return callback
.MayForce(PP_ERROR_NOINTERFACE
);