blob: d9be3b7430194e8866d401f3e5f093ce1b23b67d [file] [log] [blame]
[email protected]e9cb0b792012-09-07 07:11:061// 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]e1f5c9b2012-10-04 00:07:447#include "base/bind.h"
[email protected]e9cb0b792012-09-07 07:11:068#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
13namespace ppapi {
14namespace proxy {
15
[email protected]e1f5c9b2012-10-04 00:07:4416PrintingResource::PrintingResource(Connection connection, PP_Instance instance)
17 : PluginResource(connection, instance) {
[email protected]e9cb0b792012-09-07 07:11:0618}
19
20PrintingResource::~PrintingResource() {
21}
22
23thunk::PPB_Printing_API* PrintingResource::AsPPB_Printing_API() {
24 return this;
25}
26
27int32_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]234c1392012-09-27 23:30:4133 if (!sent_create_to_browser())
[email protected]9164da32012-10-16 03:40:5734 SendCreate(BROWSER, PpapiHostMsg_Printing_Create());
[email protected]e9cb0b792012-09-07 07:11:0635
[email protected]9164da32012-10-16 03:40:5736 Call<PpapiPluginMsg_Printing_GetDefaultPrintSettingsReply>(
37 BROWSER,
[email protected]e1f5c9b2012-10-04 00:07:4438 PpapiHostMsg_Printing_GetDefaultPrintSettings(),
39 base::Bind(&PrintingResource::OnPluginMsgGetDefaultPrintSettingsReply,
40 this, print_settings, callback));
[email protected]e9cb0b792012-09-07 07:11:0641 return PP_OK_COMPLETIONPENDING;
42}
43
[email protected]e9cb0b792012-09-07 07:11:0644void PrintingResource::OnPluginMsgGetDefaultPrintSettingsReply(
[email protected]e1f5c9b2012-10-04 00:07:4445 PP_PrintSettings_Dev* settings_out,
46 scoped_refptr<TrackedCallback> callback,
[email protected]e9cb0b792012-09-07 07:11:0647 const ResourceMessageReplyParams& params,
48 const PP_PrintSettings_Dev& settings) {
49 if (params.result() == PP_OK)
[email protected]e1f5c9b2012-10-04 00:07:4450 *settings_out = settings;
[email protected]e9cb0b792012-09-07 07:11:0651
52 // Notify the plugin of the new data.
[email protected]c9eb50582012-11-05 20:08:2453 callback->Run(params.result());
[email protected]e9cb0b792012-09-07 07:11:0654 // DANGER: May delete |this|!
55}
56
57} // namespace proxy
58} // namespace ppapi