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 "printing/printing_context_win.h" | 5 #include "printing/printing_context_win.h" |
6 | 6 |
7 #include <winspool.h> | 7 #include <winspool.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/i18n/file_util_icu.h" | |
12 #include "base/i18n/time_formatting.h" | |
13 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
14 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
15 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
16 #include "base/time/time.h" | |
17 #include "base/values.h" | 14 #include "base/values.h" |
18 #include "printing/backend/print_backend.h" | 15 #include "printing/backend/print_backend.h" |
19 #include "printing/backend/printing_info_win.h" | 16 #include "printing/backend/printing_info_win.h" |
20 #include "printing/backend/win_helper.h" | 17 #include "printing/backend/win_helper.h" |
21 #include "printing/print_job_constants.h" | 18 #include "printing/print_job_constants.h" |
22 #include "printing/print_settings_initializer_win.h" | 19 #include "printing/print_settings_initializer_win.h" |
23 #include "printing/printed_document.h" | 20 #include "printing/printed_document.h" |
24 #include "printing/printing_utils.h" | 21 #include "printing/printing_utils.h" |
25 #include "printing/units.h" | 22 #include "printing/units.h" |
26 #include "skia/ext/platform_device.h" | 23 #include "skia/ext/platform_device.h" |
27 | 24 |
28 #if defined(USE_AURA) | 25 #if defined(USE_AURA) |
29 #include "ui/aura/remote_window_tree_host_win.h" | 26 #include "ui/aura/remote_window_tree_host_win.h" |
30 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
31 #include "ui/aura/window_event_dispatcher.h" | 28 #include "ui/aura/window_event_dispatcher.h" |
32 #endif | 29 #endif |
33 | 30 |
34 using base::Time; | |
35 | |
36 namespace { | 31 namespace { |
37 | 32 |
38 HWND GetRootWindow(gfx::NativeView view) { | 33 HWND GetRootWindow(gfx::NativeView view) { |
39 HWND window = NULL; | 34 HWND window = NULL; |
40 #if defined(USE_AURA) | 35 #if defined(USE_AURA) |
41 if (view) | 36 if (view) |
42 window = view->GetHost()->GetAcceleratedWidget(); | 37 window = view->GetHost()->GetAcceleratedWidget(); |
43 #else | 38 #else |
44 if (view && IsWindow(view)) { | 39 if (view && IsWindow(view)) { |
45 window = GetAncestor(view, GA_ROOTOWNER); | 40 window = GetAncestor(view, GA_ROOTOWNER); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 | 396 |
402 // Register the application's AbortProc function with GDI. | 397 // Register the application's AbortProc function with GDI. |
403 if (SP_ERROR == SetAbortProc(context_, &AbortProc)) | 398 if (SP_ERROR == SetAbortProc(context_, &AbortProc)) |
404 return OnError(); | 399 return OnError(); |
405 | 400 |
406 DCHECK(SimplifyDocumentTitle(document_name) == document_name); | 401 DCHECK(SimplifyDocumentTitle(document_name) == document_name); |
407 DOCINFO di = { sizeof(DOCINFO) }; | 402 DOCINFO di = { sizeof(DOCINFO) }; |
408 di.lpszDocName = document_name.c_str(); | 403 di.lpszDocName = document_name.c_str(); |
409 | 404 |
410 // Is there a debug dump directory specified? If so, force to print to a file. | 405 // Is there a debug dump directory specified? If so, force to print to a file. |
411 base::FilePath debug_dump_path = PrintedDocument::debug_dump_path(); | 406 base::string16 debug_dump_path = |
412 if (!debug_dump_path.empty()) { | 407 PrintedDocument::CreateDebugDumpPath(document_name, |
413 // Create a filename. | 408 FILE_PATH_LITERAL(".prn")).value(); |
414 std::wstring filename; | 409 if (!debug_dump_path.empty()) |
415 Time now(Time::Now()); | 410 di.lpszOutput = debug_dump_path.c_str(); |
416 filename = base::TimeFormatShortDateNumeric(now); | |
417 filename += L"_"; | |
418 filename += base::TimeFormatTimeOfDay(now); | |
419 filename += L"_"; | |
420 filename += document_name; | |
421 filename += L"_"; | |
422 filename += L"buffer.prn"; | |
423 file_util::ReplaceIllegalCharactersInPath(&filename, '_'); | |
424 debug_dump_path = debug_dump_path.Append(filename); | |
425 di.lpszOutput = debug_dump_path.value().c_str(); | |
426 } | |
427 | 411 |
428 // No message loop running in unit tests. | 412 // No message loop running in unit tests. |
429 DCHECK(!base::MessageLoop::current() || | 413 DCHECK(!base::MessageLoop::current() || |
430 !base::MessageLoop::current()->NestableTasksAllowed()); | 414 !base::MessageLoop::current()->NestableTasksAllowed()); |
431 | 415 |
432 // Begin a print job by calling the StartDoc function. | 416 // Begin a print job by calling the StartDoc function. |
433 // NOTE: StartDoc() starts a message loop. That causes a lot of problems with | 417 // NOTE: StartDoc() starts a message loop. That causes a lot of problems with |
434 // IPC. Make sure recursive task processing is disabled. | 418 // IPC. Make sure recursive task processing is disabled. |
435 if (StartDoc(context_, &di) <= 0) | 419 if (StartDoc(context_, &di) <= 0) |
436 return OnError(); | 420 return OnError(); |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 | 695 |
712 if (dialog_options.hDevMode != NULL) | 696 if (dialog_options.hDevMode != NULL) |
713 GlobalFree(dialog_options.hDevMode); | 697 GlobalFree(dialog_options.hDevMode); |
714 if (dialog_options.hDevNames != NULL) | 698 if (dialog_options.hDevNames != NULL) |
715 GlobalFree(dialog_options.hDevNames); | 699 GlobalFree(dialog_options.hDevNames); |
716 | 700 |
717 return context_ ? OK : FAILED; | 701 return context_ ? OK : FAILED; |
718 } | 702 } |
719 | 703 |
720 } // namespace printing | 704 } // namespace printing |
OLD | NEW |