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