Add/resurrect support for bundles of WebStore items.
[chromium-blink-merge.git] / ppapi / cpp / dev / printing_dev.cc
blob60154cd0d37f85f58d5e3115322cd56b67c6760d
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"
13 namespace pp {
15 namespace {
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) {
24 void* object =
25 Instance::GetPerInstanceObject(instance, kPPPPrintingInterface);
26 if (!object)
27 return 0;
28 return static_cast<Printing_Dev*>(object)->QuerySupportedPrintOutputFormats();
31 int32_t Begin(PP_Instance instance,
32 const struct PP_PrintSettings_Dev* print_settings) {
33 void* object =
34 Instance::GetPerInstanceObject(instance, kPPPPrintingInterface);
35 if (!object)
36 return 0;
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) {
43 void* object =
44 pp::Instance::GetPerInstanceObject(instance, kPPPPrintingInterface);
45 if (!object)
46 return 0;
47 return static_cast<Printing_Dev*>(object)->PrintPages(
48 page_ranges, page_range_count).detach();
51 void End(PP_Instance instance) {
52 void* object =
53 pp::Instance::GetPerInstanceObject(instance, kPPPPrintingInterface);
54 if (object)
55 static_cast<Printing_Dev*>(object)->PrintEnd();
58 PP_Bool IsScalingDisabled(PP_Instance instance) {
59 void* object =
60 pp::Instance::GetPerInstanceObject(instance, kPPPPrintingInterface);
61 if (!object)
62 return PP_FALSE;
63 bool return_value =
64 static_cast<Printing_Dev*>(object)->IsPrintScalingDisabled();
65 return PP_FromBool(return_value);
68 const PPP_Printing_Dev ppp_printing = {
69 &QuerySupportedFormats,
70 &Begin,
71 &PrintPages,
72 &End,
73 &IsScalingDisabled
76 } // namespace
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);
94 // static
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);
108 } // namespace pp