Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chromecast / common / cast_resource_delegate.cc
1 // Copyright 2014 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 "chromecast/common/cast_resource_delegate.h"
6
7 #include "base/files/file_path.h"
8 #include "base/path_service.h"
9 #include "ui/gfx/image/image.h"
10
11 namespace chromecast {
12
13 namespace {
14
15 CastResourceDelegate* g_instance = NULL;
16
17 }  // namespace
18
19 // static
20 CastResourceDelegate* CastResourceDelegate::GetInstance() {
21   DCHECK(g_instance);
22   return g_instance;
23 }
24
25 CastResourceDelegate::CastResourceDelegate() {
26   DCHECK(!g_instance) << "Cannot initialize resource bundle delegate twice.";
27   g_instance = this;
28 }
29
30 CastResourceDelegate::~CastResourceDelegate() {
31   DCHECK_EQ(g_instance, this);
32   g_instance = NULL;
33 }
34
35 base::FilePath CastResourceDelegate::GetPathForResourcePack(
36     const base::FilePath& pack_path,
37     ui::ScaleFactor scale_factor) {
38   return pack_path;
39 };
40
41 base::FilePath CastResourceDelegate::GetPathForLocalePack(
42     const base::FilePath& pack_path,
43     const std::string& locale) {
44   base::FilePath product_dir;
45   if (!PathService::Get(base::DIR_MODULE, &product_dir)) {
46     NOTREACHED();
47   }
48   return product_dir.
49       Append(FILE_PATH_LITERAL("chromecast_locales")).
50       Append(FILE_PATH_LITERAL(locale)).
51       AddExtension(FILE_PATH_LITERAL("pak"));
52 };
53
54 gfx::Image CastResourceDelegate::GetImageNamed(int resource_id) {
55   return gfx::Image();
56 };
57
58 gfx::Image CastResourceDelegate::GetNativeImageNamed(
59     int resource_id,
60     ui::ResourceBundle::ImageRTL rtl) {
61   return gfx::Image();
62 };
63
64 base::RefCountedStaticMemory* CastResourceDelegate::LoadDataResourceBytes(
65     int resource_id,
66     ui::ScaleFactor scale_factor) {
67   return NULL;
68 };
69
70 bool CastResourceDelegate::GetRawDataResource(int resource_id,
71                                               ui::ScaleFactor scale_factor,
72                                               base::StringPiece* value) {
73   return false;
74 };
75
76 bool CastResourceDelegate::GetLocalizedString(int message_id,
77                                               base::string16* value) {
78   ExtraLocaledStringMap::const_iterator it =
79       extra_localized_strings_.find(message_id);
80   if (it != extra_localized_strings_.end()) {
81     *value = it->second;
82     return true;
83   }
84   return false;
85 };
86
87 void CastResourceDelegate::AddExtraLocalizedString(
88     int resource_id,
89     const base::string16& localized) {
90   RemoveExtraLocalizedString(resource_id);
91   extra_localized_strings_.insert(std::make_pair(resource_id, localized));
92 }
93
94 void CastResourceDelegate::RemoveExtraLocalizedString(int resource_id) {
95   extra_localized_strings_.erase(resource_id);
96 }
97
98 void CastResourceDelegate::ClearAllExtraLocalizedStrings() {
99   extra_localized_strings_.clear();
100 }
101
102 scoped_ptr<gfx::Font> CastResourceDelegate::GetFont(
103     ui::ResourceBundle::FontStyle style) {
104   return scoped_ptr<gfx::Font>();
105 };
106
107 }  // namespace chromecast