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