Refactor android test results logging.
[chromium-blink-merge.git] / ppapi / cpp / dev / printing_dev.cc
blob8e07194e141c0b5be19d6cb31493e6b8acec7434
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 template <> const char* interface_name<PPB_Printing_Dev_0_6>() {
24 return PPB_PRINTING_DEV_INTERFACE_0_6;
27 uint32_t QuerySupportedFormats(PP_Instance instance) {
28 void* object =
29 Instance::GetPerInstanceObject(instance, kPPPPrintingInterface);
30 if (!object)
31 return 0;
32 return static_cast<Printing_Dev*>(object)->QuerySupportedPrintOutputFormats();
35 int32_t Begin(PP_Instance instance,
36 const struct PP_PrintSettings_Dev* print_settings) {
37 void* object =
38 Instance::GetPerInstanceObject(instance, kPPPPrintingInterface);
39 if (!object)
40 return 0;
41 return static_cast<Printing_Dev*>(object)->PrintBegin(*print_settings);
44 PP_Resource PrintPages(PP_Instance instance,
45 const struct PP_PrintPageNumberRange_Dev* page_ranges,
46 uint32_t page_range_count) {
47 void* object =
48 pp::Instance::GetPerInstanceObject(instance, kPPPPrintingInterface);
49 if (!object)
50 return 0;
51 return static_cast<Printing_Dev*>(object)->PrintPages(
52 page_ranges, page_range_count).detach();
55 void End(PP_Instance instance) {
56 void* object =
57 pp::Instance::GetPerInstanceObject(instance, kPPPPrintingInterface);
58 if (object)
59 static_cast<Printing_Dev*>(object)->PrintEnd();
62 PP_Bool IsScalingDisabled(PP_Instance instance) {
63 void* object =
64 pp::Instance::GetPerInstanceObject(instance, kPPPPrintingInterface);
65 if (!object)
66 return PP_FALSE;
67 bool return_value =
68 static_cast<Printing_Dev*>(object)->IsPrintScalingDisabled();
69 return PP_FromBool(return_value);
72 const PPP_Printing_Dev ppp_printing = {
73 &QuerySupportedFormats,
74 &Begin,
75 &PrintPages,
76 &End,
77 &IsScalingDisabled
80 } // namespace
82 Printing_Dev::Printing_Dev(Instance* instance)
83 : associated_instance_(instance) {
84 Module::Get()->AddPluginInterface(kPPPPrintingInterface, &ppp_printing);
85 instance->AddPerInstanceObject(
86 kPPPPrintingInterface, this);
87 if (has_interface<PPB_Printing_Dev_0_7>()) {
88 PassRefFromConstructor(get_interface<PPB_Printing_Dev_0_7>()->Create(
89 associated_instance_.pp_instance()));
93 Printing_Dev::~Printing_Dev() {
94 Instance::RemovePerInstanceObject(associated_instance_,
95 kPPPPrintingInterface, this);
98 // static
99 bool Printing_Dev::IsAvailable() {
100 return has_interface<PPB_Printing_Dev_0_7>() ||
101 has_interface<PPB_Printing_Dev_0_6>();
105 int32_t Printing_Dev::GetDefaultPrintSettings(
106 const CompletionCallbackWithOutput<PP_PrintSettings_Dev>& callback) const {
107 if (has_interface<PPB_Printing_Dev_0_7>()) {
108 return get_interface<PPB_Printing_Dev_0_7>()->GetDefaultPrintSettings(
109 pp_resource(), callback.output(), callback.pp_completion_callback());
110 } else if (has_interface<PPB_Printing_Dev_0_6>()) {
111 bool success = PP_ToBool(get_interface<PPB_Printing_Dev_0_6>()->
112 GetDefaultPrintSettings(associated_instance_.pp_instance(),
113 callback.output()));
114 return callback.MayForce(success ? PP_OK : PP_ERROR_FAILED);
116 return callback.MayForce(PP_ERROR_NOINTERFACE);
119 } // namespace pp