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

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

Issue 1723763002: Add WebDragData to blink::WebView::dragtargetDrop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 7 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 (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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 #include "content/public/common/file_chooser_file_info.h" 73 #include "content/public/common/file_chooser_file_info.h"
74 #include "content/public/common/file_chooser_params.h" 74 #include "content/public/common/file_chooser_params.h"
75 #include "content/public/common/result_codes.h" 75 #include "content/public/common/result_codes.h"
76 #include "content/public/common/url_constants.h" 76 #include "content/public/common/url_constants.h"
77 #include "content/public/common/url_utils.h" 77 #include "content/public/common/url_utils.h"
78 #include "net/base/filename_util.h" 78 #include "net/base/filename_util.h"
79 #include "net/base/url_util.h" 79 #include "net/base/url_util.h"
80 #include "net/url_request/url_request_context_getter.h" 80 #include "net/url_request/url_request_context_getter.h"
81 #include "storage/browser/fileapi/isolated_context.h" 81 #include "storage/browser/fileapi/isolated_context.h"
82 #include "third_party/skia/include/core/SkBitmap.h" 82 #include "third_party/skia/include/core/SkBitmap.h"
83 #include "ui/base/clipboard/clipboard.h"
83 #include "ui/base/touch/touch_device.h" 84 #include "ui/base/touch/touch_device.h"
84 #include "ui/base/touch/touch_enabled.h" 85 #include "ui/base/touch/touch_enabled.h"
85 #include "ui/base/ui_base_switches.h" 86 #include "ui/base/ui_base_switches.h"
86 #include "ui/gfx/animation/animation.h" 87 #include "ui/gfx/animation/animation.h"
87 #include "ui/gfx/image/image_skia.h" 88 #include "ui/gfx/image/image_skia.h"
88 #include "ui/gfx/native_widget_types.h" 89 #include "ui/gfx/native_widget_types.h"
89 #include "ui/native_theme/native_theme_switches.h" 90 #include "ui/native_theme/native_theme_switches.h"
90 #include "url/url_constants.h" 91 #include "url/url_constants.h"
91 92
92 #if defined(OS_WIN) 93 #if defined(OS_WIN)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 display::win::GetSystemMetricsInDIP(SM_CXVSCROLL); 158 display::win::GetSystemMetricsInDIP(SM_CXVSCROLL);
158 prefs->horizontal_scroll_bar_height_in_dips = 159 prefs->horizontal_scroll_bar_height_in_dips =
159 display::win::GetSystemMetricsInDIP(SM_CYHSCROLL); 160 display::win::GetSystemMetricsInDIP(SM_CYHSCROLL);
160 prefs->arrow_bitmap_height_vertical_scroll_bar_in_dips = 161 prefs->arrow_bitmap_height_vertical_scroll_bar_in_dips =
161 display::win::GetSystemMetricsInDIP(SM_CYVSCROLL); 162 display::win::GetSystemMetricsInDIP(SM_CYVSCROLL);
162 prefs->arrow_bitmap_width_horizontal_scroll_bar_in_dips = 163 prefs->arrow_bitmap_width_horizontal_scroll_bar_in_dips =
163 display::win::GetSystemMetricsInDIP(SM_CXHSCROLL); 164 display::win::GetSystemMetricsInDIP(SM_CXHSCROLL);
164 } 165 }
165 #endif 166 #endif
166 167
168 std::vector<DropData::MetaData> DropDataToMetaData(const DropData& drop_data) {
169 std::vector<DropData::MetaData> meta_data;
170 if (!drop_data.text.is_null()) {
171 meta_data.emplace_back(DropData::Kind::STRING,
172 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeText));
173 }
174
175 if (!drop_data.url.is_empty()) {
176 meta_data.emplace_back(DropData::Kind::STRING,
177 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeURIList));
178 }
179
180 if (!drop_data.html.is_null()) {
181 meta_data.emplace_back(DropData::Kind::STRING,
182 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeHTML));
183 }
184
185 // On Aura, filenames are available before drop.
186 for (const auto& file_info : drop_data.filenames) {
187 if (!file_info.path.empty()) {
188 meta_data.emplace_back(DropData::Kind::FILENAME, file_info.path);
189 }
190 }
191
192 // On Android, only files' mime types are available before drop.
193 for (const auto& mime_type : drop_data.file_mime_types) {
194 if (!mime_type.empty()) {
195 meta_data.emplace_back(DropData::Kind::FILENAME, mime_type);
196 }
197 }
198
199 for (const auto& file_system_file : drop_data.file_system_files) {
200 if (!file_system_file.url.is_empty()) {
201 meta_data.emplace_back(DropData::Kind::FILESYSTEMFILE,
202 file_system_file.url);
203 }
204 }
205
206 for (const auto& custom_data_item : drop_data.custom_data) {
207 meta_data.emplace_back(DropData::Kind::STRING, custom_data_item.first);
208 }
209
210 return meta_data;
211 }
212
167 } // namespace 213 } // namespace
168 214
169 // static 215 // static
170 const int64_t RenderViewHostImpl::kUnloadTimeoutMS = 1000; 216 const int64_t RenderViewHostImpl::kUnloadTimeoutMS = 1000;
171 217
172 /////////////////////////////////////////////////////////////////////////////// 218 ///////////////////////////////////////////////////////////////////////////////
173 // RenderViewHost, public: 219 // RenderViewHost, public:
174 220
175 // static 221 // static
176 RenderViewHost* RenderViewHost::FromID(int render_process_id, 222 RenderViewHost* RenderViewHost::FromID(int render_process_id,
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 GetWidget()->RendererExited(status, exit_code); 630 GetWidget()->RendererExited(status, exit_code);
585 delegate_->RenderViewTerminated(this, status, exit_code); 631 delegate_->RenderViewTerminated(this, status, exit_code);
586 } 632 }
587 633
588 void RenderViewHostImpl::DragTargetDragEnter( 634 void RenderViewHostImpl::DragTargetDragEnter(
589 const DropData& drop_data, 635 const DropData& drop_data,
590 const gfx::Point& client_pt, 636 const gfx::Point& client_pt,
591 const gfx::Point& screen_pt, 637 const gfx::Point& screen_pt,
592 WebDragOperationsMask operations_allowed, 638 WebDragOperationsMask operations_allowed,
593 int key_modifiers) { 639 int key_modifiers) {
594 const int renderer_id = GetProcess()->GetID(); 640 Send(new DragMsg_TargetDragEnter(
595 ChildProcessSecurityPolicyImpl* policy = 641 GetRoutingID(), DropDataToMetaData(FilterDropData(drop_data)), client_pt,
596 ChildProcessSecurityPolicyImpl::GetInstance(); 642 screen_pt, operations_allowed, key_modifiers));
597
598 #if defined(OS_CHROMEOS)
599 // The externalfile:// scheme is used in Chrome OS to open external files in a
600 // browser tab.
601 if (drop_data.url.SchemeIs(content::kExternalFileScheme))
602 policy->GrantRequestURL(renderer_id, drop_data.url);
603 #endif
604
605 // The URL could have been cobbled together from any highlighted text string,
606 // and can't be interpreted as a capability.
607 DropData filtered_data(drop_data);
608 GetProcess()->FilterURL(true, &filtered_data.url);
609 if (drop_data.did_originate_from_renderer) {
610 filtered_data.filenames.clear();
611 }
612
613 // The filenames vector, on the other hand, does represent a capability to
614 // access the given files.
615 storage::IsolatedContext::FileInfoSet files;
616 for (std::vector<ui::FileInfo>::iterator iter(
617 filtered_data.filenames.begin());
618 iter != filtered_data.filenames.end();
619 ++iter) {
620 // A dragged file may wind up as the value of an input element, or it
621 // may be used as the target of a navigation instead. We don't know
622 // which will happen at this point, so generously grant both access
623 // and request permissions to the specific file to cover both cases.
624 // We do not give it the permission to request all file:// URLs.
625
626 // Make sure we have the same display_name as the one we register.
627 if (iter->display_name.empty()) {
628 std::string name;
629 files.AddPath(iter->path, &name);
630 iter->display_name = base::FilePath::FromUTF8Unsafe(name);
631 } else {
632 files.AddPathWithName(iter->path, iter->display_name.AsUTF8Unsafe());
633 }
634
635 policy->GrantRequestSpecificFileURL(renderer_id,
636 net::FilePathToFileURL(iter->path));
637
638 // If the renderer already has permission to read these paths, we don't need
639 // to re-grant them. This prevents problems with DnD for files in the CrOS
640 // file manager--the file manager already had read/write access to those
641 // directories, but dragging a file would cause the read/write access to be
642 // overwritten with read-only access, making them impossible to delete or
643 // rename until the renderer was killed.
644 if (!policy->CanReadFile(renderer_id, iter->path))
645 policy->GrantReadFile(renderer_id, iter->path);
646 }
647
648 storage::IsolatedContext* isolated_context =
649 storage::IsolatedContext::GetInstance();
650 DCHECK(isolated_context);
651 std::string filesystem_id = isolated_context->RegisterDraggedFileSystem(
652 files);
653 if (!filesystem_id.empty()) {
654 // Grant the permission iff the ID is valid.
655 policy->GrantReadFileSystem(renderer_id, filesystem_id);
656 }
657 filtered_data.filesystem_id = base::UTF8ToUTF16(filesystem_id);
658
659 storage::FileSystemContext* file_system_context =
660 BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(),
661 GetSiteInstance())
662 ->GetFileSystemContext();
663 for (size_t i = 0; i < filtered_data.file_system_files.size(); ++i) {
664 storage::FileSystemURL file_system_url =
665 file_system_context->CrackURL(filtered_data.file_system_files[i].url);
666
667 std::string register_name;
668 std::string filesystem_id = isolated_context->RegisterFileSystemForPath(
669 file_system_url.type(), file_system_url.filesystem_id(),
670 file_system_url.path(), &register_name);
671 policy->GrantReadFileSystem(renderer_id, filesystem_id);
672
673 // Note: We are using the origin URL provided by the sender here. It may be
674 // different from the receiver's.
675 filtered_data.file_system_files[i].url =
676 GURL(storage::GetIsolatedFileSystemRootURIString(
677 file_system_url.origin(), filesystem_id, std::string())
678 .append(register_name));
679 }
680
681 Send(new DragMsg_TargetDragEnter(GetRoutingID(), filtered_data, client_pt,
682 screen_pt, operations_allowed,
683 key_modifiers));
684 } 643 }
685 644
686 void RenderViewHostImpl::DragTargetDragOver( 645 void RenderViewHostImpl::DragTargetDragOver(
687 const gfx::Point& client_pt, 646 const gfx::Point& client_pt,
688 const gfx::Point& screen_pt, 647 const gfx::Point& screen_pt,
689 WebDragOperationsMask operations_allowed, 648 WebDragOperationsMask operations_allowed,
690 int key_modifiers) { 649 int key_modifiers) {
691 Send(new DragMsg_TargetDragOver(GetRoutingID(), client_pt, screen_pt, 650 Send(new DragMsg_TargetDragOver(GetRoutingID(), client_pt, screen_pt,
692 operations_allowed, key_modifiers)); 651 operations_allowed, key_modifiers));
693 } 652 }
694 653
695 void RenderViewHostImpl::DragTargetDragLeave() { 654 void RenderViewHostImpl::DragTargetDragLeave() {
696 Send(new DragMsg_TargetDragLeave(GetRoutingID())); 655 Send(new DragMsg_TargetDragLeave(GetRoutingID()));
697 } 656 }
698 657
699 void RenderViewHostImpl::DragTargetDrop( 658 void RenderViewHostImpl::DragTargetDrop(const DropData& drop_data,
700 const gfx::Point& client_pt, 659 const gfx::Point& client_pt,
701 const gfx::Point& screen_pt, 660 const gfx::Point& screen_pt,
702 int key_modifiers) { 661 int key_modifiers) {
703 Send(new DragMsg_TargetDrop(GetRoutingID(), client_pt, screen_pt, 662 GrantPermissionsToDraggedFiles(drop_data);
dcheng 2016/05/11 01:19:15 We probably still want to filter here, to avoid da
hush (inactive) 2016/05/12 05:34:47 What happens if the drop data at Drop time is inde
dcheng 2016/05/13 23:50:38 That seems OK to me, that's not a lot of callsites
663 Send(new DragMsg_TargetDrop(GetRoutingID(), drop_data, client_pt, screen_pt,
704 key_modifiers)); 664 key_modifiers));
705 } 665 }
706 666
707 void RenderViewHostImpl::DragSourceEndedAt( 667 void RenderViewHostImpl::DragSourceEndedAt(
708 int client_x, int client_y, int screen_x, int screen_y, 668 int client_x, int client_y, int screen_x, int screen_y,
709 WebDragOperation operation) { 669 WebDragOperation operation) {
710 Send(new DragMsg_SourceEnded(GetRoutingID(), 670 Send(new DragMsg_SourceEnded(GetRoutingID(),
711 gfx::Point(client_x, client_y), 671 gfx::Point(client_x, client_y),
712 gfx::Point(screen_x, screen_y), 672 gfx::Point(screen_x, screen_y),
713 operation)); 673 operation));
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 weak_factory_.GetWeakPtr())); 1308 weak_factory_.GetWeakPtr()));
1349 } else { 1309 } else {
1350 render_view_ready_on_process_launch_ = true; 1310 render_view_ready_on_process_launch_ = true;
1351 } 1311 }
1352 } 1312 }
1353 1313
1354 void RenderViewHostImpl::RenderViewReady() { 1314 void RenderViewHostImpl::RenderViewReady() {
1355 delegate_->RenderViewReady(this); 1315 delegate_->RenderViewReady(this);
1356 } 1316 }
1357 1317
1318 DropData RenderViewHostImpl::FilterDropData(const DropData& drop_data) {
1319 DropData filtered_data(drop_data);
1320 // The URL could have been cobbled together from any highlighted text string,
1321 // and can't be interpreted as a capability.
1322 GetProcess()->FilterURL(true, &filtered_data.url);
1323 if (filtered_data.did_originate_from_renderer) {
1324 filtered_data.filenames.clear();
1325 }
1326
1327 // The filenames vector, on the other hand, does represent a capability to
1328 // access the given files.
1329 storage::IsolatedContext::FileInfoSet files;
1330 for (auto& filename : filtered_data.filenames) {
1331 // Make sure we have the same display_name as the one we register.
1332 if (filename.display_name.empty()) {
1333 std::string name;
1334 files.AddPath(filename.path, &name);
1335 filename.display_name = base::FilePath::FromUTF8Unsafe(name);
1336 } else {
1337 files.AddPathWithName(filename.path,
1338 filename.display_name.AsUTF8Unsafe());
1339 }
1340 }
1341
1342 storage::IsolatedContext* isolated_context =
1343 storage::IsolatedContext::GetInstance();
1344 DCHECK(isolated_context);
1345 std::string filesystem_id =
1346 isolated_context->RegisterDraggedFileSystem(files);
1347 if (!filesystem_id.empty()) {
1348 // Grant the permission iff the ID is valid.
1349 filesystem_ids_to_grant_permissions_.push_back(filesystem_id);
1350 }
1351 filtered_data.filesystem_id = base::UTF8ToUTF16(filesystem_id);
1352
1353 storage::FileSystemContext* file_system_context =
1354 BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(),
1355 GetSiteInstance())
1356 ->GetFileSystemContext();
1357 for (auto& file_system_file : filtered_data.file_system_files) {
1358 storage::FileSystemURL file_system_url =
1359 file_system_context->CrackURL(file_system_file.url);
1360
1361 std::string register_name;
1362 std::string filesystem_id = isolated_context->RegisterFileSystemForPath(
1363 file_system_url.type(), file_system_url.filesystem_id(),
1364 file_system_url.path(), &register_name);
1365
1366 if (!filesystem_id.empty()) {
1367 // Grant the permission iff the ID is valid.
1368 filesystem_ids_to_grant_permissions_.push_back(filesystem_id);
1369 }
1370
1371 // Note: We are using the origin URL provided by the sender here. It may be
1372 // different from the receiver's.
1373 file_system_file.url =
1374 GURL(storage::GetIsolatedFileSystemRootURIString(
1375 file_system_url.origin(), filesystem_id, std::string())
1376 .append(register_name));
1377 }
1378
1379 return filtered_data;
1380 }
1381
1382 void RenderViewHostImpl::GrantPermissionsToDraggedFiles(
1383 const DropData& drop_data) {
1384 const int renderer_id = GetProcess()->GetID();
1385 ChildProcessSecurityPolicyImpl* policy =
1386 ChildProcessSecurityPolicyImpl::GetInstance();
1387
1388 #if defined(OS_CHROMEOS)
1389 // The externalfile:// scheme is used in Chrome OS to open external files in a
1390 // browser tab.
1391 if (drop_data.url.SchemeIs(content::kExternalFileScheme))
1392 policy->GrantRequestURL(renderer_id, drop_data.url);
1393 #endif
1394
1395 for (const auto& filename : drop_data.filenames) {
1396 // A dragged file may wind up as the value of an input element, or it
1397 // may be used as the target of a navigation instead. We don't know
1398 // which will happen at this point, so generously grant both access
1399 // and request permissions to the specific file to cover both cases.
1400 // We do not give it the permission to request all file:// URLs.
1401 policy->GrantRequestSpecificFileURL(renderer_id,
1402 net::FilePathToFileURL(filename.path));
1403
1404 // If the renderer already has permission to read these paths, we don't need
1405 // to re-grant them. This prevents problems with DnD for files in the CrOS
1406 // file manager--the file manager already had read/write access to those
1407 // directories, but dragging a file would cause the read/write access to be
1408 // overwritten with read-only access, making them impossible to delete or
1409 // rename until the renderer was killed.
1410 if (!policy->CanReadFile(renderer_id, filename.path))
1411 policy->GrantReadFile(renderer_id, filename.path);
1412 }
1413
1414 for (const auto& filesystem_id : filesystem_ids_to_grant_permissions_) {
1415 policy->GrantReadFileSystem(renderer_id, filesystem_id);
1416 }
1417
1418 filesystem_ids_to_grant_permissions_.clear();
1419 }
1420
1358 } // namespace content 1421 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698