OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/cpp/dev/printing_dev.h" | 5 #include "ppapi/cpp/dev/printing_dev.h" |
6 | 6 |
7 #include "ppapi/c/dev/ppb_printing_dev.h" | 7 #include "ppapi/c/dev/ppb_printing_dev.h" |
8 #include "ppapi/cpp/instance.h" | 8 #include "ppapi/cpp/instance.h" |
9 #include "ppapi/cpp/instance_handle.h" | 9 #include "ppapi/cpp/instance_handle.h" |
10 #include "ppapi/cpp/module.h" | 10 #include "ppapi/cpp/module.h" |
11 #include "ppapi/cpp/module_impl.h" | 11 #include "ppapi/cpp/module_impl.h" |
12 | 12 |
13 namespace pp { | 13 namespace pp { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 static const char kPPPPrintingInterface[] = PPP_PRINTING_DEV_INTERFACE; | 17 static const char kPPPPrintingInterface[] = PPP_PRINTING_DEV_INTERFACE; |
18 | 18 |
| 19 template <> const char* interface_name<PPB_Printing_Dev_0_7>() { |
| 20 return PPB_PRINTING_DEV_INTERFACE_0_7; |
| 21 } |
| 22 |
19 template <> const char* interface_name<PPB_Printing_Dev_0_6>() { | 23 template <> const char* interface_name<PPB_Printing_Dev_0_6>() { |
20 return PPB_PRINTING_DEV_INTERFACE_0_6; | 24 return PPB_PRINTING_DEV_INTERFACE_0_6; |
21 } | 25 } |
22 | 26 |
23 uint32_t QuerySupportedFormats(PP_Instance instance) { | 27 uint32_t QuerySupportedFormats(PP_Instance instance) { |
24 void* object = | 28 void* object = |
25 Instance::GetPerInstanceObject(instance, kPPPPrintingInterface); | 29 Instance::GetPerInstanceObject(instance, kPPPPrintingInterface); |
26 if (!object) | 30 if (!object) |
27 return 0; | 31 return 0; |
28 return static_cast<Printing_Dev*>(object)->QuerySupportedPrintOutputFormats(); | 32 return static_cast<Printing_Dev*>(object)->QuerySupportedPrintOutputFormats(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 &QuerySupportedFormats, | 73 &QuerySupportedFormats, |
70 &Begin, | 74 &Begin, |
71 &PrintPages, | 75 &PrintPages, |
72 &End, | 76 &End, |
73 &IsScalingDisabled | 77 &IsScalingDisabled |
74 }; | 78 }; |
75 | 79 |
76 } // namespace | 80 } // namespace |
77 | 81 |
78 Printing_Dev::Printing_Dev(Instance* instance) | 82 Printing_Dev::Printing_Dev(Instance* instance) |
79 : associated_instance_(instance) { | 83 : associated_instance_(instance) { |
80 Module::Get()->AddPluginInterface(kPPPPrintingInterface, &ppp_printing); | 84 Module::Get()->AddPluginInterface(kPPPPrintingInterface, &ppp_printing); |
81 instance->AddPerInstanceObject(kPPPPrintingInterface, this); | 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())); |
| 90 } |
82 } | 91 } |
83 | 92 |
84 Printing_Dev::~Printing_Dev() { | 93 Printing_Dev::~Printing_Dev() { |
85 Instance::RemovePerInstanceObject(associated_instance_, | 94 Instance::RemovePerInstanceObject(associated_instance_, |
86 kPPPPrintingInterface, this); | 95 kPPPPrintingInterface, this); |
87 } | 96 } |
88 | 97 |
89 // static | 98 // static |
90 bool Printing_Dev::IsAvailable() { | 99 bool Printing_Dev::IsAvailable() { |
91 return has_interface<PPB_Printing_Dev_0_6>(); | 100 return has_interface<PPB_Printing_Dev_0_7>() || |
| 101 has_interface<PPB_Printing_Dev_0_6>(); |
| 102 |
92 } | 103 } |
93 | 104 |
94 bool Printing_Dev::GetDefaultPrintSettings( | 105 void Printing_Dev::GetDefaultPrintSettings( |
95 PP_PrintSettings_Dev* print_settings) const { | 106 const CompletionCallbackWithOutput<PP_PrintSettings_Dev>& callback) const { |
96 if (!has_interface<PPB_Printing_Dev_0_6>()) | 107 if (has_interface<PPB_Printing_Dev_0_7>()) { |
97 return false; | 108 get_interface<PPB_Printing_Dev_0_7>()->GetDefaultPrintSettings( |
98 return PP_ToBool( | 109 pp_resource(), callback.output(), callback.pp_completion_callback()); |
99 get_interface<PPB_Printing_Dev_0_6>()->GetDefaultPrintSettings( | 110 } else if (has_interface<PPB_Printing_Dev_0_6>()) { |
100 associated_instance_.pp_instance(), print_settings)); | 111 bool success = PP_ToBool(get_interface<PPB_Printing_Dev_0_6>()-> |
| 112 GetDefaultPrintSettings(associated_instance_.pp_instance(), |
| 113 callback.output())); |
| 114 Module::Get()->core()->CallOnMainThread(0, callback, |
| 115 success ? PP_OK : PP_ERROR_FAILED); |
| 116 } |
101 } | 117 } |
102 | 118 |
103 } // namespace pp | 119 } // namespace pp |
OLD | NEW |