Roll src/third_party/skia 523beb7:de50d9b
[chromium-blink-merge.git] / chromecast / common / cast_content_client.cc
blobca3a2639a66f12b948a87a10af96fda91245fd61
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/base/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 {
15 namespace shell {
17 namespace {
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,
25 &os_minor_version,
26 &os_bugfix_version);
28 std::string android_version_str;
29 base::StringAppendF(
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;
40 std::string os_info;
41 base::StringAppendF(
42 &os_info,
43 "Android %s%s",
44 android_version_str.c_str(),
45 android_info_str.c_str());
46 return os_info;
48 #endif
50 } // namespace
52 std::string GetUserAgent() {
53 std::string product = "Chrome/" PRODUCT_VERSION;
54 std::string os_info;
55 base::StringAppendF(
56 &os_info,
57 "%s%s",
58 #if defined(OS_ANDROID)
59 "Linux; ",
60 BuildAndroidOsInfo().c_str()
61 #else
62 "X11; ",
63 content::BuildOSCpuInfo().c_str()
64 #endif
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(
82 int resource_id,
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(
91 resource_id);
94 gfx::Image& CastContentClient::GetNativeImageNamed(int resource_id) const {
95 return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
96 resource_id);
99 } // namespace shell
100 } // namespace chromecast