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