Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / printing / printing_context.h
blob0d9f6052e34bfe0610d4b7bd43e185abb70ecdef
1 // Copyright (c) 2011 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 PRINTING_PRINTING_CONTEXT_H_
6 #define PRINTING_PRINTING_CONTEXT_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/strings/string16.h"
13 #include "printing/print_settings.h"
14 #include "ui/gfx/native_widget_types.h"
16 namespace base {
17 class DictionaryValue;
20 namespace printing {
22 // An abstraction of a printer context, implemented by objects that describe the
23 // user selected printing context. This includes the OS-dependent UI to ask the
24 // user about the print settings. Concrete implementations directly talk to the
25 // printer and manage the document and page breaks.
26 class PRINTING_EXPORT PrintingContext {
27 public:
28 // Printing context delegate.
29 class Delegate {
30 public:
31 Delegate() {};
32 virtual ~Delegate() {};
34 // Returns parent view to use for modal dialogs.
35 virtual gfx::NativeView GetParentView() = 0;
37 // Returns application locale.
38 virtual std::string GetAppLocale() = 0;
41 // Tri-state result for user behavior-dependent functions.
42 enum Result {
43 OK,
44 CANCEL,
45 FAILED,
48 virtual ~PrintingContext();
50 // Callback of AskUserForSettings, used to notify the PrintJobWorker when
51 // print settings are available.
52 typedef base::Callback<void(Result)> PrintSettingsCallback;
54 // Asks the user what printer and format should be used to print. Updates the
55 // context with the select device settings. The result of the call is returned
56 // in the callback. This is necessary for Linux, which only has an
57 // asynchronous printing API.
58 // On Android, when |is_scripted| is true, calling it initiates a full
59 // printing flow from the framework's PrintManager.
60 // (see https://codereview.chromium.org/740983002/)
61 virtual void AskUserForSettings(int max_pages,
62 bool has_selection,
63 bool is_scripted,
64 const PrintSettingsCallback& callback) = 0;
66 // Selects the user's default printer and format. Updates the context with the
67 // default device settings.
68 virtual Result UseDefaultSettings() = 0;
70 // Updates the context with PDF printer settings.
71 Result UsePdfSettings();
73 // Returns paper size to be used for PDF or Cloud Print in device units.
74 virtual gfx::Size GetPdfPaperSizeDeviceUnits() = 0;
76 // Updates printer settings.
77 // |external_preview| is true if pdf is going to be opened in external
78 // preview. Used by MacOS only now to open Preview.app.
79 virtual Result UpdatePrinterSettings(bool external_preview,
80 bool show_system_dialog) = 0;
82 // Updates Print Settings. |job_settings| contains all print job
83 // settings information. |ranges| has the new page range settings.
84 Result UpdatePrintSettings(const base::DictionaryValue& job_settings);
86 // Initializes with predefined settings.
87 virtual Result InitWithSettings(const PrintSettings& settings) = 0;
89 // Does platform specific setup of the printer before the printing. Signal the
90 // printer that a document is about to be spooled.
91 // Warning: This function enters a message loop. That may cause side effects
92 // like IPC message processing! Some printers have side-effects on this call
93 // like virtual printers that ask the user for the path of the saved document;
94 // for example a PDF printer.
95 virtual Result NewDocument(const base::string16& document_name) = 0;
97 // Starts a new page.
98 virtual Result NewPage() = 0;
100 // Closes the printed page.
101 virtual Result PageDone() = 0;
103 // Closes the printing job. After this call the object is ready to start a new
104 // document.
105 virtual Result DocumentDone() = 0;
107 // Cancels printing. Can be used in a multi-threaded context. Takes effect
108 // immediately.
109 virtual void Cancel() = 0;
111 // Releases the native printing context.
112 virtual void ReleaseContext() = 0;
114 // Returns the native context used to print.
115 virtual gfx::NativeDrawingContext context() const = 0;
117 // Creates an instance of this object. Implementers of this interface should
118 // implement this method to create an object of their implementation.
119 static scoped_ptr<PrintingContext> Create(Delegate* delegate);
121 void set_margin_type(MarginType type);
123 const PrintSettings& settings() const {
124 return settings_;
127 protected:
128 explicit PrintingContext(Delegate* delegate);
130 // Reinitializes the settings for object reuse.
131 void ResetSettings();
133 // Does bookkeeping when an error occurs.
134 PrintingContext::Result OnError();
136 // Complete print context settings.
137 PrintSettings settings_;
139 // Printing context delegate.
140 Delegate* delegate_;
142 // Is a print job being done.
143 volatile bool in_print_job_;
145 // Did the user cancel the print job.
146 volatile bool abort_printing_;
148 private:
149 DISALLOW_COPY_AND_ASSIGN(PrintingContext);
152 } // namespace printing
154 #endif // PRINTING_PRINTING_CONTEXT_H_