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

Side by Side Diff: content/browser/renderer_host/render_view_host_impl.cc

Issue 2485693003: Drag-and-drop: DragEnter, DragOver, DragLeave, DragDrop (Closed)
Patch Set: No longer using GetSiteInstance() in RenderWidgetHostImpl. Created 4 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
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/renderer_host/render_view_host_impl.h" 5 #include "content/browser/renderer_host/render_view_host_impl.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 void RenderViewHostImpl::RenderProcessExited(RenderProcessHost* host, 620 void RenderViewHostImpl::RenderProcessExited(RenderProcessHost* host,
621 base::TerminationStatus status, 621 base::TerminationStatus status,
622 int exit_code) { 622 int exit_code) {
623 if (!GetWidget()->renderer_initialized()) 623 if (!GetWidget()->renderer_initialized())
624 return; 624 return;
625 625
626 GetWidget()->RendererExited(status, exit_code); 626 GetWidget()->RendererExited(status, exit_code);
627 delegate_->RenderViewTerminated(this, status, exit_code); 627 delegate_->RenderViewTerminated(this, status, exit_code);
628 } 628 }
629 629
630 void RenderViewHostImpl::DragTargetDragEnter(
631 const DropData& drop_data,
632 const gfx::Point& client_pt,
633 const gfx::Point& screen_pt,
634 WebDragOperationsMask operations_allowed,
635 int key_modifiers) {
636 DragTargetDragEnterWithMetaData(DropDataToMetaData(drop_data), client_pt,
637 screen_pt, operations_allowed, key_modifiers);
638 }
639
640 void RenderViewHostImpl::DragTargetDragEnterWithMetaData(
641 const std::vector<DropData::Metadata>& metadata,
642 const gfx::Point& client_pt,
643 const gfx::Point& screen_pt,
644 WebDragOperationsMask operations_allowed,
645 int key_modifiers) {
646 Send(new DragMsg_TargetDragEnter(GetRoutingID(), metadata, client_pt,
647 screen_pt, operations_allowed,
648 key_modifiers));
649 }
650
651 void RenderViewHostImpl::DragTargetDragOver(
652 const gfx::Point& client_pt,
653 const gfx::Point& screen_pt,
654 WebDragOperationsMask operations_allowed,
655 int key_modifiers) {
656 Send(new DragMsg_TargetDragOver(GetRoutingID(), client_pt, screen_pt,
657 operations_allowed, key_modifiers));
658 }
659
660 void RenderViewHostImpl::DragTargetDragLeave() {
661 Send(new DragMsg_TargetDragLeave(GetRoutingID()));
662 }
663
664 void RenderViewHostImpl::DragTargetDrop(const DropData& drop_data,
665 const gfx::Point& client_pt,
666 const gfx::Point& screen_pt,
667 int key_modifiers) {
668 DropData drop_data_with_permissions(drop_data);
669 GrantFileAccessFromDropData(&drop_data_with_permissions);
670 Send(new DragMsg_TargetDrop(GetRoutingID(), drop_data_with_permissions,
671 client_pt, screen_pt, key_modifiers));
672 }
673
674 void RenderViewHostImpl::FilterDropData(DropData* drop_data) { 630 void RenderViewHostImpl::FilterDropData(DropData* drop_data) {
675 #if DCHECK_IS_ON() 631 #if DCHECK_IS_ON()
676 drop_data->view_id = GetRoutingID(); 632 drop_data->view_id = GetRoutingID();
677 #endif // DCHECK_IS_ON() 633 #endif // DCHECK_IS_ON()
678 634
679 GetProcess()->FilterURL(true, &drop_data->url); 635 GetProcess()->FilterURL(true, &drop_data->url);
680 if (drop_data->did_originate_from_renderer) { 636 if (drop_data->did_originate_from_renderer) {
681 drop_data->filenames.clear(); 637 drop_data->filenames.clear();
682 } 638 }
683 } 639 }
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 weak_factory_.GetWeakPtr())); 1128 weak_factory_.GetWeakPtr()));
1173 } else { 1129 } else {
1174 render_view_ready_on_process_launch_ = true; 1130 render_view_ready_on_process_launch_ = true;
1175 } 1131 }
1176 } 1132 }
1177 1133
1178 void RenderViewHostImpl::RenderViewReady() { 1134 void RenderViewHostImpl::RenderViewReady() {
1179 delegate_->RenderViewReady(this); 1135 delegate_->RenderViewReady(this);
1180 } 1136 }
1181 1137
1182 void RenderViewHostImpl::GrantFileAccessFromDropData(DropData* drop_data) {
1183 DCHECK_EQ(GetRoutingID(), drop_data->view_id);
1184 const int renderer_id = GetProcess()->GetID();
1185 ChildProcessSecurityPolicyImpl* policy =
1186 ChildProcessSecurityPolicyImpl::GetInstance();
1187
1188 #if defined(OS_CHROMEOS)
1189 // The externalfile:// scheme is used in Chrome OS to open external files in a
1190 // browser tab.
1191 if (drop_data->url.SchemeIs(content::kExternalFileScheme))
1192 policy->GrantRequestURL(renderer_id, drop_data->url);
1193 #endif
1194
1195 // The filenames vector represents a capability to access the given files.
1196 storage::IsolatedContext::FileInfoSet files;
1197 for (auto& filename : drop_data->filenames) {
1198 // Make sure we have the same display_name as the one we register.
1199 if (filename.display_name.empty()) {
1200 std::string name;
1201 files.AddPath(filename.path, &name);
1202 filename.display_name = base::FilePath::FromUTF8Unsafe(name);
1203 } else {
1204 files.AddPathWithName(filename.path,
1205 filename.display_name.AsUTF8Unsafe());
1206 }
1207 // A dragged file may wind up as the value of an input element, or it
1208 // may be used as the target of a navigation instead. We don't know
1209 // which will happen at this point, so generously grant both access
1210 // and request permissions to the specific file to cover both cases.
1211 // We do not give it the permission to request all file:// URLs.
1212 policy->GrantRequestSpecificFileURL(renderer_id,
1213 net::FilePathToFileURL(filename.path));
1214
1215 // If the renderer already has permission to read these paths, we don't need
1216 // to re-grant them. This prevents problems with DnD for files in the CrOS
1217 // file manager--the file manager already had read/write access to those
1218 // directories, but dragging a file would cause the read/write access to be
1219 // overwritten with read-only access, making them impossible to delete or
1220 // rename until the renderer was killed.
1221 if (!policy->CanReadFile(renderer_id, filename.path))
1222 policy->GrantReadFile(renderer_id, filename.path);
1223 }
1224
1225 storage::IsolatedContext* isolated_context =
1226 storage::IsolatedContext::GetInstance();
1227 DCHECK(isolated_context);
1228
1229 if (!files.fileset().empty()) {
1230 std::string filesystem_id =
1231 isolated_context->RegisterDraggedFileSystem(files);
1232 if (!filesystem_id.empty()) {
1233 // Grant the permission iff the ID is valid.
1234 policy->GrantReadFileSystem(renderer_id, filesystem_id);
1235 }
1236 drop_data->filesystem_id = base::UTF8ToUTF16(filesystem_id);
1237 }
1238
1239 storage::FileSystemContext* file_system_context =
1240 BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(),
1241 GetSiteInstance())
1242 ->GetFileSystemContext();
1243 for (auto& file_system_file : drop_data->file_system_files) {
1244 storage::FileSystemURL file_system_url =
1245 file_system_context->CrackURL(file_system_file.url);
1246
1247 std::string register_name;
1248 std::string filesystem_id = isolated_context->RegisterFileSystemForPath(
1249 file_system_url.type(), file_system_url.filesystem_id(),
1250 file_system_url.path(), &register_name);
1251
1252 if (!filesystem_id.empty()) {
1253 // Grant the permission iff the ID is valid.
1254 policy->GrantReadFileSystem(renderer_id, filesystem_id);
1255 }
1256
1257 // Note: We are using the origin URL provided by the sender here. It may be
1258 // different from the receiver's.
1259 file_system_file.url =
1260 GURL(storage::GetIsolatedFileSystemRootURIString(
1261 file_system_url.origin(), filesystem_id, std::string())
1262 .append(register_name));
1263 }
1264 }
1265
1266 } // namespace content 1138 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698