Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: content/browser/frame_host/render_frame_message_filter.cc

Issue 2167513003: Moves FrameHostMsg_SetCookie to a Mojo message (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@browser-associated-interface
Patch Set: . Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/frame_host/render_frame_message_filter.h" 5 #include "content/browser/frame_host/render_frame_message_filter.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 205
206 #endif // ENABLE_PLUGINS 206 #endif // ENABLE_PLUGINS
207 207
208 RenderFrameMessageFilter::RenderFrameMessageFilter( 208 RenderFrameMessageFilter::RenderFrameMessageFilter(
209 int render_process_id, 209 int render_process_id,
210 PluginServiceImpl* plugin_service, 210 PluginServiceImpl* plugin_service,
211 BrowserContext* browser_context, 211 BrowserContext* browser_context,
212 net::URLRequestContextGetter* request_context, 212 net::URLRequestContextGetter* request_context,
213 RenderWidgetHelper* render_widget_helper) 213 RenderWidgetHelper* render_widget_helper)
214 : BrowserMessageFilter(FrameMsgStart), 214 : BrowserMessageFilter(FrameMsgStart),
215 BrowserAssociatedInterface<mojom::RenderFrameMessageFilter>(this, this),
215 #if defined(ENABLE_PLUGINS) 216 #if defined(ENABLE_PLUGINS)
216 plugin_service_(plugin_service), 217 plugin_service_(plugin_service),
217 profile_data_directory_(browser_context->GetPath()), 218 profile_data_directory_(browser_context->GetPath()),
218 #endif // ENABLE_PLUGINS 219 #endif // ENABLE_PLUGINS
219 request_context_(request_context), 220 request_context_(request_context),
220 resource_context_(browser_context->GetResourceContext()), 221 resource_context_(browser_context->GetResourceContext()),
221 render_widget_helper_(render_widget_helper), 222 render_widget_helper_(render_widget_helper),
222 incognito_(browser_context->IsOffTheRecord()), 223 incognito_(browser_context->IsOffTheRecord()),
223 render_process_id_(render_process_id) { 224 render_process_id_(render_process_id) {
224 } 225 }
225 226
226 RenderFrameMessageFilter::~RenderFrameMessageFilter() { 227 RenderFrameMessageFilter::~RenderFrameMessageFilter() {
227 // This function should be called on the IO thread. 228 // This function should be called on the IO thread.
228 DCHECK_CURRENTLY_ON(BrowserThread::IO); 229 DCHECK_CURRENTLY_ON(BrowserThread::IO);
229 } 230 }
230 231
231 bool RenderFrameMessageFilter::OnMessageReceived(const IPC::Message& message) { 232 bool RenderFrameMessageFilter::OnMessageReceived(const IPC::Message& message) {
232 bool handled = true; 233 bool handled = true;
233 IPC_BEGIN_MESSAGE_MAP(RenderFrameMessageFilter, message) 234 IPC_BEGIN_MESSAGE_MAP(RenderFrameMessageFilter, message)
234 IPC_MESSAGE_HANDLER(FrameHostMsg_CreateChildFrame, OnCreateChildFrame) 235 IPC_MESSAGE_HANDLER(FrameHostMsg_CreateChildFrame, OnCreateChildFrame)
235 IPC_MESSAGE_HANDLER(FrameHostMsg_SetCookie, OnSetCookie)
236 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_GetCookies, OnGetCookies) 236 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_GetCookies, OnGetCookies)
237 IPC_MESSAGE_HANDLER(FrameHostMsg_CookiesEnabled, OnCookiesEnabled) 237 IPC_MESSAGE_HANDLER(FrameHostMsg_CookiesEnabled, OnCookiesEnabled)
238 IPC_MESSAGE_HANDLER(FrameHostMsg_DownloadUrl, OnDownloadUrl) 238 IPC_MESSAGE_HANDLER(FrameHostMsg_DownloadUrl, OnDownloadUrl)
239 IPC_MESSAGE_HANDLER(FrameHostMsg_SaveImageFromDataURL, 239 IPC_MESSAGE_HANDLER(FrameHostMsg_SaveImageFromDataURL,
240 OnSaveImageFromDataURL) 240 OnSaveImageFromDataURL)
241 IPC_MESSAGE_HANDLER(FrameHostMsg_Are3DAPIsBlocked, OnAre3DAPIsBlocked) 241 IPC_MESSAGE_HANDLER(FrameHostMsg_Are3DAPIsBlocked, OnAre3DAPIsBlocked)
242 IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_RenderProcessGone, 242 IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_RenderProcessGone,
243 OnRenderProcessGone()) 243 OnRenderProcessGone())
244 #if defined(ENABLE_PLUGINS) 244 #if defined(ENABLE_PLUGINS)
245 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_GetPlugins, OnGetPlugins) 245 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_GetPlugins, OnGetPlugins)
246 IPC_MESSAGE_HANDLER(FrameHostMsg_GetPluginInfo, OnGetPluginInfo) 246 IPC_MESSAGE_HANDLER(FrameHostMsg_GetPluginInfo, OnGetPluginInfo)
247 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_OpenChannelToPepperPlugin, 247 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_OpenChannelToPepperPlugin,
248 OnOpenChannelToPepperPlugin) 248 OnOpenChannelToPepperPlugin)
249 IPC_MESSAGE_HANDLER(FrameHostMsg_DidCreateOutOfProcessPepperInstance, 249 IPC_MESSAGE_HANDLER(FrameHostMsg_DidCreateOutOfProcessPepperInstance,
250 OnDidCreateOutOfProcessPepperInstance) 250 OnDidCreateOutOfProcessPepperInstance)
251 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDeleteOutOfProcessPepperInstance, 251 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDeleteOutOfProcessPepperInstance,
252 OnDidDeleteOutOfProcessPepperInstance) 252 OnDidDeleteOutOfProcessPepperInstance)
253 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenChannelToPpapiBroker, 253 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenChannelToPpapiBroker,
254 OnOpenChannelToPpapiBroker) 254 OnOpenChannelToPpapiBroker)
255 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginInstanceThrottleStateChange, 255 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginInstanceThrottleStateChange,
256 OnPluginInstanceThrottleStateChange) 256 OnPluginInstanceThrottleStateChange)
257 #endif // ENABLE_PLUGINS 257 #endif // ENABLE_PLUGINS
258 IPC_MESSAGE_UNHANDLED(handled = false) 258 IPC_MESSAGE_UNHANDLED(handled = false)
259 IPC_END_MESSAGE_MAP() 259 IPC_END_MESSAGE_MAP()
260 260
261 return handled; 261 return handled;
262 } 262 }
263 263
264 void RenderFrameMessageFilter::OnDestruct() const {
265 BrowserThread::DeleteOnIOThread::Destruct(this);
266 }
267
264 void RenderFrameMessageFilter::DownloadUrl(int render_view_id, 268 void RenderFrameMessageFilter::DownloadUrl(int render_view_id,
265 int render_frame_id, 269 int render_frame_id,
266 const GURL& url, 270 const GURL& url,
267 const Referrer& referrer, 271 const Referrer& referrer,
268 const base::string16& suggested_name, 272 const base::string16& suggested_name,
269 const bool use_prompt) const { 273 const bool use_prompt) const {
270 if (!resource_context_) 274 if (!resource_context_)
271 return; 275 return;
272 276
273 std::unique_ptr<DownloadUrlParameters> parameters( 277 std::unique_ptr<DownloadUrlParameters> parameters(
(...skipping 23 matching lines...) Expand all
297 int* new_routing_id) { 301 int* new_routing_id) {
298 *new_routing_id = render_widget_helper_->GetNextRoutingID(); 302 *new_routing_id = render_widget_helper_->GetNextRoutingID();
299 BrowserThread::PostTask( 303 BrowserThread::PostTask(
300 BrowserThread::UI, FROM_HERE, 304 BrowserThread::UI, FROM_HERE,
301 base::Bind(&CreateChildFrameOnUI, render_process_id_, 305 base::Bind(&CreateChildFrameOnUI, render_process_id_,
302 params.parent_routing_id, params.scope, params.frame_name, 306 params.parent_routing_id, params.scope, params.frame_name,
303 params.frame_unique_name, params.sandbox_flags, 307 params.frame_unique_name, params.sandbox_flags,
304 params.frame_owner_properties, *new_routing_id)); 308 params.frame_owner_properties, *new_routing_id));
305 } 309 }
306 310
307 void RenderFrameMessageFilter::OnSetCookie(int render_frame_id,
308 const GURL& url,
309 const GURL& first_party_for_cookies,
310 const std::string& cookie) {
311 ChildProcessSecurityPolicyImpl* policy =
312 ChildProcessSecurityPolicyImpl::GetInstance();
313 if (!policy->CanAccessDataForOrigin(render_process_id_, url)) {
314 bad_message::ReceivedBadMessage(this,
315 bad_message::RFMF_SET_COOKIE_BAD_ORIGIN);
316 return;
317 }
318
319 net::CookieOptions options;
320 bool experimental_web_platform_features_enabled =
321 base::CommandLine::ForCurrentProcess()->HasSwitch(
322 switches::kEnableExperimentalWebPlatformFeatures);
323 const std::string enforce_strict_secure_group =
324 base::FieldTrialList::FindFullName(kEnforceStrictSecureExperiment);
325 if (experimental_web_platform_features_enabled ||
326 base::StartsWith(enforce_strict_secure_group, "Enabled",
327 base::CompareCase::INSENSITIVE_ASCII)) {
328 options.set_enforce_strict_secure();
329 }
330 if (GetContentClient()->browser()->AllowSetCookie(
331 url, first_party_for_cookies, cookie, resource_context_,
332 render_process_id_, render_frame_id, options)) {
333 net::URLRequestContext* context = GetRequestContextForURL(url);
334 // Pass a null callback since we don't care about when the 'set' completes.
335 context->cookie_store()->SetCookieWithOptionsAsync(
336 url, cookie, options, net::CookieStore::SetCookiesCallback());
337 }
338 }
339
340 void RenderFrameMessageFilter::OnGetCookies(int render_frame_id, 311 void RenderFrameMessageFilter::OnGetCookies(int render_frame_id,
341 const GURL& url, 312 const GURL& url,
342 const GURL& first_party_for_cookies, 313 const GURL& first_party_for_cookies,
343 IPC::Message* reply_msg) { 314 IPC::Message* reply_msg) {
344 ChildProcessSecurityPolicyImpl* policy = 315 ChildProcessSecurityPolicyImpl* policy =
345 ChildProcessSecurityPolicyImpl::GetInstance(); 316 ChildProcessSecurityPolicyImpl::GetInstance();
346 if (!policy->CanAccessDataForOrigin(render_process_id_, url)) { 317 if (!policy->CanAccessDataForOrigin(render_process_id_, url)) {
347 bad_message::ReceivedBadMessage(this, 318 bad_message::ReceivedBadMessage(this,
348 bad_message::RFMF_GET_COOKIES_BAD_ORIGIN); 319 bad_message::RFMF_GET_COOKIES_BAD_ORIGIN);
349 delete reply_msg; 320 delete reply_msg;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 424
454 void RenderFrameMessageFilter::OnRenderProcessGone() { 425 void RenderFrameMessageFilter::OnRenderProcessGone() {
455 // FrameHostMessage_RenderProcessGone is a synthetic IPC message used by 426 // FrameHostMessage_RenderProcessGone is a synthetic IPC message used by
456 // RenderProcessHostImpl to clean things up after a crash (it's injected 427 // RenderProcessHostImpl to clean things up after a crash (it's injected
457 // downstream of this filter). Allowing it to proceed would enable a renderer 428 // downstream of this filter). Allowing it to proceed would enable a renderer
458 // to fake its own death; instead, actually kill the renderer. 429 // to fake its own death; instead, actually kill the renderer.
459 bad_message::ReceivedBadMessage( 430 bad_message::ReceivedBadMessage(
460 this, bad_message::RFMF_RENDERER_FAKED_ITS_OWN_DEATH); 431 this, bad_message::RFMF_RENDERER_FAKED_ITS_OWN_DEATH);
461 } 432 }
462 433
434 void RenderFrameMessageFilter::SetCookie(int32_t render_frame_id,
435 const GURL& url,
436 const GURL& first_party_for_cookies,
437 const mojo::String& cookie) {
438 ChildProcessSecurityPolicyImpl* policy =
439 ChildProcessSecurityPolicyImpl::GetInstance();
440 if (!policy->CanAccessDataForOrigin(render_process_id_, url)) {
441 bad_message::ReceivedBadMessage(this,
442 bad_message::RFMF_SET_COOKIE_BAD_ORIGIN);
443 return;
444 }
445
446 net::CookieOptions options;
447 bool experimental_web_platform_features_enabled =
448 base::CommandLine::ForCurrentProcess()->HasSwitch(
449 switches::kEnableExperimentalWebPlatformFeatures);
450 const std::string enforce_strict_secure_group =
451 base::FieldTrialList::FindFullName(kEnforceStrictSecureExperiment);
452 if (experimental_web_platform_features_enabled ||
453 base::StartsWith(enforce_strict_secure_group, "Enabled",
454 base::CompareCase::INSENSITIVE_ASCII)) {
455 options.set_enforce_strict_secure();
456 }
457 if (GetContentClient()->browser()->AllowSetCookie(
458 url, first_party_for_cookies, cookie, resource_context_,
459 render_process_id_, render_frame_id, options)) {
460 net::URLRequestContext* context = GetRequestContextForURL(url);
461 // Pass a null callback since we don't care about when the 'set' completes.
462 context->cookie_store()->SetCookieWithOptionsAsync(
463 url, cookie, options, net::CookieStore::SetCookiesCallback());
464 }
465 }
466
463 #if defined(ENABLE_PLUGINS) 467 #if defined(ENABLE_PLUGINS)
464 468
465 void RenderFrameMessageFilter::OnGetPlugins( 469 void RenderFrameMessageFilter::OnGetPlugins(
466 bool refresh, 470 bool refresh,
467 IPC::Message* reply_msg) { 471 IPC::Message* reply_msg) {
468 // Don't refresh if the specified threshold has not been passed. Note that 472 // Don't refresh if the specified threshold has not been passed. Note that
469 // this check is performed before off-loading to the file thread. The reason 473 // this check is performed before off-loading to the file thread. The reason
470 // we do this is that some pages tend to request that the list of plugins be 474 // we do this is that some pages tend to request that the list of plugins be
471 // refreshed at an excessive rate. This instigates disk scanning, as the list 475 // refreshed at an excessive rate. This instigates disk scanning, as the list
472 // is accumulated by doing multiple reads from disk. This effect is 476 // is accumulated by doing multiple reads from disk. This effect is
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 net::URLRequestContext* context = 611 net::URLRequestContext* context =
608 GetContentClient()->browser()->OverrideRequestContextForURL( 612 GetContentClient()->browser()->OverrideRequestContextForURL(
609 url, resource_context_); 613 url, resource_context_);
610 if (!context) 614 if (!context)
611 context = request_context_->GetURLRequestContext(); 615 context = request_context_->GetURLRequestContext();
612 616
613 return context; 617 return context;
614 } 618 }
615 619
616 } // namespace content 620 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698