Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / android_webview / common / aw_content_client.cc
blob240b734bc0b5dc302a5b4ca133515d7a42012821
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.
5 #include "android_webview/common/aw_content_client.h"
7 #include "android_webview/common/aw_version_info_values.h"
8 #include "base/basictypes.h"
9 #include "base/command_line.h"
10 #include "content/public/common/content_switches.h"
11 #include "content/public/common/user_agent.h"
12 #include "ipc/ipc_message.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/resource/resource_bundle.h"
16 namespace {
18 std::string GetProduct() {
19 return "Chrome/" PRODUCT_VERSION;
24 namespace android_webview {
26 std::string GetUserAgent() {
27 // "Version/4.0" had been hardcoded in the legacy WebView.
28 std::string product = "Version/4.0 " + GetProduct();
29 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
30 switches::kUseMobileUserAgent)) {
31 product += " Mobile";
33 return content::BuildUserAgentFromProductAndExtraOSInfo(
34 product,
35 GetExtraOSUserAgentInfo());
38 std::string GetExtraOSUserAgentInfo() {
39 return "; wv";
42 std::string AwContentClient::GetProduct() const {
43 return ::GetProduct();
46 std::string AwContentClient::GetUserAgent() const {
47 return android_webview::GetUserAgent();
50 base::string16 AwContentClient::GetLocalizedString(int message_id) const {
51 // TODO(boliu): Used only by WebKit, so only bundle those resources for
52 // Android WebView.
53 return l10n_util::GetStringUTF16(message_id);
56 base::StringPiece AwContentClient::GetDataResource(
57 int resource_id,
58 ui::ScaleFactor scale_factor) const {
59 // TODO(boliu): Used only by WebKit, so only bundle those resources for
60 // Android WebView.
61 return ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
62 resource_id, scale_factor);
65 bool AwContentClient::CanSendWhileSwappedOut(const IPC::Message* message) {
66 // For legacy API support we perform a few browser -> renderer synchronous IPC
67 // messages that block the browser. However, the synchronous IPC replies might
68 // be dropped by the renderer during a swap out, deadlocking the browser.
69 // Because of this we should never drop any synchronous IPC replies.
70 return message->type() == IPC_REPLY_ID;
73 } // namespace android_webview