| 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 #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 <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" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 (print_preview_pages_remaining_ == print_preview_cancel_page_number_); | 138 (print_preview_pages_remaining_ == print_preview_cancel_page_number_); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void ChromeMockRenderThread::OnUpdatePrintSettings( | 141 void ChromeMockRenderThread::OnUpdatePrintSettings( |
| 142 int document_cookie, | 142 int document_cookie, |
| 143 const base::DictionaryValue& job_settings, | 143 const base::DictionaryValue& job_settings, |
| 144 PrintMsg_PrintPages_Params* params) { | 144 PrintMsg_PrintPages_Params* params) { |
| 145 // Check and make sure the required settings are all there. | 145 // Check and make sure the required settings are all there. |
| 146 // We don't actually care about the values. | 146 // We don't actually care about the values. |
| 147 std::string dummy_string; | 147 std::string dummy_string; |
| 148 int margins_type = 0; |
| 148 if (!job_settings.GetBoolean(printing::kSettingLandscape, NULL) || | 149 if (!job_settings.GetBoolean(printing::kSettingLandscape, NULL) || |
| 149 !job_settings.GetBoolean(printing::kSettingCollate, NULL) || | 150 !job_settings.GetBoolean(printing::kSettingCollate, NULL) || |
| 150 !job_settings.GetInteger(printing::kSettingColor, NULL) || | 151 !job_settings.GetInteger(printing::kSettingColor, NULL) || |
| 151 !job_settings.GetBoolean(printing::kSettingPrintToPDF, NULL) || | 152 !job_settings.GetBoolean(printing::kSettingPrintToPDF, NULL) || |
| 152 !job_settings.GetBoolean(printing::kIsFirstRequest, NULL) || | 153 !job_settings.GetBoolean(printing::kIsFirstRequest, NULL) || |
| 153 !job_settings.GetString(printing::kSettingDeviceName, &dummy_string) || | 154 !job_settings.GetString(printing::kSettingDeviceName, &dummy_string) || |
| 154 !job_settings.GetInteger(printing::kSettingDuplexMode, NULL) || | 155 !job_settings.GetInteger(printing::kSettingDuplexMode, NULL) || |
| 155 !job_settings.GetInteger(printing::kSettingCopies, NULL) || | 156 !job_settings.GetInteger(printing::kSettingCopies, NULL) || |
| 156 !job_settings.GetString(printing::kPreviewUIAddr, &dummy_string) || | 157 !job_settings.GetString(printing::kPreviewUIAddr, &dummy_string) || |
| 157 !job_settings.GetInteger(printing::kPreviewRequestID, NULL)) { | 158 !job_settings.GetInteger(printing::kPreviewRequestID, NULL) || |
| 159 !job_settings.GetInteger(printing::kSettingMarginsType, &margins_type)) { |
| 158 return; | 160 return; |
| 159 } | 161 } |
| 160 | 162 |
| 161 // Just return the default settings. | 163 // Just return the default settings. |
| 162 if (printer_.get()) { | 164 if (printer_.get()) { |
| 163 ListValue* page_range_array; | 165 ListValue* page_range_array; |
| 164 printing::PageRanges new_ranges; | 166 printing::PageRanges new_ranges; |
| 165 if (job_settings.GetList(printing::kSettingPageRange, &page_range_array)) { | 167 if (job_settings.GetList(printing::kSettingPageRange, &page_range_array)) { |
| 166 for (size_t index = 0; index < page_range_array->GetSize(); ++index) { | 168 for (size_t index = 0; index < page_range_array->GetSize(); ++index) { |
| 167 base::DictionaryValue* dict; | 169 base::DictionaryValue* dict; |
| 168 if (!page_range_array->GetDictionary(index, &dict)) | 170 if (!page_range_array->GetDictionary(index, &dict)) |
| 169 continue; | 171 continue; |
| 170 printing::PageRange range; | 172 printing::PageRange range; |
| 171 if (!dict->GetInteger(printing::kSettingPageRangeFrom, &range.from) || | 173 if (!dict->GetInteger(printing::kSettingPageRangeFrom, &range.from) || |
| 172 !dict->GetInteger(printing::kSettingPageRangeTo, &range.to)) { | 174 !dict->GetInteger(printing::kSettingPageRangeTo, &range.to)) { |
| 173 continue; | 175 continue; |
| 174 } | 176 } |
| 175 // Page numbers are 1-based in the dictionary. | 177 // Page numbers are 1-based in the dictionary. |
| 176 // Page numbers are 0-based for the printing context. | 178 // Page numbers are 0-based for the printing context. |
| 177 range.from--; | 179 range.from--; |
| 178 range.to--; | 180 range.to--; |
| 179 new_ranges.push_back(range); | 181 new_ranges.push_back(range); |
| 180 } | 182 } |
| 181 } | 183 } |
| 182 std::vector<int> pages(printing::PageRange::GetPages(new_ranges)); | 184 std::vector<int> pages(printing::PageRange::GetPages(new_ranges)); |
| 183 printer_->UpdateSettings(document_cookie, params, pages); | 185 printer_->UpdateSettings(document_cookie, params, pages, margins_type); |
| 184 } | 186 } |
| 185 } | 187 } |
| 186 | 188 |
| 187 void ChromeMockRenderThread::set_print_dialog_user_response(bool response) { | 189 void ChromeMockRenderThread::set_print_dialog_user_response(bool response) { |
| 188 print_dialog_user_response_ = response; | 190 print_dialog_user_response_ = response; |
| 189 } | 191 } |
| 190 | 192 |
| 191 void ChromeMockRenderThread::set_print_preview_cancel_page_number(int page) { | 193 void ChromeMockRenderThread::set_print_preview_cancel_page_number(int page) { |
| 192 print_preview_cancel_page_number_ = page; | 194 print_preview_cancel_page_number_ = page; |
| 193 } | 195 } |
| 194 | 196 |
| 195 int ChromeMockRenderThread::print_preview_pages_remaining() { | 197 int ChromeMockRenderThread::print_preview_pages_remaining() { |
| 196 return print_preview_pages_remaining_; | 198 return print_preview_pages_remaining_; |
| 197 } | 199 } |
| OLD | NEW |