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

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

Issue 550033002: Fixed print_web_view_helper for CEF. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tue Sep 9 16:51:46 PDT 2014 Created 6 years, 3 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
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | chrome/renderer/printing/print_web_view_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // PrintWebViewHelper handles most of the printing grunt work for RenderView. 62 // PrintWebViewHelper handles most of the printing grunt work for RenderView.
63 // We plan on making print asynchronous and that will require copying the DOM 63 // We plan on making print asynchronous and that will require copying the DOM
64 // of the document and creating a new WebView with the contents. 64 // of the document and creating a new WebView with the contents.
65 class PrintWebViewHelper 65 class PrintWebViewHelper
66 : public content::RenderViewObserver, 66 : public content::RenderViewObserver,
67 public content::RenderViewObserverTracker<PrintWebViewHelper> { 67 public content::RenderViewObserverTracker<PrintWebViewHelper> {
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 // Disable print preview and switch to system dialog printing even if full
73 // printing is build-in. This method is used by CEF.
74 static void DisablePreview();
75
72 bool IsPrintingEnabled(); 76 bool IsPrintingEnabled();
73 77
74 void PrintNode(const blink::WebNode& node); 78 void PrintNode(const blink::WebNode& node);
75 79
76 private: 80 private:
77 friend class PrintWebViewHelperTestBase; 81 friend class PrintWebViewHelperTestBase;
78 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest, 82 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperPreviewTest,
79 BlockScriptInitiatedPrinting); 83 BlockScriptInitiatedPrinting);
80 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, OnPrintPages); 84 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, OnPrintPages);
81 85 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, OnPrintPages);
86 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest,
87 BlockScriptInitiatedPrinting);
88 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest,
89 BlockScriptInitiatedPrintingFromPopup);
82 #if defined(OS_WIN) || defined(OS_MACOSX) 90 #if defined(OS_WIN) || defined(OS_MACOSX)
83 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintLayoutTest); 91 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintLayoutTest);
84 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintWithIframe); 92 FRIEND_TEST_ALL_PREFIXES(PrintWebViewHelperTest, PrintWithIframe);
85 #endif // defined(OS_WIN) || defined(OS_MACOSX) 93 #endif // defined(OS_WIN) || defined(OS_MACOSX)
86 94
87 enum PrintingResult { 95 enum PrintingResult {
88 OK, 96 OK,
89 FAIL_PRINT_INIT, 97 FAIL_PRINT_INIT,
90 FAIL_PRINT, 98 FAIL_PRINT,
91 FAIL_PREVIEW, 99 FAIL_PREVIEW,
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 310
303 void SetPrintPagesParams(const PrintMsg_PrintPages_Params& settings); 311 void SetPrintPagesParams(const PrintMsg_PrintPages_Params& settings);
304 312
305 // WebView used only to print the selection. 313 // WebView used only to print the selection.
306 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; 314 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_;
307 bool reset_prep_frame_view_; 315 bool reset_prep_frame_view_;
308 316
309 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; 317 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_;
310 bool is_print_ready_metafile_sent_; 318 bool is_print_ready_metafile_sent_;
311 bool ignore_css_margins_; 319 bool ignore_css_margins_;
320
312 // Used for scripted initiated printing blocking. 321 // Used for scripted initiated printing blocking.
313 bool is_scripted_printing_blocked_; 322 bool is_scripted_printing_blocked_;
314 323
315 // Let the browser process know of a printing failure. Only set to false when 324 // Let the browser process know of a printing failure. Only set to false when
316 // the failure came from the browser in the first place. 325 // the failure came from the browser in the first place.
317 bool notify_browser_of_print_failure_; 326 bool notify_browser_of_print_failure_;
318 327
319 // True, when printing from print preview. 328 // True, when printing from print preview.
320 bool print_for_preview_; 329 bool print_for_preview_;
321 330
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 int print_ready_metafile_page_count_; 430 int print_ready_metafile_page_count_;
422 431
423 base::TimeDelta document_render_time_; 432 base::TimeDelta document_render_time_;
424 base::TimeTicks begin_time_; 433 base::TimeTicks begin_time_;
425 434
426 enum PrintPreviewErrorBuckets error_; 435 enum PrintPreviewErrorBuckets error_;
427 436
428 State state_; 437 State state_;
429 }; 438 };
430 439
440 class ScriptingThrottler {
441 public:
442 ScriptingThrottler();
443
444 // Returns false if script initiated printing occurs too often.
445 bool IsAllowed(blink::WebFrame* frame);
446
447 // Reset the counter for script initiated printing.
448 // Scripted printing will be allowed to continue.
449 void Reset();
450
451 private:
452 base::Time last_print_;
453 int count_ = 0;
454 DISALLOW_COPY_AND_ASSIGN(ScriptingThrottler);
455 };
456
457 ScriptingThrottler scripting_throttler_;
458
431 bool print_node_in_progress_; 459 bool print_node_in_progress_;
432 PrintPreviewContext print_preview_context_; 460 PrintPreviewContext print_preview_context_;
433 bool is_loading_; 461 bool is_loading_;
434 bool is_scripted_preview_delayed_; 462 bool is_scripted_preview_delayed_;
435 base::WeakPtrFactory<PrintWebViewHelper> weak_ptr_factory_; 463 base::WeakPtrFactory<PrintWebViewHelper> weak_ptr_factory_;
436 464
437 // Used to fix a race condition where the source is a PDF and print preview 465 // Used to fix a race condition where the source is a PDF and print preview
438 // hangs because RequestPrintPreview is called before DidStopLoading() is 466 // hangs because RequestPrintPreview is called before DidStopLoading() is
439 // called. This is a store for the RequestPrintPreview() call and its 467 // called. This is a store for the RequestPrintPreview() call and its
440 // parameters so that it can be invoked after DidStopLoading. 468 // parameters so that it can be invoked after DidStopLoading.
441 base::Closure on_stop_loading_closure_; 469 base::Closure on_stop_loading_closure_;
442 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); 470 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper);
443 }; 471 };
444 472
445 } // namespace printing 473 } // namespace printing
446 474
447 #endif // CHROME_RENDERER_PRINTING_PRINT_WEB_VIEW_HELPER_H_ 475 #endif // CHROME_RENDERER_PRINTING_PRINT_WEB_VIEW_HELPER_H_
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | chrome/renderer/printing/print_web_view_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698