Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: ppapi/proxy/ppp_printing_proxy.cc

Issue 11365235: Add PPAPI permissions for file chooser, PDF, testing, video capture, and video decode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/ppb_video_decoder_proxy.cc ('k') | webkit/plugins/ppapi/plugin_module.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
22 uint32_t QuerySupportedFormats(PP_Instance instance) { 29 uint32_t QuerySupportedFormats(PP_Instance instance) {
30 if (!HasPrintingPermission(instance))
31 return 0;
32
23 uint32_t result = 0; 33 uint32_t result = 0;
24 HostDispatcher::GetForInstance(instance)->Send( 34 HostDispatcher::GetForInstance(instance)->Send(
25 new PpapiMsg_PPPPrinting_QuerySupportedFormats(API_ID_PPP_PRINTING, 35 new PpapiMsg_PPPPrinting_QuerySupportedFormats(API_ID_PPP_PRINTING,
26 instance, &result)); 36 instance, &result));
27 return result; 37 return result;
28 } 38 }
29 39
30 int32_t Begin(PP_Instance instance, 40 int32_t Begin(PP_Instance instance,
31 const struct PP_PrintSettings_Dev* print_settings) { 41 const struct PP_PrintSettings_Dev* print_settings) {
42 if (!HasPrintingPermission(instance))
43 return 0;
44
32 // Settings is just serialized as a string. 45 // Settings is just serialized as a string.
33 std::string settings_string; 46 std::string settings_string;
34 settings_string.resize(sizeof(*print_settings)); 47 settings_string.resize(sizeof(*print_settings));
35 memcpy(&settings_string[0], print_settings, sizeof(*print_settings)); 48 memcpy(&settings_string[0], print_settings, sizeof(*print_settings));
36 49
37 int32_t result = 0; 50 int32_t result = 0;
38 HostDispatcher::GetForInstance(instance)->Send( 51 HostDispatcher::GetForInstance(instance)->Send(
39 new PpapiMsg_PPPPrinting_Begin(API_ID_PPP_PRINTING, instance, 52 new PpapiMsg_PPPPrinting_Begin(API_ID_PPP_PRINTING, instance,
40 settings_string, &result)); 53 settings_string, &result));
41 return result; 54 return result;
42 } 55 }
43 56
44 PP_Resource PrintPages(PP_Instance instance, 57 PP_Resource PrintPages(PP_Instance instance,
45 const PP_PrintPageNumberRange_Dev* page_ranges, 58 const PP_PrintPageNumberRange_Dev* page_ranges,
46 uint32_t page_range_count) { 59 uint32_t page_range_count) {
60 if (!HasPrintingPermission(instance))
61 return 0;
62
47 std::vector<PP_PrintPageNumberRange_Dev> pages( 63 std::vector<PP_PrintPageNumberRange_Dev> pages(
48 page_ranges, page_ranges + page_range_count); 64 page_ranges, page_ranges + page_range_count);
49 65
50 HostResource result; 66 HostResource result;
51 HostDispatcher::GetForInstance(instance)->Send( 67 HostDispatcher::GetForInstance(instance)->Send(
52 new PpapiMsg_PPPPrinting_PrintPages(API_ID_PPP_PRINTING, 68 new PpapiMsg_PPPPrinting_PrintPages(API_ID_PPP_PRINTING,
53 instance, pages, &result)); 69 instance, pages, &result));
54 70
55 // How refcounting works when returning a resource: 71 // How refcounting works when returning a resource:
56 // 72 //
57 // The plugin in the plugin process makes a resource that it returns to the 73 // The plugin in the plugin process makes a resource that it returns to the
58 // browser. The plugin proxy code returns that ref to us and asynchronously 74 // browser. The plugin proxy code returns that ref to us and asynchronously
59 // releases it. Before any release message associated with that operation 75 // releases it. Before any release message associated with that operation
60 // comes, we'll get this reply. We need to add one ref since our caller 76 // comes, we'll get this reply. We need to add one ref since our caller
61 // expects us to add one ref for it to consume. 77 // expects us to add one ref for it to consume.
62 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource( 78 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(
63 result.host_resource()); 79 result.host_resource());
64 return result.host_resource(); 80 return result.host_resource();
65 } 81 }
66 82
67 void End(PP_Instance instance) { 83 void End(PP_Instance instance) {
84 if (!HasPrintingPermission(instance))
85 return;
86
68 HostDispatcher::GetForInstance(instance)->Send( 87 HostDispatcher::GetForInstance(instance)->Send(
69 new PpapiMsg_PPPPrinting_End(API_ID_PPP_PRINTING, instance)); 88 new PpapiMsg_PPPPrinting_End(API_ID_PPP_PRINTING, instance));
70 } 89 }
71 90
72 PP_Bool IsScalingDisabled(PP_Instance instance) { 91 PP_Bool IsScalingDisabled(PP_Instance instance) {
92 if (!HasPrintingPermission(instance))
93 return PP_FALSE;
94
73 bool result = false; 95 bool result = false;
74 HostDispatcher::GetForInstance(instance)->Send( 96 HostDispatcher::GetForInstance(instance)->Send(
75 new PpapiMsg_PPPPrinting_IsScalingDisabled(API_ID_PPP_PRINTING, 97 new PpapiMsg_PPPPrinting_IsScalingDisabled(API_ID_PPP_PRINTING,
76 instance, &result)); 98 instance, &result));
77 return PP_FromBool(result); 99 return PP_FromBool(result);
78 } 100 }
79 101
80 const PPP_Printing_Dev ppp_printing_interface = { 102 const PPP_Printing_Dev ppp_printing_interface = {
81 &QuerySupportedFormats, 103 &QuerySupportedFormats,
82 &Begin, 104 &Begin,
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 void PPP_Printing_Proxy::OnPluginMsgIsScalingDisabled(PP_Instance instance, 194 void PPP_Printing_Proxy::OnPluginMsgIsScalingDisabled(PP_Instance instance,
173 bool* result) { 195 bool* result) {
174 if (ppp_printing_impl_) 196 if (ppp_printing_impl_)
175 *result = PP_ToBool(ppp_printing_impl_->IsScalingDisabled(instance)); 197 *result = PP_ToBool(ppp_printing_impl_->IsScalingDisabled(instance));
176 else 198 else
177 *result = false; 199 *result = false;
178 } 200 }
179 201
180 } // namespace proxy 202 } // namespace proxy
181 } // namespace ppapi 203 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_video_decoder_proxy.cc ('k') | webkit/plugins/ppapi/plugin_module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698