OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "android_webview/browser/aw_print_manager.h" | 5 #include "android_webview/browser/aw_print_manager.h" |
6 | 6 |
7 #include "components/printing/browser/print_manager_utils.h" | 7 #include "components/printing/browser/print_manager_utils.h" |
8 #include "components/printing/common/print_messages.h" | 8 #include "components/printing/common/print_messages.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/browser/render_frame_host.h" |
10 | 11 |
11 DEFINE_WEB_CONTENTS_USER_DATA_KEY(android_webview::AwPrintManager); | 12 DEFINE_WEB_CONTENTS_USER_DATA_KEY(android_webview::AwPrintManager); |
12 | 13 |
13 namespace android_webview { | 14 namespace android_webview { |
14 | 15 |
15 // static | 16 // static |
16 AwPrintManager* AwPrintManager::CreateForWebContents( | 17 AwPrintManager* AwPrintManager::CreateForWebContents( |
17 content::WebContents* contents, | 18 content::WebContents* contents, |
18 const printing::PrintSettings& settings, | 19 const printing::PrintSettings& settings, |
19 const base::FileDescriptor& file_descriptor, | 20 const base::FileDescriptor& file_descriptor, |
(...skipping 14 matching lines...) Expand all Loading... |
34 set_file_descriptor(file_descriptor); | 35 set_file_descriptor(file_descriptor); |
35 pdf_writing_done_callback_ = callback; | 36 pdf_writing_done_callback_ = callback; |
36 cookie_ = 1; | 37 cookie_ = 1; |
37 } | 38 } |
38 | 39 |
39 AwPrintManager::~AwPrintManager() { | 40 AwPrintManager::~AwPrintManager() { |
40 } | 41 } |
41 | 42 |
42 bool AwPrintManager::PrintNow() { | 43 bool AwPrintManager::PrintNow() { |
43 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 44 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
44 return Send(new PrintMsg_PrintPages(routing_id())); | 45 auto* rfh = web_contents()->GetMainFrame(); |
| 46 return rfh->Send(new PrintMsg_PrintPages(rfh->GetRoutingID())); |
45 } | 47 } |
46 | 48 |
47 bool AwPrintManager::OnMessageReceived(const IPC::Message& message) { | 49 bool AwPrintManager::OnMessageReceived( |
| 50 const IPC::Message& message, |
| 51 content::RenderFrameHost* render_frame_host) { |
48 bool handled = true; | 52 bool handled = true; |
49 IPC_BEGIN_MESSAGE_MAP(AwPrintManager, message) | 53 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(AwPrintManager, message, render_frame_host) |
50 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_GetDefaultPrintSettings, | 54 IPC_MESSAGE_HANDLER_WITH_PARAM_DELAY_REPLY( |
51 OnGetDefaultPrintSettings) | 55 PrintHostMsg_GetDefaultPrintSettings, OnGetDefaultPrintSettings) |
52 IPC_MESSAGE_UNHANDLED(handled = false) | 56 IPC_MESSAGE_UNHANDLED(handled = false) |
53 IPC_END_MESSAGE_MAP() | 57 IPC_END_MESSAGE_MAP() |
54 return handled ? true : PrintManager::OnMessageReceived(message); | 58 return handled ? true |
| 59 : PrintManager::OnMessageReceived(message, render_frame_host); |
55 } | 60 } |
56 | 61 |
57 void AwPrintManager::OnGetDefaultPrintSettings(IPC::Message* reply_msg) { | 62 void AwPrintManager::OnGetDefaultPrintSettings( |
| 63 content::RenderFrameHost* render_frame_host, |
| 64 IPC::Message* reply_msg) { |
58 // Unlike the printing_message_filter, we do process this in UI thread. | 65 // Unlike the printing_message_filter, we do process this in UI thread. |
59 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 66 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
60 PrintMsg_Print_Params params; | 67 PrintMsg_Print_Params params; |
61 printing::RenderParamsFromPrintSettings(settings_, ¶ms); | 68 printing::RenderParamsFromPrintSettings(settings_, ¶ms); |
62 params.document_cookie = cookie_; | 69 params.document_cookie = cookie_; |
63 PrintHostMsg_GetDefaultPrintSettings::WriteReplyParams(reply_msg, params); | 70 PrintHostMsg_GetDefaultPrintSettings::WriteReplyParams(reply_msg, params); |
64 Send(reply_msg); | 71 render_frame_host->Send(reply_msg); |
65 } | 72 } |
66 | 73 |
67 } // namespace android_webview | 74 } // namespace android_webview |
OLD | NEW |