blob: b4400ae8871d5b944ccf9c2332fbc204e26adf5a [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
tornee72c9f4c2014-11-04 16:30:567#include "android_webview/common/aw_version_info_values.h"
[email protected]9b57401b2012-10-10 16:01:478#include "base/basictypes.h"
[email protected]97e8f0542013-07-28 08:45:149#include "base/command_line.h"
10#include "content/public/common/content_switches.h"
[email protected]efd2c3f2014-03-11 09:57:2511#include "content/public/common/user_agent.h"
[email protected]6fceb912013-02-15 06:24:1512#include "ipc/ipc_message.h"
[email protected]9b57401b2012-10-10 16:01:4713#include "ui/base/l10n/l10n_util.h"
14#include "ui/base/resource/resource_bundle.h"
[email protected]9b57401b2012-10-10 16:01:4715
dgozman102fee92015-04-20 15:45:4616namespace android_webview {
[email protected]9b57401b2012-10-10 16:01:4717
[email protected]aa051272014-03-10 05:56:5618std::string GetProduct() {
tornee72c9f4c2014-11-04 16:30:5619 return "Chrome/" PRODUCT_VERSION;
[email protected]9b57401b2012-10-10 16:01:4720}
21
[email protected]aa051272014-03-10 05:56:5622std::string GetUserAgent() {
[email protected]f58731e2013-11-26 23:29:0623 // "Version/4.0" had been hardcoded in the legacy WebView.
[email protected]9a5bb052014-04-17 16:50:5624 std::string product = "Version/4.0 " + GetProduct();
pgal.u-szeged929d45a92014-10-28 11:50:4125 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]97e8f0542013-07-28 08:45:1426 switches::kUseMobileUserAgent)) {
27 product += " Mobile";
28 }
gsenntone98c5bb42015-03-30 19:22:5729 return content::BuildUserAgentFromProductAndExtraOSInfo(
30 product,
31 GetExtraOSUserAgentInfo());
32}
33
34std::string GetExtraOSUserAgentInfo() {
35 return "; wv";
[email protected]9b57401b2012-10-10 16:01:4736}
37
[email protected]aa051272014-03-10 05:56:5638std::string AwContentClient::GetProduct() const {
dgozman102fee92015-04-20 15:45:4639 return android_webview::GetProduct();
[email protected]aa051272014-03-10 05:56:5640}
41
42std::string AwContentClient::GetUserAgent() const {
43 return android_webview::GetUserAgent();
44}
45
[email protected]865eb542013-12-19 22:44:4946base::string16 AwContentClient::GetLocalizedString(int message_id) const {
[email protected]9b57401b2012-10-10 16:01:4747 // TODO(boliu): Used only by WebKit, so only bundle those resources for
48 // Android WebView.
49 return l10n_util::GetStringUTF16(message_id);
50}
51
52base::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]4d8bb1a92012-11-01 21:12:4057 return ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
[email protected]9b57401b2012-10-10 16:01:4758 resource_id, scale_factor);
59}
60
[email protected]6fceb912013-02-15 06:24:1561bool 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]9b57401b2012-10-10 16:01:4769} // namespace android_webview