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

Unified Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 2485693003: Drag-and-drop: DragEnter, DragOver, DragLeave, DragDrop (Closed)
Patch Set: Rebased. More fixes. 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/render_widget_host_impl.cc
diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc
index 33766b79d7677b2e57150e4258f2241bce17c678..aa54face8ed21d62c431223d4392dcfffc7d96a4 100644
--- a/content/browser/renderer_host/render_widget_host_impl.cc
+++ b/content/browser/renderer_host/render_widget_host_impl.cc
@@ -76,9 +76,12 @@
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/service/gpu_switches.h"
#include "gpu/ipc/common/gpu_messages.h"
+#include "net/base/filename_util.h"
#include "skia/ext/image_operations.h"
#include "skia/ext/platform_canvas.h"
+#include "storage/browser/fileapi/isolated_context.h"
#include "third_party/WebKit/public/web/WebCompositionUnderline.h"
+#include "ui/base/clipboard/clipboard.h"
#include "ui/events/blink/web_input_event_traits.h"
#include "ui/events/event.h"
#include "ui/events/keycodes/keyboard_codes.h"
@@ -97,6 +100,7 @@
using base::Time;
using base::TimeDelta;
using base::TimeTicks;
+using blink::WebDragOperationsMask;
using blink::WebGestureEvent;
using blink::WebInputEvent;
using blink::WebKeyboardEvent;
@@ -182,6 +186,56 @@ inline blink::WebGestureEvent CreateScrollEndForWrapping(
return wrap_gesture_scroll_end;
}
+std::vector<DropData::Metadata> DropDataToMetaData(const DropData& drop_data) {
+ std::vector<DropData::Metadata> metadata;
+ if (!drop_data.text.is_null()) {
+ metadata.push_back(DropData::Metadata::CreateForMimeType(
+ DropData::Kind::STRING,
+ base::ASCIIToUTF16(ui::Clipboard::kMimeTypeText)));
+ }
+
+ if (drop_data.url.is_valid()) {
+ metadata.push_back(DropData::Metadata::CreateForMimeType(
+ DropData::Kind::STRING,
+ base::ASCIIToUTF16(ui::Clipboard::kMimeTypeURIList)));
+ }
+
+ if (!drop_data.html.is_null()) {
+ metadata.push_back(DropData::Metadata::CreateForMimeType(
+ DropData::Kind::STRING,
+ base::ASCIIToUTF16(ui::Clipboard::kMimeTypeHTML)));
+ }
+
+ // On Aura, filenames are available before drop.
+ for (const auto& file_info : drop_data.filenames) {
+ if (!file_info.path.empty()) {
+ metadata.push_back(DropData::Metadata::CreateForFilePath(file_info.path));
+ }
+ }
+
+ // On Android, only files' mime types are available before drop.
+ for (const auto& mime_type : drop_data.file_mime_types) {
+ if (!mime_type.empty()) {
+ metadata.push_back(DropData::Metadata::CreateForMimeType(
+ DropData::Kind::FILENAME, mime_type));
+ }
+ }
+
+ for (const auto& file_system_file : drop_data.file_system_files) {
+ if (!file_system_file.url.is_empty()) {
+ metadata.push_back(
+ DropData::Metadata::CreateForFileSystemUrl(file_system_file.url));
+ }
+ }
+
+ for (const auto& custom_data_item : drop_data.custom_data) {
+ metadata.push_back(DropData::Metadata::CreateForMimeType(
+ DropData::Kind::STRING, custom_data_item.first));
+ }
+
+ return metadata;
+}
+
} // namespace
///////////////////////////////////////////////////////////////////////////////
@@ -1278,6 +1332,61 @@ void RenderWidgetHostImpl::HandleCompositorProto(
Send(new ViewMsg_HandleCompositorProto(GetRoutingID(), proto));
}
+void RenderWidgetHostImpl::DragTargetDragEnter(
+ const DropData& drop_data,
+ const gfx::Point& client_pt,
+ const gfx::Point& screen_pt,
+ WebDragOperationsMask operations_allowed,
+ int key_modifiers) {
+ DragTargetDragEnterWithMetaData(DropDataToMetaData(drop_data), client_pt,
+ screen_pt, operations_allowed, key_modifiers);
+}
+
+void RenderWidgetHostImpl::DragTargetDragEnterWithMetaData(
+ const std::vector<DropData::Metadata>& metadata,
+ const gfx::Point& client_pt,
+ const gfx::Point& screen_pt,
+ WebDragOperationsMask operations_allowed,
+ int key_modifiers) {
+ Send(new DragMsg_TargetDragEnter(GetRoutingID(), metadata, client_pt,
+ screen_pt, operations_allowed,
+ key_modifiers));
+}
+
+void RenderWidgetHostImpl::DragTargetDragOver(
+ const gfx::Point& client_pt,
+ const gfx::Point& screen_pt,
+ WebDragOperationsMask operations_allowed,
+ int key_modifiers) {
+ Send(new DragMsg_TargetDragOver(GetRoutingID(), client_pt, screen_pt,
+ operations_allowed, key_modifiers));
+}
+
+void RenderWidgetHostImpl::DragTargetDragLeave() {
+ Send(new DragMsg_TargetDragLeave(GetRoutingID()));
+}
+
+void RenderWidgetHostImpl::DragTargetDrop(const DropData& drop_data,
+ const gfx::Point& client_pt,
+ const gfx::Point& screen_pt,
+ int key_modifiers) {
+ DropData drop_data_with_permissions(drop_data);
+ GrantFileAccessFromDropData(&drop_data_with_permissions);
+ Send(new DragMsg_TargetDrop(GetRoutingID(), drop_data_with_permissions,
+ client_pt, screen_pt, key_modifiers));
+}
+
+void RenderWidgetHostImpl::FilterDropData(DropData* drop_data) {
+#if DCHECK_IS_ON()
+ drop_data->view_id = GetRoutingID();
+#endif // DCHECK_IS_ON()
+
+ GetProcess()->FilterURL(true, &drop_data->url);
+ if (drop_data->did_originate_from_renderer) {
+ drop_data->filenames.clear();
+ }
+}
+
void RenderWidgetHostImpl::NotifyScreenInfoChanged() {
if (delegate_)
delegate_->ScreenInfoChanged();
@@ -1352,6 +1461,9 @@ void RenderWidgetHostImpl::OnStartDragging(
const SkBitmap& bitmap,
const gfx::Vector2d& bitmap_offset_in_dip,
const DragEventSourceInfo& event_info) {
+ // TODO(paulmeyer): Stop relying on RenderViewHost once
+ // DragSourceSystemDragEnded is moved into RenderWidgetHost. See
+ // crbug.com/647249.
RenderViewHost* rvh = RenderViewHost::From(this);
if (!rvh)
return;
@@ -1387,9 +1499,7 @@ void RenderWidgetHostImpl::OnStartDragging(
}
storage::FileSystemContext* file_system_context =
- BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(),
- rvh->GetSiteInstance())
- ->GetFileSystemContext();
+ GetProcess()->GetStoragePartition()->GetFileSystemContext();
filtered_data.file_system_files.clear();
for (size_t i = 0; i < drop_data.file_system_files.size(); ++i) {
storage::FileSystemURL file_system_url =
@@ -2279,4 +2389,86 @@ BrowserAccessibilityManager*
delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL;
}
+void RenderWidgetHostImpl::GrantFileAccessFromDropData(DropData* drop_data) {
+ DCHECK_EQ(GetRoutingID(), drop_data->view_id);
+ const int renderer_id = GetProcess()->GetID();
+ ChildProcessSecurityPolicyImpl* policy =
+ ChildProcessSecurityPolicyImpl::GetInstance();
+
+#if defined(OS_CHROMEOS)
+ // The externalfile:// scheme is used in Chrome OS to open external files in a
+ // browser tab.
+ if (drop_data->url.SchemeIs(content::kExternalFileScheme))
+ policy->GrantRequestURL(renderer_id, drop_data->url);
+#endif
+
+ // The filenames vector represents a capability to access the given files.
+ storage::IsolatedContext::FileInfoSet files;
+ for (auto& filename : drop_data->filenames) {
+ // Make sure we have the same display_name as the one we register.
+ if (filename.display_name.empty()) {
+ std::string name;
+ files.AddPath(filename.path, &name);
+ filename.display_name = base::FilePath::FromUTF8Unsafe(name);
+ } else {
+ files.AddPathWithName(filename.path,
+ filename.display_name.AsUTF8Unsafe());
+ }
+ // A dragged file may wind up as the value of an input element, or it
+ // may be used as the target of a navigation instead. We don't know
+ // which will happen at this point, so generously grant both access
+ // and request permissions to the specific file to cover both cases.
+ // We do not give it the permission to request all file:// URLs.
+ policy->GrantRequestSpecificFileURL(renderer_id,
+ net::FilePathToFileURL(filename.path));
+
+ // If the renderer already has permission to read these paths, we don't need
+ // to re-grant them. This prevents problems with DnD for files in the CrOS
+ // file manager--the file manager already had read/write access to those
+ // directories, but dragging a file would cause the read/write access to be
+ // overwritten with read-only access, making them impossible to delete or
+ // rename until the renderer was killed.
+ if (!policy->CanReadFile(renderer_id, filename.path))
+ policy->GrantReadFile(renderer_id, filename.path);
+ }
+
+ storage::IsolatedContext* isolated_context =
+ storage::IsolatedContext::GetInstance();
+ DCHECK(isolated_context);
+
+ if (!files.fileset().empty()) {
+ std::string filesystem_id =
+ isolated_context->RegisterDraggedFileSystem(files);
+ if (!filesystem_id.empty()) {
+ // Grant the permission iff the ID is valid.
+ policy->GrantReadFileSystem(renderer_id, filesystem_id);
+ }
+ drop_data->filesystem_id = base::UTF8ToUTF16(filesystem_id);
+ }
+
+ storage::FileSystemContext* file_system_context =
+ GetProcess()->GetStoragePartition()->GetFileSystemContext();
+ for (auto& file_system_file : drop_data->file_system_files) {
+ storage::FileSystemURL file_system_url =
+ file_system_context->CrackURL(file_system_file.url);
+
+ std::string register_name;
+ std::string filesystem_id = isolated_context->RegisterFileSystemForPath(
+ file_system_url.type(), file_system_url.filesystem_id(),
+ file_system_url.path(), &register_name);
+
+ if (!filesystem_id.empty()) {
+ // Grant the permission iff the ID is valid.
+ policy->GrantReadFileSystem(renderer_id, filesystem_id);
+ }
+
+ // Note: We are using the origin URL provided by the sender here. It may be
+ // different from the receiver's.
+ file_system_file.url =
+ GURL(storage::GetIsolatedFileSystemRootURIString(
+ file_system_url.origin(), filesystem_id, std::string())
+ .append(register_name));
+ }
+}
+
} // namespace content
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.h ('k') | content/browser/web_contents/web_contents_view_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698