| OLD | NEW | 
|    1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2006-2008 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 "app/resource_bundle.h" |    5 #include "app/resource_bundle.h" | 
|    6  |    6  | 
|    7 #import <Foundation/Foundation.h> |    7 #import <Foundation/Foundation.h> | 
|    8  |    8  | 
|    9 #include "app/gfx/font.h" |    9 #include "app/gfx/font.h" | 
|   10 #include "app/l10n_util.h" |   10 #include "app/l10n_util.h" | 
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   68 void ResourceBundle::LoadThemeResources() { |   68 void ResourceBundle::LoadThemeResources() { | 
|   69   DCHECK(theme_data_ == NULL) << "theme data already loaded!"; |   69   DCHECK(theme_data_ == NULL) << "theme data already loaded!"; | 
|   70   theme_data_ = LoadResourceDataPack(@"theme"); |   70   theme_data_ = LoadResourceDataPack(@"theme"); | 
|   71   DCHECK(theme_data_) << "failed to load theme.pak"; |   71   DCHECK(theme_data_) << "failed to load theme.pak"; | 
|   72 } |   72 } | 
|   73  |   73  | 
|   74 /* static */ |   74 /* static */ | 
|   75 bool ResourceBundle::LoadResourceBytes(DataHandle module, int resource_id, |   75 bool ResourceBundle::LoadResourceBytes(DataHandle module, int resource_id, | 
|   76                                        std::vector<unsigned char>* bytes) { |   76                                        std::vector<unsigned char>* bytes) { | 
|   77   DCHECK(module); |   77   DCHECK(module); | 
|   78   StringPiece data; |   78   base::StringPiece data; | 
|   79   if (!module->Get(resource_id, &data)) |   79   if (!module->Get(resource_id, &data)) | 
|   80     return false; |   80     return false; | 
|   81  |   81  | 
|   82   bytes->resize(data.length()); |   82   bytes->resize(data.length()); | 
|   83   memcpy(&(bytes->front()), data.data(), data.length()); |   83   memcpy(&(bytes->front()), data.data(), data.length()); | 
|   84  |   84  | 
|   85   return true; |   85   return true; | 
|   86 } |   86 } | 
|   87  |   87  | 
|   88 StringPiece ResourceBundle::GetRawDataResource(int resource_id) { |   88 base::StringPiece ResourceBundle::GetRawDataResource(int resource_id) { | 
|   89   DCHECK(resources_data_); |   89   DCHECK(resources_data_); | 
|   90   StringPiece data; |   90   base::StringPiece data; | 
|   91   if (!resources_data_->Get(resource_id, &data)) |   91   if (!resources_data_->Get(resource_id, &data)) | 
|   92     return StringPiece(); |   92     return base::StringPiece(); | 
|   93   return data; |   93   return data; | 
|   94 } |   94 } | 
|   95  |   95  | 
|   96 string16 ResourceBundle::GetLocalizedString(int message_id) { |   96 string16 ResourceBundle::GetLocalizedString(int message_id) { | 
|   97   // If for some reason we were unable to load a resource dll, return an empty |   97   // If for some reason we were unable to load a resource dll, return an empty | 
|   98   // string (better than crashing). |   98   // string (better than crashing). | 
|   99   if (!locale_resources_data_) { |   99   if (!locale_resources_data_) { | 
|  100     LOG(WARNING) << "locale resources are not loaded"; |  100     LOG(WARNING) << "locale resources are not loaded"; | 
|  101     return string16(); |  101     return string16(); | 
|  102   } |  102   } | 
|  103  |  103  | 
|  104   StringPiece data; |  104   base::StringPiece data; | 
|  105   if (!locale_resources_data_->Get(message_id, &data)) { |  105   if (!locale_resources_data_->Get(message_id, &data)) { | 
|  106     // Fall back on the main data pack (shouldn't be any strings here except in |  106     // Fall back on the main data pack (shouldn't be any strings here except in | 
|  107     // unittests). |  107     // unittests). | 
|  108     data = GetRawDataResource(message_id); |  108     data = GetRawDataResource(message_id); | 
|  109     if (data.empty()) { |  109     if (data.empty()) { | 
|  110       NOTREACHED() << "unable to find resource: " << message_id; |  110       NOTREACHED() << "unable to find resource: " << message_id; | 
|  111       return string16(); |  111       return string16(); | 
|  112     } |  112     } | 
|  113   } |  113   } | 
|  114  |  114  | 
|  115   // Data pack encodes strings as UTF16. |  115   // Data pack encodes strings as UTF16. | 
|  116   string16 msg(reinterpret_cast<const char16*>(data.data()), |  116   string16 msg(reinterpret_cast<const char16*>(data.data()), | 
|  117                data.length() / 2); |  117                data.length() / 2); | 
|  118   return msg; |  118   return msg; | 
|  119 } |  119 } | 
|  120  |  120  | 
|  121 NSImage* ResourceBundle::GetNSImageNamed(int resource_id) { |  121 NSImage* ResourceBundle::GetNSImageNamed(int resource_id) { | 
|  122   // Currently this doesn't make a cache holding these as NSImages because |  122   // Currently this doesn't make a cache holding these as NSImages because | 
|  123   // GetBitmapNamed has a cache, and we don't want to double cache. |  123   // GetBitmapNamed has a cache, and we don't want to double cache. | 
|  124   SkBitmap* bitmap = GetBitmapNamed(resource_id); |  124   SkBitmap* bitmap = GetBitmapNamed(resource_id); | 
|  125   if (!bitmap) |  125   if (!bitmap) | 
|  126     return nil; |  126     return nil; | 
|  127  |  127  | 
|  128   NSImage* nsimage = gfx::SkBitmapToNSImage(*bitmap); |  128   NSImage* nsimage = gfx::SkBitmapToNSImage(*bitmap); | 
|  129   return nsimage; |  129   return nsimage; | 
|  130 } |  130 } | 
| OLD | NEW |