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.
5 #include "chromecast/common/cast_content_client.h"
7 #include "base/strings/stringprintf.h"
8 #include "base/sys_info.h"
9 #include "chromecast/common/version.h"
10 #include "content/public/common/user_agent.h"
11 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/base/resource/resource_bundle.h"
14 namespace chromecast
{
19 #if defined(OS_ANDROID)
20 std::string
BuildAndroidOsInfo() {
21 int32 os_major_version
= 0;
22 int32 os_minor_version
= 0;
23 int32 os_bugfix_version
= 0;
24 base::SysInfo::OperatingSystemVersionNumbers(&os_major_version
,
28 std::string android_version_str
;
30 &android_version_str
, "%d.%d", os_major_version
, os_minor_version
);
31 if (os_bugfix_version
!= 0)
32 base::StringAppendF(&android_version_str
, ".%d", os_bugfix_version
);
34 std::string android_info_str
;
35 // Append the build ID.
36 std::string android_build_id
= base::SysInfo::GetAndroidBuildID();
37 if (android_build_id
.size() > 0)
38 android_info_str
+= "; Build/" + android_build_id
;
44 android_version_str
.c_str(),
45 android_info_str
.c_str());
52 std::string
GetUserAgent() {
53 std::string product
= "Chrome/" PRODUCT_VERSION
;
58 #if defined(OS_ANDROID)
60 BuildAndroidOsInfo().c_str()
63 content::BuildOSCpuInfo().c_str()
66 return content::BuildUserAgentFromOSAndProduct(os_info
, product
) +
67 " CrKey/" CAST_BUILD_REVISION
;
70 CastContentClient::~CastContentClient() {
73 std::string
CastContentClient::GetUserAgent() const {
74 return chromecast::shell::GetUserAgent();
77 base::string16
CastContentClient::GetLocalizedString(int message_id
) const {
78 return l10n_util::GetStringUTF16(message_id
);
81 base::StringPiece
CastContentClient::GetDataResource(
83 ui::ScaleFactor scale_factor
) const {
84 return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
85 resource_id
, scale_factor
);
88 base::RefCountedStaticMemory
* CastContentClient::GetDataResourceBytes(
89 int resource_id
) const {
90 return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
94 gfx::Image
& CastContentClient::GetNativeImageNamed(int resource_id
) const {
95 return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
100 } // namespace chromecast