• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that can
3 // be found in the LICENSE file.
4 
5 #include "libcef/common/resource_bundle_impl.h"
6 
7 #include "base/memory/ref_counted_memory.h"
8 #include "ui/base/resource/resource_bundle.h"
9 
CefResourceBundleImpl()10 CefResourceBundleImpl::CefResourceBundleImpl() {}
11 
GetLocalizedString(int string_id)12 CefString CefResourceBundleImpl::GetLocalizedString(int string_id) {
13   if (!ui::ResourceBundle::HasSharedInstance())
14     return CefString();
15 
16   return ui::ResourceBundle::GetSharedInstance().GetLocalizedString(string_id);
17 }
18 
GetDataResource(int resource_id)19 CefRefPtr<CefBinaryValue> CefResourceBundleImpl::GetDataResource(
20     int resource_id) {
21   return GetDataResourceForScale(resource_id, SCALE_FACTOR_NONE);
22 }
23 
GetDataResourceForScale(int resource_id,ScaleFactor scale_factor)24 CefRefPtr<CefBinaryValue> CefResourceBundleImpl::GetDataResourceForScale(
25     int resource_id,
26     ScaleFactor scale_factor) {
27   if (!ui::ResourceBundle::HasSharedInstance())
28     return nullptr;
29 
30   base::RefCountedMemory* result =
31       ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
32           resource_id, static_cast<ui::ResourceScaleFactor>(scale_factor));
33   if (!result)
34     return nullptr;
35 
36   return CefBinaryValue::Create(result->data(), result->size());
37 }
38 
39 // static
GetGlobal()40 CefRefPtr<CefResourceBundle> CefResourceBundle::GetGlobal() {
41   return new CefResourceBundleImpl();
42 }
43