Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: components/printing/renderer/print_web_view_helper.h

Issue 2458833005: Move printing defines to buildflag system. (Closed)
Patch Set: Merge Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef COMPONENTS_PRINTING_RENDERER_PRINT_WEB_VIEW_HELPER_H_ 5 #ifndef COMPONENTS_PRINTING_RENDERER_PRINT_WEB_VIEW_HELPER_H_
6 #define COMPONENTS_PRINTING_RENDERER_PRINT_WEB_VIEW_HELPER_H_ 6 #define COMPONENTS_PRINTING_RENDERER_PRINT_WEB_VIEW_HELPER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/shared_memory.h" 14 #include "base/memory/shared_memory.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "content/public/renderer/render_view_observer.h" 18 #include "content/public/renderer/render_view_observer.h"
19 #include "content/public/renderer/render_view_observer_tracker.h" 19 #include "content/public/renderer/render_view_observer_tracker.h"
20 #include "printing/features/features.h"
20 #include "printing/pdf_metafile_skia.h" 21 #include "printing/pdf_metafile_skia.h"
21 #include "third_party/WebKit/public/platform/WebCanvas.h" 22 #include "third_party/WebKit/public/platform/WebCanvas.h"
22 #include "third_party/WebKit/public/web/WebNode.h" 23 #include "third_party/WebKit/public/web/WebNode.h"
23 #include "third_party/WebKit/public/web/WebPrintParams.h" 24 #include "third_party/WebKit/public/web/WebPrintParams.h"
24 #include "ui/gfx/geometry/size.h" 25 #include "ui/gfx/geometry/size.h"
25 26
26 struct PrintMsg_Print_Params; 27 struct PrintMsg_Print_Params;
27 struct PrintMsg_PrintPage_Params; 28 struct PrintMsg_PrintPage_Params;
28 struct PrintMsg_PrintPages_Params; 29 struct PrintMsg_PrintPages_Params;
29 struct PrintHostMsg_SetOptionsFromDocument_Params; 30 struct PrintHostMsg_SetOptionsFromDocument_Params;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 BlockScriptInitiatedPrintingFromPopup); 137 BlockScriptInitiatedPrintingFromPopup);
137 #if defined(OS_WIN) || defined(OS_MACOSX) 138 #if defined(OS_WIN) || defined(OS_MACOSX)
138 FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintWebViewHelperTest, PrintLayoutTest); 139 FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintWebViewHelperTest, PrintLayoutTest);
139 FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintWebViewHelperTest, PrintWithIframe); 140 FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintWebViewHelperTest, PrintWithIframe);
140 #endif // defined(OS_WIN) || defined(OS_MACOSX) 141 #endif // defined(OS_WIN) || defined(OS_MACOSX)
141 142
142 enum PrintingResult { 143 enum PrintingResult {
143 OK, 144 OK,
144 FAIL_PRINT_INIT, 145 FAIL_PRINT_INIT,
145 FAIL_PRINT, 146 FAIL_PRINT,
146 #if defined(ENABLE_PRINT_PREVIEW) 147 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
147 FAIL_PREVIEW, 148 FAIL_PREVIEW,
148 #endif 149 #endif
149 }; 150 };
150 151
151 enum PrintPreviewErrorBuckets { 152 enum PrintPreviewErrorBuckets {
152 PREVIEW_ERROR_NONE, // Always first. 153 PREVIEW_ERROR_NONE, // Always first.
153 PREVIEW_ERROR_BAD_SETTING, 154 PREVIEW_ERROR_BAD_SETTING,
154 PREVIEW_ERROR_METAFILE_COPY_FAILED, 155 PREVIEW_ERROR_METAFILE_COPY_FAILED,
155 PREVIEW_ERROR_METAFILE_INIT_FAILED_DEPRECATED, 156 PREVIEW_ERROR_METAFILE_INIT_FAILED_DEPRECATED,
156 PREVIEW_ERROR_ZERO_PAGES, 157 PREVIEW_ERROR_ZERO_PAGES,
(...skipping 11 matching lines...) Expand all
168 }; 169 };
169 170
170 // RenderViewObserver implementation. 171 // RenderViewObserver implementation.
171 bool OnMessageReceived(const IPC::Message& message) override; 172 bool OnMessageReceived(const IPC::Message& message) override;
172 void PrintPage(blink::WebLocalFrame* frame, bool user_initiated) override; 173 void PrintPage(blink::WebLocalFrame* frame, bool user_initiated) override;
173 void DidStartLoading() override; 174 void DidStartLoading() override;
174 void DidStopLoading() override; 175 void DidStopLoading() override;
175 void OnDestruct() override; 176 void OnDestruct() override;
176 177
177 // Message handlers --------------------------------------------------------- 178 // Message handlers ---------------------------------------------------------
178 #if defined(ENABLE_BASIC_PRINTING) 179 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
179 void OnPrintPages(); 180 void OnPrintPages();
180 void OnPrintForSystemDialog(); 181 void OnPrintForSystemDialog();
181 void OnPrintForPrintPreview(const base::DictionaryValue& job_settings); 182 void OnPrintForPrintPreview(const base::DictionaryValue& job_settings);
182 #endif // defined(ENABLE_BASIC_PRINTING) 183 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
183 #if defined(ENABLE_PRINT_PREVIEW) 184 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
184 void OnInitiatePrintPreview(bool selection_only); 185 void OnInitiatePrintPreview(bool selection_only);
185 void OnPrintPreview(const base::DictionaryValue& settings); 186 void OnPrintPreview(const base::DictionaryValue& settings);
186 #endif // defined(ENABLE_PRINT_PREVIEW) 187 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
187 void OnPrintingDone(bool success); 188 void OnPrintingDone(bool success);
188 189
189 // Get |page_size| and |content_area| information from 190 // Get |page_size| and |content_area| information from
190 // |page_layout_in_points|. 191 // |page_layout_in_points|.
191 void GetPageSizeAndContentAreaFromPageLayout( 192 void GetPageSizeAndContentAreaFromPageLayout(
192 const PageSizeMargins& page_layout_in_points, 193 const PageSizeMargins& page_layout_in_points,
193 gfx::Size* page_size, 194 gfx::Size* page_size,
194 gfx::Rect* content_area); 195 gfx::Rect* content_area);
195 196
196 // Update |ignore_css_margins_| based on settings. 197 // Update |ignore_css_margins_| based on settings.
197 void UpdateFrameMarginsCssInfo(const base::DictionaryValue& settings); 198 void UpdateFrameMarginsCssInfo(const base::DictionaryValue& settings);
198 199
199 #if defined(ENABLE_PRINT_PREVIEW) 200 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
200 // Prepare frame for creating preview document. 201 // Prepare frame for creating preview document.
201 void PrepareFrameForPreviewDocument(); 202 void PrepareFrameForPreviewDocument();
202 203
203 // Continue creating preview document. 204 // Continue creating preview document.
204 void OnFramePreparedForPreviewDocument(); 205 void OnFramePreparedForPreviewDocument();
205 206
206 // Initialize the print preview document. 207 // Initialize the print preview document.
207 bool CreatePreviewDocument(); 208 bool CreatePreviewDocument();
208 209
209 // Renders a print preview page. |page_number| is 0-based. 210 // Renders a print preview page. |page_number| is 0-based.
210 // Returns true if print preview should continue, false on failure. 211 // Returns true if print preview should continue, false on failure.
211 bool RenderPreviewPage(int page_number, 212 bool RenderPreviewPage(int page_number,
212 const PrintMsg_Print_Params& print_params); 213 const PrintMsg_Print_Params& print_params);
213 214
214 // Finalize the print ready preview document. 215 // Finalize the print ready preview document.
215 bool FinalizePrintReadyDocument(); 216 bool FinalizePrintReadyDocument();
216 #endif // defined(ENABLE_PRINT_PREVIEW) 217 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
217 218
218 // Enable/Disable window.print calls. If |blocked| is true window.print 219 // Enable/Disable window.print calls. If |blocked| is true window.print
219 // calls will silently fail. Call with |blocked| set to false to reenable. 220 // calls will silently fail. Call with |blocked| set to false to reenable.
220 void SetScriptedPrintBlocked(bool blocked); 221 void SetScriptedPrintBlocked(bool blocked);
221 222
222 // Main printing code ------------------------------------------------------- 223 // Main printing code -------------------------------------------------------
223 224
224 #if defined(ENABLE_BASIC_PRINTING) 225 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
225 // |is_scripted| should be true when the call is coming from window.print() 226 // |is_scripted| should be true when the call is coming from window.print()
226 void Print(blink::WebLocalFrame* frame, 227 void Print(blink::WebLocalFrame* frame,
227 const blink::WebNode& node, 228 const blink::WebNode& node,
228 bool is_scripted); 229 bool is_scripted);
229 #endif // defined(ENABLE_BASIC_PRINTING) 230 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
230 231
231 // Notification when printing is done - signal tear-down/free resources. 232 // Notification when printing is done - signal tear-down/free resources.
232 void DidFinishPrinting(PrintingResult result); 233 void DidFinishPrinting(PrintingResult result);
233 234
234 // Print Settings ----------------------------------------------------------- 235 // Print Settings -----------------------------------------------------------
235 236
236 // Initialize print page settings with default settings. 237 // Initialize print page settings with default settings.
237 // Used only for native printing workflow. 238 // Used only for native printing workflow.
238 bool InitPrintSettings(bool fit_to_paper_size); 239 bool InitPrintSettings(bool fit_to_paper_size);
239 240
240 // Calculate number of pages in source document. 241 // Calculate number of pages in source document.
241 bool CalculateNumberOfPages(blink::WebLocalFrame* frame, 242 bool CalculateNumberOfPages(blink::WebLocalFrame* frame,
242 const blink::WebNode& node, 243 const blink::WebNode& node,
243 int* number_of_pages); 244 int* number_of_pages);
244 245
245 #if defined(ENABLE_PRINT_PREVIEW) 246 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
246 // Set options for print preset from source PDF document. 247 // Set options for print preset from source PDF document.
247 bool SetOptionsFromPdfDocument( 248 bool SetOptionsFromPdfDocument(
248 PrintHostMsg_SetOptionsFromDocument_Params* options); 249 PrintHostMsg_SetOptionsFromDocument_Params* options);
249 250
250 // Update the current print settings with new |passed_job_settings|. 251 // Update the current print settings with new |passed_job_settings|.
251 // |passed_job_settings| dictionary contains print job details such as printer 252 // |passed_job_settings| dictionary contains print job details such as printer
252 // name, number of copies, page range, etc. 253 // name, number of copies, page range, etc.
253 bool UpdatePrintSettings(blink::WebLocalFrame* frame, 254 bool UpdatePrintSettings(blink::WebLocalFrame* frame,
254 const blink::WebNode& node, 255 const blink::WebNode& node,
255 const base::DictionaryValue& passed_job_settings); 256 const base::DictionaryValue& passed_job_settings);
256 #endif // defined(ENABLE_PRINT_PREVIEW) 257 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
257 258
258 // Get final print settings from the user. 259 // Get final print settings from the user.
259 // Return false if the user cancels or on error. 260 // Return false if the user cancels or on error.
260 bool GetPrintSettingsFromUser(blink::WebLocalFrame* frame, 261 bool GetPrintSettingsFromUser(blink::WebLocalFrame* frame,
261 const blink::WebNode& node, 262 const blink::WebNode& node,
262 int expected_pages_count, 263 int expected_pages_count,
263 bool is_scripted); 264 bool is_scripted);
264 265
265 // Page Printing / Rendering ------------------------------------------------ 266 // Page Printing / Rendering ------------------------------------------------
266 267
267 #if defined(ENABLE_BASIC_PRINTING) 268 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
268 void OnFramePreparedForPrintPages(); 269 void OnFramePreparedForPrintPages();
269 void PrintPages(); 270 void PrintPages();
270 bool PrintPagesNative(blink::WebLocalFrame* frame, int page_count); 271 bool PrintPagesNative(blink::WebLocalFrame* frame, int page_count);
271 void FinishFramePrinting(); 272 void FinishFramePrinting();
272 // Render the frame for printing. 273 // Render the frame for printing.
273 bool RenderPagesForPrint(blink::WebLocalFrame* frame, 274 bool RenderPagesForPrint(blink::WebLocalFrame* frame,
274 const blink::WebNode& node); 275 const blink::WebNode& node);
275 #endif // defined(ENABLE_BASIC_PRINTING) 276 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
276 277
277 // Prints the page listed in |params|. 278 // Prints the page listed in |params|.
278 #if defined(OS_MACOSX) 279 #if defined(OS_MACOSX)
279 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, 280 void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
280 blink::WebLocalFrame* frame); 281 blink::WebLocalFrame* frame);
281 #else 282 #else
282 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, 283 void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
283 blink::WebLocalFrame* frame, 284 blink::WebLocalFrame* frame,
284 PdfMetafileSkia* metafile, 285 PdfMetafileSkia* metafile,
285 gfx::Size* page_size_in_dpi, 286 gfx::Size* page_size_in_dpi,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 bool ignore_css_margins, 322 bool ignore_css_margins,
322 double* scale_factor, 323 double* scale_factor,
323 PageSizeMargins* page_layout_in_points); 324 PageSizeMargins* page_layout_in_points);
324 325
325 // Return an array of pages to print given the print |params| and an expected 326 // Return an array of pages to print given the print |params| and an expected
326 // |page_count|. Page numbers are zero-based. 327 // |page_count|. Page numbers are zero-based.
327 static std::vector<int> GetPrintedPages( 328 static std::vector<int> GetPrintedPages(
328 const PrintMsg_PrintPages_Params& params, 329 const PrintMsg_PrintPages_Params& params,
329 int page_count); 330 int page_count);
330 331
331 #if defined(ENABLE_PRINT_PREVIEW) 332 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
332 // Given the |device| and |canvas| to draw on, prints the appropriate headers 333 // Given the |device| and |canvas| to draw on, prints the appropriate headers
333 // and footers using strings from |header_footer_info| on to the canvas. 334 // and footers using strings from |header_footer_info| on to the canvas.
334 static void PrintHeaderAndFooter(blink::WebCanvas* canvas, 335 static void PrintHeaderAndFooter(blink::WebCanvas* canvas,
335 int page_number, 336 int page_number,
336 int total_pages, 337 int total_pages,
337 const blink::WebFrame& source_frame, 338 const blink::WebFrame& source_frame,
338 float webkit_scale_factor, 339 float webkit_scale_factor,
339 const PageSizeMargins& page_layout_in_points, 340 const PageSizeMargins& page_layout_in_points,
340 const PrintMsg_Print_Params& params); 341 const PrintMsg_Print_Params& params);
341 #endif // defined(ENABLE_PRINT_PREVIEW) 342 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
342 343
343 bool GetPrintFrame(blink::WebLocalFrame** frame); 344 bool GetPrintFrame(blink::WebLocalFrame** frame);
344 345
345 // Script Initiated Printing ------------------------------------------------ 346 // Script Initiated Printing ------------------------------------------------
346 347
347 // Return true if script initiated printing is currently 348 // Return true if script initiated printing is currently
348 // allowed. |user_initiated| should be true when a user event triggered the 349 // allowed. |user_initiated| should be true when a user event triggered the
349 // script, most likely by pressing a print button on the page. 350 // script, most likely by pressing a print button on the page.
350 bool IsScriptInitiatedPrintAllowed(blink::WebFrame* frame, 351 bool IsScriptInitiatedPrintAllowed(blink::WebFrame* frame,
351 bool user_initiated); 352 bool user_initiated);
352 353
353 #if defined(ENABLE_PRINT_PREVIEW) 354 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
354 // Shows scripted print preview when options from plugin are available. 355 // Shows scripted print preview when options from plugin are available.
355 void ShowScriptedPrintPreview(); 356 void ShowScriptedPrintPreview();
356 357
357 void RequestPrintPreview(PrintPreviewRequestType type); 358 void RequestPrintPreview(PrintPreviewRequestType type);
358 359
359 // Checks whether print preview should continue or not. 360 // Checks whether print preview should continue or not.
360 // Returns true if canceling, false if continuing. 361 // Returns true if canceling, false if continuing.
361 bool CheckForCancel(); 362 bool CheckForCancel();
362 363
363 // Notifies the browser a print preview page has been rendered. 364 // Notifies the browser a print preview page has been rendered.
364 // |page_number| is 0-based. 365 // |page_number| is 0-based.
365 // For a valid |page_number| with modifiable content, 366 // For a valid |page_number| with modifiable content,
366 // |metafile| is the rendered page. Otherwise |metafile| is NULL. 367 // |metafile| is the rendered page. Otherwise |metafile| is NULL.
367 // Returns true if print preview should continue, false on failure. 368 // Returns true if print preview should continue, false on failure.
368 bool PreviewPageRendered(int page_number, PdfMetafileSkia* metafile); 369 bool PreviewPageRendered(int page_number, PdfMetafileSkia* metafile);
369 #endif // defined(ENABLE_PRINT_PREVIEW) 370 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
370 371
371 void SetPrintPagesParams(const PrintMsg_PrintPages_Params& settings); 372 void SetPrintPagesParams(const PrintMsg_PrintPages_Params& settings);
372 373
373 // WebView used only to print the selection. 374 // WebView used only to print the selection.
374 std::unique_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; 375 std::unique_ptr<PrepareFrameAndViewForPrint> prep_frame_view_;
375 bool reset_prep_frame_view_; 376 bool reset_prep_frame_view_;
376 377
377 std::unique_ptr<PrintMsg_PrintPages_Params> print_pages_params_; 378 std::unique_ptr<PrintMsg_PrintPages_Params> print_pages_params_;
378 bool is_print_ready_metafile_sent_; 379 bool is_print_ready_metafile_sent_;
379 bool ignore_css_margins_; 380 bool ignore_css_margins_;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 base::Closure on_stop_loading_closure_; 532 base::Closure on_stop_loading_closure_;
532 533
533 base::WeakPtrFactory<PrintWebViewHelper> weak_ptr_factory_; 534 base::WeakPtrFactory<PrintWebViewHelper> weak_ptr_factory_;
534 535
535 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); 536 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper);
536 }; 537 };
537 538
538 } // namespace printing 539 } // namespace printing
539 540
540 #endif // COMPONENTS_PRINTING_RENDERER_PRINT_WEB_VIEW_HELPER_H_ 541 #endif // COMPONENTS_PRINTING_RENDERER_PRINT_WEB_VIEW_HELPER_H_
OLDNEW
« no previous file with comments | « components/printing/common/print_messages.cc ('k') | components/printing/renderer/print_web_view_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698