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 "content/public/common/content_client.h" 6 7 #include "base/logging.h" 8 #include "base/strings/string_piece.h" 9 #include "ui/gfx/image/image.h" 10 #include "webkit/common/user_agent/user_agent.h" 11 12 namespace content { 13 14 static ContentClient* g_client; 15 16 class InternalTestInitializer { 17 public: 18 static ContentBrowserClient* SetBrowser(ContentBrowserClient* b) { 19 ContentBrowserClient* rv = g_client->browser_; 20 g_client->browser_ = b; 21 return rv; 22 } 23 24 static ContentRendererClient* SetRenderer(ContentRendererClient* r) { 25 ContentRendererClient* rv = g_client->renderer_; 26 g_client->renderer_ = r; 27 return rv; 28 } 29 30 static ContentUtilityClient* SetUtility(ContentUtilityClient* u) { 31 ContentUtilityClient* rv = g_client->utility_; 32 g_client->utility_ = u; 33 return rv; 34 } 35 }; 36 37 void SetContentClient(ContentClient* client) { 38 g_client = client; 39 40 // Set the default user agent as provided by the client. We need to make 41 // sure this is done before webkit_glue::GetUserAgent() is called (so that 42 // the UA doesn't change). 43 if (client) { 44 webkit_glue::SetUserAgent(client->GetUserAgent(), false); 45 } 46 } 47 48 ContentClient* GetContentClient() { 49 return g_client; 50 } 51 52 ContentBrowserClient* SetBrowserClientForTesting(ContentBrowserClient* b) { 53 return InternalTestInitializer::SetBrowser(b); 54 } 55 56 ContentRendererClient* SetRendererClientForTesting(ContentRendererClient* r) { 57 return InternalTestInitializer::SetRenderer(r); 58 } 59 60 ContentUtilityClient* SetUtilityClientForTesting(ContentUtilityClient* u) { 61 return InternalTestInitializer::SetUtility(u); 62 } 63 64 const std::string& GetUserAgent(const GURL& url) { 65 DCHECK(g_client); 66 return webkit_glue::GetUserAgent(url); 67 } 68 69 ContentClient::ContentClient() 70 : browser_(NULL), plugin_(NULL), renderer_(NULL), utility_(NULL) { 71 } 72 73 ContentClient::~ContentClient() { 74 } 75 76 bool ContentClient::CanSendWhileSwappedOut(const IPC::Message* message) { 77 return false; 78 } 79 80 bool ContentClient::CanHandleWhileSwappedOut(const IPC::Message& message) { 81 return false; 82 } 83 84 std::string ContentClient::GetProduct() const { 85 return std::string(); 86 } 87 88 std::string ContentClient::GetUserAgent() const { 89 return std::string(); 90 } 91 92 base::string16 ContentClient::GetLocalizedString(int message_id) const { 93 return base::string16(); 94 } 95 96 base::StringPiece ContentClient::GetDataResource( 97 int resource_id, 98 ui::ScaleFactor scale_factor) const { 99 return base::StringPiece(); 100 } 101 102 base::RefCountedStaticMemory* ContentClient::GetDataResourceBytes( 103 int resource_id) const { 104 return NULL; 105 } 106 107 gfx::Image& ContentClient::GetNativeImageNamed(int resource_id) const { 108 CR_DEFINE_STATIC_LOCAL(gfx::Image, kEmptyImage, ()); 109 return kEmptyImage; 110 } 111 112 std::string ContentClient::GetProcessTypeNameInEnglish(int type) { 113 NOTIMPLEMENTED(); 114 return std::string(); 115 } 116 117 #if defined(OS_MACOSX) && !defined(OS_IOS) 118 bool ContentClient::GetSandboxProfileForSandboxType( 119 int sandbox_type, 120 int* sandbox_profile_resource_id) const { 121 return false; 122 } 123 124 std::string ContentClient::GetCarbonInterposePath() const { 125 return std::string(); 126 } 127 #endif 128 129 } // namespace content 130