content_client.h revision 010d83a9304c5a91596085d917d248abff47903a
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CONTENT_PUBLIC_COMMON_CONTENT_CLIENT_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CONTENT_PUBLIC_COMMON_CONTENT_CLIENT_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/strings/string16.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/strings/string_piece.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "build/build_config.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/content_export.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/layout.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GURL;
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RefCountedStaticMemory;
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace IPC {
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Message;
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gfx {
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Image;
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gpu {
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct GPUInfo;
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace sandbox {
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TargetPolicy;
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ContentBrowserClient;
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ContentClient;
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ContentPluginClient;
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ContentRendererClient;
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ContentUtilityClient;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct PepperPluginInfo;
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Setter and getter for the client.  The client should be set early, before any
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// content code is called.
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)CONTENT_EXPORT void SetContentClient(ContentClient* client);
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
53#if defined(CONTENT_IMPLEMENTATION)
54// Content's embedder API should only be used by content.
55ContentClient* GetContentClient();
56#endif
57
58// Used for tests to override the relevant embedder interfaces. Each method
59// returns the old value.
60CONTENT_EXPORT ContentBrowserClient* SetBrowserClientForTesting(
61    ContentBrowserClient* b);
62CONTENT_EXPORT ContentRendererClient* SetRendererClientForTesting(
63    ContentRendererClient* r);
64CONTENT_EXPORT ContentUtilityClient* SetUtilityClientForTesting(
65    ContentUtilityClient* u);
66
67// Interface that the embedder implements.
68class CONTENT_EXPORT ContentClient {
69 public:
70  ContentClient();
71  virtual ~ContentClient();
72
73  ContentBrowserClient* browser() { return browser_; }
74  ContentPluginClient* plugin() { return plugin_; }
75  ContentRendererClient* renderer() { return renderer_; }
76  ContentUtilityClient* utility() { return utility_; }
77
78  // Sets the currently active URL.  Use GURL() to clear the URL.
79  virtual void SetActiveURL(const GURL& url) {}
80
81  // Sets the data on the current gpu.
82  virtual void SetGpuInfo(const gpu::GPUInfo& gpu_info) {}
83
84  // Gives the embedder a chance to register its own pepper plugins.
85  virtual void AddPepperPlugins(
86      std::vector<content::PepperPluginInfo>* plugins) {}
87
88  // Gives the embedder a chance to register its own standard and saveable
89  // url schemes early on in the startup sequence.
90  virtual void AddAdditionalSchemes(
91      std::vector<std::string>* standard_schemes,
92      std::vector<std::string>* savable_schemes) {}
93
94  // Returns whether the given message should be sent in a swapped out renderer.
95  virtual bool CanSendWhileSwappedOut(const IPC::Message* message);
96
97  // Returns a string describing the embedder product name and version,
98  // of the form "productname/version", with no other slashes.
99  // Used as part of the user agent string.
100  virtual std::string GetProduct() const;
101
102  // Returns the user agent.
103  virtual std::string GetUserAgent() const;
104
105  // Returns a string resource given its id.
106  virtual base::string16 GetLocalizedString(int message_id) const;
107
108  // Return the contents of a resource in a StringPiece given the resource id.
109  virtual base::StringPiece GetDataResource(
110      int resource_id,
111      ui::ScaleFactor scale_factor) const;
112
113  // Returns the raw bytes of a scale independent data resource.
114  virtual base::RefCountedStaticMemory* GetDataResourceBytes(
115      int resource_id) const;
116
117  // Returns a native image given its id.
118  virtual gfx::Image& GetNativeImageNamed(int resource_id) const;
119
120  // Called by content::GetProcessTypeNameInEnglish for process types that it
121  // doesn't know about because they're from the embedder.
122  virtual std::string GetProcessTypeNameInEnglish(int type);
123
124#if defined(OS_MACOSX) && !defined(OS_IOS)
125  // Allows the embedder to define a new |sandbox_type| by mapping it to the
126  // resource ID corresponding to the sandbox profile to use. The legal values
127  // for |sandbox_type| are defined by the embedder and should start with
128  // SandboxType::SANDBOX_TYPE_AFTER_LAST_TYPE. Returns false if no sandbox
129  // profile for the given |sandbox_type| exists. Otherwise,
130  // |sandbox_profile_resource_id| is set to the resource ID corresponding to
131  // the sandbox profile to use and true is returned.
132  virtual bool GetSandboxProfileForSandboxType(
133      int sandbox_type,
134      int* sandbox_profile_resource_id) const;
135
136  // Gets the Carbon interposing path to give to DYLD. Returns an empty string
137  // if the embedder doesn't bundle it.
138  virtual std::string GetCarbonInterposePath() const;
139#endif
140
141 private:
142  friend class ContentClientInitializer;  // To set these pointers.
143  friend class InternalTestInitializer;
144
145  // The embedder API for participating in browser logic.
146  ContentBrowserClient* browser_;
147  // The embedder API for participating in plugin logic.
148  ContentPluginClient* plugin_;
149  // The embedder API for participating in renderer logic.
150  ContentRendererClient* renderer_;
151  // The embedder API for participating in utility logic.
152  ContentUtilityClient* utility_;
153};
154
155}  // namespace content
156
157#endif  // CONTENT_PUBLIC_COMMON_CONTENT_CLIENT_H_
158