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 7 #include "base/basictypes.h" 8 #include "base/command_line.h" 9 #include "content/public/common/content_switches.h" 10 #include "ipc/ipc_message.h" 11 #include "ui/base/l10n/l10n_util.h" 12 #include "ui/base/resource/resource_bundle.h" 13 #include "webkit/common/user_agent/user_agent_util.h" 14 15 namespace android_webview { 16 17 std::string AwContentClient::GetProduct() const { 18 // "Version/4.0" had been hardcoded in the legacy WebView. 19 // "Chrome/30.0.0.0" identifies that this WebView is derived originally 20 // from Chromium M30. 21 return std::string("Version/4.0 Chrome/30.0.0.0"); 22 } 23 24 std::string AwContentClient::GetUserAgent() const { 25 std::string product = GetProduct(); 26 if (CommandLine::ForCurrentProcess()->HasSwitch( 27 switches::kUseMobileUserAgent)) { 28 product += " Mobile"; 29 } 30 return webkit_glue::BuildUserAgentFromProduct(product); 31 } 32 33 string16 AwContentClient::GetLocalizedString(int message_id) const { 34 // TODO(boliu): Used only by WebKit, so only bundle those resources for 35 // Android WebView. 36 return l10n_util::GetStringUTF16(message_id); 37 } 38 39 base::StringPiece AwContentClient::GetDataResource( 40 int resource_id, 41 ui::ScaleFactor scale_factor) const { 42 // TODO(boliu): Used only by WebKit, so only bundle those resources for 43 // Android WebView. 44 return ResourceBundle::GetSharedInstance().GetRawDataResourceForScale( 45 resource_id, scale_factor); 46 } 47 48 bool AwContentClient::CanSendWhileSwappedOut(const IPC::Message* message) { 49 // For legacy API support we perform a few browser -> renderer synchronous IPC 50 // messages that block the browser. However, the synchronous IPC replies might 51 // be dropped by the renderer during a swap out, deadlocking the browser. 52 // Because of this we should never drop any synchronous IPC replies. 53 return message->type() == IPC_REPLY_ID; 54 } 55 56 } // namespace android_webview 57