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/browser/dom_ui/print_preview_handler.h" | 5 #include "chrome/browser/dom_ui/print_preview_handler.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/dom_ui/web_ui_util.h" |
8 #include "chrome/browser/renderer_host/render_view_host.h" | 9 #include "chrome/browser/renderer_host/render_view_host.h" |
9 #include "printing/backend/print_backend.h" | 10 #include "printing/backend/print_backend.h" |
10 | 11 |
11 PrintPreviewHandler::PrintPreviewHandler() | 12 PrintPreviewHandler::PrintPreviewHandler() |
12 : print_backend_(printing::PrintBackend::CreateInstance(NULL)) { | 13 : print_backend_(printing::PrintBackend::CreateInstance(NULL)) { |
13 } | 14 } |
14 | 15 |
15 PrintPreviewHandler::~PrintPreviewHandler() { | 16 PrintPreviewHandler::~PrintPreviewHandler() { |
16 } | 17 } |
17 | 18 |
(...skipping 10 matching lines...) Expand all Loading... |
28 printing::PrinterList printer_list; | 29 printing::PrinterList printer_list; |
29 print_backend_->EnumeratePrinters(&printer_list); | 30 print_backend_->EnumeratePrinters(&printer_list); |
30 for (printing::PrinterList::iterator index = printer_list.begin(); | 31 for (printing::PrinterList::iterator index = printer_list.begin(); |
31 index != printer_list.end(); ++index) { | 32 index != printer_list.end(); ++index) { |
32 printers.Append(new StringValue(index->printer_name)); | 33 printers.Append(new StringValue(index->printer_name)); |
33 } | 34 } |
34 | 35 |
35 web_ui_->CallJavascriptFunction(L"setPrinters", printers); | 36 web_ui_->CallJavascriptFunction(L"setPrinters", printers); |
36 } | 37 } |
37 | 38 |
38 void PrintPreviewHandler::HandlePrint(const ListValue*) { | 39 void PrintPreviewHandler::HandlePrint(const ListValue* args) { |
39 web_ui_->GetRenderViewHost()->PrintForPrintPreview(); | 40 std::string json_str( |
| 41 web_ui_util::GetJsonResponseFromFirstArgumentInList(args)); |
| 42 if (json_str.empty()) { |
| 43 NOTREACHED() << "Empty print job settings"; |
| 44 return; |
| 45 } |
| 46 web_ui_->GetRenderViewHost()->PrintForPrintPreview(json_str); |
40 } | 47 } |
OLD | NEW |