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

Side by Side Diff: content/renderer/render_frame_impl.cc

Issue 837283003: Start replicating sandbox flags for OOPIF (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix OnCreateChildFrame usage in unit tests Created 5 years, 11 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/renderer/render_frame_impl.h" 5 #include "content/renderer/render_frame_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 RenderThreadImpl::current()->SharedMainThreadContextProvider().get(); 482 RenderThreadImpl::current()->SharedMainThreadContextProvider().get();
483 if (!provider) 483 if (!provider)
484 return media::Context3D(); 484 return media::Context3D();
485 return media::Context3D(provider->ContextGL(), provider->GrContext()); 485 return media::Context3D(provider->ContextGL(), provider->GrContext());
486 } 486 }
487 #endif 487 #endif
488 488
489 RenderFrameImpl::CreateRenderFrameImplFunction g_create_render_frame_impl = 489 RenderFrameImpl::CreateRenderFrameImplFunction g_create_render_frame_impl =
490 nullptr; 490 nullptr;
491 491
492 #define STATIC_ASSERT_MATCHING_ENUMS(content_name, blink_name) \
493 static_assert( \
494 static_cast<int>(content_name) == static_cast<int>(blink_name), \
495 "enum values must match")
496
497 // Check that blink::WebSandboxFlags is kept in sync with
498 // content::SandboxFlags.
499 STATIC_ASSERT_MATCHING_ENUMS(SandboxFlags::NONE,
500 blink::WebSandboxFlags::None);
501 STATIC_ASSERT_MATCHING_ENUMS(SandboxFlags::NAVIGATION,
502 blink::WebSandboxFlags::Navigation);
503 STATIC_ASSERT_MATCHING_ENUMS(SandboxFlags::PLUGINS,
504 blink::WebSandboxFlags::Plugins);
505 STATIC_ASSERT_MATCHING_ENUMS(SandboxFlags::ORIGIN,
506 blink::WebSandboxFlags::Origin);
507 STATIC_ASSERT_MATCHING_ENUMS(SandboxFlags::FORMS,
508 blink::WebSandboxFlags::Forms);
509 STATIC_ASSERT_MATCHING_ENUMS(SandboxFlags::SCRIPTS,
510 blink::WebSandboxFlags::Scripts);
511 STATIC_ASSERT_MATCHING_ENUMS(SandboxFlags::TOP_NAVIGATION,
512 blink::WebSandboxFlags::TopNavigation);
513 STATIC_ASSERT_MATCHING_ENUMS(SandboxFlags::POPUPS,
514 blink::WebSandboxFlags::Popups);
515 STATIC_ASSERT_MATCHING_ENUMS(SandboxFlags::AUTOMATIC_FEATURES,
516 blink::WebSandboxFlags::AutomaticFeatures);
517 STATIC_ASSERT_MATCHING_ENUMS(SandboxFlags::POINTER_LOCK,
518 blink::WebSandboxFlags::PointerLock);
519 STATIC_ASSERT_MATCHING_ENUMS(SandboxFlags::DOCUMENT_DOMAIN,
520 blink::WebSandboxFlags::DocumentDomain);
521 STATIC_ASSERT_MATCHING_ENUMS(SandboxFlags::ORIENTATION_LOCK,
522 blink::WebSandboxFlags::OrientationLock);
523 STATIC_ASSERT_MATCHING_ENUMS(SandboxFlags::ALL,
524 blink::WebSandboxFlags::All);
525
492 } // namespace 526 } // namespace
493 527
494
495 // static 528 // static
496 RenderFrameImpl* RenderFrameImpl::Create(RenderViewImpl* render_view, 529 RenderFrameImpl* RenderFrameImpl::Create(RenderViewImpl* render_view,
497 int32 routing_id) { 530 int32 routing_id) {
498 DCHECK(routing_id != MSG_ROUTING_NONE); 531 DCHECK(routing_id != MSG_ROUTING_NONE);
499 532
500 if (g_create_render_frame_impl) 533 if (g_create_render_frame_impl)
501 return g_create_render_frame_impl(render_view, routing_id); 534 return g_create_render_frame_impl(render_view, routing_id);
502 else 535 else
503 return new RenderFrameImpl(render_view, routing_id); 536 return new RenderFrameImpl(render_view, routing_id);
504 } 537 }
505 538
506 // static 539 // static
507 RenderFrameImpl* RenderFrameImpl::FromRoutingID(int32 routing_id) { 540 RenderFrameImpl* RenderFrameImpl::FromRoutingID(int32 routing_id) {
508 RoutingIDFrameMap::iterator iter = 541 RoutingIDFrameMap::iterator iter =
509 g_routing_id_frame_map.Get().find(routing_id); 542 g_routing_id_frame_map.Get().find(routing_id);
510 if (iter != g_routing_id_frame_map.Get().end()) 543 if (iter != g_routing_id_frame_map.Get().end())
511 return iter->second; 544 return iter->second;
512 return NULL; 545 return NULL;
513 } 546 }
514 547
515 // static 548 // static
516 void RenderFrameImpl::CreateFrame(int routing_id, 549 void RenderFrameImpl::CreateFrame(
517 int parent_routing_id, 550 int routing_id,
518 int proxy_routing_id) { 551 int parent_routing_id,
552 int proxy_routing_id,
553 const FrameReplicationState& replicated_state) {
519 // TODO(nasko): For now, this message is only sent for subframes, as the 554 // TODO(nasko): For now, this message is only sent for subframes, as the
520 // top level frame is created when the RenderView is created through the 555 // top level frame is created when the RenderView is created through the
521 // ViewMsg_New IPC. 556 // ViewMsg_New IPC.
522 CHECK_NE(MSG_ROUTING_NONE, parent_routing_id); 557 CHECK_NE(MSG_ROUTING_NONE, parent_routing_id);
523 558
524 blink::WebLocalFrame* web_frame; 559 blink::WebLocalFrame* web_frame;
525 RenderFrameImpl* render_frame; 560 RenderFrameImpl* render_frame;
526 if (proxy_routing_id == MSG_ROUTING_NONE) { 561 if (proxy_routing_id == MSG_ROUTING_NONE) {
527 RenderFrameProxy* parent_proxy = 562 RenderFrameProxy* parent_proxy =
528 RenderFrameProxy::FromRoutingID(parent_routing_id); 563 RenderFrameProxy::FromRoutingID(parent_routing_id);
529 // If the browser is sending a valid parent routing id, it should already 564 // If the browser is sending a valid parent routing id, it should already
530 // be created and registered. 565 // be created and registered.
531 CHECK(parent_proxy); 566 CHECK(parent_proxy);
532 blink::WebRemoteFrame* parent_web_frame = parent_proxy->web_frame(); 567 blink::WebRemoteFrame* parent_web_frame = parent_proxy->web_frame();
533 568
534 // Create the RenderFrame and WebLocalFrame, linking the two. 569 // Create the RenderFrame and WebLocalFrame, linking the two.
535 render_frame = 570 render_frame =
536 RenderFrameImpl::Create(parent_proxy->render_view(), routing_id); 571 RenderFrameImpl::Create(parent_proxy->render_view(), routing_id);
537 web_frame = parent_web_frame->createLocalChild("", render_frame); 572 web_frame = parent_web_frame->createLocalChild("",
573 ContentToWebSandboxFlags(replicated_state.sandbox_flags),
574 render_frame);
538 } else { 575 } else {
539 RenderFrameProxy* proxy = 576 RenderFrameProxy* proxy =
540 RenderFrameProxy::FromRoutingID(proxy_routing_id); 577 RenderFrameProxy::FromRoutingID(proxy_routing_id);
541 CHECK(proxy); 578 CHECK(proxy);
542 render_frame = RenderFrameImpl::Create(proxy->render_view(), routing_id); 579 render_frame = RenderFrameImpl::Create(proxy->render_view(), routing_id);
543 web_frame = blink::WebLocalFrame::create(render_frame); 580 web_frame = blink::WebLocalFrame::create(render_frame);
544 render_frame->proxy_routing_id_ = proxy_routing_id; 581 render_frame->proxy_routing_id_ = proxy_routing_id;
545 web_frame->initializeToReplaceRemoteFrame(proxy->web_frame()); 582 web_frame->initializeToReplaceRemoteFrame(proxy->web_frame());
546 } 583 }
547 render_frame->SetWebFrame(web_frame); 584 render_frame->SetWebFrame(web_frame);
(...skipping 13 matching lines...) Expand all
561 return NULL; 598 return NULL;
562 } 599 }
563 600
564 // static 601 // static
565 void RenderFrameImpl::InstallCreateHook( 602 void RenderFrameImpl::InstallCreateHook(
566 CreateRenderFrameImplFunction create_render_frame_impl) { 603 CreateRenderFrameImplFunction create_render_frame_impl) {
567 CHECK(!g_create_render_frame_impl); 604 CHECK(!g_create_render_frame_impl);
568 g_create_render_frame_impl = create_render_frame_impl; 605 g_create_render_frame_impl = create_render_frame_impl;
569 } 606 }
570 607
608 // static
609 content::SandboxFlags RenderFrameImpl::WebToContentSandboxFlags(
610 blink::WebSandboxFlags flags) {
611 return static_cast<content::SandboxFlags>(flags);
612 }
613
614 // static
615 blink::WebSandboxFlags RenderFrameImpl::ContentToWebSandboxFlags(
616 content::SandboxFlags flags) {
617 return static_cast<blink::WebSandboxFlags>(flags);
618 }
619
571 // RenderFrameImpl ---------------------------------------------------------- 620 // RenderFrameImpl ----------------------------------------------------------
572 RenderFrameImpl::RenderFrameImpl(RenderViewImpl* render_view, int routing_id) 621 RenderFrameImpl::RenderFrameImpl(RenderViewImpl* render_view, int routing_id)
573 : frame_(NULL), 622 : frame_(NULL),
574 render_view_(render_view->AsWeakPtr()), 623 render_view_(render_view->AsWeakPtr()),
575 routing_id_(routing_id), 624 routing_id_(routing_id),
576 is_swapped_out_(false), 625 is_swapped_out_(false),
577 render_frame_proxy_(NULL), 626 render_frame_proxy_(NULL),
578 is_detaching_(false), 627 is_detaching_(false),
579 proxy_routing_id_(MSG_ROUTING_NONE), 628 proxy_routing_id_(MSG_ROUTING_NONE),
580 #if defined(ENABLE_PLUGINS) 629 #if defined(ENABLE_PLUGINS)
(...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1930 } 1979 }
1931 1980
1932 void RenderFrameImpl::didAccessInitialDocument(blink::WebLocalFrame* frame) { 1981 void RenderFrameImpl::didAccessInitialDocument(blink::WebLocalFrame* frame) {
1933 DCHECK(!frame_ || frame_ == frame); 1982 DCHECK(!frame_ || frame_ == frame);
1934 // Notify the browser process that it is no longer safe to show the pending 1983 // Notify the browser process that it is no longer safe to show the pending
1935 // URL of the main frame, since a URL spoof is now possible. 1984 // URL of the main frame, since a URL spoof is now possible.
1936 if (!frame->parent() && render_view_->page_id_ == -1) 1985 if (!frame->parent() && render_view_->page_id_ == -1)
1937 Send(new FrameHostMsg_DidAccessInitialDocument(routing_id_)); 1986 Send(new FrameHostMsg_DidAccessInitialDocument(routing_id_));
1938 } 1987 }
1939 1988
1989 // TODO(alexmos): Remove once Blink is updated to use the version that takes
1990 // sandbox flags.
1991 blink::WebFrame* RenderFrameImpl::createChildFrame(
1992 blink::WebLocalFrame* parent,
1993 const blink::WebString& name) {
1994 return createChildFrame(parent, name, blink::WebSandboxFlags::None);
1995 }
1996
1940 blink::WebFrame* RenderFrameImpl::createChildFrame( 1997 blink::WebFrame* RenderFrameImpl::createChildFrame(
1941 blink::WebLocalFrame* parent, 1998 blink::WebLocalFrame* parent,
1942 const blink::WebString& name) { 1999 const blink::WebString& name,
2000 blink::WebSandboxFlags sandbox_flags) {
1943 // Synchronously notify the browser of a child frame creation to get the 2001 // Synchronously notify the browser of a child frame creation to get the
1944 // routing_id for the RenderFrame. 2002 // routing_id for the RenderFrame.
1945 int child_routing_id = MSG_ROUTING_NONE; 2003 int child_routing_id = MSG_ROUTING_NONE;
1946 CHECK(Send(new FrameHostMsg_CreateChildFrame(routing_id_, 2004 CHECK(Send(new FrameHostMsg_CreateChildFrame(
1947 base::UTF16ToUTF8(name), 2005 routing_id_,
1948 &child_routing_id))); 2006 base::UTF16ToUTF8(name),
2007 WebToContentSandboxFlags(sandbox_flags),
2008 &child_routing_id)));
1949 2009
1950 // Allocation of routing id failed, so we can't create a child frame. This can 2010 // Allocation of routing id failed, so we can't create a child frame. This can
1951 // happen if this RenderFrameImpl's IPCs are being filtered when in swapped 2011 // happen if this RenderFrameImpl's IPCs are being filtered when in swapped
1952 // out state. 2012 // out state.
1953 if (child_routing_id == MSG_ROUTING_NONE) { 2013 if (child_routing_id == MSG_ROUTING_NONE) {
1954 #if !defined(OS_LINUX) 2014 #if !defined(OS_LINUX)
1955 // DumpWithoutCrashing() crashes on Linux in renderer processes when 2015 // DumpWithoutCrashing() crashes on Linux in renderer processes when
1956 // breakpad and sandboxing are enabled: crbug.com/349600 2016 // breakpad and sandboxing are enabled: crbug.com/349600
1957 base::debug::Alias(parent); 2017 base::debug::Alias(parent);
1958 base::debug::Alias(&routing_id_); 2018 base::debug::Alias(&routing_id_);
(...skipping 2372 matching lines...) Expand 10 before | Expand all | Expand 10 after
4331 4391
4332 #if defined(ENABLE_BROWSER_CDMS) 4392 #if defined(ENABLE_BROWSER_CDMS)
4333 RendererCdmManager* RenderFrameImpl::GetCdmManager() { 4393 RendererCdmManager* RenderFrameImpl::GetCdmManager() {
4334 if (!cdm_manager_) 4394 if (!cdm_manager_)
4335 cdm_manager_ = new RendererCdmManager(this); 4395 cdm_manager_ = new RendererCdmManager(this);
4336 return cdm_manager_; 4396 return cdm_manager_;
4337 } 4397 }
4338 #endif // defined(ENABLE_BROWSER_CDMS) 4398 #endif // defined(ENABLE_BROWSER_CDMS)
4339 4399
4340 } // namespace content 4400 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698