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

Side by Side Diff: content/browser/web_contents/render_view_host_manager.cc

Issue 11193051: To fix the cross-site post submission bug. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reuse ResourceRequestBody Struct Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/web_contents/render_view_host_manager.h" 5 #include "content/browser/web_contents/render_view_host_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "content/browser/child_process_security_policy_impl.h"
11 #include "content/browser/debugger/devtools_manager_impl.h" 12 #include "content/browser/debugger/devtools_manager_impl.h"
12 #include "content/browser/renderer_host/render_process_host_impl.h" 13 #include "content/browser/renderer_host/render_process_host_impl.h"
13 #include "content/browser/renderer_host/render_view_host_factory.h" 14 #include "content/browser/renderer_host/render_view_host_factory.h"
14 #include "content/browser/renderer_host/render_view_host_impl.h" 15 #include "content/browser/renderer_host/render_view_host_impl.h"
15 #include "content/browser/site_instance_impl.h" 16 #include "content/browser/site_instance_impl.h"
16 #include "content/browser/web_contents/navigation_controller_impl.h" 17 #include "content/browser/web_contents/navigation_controller_impl.h"
17 #include "content/browser/web_contents/navigation_entry_impl.h" 18 #include "content/browser/web_contents/navigation_entry_impl.h"
18 #include "content/browser/webui/web_ui_impl.h" 19 #include "content/browser/webui/web_ui_impl.h"
19 #include "content/common/view_messages.h" 20 #include "content/common/view_messages.h"
20 #include "content/port/browser/render_widget_host_view_port.h" 21 #include "content/port/browser/render_widget_host_view_port.h"
21 #include "content/public/browser/content_browser_client.h" 22 #include "content/public/browser/content_browser_client.h"
22 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/notification_types.h" 24 #include "content/public/browser/notification_types.h"
24 #include "content/public/browser/web_contents_view.h" 25 #include "content/public/browser/web_contents_view.h"
25 #include "content/public/browser/web_ui_controller.h" 26 #include "content/public/browser/web_ui_controller.h"
26 #include "content/public/browser/web_ui_controller_factory.h" 27 #include "content/public/browser/web_ui_controller_factory.h"
27 #include "content/public/common/content_switches.h" 28 #include "content/public/common/content_switches.h"
28 #include "content/public/common/url_constants.h" 29 #include "content/public/common/url_constants.h"
30 #include "webkit/glue/resource_request_body.h"
31
32 using webkit_glue::ResourceRequestBody;
29 33
30 namespace content { 34 namespace content {
31 35
32 RenderViewHostManager::RenderViewHostManager( 36 RenderViewHostManager::RenderViewHostManager(
33 RenderViewHostDelegate* render_view_delegate, 37 RenderViewHostDelegate* render_view_delegate,
34 RenderWidgetHostDelegate* render_widget_delegate, 38 RenderWidgetHostDelegate* render_widget_delegate,
35 Delegate* delegate) 39 Delegate* delegate)
36 : delegate_(delegate), 40 : delegate_(delegate),
37 cross_navigation_pending_(false), 41 cross_navigation_pending_(false),
38 render_view_delegate_(render_view_delegate), 42 render_view_delegate_(render_view_delegate),
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 // cross-navigating (Note that we don't care about on{before}unload 832 // cross-navigating (Note that we don't care about on{before}unload
829 // handlers if the current RVH isn't live.) 833 // handlers if the current RVH isn't live.)
830 CommitPending(); 834 CommitPending();
831 return render_view_host_; 835 return render_view_host_;
832 } else { 836 } else {
833 NOTREACHED(); 837 NOTREACHED();
834 return render_view_host_; 838 return render_view_host_;
835 } 839 }
836 } 840 }
837 // Otherwise, it's safe to treat this as a pending cross-site transition. 841 // Otherwise, it's safe to treat this as a pending cross-site transition.
842 // For the cross-process Post Submission request, we need to migrate the
843 // permission to read the upload file from the old process to the
844 // new process. TODO: I am not sure whether we need to revoke
845 // this permission after the POST.
846 if (entry.GetHasPostData()) {
847 ChildProcessSecurityPolicyImpl* policy =
848 ChildProcessSecurityPolicyImpl::GetInstance();
849 int oldID = render_view_host_->GetSiteInstance()->GetProcess()->GetID();
850 int newID =
851 pending_render_view_host_->GetSiteInstance()->GetProcess()->GetID();
852
853 const std::vector<ResourceRequestBody::Element>* uploads =
854 entry.request.request_body->elements();
855 std::vector<ResourceRequestBody::Element>::const_iterator iter;
856 for (iter = uploads->begin(); iter != uploads->end(); ++iter) {
857 if (iter->type() == ResourceRequestBody::Element::TYPE_FILE) {
858 if (policy->CanReadFile(oldID, iter->path())) {
859 policy->GrantReadFile(newID, iter->path());
860 }
861 }
862 }
863 }
838 864
839 // Make sure the old render view stops, in case a load is in progress. 865 // Make sure the old render view stops, in case a load is in progress.
840 render_view_host_->Send( 866 render_view_host_->Send(
841 new ViewMsg_Stop(render_view_host_->GetRoutingID())); 867 new ViewMsg_Stop(render_view_host_->GetRoutingID()));
842 868
843 // Suspend the new render view (i.e., don't let it send the cross-site 869 // Suspend the new render view (i.e., don't let it send the cross-site
844 // Navigate message) until we hear back from the old renderer's 870 // Navigate message) until we hear back from the old renderer's
845 // onbeforeunload handler. If the handler returns false, we'll have to 871 // onbeforeunload handler. If the handler returns false, we'll have to
846 // cancel the request. 872 // cancel the request.
847 DCHECK(!pending_render_view_host_->are_navigations_suspended()); 873 DCHECK(!pending_render_view_host_->are_navigations_suspended());
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( 985 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost(
960 SiteInstance* instance) { 986 SiteInstance* instance) {
961 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); 987 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId());
962 if (iter != swapped_out_hosts_.end()) 988 if (iter != swapped_out_hosts_.end())
963 return iter->second; 989 return iter->second;
964 990
965 return NULL; 991 return NULL;
966 } 992 }
967 993
968 } // namespace content 994 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698