Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / printing / browser / print_manager.h
blobea24f5152ac22b01b0a725f141d91778687bc134
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 #ifndef COMPONENTS_PRINTING_BROWSER_PRINT_MANAGER_H_
6 #define COMPONENTS_PRINTING_BROWSER_PRINT_MANAGER_H_
8 #include "content/public/browser/web_contents_observer.h"
10 #if defined(OS_ANDROID)
11 #include "base/callback.h"
12 #include "base/file_descriptor_posix.h"
13 #endif
15 namespace printing {
17 class PrintManager : public content::WebContentsObserver {
18 public:
19 ~PrintManager() override;
21 #if defined(OS_ANDROID)
22 // TODO(timvolodine): consider introducing PrintManagerAndroid (crbug/500960)
23 typedef base::Callback<void(int, bool)> PdfWritingDoneCallback;
25 void PdfWritingDone(bool result);
27 // Sets the file descriptor into which the PDF will be written.
28 void set_file_descriptor(const base::FileDescriptor& file_descriptor) {
29 file_descriptor_ = file_descriptor;
32 // Gets the file descriptor into which the PDF will be written.
33 base::FileDescriptor file_descriptor() const { return file_descriptor_; }
34 #endif
36 protected:
37 explicit PrintManager(content::WebContents* contents);
39 // Terminates or cancels the print job if one was pending.
40 void RenderProcessGone(base::TerminationStatus status) override;
42 // content::WebContentsObserver
43 bool OnMessageReceived(const IPC::Message& message) override;
45 // IPC handlers
46 virtual void OnDidGetPrintedPagesCount(int cookie, int number_pages);
47 virtual void OnPrintingFailed(int cookie);
49 int number_pages_; // Number of pages to print in the print job.
50 int cookie_; // The current document cookie.
52 #if defined(OS_ANDROID)
53 // The file descriptor into which the PDF of the page will be written.
54 base::FileDescriptor file_descriptor_;
56 // Callback to execute when done writing pdf.
57 PdfWritingDoneCallback pdf_writing_done_callback_;
58 #endif
60 private:
61 void OnDidGetDocumentCookie(int cookie);
63 DISALLOW_COPY_AND_ASSIGN(PrintManager);
66 } // namespace printing
68 #endif // COMPONENTS_PRINTING_BROWSER_PRINT_MANAGER_H_