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.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_MESSAGE_FILTER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_MESSAGE_FILTER_H_
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"
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"
41 #if defined(OS_ANDROID)
42 #include "base/threading/worker_pool.h"
45 #if defined(ENABLE_PLUGINS)
46 #include "content/common/pepper_renderer_instance_data.h"
49 struct FontDescriptor;
50 struct FrameHostMsg_AddNavigationTransitionData_Params;
51 struct ViewHostMsg_CreateWindow_Params;
64 struct GpuMemoryBufferHandle;
75 class URLRequestContext;
76 class URLRequestContextGetter;
81 class DOMStorageContextWrapper;
83 class PluginServiceImpl;
84 class RenderWidgetHelper;
85 class ResourceContext;
86 class ResourceDispatcherHostImpl;
90 // This class filters out incoming IPC messages for the renderer process on the
92 class CONTENT_EXPORT RenderMessageFilter : public BrowserMessageFilter {
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);
104 // IPC::MessageFilter methods:
105 void OnChannelClosing() override;
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;
113 bool OffTheRecord() const;
115 int render_process_id() const { return render_process_id_; }
117 // Returns the correct net::CookieStore depending on what type of url is
119 // Only call on the IO thread.
120 net::CookieStore* GetCookieStoreForURL(const GURL& url);
123 ~RenderMessageFilter() override;
125 // This method will be overridden by TestSaveImageFromDataURL class for test.
126 virtual void DownloadUrl(int render_view_id,
128 const Referrer& referrer,
129 const base::string16& suggested_name,
130 const bool use_prompt) const;
133 friend class BrowserThread;
134 friend class base::DeleteHelper<RenderMessageFilter>;
136 class OpenChannelToNpapiPluginCallback;
138 void OnGetProcessMemorySizes(size_t* private_bytes, size_t* shared_bytes);
139 void OnCreateWindow(const ViewHostMsg_CreateWindow_Params& params,
141 int* main_frame_route_id,
143 int64* cloned_session_storage_namespace_id);
144 void OnCreateWidget(int opener_id,
145 blink::WebPopupType popup_type,
148 void OnCreateFullscreenWidget(int opener_id,
151 void OnSetCookie(int render_frame_id,
153 const GURL& first_party_for_cookies,
154 const std::string& cookie);
155 void OnGetCookies(int render_frame_id,
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,
166 const GURL& first_party_for_cookies,
167 bool* cookies_enabled);
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);
176 void OnPreCacheFontCharacters(const LOGFONT& log_font,
177 const base::string16& characters);
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,
186 const GURL& policy_url,
187 const std::string& mime_type,
190 std::string* actual_mime_type);
191 void OnOpenChannelToPlugin(int render_frame_id,
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(
201 PepperRendererInstanceData instance_data,
203 void OnDidDeleteOutOfProcessPepperInstance(int plugin_child_id,
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,
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);
218 void OnGetAudioHardwareConfig(media::AudioParameters* input_params,
219 media::AudioParameters* output_params);
222 // Used to look up the monitor color profile.
223 void OnGetMonitorColorProfile(std::vector<char>* profile);
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);
243 // Browser side discardable shared memory allocation.
244 void OnAllocateLockedDiscardableSharedMemory(
246 base::SharedMemoryHandle* handle);
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>&);
264 // Check the policy for getting cookies. Gets the cookies if allowed.
265 void CheckPolicyForCookies(int render_frame_id,
267 const GURL& first_party_for_cookies,
268 IPC::Message* reply_msg,
269 const net::CookieList& cookie_list);
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);
278 bool CheckBenchmarkingEnabled() const;
279 bool CheckPreparsedJsCachingEnabled() const;
280 void OnCompletedOpenChannelToNpapiPlugin(
281 OpenChannelToNpapiPluginCallback* client);
283 void OnAre3DAPIsBlocked(int render_view_id,
284 const GURL& top_origin_url,
285 ThreeDAPIType requester,
287 void OnDidLose3DContext(const GURL& top_origin_url,
288 ThreeDAPIType context_type,
289 int arb_robustness_status_code);
291 #if defined(OS_ANDROID)
292 void OnWebAudioMediaCodec(base::SharedMemoryHandle encoded_data_handle,
293 base::FileDescriptor pcm_output,
297 void OnAddNavigationTransitionData(
298 FrameHostMsg_AddNavigationTransitionData_Params params);
300 void OnAllocateGpuMemoryBuffer(uint32 width,
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,
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_;
317 // Contextual information to be used for requests created here.
318 scoped_refptr<net::URLRequestContextGetter> request_context_;
320 // The ResourceContext which is to be used on the IO thread.
321 ResourceContext* resource_context_;
323 scoped_refptr<RenderWidgetHelper> render_widget_helper_;
325 // Whether this process is used for incognito contents.
326 // This doesn't belong here; http://crbug.com/89628
329 // Initialized to 0, accessed on FILE thread only.
330 base::TimeTicks last_plugin_refresh_time_;
332 scoped_refptr<DOMStorageContextWrapper> dom_storage_context_;
334 int render_process_id_;
336 std::set<OpenChannelToNpapiPluginCallback*> plugin_host_clients_;
338 media::AudioManager* audio_manager_;
339 MediaInternals* media_internals_;
341 DISALLOW_COPY_AND_ASSIGN(RenderMessageFilter);
344 } // namespace content
346 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_MESSAGE_FILTER_H_