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"
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 // Interface that the embedder implements.
69 class CONTENT_EXPORT ContentClient
{
72 virtual ~ContentClient();
74 ContentBrowserClient
* browser() { return browser_
; }
75 ContentPluginClient
* plugin() { return plugin_
; }
76 ContentRendererClient
* renderer() { return renderer_
; }
77 ContentUtilityClient
* utility() { return utility_
; }
79 // Sets the currently active URL. Use GURL() to clear the URL.
80 virtual void SetActiveURL(const GURL
& url
) {}
82 // Sets the data on the current gpu.
83 virtual void SetGpuInfo(const gpu::GPUInfo
& gpu_info
) {}
85 // Gives the embedder a chance to register its own pepper plugins.
86 virtual void AddPepperPlugins(
87 std::vector
<content::PepperPluginInfo
>* plugins
) {}
89 // Gives the embedder a chance to register its own standard and saveable
90 // url schemes early on in the startup sequence.
91 virtual void AddAdditionalSchemes(
92 std::vector
<std::string
>* standard_schemes
,
93 std::vector
<std::string
>* savable_schemes
) {}
95 // Returns whether the given message should be sent in a swapped out renderer.
96 virtual bool CanSendWhileSwappedOut(const IPC::Message
* message
);
98 // Returns a string describing the embedder product name and version,
99 // of the form "productname/version", with no other slashes.
100 // Used as part of the user agent string.
101 virtual std::string
GetProduct() const;
103 // Returns the user agent.
104 virtual std::string
GetUserAgent() const;
106 // Returns a string resource given its id.
107 virtual base::string16
GetLocalizedString(int message_id
) const;
109 // Return the contents of a resource in a StringPiece given the resource id.
110 virtual base::StringPiece
GetDataResource(
112 ui::ScaleFactor scale_factor
) const;
114 // Returns the raw bytes of a scale independent data resource.
115 virtual base::RefCountedStaticMemory
* GetDataResourceBytes(
116 int resource_id
) const;
118 // Returns a native image given its id.
119 virtual gfx::Image
& GetNativeImageNamed(int resource_id
) const;
121 // Called by content::GetProcessTypeNameInEnglish for process types that it
122 // doesn't know about because they're from the embedder.
123 virtual std::string
GetProcessTypeNameInEnglish(int type
);
125 #if defined(OS_MACOSX) && !defined(OS_IOS)
126 // Allows the embedder to define a new |sandbox_type| by mapping it to the
127 // resource ID corresponding to the sandbox profile to use. The legal values
128 // for |sandbox_type| are defined by the embedder and should start with
129 // SandboxType::SANDBOX_TYPE_AFTER_LAST_TYPE. Returns false if no sandbox
130 // profile for the given |sandbox_type| exists. Otherwise,
131 // |sandbox_profile_resource_id| is set to the resource ID corresponding to
132 // the sandbox profile to use and true is returned.
133 virtual bool GetSandboxProfileForSandboxType(
135 int* sandbox_profile_resource_id
) const;
138 // Gives the embedder a chance to register additional schemes and origins
139 // that need to be considered trustworthy.
140 // See https://www.w3.org/TR/powerful-features/#is-origin-trustworthy.
141 virtual void AddSecureSchemesAndOrigins(std::set
<std::string
>* schemes
,
142 std::set
<GURL
>* origins
) {}
145 friend class ContentClientInitializer
; // To set these pointers.
146 friend class InternalTestInitializer
;
148 // The embedder API for participating in browser logic.
149 ContentBrowserClient
* browser_
;
150 // The embedder API for participating in plugin logic.
151 ContentPluginClient
* plugin_
;
152 // The embedder API for participating in renderer logic.
153 ContentRendererClient
* renderer_
;
154 // The embedder API for participating in utility logic.
155 ContentUtilityClient
* utility_
;
158 } // namespace content
160 #endif // CONTENT_PUBLIC_COMMON_CONTENT_CLIENT_H_