Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / public / common / content_client.h
blob9b9cebac720c5ff42fb525d284523ce238dbc429
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 <set>
9 #include <string>
10 #include <vector>
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"
19 class GURL;
21 namespace base {
22 class RefCountedStaticMemory;
25 namespace IPC {
26 class Message;
29 namespace gfx {
30 class Image;
33 namespace gpu {
34 struct GPUInfo;
37 namespace sandbox {
38 class TargetPolicy;
41 namespace content {
43 class ContentBrowserClient;
44 class ContentClient;
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();
57 #endif
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 {
70 public:
71 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(
111 int resource_id,
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(
134 int sandbox_type,
135 int* sandbox_profile_resource_id) const;
136 #endif
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) {}
144 private:
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_