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

Side by Side Diff: chrome/renderer/chrome_mock_render_thread.cc

Issue 10873097: Merge 153342 - Print preview: Use an ID instead of memory pointer string in WebUI. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1229/src/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/chrome_mock_render_thread.h ('k') | chrome/renderer/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 #include "chrome/renderer/chrome_mock_render_thread.h" 5 #include "chrome/renderer/chrome_mock_render_thread.h"
6 6
7 #include <fcntl.h> 7 #include <vector>
8 8
9 #include "base/file_util.h" 9 #include "base/values.h"
10 #include "base/process_util.h"
11 #include "chrome/common/extensions/extension_messages.h" 10 #include "chrome/common/extensions/extension_messages.h"
12 #include "chrome/common/print_messages.h" 11 #include "chrome/common/print_messages.h"
13 #include "chrome/common/render_messages.h" 12 #include "chrome/renderer/mock_printer.h"
14 #include "chrome/common/url_constants.h"
15 #include "ipc/ipc_message_utils.h"
16 #include "ipc/ipc_sync_message.h" 13 #include "ipc/ipc_sync_message.h"
17 #include "printing/print_job_constants.h" 14 #include "printing/print_job_constants.h"
18 #include "printing/page_range.h" 15 #include "printing/page_range.h"
19 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
20 17
18 #if defined(OS_CHROMEOS)
19 #include <fcntl.h>
20
21 #include "base/file_util.h"
22 #endif
23
21 ChromeMockRenderThread::ChromeMockRenderThread() 24 ChromeMockRenderThread::ChromeMockRenderThread()
22 : printer_(new MockPrinter), 25 : printer_(new MockPrinter),
23 print_dialog_user_response_(true), 26 print_dialog_user_response_(true),
24 print_preview_cancel_page_number_(-1), 27 print_preview_cancel_page_number_(-1),
25 print_preview_pages_remaining_(0) { 28 print_preview_pages_remaining_(0) {
26 } 29 }
27 30
28 ChromeMockRenderThread::~ChromeMockRenderThread() { 31 ChromeMockRenderThread::~ChromeMockRenderThread() {
29 } 32 }
30 33
(...skipping 26 matching lines...) Expand all
57 OnAllocateTempFileForPrinting) 60 OnAllocateTempFileForPrinting)
58 IPC_MESSAGE_HANDLER(PrintHostMsg_TempFileForPrintingWritten, 61 IPC_MESSAGE_HANDLER(PrintHostMsg_TempFileForPrintingWritten,
59 OnTempFileForPrintingWritten) 62 OnTempFileForPrintingWritten)
60 #endif 63 #endif
61 IPC_MESSAGE_UNHANDLED(handled = false) 64 IPC_MESSAGE_UNHANDLED(handled = false)
62 IPC_END_MESSAGE_MAP_EX() 65 IPC_END_MESSAGE_MAP_EX()
63 return handled; 66 return handled;
64 } 67 }
65 68
66 void ChromeMockRenderThread::OnMsgOpenChannelToExtension( 69 void ChromeMockRenderThread::OnMsgOpenChannelToExtension(
67 int routing_id, const std::string& source_extension_id, 70 int routing_id,
71 const std::string& source_extension_id,
68 const std::string& target_extension_id, 72 const std::string& target_extension_id,
69 const std::string& channel_name, int* port_id) { 73 const std::string& channel_name,
74 int* port_id) {
70 *port_id = 0; 75 *port_id = 0;
71 } 76 }
72 77
73 #if defined(OS_CHROMEOS) 78 #if defined(OS_CHROMEOS)
74 void ChromeMockRenderThread::OnAllocateTempFileForPrinting( 79 void ChromeMockRenderThread::OnAllocateTempFileForPrinting(
75 base::FileDescriptor* renderer_fd, 80 base::FileDescriptor* renderer_fd,
76 int* browser_fd) { 81 int* browser_fd) {
77 renderer_fd->fd = *browser_fd = -1; 82 renderer_fd->fd = *browser_fd = -1;
78 renderer_fd->auto_close = false; 83 renderer_fd->auto_close = false;
79 84
80 FilePath path; 85 FilePath path;
81 if (file_util::CreateTemporaryFile(&path)) { 86 if (file_util::CreateTemporaryFile(&path)) {
82 int fd = open(path.value().c_str(), O_WRONLY); 87 int fd = open(path.value().c_str(), O_WRONLY);
83 DCHECK_GE(fd, 0); 88 DCHECK_GE(fd, 0);
84 renderer_fd->fd = *browser_fd = fd; 89 renderer_fd->fd = *browser_fd = fd;
85 } 90 }
86 } 91 }
87 92
88 void ChromeMockRenderThread::OnTempFileForPrintingWritten(int render_view_id, 93 void ChromeMockRenderThread::OnTempFileForPrintingWritten(int render_view_id,
89 int browser_fd) { 94 int browser_fd) {
90 close(browser_fd); 95 close(browser_fd);
91 } 96 }
92 #endif // defined(OS_CHROMEOS) 97 #endif // defined(OS_CHROMEOS)
93 98
94 void ChromeMockRenderThread::OnGetDefaultPrintSettings( 99 void ChromeMockRenderThread::OnGetDefaultPrintSettings(
95 PrintMsg_Print_Params* params) { 100 PrintMsg_Print_Params* params) {
96 if (printer_.get()) 101 printer_->GetDefaultPrintSettings(params);
97 printer_->GetDefaultPrintSettings(params);
98 } 102 }
99 103
100 void ChromeMockRenderThread::OnScriptedPrint( 104 void ChromeMockRenderThread::OnScriptedPrint(
101 const PrintHostMsg_ScriptedPrint_Params& params, 105 const PrintHostMsg_ScriptedPrint_Params& params,
102 PrintMsg_PrintPages_Params* settings) { 106 PrintMsg_PrintPages_Params* settings) {
103 if (print_dialog_user_response_ && printer_.get()) { 107 if (print_dialog_user_response_) {
104 printer_->ScriptedPrint(params.cookie, 108 printer_->ScriptedPrint(params.cookie,
105 params.expected_pages_count, 109 params.expected_pages_count,
106 params.has_selection, 110 params.has_selection,
107 settings); 111 settings);
108 } 112 }
109 } 113 }
110 114
111 void ChromeMockRenderThread::OnDidGetPrintedPagesCount( 115 void ChromeMockRenderThread::OnDidGetPrintedPagesCount(
112 int cookie, int number_pages) { 116 int cookie, int number_pages) {
113 if (printer_.get()) 117 printer_->SetPrintedPagesCount(cookie, number_pages);
114 printer_->SetPrintedPagesCount(cookie, number_pages);
115 } 118 }
116 119
117 void ChromeMockRenderThread::OnDidPrintPage( 120 void ChromeMockRenderThread::OnDidPrintPage(
118 const PrintHostMsg_DidPrintPage_Params& params) { 121 const PrintHostMsg_DidPrintPage_Params& params) {
119 if (printer_.get()) 122 printer_->PrintPage(params);
120 printer_->PrintPage(params);
121 } 123 }
122 124
123 void ChromeMockRenderThread::OnDidGetPreviewPageCount( 125 void ChromeMockRenderThread::OnDidGetPreviewPageCount(
124 const PrintHostMsg_DidGetPreviewPageCount_Params& params) { 126 const PrintHostMsg_DidGetPreviewPageCount_Params& params) {
125 print_preview_pages_remaining_ = params.page_count; 127 print_preview_pages_remaining_ = params.page_count;
126 } 128 }
127 129
128 void ChromeMockRenderThread::OnDidPreviewPage( 130 void ChromeMockRenderThread::OnDidPreviewPage(
129 const PrintHostMsg_DidPreviewPage_Params& params) { 131 const PrintHostMsg_DidPreviewPage_Params& params) {
130 DCHECK(params.page_number >= printing::FIRST_PAGE_INDEX); 132 DCHECK_GE(params.page_number, printing::FIRST_PAGE_INDEX);
131 print_preview_pages_remaining_--; 133 print_preview_pages_remaining_--;
132 } 134 }
133 135
134 void ChromeMockRenderThread::OnCheckForCancel( 136 void ChromeMockRenderThread::OnCheckForCancel(int32 preview_ui_id,
135 const std::string& preview_ui_addr, 137 int preview_request_id,
136 int preview_request_id, 138 bool* cancel) {
137 bool* cancel) {
138 *cancel = 139 *cancel =
139 (print_preview_pages_remaining_ == print_preview_cancel_page_number_); 140 (print_preview_pages_remaining_ == print_preview_cancel_page_number_);
140 } 141 }
141 142
142 void ChromeMockRenderThread::OnUpdatePrintSettings( 143 void ChromeMockRenderThread::OnUpdatePrintSettings(
143 int document_cookie, 144 int document_cookie,
144 const base::DictionaryValue& job_settings, 145 const base::DictionaryValue& job_settings,
145 PrintMsg_PrintPages_Params* params) { 146 PrintMsg_PrintPages_Params* params) {
146 // Check and make sure the required settings are all there. 147 // Check and make sure the required settings are all there.
147 // We don't actually care about the values. 148 // We don't actually care about the values.
148 std::string dummy_string; 149 std::string dummy_string;
149 int margins_type = 0; 150 int margins_type = 0;
150 if (!job_settings.GetBoolean(printing::kSettingLandscape, NULL) || 151 if (!job_settings.GetBoolean(printing::kSettingLandscape, NULL) ||
151 !job_settings.GetBoolean(printing::kSettingCollate, NULL) || 152 !job_settings.GetBoolean(printing::kSettingCollate, NULL) ||
152 !job_settings.GetInteger(printing::kSettingColor, NULL) || 153 !job_settings.GetInteger(printing::kSettingColor, NULL) ||
153 !job_settings.GetBoolean(printing::kSettingPrintToPDF, NULL) || 154 !job_settings.GetBoolean(printing::kSettingPrintToPDF, NULL) ||
154 !job_settings.GetBoolean(printing::kIsFirstRequest, NULL) || 155 !job_settings.GetBoolean(printing::kIsFirstRequest, NULL) ||
155 !job_settings.GetString(printing::kSettingDeviceName, &dummy_string) || 156 !job_settings.GetString(printing::kSettingDeviceName, &dummy_string) ||
156 !job_settings.GetInteger(printing::kSettingDuplexMode, NULL) || 157 !job_settings.GetInteger(printing::kSettingDuplexMode, NULL) ||
157 !job_settings.GetInteger(printing::kSettingCopies, NULL) || 158 !job_settings.GetInteger(printing::kSettingCopies, NULL) ||
158 !job_settings.GetString(printing::kPreviewUIAddr, &dummy_string) || 159 !job_settings.GetInteger(printing::kPreviewUIID, NULL) ||
159 !job_settings.GetInteger(printing::kPreviewRequestID, NULL) || 160 !job_settings.GetInteger(printing::kPreviewRequestID, NULL) ||
160 !job_settings.GetInteger(printing::kSettingMarginsType, &margins_type)) { 161 !job_settings.GetInteger(printing::kSettingMarginsType, &margins_type)) {
161 return; 162 return;
162 } 163 }
163 164
164 // Just return the default settings. 165 // Just return the default settings.
165 if (printer_.get()) { 166 const ListValue* page_range_array;
166 const ListValue* page_range_array; 167 printing::PageRanges new_ranges;
167 printing::PageRanges new_ranges; 168 if (job_settings.GetList(printing::kSettingPageRange, &page_range_array)) {
168 if (job_settings.GetList(printing::kSettingPageRange, &page_range_array)) { 169 for (size_t index = 0; index < page_range_array->GetSize(); ++index) {
169 for (size_t index = 0; index < page_range_array->GetSize(); ++index) { 170 const base::DictionaryValue* dict;
170 const base::DictionaryValue* dict; 171 if (!page_range_array->GetDictionary(index, &dict))
171 if (!page_range_array->GetDictionary(index, &dict)) 172 continue;
172 continue; 173 printing::PageRange range;
173 printing::PageRange range; 174 if (!dict->GetInteger(printing::kSettingPageRangeFrom, &range.from) ||
174 if (!dict->GetInteger(printing::kSettingPageRangeFrom, &range.from) || 175 !dict->GetInteger(printing::kSettingPageRangeTo, &range.to)) {
175 !dict->GetInteger(printing::kSettingPageRangeTo, &range.to)) { 176 continue;
176 continue;
177 }
178 // Page numbers are 1-based in the dictionary.
179 // Page numbers are 0-based for the printing context.
180 range.from--;
181 range.to--;
182 new_ranges.push_back(range);
183 } 177 }
178 // Page numbers are 1-based in the dictionary.
179 // Page numbers are 0-based for the printing context.
180 range.from--;
181 range.to--;
182 new_ranges.push_back(range);
184 } 183 }
185 std::vector<int> pages(printing::PageRange::GetPages(new_ranges));
186 printer_->UpdateSettings(document_cookie, params, pages, margins_type);
187 } 184 }
185 std::vector<int> pages(printing::PageRange::GetPages(new_ranges));
186 printer_->UpdateSettings(document_cookie, params, pages, margins_type);
187 }
188
189 MockPrinter* ChromeMockRenderThread::printer() {
190 return printer_.get();
188 } 191 }
189 192
190 void ChromeMockRenderThread::set_print_dialog_user_response(bool response) { 193 void ChromeMockRenderThread::set_print_dialog_user_response(bool response) {
191 print_dialog_user_response_ = response; 194 print_dialog_user_response_ = response;
192 } 195 }
193 196
194 void ChromeMockRenderThread::set_print_preview_cancel_page_number(int page) { 197 void ChromeMockRenderThread::set_print_preview_cancel_page_number(int page) {
195 print_preview_cancel_page_number_ = page; 198 print_preview_cancel_page_number_ = page;
196 } 199 }
197 200
198 int ChromeMockRenderThread::print_preview_pages_remaining() { 201 int ChromeMockRenderThread::print_preview_pages_remaining() const {
199 return print_preview_pages_remaining_; 202 return print_preview_pages_remaining_;
200 } 203 }
OLDNEW
« no previous file with comments | « chrome/renderer/chrome_mock_render_thread.h ('k') | chrome/renderer/print_web_view_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698