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