Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / renderer_host / pepper / pepper_printing_host.cc
blob047f1203d7288128116a435ea06e4169d0f4ceab
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.
5 #include "content/browser/renderer_host/pepper/pepper_printing_host.h"
7 #include "ppapi/c/dev/pp_print_settings_dev.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/host/dispatch_host_message.h"
10 #include "ppapi/host/host_message_context.h"
11 #include "ppapi/host/ppapi_host.h"
12 #include "ppapi/proxy/ppapi_messages.h"
14 namespace content {
16 PepperPrintingHost::PepperPrintingHost(
17 ppapi::host::PpapiHost* host,
18 PP_Instance instance,
19 PP_Resource resource,
20 scoped_ptr<PepperPrintSettingsManager> print_settings_manager)
21 : ResourceHost(host, instance, resource),
22 print_settings_manager_(print_settings_manager.Pass()),
23 weak_factory_(this) {}
25 PepperPrintingHost::~PepperPrintingHost() {}
27 int32_t PepperPrintingHost::OnResourceMessageReceived(
28 const IPC::Message& msg,
29 ppapi::host::HostMessageContext* context) {
30 PPAPI_BEGIN_MESSAGE_MAP(PepperPrintingHost, msg)
31 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
32 PpapiHostMsg_Printing_GetDefaultPrintSettings,
33 OnGetDefaultPrintSettings)
34 PPAPI_END_MESSAGE_MAP()
35 return PP_ERROR_FAILED;
38 int32_t PepperPrintingHost::OnGetDefaultPrintSettings(
39 ppapi::host::HostMessageContext* context) {
40 print_settings_manager_->GetDefaultPrintSettings(
41 base::Bind(&PepperPrintingHost::PrintSettingsCallback,
42 weak_factory_.GetWeakPtr(),
43 context->MakeReplyMessageContext()));
44 return PP_OK_COMPLETIONPENDING;
47 void PepperPrintingHost::PrintSettingsCallback(
48 ppapi::host::ReplyMessageContext reply_context,
49 PepperPrintSettingsManager::Result result) {
50 reply_context.params.set_result(result.second);
51 host()->SendReply(
52 reply_context,
53 PpapiPluginMsg_Printing_GetDefaultPrintSettingsReply(result.first));
56 } // namespace content