OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_PRINT_WEB_VIEW_HELPER_H_ | 5 #ifndef CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
6 #define CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 6 #define CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "content/renderer/render_view_observer.h" | 12 #include "content/renderer/render_view_observer.h" |
| 13 #include "content/renderer/render_view_observer_tracker.h" |
13 #include "printing/native_metafile.h" | 14 #include "printing/native_metafile.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" |
16 #include "ui/gfx/size.h" | 17 #include "ui/gfx/size.h" |
17 | 18 |
18 class DictionaryValue; | 19 class DictionaryValue; |
19 struct PrintMsg_Print_Params; | 20 struct PrintMsg_Print_Params; |
20 struct PrintMsg_PrintPage_Params; | 21 struct PrintMsg_PrintPage_Params; |
21 struct PrintMsg_PrintPages_Params; | 22 struct PrintMsg_PrintPages_Params; |
22 | 23 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 bool use_browser_overlays_; | 63 bool use_browser_overlays_; |
63 | 64 |
64 DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint); | 65 DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint); |
65 }; | 66 }; |
66 | 67 |
67 | 68 |
68 // PrintWebViewHelper handles most of the printing grunt work for RenderView. | 69 // PrintWebViewHelper handles most of the printing grunt work for RenderView. |
69 // We plan on making print asynchronous and that will require copying the DOM | 70 // We plan on making print asynchronous and that will require copying the DOM |
70 // of the document and creating a new WebView with the contents. | 71 // of the document and creating a new WebView with the contents. |
71 class PrintWebViewHelper : public RenderViewObserver , | 72 class PrintWebViewHelper : public RenderViewObserver , |
| 73 public RenderViewObserverTracker<PrintWebViewHelper>, |
72 public WebKit::WebViewClient, | 74 public WebKit::WebViewClient, |
73 public WebKit::WebFrameClient { | 75 public WebKit::WebFrameClient { |
74 public: | 76 public: |
75 explicit PrintWebViewHelper(RenderView* render_view); | 77 explicit PrintWebViewHelper(RenderView* render_view); |
76 virtual ~PrintWebViewHelper(); | 78 virtual ~PrintWebViewHelper(); |
77 | 79 |
78 // Prints |frame| which called window.print(). | |
79 void ScriptInitiatedPrint(WebKit::WebFrame* frame); | |
80 | |
81 protected: | 80 protected: |
82 // WebKit::WebViewClient override: | 81 // WebKit::WebViewClient override: |
83 virtual void didStopLoading(); | 82 virtual void didStopLoading(); |
84 | 83 |
85 private: | 84 private: |
86 FRIEND_TEST_ALL_PREFIXES(RenderViewTest, BlockScriptInitiatedPrinting); | 85 FRIEND_TEST_ALL_PREFIXES(RenderViewTest, BlockScriptInitiatedPrinting); |
87 FRIEND_TEST_ALL_PREFIXES(RenderViewTest, OnPrintPages); | 86 FRIEND_TEST_ALL_PREFIXES(RenderViewTest, OnPrintPages); |
88 | 87 |
89 #if defined(OS_WIN) || defined(OS_MACOSX) | 88 #if defined(OS_WIN) || defined(OS_MACOSX) |
90 FRIEND_TEST_ALL_PREFIXES(RenderViewTest, PrintLayoutTest); | 89 FRIEND_TEST_ALL_PREFIXES(RenderViewTest, PrintLayoutTest); |
91 FRIEND_TEST_ALL_PREFIXES(RenderViewTest, PrintWithIframe); | 90 FRIEND_TEST_ALL_PREFIXES(RenderViewTest, PrintWithIframe); |
92 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 91 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
93 | 92 |
94 // RenderViewObserver implementation. | 93 // RenderViewObserver implementation. |
95 virtual bool OnMessageReceived(const IPC::Message& message); | 94 virtual bool OnMessageReceived(const IPC::Message& message); |
| 95 virtual void printPage(WebKit::WebFrame* frame); |
96 | 96 |
97 // Message handlers --------------------------------------------------------- | 97 // Message handlers --------------------------------------------------------- |
98 | 98 |
99 // Print the document. | 99 // Print the document. |
100 void OnPrintPages(); | 100 void OnPrintPages(); |
101 | 101 |
102 // Generate a print preview using |settings|. | 102 // Generate a print preview using |settings|. |
103 void OnPrintPreview(const DictionaryValue& settings); | 103 void OnPrintPreview(const DictionaryValue& settings); |
104 | 104 |
105 // Print / preview the node under the context menu. | 105 // Print / preview the node under the context menu. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 238 |
239 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; | 239 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; |
240 base::Time last_cancelled_script_print_; | 240 base::Time last_cancelled_script_print_; |
241 int user_cancelled_scripted_print_count_; | 241 int user_cancelled_scripted_print_count_; |
242 bool is_preview_; | 242 bool is_preview_; |
243 | 243 |
244 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 244 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
245 }; | 245 }; |
246 | 246 |
247 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 247 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
OLD | NEW |