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 "content/public/common/user_agent.h" 11 #include "ipc/ipc_message.h" 12 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/resource/resource_bundle.h" 14 15 namespace { 16 GetProduct()17std::string GetProduct() { 18 // "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/39.0.0.0"; 22 } 23 24 } 25 26 namespace android_webview { 27 GetUserAgent()28std::string GetUserAgent() { 29 // "Version/4.0" had been hardcoded in the legacy WebView. 30 std::string product = "Version/4.0 " + GetProduct(); 31 if (CommandLine::ForCurrentProcess()->HasSwitch( 32 switches::kUseMobileUserAgent)) { 33 product += " Mobile"; 34 } 35 return content::BuildUserAgentFromProduct(product); 36 } 37 GetProduct() const38std::string AwContentClient::GetProduct() const { 39 return ::GetProduct(); 40 } 41 GetUserAgent() const42std::string AwContentClient::GetUserAgent() const { 43 return android_webview::GetUserAgent(); 44 } 45 GetLocalizedString(int message_id) const46base::string16 AwContentClient::GetLocalizedString(int message_id) const { 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 GetDataResource(int resource_id,ui::ScaleFactor scale_factor) const52base::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. 57 return ResourceBundle::GetSharedInstance().GetRawDataResourceForScale( 58 resource_id, scale_factor); 59 } 60 CanSendWhileSwappedOut(const IPC::Message * message)61bool 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 69 } // namespace android_webview 70