OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_MOCK_PRINTER_H_ | 5 #ifndef CHROME_RENDERER_MOCK_PRINTER_H_ |
6 #define CHROME_RENDERER_MOCK_PRINTER_H_ | 6 #define CHROME_RENDERER_MOCK_PRINTER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
14 | 14 #include "printing/image.h" |
15 #if defined(OS_WIN) | |
16 #include "chrome/renderer/mock_printer_driver_win.h" | |
17 #endif | |
18 | 15 |
19 struct ViewMsg_Print_Params; | 16 struct ViewMsg_Print_Params; |
20 struct ViewMsg_PrintPages_Params; | 17 struct ViewMsg_PrintPages_Params; |
21 struct ViewHostMsg_DidPrintPage_Params; | 18 struct ViewHostMsg_DidPrintPage_Params; |
22 | 19 |
23 // A class which represents an output page used in the MockPrinter class. | 20 // A class which represents an output page used in the MockPrinter class. |
24 // The MockPrinter class stores output pages in a vector, so, this class | 21 // The MockPrinter class stores output pages in a vector, so, this class |
25 // inherits the base::RefCounted<> class so that the MockPrinter class can use | 22 // inherits the base::RefCounted<> class so that the MockPrinter class can use |
26 // a smart pointer of this object (i.e. scoped_refptr<>). | 23 // a smart pointer of this object (i.e. scoped_refptr<>). |
27 class MockPrinterPage : public base::RefCounted<MockPrinterPage> { | 24 class MockPrinterPage : public base::RefCounted<MockPrinterPage> { |
28 public: | 25 public: |
29 MockPrinterPage() | 26 MockPrinterPage(const void* source_data, |
30 : width_(0), | |
31 height_(0), | |
32 source_size_(0), | |
33 bitmap_size_(0) { | |
34 } | |
35 | |
36 MockPrinterPage(int width, | |
37 int height, | |
38 const void* source_data, | |
39 size_t source_size, | 27 size_t source_size, |
40 const void* bitmap_data, | 28 const printing::Image& image) |
41 size_t bitmap_size) | 29 : source_size_(source_size), |
42 : width_(width), | 30 image_(image) { |
43 height_(height), | 31 // Create copies of the source data |
44 source_size_(source_size), | |
45 bitmap_size_(bitmap_size) { | |
46 // Create copies of the source data and the bitmap data. | |
47 source_data_.reset(new uint8[source_size]); | 32 source_data_.reset(new uint8[source_size]); |
48 if (source_data_.get()) | 33 if (source_data_.get()) |
49 memcpy(source_data_.get(), source_data, source_size); | 34 memcpy(source_data_.get(), source_data, source_size); |
50 bitmap_data_.reset(new uint8[bitmap_size]); | |
51 if (bitmap_data_.get()) | |
52 memcpy(bitmap_data_.get(), bitmap_data, bitmap_size); | |
53 } | 35 } |
54 | 36 |
55 ~MockPrinterPage() { | 37 ~MockPrinterPage() { |
56 } | 38 } |
57 | 39 |
58 int width() { return width_; } | 40 int width() const { return image_.size().width(); } |
59 int height() { return height_; } | 41 int height() const { return image_.size().height(); } |
60 const uint8* source_data() { return source_data_.get(); } | 42 const uint8* source_data() const { return source_data_.get(); } |
61 const size_t source_size() { return source_size_; } | 43 const size_t source_size() const { return source_size_; } |
62 const uint8* bitmap_data() { return bitmap_data_.get(); } | 44 const printing::Image& image() const { return image_; } |
63 const size_t bitmap_size() { return bitmap_size_; } | |
64 | 45 |
65 private: | 46 private: |
66 int width_; | |
67 int height_; | |
68 size_t source_size_; | 47 size_t source_size_; |
69 scoped_array<uint8> source_data_; | 48 scoped_array<uint8> source_data_; |
70 size_t bitmap_size_; | 49 printing::Image image_; |
71 scoped_array<uint8> bitmap_data_; | |
72 | 50 |
73 DISALLOW_COPY_AND_ASSIGN(MockPrinterPage); | 51 DISALLOW_COPY_AND_ASSIGN(MockPrinterPage); |
74 }; | 52 }; |
75 | 53 |
76 // A class which implements a pseudo-printer object used by the RenderViewTest | 54 // A class which implements a pseudo-printer object used by the RenderViewTest |
77 // class. | 55 // class. |
78 // This class consists of three parts: | 56 // This class consists of three parts: |
79 // 1. An IPC-message hanlder sent from the RenderView class; | 57 // 1. An IPC-message hanlder sent from the RenderView class; |
80 // 2. A renderer that creates a printing job into bitmaps, and; | 58 // 2. A renderer that creates a printing job into bitmaps, and; |
81 // 3. A vector which saves the output pages of a printing job. | 59 // 3. A vector which saves the output pages of a printing job. |
(...skipping 19 matching lines...) Expand all Loading... |
101 void ScriptedPrint(int cookie, | 79 void ScriptedPrint(int cookie, |
102 int expected_pages_count, | 80 int expected_pages_count, |
103 bool has_selection, | 81 bool has_selection, |
104 ViewMsg_PrintPages_Params* settings); | 82 ViewMsg_PrintPages_Params* settings); |
105 void SetPrintedPagesCount(int cookie, int number_pages); | 83 void SetPrintedPagesCount(int cookie, int number_pages); |
106 void PrintPage(const ViewHostMsg_DidPrintPage_Params& params); | 84 void PrintPage(const ViewHostMsg_DidPrintPage_Params& params); |
107 | 85 |
108 // Functions that retrieve the output pages. | 86 // Functions that retrieve the output pages. |
109 Status GetPrinterStatus() const { return printer_status_; } | 87 Status GetPrinterStatus() const { return printer_status_; } |
110 int GetPrintedPages() const; | 88 int GetPrintedPages() const; |
| 89 |
| 90 // Get a pointer to the printed page, returns NULL if pageno has not been |
| 91 // printed. The pointer is for read only view and should not be deleted. |
| 92 const MockPrinterPage* GetPrintedPage(size_t pageno) const; |
| 93 |
111 int GetWidth(size_t page) const; | 94 int GetWidth(size_t page) const; |
112 int GetHeight(size_t page) const; | 95 int GetHeight(size_t page) const; |
113 bool GetSourceChecksum(size_t page, std::string* checksum) const; | |
114 bool GetBitmapChecksum(size_t page, std::string* checksum) const; | 96 bool GetBitmapChecksum(size_t page, std::string* checksum) const; |
115 bool GetSource(size_t page, const void** data, size_t* size) const; | 97 bool GetSource(size_t page, const void** data, size_t* size) const; |
116 bool GetBitmap(size_t page, const void** data, size_t* size) const; | 98 bool GetBitmap(size_t page, const void** data, size_t* size) const; |
117 bool SaveSource(size_t page, const std::wstring& filename) const; | 99 bool SaveSource(size_t page, const std::wstring& filename) const; |
118 bool SaveBitmap(size_t page, const std::wstring& filename) const; | 100 bool SaveBitmap(size_t page, const std::wstring& filename) const; |
119 | 101 |
120 protected: | 102 protected: |
121 int CreateDocumentCookie(); | 103 int CreateDocumentCookie(); |
122 bool GetChecksum(const void* data, size_t size, std::string* checksum) const; | 104 bool GetChecksum(const void* data, size_t size, std::string* checksum) const; |
123 | 105 |
(...skipping 18 matching lines...) Expand all Loading... |
142 int current_document_cookie_; | 124 int current_document_cookie_; |
143 | 125 |
144 // The current status of this printer. | 126 // The current status of this printer. |
145 Status printer_status_; | 127 Status printer_status_; |
146 | 128 |
147 // The output of a printing job. | 129 // The output of a printing job. |
148 int number_pages_; | 130 int number_pages_; |
149 int page_number_; | 131 int page_number_; |
150 std::vector<scoped_refptr<MockPrinterPage> > pages_; | 132 std::vector<scoped_refptr<MockPrinterPage> > pages_; |
151 | 133 |
152 #if defined(OS_WIN) | |
153 MockPrinterDriverWin driver_; | |
154 #endif | |
155 | |
156 DISALLOW_COPY_AND_ASSIGN(MockPrinter); | 134 DISALLOW_COPY_AND_ASSIGN(MockPrinter); |
157 }; | 135 }; |
158 | 136 |
159 #endif // CHROME_RENDERER_MOCK_PRINTER_H_ | 137 #endif // CHROME_RENDERER_MOCK_PRINTER_H_ |
OLD | NEW |