| 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/printing_resource.h" | 5 #include "ppapi/proxy/printing_resource.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 7 #include "ipc/ipc_message.h" | 8 #include "ipc/ipc_message.h" |
| 8 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/proxy/dispatch_reply_message.h" | 10 #include "ppapi/proxy/dispatch_reply_message.h" |
| 10 #include "ppapi/proxy/ppapi_messages.h" | 11 #include "ppapi/proxy/ppapi_messages.h" |
| 11 | 12 |
| 12 namespace ppapi { | 13 namespace ppapi { |
| 13 namespace proxy { | 14 namespace proxy { |
| 14 | 15 |
| 15 PrintingResource::PrintingResource(Connection connection, | 16 PrintingResource::PrintingResource(Connection connection, PP_Instance instance) |
| 16 PP_Instance instance) | 17 : PluginResource(connection, instance) { |
| 17 : PluginResource(connection, instance), | |
| 18 print_settings_(NULL) { | |
| 19 } | 18 } |
| 20 | 19 |
| 21 PrintingResource::~PrintingResource() { | 20 PrintingResource::~PrintingResource() { |
| 22 } | 21 } |
| 23 | 22 |
| 24 thunk::PPB_Printing_API* PrintingResource::AsPPB_Printing_API() { | 23 thunk::PPB_Printing_API* PrintingResource::AsPPB_Printing_API() { |
| 25 return this; | 24 return this; |
| 26 } | 25 } |
| 27 | 26 |
| 28 int32_t PrintingResource::GetDefaultPrintSettings( | 27 int32_t PrintingResource::GetDefaultPrintSettings( |
| 29 PP_PrintSettings_Dev* print_settings, | 28 PP_PrintSettings_Dev* print_settings, |
| 30 scoped_refptr<TrackedCallback> callback) { | 29 scoped_refptr<TrackedCallback> callback) { |
| 31 if (!print_settings) | 30 if (!print_settings) |
| 32 return PP_ERROR_BADARGUMENT; | 31 return PP_ERROR_BADARGUMENT; |
| 33 | 32 |
| 34 if (TrackedCallback::IsPending(callback_)) | |
| 35 return PP_ERROR_INPROGRESS; | |
| 36 | |
| 37 if (!sent_create_to_browser()) | 33 if (!sent_create_to_browser()) |
| 38 SendCreateToBrowser(PpapiHostMsg_Printing_Create()); | 34 SendCreateToBrowser(PpapiHostMsg_Printing_Create()); |
| 39 | 35 |
| 40 DCHECK(!print_settings_); | 36 CallBrowser<PpapiPluginMsg_Printing_GetDefaultPrintSettingsReply>( |
| 41 print_settings_ = print_settings; | 37 PpapiHostMsg_Printing_GetDefaultPrintSettings(), |
| 42 callback_ = callback; | 38 base::Bind(&PrintingResource::OnPluginMsgGetDefaultPrintSettingsReply, |
| 43 | 39 this, print_settings, callback)); |
| 44 CallBrowser(PpapiHostMsg_Printing_GetDefaultPrintSettings()); | |
| 45 return PP_OK_COMPLETIONPENDING; | 40 return PP_OK_COMPLETIONPENDING; |
| 46 } | 41 } |
| 47 | 42 |
| 48 void PrintingResource::OnReplyReceived( | |
| 49 const ResourceMessageReplyParams& params, | |
| 50 const IPC::Message& msg) { | |
| 51 IPC_BEGIN_MESSAGE_MAP(PrintingResource, msg) | |
| 52 PPAPI_DISPATCH_RESOURCE_REPLY( | |
| 53 PpapiPluginMsg_Printing_GetDefaultPrintSettingsReply, | |
| 54 OnPluginMsgGetDefaultPrintSettingsReply) | |
| 55 IPC_END_MESSAGE_MAP() | |
| 56 } | |
| 57 | |
| 58 void PrintingResource::OnPluginMsgGetDefaultPrintSettingsReply( | 43 void PrintingResource::OnPluginMsgGetDefaultPrintSettingsReply( |
| 44 PP_PrintSettings_Dev* settings_out, |
| 45 scoped_refptr<TrackedCallback> callback, |
| 59 const ResourceMessageReplyParams& params, | 46 const ResourceMessageReplyParams& params, |
| 60 const PP_PrintSettings_Dev& settings) { | 47 const PP_PrintSettings_Dev& settings) { |
| 61 if (params.result() == PP_OK) | 48 if (params.result() == PP_OK) |
| 62 *print_settings_ = settings; | 49 *settings_out = settings; |
| 63 print_settings_ = NULL; | |
| 64 | 50 |
| 65 // Notify the plugin of the new data. | 51 // Notify the plugin of the new data. |
| 66 TrackedCallback::ClearAndRun(&callback_, params.result()); | 52 TrackedCallback::ClearAndRun(&callback, params.result()); |
| 67 // DANGER: May delete |this|! | 53 // DANGER: May delete |this|! |
| 68 } | 54 } |
| 69 | 55 |
| 70 } // namespace proxy | 56 } // namespace proxy |
| 71 } // namespace ppapi | 57 } // namespace ppapi |
| OLD | NEW |