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 | |
36 | |
hush (inactive)
2015/01/14 01:55:47
stale line.
sgurun-gerrit only
2015/01/14 02:03:17
Done.
| |
22 PrintManager::PrintManager(content::WebContents* contents, | 37 PrintManager::PrintManager(content::WebContents* contents, |
23 PrintSettings* settings, | 38 PrintSettings* settings, |
24 int fd, | 39 int fd, |
25 PrintManagerDelegate* delegate) | 40 PrintManagerDelegate* delegate) |
26 : content::WebContentsObserver(contents), | 41 : content::WebContentsObserver(contents), |
27 settings_(settings), | 42 settings_(settings), |
28 fd_(fd), | 43 fd_(fd), |
29 delegate_(delegate), | 44 delegate_(delegate), |
30 number_pages_(0), | 45 number_pages_(0), |
31 cookie_(1), | 46 cookie_(1), |
32 printing_(false) { | 47 printing_(false) { |
33 DCHECK(delegate_); | 48 DCHECK(delegate_); |
34 } | 49 } |
35 | 50 |
36 PrintManager::~PrintManager() {} | 51 PrintManager::~PrintManager() {} |
37 | 52 |
38 bool PrintManager::OnMessageReceived(const IPC::Message& message) { | 53 bool PrintManager::OnMessageReceived(const IPC::Message& message) { |
39 bool handled = true; | 54 bool handled = true; |
40 IPC_BEGIN_MESSAGE_MAP(PrintManager, message) | 55 IPC_BEGIN_MESSAGE_MAP(PrintManager, message) |
41 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, | 56 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, |
42 OnDidGetPrintedPagesCount) | 57 OnDidGetPrintedPagesCount) |
43 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetDocumentCookie, | 58 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetDocumentCookie, |
44 OnDidGetDocumentCookie) | 59 OnDidGetDocumentCookie) |
45 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintingFailed, OnPrintingFailed) | 60 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintingFailed, OnPrintingFailed) |
46 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_GetDefaultPrintSettings, | 61 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_GetDefaultPrintSettings, |
47 OnGetDefaultPrintSettings) | 62 OnGetDefaultPrintSettings) |
48 IPC_MESSAGE_HANDLER(PrintHostMsg_AllocateTempFileForPrinting, | |
49 OnAllocateTempFileForPrinting) | |
50 IPC_MESSAGE_HANDLER(PrintHostMsg_TempFileForPrintingWritten, | |
51 OnTempFileForPrintingWritten) | |
52 IPC_MESSAGE_UNHANDLED(handled = false) | 63 IPC_MESSAGE_UNHANDLED(handled = false) |
53 IPC_END_MESSAGE_MAP() | 64 IPC_END_MESSAGE_MAP() |
54 | 65 |
55 return handled ? true : WebContentsObserver::OnMessageReceived(message); | 66 return handled ? true : WebContentsObserver::OnMessageReceived(message); |
56 } | 67 } |
57 | 68 |
58 void PrintManager::OnAllocateTempFileForPrinting( | 69 void PrintManager::OnAllocateTempFileForPrinting( |
59 base::FileDescriptor* temp_file_fd, | 70 base::FileDescriptor* temp_file_fd, |
60 int* sequence_number) { | 71 int* sequence_number) { |
61 // we don't really use the sequence number. | 72 // 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() { | 145 bool PrintManager::PrintNow() { |
135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
136 if (printing_) | 147 if (printing_) |
137 return false; | 148 return false; |
138 | 149 |
139 printing_ = true; | 150 printing_ = true; |
140 return Send(new PrintMsg_PrintPages(routing_id())); | 151 return Send(new PrintMsg_PrintPages(routing_id())); |
141 } | 152 } |
142 | 153 |
143 } // namespace android_webview | 154 } // namespace android_webview |
OLD | NEW |