[email protected] | e9cb0b79 | 2012-09-07 07:11:06 | [diff] [blame] | 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 | |
[email protected] | e1f5c9b | 2012-10-04 00:07:44 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | e9cb0b79 | 2012-09-07 07:11:06 | [diff] [blame] | 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 | |
[email protected] | e1f5c9b | 2012-10-04 00:07:44 | [diff] [blame] | 16 | PrintingResource::PrintingResource(Connection connection, PP_Instance instance) |
| 17 | : PluginResource(connection, instance) { |
[email protected] | e9cb0b79 | 2012-09-07 07:11:06 | [diff] [blame] | 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 | |
[email protected] | 234c139 | 2012-09-27 23:30:41 | [diff] [blame] | 33 | if (!sent_create_to_browser()) |
[email protected] | 9164da3 | 2012-10-16 03:40:57 | [diff] [blame] | 34 | SendCreate(BROWSER, PpapiHostMsg_Printing_Create()); |
[email protected] | e9cb0b79 | 2012-09-07 07:11:06 | [diff] [blame] | 35 | |
[email protected] | 9164da3 | 2012-10-16 03:40:57 | [diff] [blame] | 36 | Call<PpapiPluginMsg_Printing_GetDefaultPrintSettingsReply>( |
| 37 | BROWSER, |
[email protected] | e1f5c9b | 2012-10-04 00:07:44 | [diff] [blame] | 38 | PpapiHostMsg_Printing_GetDefaultPrintSettings(), |
| 39 | base::Bind(&PrintingResource::OnPluginMsgGetDefaultPrintSettingsReply, |
| 40 | this, print_settings, callback)); |
[email protected] | e9cb0b79 | 2012-09-07 07:11:06 | [diff] [blame] | 41 | return PP_OK_COMPLETIONPENDING; |
| 42 | } |
| 43 | |
[email protected] | e9cb0b79 | 2012-09-07 07:11:06 | [diff] [blame] | 44 | void PrintingResource::OnPluginMsgGetDefaultPrintSettingsReply( |
[email protected] | e1f5c9b | 2012-10-04 00:07:44 | [diff] [blame] | 45 | PP_PrintSettings_Dev* settings_out, |
| 46 | scoped_refptr<TrackedCallback> callback, |
[email protected] | e9cb0b79 | 2012-09-07 07:11:06 | [diff] [blame] | 47 | const ResourceMessageReplyParams& params, |
| 48 | const PP_PrintSettings_Dev& settings) { |
| 49 | if (params.result() == PP_OK) |
[email protected] | e1f5c9b | 2012-10-04 00:07:44 | [diff] [blame] | 50 | *settings_out = settings; |
[email protected] | e9cb0b79 | 2012-09-07 07:11:06 | [diff] [blame] | 51 | |
| 52 | // Notify the plugin of the new data. |
[email protected] | c9eb5058 | 2012-11-05 20:08:24 | [diff] [blame] | 53 | callback->Run(params.result()); |
[email protected] | e9cb0b79 | 2012-09-07 07:11:06 | [diff] [blame] | 54 | // DANGER: May delete |this|! |
| 55 | } |
| 56 | |
| 57 | } // namespace proxy |
| 58 | } // namespace ppapi |