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

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

Issue 211383007: Use FilePaths in content::DropData to avoid redundant conversions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clang-format Created 6 years, 8 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 | 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/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 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 // and can't be interpreted as a capability. 774 // and can't be interpreted as a capability.
775 DropData filtered_data(drop_data); 775 DropData filtered_data(drop_data);
776 GetProcess()->FilterURL(true, &filtered_data.url); 776 GetProcess()->FilterURL(true, &filtered_data.url);
777 if (drop_data.did_originate_from_renderer) { 777 if (drop_data.did_originate_from_renderer) {
778 filtered_data.filenames.clear(); 778 filtered_data.filenames.clear();
779 } 779 }
780 780
781 // The filenames vector, on the other hand, does represent a capability to 781 // The filenames vector, on the other hand, does represent a capability to
782 // access the given files. 782 // access the given files.
783 fileapi::IsolatedContext::FileInfoSet files; 783 fileapi::IsolatedContext::FileInfoSet files;
784 for (std::vector<DropData::FileInfo>::iterator iter( 784 for (std::vector<ui::FileInfo>::iterator iter(
785 filtered_data.filenames.begin()); 785 filtered_data.filenames.begin());
786 iter != filtered_data.filenames.end(); ++iter) { 786 iter != filtered_data.filenames.end();
787 ++iter) {
787 // A dragged file may wind up as the value of an input element, or it 788 // A dragged file may wind up as the value of an input element, or it
788 // may be used as the target of a navigation instead. We don't know 789 // may be used as the target of a navigation instead. We don't know
789 // which will happen at this point, so generously grant both access 790 // which will happen at this point, so generously grant both access
790 // and request permissions to the specific file to cover both cases. 791 // and request permissions to the specific file to cover both cases.
791 // We do not give it the permission to request all file:// URLs. 792 // We do not give it the permission to request all file:// URLs.
792 base::FilePath path =
793 base::FilePath::FromUTF8Unsafe(base::UTF16ToUTF8(iter->path));
794 793
795 // Make sure we have the same display_name as the one we register. 794 // Make sure we have the same display_name as the one we register.
796 if (iter->display_name.empty()) { 795 if (iter->display_name.empty()) {
797 std::string name; 796 std::string name;
798 files.AddPath(path, &name); 797 files.AddPath(iter->path, &name);
799 iter->display_name = base::UTF8ToUTF16(name); 798 iter->display_name = base::FilePath::FromUTF8Unsafe(name);
800 } else { 799 } else {
801 files.AddPathWithName(path, base::UTF16ToUTF8(iter->display_name)); 800 files.AddPathWithName(iter->path, iter->display_name.AsUTF8Unsafe());
802 } 801 }
803 802
804 policy->GrantRequestSpecificFileURL(renderer_id, 803 policy->GrantRequestSpecificFileURL(renderer_id,
805 net::FilePathToFileURL(path)); 804 net::FilePathToFileURL(iter->path));
806 805
807 // If the renderer already has permission to read these paths, we don't need 806 // If the renderer already has permission to read these paths, we don't need
808 // to re-grant them. This prevents problems with DnD for files in the CrOS 807 // to re-grant them. This prevents problems with DnD for files in the CrOS
809 // file manager--the file manager already had read/write access to those 808 // file manager--the file manager already had read/write access to those
810 // directories, but dragging a file would cause the read/write access to be 809 // directories, but dragging a file would cause the read/write access to be
811 // overwritten with read-only access, making them impossible to delete or 810 // overwritten with read-only access, making them impossible to delete or
812 // rename until the renderer was killed. 811 // rename until the renderer was killed.
813 if (!policy->CanReadFile(renderer_id, path)) 812 if (!policy->CanReadFile(renderer_id, iter->path))
814 policy->GrantReadFile(renderer_id, path); 813 policy->GrantReadFile(renderer_id, iter->path);
815 } 814 }
816 815
817 fileapi::IsolatedContext* isolated_context = 816 fileapi::IsolatedContext* isolated_context =
818 fileapi::IsolatedContext::GetInstance(); 817 fileapi::IsolatedContext::GetInstance();
819 DCHECK(isolated_context); 818 DCHECK(isolated_context);
820 std::string filesystem_id = isolated_context->RegisterDraggedFileSystem( 819 std::string filesystem_id = isolated_context->RegisterDraggedFileSystem(
821 files); 820 files);
822 if (!filesystem_id.empty()) { 821 if (!filesystem_id.empty()) {
823 // Grant the permission iff the ID is valid. 822 // Grant the permission iff the ID is valid.
824 policy->GrantReadFileSystem(renderer_id, filesystem_id); 823 policy->GrantReadFileSystem(renderer_id, filesystem_id);
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
1484 process->FilterURL(false, &filtered_data.html_base_url); 1483 process->FilterURL(false, &filtered_data.html_base_url);
1485 // Filter out any paths that the renderer didn't have access to. This prevents 1484 // Filter out any paths that the renderer didn't have access to. This prevents
1486 // the following attack on a malicious renderer: 1485 // the following attack on a malicious renderer:
1487 // 1. StartDragging IPC sent with renderer-specified filesystem paths that it 1486 // 1. StartDragging IPC sent with renderer-specified filesystem paths that it
1488 // doesn't have read permissions for. 1487 // doesn't have read permissions for.
1489 // 2. We initiate a native DnD operation. 1488 // 2. We initiate a native DnD operation.
1490 // 3. DnD operation immediately ends since mouse is not held down. DnD events 1489 // 3. DnD operation immediately ends since mouse is not held down. DnD events
1491 // still fire though, which causes read permissions to be granted to the 1490 // still fire though, which causes read permissions to be granted to the
1492 // renderer for any file paths in the drop. 1491 // renderer for any file paths in the drop.
1493 filtered_data.filenames.clear(); 1492 filtered_data.filenames.clear();
1494 for (std::vector<DropData::FileInfo>::const_iterator it = 1493 for (std::vector<ui::FileInfo>::const_iterator it =
1495 drop_data.filenames.begin(); 1494 drop_data.filenames.begin();
1496 it != drop_data.filenames.end(); ++it) { 1495 it != drop_data.filenames.end();
1497 base::FilePath path( 1496 ++it) {
1498 base::FilePath::FromUTF8Unsafe(base::UTF16ToUTF8(it->path))); 1497 if (policy->CanReadFile(GetProcess()->GetID(), it->path))
1499 if (policy->CanReadFile(GetProcess()->GetID(), path))
1500 filtered_data.filenames.push_back(*it); 1498 filtered_data.filenames.push_back(*it);
1501 } 1499 }
1502 float scale = ui::GetImageScale(GetScaleFactorForView(GetView())); 1500 float scale = ui::GetImageScale(GetScaleFactorForView(GetView()));
1503 gfx::ImageSkia image(gfx::ImageSkiaRep(bitmap, scale)); 1501 gfx::ImageSkia image(gfx::ImageSkiaRep(bitmap, scale));
1504 view->StartDragging(filtered_data, drag_operations_mask, image, 1502 view->StartDragging(filtered_data, drag_operations_mask, image,
1505 bitmap_offset_in_dip, event_info); 1503 bitmap_offset_in_dip, event_info);
1506 } 1504 }
1507 1505
1508 void RenderViewHostImpl::OnUpdateDragCursor(WebDragOperation current_op) { 1506 void RenderViewHostImpl::OnUpdateDragCursor(WebDragOperation current_op) {
1509 RenderViewHostDelegateView* view = delegate_->GetDelegateView(); 1507 RenderViewHostDelegateView* view = delegate_->GetDelegateView();
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1951 return true; 1949 return true;
1952 } 1950 }
1953 1951
1954 void RenderViewHostImpl::AttachToFrameTree() { 1952 void RenderViewHostImpl::AttachToFrameTree() {
1955 FrameTree* frame_tree = delegate_->GetFrameTree(); 1953 FrameTree* frame_tree = delegate_->GetFrameTree();
1956 1954
1957 frame_tree->ResetForMainFrameSwap(); 1955 frame_tree->ResetForMainFrameSwap();
1958 } 1956 }
1959 1957
1960 } // namespace content 1958 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698