1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// Copyright (c) 2011 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/dev/printing_dev.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
namespace pp {
namespace {
static const char kPPPPrintingInterface[] = PPP_PRINTING_DEV_INTERFACE;
#ifdef PPP_PRINTING_DEV_USE_0_4
uint32_t QuerySupportedFormats(PP_Instance instance) {
void* object =
pp::Instance::GetPerInstanceObject(instance, kPPPPrintingInterface);
if (!object)
return 0;
return static_cast<Printing_Dev*>(object)->QuerySupportedPrintOutputFormats();
}
#else
PP_PrintOutputFormat_Dev* QuerySupportedFormats(PP_Instance instance,
uint32_t* format_count) {
void* object =
pp::Instance::GetPerInstanceObject(instance, kPPPPrintingInterface);
if (!object)
return NULL;
return static_cast<Printing_Dev*>(object)->QuerySupportedPrintOutputFormats(
format_count);
}
#endif
int32_t Begin(PP_Instance instance,
const struct PP_PrintSettings_Dev* print_settings) {
void* object =
pp::Instance::GetPerInstanceObject(instance, kPPPPrintingInterface);
if (!object)
return 0;
return static_cast<Printing_Dev*>(object)->PrintBegin(*print_settings);
}
PP_Resource PrintPages(PP_Instance instance,
const struct PP_PrintPageNumberRange_Dev* page_ranges,
uint32_t page_range_count) {
void* object =
pp::Instance::GetPerInstanceObject(instance, kPPPPrintingInterface);
if (!object)
return 0;
return static_cast<Printing_Dev*>(object)->PrintPages(
page_ranges, page_range_count).detach();
}
void End(PP_Instance instance) {
void* object =
pp::Instance::GetPerInstanceObject(instance, kPPPPrintingInterface);
if (object)
static_cast<Printing_Dev*>(object)->PrintEnd();
}
const PPP_Printing_Dev ppp_printing = {
&QuerySupportedFormats,
&Begin,
&PrintPages,
&End
};
} // namespace
Printing_Dev::Printing_Dev(Instance* instance)
: associated_instance_(instance) {
pp::Module::Get()->AddPluginInterface(kPPPPrintingInterface, &ppp_printing);
associated_instance_->AddPerInstanceObject(kPPPPrintingInterface, this);
}
Printing_Dev::~Printing_Dev() {
associated_instance_->RemovePerInstanceObject(kPPPPrintingInterface, this);
}
} // namespace pp
|