| OLD | NEW |
| 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/browser/ui/webui/print_preview/print_preview_ui.h" | 5 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/printing/background_printing_manager.h" | 15 #include "chrome/browser/printing/background_printing_manager.h" |
| 16 #include "chrome/browser/printing/print_preview_data_service.h" | 16 #include "chrome/browser/printing/print_preview_data_service.h" |
| 17 #include "chrome/browser/printing/print_preview_tab_controller.h" | 17 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 20 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 20 #include "chrome/browser/ui/webui/html_dialog_ui.h" |
| 21 #include "chrome/browser/ui/webui/print_preview/print_preview_data_source.h" | 21 #include "chrome/browser/ui/webui/print_preview/print_preview_data_source.h" |
| 22 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" | 22 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" |
| 23 #include "chrome/common/print_messages.h" | 23 #include "chrome/common/print_messages.h" |
| 24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 25 #include "printing/page_size_margins.h" | 25 #include "printing/page_size_margins.h" |
| 26 #include "printing/print_job_constants.h" | 26 #include "printing/print_job_constants.h" |
| 27 #include "ui/gfx/rect.h" |
| 27 | 28 |
| 28 using content::WebContents; | 29 using content::WebContents; |
| 29 using printing::PageSizeMargins; | 30 using printing::PageSizeMargins; |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 // Thread-safe wrapper around a std::map to keep track of mappings from | 34 // Thread-safe wrapper around a std::map to keep track of mappings from |
| 34 // PrintPreviewUI addresses to most recent print preview request ids. | 35 // PrintPreviewUI addresses to most recent print preview request ids. |
| 35 class PrintPreviewRequestIdMapWithLock { | 36 class PrintPreviewRequestIdMapWithLock { |
| 36 public: | 37 public: |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 const PrintHostMsg_DidGetPreviewPageCount_Params& params) { | 200 const PrintHostMsg_DidGetPreviewPageCount_Params& params) { |
| 200 DCHECK_GT(params.page_count, 0); | 201 DCHECK_GT(params.page_count, 0); |
| 201 base::FundamentalValue count(params.page_count); | 202 base::FundamentalValue count(params.page_count); |
| 202 base::FundamentalValue request_id(params.preview_request_id); | 203 base::FundamentalValue request_id(params.preview_request_id); |
| 203 web_ui()->CallJavascriptFunction("onDidGetPreviewPageCount", | 204 web_ui()->CallJavascriptFunction("onDidGetPreviewPageCount", |
| 204 count, | 205 count, |
| 205 request_id); | 206 request_id); |
| 206 } | 207 } |
| 207 | 208 |
| 208 void PrintPreviewUI::OnDidGetDefaultPageLayout( | 209 void PrintPreviewUI::OnDidGetDefaultPageLayout( |
| 209 const PageSizeMargins& page_layout, bool has_custom_page_size_style) { | 210 const PageSizeMargins& page_layout, const gfx::Rect& printable_area, |
| 211 bool has_custom_page_size_style) { |
| 210 if (page_layout.margin_top < 0 || page_layout.margin_left < 0 || | 212 if (page_layout.margin_top < 0 || page_layout.margin_left < 0 || |
| 211 page_layout.margin_bottom < 0 || page_layout.margin_right < 0 || | 213 page_layout.margin_bottom < 0 || page_layout.margin_right < 0 || |
| 212 page_layout.content_width < 0 || page_layout.content_height < 0) { | 214 page_layout.content_width < 0 || page_layout.content_height < 0 || |
| 215 printable_area.width() <= 0 || printable_area.height() <= 0) { |
| 213 NOTREACHED(); | 216 NOTREACHED(); |
| 214 return; | 217 return; |
| 215 } | 218 } |
| 216 | 219 |
| 217 base::DictionaryValue layout; | 220 base::DictionaryValue layout; |
| 218 layout.SetDouble(printing::kSettingMarginTop, page_layout.margin_top); | 221 layout.SetDouble(printing::kSettingMarginTop, page_layout.margin_top); |
| 219 layout.SetDouble(printing::kSettingMarginLeft, page_layout.margin_left); | 222 layout.SetDouble(printing::kSettingMarginLeft, page_layout.margin_left); |
| 220 layout.SetDouble(printing::kSettingMarginBottom, page_layout.margin_bottom); | 223 layout.SetDouble(printing::kSettingMarginBottom, page_layout.margin_bottom); |
| 221 layout.SetDouble(printing::kSettingMarginRight, page_layout.margin_right); | 224 layout.SetDouble(printing::kSettingMarginRight, page_layout.margin_right); |
| 222 layout.SetDouble(printing::kSettingContentWidth, page_layout.content_width); | 225 layout.SetDouble(printing::kSettingContentWidth, page_layout.content_width); |
| 223 layout.SetDouble(printing::kSettingContentHeight, page_layout.content_height); | 226 layout.SetDouble(printing::kSettingContentHeight, page_layout.content_height); |
| 227 layout.SetInteger(printing::kSettingPrintableAreaX, printable_area.x()); |
| 228 layout.SetInteger(printing::kSettingPrintableAreaY, printable_area.y()); |
| 229 layout.SetInteger(printing::kSettingPrintableAreaWidth, |
| 230 printable_area.width()); |
| 231 layout.SetInteger(printing::kSettingPrintableAreaHeight, |
| 232 printable_area.height()); |
| 224 | 233 |
| 225 base::FundamentalValue has_page_size_style(has_custom_page_size_style); | 234 base::FundamentalValue has_page_size_style(has_custom_page_size_style); |
| 226 web_ui()->CallJavascriptFunction("onDidGetDefaultPageLayout", layout, | 235 web_ui()->CallJavascriptFunction("onDidGetDefaultPageLayout", layout, |
| 227 has_page_size_style); | 236 has_page_size_style); |
| 228 } | 237 } |
| 229 | 238 |
| 230 void PrintPreviewUI::OnDidPreviewPage(int page_number, | 239 void PrintPreviewUI::OnDidPreviewPage(int page_number, |
| 231 int preview_request_id) { | 240 int preview_request_id) { |
| 232 DCHECK_GE(page_number, 0); | 241 DCHECK_GE(page_number, 0); |
| 233 base::FundamentalValue number(page_number); | 242 base::FundamentalValue number(page_number); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); | 320 ConstrainedHtmlUIDelegate* delegate = GetConstrainedDelegate(); |
| 312 if (!delegate) | 321 if (!delegate) |
| 313 return; | 322 return; |
| 314 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed(""); | 323 delegate->GetHtmlDialogUIDelegate()->OnDialogClosed(""); |
| 315 delegate->OnDialogCloseFromWebUI(); | 324 delegate->OnDialogCloseFromWebUI(); |
| 316 } | 325 } |
| 317 | 326 |
| 318 void PrintPreviewUI::OnReloadPrintersList() { | 327 void PrintPreviewUI::OnReloadPrintersList() { |
| 319 web_ui()->CallJavascriptFunction("reloadPrintersList"); | 328 web_ui()->CallJavascriptFunction("reloadPrintersList"); |
| 320 } | 329 } |
| OLD | NEW |