[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 | |||||
torne | e72c9f4c | 2014-11-04 16:30:56 | [diff] [blame] | 7 | #include "android_webview/common/aw_version_info_values.h" |
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 8 | #include "base/basictypes.h" |
[email protected] | 97e8f054 | 2013-07-28 08:45:14 | [diff] [blame] | 9 | #include "base/command_line.h" |
10 | #include "content/public/common/content_switches.h" | ||||
[email protected] | efd2c3f | 2014-03-11 09:57:25 | [diff] [blame] | 11 | #include "content/public/common/user_agent.h" |
[email protected] | 6fceb91 | 2013-02-15 06:24:15 | [diff] [blame] | 12 | #include "ipc/ipc_message.h" |
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 13 | #include "ui/base/l10n/l10n_util.h" |
14 | #include "ui/base/resource/resource_bundle.h" | ||||
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 15 | |
dgozman | 102fee9 | 2015-04-20 15:45:46 | [diff] [blame^] | 16 | namespace android_webview { |
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 17 | |
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 18 | std::string GetProduct() { |
torne | e72c9f4c | 2014-11-04 16:30:56 | [diff] [blame] | 19 | return "Chrome/" PRODUCT_VERSION; |
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 20 | } |
21 | |||||
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 22 | std::string GetUserAgent() { |
[email protected] | f58731e | 2013-11-26 23:29:06 | [diff] [blame] | 23 | // "Version/4.0" had been hardcoded in the legacy WebView. |
[email protected] | 9a5bb05 | 2014-04-17 16:50:56 | [diff] [blame] | 24 | std::string product = "Version/4.0 " + GetProduct(); |
pgal.u-szeged | 929d45a9 | 2014-10-28 11:50:41 | [diff] [blame] | 25 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | 97e8f054 | 2013-07-28 08:45:14 | [diff] [blame] | 26 | switches::kUseMobileUserAgent)) { |
27 | product += " Mobile"; | ||||
28 | } | ||||
gsennton | e98c5bb4 | 2015-03-30 19:22:57 | [diff] [blame] | 29 | return content::BuildUserAgentFromProductAndExtraOSInfo( |
30 | product, | ||||
31 | GetExtraOSUserAgentInfo()); | ||||
32 | } | ||||
33 | |||||
34 | std::string GetExtraOSUserAgentInfo() { | ||||
35 | return "; wv"; | ||||
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 36 | } |
37 | |||||
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 38 | std::string AwContentClient::GetProduct() const { |
dgozman | 102fee9 | 2015-04-20 15:45:46 | [diff] [blame^] | 39 | return android_webview::GetProduct(); |
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 40 | } |
41 | |||||
42 | std::string AwContentClient::GetUserAgent() const { | ||||
43 | return android_webview::GetUserAgent(); | ||||
44 | } | ||||
45 | |||||
[email protected] | 865eb54 | 2013-12-19 22:44:49 | [diff] [blame] | 46 | base::string16 AwContentClient::GetLocalizedString(int message_id) const { |
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 47 | // TODO(boliu): Used only by WebKit, so only bundle those resources for |
48 | // Android WebView. | ||||
49 | return l10n_util::GetStringUTF16(message_id); | ||||
50 | } | ||||
51 | |||||
52 | base::StringPiece AwContentClient::GetDataResource( | ||||
53 | int resource_id, | ||||
54 | ui::ScaleFactor scale_factor) const { | ||||
55 | // TODO(boliu): Used only by WebKit, so only bundle those resources for | ||||
56 | // Android WebView. | ||||
[email protected] | 4d8bb1a9 | 2012-11-01 21:12:40 | [diff] [blame] | 57 | return ResourceBundle::GetSharedInstance().GetRawDataResourceForScale( |
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 58 | resource_id, scale_factor); |
59 | } | ||||
60 | |||||
[email protected] | 6fceb91 | 2013-02-15 06:24:15 | [diff] [blame] | 61 | bool AwContentClient::CanSendWhileSwappedOut(const IPC::Message* message) { |
62 | // For legacy API support we perform a few browser -> renderer synchronous IPC | ||||
63 | // messages that block the browser. However, the synchronous IPC replies might | ||||
64 | // be dropped by the renderer during a swap out, deadlocking the browser. | ||||
65 | // Because of this we should never drop any synchronous IPC replies. | ||||
66 | return message->type() == IPC_REPLY_ID; | ||||
67 | } | ||||
68 | |||||
[email protected] | 9b57401b | 2012-10-10 16:01:47 | [diff] [blame] | 69 | } // namespace android_webview |