OLD | NEW |
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 CHROME_RENDERER_PRINTING_PRINT_WEB_VIEW_HELPER_H_ | 5 #ifndef CHROME_RENDERER_PRINTING_PRINT_WEB_VIEW_HELPER_H_ |
6 #define CHROME_RENDERER_PRINTING_PRINT_WEB_VIEW_HELPER_H_ | 6 #define CHROME_RENDERER_PRINTING_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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 public: | 68 public: |
69 explicit PrintWebViewHelper(content::RenderView* render_view); | 69 explicit PrintWebViewHelper(content::RenderView* render_view); |
70 virtual ~PrintWebViewHelper(); | 70 virtual ~PrintWebViewHelper(); |
71 | 71 |
72 bool IsPrintingEnabled(); | 72 bool IsPrintingEnabled(); |
73 | 73 |
74 void PrintNode(const blink::WebNode& node); | 74 void PrintNode(const blink::WebNode& node); |
75 | 75 |
76 private: | 76 private: |
77 friend class PrintWebViewHelperTestBase; | 77 friend class PrintWebViewHelperTestBase; |
78 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, | 78 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, |
79 BlockScriptInitiatedPrinting); | 79 BlockScriptInitiatedPrinting); |
80 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, | |
81 BlockScriptInitiatedPrintingFromPopup); | |
82 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, OnPrintPages); | 80 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, OnPrintPages); |
83 | 81 |
84 #if defined(OS_WIN) || defined(OS_MACOSX) | 82 #if defined(OS_WIN) || defined(OS_MACOSX) |
85 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintLayoutTest); | 83 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintLayoutTest); |
86 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintWithIframe); | 84 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintWithIframe); |
87 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 85 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
88 | 86 |
89 enum PrintingResult { | 87 enum PrintingResult { |
90 OK, | 88 OK, |
91 FAIL_PRINT_INIT, | 89 FAIL_PRINT_INIT, |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 bool GetPrintFrame(blink::WebLocalFrame** frame); | 285 bool GetPrintFrame(blink::WebLocalFrame** frame); |
288 | 286 |
289 // Script Initiated Printing ------------------------------------------------ | 287 // Script Initiated Printing ------------------------------------------------ |
290 | 288 |
291 // Return true if script initiated printing is currently | 289 // Return true if script initiated printing is currently |
292 // allowed. |user_initiated| should be true when a user event triggered the | 290 // allowed. |user_initiated| should be true when a user event triggered the |
293 // script, most likely by pressing a print button on the page. | 291 // script, most likely by pressing a print button on the page. |
294 bool IsScriptInitiatedPrintAllowed(blink::WebFrame* frame, | 292 bool IsScriptInitiatedPrintAllowed(blink::WebFrame* frame, |
295 bool user_initiated); | 293 bool user_initiated); |
296 | 294 |
297 // Returns true if script initiated printing occurs too often. | 295 // Shows scripted print preview when options from plugin are available. |
298 bool IsScriptInitiatedPrintTooFrequent(blink::WebFrame* frame); | |
299 | |
300 // Reset the counter for script initiated printing. | |
301 // Scripted printing will be allowed to continue. | |
302 void ResetScriptedPrintCount(); | |
303 | |
304 // Increment the counter for script initiated printing. | |
305 // Scripted printing will be blocked for a limited amount of time. | |
306 void IncrementScriptedPrintCount(); | |
307 | |
308 // Shows scripted print preview when options from plugin are availible. | |
309 void ShowScriptedPrintPreview(); | 296 void ShowScriptedPrintPreview(); |
310 | 297 |
311 void RequestPrintPreview(PrintPreviewRequestType type); | 298 void RequestPrintPreview(PrintPreviewRequestType type); |
312 | 299 |
313 // Checks whether print preview should continue or not. | 300 // Checks whether print preview should continue or not. |
314 // Returns true if cancelling, false if continuing. | 301 // Returns true if canceling, false if continuing. |
315 bool CheckForCancel(); | 302 bool CheckForCancel(); |
316 | 303 |
317 // Notifies the browser a print preview page has been rendered. | 304 // Notifies the browser a print preview page has been rendered. |
318 // |page_number| is 0-based. | 305 // |page_number| is 0-based. |
319 // For a valid |page_number| with modifiable content, | 306 // For a valid |page_number| with modifiable content, |
320 // |metafile| is the rendered page. Otherwise |metafile| is NULL. | 307 // |metafile| is the rendered page. Otherwise |metafile| is NULL. |
321 // Returns true if print preview should continue, false on failure. | 308 // Returns true if print preview should continue, false on failure. |
322 bool PreviewPageRendered(int page_number, Metafile* metafile); | 309 bool PreviewPageRendered(int page_number, Metafile* metafile); |
323 | 310 |
324 void SetPrintPagesParams(const PrintMsg_PrintPages_Params& settings); | 311 void SetPrintPagesParams(const PrintMsg_PrintPages_Params& settings); |
325 | 312 |
326 // WebView used only to print the selection. | 313 // WebView used only to print the selection. |
327 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; | 314 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; |
328 bool reset_prep_frame_view_; | 315 bool reset_prep_frame_view_; |
329 | 316 |
330 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; | 317 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; |
331 bool is_preview_enabled_; | |
332 bool is_scripted_print_throttling_disabled_; | |
333 bool is_print_ready_metafile_sent_; | 318 bool is_print_ready_metafile_sent_; |
334 bool ignore_css_margins_; | 319 bool ignore_css_margins_; |
335 | |
336 // Used for scripted initiated printing blocking. | 320 // Used for scripted initiated printing blocking. |
337 base::Time last_cancelled_script_print_; | |
338 int user_cancelled_scripted_print_count_; | |
339 bool is_scripted_printing_blocked_; | 321 bool is_scripted_printing_blocked_; |
340 | 322 |
341 // Let the browser process know of a printing failure. Only set to false when | 323 // Let the browser process know of a printing failure. Only set to false when |
342 // the failure came from the browser in the first place. | 324 // the failure came from the browser in the first place. |
343 bool notify_browser_of_print_failure_; | 325 bool notify_browser_of_print_failure_; |
344 | 326 |
345 // True, when printing from print preview. | 327 // True, when printing from print preview. |
346 bool print_for_preview_; | 328 bool print_for_preview_; |
347 | 329 |
348 // Strings generated by the browser process to be printed as headers and | 330 // Strings generated by the browser process to be printed as headers and |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 // hangs because RequestPrintPreview is called before DidStopLoading() is | 450 // hangs because RequestPrintPreview is called before DidStopLoading() is |
469 // called. This is a store for the RequestPrintPreview() call and its | 451 // called. This is a store for the RequestPrintPreview() call and its |
470 // parameters so that it can be invoked after DidStopLoading. | 452 // parameters so that it can be invoked after DidStopLoading. |
471 base::Closure on_stop_loading_closure_; | 453 base::Closure on_stop_loading_closure_; |
472 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 454 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
473 }; | 455 }; |
474 | 456 |
475 } // namespace printing | 457 } // namespace printing |
476 | 458 |
477 #endif // CHROME_RENDERER_PRINTING_PRINT_WEB_VIEW_HELPER_H_ | 459 #endif // CHROME_RENDERER_PRINTING_PRINT_WEB_VIEW_HELPER_H_ |
OLD | NEW |