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