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

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

Issue 1556463003: Mark printing code as basic printing and/or print preview code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 11 months 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 <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 BlockScriptInitiatedPrintingFromPopup); 130 BlockScriptInitiatedPrintingFromPopup);
131 #if defined(OS_WIN) || defined(OS_MACOSX) 131 #if defined(OS_WIN) || defined(OS_MACOSX)
132 FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintWebViewHelperTest, PrintLayoutTest); 132 FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintWebViewHelperTest, PrintLayoutTest);
133 FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintWebViewHelperTest, PrintWithIframe); 133 FRIEND_TEST_ALL_PREFIXES(MAYBE_PrintWebViewHelperTest, PrintWithIframe);
134 #endif // defined(OS_WIN) || defined(OS_MACOSX) 134 #endif // defined(OS_WIN) || defined(OS_MACOSX)
135 135
136 enum PrintingResult { 136 enum PrintingResult {
137 OK, 137 OK,
138 FAIL_PRINT_INIT, 138 FAIL_PRINT_INIT,
139 FAIL_PRINT, 139 FAIL_PRINT,
140 #if defined(ENABLE_PRINT_PREVIEW)
140 FAIL_PREVIEW, 141 FAIL_PREVIEW,
142 #endif
141 }; 143 };
142 144
143 enum PrintPreviewErrorBuckets { 145 enum PrintPreviewErrorBuckets {
144 PREVIEW_ERROR_NONE, // Always first. 146 PREVIEW_ERROR_NONE, // Always first.
145 PREVIEW_ERROR_BAD_SETTING, 147 PREVIEW_ERROR_BAD_SETTING,
146 PREVIEW_ERROR_METAFILE_COPY_FAILED, 148 PREVIEW_ERROR_METAFILE_COPY_FAILED,
147 PREVIEW_ERROR_METAFILE_INIT_FAILED, 149 PREVIEW_ERROR_METAFILE_INIT_FAILED,
148 PREVIEW_ERROR_ZERO_PAGES, 150 PREVIEW_ERROR_ZERO_PAGES,
149 PREVIEW_ERROR_MAC_DRAFT_METAFILE_INIT_FAILED, 151 PREVIEW_ERROR_MAC_DRAFT_METAFILE_INIT_FAILED,
150 PREVIEW_ERROR_PAGE_RENDERED_WITHOUT_METAFILE, 152 PREVIEW_ERROR_PAGE_RENDERED_WITHOUT_METAFILE,
(...skipping 11 matching lines...) Expand all
162 // RenderViewObserver implementation. 164 // RenderViewObserver implementation.
163 bool OnMessageReceived(const IPC::Message& message) override; 165 bool OnMessageReceived(const IPC::Message& message) override;
164 void PrintPage(blink::WebLocalFrame* frame, bool user_initiated) override; 166 void PrintPage(blink::WebLocalFrame* frame, bool user_initiated) override;
165 void DidStartLoading() override; 167 void DidStartLoading() override;
166 void DidStopLoading() override; 168 void DidStopLoading() override;
167 169
168 // Message handlers --------------------------------------------------------- 170 // Message handlers ---------------------------------------------------------
169 #if defined(ENABLE_BASIC_PRINTING) 171 #if defined(ENABLE_BASIC_PRINTING)
170 void OnPrintPages(); 172 void OnPrintPages();
171 void OnPrintForSystemDialog(); 173 void OnPrintForSystemDialog();
172 #endif // ENABLE_BASIC_PRINTING 174 void OnPrintForPrintPreview(const base::DictionaryValue& job_settings);
175 #endif // defined(ENABLE_BASIC_PRINTING)
176 #if defined(ENABLE_PRINT_PREVIEW)
173 void OnInitiatePrintPreview(bool selection_only); 177 void OnInitiatePrintPreview(bool selection_only);
174 void OnPrintPreview(const base::DictionaryValue& settings); 178 void OnPrintPreview(const base::DictionaryValue& settings);
175 void OnPrintForPrintPreview(const base::DictionaryValue& job_settings); 179 #endif // defined(ENABLE_PRINT_PREVIEW)
176 void OnPrintingDone(bool success); 180 void OnPrintingDone(bool success);
177 181
178 // Get |page_size| and |content_area| information from 182 // Get |page_size| and |content_area| information from
179 // |page_layout_in_points|. 183 // |page_layout_in_points|.
180 void GetPageSizeAndContentAreaFromPageLayout( 184 void GetPageSizeAndContentAreaFromPageLayout(
181 const PageSizeMargins& page_layout_in_points, 185 const PageSizeMargins& page_layout_in_points,
182 gfx::Size* page_size, 186 gfx::Size* page_size,
183 gfx::Rect* content_area); 187 gfx::Rect* content_area);
184 188
185 // Update |ignore_css_margins_| based on settings. 189 // Update |ignore_css_margins_| based on settings.
186 void UpdateFrameMarginsCssInfo(const base::DictionaryValue& settings); 190 void UpdateFrameMarginsCssInfo(const base::DictionaryValue& settings);
187 191
188 // Returns true if the current destination printer is PRINT_TO_PDF. 192 #if defined(ENABLE_PRINT_PREVIEW)
189 bool IsPrintToPdfRequested(const base::DictionaryValue& settings);
190
191 // Prepare frame for creating preview document. 193 // Prepare frame for creating preview document.
192 void PrepareFrameForPreviewDocument(); 194 void PrepareFrameForPreviewDocument();
193 195
194 // Continue creating preview document. 196 // Continue creating preview document.
195 void OnFramePreparedForPreviewDocument(); 197 void OnFramePreparedForPreviewDocument();
196 198
197 // Initialize the print preview document. 199 // Initialize the print preview document.
198 bool CreatePreviewDocument(); 200 bool CreatePreviewDocument();
199 201
200 // Renders a print preview page. |page_number| is 0-based. 202 // Renders a print preview page. |page_number| is 0-based.
201 // Returns true if print preview should continue, false on failure. 203 // Returns true if print preview should continue, false on failure.
202 bool RenderPreviewPage(int page_number, 204 bool RenderPreviewPage(int page_number,
203 const PrintMsg_Print_Params& print_params); 205 const PrintMsg_Print_Params& print_params);
204 206
205 // Finalize the print ready preview document. 207 // Finalize the print ready preview document.
206 bool FinalizePrintReadyDocument(); 208 bool FinalizePrintReadyDocument();
209 #endif // defined(ENABLE_PRINT_PREVIEW)
207 210
208 // Enable/Disable window.print calls. If |blocked| is true window.print 211 // Enable/Disable window.print calls. If |blocked| is true window.print
209 // calls will silently fail. Call with |blocked| set to false to reenable. 212 // calls will silently fail. Call with |blocked| set to false to reenable.
210 void SetScriptedPrintBlocked(bool blocked); 213 void SetScriptedPrintBlocked(bool blocked);
211 214
212 // Main printing code ------------------------------------------------------- 215 // Main printing code -------------------------------------------------------
213 216
217 #if defined(ENABLE_BASIC_PRINTING)
214 // |is_scripted| should be true when the call is coming from window.print() 218 // |is_scripted| should be true when the call is coming from window.print()
215 void Print(blink::WebLocalFrame* frame, 219 void Print(blink::WebLocalFrame* frame,
216 const blink::WebNode& node, 220 const blink::WebNode& node,
217 bool is_scripted); 221 bool is_scripted);
222 #endif // defined(ENABLE_BASIC_PRINTING)
218 223
219 // Notification when printing is done - signal tear-down/free resources. 224 // Notification when printing is done - signal tear-down/free resources.
220 void DidFinishPrinting(PrintingResult result); 225 void DidFinishPrinting(PrintingResult result);
221 226
222 // Print Settings ----------------------------------------------------------- 227 // Print Settings -----------------------------------------------------------
223 228
224 // Initialize print page settings with default settings. 229 // Initialize print page settings with default settings.
225 // Used only for native printing workflow. 230 // Used only for native printing workflow.
226 bool InitPrintSettings(bool fit_to_paper_size); 231 bool InitPrintSettings(bool fit_to_paper_size);
227 232
228 // Calculate number of pages in source document. 233 // Calculate number of pages in source document.
229 bool CalculateNumberOfPages(blink::WebLocalFrame* frame, 234 bool CalculateNumberOfPages(blink::WebLocalFrame* frame,
230 const blink::WebNode& node, 235 const blink::WebNode& node,
231 int* number_of_pages); 236 int* number_of_pages);
232 237
238 #if defined(ENABLE_PRINT_PREVIEW)
233 // Set options for print preset from source PDF document. 239 // Set options for print preset from source PDF document.
234 bool SetOptionsFromPdfDocument( 240 bool SetOptionsFromPdfDocument(
235 PrintHostMsg_SetOptionsFromDocument_Params* options); 241 PrintHostMsg_SetOptionsFromDocument_Params* options);
236 242
237 // Update the current print settings with new |passed_job_settings|. 243 // Update the current print settings with new |passed_job_settings|.
238 // |passed_job_settings| dictionary contains print job details such as printer 244 // |passed_job_settings| dictionary contains print job details such as printer
239 // name, number of copies, page range, etc. 245 // name, number of copies, page range, etc.
240 bool UpdatePrintSettings(blink::WebLocalFrame* frame, 246 bool UpdatePrintSettings(blink::WebLocalFrame* frame,
241 const blink::WebNode& node, 247 const blink::WebNode& node,
242 const base::DictionaryValue& passed_job_settings); 248 const base::DictionaryValue& passed_job_settings);
249 #endif // defined(ENABLE_PRINT_PREVIEW)
243 250
244 // Get final print settings from the user. 251 // Get final print settings from the user.
245 // Return false if the user cancels or on error. 252 // Return false if the user cancels or on error.
246 bool GetPrintSettingsFromUser(blink::WebLocalFrame* frame, 253 bool GetPrintSettingsFromUser(blink::WebLocalFrame* frame,
247 const blink::WebNode& node, 254 const blink::WebNode& node,
248 int expected_pages_count, 255 int expected_pages_count,
249 bool is_scripted); 256 bool is_scripted);
250 257
251 // Page Printing / Rendering ------------------------------------------------ 258 // Page Printing / Rendering ------------------------------------------------
252 259
260 #if defined(ENABLE_BASIC_PRINTING)
253 void OnFramePreparedForPrintPages(); 261 void OnFramePreparedForPrintPages();
254 void PrintPages(); 262 void PrintPages();
255 bool PrintPagesNative(blink::WebFrame* frame, int page_count); 263 bool PrintPagesNative(blink::WebFrame* frame, int page_count);
256 void FinishFramePrinting(); 264 void FinishFramePrinting();
265 // Render the frame for printing.
266 bool RenderPagesForPrint(blink::WebLocalFrame* frame,
267 const blink::WebNode& node);
268 #endif // defined(ENABLE_BASIC_PRINTING)
257 269
258 // Prints the page listed in |params|. 270 // Prints the page listed in |params|.
259 #if defined(OS_LINUX) || defined(OS_ANDROID) 271 #if defined(OS_LINUX) || defined(OS_ANDROID)
260 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, 272 void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
261 blink::WebFrame* frame, 273 blink::WebFrame* frame,
262 PdfMetafileSkia* metafile); 274 PdfMetafileSkia* metafile);
263 #elif defined(OS_WIN) 275 #elif defined(OS_WIN)
264 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, 276 void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
265 blink::WebFrame* frame, 277 blink::WebFrame* frame,
266 PdfMetafileSkia* metafile, 278 PdfMetafileSkia* metafile,
267 gfx::Size* page_size_in_dpi, 279 gfx::Size* page_size_in_dpi,
268 gfx::Rect* content_area_in_dpi); 280 gfx::Rect* content_area_in_dpi);
269 #else 281 #else
270 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, 282 void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
271 blink::WebFrame* frame); 283 blink::WebFrame* frame);
272 #endif 284 #endif
273 285
274 // Render the frame for printing.
275 bool RenderPagesForPrint(blink::WebLocalFrame* frame,
276 const blink::WebNode& node);
277
278 // Platform specific helper function for rendering page(s) to |metafile|. 286 // Platform specific helper function for rendering page(s) to |metafile|.
279 #if defined(OS_MACOSX) 287 #if defined(OS_MACOSX)
280 void RenderPage(const PrintMsg_Print_Params& params, 288 void RenderPage(const PrintMsg_Print_Params& params,
281 int page_number, 289 int page_number,
282 blink::WebFrame* frame, 290 blink::WebFrame* frame,
283 bool is_preview, 291 bool is_preview,
284 PdfMetafileSkia* metafile, 292 PdfMetafileSkia* metafile,
285 gfx::Size* page_size, 293 gfx::Size* page_size,
286 gfx::Rect* content_rect); 294 gfx::Rect* content_rect);
287 #endif // defined(OS_MACOSX) 295 #endif // defined(OS_MACOSX)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 bool GetPrintFrame(blink::WebLocalFrame** frame); 340 bool GetPrintFrame(blink::WebLocalFrame** frame);
333 341
334 // Script Initiated Printing ------------------------------------------------ 342 // Script Initiated Printing ------------------------------------------------
335 343
336 // Return true if script initiated printing is currently 344 // Return true if script initiated printing is currently
337 // allowed. |user_initiated| should be true when a user event triggered the 345 // allowed. |user_initiated| should be true when a user event triggered the
338 // script, most likely by pressing a print button on the page. 346 // script, most likely by pressing a print button on the page.
339 bool IsScriptInitiatedPrintAllowed(blink::WebFrame* frame, 347 bool IsScriptInitiatedPrintAllowed(blink::WebFrame* frame,
340 bool user_initiated); 348 bool user_initiated);
341 349
350 #if defined(ENABLE_PRINT_PREVIEW)
342 // Shows scripted print preview when options from plugin are available. 351 // Shows scripted print preview when options from plugin are available.
343 void ShowScriptedPrintPreview(); 352 void ShowScriptedPrintPreview();
344 353
345 void RequestPrintPreview(PrintPreviewRequestType type); 354 void RequestPrintPreview(PrintPreviewRequestType type);
346 355
347 // Checks whether print preview should continue or not. 356 // Checks whether print preview should continue or not.
348 // Returns true if canceling, false if continuing. 357 // Returns true if canceling, false if continuing.
349 bool CheckForCancel(); 358 bool CheckForCancel();
350 359
351 // Notifies the browser a print preview page has been rendered. 360 // Notifies the browser a print preview page has been rendered.
352 // |page_number| is 0-based. 361 // |page_number| is 0-based.
353 // For a valid |page_number| with modifiable content, 362 // For a valid |page_number| with modifiable content,
354 // |metafile| is the rendered page. Otherwise |metafile| is NULL. 363 // |metafile| is the rendered page. Otherwise |metafile| is NULL.
355 // Returns true if print preview should continue, false on failure. 364 // Returns true if print preview should continue, false on failure.
356 bool PreviewPageRendered(int page_number, PdfMetafileSkia* metafile); 365 bool PreviewPageRendered(int page_number, PdfMetafileSkia* metafile);
366 #endif // defined(ENABLE_PRINT_PREVIEW)
357 367
358 void SetPrintPagesParams(const PrintMsg_PrintPages_Params& settings); 368 void SetPrintPagesParams(const PrintMsg_PrintPages_Params& settings);
359 369
360 // WebView used only to print the selection. 370 // WebView used only to print the selection.
361 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; 371 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_;
362 bool reset_prep_frame_view_; 372 bool reset_prep_frame_view_;
363 373
364 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; 374 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_;
365 bool is_print_ready_metafile_sent_; 375 bool is_print_ready_metafile_sent_;
366 bool ignore_css_margins_; 376 bool ignore_css_margins_;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 base::Closure on_stop_loading_closure_; 528 base::Closure on_stop_loading_closure_;
519 529
520 base::WeakPtrFactory<PrintWebViewHelper> weak_ptr_factory_; 530 base::WeakPtrFactory<PrintWebViewHelper> weak_ptr_factory_;
521 531
522 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); 532 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper);
523 }; 533 };
524 534
525 } // namespace printing 535 } // namespace printing
526 536
527 #endif // COMPONENTS_PRINTING_RENDERER_PRINT_WEB_VIEW_HELPER_H_ 537 #endif // COMPONENTS_PRINTING_RENDERER_PRINT_WEB_VIEW_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698