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. 4 5 #include "ppapi/proxy/printing_resource.h" 6 7 #include "base/bind.h" 8 #include "ipc/ipc_message.h" 9 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/proxy/dispatch_reply_message.h" 11 #include "ppapi/proxy/ppapi_messages.h" 12 13 namespace ppapi { 14 namespace proxy { 15 16 PrintingResource::PrintingResource(Connection connection, PP_Instance instance) 17 : PluginResource(connection, instance) { 18 } 19 20 PrintingResource::~PrintingResource() { 21 } 22 23 thunk::PPB_Printing_API* PrintingResource::AsPPB_Printing_API() { 24 return this; 25 } 26 27 int32_t PrintingResource::GetDefaultPrintSettings( 28 PP_PrintSettings_Dev* print_settings, 29 scoped_refptr<TrackedCallback> callback) { 30 if (!print_settings) 31 return PP_ERROR_BADARGUMENT; 32 33 if (!sent_create_to_browser()) 34 SendCreate(BROWSER, PpapiHostMsg_Printing_Create()); 35 36 Call<PpapiPluginMsg_Printing_GetDefaultPrintSettingsReply>( 37 BROWSER, 38 PpapiHostMsg_Printing_GetDefaultPrintSettings(), 39 base::Bind(&PrintingResource::OnPluginMsgGetDefaultPrintSettingsReply, 40 this, print_settings, callback)); 41 return PP_OK_COMPLETIONPENDING; 42 } 43 44 void PrintingResource::OnPluginMsgGetDefaultPrintSettingsReply( 45 PP_PrintSettings_Dev* settings_out, 46 scoped_refptr<TrackedCallback> callback, 47 const ResourceMessageReplyParams& params, 48 const PP_PrintSettings_Dev& settings) { 49 if (params.result() == PP_OK) 50 *settings_out = settings; 51 52 // Notify the plugin of the new data. 53 callback->Run(params.result()); 54 // DANGER: May delete |this|! 55 } 56 57 } // namespace proxy 58 } // namespace ppapi 59