blob: 30ef6c249e9a2ea501a1d9c3e9e4e083fdba8265 [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
7#include "base/basictypes.h"
[email protected]97e8f0542013-07-28 08:45:148#include "base/command_line.h"
9#include "content/public/common/content_switches.h"
[email protected]6fceb912013-02-15 06:24:1510#include "ipc/ipc_message.h"
[email protected]9b57401b2012-10-10 16:01:4711#include "ui/base/l10n/l10n_util.h"
12#include "ui/base/resource/resource_bundle.h"
[email protected]8468d282013-05-23 04:53:4513#include "webkit/common/user_agent/user_agent_util.h"
[email protected]9b57401b2012-10-10 16:01:4714
15namespace android_webview {
16
17std::string AwContentClient::GetProduct() const {
[email protected]f58731e2013-11-26 23:29:0618 // "Chrome/XX.0.0.0" identifies that this WebView is derived from the
19 // corresponding Chromium version XX.
20 // TODO(torne): Use chrome/VERSION file. See http://crbug.com/297522
21 return "Chrome/33.0.0.0";
[email protected]9b57401b2012-10-10 16:01:4722}
23
24std::string AwContentClient::GetUserAgent() const {
[email protected]f58731e2013-11-26 23:29:0625 // "Version/4.0" had been hardcoded in the legacy WebView.
26 std::string product = "Version/4.0 " + GetProduct();
[email protected]97e8f0542013-07-28 08:45:1427 if (CommandLine::ForCurrentProcess()->HasSwitch(
28 switches::kUseMobileUserAgent)) {
29 product += " Mobile";
30 }
31 return webkit_glue::BuildUserAgentFromProduct(product);
[email protected]9b57401b2012-10-10 16:01:4732}
33
34string16 AwContentClient::GetLocalizedString(int message_id) const {
35 // TODO(boliu): Used only by WebKit, so only bundle those resources for
36 // Android WebView.
37 return l10n_util::GetStringUTF16(message_id);
38}
39
40base::StringPiece AwContentClient::GetDataResource(
41 int resource_id,
42 ui::ScaleFactor scale_factor) const {
43 // TODO(boliu): Used only by WebKit, so only bundle those resources for
44 // Android WebView.
[email protected]4d8bb1a92012-11-01 21:12:4045 return ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
[email protected]9b57401b2012-10-10 16:01:4746 resource_id, scale_factor);
47}
48
[email protected]6fceb912013-02-15 06:24:1549bool AwContentClient::CanSendWhileSwappedOut(const IPC::Message* message) {
50 // For legacy API support we perform a few browser -> renderer synchronous IPC
51 // messages that block the browser. However, the synchronous IPC replies might
52 // be dropped by the renderer during a swap out, deadlocking the browser.
53 // Because of this we should never drop any synchronous IPC replies.
54 return message->type() == IPC_REPLY_ID;
55}
56
[email protected]9b57401b2012-10-10 16:01:4757} // namespace android_webview