Chromium Code Reviews| Index: android_webview/browser/aw_printing_message_filter.cc |
| diff --git a/android_webview/browser/aw_printing_message_filter.cc b/android_webview/browser/aw_printing_message_filter.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..524aed81defd2325f4f842aa99ea802ff0fff989 |
| --- /dev/null |
| +++ b/android_webview/browser/aw_printing_message_filter.cc |
| @@ -0,0 +1,86 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "android_webview/browser/aw_printing_message_filter.h" |
| + |
| +#include "android_webview/browser/renderer_host/print_manager.h" |
| +#include "android_webview/common/print_messages.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/render_view_host.h" |
| +#include "content/public/browser/web_contents.h" |
| + |
| +using content::BrowserThread; |
| +using content::WebContents; |
| + |
| + |
| +namespace android_webview { |
| + |
| +namespace { |
| + |
| +PrintManager* GetPrintManager(int render_process_id, int render_view_id) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + content::RenderViewHost* rvh = content::RenderViewHost::FromID( |
|
nasko
2015/01/14 19:16:33
Replace the implementation of this method to use R
sgurun-gerrit only
2015/01/14 19:35:20
Again this code is to bring webview code in line w
|
| + render_process_id, render_view_id); |
| + if (rvh == nullptr) |
|
dgn
2015/01/14 11:19:19
nit: if(!rvh)
same for other occurrences below
sgurun-gerrit only
2015/01/14 18:55:58
thanks, I think both ways are pretty prevalent in
|
| + return nullptr; |
| + WebContents* web_contents = WebContents::FromRenderViewHost(rvh); |
| + if (web_contents == nullptr) |
| + return nullptr; |
| + return PrintManager::FromWebContents(web_contents); |
| +} |
| + |
| +} // namespace |
| + |
| +AwPrintingMessageFilter::AwPrintingMessageFilter(int render_process_id) |
| + : BrowserMessageFilter(PrintMsgStart), |
| + render_process_id_(render_process_id) { |
| +} |
| + |
| +AwPrintingMessageFilter::~AwPrintingMessageFilter() { |
| +} |
| + |
| +void AwPrintingMessageFilter::OverrideThreadForMessage( |
| + const IPC::Message& message, BrowserThread::ID* thread) { |
| + if (message.type() == PrintHostMsg_AllocateTempFileForPrinting::ID || |
| + message.type() == PrintHostMsg_TempFileForPrintingWritten::ID) { |
| + *thread = BrowserThread::UI; |
| + } |
| +} |
| + |
| +bool AwPrintingMessageFilter::OnMessageReceived(const IPC::Message& message) { |
| + bool handled = true; |
| + IPC_BEGIN_MESSAGE_MAP(AwPrintingMessageFilter, message) |
| + IPC_MESSAGE_HANDLER(PrintHostMsg_AllocateTempFileForPrinting, |
| + OnAllocateTempFileForPrinting) |
| + IPC_MESSAGE_HANDLER(PrintHostMsg_TempFileForPrintingWritten, |
| + OnTempFileForPrintingWritten) |
| + IPC_MESSAGE_UNHANDLED(handled = false) |
| + IPC_END_MESSAGE_MAP() |
| + return handled; |
| +} |
| + |
| +void AwPrintingMessageFilter::OnAllocateTempFileForPrinting( |
| + int render_view_id, |
| + base::FileDescriptor* temp_file_fd, |
| + int* sequence_number) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + PrintManager* print_manager = |
| + GetPrintManager(render_process_id_, render_view_id); |
| + if (print_manager == nullptr) |
| + return; |
| + print_manager->OnAllocateTempFileForPrinting(temp_file_fd, sequence_number); |
| +} |
| + |
| +void AwPrintingMessageFilter::OnTempFileForPrintingWritten( |
| + int render_view_id, |
| + int sequence_number) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + PrintManager* print_manager = |
| + GetPrintManager(render_process_id_, render_view_id); |
| + if (print_manager == nullptr) |
| + return; |
| + print_manager->OnTempFileForPrintingWritten(sequence_number); |
| +} |
| + |
| +} // namespace android_webview |