Home | History | Annotate | Download | only in common
      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 GURL;
     19 
     20 namespace base {
     21 class RefCountedStaticMemory;
     22 }
     23 
     24 namespace IPC {
     25 class Message;
     26 }
     27 
     28 namespace gfx {
     29 class Image;
     30 }
     31 
     32 namespace gpu {
     33 struct GPUInfo;
     34 }
     35 
     36 namespace sandbox {
     37 class TargetPolicy;
     38 }
     39 
     40 namespace content {
     41 
     42 class ContentBrowserClient;
     43 class ContentClient;
     44 class ContentPluginClient;
     45 class ContentRendererClient;
     46 class ContentUtilityClient;
     47 struct PepperPluginInfo;
     48 
     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);
     52 
     53 #if defined(CONTENT_IMPLEMENTATION)
     54 // Content's embedder API should only be used by content.
     55 ContentClient* GetContentClient();
     56 #endif
     57 
     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);
     66 
     67 // Interface that the embedder implements.
     68 class CONTENT_EXPORT ContentClient {
     69  public:
     70   ContentClient();
     71   virtual ~ContentClient();
     72 
     73   ContentBrowserClient* browser() { return browser_; }
     74   ContentPluginClient* plugin() { return plugin_; }
     75   ContentRendererClient* renderer() { return renderer_; }
     76   ContentUtilityClient* utility() { return utility_; }
     77 
     78   // Sets the currently active URL.  Use GURL() to clear the URL.
     79   virtual void SetActiveURL(const GURL& url) {}
     80 
     81   // Sets the data on the current gpu.
     82   virtual void SetGpuInfo(const gpu::GPUInfo& gpu_info) {}
     83 
     84   // Gives the embedder a chance to register its own pepper plugins.
     85   virtual void AddPepperPlugins(
     86       std::vector<content::PepperPluginInfo>* plugins) {}
     87 
     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) {}
     93 
     94   // Returns whether the given message should be sent in a swapped out renderer.
     95   virtual bool CanSendWhileSwappedOut(const IPC::Message* message);
     96 
     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;
    101 
    102   // Returns the user agent.
    103   virtual std::string GetUserAgent() const;
    104 
    105   // Returns a string resource given its id.
    106   virtual base::string16 GetLocalizedString(int message_id) const;
    107 
    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;
    112 
    113   // Returns the raw bytes of a scale independent data resource.
    114   virtual base::RefCountedStaticMemory* GetDataResourceBytes(
    115       int resource_id) const;
    116 
    117   // Returns a native image given its id.
    118   virtual gfx::Image& GetNativeImageNamed(int resource_id) const;
    119 
    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);
    123 
    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
    136 
    137  private:
    138   friend class ContentClientInitializer;  // To set these pointers.
    139   friend class InternalTestInitializer;
    140 
    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_;
    149 };
    150 
    151 }  // namespace content
    152 
    153 #endif  // CONTENT_PUBLIC_COMMON_CONTENT_CLIENT_H_
    154