• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CONTENT_PUBLIC_COMMON_CONTENT_CLIENT_H_
6 #define CONTENT_PUBLIC_COMMON_CONTENT_CLIENT_H_
7 
8 #include <string>
9 #include <vector>
10 
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"
17 
18 class CommandLine;
19 class GURL;
20 
21 namespace base {
22 class RefCountedStaticMemory;
23 }
24 
25 namespace IPC {
26 class Message;
27 }
28 
29 namespace gfx {
30 class Image;
31 }
32 
33 namespace gpu {
34 struct GPUInfo;
35 }
36 
37 namespace sandbox {
38 class TargetPolicy;
39 }
40 
41 namespace content {
42 
43 class ContentBrowserClient;
44 class ContentClient;
45 class ContentPluginClient;
46 class ContentRendererClient;
47 class ContentUtilityClient;
48 struct PepperPluginInfo;
49 
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);
53 
54 #if defined(CONTENT_IMPLEMENTATION)
55 // Content's embedder API should only be used by content.
56 ContentClient* GetContentClient();
57 #endif
58 
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);
67 
68 // Returns the user agent string being used by the browser. SetContentClient()
69 // must be called prior to calling this, and this routine must be used
70 // instead of webkit_glue::GetUserAgent() in order to ensure that we use
71 // the same user agent string everywhere.
72 // TODO(dpranke): This is caused by webkit_glue being a library that can
73 // get linked into multiple linkable objects, causing us to have multiple
74 // static values of the user agent. This will be fixed when we clean up
75 // webkit_glue.
76 CONTENT_EXPORT const std::string& GetUserAgent(const GURL& url);
77 
78 // Interface that the embedder implements.
79 class CONTENT_EXPORT ContentClient {
80  public:
81   ContentClient();
82   virtual ~ContentClient();
83 
browser()84   ContentBrowserClient* browser() { return browser_; }
plugin()85   ContentPluginClient* plugin() { return plugin_; }
renderer()86   ContentRendererClient* renderer() { return renderer_; }
utility()87   ContentUtilityClient* utility() { return utility_; }
88 
89   // Sets the currently active URL.  Use GURL() to clear the URL.
SetActiveURL(const GURL & url)90   virtual void SetActiveURL(const GURL& url) {}
91 
92   // Sets the data on the current gpu.
SetGpuInfo(const gpu::GPUInfo & gpu_info)93   virtual void SetGpuInfo(const gpu::GPUInfo& gpu_info) {}
94 
95   // Gives the embedder a chance to register its own pepper plugins.
AddPepperPlugins(std::vector<content::PepperPluginInfo> * plugins)96   virtual void AddPepperPlugins(
97       std::vector<content::PepperPluginInfo>* plugins) {}
98 
99   // Gives the embedder a chance to register its own standard and saveable
100   // url schemes early on in the startup sequence.
AddAdditionalSchemes(std::vector<std::string> * standard_schemes,std::vector<std::string> * savable_schemes)101   virtual void AddAdditionalSchemes(
102       std::vector<std::string>* standard_schemes,
103       std::vector<std::string>* savable_schemes) {}
104 
105   // Returns whether the given message should be sent in a swapped out renderer.
106   virtual bool CanSendWhileSwappedOut(const IPC::Message* message);
107 
108   // Returns whether the given message should be processed in the browser on
109   // behalf of a swapped out renderer.
110   virtual bool CanHandleWhileSwappedOut(const IPC::Message& message);
111 
112   // Returns a string describing the embedder product name and version,
113   // of the form "productname/version", with no other slashes.
114   // Used as part of the user agent string.
115   virtual std::string GetProduct() const;
116 
117   // Returns the user agent.
118   virtual std::string GetUserAgent() const;
119 
120   // Returns a string resource given its id.
121   virtual base::string16 GetLocalizedString(int message_id) const;
122 
123   // Return the contents of a resource in a StringPiece given the resource id.
124   virtual base::StringPiece GetDataResource(
125       int resource_id,
126       ui::ScaleFactor scale_factor) const;
127 
128   // Returns the raw bytes of a scale independent data resource.
129   virtual base::RefCountedStaticMemory* GetDataResourceBytes(
130       int resource_id) const;
131 
132   // Returns a native image given its id.
133   virtual gfx::Image& GetNativeImageNamed(int resource_id) const;
134 
135   // Called by content::GetProcessTypeNameInEnglish for process types that it
136   // doesn't know about because they're from the embedder.
137   virtual std::string GetProcessTypeNameInEnglish(int type);
138 
139 #if defined(OS_MACOSX) && !defined(OS_IOS)
140   // Allows the embedder to define a new |sandbox_type| by mapping it to the
141   // resource ID corresponding to the sandbox profile to use. The legal values
142   // for |sandbox_type| are defined by the embedder and should start with
143   // SandboxType::SANDBOX_TYPE_AFTER_LAST_TYPE. Returns false if no sandbox
144   // profile for the given |sandbox_type| exists. Otherwise,
145   // |sandbox_profile_resource_id| is set to the resource ID corresponding to
146   // the sandbox profile to use and true is returned.
147   virtual bool GetSandboxProfileForSandboxType(
148       int sandbox_type,
149       int* sandbox_profile_resource_id) const;
150 
151   // Gets the Carbon interposing path to give to DYLD. Returns an empty string
152   // if the embedder doesn't bundle it.
153   virtual std::string GetCarbonInterposePath() const;
154 #endif
155 
156  private:
157   friend class ContentClientInitializer;  // To set these pointers.
158   friend class InternalTestInitializer;
159 
160   // The embedder API for participating in browser logic.
161   ContentBrowserClient* browser_;
162   // The embedder API for participating in plugin logic.
163   ContentPluginClient* plugin_;
164   // The embedder API for participating in renderer logic.
165   ContentRendererClient* renderer_;
166   // The embedder API for participating in utility logic.
167   ContentUtilityClient* utility_;
168 };
169 
170 }  // namespace content
171 
172 #endif  // CONTENT_PUBLIC_COMMON_CONTENT_CLIENT_H_
173