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_
12 #include "base/basictypes.h"
13 #include "base/strings/string16.h"
14 #include "base/strings/string_piece.h"
15 #include "build/build_config.h"
16 #include "content/common/content_export.h"
17 #include "ui/base/layout.h"
18 #include "url/url_util.h"
23 class RefCountedStaticMemory
;
44 class ContentBrowserClient
;
46 class ContentPluginClient
;
47 class ContentRendererClient
;
48 class ContentUtilityClient
;
49 struct PepperPluginInfo
;
51 // Setter and getter for the client. The client should be set early, before any
52 // content code is called.
53 CONTENT_EXPORT
void SetContentClient(ContentClient
* client
);
55 #if defined(CONTENT_IMPLEMENTATION)
56 // Content's embedder API should only be used by content.
57 ContentClient
* GetContentClient();
60 // Used for tests to override the relevant embedder interfaces. Each method
61 // returns the old value.
62 CONTENT_EXPORT ContentBrowserClient
* SetBrowserClientForTesting(
63 ContentBrowserClient
* b
);
64 CONTENT_EXPORT ContentRendererClient
* SetRendererClientForTesting(
65 ContentRendererClient
* r
);
66 CONTENT_EXPORT ContentUtilityClient
* SetUtilityClientForTesting(
67 ContentUtilityClient
* u
);
69 // Interface that the embedder implements.
70 class CONTENT_EXPORT ContentClient
{
73 virtual ~ContentClient();
75 ContentBrowserClient
* browser() { return browser_
; }
76 ContentPluginClient
* plugin() { return plugin_
; }
77 ContentRendererClient
* renderer() { return renderer_
; }
78 ContentUtilityClient
* utility() { return utility_
; }
80 // Sets the currently active URL. Use GURL() to clear the URL.
81 virtual void SetActiveURL(const GURL
& url
) {}
83 // Sets the data on the current gpu.
84 virtual void SetGpuInfo(const gpu::GPUInfo
& gpu_info
) {}
86 // Gives the embedder a chance to register its own pepper plugins.
87 virtual void AddPepperPlugins(
88 std::vector
<content::PepperPluginInfo
>* plugins
) {}
90 // Gives the embedder a chance to register its own standard and saveable
91 // url schemes early on in the startup sequence.
92 virtual void AddAdditionalSchemes(
93 std::vector
<url::SchemeWithType
>* standard_schemes
,
94 std::vector
<std::string
>* savable_schemes
) {}
96 // Returns whether the given message should be sent in a swapped out renderer.
97 virtual bool CanSendWhileSwappedOut(const IPC::Message
* message
);
99 // Returns a string describing the embedder product name and version,
100 // of the form "productname/version", with no other slashes.
101 // Used as part of the user agent string.
102 virtual std::string
GetProduct() const;
104 // Returns the user agent.
105 virtual std::string
GetUserAgent() const;
107 // Returns a string resource given its id.
108 virtual base::string16
GetLocalizedString(int message_id
) const;
110 // Return the contents of a resource in a StringPiece given the resource id.
111 virtual base::StringPiece
GetDataResource(
113 ui::ScaleFactor scale_factor
) const;
115 // Returns the raw bytes of a scale independent data resource.
116 virtual base::RefCountedStaticMemory
* GetDataResourceBytes(
117 int resource_id
) const;
119 // Returns a native image given its id.
120 virtual gfx::Image
& GetNativeImageNamed(int resource_id
) const;
122 // Called by content::GetProcessTypeNameInEnglish for process types that it
123 // doesn't know about because they're from the embedder.
124 virtual std::string
GetProcessTypeNameInEnglish(int type
);
126 #if defined(OS_MACOSX) && !defined(OS_IOS)
127 // Allows the embedder to define a new |sandbox_type| by mapping it to the
128 // resource ID corresponding to the sandbox profile to use. The legal values
129 // for |sandbox_type| are defined by the embedder and should start with
130 // SandboxType::SANDBOX_TYPE_AFTER_LAST_TYPE. Returns false if no sandbox
131 // profile for the given |sandbox_type| exists. Otherwise,
132 // |sandbox_profile_resource_id| is set to the resource ID corresponding to
133 // the sandbox profile to use and true is returned.
134 virtual bool GetSandboxProfileForSandboxType(
136 int* sandbox_profile_resource_id
) const;
139 // Gives the embedder a chance to register additional schemes and origins
140 // that need to be considered trustworthy.
141 // See https://www.w3.org/TR/powerful-features/#is-origin-trustworthy.
142 virtual void AddSecureSchemesAndOrigins(std::set
<std::string
>* schemes
,
143 std::set
<GURL
>* origins
) {}
145 // Gives the embedder a chance to register additional schemes that
146 // should be allowed to register service workers. Only secure and
147 // trustworthy schemes should be added.
148 virtual void AddServiceWorkerSchemes(std::set
<std::string
>* schemes
) {}
151 friend class ContentClientInitializer
; // To set these pointers.
152 friend class InternalTestInitializer
;
154 // The embedder API for participating in browser logic.
155 ContentBrowserClient
* browser_
;
156 // The embedder API for participating in plugin logic.
157 ContentPluginClient
* plugin_
;
158 // The embedder API for participating in renderer logic.
159 ContentRendererClient
* renderer_
;
160 // The embedder API for participating in utility logic.
161 ContentUtilityClient
* utility_
;
164 } // namespace content
166 #endif // CONTENT_PUBLIC_COMMON_CONTENT_CLIENT_H_