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

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: rebase Created 4 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
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 gfx::win::GetSystemMetricsInDIP(SM_CXVSCROLL); 158 gfx::win::GetSystemMetricsInDIP(SM_CXVSCROLL);
158 prefs->horizontal_scroll_bar_height_in_dips = 159 prefs->horizontal_scroll_bar_height_in_dips =
159 gfx::win::GetSystemMetricsInDIP(SM_CYHSCROLL); 160 gfx::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 gfx::win::GetSystemMetricsInDIP(SM_CYVSCROLL); 162 gfx::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 gfx::win::GetSystemMetricsInDIP(SM_CXHSCROLL); 164 gfx::win::GetSystemMetricsInDIP(SM_CXHSCROLL);
164 } 165 }
165 #endif 166 #endif
166 167
168 void DropDataToMetaData(const DropData& drop_data,
169 std::vector<MimeTypeKindPair>& meta_data) {
Avi (use Gerrit) 2016/04/12 02:51:51 Reference parameters aren't allowed for out parame
hush (inactive) 2016/04/12 20:36:57 Done.
170 if (!drop_data.text.is_null()) {
171 MimeTypeKindPair pair = std::make_pair(
172 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeText), STRING_KIND);
173 meta_data.push_back(pair);
174 }
175
176 if (!drop_data.url.is_empty()) {
177 MimeTypeKindPair pair = std::make_pair(
178 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeURIList), STRING_KIND);
179 meta_data.push_back(pair);
180 }
181
182 if (!drop_data.html.is_null()) {
183 MimeTypeKindPair pair = std::make_pair(
184 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeHTML), STRING_KIND);
185 meta_data.push_back(pair);
186 }
187
188 for (const auto& file_info : drop_data.filenames) {
189 if (!file_info.path.empty()) {
190 MimeTypeKindPair pair = std::make_pair(base::string16(), FILENAME_KIND);
191 meta_data.push_back(pair);
192 }
193 }
194
195 for (const auto& file_system_file : drop_data.file_system_files) {
196 if (!file_system_file.url.is_empty()) {
197 MimeTypeKindPair pair =
198 std::make_pair(base::string16(), FILESYSTEMFILE_KIND);
199 meta_data.push_back(pair);
200 }
201 }
202
203 for (const auto& custom_data_item : drop_data.custom_data) {
204 MimeTypeKindPair pair = std::make_pair(custom_data_item.first, STRING_KIND);
205 meta_data.push_back(pair);
206 }
207 }
208
167 } // namespace 209 } // namespace
168 210
169 // static 211 // static
170 const int64_t RenderViewHostImpl::kUnloadTimeoutMS = 1000; 212 const int64_t RenderViewHostImpl::kUnloadTimeoutMS = 1000;
171 213
172 /////////////////////////////////////////////////////////////////////////////// 214 ///////////////////////////////////////////////////////////////////////////////
173 // RenderViewHost, public: 215 // RenderViewHost, public:
174 216
175 // static 217 // static
176 RenderViewHost* RenderViewHost::FromID(int render_process_id, 218 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); 626 GetWidget()->RendererExited(status, exit_code);
585 delegate_->RenderViewTerminated(this, status, exit_code); 627 delegate_->RenderViewTerminated(this, status, exit_code);
586 } 628 }
587 629
588 void RenderViewHostImpl::DragTargetDragEnter( 630 void RenderViewHostImpl::DragTargetDragEnter(
589 const DropData& drop_data, 631 const DropData& drop_data,
590 const gfx::Point& client_pt, 632 const gfx::Point& client_pt,
591 const gfx::Point& screen_pt, 633 const gfx::Point& screen_pt,
592 WebDragOperationsMask operations_allowed, 634 WebDragOperationsMask operations_allowed,
593 int key_modifiers) { 635 int key_modifiers) {
636 #if defined(OS_CHROMEOS)
594 const int renderer_id = GetProcess()->GetID(); 637 const int renderer_id = GetProcess()->GetID();
595 ChildProcessSecurityPolicyImpl* policy = 638 ChildProcessSecurityPolicyImpl* policy =
596 ChildProcessSecurityPolicyImpl::GetInstance(); 639 ChildProcessSecurityPolicyImpl::GetInstance();
597 640
598 #if defined(OS_CHROMEOS)
599 // The externalfile:// scheme is used in Chrome OS to open external files in a 641 // The externalfile:// scheme is used in Chrome OS to open external files in a
600 // browser tab. 642 // browser tab.
601 if (drop_data.url.SchemeIs(content::kExternalFileScheme)) 643 if (drop_data.url.SchemeIs(content::kExternalFileScheme))
602 policy->GrantRequestURL(renderer_id, drop_data.url); 644 policy->GrantRequestURL(renderer_id, drop_data.url);
603 #endif 645 #endif
604 646
605 // The URL could have been cobbled together from any highlighted text string, 647 // The URL could have been cobbled together from any highlighted text string,
606 // and can't be interpreted as a capability. 648 // and can't be interpreted as a capability.
607 DropData filtered_data(drop_data); 649 DropData filtered_data(drop_data);
608 GetProcess()->FilterURL(true, &filtered_data.url); 650 FilterDropData(filtered_data);
609 if (drop_data.did_originate_from_renderer) {
610 filtered_data.filenames.clear();
611 }
612 651
613 // The filenames vector, on the other hand, does represent a capability to 652 std::vector<MimeTypeKindPair> meta_data;
614 // access the given files. 653 DropDataToMetaData(filtered_data, meta_data);
615 storage::IsolatedContext::FileInfoSet files; 654 Send(new DragMsg_TargetDragEnter(GetRoutingID(), meta_data, client_pt,
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, 655 screen_pt, operations_allowed,
683 key_modifiers)); 656 key_modifiers));
684 } 657 }
685 658
686 void RenderViewHostImpl::DragTargetDragOver( 659 void RenderViewHostImpl::DragTargetDragOver(
687 const gfx::Point& client_pt, 660 const gfx::Point& client_pt,
688 const gfx::Point& screen_pt, 661 const gfx::Point& screen_pt,
689 WebDragOperationsMask operations_allowed, 662 WebDragOperationsMask operations_allowed,
690 int key_modifiers) { 663 int key_modifiers) {
691 Send(new DragMsg_TargetDragOver(GetRoutingID(), client_pt, screen_pt, 664 Send(new DragMsg_TargetDragOver(GetRoutingID(), client_pt, screen_pt,
692 operations_allowed, key_modifiers)); 665 operations_allowed, key_modifiers));
693 } 666 }
694 667
695 void RenderViewHostImpl::DragTargetDragLeave() { 668 void RenderViewHostImpl::DragTargetDragLeave() {
696 Send(new DragMsg_TargetDragLeave(GetRoutingID())); 669 Send(new DragMsg_TargetDragLeave(GetRoutingID()));
697 } 670 }
698 671
699 void RenderViewHostImpl::DragTargetDrop( 672 void RenderViewHostImpl::DragTargetDrop(const DropData& drop_data,
700 const gfx::Point& client_pt, 673 const gfx::Point& client_pt,
701 const gfx::Point& screen_pt, 674 const gfx::Point& screen_pt,
702 int key_modifiers) { 675 int key_modifiers) {
703 Send(new DragMsg_TargetDrop(GetRoutingID(), client_pt, screen_pt, 676 DropData filtered_data(drop_data);
704 key_modifiers)); 677 FilterDropData(filtered_data);
678 Send(new DragMsg_TargetDrop(GetRoutingID(), filtered_data, client_pt,
679 screen_pt, key_modifiers));
705 } 680 }
706 681
707 void RenderViewHostImpl::DragSourceEndedAt( 682 void RenderViewHostImpl::DragSourceEndedAt(
708 int client_x, int client_y, int screen_x, int screen_y, 683 int client_x, int client_y, int screen_x, int screen_y,
709 WebDragOperation operation) { 684 WebDragOperation operation) {
710 Send(new DragMsg_SourceEnded(GetRoutingID(), 685 Send(new DragMsg_SourceEnded(GetRoutingID(),
711 gfx::Point(client_x, client_y), 686 gfx::Point(client_x, client_y),
712 gfx::Point(screen_x, screen_y), 687 gfx::Point(screen_x, screen_y),
713 operation)); 688 operation));
714 } 689 }
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 weak_factory_.GetWeakPtr())); 1323 weak_factory_.GetWeakPtr()));
1349 } else { 1324 } else {
1350 render_view_ready_on_process_launch_ = true; 1325 render_view_ready_on_process_launch_ = true;
1351 } 1326 }
1352 } 1327 }
1353 1328
1354 void RenderViewHostImpl::RenderViewReady() { 1329 void RenderViewHostImpl::RenderViewReady() {
1355 delegate_->RenderViewReady(this); 1330 delegate_->RenderViewReady(this);
1356 } 1331 }
1357 1332
1333 void RenderViewHostImpl::FilterDropData(DropData& filtered_data) {
1334 const int renderer_id = GetProcess()->GetID();
1335 ChildProcessSecurityPolicyImpl* policy =
1336 ChildProcessSecurityPolicyImpl::GetInstance();
1337
1338 GetProcess()->FilterURL(true, &filtered_data.url);
1339 if (filtered_data.did_originate_from_renderer) {
1340 filtered_data.filenames.clear();
1341 }
1342
1343 // The filenames vector, on the other hand, does represent a capability to
1344 // access the given files.
1345 storage::IsolatedContext::FileInfoSet files;
1346 for (auto& filename : filtered_data.filenames) {
1347 // A dragged file may wind up as the value of an input element, or it
1348 // may be used as the target of a navigation instead. We don't know
1349 // which will happen at this point, so generously grant both access
1350 // and request permissions to the specific file to cover both cases.
1351 // We do not give it the permission to request all file:// URLs.
1352
1353 // Make sure we have the same display_name as the one we register.
1354 if (filename.display_name.empty()) {
1355 std::string name;
1356 files.AddPath(filename.path, &name);
1357 filename.display_name = base::FilePath::FromUTF8Unsafe(name);
1358 } else {
1359 files.AddPathWithName(filename.path,
1360 filename.display_name.AsUTF8Unsafe());
1361 }
1362
1363 policy->GrantRequestSpecificFileURL(renderer_id,
1364 net::FilePathToFileURL(filename.path));
1365
1366 // If the renderer already has permission to read these paths, we don't need
1367 // to re-grant them. This prevents problems with DnD for files in the CrOS
1368 // file manager--the file manager already had read/write access to those
1369 // directories, but dragging a file would cause the read/write access to be
1370 // overwritten with read-only access, making them impossible to delete or
1371 // rename until the renderer was killed.
1372 if (!policy->CanReadFile(renderer_id, filename.path))
1373 policy->GrantReadFile(renderer_id, filename.path);
1374 }
1375
1376 storage::IsolatedContext* isolated_context =
1377 storage::IsolatedContext::GetInstance();
1378 DCHECK(isolated_context);
1379 std::string filesystem_id =
1380 isolated_context->RegisterDraggedFileSystem(files);
1381 if (!filesystem_id.empty()) {
1382 // Grant the permission iff the ID is valid.
1383 policy->GrantReadFileSystem(renderer_id, filesystem_id);
1384 }
1385 filtered_data.filesystem_id = base::UTF8ToUTF16(filesystem_id);
1386
1387 storage::FileSystemContext* file_system_context =
1388 BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(),
1389 GetSiteInstance())
1390 ->GetFileSystemContext();
1391 for (auto file_system_file : filtered_data.file_system_files) {
Avi (use Gerrit) 2016/04/12 02:51:51 Did you mean for (auto& file_system_file : ...) ?
hush (inactive) 2016/04/12 20:36:57 Yeah. Sorry I missed it. Added &.
1392 storage::FileSystemURL file_system_url =
1393 file_system_context->CrackURL(file_system_file.url);
1394
1395 std::string register_name;
1396 std::string filesystem_id = isolated_context->RegisterFileSystemForPath(
1397 file_system_url.type(), file_system_url.filesystem_id(),
1398 file_system_url.path(), &register_name);
1399 policy->GrantReadFileSystem(renderer_id, filesystem_id);
1400
1401 // Note: We are using the origin URL provided by the sender here. It may be
1402 // different from the receiver's.
1403 file_system_file.url =
Avi (use Gerrit) 2016/04/12 02:51:51 As noted above, you are modifying a local copy her
1404 GURL(storage::GetIsolatedFileSystemRootURIString(
1405 file_system_url.origin(), filesystem_id, std::string())
1406 .append(register_name));
1407 }
1408 }
1409
1358 } // namespace content 1410 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698