| 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/print_destination_interface.h" | 5 #include "printing/print_destination_interface.h" |
| 6 | 6 |
| 7 #include "base/safe_numerics.h" |
| 7 #include "base/win/metro.h" | 8 #include "base/win/metro.h" |
| 8 #include "win8/util/win8_util.h" | 9 #include "win8/util/win8_util.h" |
| 9 | 10 |
| 10 namespace printing { | 11 namespace printing { |
| 11 | 12 |
| 12 class PrintDestinationWin : public PrintDestinationInterface { | 13 class PrintDestinationWin : public PrintDestinationInterface { |
| 13 public: | 14 public: |
| 14 PrintDestinationWin() | 15 PrintDestinationWin() |
| 15 : metro_set_print_page_count_(NULL), | 16 : metro_set_print_page_count_(NULL), |
| 16 metro_set_print_page_content_(NULL) { | 17 metro_set_print_page_content_(NULL) { |
| 17 HMODULE metro_module = base::win::GetMetroModule(); | 18 HMODULE metro_module = base::win::GetMetroModule(); |
| 18 if (metro_module != NULL) { | 19 if (metro_module != NULL) { |
| 19 metro_set_print_page_count_ = | 20 metro_set_print_page_count_ = |
| 20 reinterpret_cast<MetroSetPrintPageCount>( | 21 reinterpret_cast<MetroSetPrintPageCount>( |
| 21 ::GetProcAddress(metro_module, "MetroSetPrintPageCount")); | 22 ::GetProcAddress(metro_module, "MetroSetPrintPageCount")); |
| 22 metro_set_print_page_content_ = | 23 metro_set_print_page_content_ = |
| 23 reinterpret_cast<MetroSetPrintPageContent>( | 24 reinterpret_cast<MetroSetPrintPageContent>( |
| 24 ::GetProcAddress(metro_module, "MetroSetPrintPageContent")); | 25 ::GetProcAddress(metro_module, "MetroSetPrintPageContent")); |
| 25 } | 26 } |
| 26 } | 27 } |
| 27 virtual void SetPageCount(int page_count) { | 28 virtual void SetPageCount(int page_count) { |
| 28 if (metro_set_print_page_count_) | 29 if (metro_set_print_page_count_) |
| 29 metro_set_print_page_count_(page_count); | 30 metro_set_print_page_count_(page_count); |
| 30 } | 31 } |
| 31 | 32 |
| 32 virtual void SetPageContent(int page_number, | 33 virtual void SetPageContent(int page_number, |
| 33 void* content, | 34 void* content, |
| 34 size_t content_size) { | 35 size_t content_size) { |
| 35 if (metro_set_print_page_content_) | 36 if (metro_set_print_page_content_) |
| 36 metro_set_print_page_content_(page_number - 1, content, content_size); | 37 metro_set_print_page_content_(page_number - 1, content, |
| 38 base::checked_numeric_cast<UINT32>(content_size)); |
| 37 } | 39 } |
| 38 private: | 40 private: |
| 39 typedef void (*MetroSetPrintPageCount)(INT); | 41 typedef void (*MetroSetPrintPageCount)(INT); |
| 40 typedef void (*MetroSetPrintPageContent)(INT, VOID*, UINT32); | 42 typedef void (*MetroSetPrintPageContent)(INT, VOID*, UINT32); |
| 41 MetroSetPrintPageCount metro_set_print_page_count_; | 43 MetroSetPrintPageCount metro_set_print_page_count_; |
| 42 MetroSetPrintPageContent metro_set_print_page_content_; | 44 MetroSetPrintPageContent metro_set_print_page_content_; |
| 43 }; | 45 }; |
| 44 | 46 |
| 45 PrintDestinationInterface* CreatePrintDestination() { | 47 PrintDestinationInterface* CreatePrintDestination() { |
| 46 // We currently only support the Metro print destination. | 48 // We currently only support the Metro print destination. |
| 47 if (win8::IsSingleWindowMetroMode()) | 49 if (win8::IsSingleWindowMetroMode()) |
| 48 return new PrintDestinationWin; | 50 return new PrintDestinationWin; |
| 49 else | 51 else |
| 50 return NULL; | 52 return NULL; |
| 51 } | 53 } |
| 52 | 54 |
| 53 } // namespace printing | 55 } // namespace printing |
| OLD | NEW |