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 2485693003: Drag-and-drop: DragEnter, DragOver, DragLeave, DragDrop (Closed)
Patch Set: Addressed comments by dcheng@. 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 #include "content/public/common/content_constants.h" 72 #include "content/public/common/content_constants.h"
73 #include "content/public/common/content_features.h" 73 #include "content/public/common/content_features.h"
74 #include "content/public/common/content_switches.h" 74 #include "content/public/common/content_switches.h"
75 #include "content/public/common/context_menu_params.h" 75 #include "content/public/common/context_menu_params.h"
76 #include "content/public/common/drop_data.h" 76 #include "content/public/common/drop_data.h"
77 #include "content/public/common/file_chooser_file_info.h" 77 #include "content/public/common/file_chooser_file_info.h"
78 #include "content/public/common/file_chooser_params.h" 78 #include "content/public/common/file_chooser_params.h"
79 #include "content/public/common/result_codes.h" 79 #include "content/public/common/result_codes.h"
80 #include "content/public/common/url_constants.h" 80 #include "content/public/common/url_constants.h"
81 #include "content/public/common/url_utils.h" 81 #include "content/public/common/url_utils.h"
82 #include "net/base/filename_util.h"
83 #include "net/base/url_util.h" 82 #include "net/base/url_util.h"
84 #include "net/url_request/url_request_context_getter.h" 83 #include "net/url_request/url_request_context_getter.h"
85 #include "storage/browser/fileapi/isolated_context.h"
86 #include "third_party/skia/include/core/SkBitmap.h" 84 #include "third_party/skia/include/core/SkBitmap.h"
87 #include "ui/base/clipboard/clipboard.h" 85 #include "ui/base/clipboard/clipboard.h"
88 #include "ui/base/touch/touch_device.h" 86 #include "ui/base/touch/touch_device.h"
89 #include "ui/base/touch/touch_enabled.h" 87 #include "ui/base/touch/touch_enabled.h"
90 #include "ui/base/ui_base_switches.h" 88 #include "ui/base/ui_base_switches.h"
91 #include "ui/gfx/animation/animation.h" 89 #include "ui/gfx/animation/animation.h"
92 #include "ui/gfx/color_space.h" 90 #include "ui/gfx/color_space.h"
93 #include "ui/gfx/image/image_skia.h" 91 #include "ui/gfx/image/image_skia.h"
94 #include "ui/gfx/native_widget_types.h" 92 #include "ui/gfx/native_widget_types.h"
95 #include "ui/native_theme/native_theme_switches.h" 93 #include "ui/native_theme/native_theme_switches.h"
96 #include "url/url_constants.h" 94 #include "url/url_constants.h"
97 95
98 #if defined(OS_WIN) 96 #if defined(OS_WIN)
99 #include "ui/display/win/screen_win.h" 97 #include "ui/display/win/screen_win.h"
100 #include "ui/gfx/geometry/dip_util.h" 98 #include "ui/gfx/geometry/dip_util.h"
101 #include "ui/gfx/platform_font_win.h" 99 #include "ui/gfx/platform_font_win.h"
102 #endif 100 #endif
103 101
104 using base::TimeDelta; 102 using base::TimeDelta;
105 using blink::WebConsoleMessage; 103 using blink::WebConsoleMessage;
106 using blink::WebDragOperation; 104 using blink::WebDragOperation;
107 using blink::WebDragOperationNone;
108 using blink::WebDragOperationsMask;
109 using blink::WebInputEvent; 105 using blink::WebInputEvent;
110 using blink::WebMediaPlayerAction; 106 using blink::WebMediaPlayerAction;
111 using blink::WebPluginAction; 107 using blink::WebPluginAction;
112 108
113 namespace content { 109 namespace content {
114 namespace { 110 namespace {
115 111
116 void GetPlatformSpecificPrefs(RendererPreferences* prefs) { 112 void GetPlatformSpecificPrefs(RendererPreferences* prefs) {
117 #if defined(OS_WIN) 113 #if defined(OS_WIN)
118 NONCLIENTMETRICS_XP metrics = {0}; 114 NONCLIENTMETRICS_XP metrics = {0};
(...skipping 25 matching lines...) Expand all
144 display::win::ScreenWin::GetSystemMetricsInDIP(SM_CYHSCROLL); 140 display::win::ScreenWin::GetSystemMetricsInDIP(SM_CYHSCROLL);
145 prefs->arrow_bitmap_height_vertical_scroll_bar_in_dips = 141 prefs->arrow_bitmap_height_vertical_scroll_bar_in_dips =
146 display::win::ScreenWin::GetSystemMetricsInDIP(SM_CYVSCROLL); 142 display::win::ScreenWin::GetSystemMetricsInDIP(SM_CYVSCROLL);
147 prefs->arrow_bitmap_width_horizontal_scroll_bar_in_dips = 143 prefs->arrow_bitmap_width_horizontal_scroll_bar_in_dips =
148 display::win::ScreenWin::GetSystemMetricsInDIP(SM_CXHSCROLL); 144 display::win::ScreenWin::GetSystemMetricsInDIP(SM_CXHSCROLL);
149 #elif defined(OS_LINUX) 145 #elif defined(OS_LINUX)
150 prefs->system_font_family_name = gfx::Font().GetFontName(); 146 prefs->system_font_family_name = gfx::Font().GetFontName();
151 #endif 147 #endif
152 } 148 }
153 149
154 std::vector<DropData::Metadata> DropDataToMetaData(const DropData& drop_data) { 150 std::vector<DropData::Metadata> DropDataToMetaData(const DropData& drop_data) {
nasko 2016/11/10 17:33:15 This method can be removed, right? I don't see any
paulmeyer 2016/11/11 23:26:48 Done.
155 std::vector<DropData::Metadata> metadata; 151 std::vector<DropData::Metadata> metadata;
156 if (!drop_data.text.is_null()) { 152 if (!drop_data.text.is_null()) {
157 metadata.push_back(DropData::Metadata::CreateForMimeType( 153 metadata.push_back(DropData::Metadata::CreateForMimeType(
158 DropData::Kind::STRING, 154 DropData::Kind::STRING,
159 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeText))); 155 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeText)));
160 } 156 }
161 157
162 if (drop_data.url.is_valid()) { 158 if (drop_data.url.is_valid()) {
163 metadata.push_back(DropData::Metadata::CreateForMimeType( 159 metadata.push_back(DropData::Metadata::CreateForMimeType(
164 DropData::Kind::STRING, 160 DropData::Kind::STRING,
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 void RenderViewHostImpl::RenderProcessExited(RenderProcessHost* host, 616 void RenderViewHostImpl::RenderProcessExited(RenderProcessHost* host,
621 base::TerminationStatus status, 617 base::TerminationStatus status,
622 int exit_code) { 618 int exit_code) {
623 if (!GetWidget()->renderer_initialized()) 619 if (!GetWidget()->renderer_initialized())
624 return; 620 return;
625 621
626 GetWidget()->RendererExited(status, exit_code); 622 GetWidget()->RendererExited(status, exit_code);
627 delegate_->RenderViewTerminated(this, status, exit_code); 623 delegate_->RenderViewTerminated(this, status, exit_code);
628 } 624 }
629 625
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) {
675 #if DCHECK_IS_ON()
676 drop_data->view_id = GetRoutingID();
677 #endif // DCHECK_IS_ON()
678
679 GetProcess()->FilterURL(true, &drop_data->url);
680 if (drop_data->did_originate_from_renderer) {
681 drop_data->filenames.clear();
682 }
683 }
684
685 void RenderViewHostImpl::DragSourceEndedAt( 626 void RenderViewHostImpl::DragSourceEndedAt(
686 int client_x, int client_y, int screen_x, int screen_y, 627 int client_x, int client_y, int screen_x, int screen_y,
687 WebDragOperation operation) { 628 WebDragOperation operation) {
688 Send(new DragMsg_SourceEnded(GetRoutingID(), 629 Send(new DragMsg_SourceEnded(GetRoutingID(),
689 gfx::Point(client_x, client_y), 630 gfx::Point(client_x, client_y),
690 gfx::Point(screen_x, screen_y), 631 gfx::Point(screen_x, screen_y),
691 operation)); 632 operation));
692 } 633 }
693 634
694 void RenderViewHostImpl::DragSourceSystemDragEnded() { 635 void RenderViewHostImpl::DragSourceSystemDragEnded() {
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 weak_factory_.GetWeakPtr())); 1113 weak_factory_.GetWeakPtr()));
1173 } else { 1114 } else {
1174 render_view_ready_on_process_launch_ = true; 1115 render_view_ready_on_process_launch_ = true;
1175 } 1116 }
1176 } 1117 }
1177 1118
1178 void RenderViewHostImpl::RenderViewReady() { 1119 void RenderViewHostImpl::RenderViewReady() {
1179 delegate_->RenderViewReady(this); 1120 delegate_->RenderViewReady(this);
1180 } 1121 }
1181 1122
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 1123 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698