Removing uses of X11 native key events.
[chromium-blink-merge.git] / content / public / common / content_client.h
blob13f0d5c57dc0b986c9c016e7404b6c71a5345440
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_
8 #include <string>
9 #include <vector>
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"
18 class GURL;
20 namespace base {
21 class RefCountedStaticMemory;
24 namespace IPC {
25 class Message;
28 namespace gfx {
29 class Image;
32 namespace gpu {
33 struct GPUInfo;
36 namespace sandbox {
37 class TargetPolicy;
40 namespace content {
42 class ContentBrowserClient;
43 class ContentClient;
44 class ContentPluginClient;
45 class ContentRendererClient;
46 class ContentUtilityClient;
47 struct PepperPluginInfo;
49 // Setter and getter for the client. The client should be set early, before any
50 // content code is called.
51 CONTENT_EXPORT void SetContentClient(ContentClient* client);
53 #if defined(CONTENT_IMPLEMENTATION)
54 // Content's embedder API should only be used by content.
55 ContentClient* GetContentClient();
56 #endif
58 // Used for tests to override the relevant embedder interfaces. Each method
59 // returns the old value.
60 CONTENT_EXPORT ContentBrowserClient* SetBrowserClientForTesting(
61 ContentBrowserClient* b);
62 CONTENT_EXPORT ContentRendererClient* SetRendererClientForTesting(
63 ContentRendererClient* r);
64 CONTENT_EXPORT ContentUtilityClient* SetUtilityClientForTesting(
65 ContentUtilityClient* u);
67 // Interface that the embedder implements.
68 class CONTENT_EXPORT ContentClient {
69 public:
70 ContentClient();
71 virtual ~ContentClient();
73 ContentBrowserClient* browser() { return browser_; }
74 ContentPluginClient* plugin() { return plugin_; }
75 ContentRendererClient* renderer() { return renderer_; }
76 ContentUtilityClient* utility() { return utility_; }
78 // Sets the currently active URL. Use GURL() to clear the URL.
79 virtual void SetActiveURL(const GURL& url) {}
81 // Sets the data on the current gpu.
82 virtual void SetGpuInfo(const gpu::GPUInfo& gpu_info) {}
84 // Gives the embedder a chance to register its own pepper plugins.
85 virtual void AddPepperPlugins(
86 std::vector<content::PepperPluginInfo>* plugins) {}
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) {}
94 // Returns whether the given message should be sent in a swapped out renderer.
95 virtual bool CanSendWhileSwappedOut(const IPC::Message* message);
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;
102 // Returns the user agent.
103 virtual std::string GetUserAgent() const;
105 // Returns a string resource given its id.
106 virtual base::string16 GetLocalizedString(int message_id) const;
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;
113 // Returns the raw bytes of a scale independent data resource.
114 virtual base::RefCountedStaticMemory* GetDataResourceBytes(
115 int resource_id) const;
117 // Returns a native image given its id.
118 virtual gfx::Image& GetNativeImageNamed(int resource_id) const;
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);
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 #endif
137 private:
138 friend class ContentClientInitializer; // To set these pointers.
139 friend class InternalTestInitializer;
141 // The embedder API for participating in browser logic.
142 ContentBrowserClient* browser_;
143 // The embedder API for participating in plugin logic.
144 ContentPluginClient* plugin_;
145 // The embedder API for participating in renderer logic.
146 ContentRendererClient* renderer_;
147 // The embedder API for participating in utility logic.
148 ContentUtilityClient* utility_;
151 } // namespace content
153 #endif // CONTENT_PUBLIC_COMMON_CONTENT_CLIENT_H_