Home | History | Annotate | Download | only in renderer_host
      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_BROWSER_RENDERER_HOST_RENDER_MESSAGE_FILTER_H_
      6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_MESSAGE_FILTER_H_
      7 
      8 #if defined(OS_WIN)
      9 #include <windows.h>
     10 #endif
     11 
     12 #include <set>
     13 #include <string>
     14 #include <vector>
     15 
     16 #include "base/files/file_path.h"
     17 #include "base/memory/linked_ptr.h"
     18 #include "base/memory/shared_memory.h"
     19 #include "base/sequenced_task_runner_helpers.h"
     20 #include "base/strings/string16.h"
     21 #include "build/build_config.h"
     22 #include "cc/resources/shared_bitmap_manager.h"
     23 #include "content/common/pepper_renderer_instance_data.h"
     24 #include "content/public/browser/browser_message_filter.h"
     25 #include "content/public/common/three_d_api_types.h"
     26 #include "ipc/message_filter.h"
     27 #include "media/audio/audio_parameters.h"
     28 #include "media/base/channel_layout.h"
     29 #include "net/cookies/canonical_cookie.h"
     30 #include "third_party/WebKit/public/web/WebPopupType.h"
     31 #include "ui/gfx/native_widget_types.h"
     32 #include "ui/surface/transport_dib.h"
     33 
     34 #if defined(OS_MACOSX)
     35 #include "content/common/mac/font_loader.h"
     36 #endif
     37 
     38 #if defined(OS_ANDROID)
     39 #include "base/threading/worker_pool.h"
     40 #endif
     41 
     42 struct FontDescriptor;
     43 struct ViewHostMsg_CreateWindow_Params;
     44 
     45 namespace blink {
     46 struct WebScreenInfo;
     47 }
     48 
     49 namespace base {
     50 class ProcessMetrics;
     51 class SharedMemory;
     52 class TaskRunner;
     53 }
     54 
     55 namespace media {
     56 class AudioManager;
     57 struct MediaLogEvent;
     58 }
     59 
     60 namespace net {
     61 class CookieStore;
     62 class KeygenHandler;
     63 class URLRequestContext;
     64 class URLRequestContextGetter;
     65 }
     66 
     67 namespace content {
     68 class BrowserContext;
     69 class DOMStorageContextWrapper;
     70 class MediaInternals;
     71 class PluginServiceImpl;
     72 class RenderWidgetHelper;
     73 class ResourceContext;
     74 class ResourceDispatcherHostImpl;
     75 struct Referrer;
     76 struct WebPluginInfo;
     77 
     78 // This class filters out incoming IPC messages for the renderer process on the
     79 // IPC thread.
     80 class RenderMessageFilter : public BrowserMessageFilter {
     81  public:
     82   // Create the filter.
     83   RenderMessageFilter(int render_process_id,
     84                       PluginServiceImpl * plugin_service,
     85                       BrowserContext* browser_context,
     86                       net::URLRequestContextGetter* request_context,
     87                       RenderWidgetHelper* render_widget_helper,
     88                       media::AudioManager* audio_manager,
     89                       MediaInternals* media_internals,
     90                       DOMStorageContextWrapper* dom_storage_context);
     91 
     92   // IPC::MessageFilter methods:
     93   virtual void OnChannelClosing() OVERRIDE;
     94   virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
     95 
     96   // BrowserMessageFilter methods:
     97   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
     98   virtual void OnDestruct() const OVERRIDE;
     99   virtual base::TaskRunner* OverrideTaskRunnerForMessage(
    100       const IPC::Message& message) OVERRIDE;
    101 
    102   bool OffTheRecord() const;
    103 
    104   int render_process_id() const { return render_process_id_; }
    105 
    106   // Returns the correct net::CookieStore depending on what type of url is
    107   // given.
    108   // Only call on the IO thread.
    109   net::CookieStore* GetCookieStoreForURL(const GURL& url);
    110 
    111  private:
    112   friend class BrowserThread;
    113   friend class base::DeleteHelper<RenderMessageFilter>;
    114 
    115   class OpenChannelToNpapiPluginCallback;
    116 
    117   virtual ~RenderMessageFilter();
    118 
    119   void OnGetProcessMemorySizes(size_t* private_bytes, size_t* shared_bytes);
    120   void OnCreateWindow(const ViewHostMsg_CreateWindow_Params& params,
    121                       int* route_id,
    122                       int* main_frame_route_id,
    123                       int* surface_id,
    124                       int64* cloned_session_storage_namespace_id);
    125   void OnCreateWidget(int opener_id,
    126                       blink::WebPopupType popup_type,
    127                       int* route_id,
    128                       int* surface_id);
    129   void OnCreateFullscreenWidget(int opener_id,
    130                                 int* route_id,
    131                                 int* surface_id);
    132   void OnSetCookie(int render_frame_id,
    133                    const GURL& url,
    134                    const GURL& first_party_for_cookies,
    135                    const std::string& cookie);
    136   void OnGetCookies(int render_frame_id,
    137                     const GURL& url,
    138                     const GURL& first_party_for_cookies,
    139                     IPC::Message* reply_msg);
    140   void OnGetRawCookies(const GURL& url,
    141                        const GURL& first_party_for_cookies,
    142                        IPC::Message* reply_msg);
    143   void OnDeleteCookie(const GURL& url,
    144                       const std::string& cookieName);
    145   void OnCookiesEnabled(int render_frame_id,
    146                         const GURL& url,
    147                         const GURL& first_party_for_cookies,
    148                         bool* cookies_enabled);
    149 
    150 #if defined(OS_MACOSX)
    151   // Messages for OOP font loading.
    152   void OnLoadFont(const FontDescriptor& font, IPC::Message* reply_msg);
    153   void SendLoadFontReply(IPC::Message* reply, FontLoader::Result* result);
    154 #endif
    155 
    156 #if defined(OS_WIN)
    157   void OnPreCacheFontCharacters(const LOGFONT& log_font,
    158                                 const base::string16& characters);
    159 #endif
    160 
    161   void OnGetPlugins(bool refresh, IPC::Message* reply_msg);
    162   void GetPluginsCallback(IPC::Message* reply_msg,
    163                           const std::vector<WebPluginInfo>& plugins);
    164   void OnGetPluginInfo(int render_frame_id,
    165                        const GURL& url,
    166                        const GURL& policy_url,
    167                        const std::string& mime_type,
    168                        bool* found,
    169                        WebPluginInfo* info,
    170                        std::string* actual_mime_type);
    171   void OnOpenChannelToPlugin(int render_frame_id,
    172                              const GURL& url,
    173                              const GURL& policy_url,
    174                              const std::string& mime_type,
    175                              IPC::Message* reply_msg);
    176   void OnOpenChannelToPepperPlugin(const base::FilePath& path,
    177                                    IPC::Message* reply_msg);
    178   void OnDidCreateOutOfProcessPepperInstance(
    179       int plugin_child_id,
    180       int32 pp_instance,
    181       PepperRendererInstanceData instance_data,
    182       bool is_external);
    183   void OnDidDeleteOutOfProcessPepperInstance(int plugin_child_id,
    184                                              int32 pp_instance,
    185                                              bool is_external);
    186   void OnOpenChannelToPpapiBroker(int routing_id,
    187                                   const base::FilePath& path);
    188   void OnGenerateRoutingID(int* route_id);
    189   void OnDownloadUrl(int render_view_id,
    190                      const GURL& url,
    191                      const Referrer& referrer,
    192                      const base::string16& suggested_name,
    193                      const bool use_prompt);
    194   void OnCheckNotificationPermission(const GURL& source_origin,
    195                                      int* permission_level);
    196 
    197   void OnGetCPUUsage(int* cpu_usage);
    198 
    199   void OnGetAudioHardwareConfig(media::AudioParameters* input_params,
    200                                 media::AudioParameters* output_params);
    201 
    202 #if defined(OS_WIN)
    203   // Used to look up the monitor color profile.
    204   void OnGetMonitorColorProfile(std::vector<char>* profile);
    205 #endif
    206 
    207   // Used to ask the browser to allocate a block of shared memory for the
    208   // renderer to send back data in, since shared memory can't be created
    209   // in the renderer on POSIX due to the sandbox.
    210   void OnAllocateSharedMemory(uint32 buffer_size,
    211                               base::SharedMemoryHandle* handle);
    212   void AllocateSharedBitmapOnFileThread(uint32 buffer_size,
    213                                         const cc::SharedBitmapId& id,
    214                                         IPC::Message* reply_msg);
    215   void OnAllocateSharedBitmap(uint32 buffer_size,
    216                               const cc::SharedBitmapId& id,
    217                               IPC::Message* reply_msg);
    218   void OnAllocatedSharedBitmap(size_t buffer_size,
    219                                const base::SharedMemoryHandle& handle,
    220                                const cc::SharedBitmapId& id);
    221   void OnDeletedSharedBitmap(const cc::SharedBitmapId& id);
    222   void OnResolveProxy(const GURL& url, IPC::Message* reply_msg);
    223 
    224   // Browser side transport DIB allocation
    225   void OnAllocTransportDIB(uint32 size,
    226                            bool cache_in_browser,
    227                            TransportDIB::Handle* result);
    228   void OnFreeTransportDIB(TransportDIB::Id dib_id);
    229   void OnCacheableMetadataAvailable(const GURL& url,
    230                                     double expected_response_time,
    231                                     const std::vector<char>& data);
    232   void OnKeygen(uint32 key_size_index, const std::string& challenge_string,
    233                 const GURL& url, IPC::Message* reply_msg);
    234   void PostKeygenToWorkerThread(IPC::Message* reply_msg,
    235                                 scoped_ptr<net::KeygenHandler> keygen_handler);
    236   void OnKeygenOnWorkerThread(scoped_ptr<net::KeygenHandler> keygen_handler,
    237                               IPC::Message* reply_msg);
    238   void OnMediaLogEvents(const std::vector<media::MediaLogEvent>&);
    239 
    240   // Check the policy for getting cookies. Gets the cookies if allowed.
    241   void CheckPolicyForCookies(int render_frame_id,
    242                              const GURL& url,
    243                              const GURL& first_party_for_cookies,
    244                              IPC::Message* reply_msg,
    245                              const net::CookieList& cookie_list);
    246 
    247   // Writes the cookies to reply messages, and sends the message.
    248   // Callback functions for getting cookies from cookie store.
    249   void SendGetCookiesResponse(IPC::Message* reply_msg,
    250                               const std::string& cookies);
    251   void SendGetRawCookiesResponse(IPC::Message* reply_msg,
    252                                  const net::CookieList& cookie_list);
    253 
    254   bool CheckBenchmarkingEnabled() const;
    255   bool CheckPreparsedJsCachingEnabled() const;
    256   void OnCompletedOpenChannelToNpapiPlugin(
    257       OpenChannelToNpapiPluginCallback* client);
    258 
    259   void OnAre3DAPIsBlocked(int render_view_id,
    260                           const GURL& top_origin_url,
    261                           ThreeDAPIType requester,
    262                           bool* blocked);
    263   void OnDidLose3DContext(const GURL& top_origin_url,
    264                           ThreeDAPIType context_type,
    265                           int arb_robustness_status_code);
    266 
    267 #if defined(OS_ANDROID)
    268   void OnWebAudioMediaCodec(base::SharedMemoryHandle encoded_data_handle,
    269                             base::FileDescriptor pcm_output,
    270                             uint32_t data_size);
    271 #endif
    272 
    273   // Cached resource request dispatcher host and plugin service, guaranteed to
    274   // be non-null if Init succeeds. We do not own the objects, they are managed
    275   // by the BrowserProcess, which has a wider scope than we do.
    276   ResourceDispatcherHostImpl* resource_dispatcher_host_;
    277   PluginServiceImpl* plugin_service_;
    278   base::FilePath profile_data_directory_;
    279 
    280   // Contextual information to be used for requests created here.
    281   scoped_refptr<net::URLRequestContextGetter> request_context_;
    282 
    283   // The ResourceContext which is to be used on the IO thread.
    284   ResourceContext* resource_context_;
    285 
    286   scoped_refptr<RenderWidgetHelper> render_widget_helper_;
    287 
    288   // Whether this process is used for incognito contents.
    289   // This doesn't belong here; http://crbug.com/89628
    290   bool incognito_;
    291 
    292   // Initialized to 0, accessed on FILE thread only.
    293   base::TimeTicks last_plugin_refresh_time_;
    294 
    295   scoped_refptr<DOMStorageContextWrapper> dom_storage_context_;
    296 
    297   int render_process_id_;
    298 
    299   std::set<OpenChannelToNpapiPluginCallback*> plugin_host_clients_;
    300 
    301   // Records the last time we sampled CPU usage of the renderer process.
    302   base::TimeTicks cpu_usage_sample_time_;
    303   // Records the last sampled CPU usage in percents.
    304   int cpu_usage_;
    305   // Used for sampling CPU usage of the renderer process.
    306   scoped_ptr<base::ProcessMetrics> process_metrics_;
    307 
    308   media::AudioManager* audio_manager_;
    309   MediaInternals* media_internals_;
    310 
    311   DISALLOW_COPY_AND_ASSIGN(RenderMessageFilter);
    312 };
    313 
    314 }  // namespace content
    315 
    316 #endif  // CONTENT_BROWSER_RENDERER_HOST_RENDER_MESSAGE_FILTER_H_
    317