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 "ui/base/resource/resource_data_dll_win.h" 6 7 #include "base/logging.h" 8 #include "base/memory/ref_counted_memory.h" 9 #include "base/win/resource_util.h" 10 11 namespace ui { 12 13 ResourceDataDLL::ResourceDataDLL(HINSTANCE module) : module_(module) { 14 DCHECK(module_); 15 } 16 17 ResourceDataDLL::~ResourceDataDLL() { 18 } 19 20 bool ResourceDataDLL::HasResource(uint16 resource_id) const { 21 void* data_ptr; 22 size_t data_size; 23 return base::win::GetDataResourceFromModule(module_, 24 resource_id, 25 &data_ptr, 26 &data_size); 27 } 28 29 bool ResourceDataDLL::GetStringPiece(uint16 resource_id, 30 base::StringPiece* data) const { 31 DCHECK(data); 32 void* data_ptr; 33 size_t data_size; 34 if (base::win::GetDataResourceFromModule(module_, 35 resource_id, 36 &data_ptr, 37 &data_size)) { 38 data->set(static_cast<const char*>(data_ptr), data_size); 39 return true; 40 } 41 return false; 42 } 43 44 base::RefCountedStaticMemory* ResourceDataDLL::GetStaticMemory( 45 uint16 resource_id) const { 46 void* data_ptr; 47 size_t data_size; 48 if (base::win::GetDataResourceFromModule(module_, resource_id, &data_ptr, 49 &data_size)) { 50 return new base::RefCountedStaticMemory( 51 reinterpret_cast<const unsigned char*>(data_ptr), data_size); 52 } 53 return NULL; 54 } 55 56 ResourceHandle::TextEncodingType ResourceDataDLL::GetTextEncodingType() const { 57 return BINARY; 58 } 59 60 ScaleFactor ResourceDataDLL::GetScaleFactor() const { 61 return ui::SCALE_FACTOR_NONE; 62 } 63 64 } // namespace ui 65