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/string16.h"
13 #include "base/string_piece.h"
14 #include "build/build_config.h"
15 #include "content/common/content_export.h"
16 #include "ui/base/layout.h"
45 class ContentBrowserClient
;
47 class ContentPluginClient
;
48 class ContentRendererClient
;
49 class ContentUtilityClient
;
51 struct PepperPluginInfo
;
53 // Setter and getter for the client. The client should be set early, before any
54 // content code is called.
55 CONTENT_EXPORT
void SetContentClient(ContentClient
* client
);
56 CONTENT_EXPORT ContentClient
* GetContentClient();
58 // Returns the user agent string being used by the browser. SetContentClient()
59 // must be called prior to calling this, and this routine must be used
60 // instead of webkit_glue::GetUserAgent() in order to ensure that we use
61 // the same user agent string everywhere.
62 // TODO(dpranke): This is caused by webkit_glue being a library that can
63 // get linked into multiple linkable objects, causing us to have multiple
64 // static values of the user agent. This will be fixed when we clean up
66 CONTENT_EXPORT
const std::string
& GetUserAgent(const GURL
& url
);
68 // Returns the PPAPI global singleton. See webkit/plugins/ppapi/host_globals.h
69 // TODO(dpranke): Also needed since webkit_glue is a library.
70 CONTENT_EXPORT
webkit::ppapi::HostGlobals
* GetHostGlobals();
72 // Interface that the embedder implements.
73 class CONTENT_EXPORT ContentClient
{
76 virtual ~ContentClient();
78 ContentBrowserClient
* browser() { return browser_
; }
79 ContentPluginClient
* plugin() { return plugin_
; }
80 ContentRendererClient
* renderer() { return renderer_
; }
81 ContentUtilityClient
* utility() { return utility_
; }
83 // Sets the currently active URL. Use GURL() to clear the URL.
84 virtual void SetActiveURL(const GURL
& url
) {}
86 // Sets the data on the current gpu.
87 virtual void SetGpuInfo(const content::GPUInfo
& gpu_info
) {}
89 // Gives the embedder a chance to register its own pepper plugins.
90 virtual void AddPepperPlugins(
91 std::vector
<content::PepperPluginInfo
>* plugins
) {}
93 // Gives the embedder a chance to register its own internal NPAPI plugins.
94 virtual void AddNPAPIPlugins(
95 webkit::npapi::PluginList
* plugin_list
) {}
97 // Gives the embedder a chance to register its own standard and saveable
98 // url schemes early on in the startup sequence.
99 virtual void AddAdditionalSchemes(
100 std::vector
<std::string
>* standard_schemes
,
101 std::vector
<std::string
>* savable_schemes
) {}
103 // Returns true if the url has a scheme for WebUI. See also
104 // WebUIControllerFactory::UseWebUIForURL in the browser process.
105 virtual bool HasWebUIScheme(const GURL
& url
) const;
107 // Returns whether the given message should be processed in the browser on
108 // behalf of a swapped out renderer.
109 virtual bool CanHandleWhileSwappedOut(const IPC::Message
& message
);
111 // Returns a string describing the embedder version. Used as part of the
112 // user agent string.
113 virtual std::string
GetProduct() const;
115 // Returns the user agent.
116 virtual std::string
GetUserAgent() const;
118 // Returns a string resource given its id.
119 virtual string16
GetLocalizedString(int message_id
) const;
121 // Return the contents of a resource in a StringPiece given the resource id.
122 virtual base::StringPiece
GetDataResource(
124 ui::ScaleFactor scale_factor
) const;
126 // Returns a native image given its id.
127 virtual gfx::Image
& GetNativeImageNamed(int resource_id
) const;
130 // Allows the embedder to sandbox a plugin, and apply a custom policy.
131 virtual bool SandboxPlugin(CommandLine
* command_line
,
132 sandbox::TargetPolicy
* policy
);
135 #if defined(OS_MACOSX) && !defined(OS_IOS)
136 // Allows the embedder to define a new |sandbox_type| by mapping it to the
137 // resource ID corresponding to the sandbox profile to use. The legal values
138 // for |sandbox_type| are defined by the embedder and should start with
139 // SandboxType::SANDBOX_TYPE_AFTER_LAST_TYPE. Returns false if no sandbox
140 // profile for the given |sandbox_type| exists. Otherwise,
141 // |sandbox_profile_resource_id| is set to the resource ID corresponding to
142 // the sandbox profile to use and true is returned.
143 virtual bool GetSandboxProfileForSandboxType(
145 int* sandbox_profile_resource_id
) const;
147 // Gets the Carbon interposing path to give to DYLD. Returns an empty string
148 // if the embedder doesn't bundle it.
149 virtual std::string
GetCarbonInterposePath() const;
152 void set_browser_for_testing(ContentBrowserClient
* c
) { browser_
= c
; }
153 void set_renderer_for_testing(ContentRendererClient
* r
) { renderer_
= r
; }
156 friend class ContentClientInitializer
; // To set these pointers.
158 // The embedder API for participating in browser logic.
159 ContentBrowserClient
* browser_
;
160 // The embedder API for participating in plugin logic.
161 ContentPluginClient
* plugin_
;
162 // The embedder API for participating in renderer logic.
163 ContentRendererClient
* renderer_
;
164 // The embedder API for participating in utility logic.
165 ContentUtilityClient
* utility_
;
168 } // namespace content
170 #endif // CONTENT_PUBLIC_COMMON_CONTENT_CLIENT_H_