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/proxy/ppp_printing_proxy.h" | 5 #include "ppapi/proxy/ppp_printing_proxy.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "ppapi/c/dev/ppp_printing_dev.h" | 9 #include "ppapi/c/dev/ppp_printing_dev.h" |
10 #include "ppapi/proxy/host_dispatcher.h" | 10 #include "ppapi/proxy/host_dispatcher.h" |
11 #include "ppapi/proxy/plugin_dispatcher.h" | 11 #include "ppapi/proxy/plugin_dispatcher.h" |
12 #include "ppapi/proxy/ppapi_messages.h" | 12 #include "ppapi/proxy/ppapi_messages.h" |
13 #include "ppapi/shared_impl/ppapi_globals.h" | 13 #include "ppapi/shared_impl/ppapi_globals.h" |
14 #include "ppapi/shared_impl/proxy_lock.h" | 14 #include "ppapi/shared_impl/proxy_lock.h" |
15 #include "ppapi/shared_impl/resource_tracker.h" | 15 #include "ppapi/shared_impl/resource_tracker.h" |
16 | 16 |
17 namespace ppapi { | 17 namespace ppapi { |
18 namespace proxy { | 18 namespace proxy { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 bool HasPrintingPermission(PP_Instance instance) { | |
23 Dispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | |
24 if (!dispatcher) | |
25 return false; | |
26 return dispatcher->permissions().HasPermission(PERMISSION_DEV); | |
27 } | |
28 | |
29 uint32_t QuerySupportedFormats(PP_Instance instance) { | 22 uint32_t QuerySupportedFormats(PP_Instance instance) { |
30 if (!HasPrintingPermission(instance)) | |
31 return 0; | |
32 | |
33 uint32_t result = 0; | 23 uint32_t result = 0; |
34 HostDispatcher::GetForInstance(instance)->Send( | 24 HostDispatcher::GetForInstance(instance)->Send( |
35 new PpapiMsg_PPPPrinting_QuerySupportedFormats(API_ID_PPP_PRINTING, | 25 new PpapiMsg_PPPPrinting_QuerySupportedFormats(API_ID_PPP_PRINTING, |
36 instance, &result)); | 26 instance, &result)); |
37 return result; | 27 return result; |
38 } | 28 } |
39 | 29 |
40 int32_t Begin(PP_Instance instance, | 30 int32_t Begin(PP_Instance instance, |
41 const struct PP_PrintSettings_Dev* print_settings) { | 31 const struct PP_PrintSettings_Dev* print_settings) { |
42 if (!HasPrintingPermission(instance)) | |
43 return 0; | |
44 | |
45 // Settings is just serialized as a string. | 32 // Settings is just serialized as a string. |
46 std::string settings_string; | 33 std::string settings_string; |
47 settings_string.resize(sizeof(*print_settings)); | 34 settings_string.resize(sizeof(*print_settings)); |
48 memcpy(&settings_string[0], print_settings, sizeof(*print_settings)); | 35 memcpy(&settings_string[0], print_settings, sizeof(*print_settings)); |
49 | 36 |
50 int32_t result = 0; | 37 int32_t result = 0; |
51 HostDispatcher::GetForInstance(instance)->Send( | 38 HostDispatcher::GetForInstance(instance)->Send( |
52 new PpapiMsg_PPPPrinting_Begin(API_ID_PPP_PRINTING, instance, | 39 new PpapiMsg_PPPPrinting_Begin(API_ID_PPP_PRINTING, instance, |
53 settings_string, &result)); | 40 settings_string, &result)); |
54 return result; | 41 return result; |
55 } | 42 } |
56 | 43 |
57 PP_Resource PrintPages(PP_Instance instance, | 44 PP_Resource PrintPages(PP_Instance instance, |
58 const PP_PrintPageNumberRange_Dev* page_ranges, | 45 const PP_PrintPageNumberRange_Dev* page_ranges, |
59 uint32_t page_range_count) { | 46 uint32_t page_range_count) { |
60 if (!HasPrintingPermission(instance)) | |
61 return 0; | |
62 | |
63 std::vector<PP_PrintPageNumberRange_Dev> pages( | 47 std::vector<PP_PrintPageNumberRange_Dev> pages( |
64 page_ranges, page_ranges + page_range_count); | 48 page_ranges, page_ranges + page_range_count); |
65 | 49 |
66 HostResource result; | 50 HostResource result; |
67 HostDispatcher::GetForInstance(instance)->Send( | 51 HostDispatcher::GetForInstance(instance)->Send( |
68 new PpapiMsg_PPPPrinting_PrintPages(API_ID_PPP_PRINTING, | 52 new PpapiMsg_PPPPrinting_PrintPages(API_ID_PPP_PRINTING, |
69 instance, pages, &result)); | 53 instance, pages, &result)); |
70 | 54 |
71 // How refcounting works when returning a resource: | 55 // How refcounting works when returning a resource: |
72 // | 56 // |
73 // The plugin in the plugin process makes a resource that it returns to the | 57 // The plugin in the plugin process makes a resource that it returns to the |
74 // browser. The plugin proxy code returns that ref to us and asynchronously | 58 // browser. The plugin proxy code returns that ref to us and asynchronously |
75 // releases it. Before any release message associated with that operation | 59 // releases it. Before any release message associated with that operation |
76 // comes, we'll get this reply. We need to add one ref since our caller | 60 // comes, we'll get this reply. We need to add one ref since our caller |
77 // expects us to add one ref for it to consume. | 61 // expects us to add one ref for it to consume. |
78 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource( | 62 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource( |
79 result.host_resource()); | 63 result.host_resource()); |
80 return result.host_resource(); | 64 return result.host_resource(); |
81 } | 65 } |
82 | 66 |
83 void End(PP_Instance instance) { | 67 void End(PP_Instance instance) { |
84 if (!HasPrintingPermission(instance)) | |
85 return; | |
86 | |
87 HostDispatcher::GetForInstance(instance)->Send( | 68 HostDispatcher::GetForInstance(instance)->Send( |
88 new PpapiMsg_PPPPrinting_End(API_ID_PPP_PRINTING, instance)); | 69 new PpapiMsg_PPPPrinting_End(API_ID_PPP_PRINTING, instance)); |
89 } | 70 } |
90 | 71 |
91 PP_Bool IsScalingDisabled(PP_Instance instance) { | 72 PP_Bool IsScalingDisabled(PP_Instance instance) { |
92 if (!HasPrintingPermission(instance)) | |
93 return PP_FALSE; | |
94 | |
95 bool result = false; | 73 bool result = false; |
96 HostDispatcher::GetForInstance(instance)->Send( | 74 HostDispatcher::GetForInstance(instance)->Send( |
97 new PpapiMsg_PPPPrinting_IsScalingDisabled(API_ID_PPP_PRINTING, | 75 new PpapiMsg_PPPPrinting_IsScalingDisabled(API_ID_PPP_PRINTING, |
98 instance, &result)); | 76 instance, &result)); |
99 return PP_FromBool(result); | 77 return PP_FromBool(result); |
100 } | 78 } |
101 | 79 |
102 const PPP_Printing_Dev ppp_printing_interface = { | 80 const PPP_Printing_Dev ppp_printing_interface = { |
103 &QuerySupportedFormats, | 81 &QuerySupportedFormats, |
104 &Begin, | 82 &Begin, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 if (ppp_printing_impl_) { | 180 if (ppp_printing_impl_) { |
203 *result = PP_ToBool(CallWhileUnlocked(ppp_printing_impl_->IsScalingDisabled, | 181 *result = PP_ToBool(CallWhileUnlocked(ppp_printing_impl_->IsScalingDisabled, |
204 instance)); | 182 instance)); |
205 } else { | 183 } else { |
206 *result = false; | 184 *result = false; |
207 } | 185 } |
208 } | 186 } |
209 | 187 |
210 } // namespace proxy | 188 } // namespace proxy |
211 } // namespace ppapi | 189 } // namespace ppapi |
OLD | NEW |