exclude PluginsFieldTrialTest.NoPrefLeftBehind from valgrind bot
[chromium-blink-merge.git] / android_webview / browser / aw_print_manager.cc
blob80748093e636e55e070235560d8c138d72f7a966
1 // Copyright 2015 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 "android_webview/browser/aw_print_manager.h"
7 #include "components/printing/browser/print_manager_utils.h"
8 #include "components/printing/common/print_messages.h"
9 #include "content/public/browser/browser_thread.h"
11 DEFINE_WEB_CONTENTS_USER_DATA_KEY(android_webview::AwPrintManager);
13 namespace android_webview {
15 // static
16 AwPrintManager* AwPrintManager::CreateForWebContents(
17 content::WebContents* contents,
18 const printing::PrintSettings& settings,
19 const base::FileDescriptor& file_descriptor,
20 const PrintManager::PdfWritingDoneCallback& callback) {
21 AwPrintManager* print_manager =
22 new AwPrintManager(contents, settings, file_descriptor, callback);
23 contents->SetUserData(UserDataKey(), print_manager);
24 return print_manager;
27 AwPrintManager::AwPrintManager(
28 content::WebContents* contents,
29 const printing::PrintSettings& settings,
30 const base::FileDescriptor& file_descriptor,
31 const PdfWritingDoneCallback& callback)
32 : PrintManager(contents),
33 settings_(settings) {
34 set_file_descriptor(file_descriptor);
35 pdf_writing_done_callback_ = callback;
36 cookie_ = 1;
39 AwPrintManager::~AwPrintManager() {
42 bool AwPrintManager::PrintNow() {
43 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
44 return Send(new PrintMsg_PrintPages(routing_id()));
47 bool AwPrintManager::OnMessageReceived(const IPC::Message& message) {
48 bool handled = true;
49 IPC_BEGIN_MESSAGE_MAP(AwPrintManager, message)
50 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_GetDefaultPrintSettings,
51 OnGetDefaultPrintSettings)
52 IPC_MESSAGE_UNHANDLED(handled = false)
53 IPC_END_MESSAGE_MAP()
54 return handled ? true : PrintManager::OnMessageReceived(message);
57 void AwPrintManager::OnGetDefaultPrintSettings(IPC::Message* reply_msg) {
58 // Unlike the printing_message_filter, we do process this in UI thread.
59 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
60 PrintMsg_Print_Params params;
61 printing::RenderParamsFromPrintSettings(settings_, &params);
62 params.document_cookie = cookie_;
63 PrintHostMsg_GetDefaultPrintSettings::WriteReplyParams(reply_msg, params);
64 Send(reply_msg);
67 } // namespace android_webview