blob: f686cf4f8fb3b933d78f811f5069f27e6f21fcbe [file] [log] [blame]
[email protected]9b57401b2012-10-10 16:01:471// Copyright (c) 2012 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 "android_webview/common/aw_content_client.h"
6
chcunninghama4a8efb2017-03-22 16:55:027#include "android_webview/common/aw_media_drm_bridge_client.h"
xhwang87c426172016-06-10 20:29:218#include "android_webview/common/aw_resource.h"
tornee72c9f4c2014-11-04 16:30:569#include "android_webview/common/aw_version_info_values.h"
tobiasjs41536401d2017-02-10 19:27:0210#include "android_webview/common/crash_reporter/crash_keys.h"
jam09015352017-01-19 01:49:0211#include "android_webview/common/url_constants.h"
[email protected]97e8f0542013-07-28 08:45:1412#include "base/command_line.h"
tobiasjs41536401d2017-02-10 19:27:0213#include "base/debug/crash_logging.h"
[email protected]97e8f0542013-07-28 08:45:1414#include "content/public/common/content_switches.h"
[email protected]efd2c3f2014-03-11 09:57:2515#include "content/public/common/user_agent.h"
tobiasjsb848517ac2015-09-29 12:03:3816#include "gpu/config/gpu_info.h"
sadrul1432276f2017-03-21 02:03:4117#include "gpu/config/gpu_util.h"
[email protected]6fceb912013-02-15 06:24:1518#include "ipc/ipc_message.h"
[email protected]9b57401b2012-10-10 16:01:4719#include "ui/base/l10n/l10n_util.h"
20#include "ui/base/resource/resource_bundle.h"
[email protected]9b57401b2012-10-10 16:01:4721
dgozman102fee92015-04-20 15:45:4622namespace android_webview {
[email protected]9b57401b2012-10-10 16:01:4723
[email protected]aa051272014-03-10 05:56:5624std::string GetProduct() {
tornee72c9f4c2014-11-04 16:30:5625 return "Chrome/" PRODUCT_VERSION;
[email protected]9b57401b2012-10-10 16:01:4726}
27
[email protected]aa051272014-03-10 05:56:5628std::string GetUserAgent() {
[email protected]f58731e2013-11-26 23:29:0629 // "Version/4.0" had been hardcoded in the legacy WebView.
[email protected]9a5bb052014-04-17 16:50:5630 std::string product = "Version/4.0 " + GetProduct();
pgal.u-szeged929d45a92014-10-28 11:50:4131 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]97e8f0542013-07-28 08:45:1432 switches::kUseMobileUserAgent)) {
33 product += " Mobile";
34 }
gsenntone98c5bb42015-03-30 19:22:5735 return content::BuildUserAgentFromProductAndExtraOSInfo(
36 product,
37 GetExtraOSUserAgentInfo());
38}
39
40std::string GetExtraOSUserAgentInfo() {
41 return "; wv";
[email protected]9b57401b2012-10-10 16:01:4742}
43
jam09015352017-01-19 01:49:0244void AwContentClient::AddAdditionalSchemes(Schemes* schemes) {
45 schemes->local_schemes.push_back(url::kContentScheme);
46 schemes->secure_schemes.push_back(
47 android_webview::kAndroidWebViewVideoPosterScheme);
48}
49
[email protected]aa051272014-03-10 05:56:5650std::string AwContentClient::GetProduct() const {
dgozman102fee92015-04-20 15:45:4651 return android_webview::GetProduct();
[email protected]aa051272014-03-10 05:56:5652}
53
54std::string AwContentClient::GetUserAgent() const {
55 return android_webview::GetUserAgent();
56}
57
[email protected]865eb542013-12-19 22:44:4958base::string16 AwContentClient::GetLocalizedString(int message_id) const {
[email protected]9b57401b2012-10-10 16:01:4759 // TODO(boliu): Used only by WebKit, so only bundle those resources for
60 // Android WebView.
61 return l10n_util::GetStringUTF16(message_id);
62}
63
64base::StringPiece AwContentClient::GetDataResource(
65 int resource_id,
66 ui::ScaleFactor scale_factor) const {
67 // TODO(boliu): Used only by WebKit, so only bundle those resources for
68 // Android WebView.
[email protected]4d8bb1a92012-11-01 21:12:4069 return ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
[email protected]9b57401b2012-10-10 16:01:4770 resource_id, scale_factor);
71}
72
[email protected]6fceb912013-02-15 06:24:1573bool AwContentClient::CanSendWhileSwappedOut(const IPC::Message* message) {
74 // For legacy API support we perform a few browser -> renderer synchronous IPC
75 // messages that block the browser. However, the synchronous IPC replies might
76 // be dropped by the renderer during a swap out, deadlocking the browser.
77 // Because of this we should never drop any synchronous IPC replies.
78 return message->type() == IPC_REPLY_ID;
79}
80
tobiasjsb848517ac2015-09-29 12:03:3881void AwContentClient::SetGpuInfo(const gpu::GPUInfo& gpu_info) {
82 gpu_fingerprint_ = gpu_info.gl_version + '|' + gpu_info.gl_vendor + '|' +
83 gpu_info.gl_renderer;
84 std::replace_if(gpu_fingerprint_.begin(), gpu_fingerprint_.end(),
85 [](char c) { return !::isprint(c); }, '_');
tobiasjs41536401d2017-02-10 19:27:0286
sadrul1432276f2017-03-21 02:03:4187 gpu::SetKeysForCrashLogging(gpu_info);
tobiasjsb848517ac2015-09-29 12:03:3888}
89
boliu66024c62016-04-20 04:00:4190bool AwContentClient::UsingSynchronousCompositing() {
91 return true;
92}
93
chcunninghama4a8efb2017-03-22 16:55:0294media::MediaDrmBridgeClient* AwContentClient::GetMediaDrmBridgeClient() {
95 return new AwMediaDrmBridgeClient(
96 AwResource::GetConfigKeySystemUuidMapping());
xhwang87c426172016-06-10 20:29:2197}
98
[email protected]9b57401b2012-10-10 16:01:4799} // namespace android_webview