OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/renderer_host/print_manager.h" | 5 #include "android_webview/browser/renderer_host/print_manager.h" |
6 | 6 |
7 #include "android_webview/browser/aw_browser_context.h" | 7 #include "android_webview/browser/aw_browser_context.h" |
8 #include "android_webview/common/print_messages.h" | 8 #include "android_webview/common/print_messages.h" |
9 #include "android_webview/common/render_view_messages.h" | 9 #include "android_webview/common/render_view_messages.h" |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
15 #include "printing/print_settings.h" | 15 #include "printing/print_settings.h" |
16 | 16 |
17 using content::BrowserThread; | 17 using content::BrowserThread; |
18 using printing::PrintSettings; | 18 using printing::PrintSettings; |
19 | 19 |
| 20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(android_webview::PrintManager); |
| 21 |
20 namespace android_webview { | 22 namespace android_webview { |
21 | 23 |
| 24 // static |
| 25 PrintManager* PrintManager::CreateForWebContents( |
| 26 content::WebContents* contents, |
| 27 PrintSettings* settings, |
| 28 int fd, |
| 29 PrintManagerDelegate* delegate) { |
| 30 PrintManager* print_manager = |
| 31 new PrintManager(contents, settings, fd, delegate); |
| 32 contents->SetUserData(UserDataKey(), print_manager); |
| 33 return print_manager; |
| 34 } |
| 35 |
22 PrintManager::PrintManager(content::WebContents* contents, | 36 PrintManager::PrintManager(content::WebContents* contents, |
23 PrintSettings* settings, | 37 PrintSettings* settings, |
24 int fd, | 38 int fd, |
25 PrintManagerDelegate* delegate) | 39 PrintManagerDelegate* delegate) |
26 : content::WebContentsObserver(contents), | 40 : content::WebContentsObserver(contents), |
27 settings_(settings), | 41 settings_(settings), |
28 fd_(fd), | 42 fd_(fd), |
29 delegate_(delegate), | 43 delegate_(delegate), |
30 number_pages_(0), | 44 number_pages_(0), |
31 cookie_(1), | 45 cookie_(1), |
32 printing_(false) { | 46 printing_(false) { |
33 DCHECK(delegate_); | 47 DCHECK(delegate_); |
34 } | 48 } |
35 | 49 |
36 PrintManager::~PrintManager() {} | 50 PrintManager::~PrintManager() {} |
37 | 51 |
38 bool PrintManager::OnMessageReceived(const IPC::Message& message) { | 52 bool PrintManager::OnMessageReceived(const IPC::Message& message) { |
39 bool handled = true; | 53 bool handled = true; |
40 IPC_BEGIN_MESSAGE_MAP(PrintManager, message) | 54 IPC_BEGIN_MESSAGE_MAP(PrintManager, message) |
41 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, | 55 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, |
42 OnDidGetPrintedPagesCount) | 56 OnDidGetPrintedPagesCount) |
43 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetDocumentCookie, | 57 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetDocumentCookie, |
44 OnDidGetDocumentCookie) | 58 OnDidGetDocumentCookie) |
45 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintingFailed, OnPrintingFailed) | 59 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintingFailed, OnPrintingFailed) |
46 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_GetDefaultPrintSettings, | 60 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_GetDefaultPrintSettings, |
47 OnGetDefaultPrintSettings) | 61 OnGetDefaultPrintSettings) |
48 IPC_MESSAGE_HANDLER(PrintHostMsg_AllocateTempFileForPrinting, | |
49 OnAllocateTempFileForPrinting) | |
50 IPC_MESSAGE_HANDLER(PrintHostMsg_TempFileForPrintingWritten, | |
51 OnTempFileForPrintingWritten) | |
52 IPC_MESSAGE_UNHANDLED(handled = false) | 62 IPC_MESSAGE_UNHANDLED(handled = false) |
53 IPC_END_MESSAGE_MAP() | 63 IPC_END_MESSAGE_MAP() |
54 | 64 |
55 return handled ? true : WebContentsObserver::OnMessageReceived(message); | 65 return handled ? true : WebContentsObserver::OnMessageReceived(message); |
56 } | 66 } |
57 | 67 |
58 void PrintManager::OnAllocateTempFileForPrinting( | 68 void PrintManager::OnAllocateTempFileForPrinting( |
59 base::FileDescriptor* temp_file_fd, | 69 base::FileDescriptor* temp_file_fd, |
60 int* sequence_number) { | 70 int* sequence_number) { |
61 // we don't really use the sequence number. | 71 // we don't really use the sequence number. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 bool PrintManager::PrintNow() { | 144 bool PrintManager::PrintNow() { |
135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
136 if (printing_) | 146 if (printing_) |
137 return false; | 147 return false; |
138 | 148 |
139 printing_ = true; | 149 printing_ = true; |
140 return Send(new PrintMsg_PrintPages(routing_id())); | 150 return Send(new PrintMsg_PrintPages(routing_id())); |
141 } | 151 } |
142 | 152 |
143 } // namespace android_webview | 153 } // namespace android_webview |
OLD | NEW |