[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 1 | // 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 | |
chcunningham | a4a8efb | 2017-03-22 16:55:02 | [diff] [blame^] | 7 | #include "android_webview/common/aw_media_drm_bridge_client.h" |
xhwang | 87c42617 | 2016-06-10 20:29:21 | [diff] [blame] | 8 | #include "android_webview/common/aw_resource.h" |
torne | e72c9f4c | 2014-11-04 16:30:56 | [diff] [blame] | 9 | #include "android_webview/common/aw_version_info_values.h" |
tobiasjs | 41536401d | 2017-02-10 19:27:02 | [diff] [blame] | 10 | #include "android_webview/common/crash_reporter/crash_keys.h" |
jam | 0901535 | 2017-01-19 01:49:02 | [diff] [blame] | 11 | #include "android_webview/common/url_constants.h" |
[email protected] | 97e8f054 | 2013-07-28 08:45:14 | [diff] [blame] | 12 | #include "base/command_line.h" |
tobiasjs | 41536401d | 2017-02-10 19:27:02 | [diff] [blame] | 13 | #include "base/debug/crash_logging.h" |
[email protected] | 97e8f054 | 2013-07-28 08:45:14 | [diff] [blame] | 14 | #include "content/public/common/content_switches.h" |
[email protected] | efd2c3f | 2014-03-11 09:57:25 | [diff] [blame] | 15 | #include "content/public/common/user_agent.h" |
tobiasjs | b848517ac | 2015-09-29 12:03:38 | [diff] [blame] | 16 | #include "gpu/config/gpu_info.h" |
sadrul | 1432276f | 2017-03-21 02:03:41 | [diff] [blame] | 17 | #include "gpu/config/gpu_util.h" |
[email protected] | 6fceb91 | 2013-02-15 06:24:15 | [diff] [blame] | 18 | #include "ipc/ipc_message.h" |
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 19 | #include "ui/base/l10n/l10n_util.h" |
| 20 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 21 | |
dgozman | 102fee9 | 2015-04-20 15:45:46 | [diff] [blame] | 22 | namespace android_webview { |
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 23 | |
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 24 | std::string GetProduct() { |
torne | e72c9f4c | 2014-11-04 16:30:56 | [diff] [blame] | 25 | return "Chrome/" PRODUCT_VERSION; |
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 26 | } |
| 27 | |
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 28 | std::string GetUserAgent() { |
[email protected] | f58731e | 2013-11-26 23:29:06 | [diff] [blame] | 29 | // "Version/4.0" had been hardcoded in the legacy WebView. |
[email protected] | 9a5bb05 | 2014-04-17 16:50:56 | [diff] [blame] | 30 | std::string product = "Version/4.0 " + GetProduct(); |
pgal.u-szeged | 929d45a9 | 2014-10-28 11:50:41 | [diff] [blame] | 31 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | 97e8f054 | 2013-07-28 08:45:14 | [diff] [blame] | 32 | switches::kUseMobileUserAgent)) { |
| 33 | product += " Mobile"; |
| 34 | } |
gsennton | e98c5bb4 | 2015-03-30 19:22:57 | [diff] [blame] | 35 | return content::BuildUserAgentFromProductAndExtraOSInfo( |
| 36 | product, |
| 37 | GetExtraOSUserAgentInfo()); |
| 38 | } |
| 39 | |
| 40 | std::string GetExtraOSUserAgentInfo() { |
| 41 | return "; wv"; |
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 42 | } |
| 43 | |
jam | 0901535 | 2017-01-19 01:49:02 | [diff] [blame] | 44 | void 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] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 50 | std::string AwContentClient::GetProduct() const { |
dgozman | 102fee9 | 2015-04-20 15:45:46 | [diff] [blame] | 51 | return android_webview::GetProduct(); |
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | std::string AwContentClient::GetUserAgent() const { |
| 55 | return android_webview::GetUserAgent(); |
| 56 | } |
| 57 | |
[email protected] | 865eb54 | 2013-12-19 22:44:49 | [diff] [blame] | 58 | base::string16 AwContentClient::GetLocalizedString(int message_id) const { |
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 59 | // TODO(boliu): Used only by WebKit, so only bundle those resources for |
| 60 | // Android WebView. |
| 61 | return l10n_util::GetStringUTF16(message_id); |
| 62 | } |
| 63 | |
| 64 | base::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] | 4d8bb1a9 | 2012-11-01 21:12:40 | [diff] [blame] | 69 | return ResourceBundle::GetSharedInstance().GetRawDataResourceForScale( |
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 70 | resource_id, scale_factor); |
| 71 | } |
| 72 | |
[email protected] | 6fceb91 | 2013-02-15 06:24:15 | [diff] [blame] | 73 | bool 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 | |
tobiasjs | b848517ac | 2015-09-29 12:03:38 | [diff] [blame] | 81 | void 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); }, '_'); |
tobiasjs | 41536401d | 2017-02-10 19:27:02 | [diff] [blame] | 86 | |
sadrul | 1432276f | 2017-03-21 02:03:41 | [diff] [blame] | 87 | gpu::SetKeysForCrashLogging(gpu_info); |
tobiasjs | b848517ac | 2015-09-29 12:03:38 | [diff] [blame] | 88 | } |
| 89 | |
boliu | 66024c6 | 2016-04-20 04:00:41 | [diff] [blame] | 90 | bool AwContentClient::UsingSynchronousCompositing() { |
| 91 | return true; |
| 92 | } |
| 93 | |
chcunningham | a4a8efb | 2017-03-22 16:55:02 | [diff] [blame^] | 94 | media::MediaDrmBridgeClient* AwContentClient::GetMediaDrmBridgeClient() { |
| 95 | return new AwMediaDrmBridgeClient( |
| 96 | AwResource::GetConfigKeySystemUuidMapping()); |
xhwang | 87c42617 | 2016-06-10 20:29:21 | [diff] [blame] | 97 | } |
| 98 | |
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 99 | } // namespace android_webview |