Chromium Code Reviews| Index: content/renderer/render_widget.cc |
| diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc |
| index ff7dcb2760822be29d33c2a1151b37a967770fed..b0c64d288fd2fb44abe06b9cbd3d5939199154f5 100644 |
| --- a/content/renderer/render_widget.cc |
| +++ b/content/renderer/render_widget.cc |
| @@ -38,6 +38,7 @@ |
| #include "content/public/common/content_features.h" |
| #include "content/public/common/content_switches.h" |
| #include "content/public/common/context_menu_params.h" |
| +#include "content/public/common/drop_data.h" |
| #include "content/renderer/cursor_utils.h" |
| #include "content/renderer/devtools/render_widget_screen_metrics_emulator.h" |
| #include "content/renderer/drop_data_builder.h" |
| @@ -60,6 +61,8 @@ |
| #include "ipc/ipc_sync_message.h" |
| #include "skia/ext/platform_canvas.h" |
| #include "third_party/WebKit/public/platform/WebCursorInfo.h" |
| +#include "third_party/WebKit/public/platform/WebDragData.h" |
| +#include "third_party/WebKit/public/platform/WebDragOperation.h" |
|
dcheng
2016/11/09 20:23:17
Can we clean up the corresponding forward declares
paulmeyer
2016/11/09 23:19:11
Done.
|
| #include "third_party/WebKit/public/platform/WebPoint.h" |
| #include "third_party/WebKit/public/platform/WebRect.h" |
| #include "third_party/WebKit/public/platform/WebSize.h" |
| @@ -77,6 +80,7 @@ |
| #include "third_party/WebKit/public/web/WebView.h" |
| #include "third_party/WebKit/public/web/WebWidget.h" |
| #include "third_party/skia/include/core/SkShader.h" |
| +#include "ui/base/clipboard/clipboard.h" |
| #include "ui/base/ui_base_switches.h" |
| #include "ui/gfx/geometry/point_conversions.h" |
| #include "ui/gfx/geometry/rect_conversions.h" |
| @@ -107,8 +111,10 @@ |
| using blink::WebCompositionUnderline; |
| using blink::WebCursorInfo; |
| using blink::WebDeviceEmulationParams; |
| +using blink::WebDragOperation; |
| using blink::WebDragOperationsMask; |
| using blink::WebDragData; |
| +using blink::WebFrameWidget; |
| using blink::WebGestureEvent; |
| using blink::WebImage; |
| using blink::WebInputEvent; |
| @@ -125,12 +131,15 @@ using blink::WebPopupType; |
| using blink::WebRange; |
| using blink::WebRect; |
| using blink::WebSize; |
| +using blink::WebString; |
| using blink::WebTextDirection; |
| using blink::WebTouchEvent; |
| using blink::WebTouchPoint; |
| using blink::WebVector; |
| using blink::WebWidget; |
| +namespace content { |
| + |
| namespace { |
| typedef std::map<std::string, ui::TextInputMode> TextInputModeMap; |
| @@ -182,6 +191,128 @@ content::RenderWidgetInputHandlerDelegate* GetRenderWidgetInputHandlerDelegate( |
| return widget; |
| } |
| +WebDragData DropMetaDataToWebDragData( |
| + const std::vector<DropData::Metadata>& drop_meta_data) { |
| + std::vector<WebDragData::Item> item_list; |
| + for (const auto& meta_data_item : drop_meta_data) { |
| + if (meta_data_item.kind == DropData::Kind::STRING) { |
| + WebDragData::Item item; |
| + item.storageType = WebDragData::Item::StorageTypeString; |
| + item.stringType = meta_data_item.mime_type; |
| + // Have to pass a dummy URL here instead of an empty URL because the |
| + // DropData received by browser_plugins goes through a round trip: |
| + // DropData::MetaData --> WebDragData-->DropData. In the end, DropData |
| + // will contain an empty URL (which means no URL is dragged) if the URL in |
| + // WebDragData is empty. |
| + if (base::EqualsASCII(meta_data_item.mime_type, |
| + ui::Clipboard::kMimeTypeURIList)) { |
| + item.stringData = WebString::fromUTF8("about:dragdrop-placeholder"); |
| + } |
| + item_list.push_back(item); |
| + continue; |
| + } |
| + |
| + // TODO(hush): crbug.com/584789. Blink needs to support creating a file with |
| + // just the mimetype. This is needed to drag files to WebView on Android |
| + // platform. |
| + if ((meta_data_item.kind == DropData::Kind::FILENAME) && |
| + !meta_data_item.filename.empty()) { |
| + WebDragData::Item item; |
| + item.storageType = WebDragData::Item::StorageTypeFilename; |
| + item.filenameData = meta_data_item.filename.AsUTF16Unsafe(); |
| + item_list.push_back(item); |
| + continue; |
| + } |
| + |
| + if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) { |
| + WebDragData::Item item; |
| + item.storageType = WebDragData::Item::StorageTypeFileSystemFile; |
| + item.fileSystemURL = meta_data_item.file_system_url; |
| + item_list.push_back(item); |
| + continue; |
| + } |
| + } |
| + |
| + WebDragData result; |
| + result.initialize(); |
| + result.setItems(item_list); |
| + return result; |
| +} |
| + |
| +WebDragData DropDataToWebDragData(const DropData& drop_data) { |
| + std::vector<WebDragData::Item> item_list; |
| + |
| + // These fields are currently unused when dragging into WebKit. |
| + DCHECK(drop_data.download_metadata.empty()); |
| + DCHECK(drop_data.file_contents.empty()); |
| + DCHECK(drop_data.file_description_filename.empty()); |
| + |
| + if (!drop_data.text.is_null()) { |
| + WebDragData::Item item; |
| + item.storageType = WebDragData::Item::StorageTypeString; |
| + item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText); |
| + item.stringData = drop_data.text.string(); |
| + item_list.push_back(item); |
| + } |
| + |
| + if (!drop_data.url.is_empty()) { |
| + WebDragData::Item item; |
| + item.storageType = WebDragData::Item::StorageTypeString; |
| + item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList); |
| + item.stringData = WebString::fromUTF8(drop_data.url.spec()); |
| + item.title = drop_data.url_title; |
| + item_list.push_back(item); |
| + } |
| + |
| + if (!drop_data.html.is_null()) { |
| + WebDragData::Item item; |
| + item.storageType = WebDragData::Item::StorageTypeString; |
| + item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML); |
| + item.stringData = drop_data.html.string(); |
| + item.baseURL = drop_data.html_base_url; |
| + item_list.push_back(item); |
| + } |
| + |
| + for (std::vector<ui::FileInfo>::const_iterator it = |
| + drop_data.filenames.begin(); |
| + it != drop_data.filenames.end(); |
| + ++it) { |
| + WebDragData::Item item; |
| + item.storageType = WebDragData::Item::StorageTypeFilename; |
| + item.filenameData = it->path.AsUTF16Unsafe(); |
| + item.displayNameData = it->display_name.AsUTF16Unsafe(); |
| + item_list.push_back(item); |
| + } |
| + |
| + for (std::vector<DropData::FileSystemFileInfo>::const_iterator it = |
| + drop_data.file_system_files.begin(); |
| + it != drop_data.file_system_files.end(); |
| + ++it) { |
| + WebDragData::Item item; |
| + item.storageType = WebDragData::Item::StorageTypeFileSystemFile; |
| + item.fileSystemURL = it->url; |
| + item.fileSystemFileSize = it->size; |
| + item_list.push_back(item); |
| + } |
| + |
| + for (std::map<base::string16, base::string16>::const_iterator it = |
| + drop_data.custom_data.begin(); |
| + it != drop_data.custom_data.end(); |
| + ++it) { |
| + WebDragData::Item item; |
| + item.storageType = WebDragData::Item::StorageTypeString; |
| + item.stringType = it->first; |
| + item.stringData = it->second; |
| + item_list.push_back(item); |
| + } |
| + |
| + WebDragData result; |
| + result.initialize(); |
| + result.setItems(item_list); |
| + result.setFilesystemId(drop_data.filesystem_id); |
| + return result; |
| +} |
| + |
| content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget = |
| nullptr; |
| @@ -204,8 +335,6 @@ ui::TextInputMode ConvertWebTextInputMode(blink::WebTextInputMode mode) { |
| } // namespace |
| -namespace content { |
| - |
| // RenderWidget --------------------------------------------------------------- |
| RenderWidget::RenderWidget(CompositorDependencies* compositor_deps, |
| @@ -520,12 +649,16 @@ bool RenderWidget::OnMessageReceived(const IPC::Message& message) { |
| OnWaitNextFrameForTests) |
| IPC_MESSAGE_HANDLER(InputMsg_RequestCompositionUpdate, |
| OnRequestCompositionUpdate) |
| + IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto) |
| + IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) |
| + IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) |
| + IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) |
| + IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) |
| #if defined(OS_ANDROID) |
| IPC_MESSAGE_HANDLER(InputMsg_ImeEventAck, OnImeEventAck) |
| IPC_MESSAGE_HANDLER(InputMsg_RequestTextInputStateUpdate, |
| OnRequestTextInputStateUpdate) |
| #endif |
| - IPC_MESSAGE_HANDLER(ViewMsg_HandleCompositorProto, OnHandleCompositorProto) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| return handled; |
| @@ -1530,6 +1663,60 @@ void RenderWidget::OnHandleCompositorProto(const std::vector<uint8_t>& proto) { |
| compositor_->OnHandleCompositorProto(proto); |
| } |
| +void RenderWidget::OnDragTargetDragEnter( |
| + const std::vector<DropData::Metadata>& drop_meta_data, |
| + const gfx::Point& client_point, |
| + const gfx::Point& screen_point, |
| + WebDragOperationsMask ops, |
| + int key_modifiers) { |
| + if (!GetWebWidget()) |
|
dcheng
2016/11/09 20:23:17
How come this needs to do null checks, but RenderV
paulmeyer
2016/11/09 23:19:11
It seems to be possible for this message to come d
|
| + return; |
| + |
| + DCHECK(GetWebWidget()->isWebFrameWidget()); |
| + WebDragOperation operation = static_cast<WebFrameWidget*>(GetWebWidget())-> |
| + dragTargetDragEnter(DropMetaDataToWebDragData(drop_meta_data), |
| + client_point, screen_point, ops, key_modifiers); |
| + |
| + Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation)); |
| +} |
| + |
| +void RenderWidget::OnDragTargetDragOver(const gfx::Point& client_point, |
| + const gfx::Point& screen_point, |
| + WebDragOperationsMask ops, |
| + int key_modifiers) { |
| + if (!GetWebWidget()) |
| + return; |
| + |
| + DCHECK(GetWebWidget()->isWebFrameWidget()); |
| + WebDragOperation operation = |
| + static_cast<WebFrameWidget*>(GetWebWidget())->dragTargetDragOver( |
| + ConvertWindowPointToViewport(client_point), |
| + screen_point, ops, key_modifiers); |
| + |
| + Send(new DragHostMsg_UpdateDragCursor(routing_id(), operation)); |
| +} |
| + |
| +void RenderWidget::OnDragTargetDragLeave() { |
| + if (!GetWebWidget()) |
| + return; |
| + DCHECK(GetWebWidget()->isWebFrameWidget()); |
| + static_cast<WebFrameWidget*>(GetWebWidget())->dragTargetDragLeave(); |
| +} |
| + |
| +void RenderWidget::OnDragTargetDrop(const DropData& drop_data, |
| + const gfx::Point& client_point, |
| + const gfx::Point& screen_point, |
| + int key_modifiers) { |
| + if (!GetWebWidget()) |
| + return; |
| + |
| + DCHECK(GetWebWidget()->isWebFrameWidget()); |
| + static_cast<WebFrameWidget*>(GetWebWidget())->dragTargetDrop( |
| + DropDataToWebDragData(drop_data), |
| + ConvertWindowPointToViewport(client_point), |
| + screen_point, key_modifiers); |
| +} |
| + |
| void RenderWidget::showImeIfNeeded() { |
| #if defined(OS_ANDROID) || defined(USE_AURA) |
| UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME); |
| @@ -2067,6 +2254,13 @@ float RenderWidget::GetOriginalDeviceScaleFactor() const { |
| device_scale_factor_; |
| } |
| +gfx::Point RenderWidget::ConvertWindowPointToViewport( |
| + const gfx::Point& point) { |
| + blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0); |
| + convertWindowToViewport(&point_in_viewport); |
| + return gfx::Point(point_in_viewport.x, point_in_viewport.y); |
| +} |
| + |
| bool RenderWidget::requestPointerLock() { |
| return mouse_lock_dispatcher_->LockMouse(webwidget_mouse_lock_target_.get()); |
| } |
| @@ -2090,7 +2284,7 @@ void RenderWidget::startDragging(blink::WebReferrerPolicy policy, |
| DropData drop_data(DropDataBuilder::Build(data)); |
| drop_data.referrer_policy = policy; |
| gfx::Vector2d imageOffset(offset_in_window.x, offset_in_window.y); |
| - Send(new DragHostMsg_StartDragging(routing_id_, drop_data, mask, |
| + Send(new DragHostMsg_StartDragging(routing_id(), drop_data, mask, |
| image.getSkBitmap(), imageOffset, |
| possible_drag_event_info_)); |
| } |