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

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

Issue 7544018: Print preview page selection should not require a rerendering of draft pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix style Created 9 years, 4 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/mock_render_thread.h ('k') | chrome/renderer/print_web_view_helper.h » ('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) 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 #include "chrome/renderer/mock_render_thread.h" 5 #include "chrome/renderer/mock_render_thread.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
11 #include "chrome/common/extensions/extension_messages.h" 11 #include "chrome/common/extensions/extension_messages.h"
12 #include "chrome/common/print_messages.h" 12 #include "chrome/common/print_messages.h"
13 #include "chrome/common/render_messages.h" 13 #include "chrome/common/render_messages.h"
14 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
15 #include "content/common/view_messages.h" 15 #include "content/common/view_messages.h"
16 #include "ipc/ipc_message_utils.h" 16 #include "ipc/ipc_message_utils.h"
17 #include "ipc/ipc_sync_message.h" 17 #include "ipc/ipc_sync_message.h"
18 #include "printing/print_job_constants.h" 18 #include "printing/print_job_constants.h"
19 #include "printing/page_range.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 MockRenderThread::MockRenderThread() 22 MockRenderThread::MockRenderThread()
22 : routing_id_(0), 23 : routing_id_(0),
23 opener_id_(0), 24 opener_id_(0),
24 widget_(NULL), 25 widget_(NULL),
25 reply_deserializer_(NULL), 26 reply_deserializer_(NULL),
26 printer_(new MockPrinter), 27 printer_(new MockPrinter),
27 print_dialog_user_response_(true), 28 print_dialog_user_response_(true),
28 print_preview_pages_remaining_(0) { 29 print_preview_pages_remaining_(0) {
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 } 207 }
207 208
208 void MockRenderThread::OnDidPrintPage( 209 void MockRenderThread::OnDidPrintPage(
209 const PrintHostMsg_DidPrintPage_Params& params) { 210 const PrintHostMsg_DidPrintPage_Params& params) {
210 if (printer_.get()) 211 if (printer_.get())
211 printer_->PrintPage(params); 212 printer_->PrintPage(params);
212 } 213 }
213 214
214 void MockRenderThread::OnDidGetPreviewPageCount(int document_cookie, 215 void MockRenderThread::OnDidGetPreviewPageCount(int document_cookie,
215 int number_pages, 216 int number_pages,
216 bool is_modifiable) { 217 bool is_modifiable,
218 bool clear_preview_data) {
217 print_preview_pages_remaining_ = number_pages; 219 print_preview_pages_remaining_ = number_pages;
218 } 220 }
219 221
220 void MockRenderThread::OnDidPreviewPage( 222 void MockRenderThread::OnDidPreviewPage(
221 const PrintHostMsg_DidPreviewPage_Params& params) { 223 const PrintHostMsg_DidPreviewPage_Params& params) {
222 if (params.page_number < printing::FIRST_PAGE_INDEX) 224 if (params.page_number < printing::FIRST_PAGE_INDEX)
223 return; 225 return;
224 print_preview_pages_remaining_--; 226 print_preview_pages_remaining_--;
225 } 227 }
226 228
227 void MockRenderThread::OnUpdatePrintSettings( 229 void MockRenderThread::OnUpdatePrintSettings(
228 int document_cookie, 230 int document_cookie,
229 const DictionaryValue& job_settings, 231 const DictionaryValue& job_settings,
230 PrintMsg_PrintPages_Params* params) { 232 PrintMsg_PrintPages_Params* params) {
231 // Check and make sure the required settings are all there. 233 // Check and make sure the required settings are all there.
232 // We don't actually care about the values. 234 // We don't actually care about the values.
233 std::string dummy_string; 235 std::string dummy_string;
234 if (!job_settings.GetBoolean(printing::kSettingLandscape, NULL) || 236 if (!job_settings.GetBoolean(printing::kSettingLandscape, NULL) ||
235 !job_settings.GetBoolean(printing::kSettingCollate, NULL) || 237 !job_settings.GetBoolean(printing::kSettingCollate, NULL) ||
236 !job_settings.GetBoolean(printing::kSettingColor, NULL) || 238 !job_settings.GetBoolean(printing::kSettingColor, NULL) ||
237 !job_settings.GetBoolean(printing::kSettingPrintToPDF, NULL) || 239 !job_settings.GetBoolean(printing::kSettingPrintToPDF, NULL) ||
238 !job_settings.GetString(printing::kSettingDeviceName, &dummy_string) || 240 !job_settings.GetString(printing::kSettingDeviceName, &dummy_string) ||
239 !job_settings.GetInteger(printing::kSettingDuplexMode, NULL) || 241 !job_settings.GetInteger(printing::kSettingDuplexMode, NULL) ||
240 !job_settings.GetInteger(printing::kSettingCopies, NULL)) { 242 !job_settings.GetInteger(printing::kSettingCopies, NULL)) {
241 return; 243 return;
242 } 244 }
243 245
244 // Just return the default settings. 246 // Just return the default settings.
245 if (printer_.get()) 247 if (printer_.get()) {
246 printer_->UpdateSettings(document_cookie, params); 248 ListValue* page_range_array = new ListValue();
249 printing::PageRanges new_ranges;
250 if (job_settings.GetList(printing::kSettingPageRange, &page_range_array)) {
251 for (size_t index = 0; index < page_range_array->GetSize(); ++index) {
252 DictionaryValue* dict;
253 if (!page_range_array->GetDictionary(index, &dict))
254 continue;
255 printing::PageRange range;
256 if (!dict->GetInteger(printing::kSettingPageRangeFrom, &range.from) ||
257 !dict->GetInteger(printing::kSettingPageRangeTo, &range.to)) {
258 continue;
259 }
260 // Page numbers are 1-based in the dictionary.
261 // Page numbers are 0-based for the printing context.
262 range.from--;
263 range.to--;
264 new_ranges.push_back(range);
265 }
266 }
267 std::vector<int> pages(printing::PageRange::GetPages(new_ranges));
268 printer_->UpdateSettings(document_cookie, params, pages);
269 }
247 } 270 }
248 271
249 void MockRenderThread::set_print_dialog_user_response(bool response) { 272 void MockRenderThread::set_print_dialog_user_response(bool response) {
250 print_dialog_user_response_ = response; 273 print_dialog_user_response_ = response;
251 } 274 }
252 275
253 int MockRenderThread::print_preview_pages_remaining() { 276 int MockRenderThread::print_preview_pages_remaining() {
254 return print_preview_pages_remaining_; 277 return print_preview_pages_remaining_;
255 } 278 }
OLDNEW
« no previous file with comments | « chrome/renderer/mock_render_thread.h ('k') | chrome/renderer/print_web_view_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698