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