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.
5 #ifndef CONTENT_PUBLIC_COMMON_CONTENT_CLIENT_H_
6 #define CONTENT_PUBLIC_COMMON_CONTENT_CLIENT_H_
11 #include "base/basictypes.h"
12 #include "base/strings/string16.h"
13 #include "base/strings/string_piece.h"
14 #include "build/build_config.h"
15 #include "content/common/content_export.h"
16 #include "ui/base/layout.h"
22 class RefCountedStaticMemory;
43 class ContentBrowserClient;
45 class ContentPluginClient;
46 class ContentRendererClient;
47 class ContentUtilityClient;
48 struct PepperPluginInfo;
50 // Setter and getter for the client. The client should be set early, before any
51 // content code is called.
52 CONTENT_EXPORT void SetContentClient(ContentClient* client);
54 #if defined(CONTENT_IMPLEMENTATION)
55 // Content's embedder API should only be used by content.
56 ContentClient* GetContentClient();
59 // Used for tests to override the relevant embedder interfaces. Each method
60 // returns the old value.
61 CONTENT_EXPORT ContentBrowserClient* SetBrowserClientForTesting(
62 ContentBrowserClient* b);
63 CONTENT_EXPORT ContentRendererClient* SetRendererClientForTesting(
64 ContentRendererClient* r);
65 CONTENT_EXPORT ContentUtilityClient* SetUtilityClientForTesting(
66 ContentUtilityClient* u);
68 // Returns the user agent string being used by the browser. SetContentClient()
69 // must be called prior to calling this, and this routine must be used
70 // instead of webkit_glue::GetUserAgent() in order to ensure that we use
71 // the same user agent string everywhere.
72 // TODO(dpranke): This is caused by webkit_glue being a library that can
73 // get linked into multiple linkable objects, causing us to have multiple
74 // static values of the user agent. This will be fixed when we clean up
76 CONTENT_EXPORT const std::string& GetUserAgent(const GURL& url);
78 // Interface that the embedder implements.
79 class CONTENT_EXPORT ContentClient {
82 virtual ~ContentClient();
84 ContentBrowserClient* browser() { return browser_; }
85 ContentPluginClient* plugin() { return plugin_; }
86 ContentRendererClient* renderer() { return renderer_; }
87 ContentUtilityClient* utility() { return utility_; }
89 // Sets the currently active URL. Use GURL() to clear the URL.
90 virtual void SetActiveURL(const GURL& url) {}
92 // Sets the data on the current gpu.
93 virtual void SetGpuInfo(const gpu::GPUInfo& gpu_info) {}
95 // Gives the embedder a chance to register its own pepper plugins.
96 virtual void AddPepperPlugins(
97 std::vector<content::PepperPluginInfo>* plugins) {}
99 // Gives the embedder a chance to register its own standard and saveable
100 // url schemes early on in the startup sequence.
101 virtual void AddAdditionalSchemes(
102 std::vector<std::string>* standard_schemes,
103 std::vector<std::string>* savable_schemes) {}
105 // Returns whether the given message should be sent in a swapped out renderer.
106 virtual bool CanSendWhileSwappedOut(const IPC::Message* message);
108 // Returns whether the given message should be processed in the browser on
109 // behalf of a swapped out renderer.
110 virtual bool CanHandleWhileSwappedOut(const IPC::Message& message);
112 // Returns a string describing the embedder product name and version,
113 // of the form "productname/version", with no other slashes.
114 // Used as part of the user agent string.
115 virtual std::string GetProduct() const;
117 // Returns the user agent.
118 virtual std::string GetUserAgent() const;
120 // Returns a string resource given its id.
121 virtual string16 GetLocalizedString(int message_id) const;
123 // Return the contents of a resource in a StringPiece given the resource id.
124 virtual base::StringPiece GetDataResource(
126 ui::ScaleFactor scale_factor) const;
128 // Returns the raw bytes of a scale independent data resource.
129 virtual base::RefCountedStaticMemory* GetDataResourceBytes(
130 int resource_id) const;
132 // Returns a native image given its id.
133 virtual gfx::Image& GetNativeImageNamed(int resource_id) const;
135 // Called by content::GetProcessTypeNameInEnglish for process types that it
136 // doesn't know about because they're from the embedder.
137 virtual std::string GetProcessTypeNameInEnglish(int type);
139 #if defined(OS_MACOSX) && !defined(OS_IOS)
140 // Allows the embedder to define a new |sandbox_type| by mapping it to the
141 // resource ID corresponding to the sandbox profile to use. The legal values
142 // for |sandbox_type| are defined by the embedder and should start with
143 // SandboxType::SANDBOX_TYPE_AFTER_LAST_TYPE. Returns false if no sandbox
144 // profile for the given |sandbox_type| exists. Otherwise,
145 // |sandbox_profile_resource_id| is set to the resource ID corresponding to
146 // the sandbox profile to use and true is returned.
147 virtual bool GetSandboxProfileForSandboxType(
149 int* sandbox_profile_resource_id) const;
151 // Gets the Carbon interposing path to give to DYLD. Returns an empty string
152 // if the embedder doesn't bundle it.
153 virtual std::string GetCarbonInterposePath() const;
157 friend class ContentClientInitializer; // To set these pointers.
158 friend class InternalTestInitializer;
160 // The embedder API for participating in browser logic.
161 ContentBrowserClient* browser_;
162 // The embedder API for participating in plugin logic.
163 ContentPluginClient* plugin_;
164 // The embedder API for participating in renderer logic.
165 ContentRendererClient* renderer_;
166 // The embedder API for participating in utility logic.
167 ContentUtilityClient* utility_;
170 } // namespace content
172 #endif // CONTENT_PUBLIC_COMMON_CONTENT_CLIENT_H_