| OLD | NEW |
| 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/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 #include "content/renderer/render_process.h" | 54 #include "content/renderer/render_process.h" |
| 55 #include "content/renderer/render_thread_impl.h" | 55 #include "content/renderer/render_thread_impl.h" |
| 56 #include "content/renderer/render_view_impl.h" | 56 #include "content/renderer/render_view_impl.h" |
| 57 #include "content/renderer/render_widget_owner_delegate.h" | 57 #include "content/renderer/render_widget_owner_delegate.h" |
| 58 #include "content/renderer/renderer_blink_platform_impl.h" | 58 #include "content/renderer/renderer_blink_platform_impl.h" |
| 59 #include "content/renderer/resizing_mode_selector.h" | 59 #include "content/renderer/resizing_mode_selector.h" |
| 60 #include "ipc/ipc_message_start.h" | 60 #include "ipc/ipc_message_start.h" |
| 61 #include "ipc/ipc_sync_message.h" | 61 #include "ipc/ipc_sync_message.h" |
| 62 #include "ppapi/features/features.h" | 62 #include "ppapi/features/features.h" |
| 63 #include "skia/ext/platform_canvas.h" | 63 #include "skia/ext/platform_canvas.h" |
| 64 #include "third_party/WebKit/public/platform/FilePathConversion.h" |
| 64 #include "third_party/WebKit/public/platform/WebCursorInfo.h" | 65 #include "third_party/WebKit/public/platform/WebCursorInfo.h" |
| 65 #include "third_party/WebKit/public/platform/WebDragData.h" | 66 #include "third_party/WebKit/public/platform/WebDragData.h" |
| 66 #include "third_party/WebKit/public/platform/WebDragOperation.h" | 67 #include "third_party/WebKit/public/platform/WebDragOperation.h" |
| 67 #include "third_party/WebKit/public/platform/WebPoint.h" | 68 #include "third_party/WebKit/public/platform/WebPoint.h" |
| 68 #include "third_party/WebKit/public/platform/WebRect.h" | 69 #include "third_party/WebKit/public/platform/WebRect.h" |
| 69 #include "third_party/WebKit/public/platform/WebSize.h" | 70 #include "third_party/WebKit/public/platform/WebSize.h" |
| 70 #include "third_party/WebKit/public/platform/WebString.h" | 71 #include "third_party/WebKit/public/platform/WebString.h" |
| 71 #include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_sc
heduling_state.h" | 72 #include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_sc
heduling_state.h" |
| 72 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul
er.h" | 73 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul
er.h" |
| 73 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" | 74 #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 return widget; | 194 return widget; |
| 194 } | 195 } |
| 195 | 196 |
| 196 WebDragData DropMetaDataToWebDragData( | 197 WebDragData DropMetaDataToWebDragData( |
| 197 const std::vector<DropData::Metadata>& drop_meta_data) { | 198 const std::vector<DropData::Metadata>& drop_meta_data) { |
| 198 std::vector<WebDragData::Item> item_list; | 199 std::vector<WebDragData::Item> item_list; |
| 199 for (const auto& meta_data_item : drop_meta_data) { | 200 for (const auto& meta_data_item : drop_meta_data) { |
| 200 if (meta_data_item.kind == DropData::Kind::STRING) { | 201 if (meta_data_item.kind == DropData::Kind::STRING) { |
| 201 WebDragData::Item item; | 202 WebDragData::Item item; |
| 202 item.storageType = WebDragData::Item::StorageTypeString; | 203 item.storageType = WebDragData::Item::StorageTypeString; |
| 203 item.stringType = meta_data_item.mime_type; | 204 item.stringType = WebString::fromUTF16(meta_data_item.mime_type); |
| 204 // Have to pass a dummy URL here instead of an empty URL because the | 205 // Have to pass a dummy URL here instead of an empty URL because the |
| 205 // DropData received by browser_plugins goes through a round trip: | 206 // DropData received by browser_plugins goes through a round trip: |
| 206 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData | 207 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData |
| 207 // will contain an empty URL (which means no URL is dragged) if the URL in | 208 // will contain an empty URL (which means no URL is dragged) if the URL in |
| 208 // WebDragData is empty. | 209 // WebDragData is empty. |
| 209 if (base::EqualsASCII(meta_data_item.mime_type, | 210 if (base::EqualsASCII(meta_data_item.mime_type, |
| 210 ui::Clipboard::kMimeTypeURIList)) { | 211 ui::Clipboard::kMimeTypeURIList)) { |
| 211 item.stringData = WebString::fromUTF8("about:dragdrop-placeholder"); | 212 item.stringData = WebString::fromUTF8("about:dragdrop-placeholder"); |
| 212 } | 213 } |
| 213 item_list.push_back(item); | 214 item_list.push_back(item); |
| 214 continue; | 215 continue; |
| 215 } | 216 } |
| 216 | 217 |
| 217 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with | 218 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with |
| 218 // just the mimetype. This is needed to drag files to WebView on Android | 219 // just the mimetype. This is needed to drag files to WebView on Android |
| 219 // platform. | 220 // platform. |
| 220 if ((meta_data_item.kind == DropData::Kind::FILENAME) && | 221 if ((meta_data_item.kind == DropData::Kind::FILENAME) && |
| 221 !meta_data_item.filename.empty()) { | 222 !meta_data_item.filename.empty()) { |
| 222 WebDragData::Item item; | 223 WebDragData::Item item; |
| 223 item.storageType = WebDragData::Item::StorageTypeFilename; | 224 item.storageType = WebDragData::Item::StorageTypeFilename; |
| 224 item.filenameData = meta_data_item.filename.AsUTF16Unsafe(); | 225 item.filenameData = blink::FilePathToWebString(meta_data_item.filename); |
| 225 item_list.push_back(item); | 226 item_list.push_back(item); |
| 226 continue; | 227 continue; |
| 227 } | 228 } |
| 228 | 229 |
| 229 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) { | 230 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) { |
| 230 WebDragData::Item item; | 231 WebDragData::Item item; |
| 231 item.storageType = WebDragData::Item::StorageTypeFileSystemFile; | 232 item.storageType = WebDragData::Item::StorageTypeFileSystemFile; |
| 232 item.fileSystemURL = meta_data_item.file_system_url; | 233 item.fileSystemURL = meta_data_item.file_system_url; |
| 233 item_list.push_back(item); | 234 item_list.push_back(item); |
| 234 continue; | 235 continue; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 246 | 247 |
| 247 // These fields are currently unused when dragging into WebKit. | 248 // These fields are currently unused when dragging into WebKit. |
| 248 DCHECK(drop_data.download_metadata.empty()); | 249 DCHECK(drop_data.download_metadata.empty()); |
| 249 DCHECK(drop_data.file_contents.empty()); | 250 DCHECK(drop_data.file_contents.empty()); |
| 250 DCHECK(drop_data.file_description_filename.empty()); | 251 DCHECK(drop_data.file_description_filename.empty()); |
| 251 | 252 |
| 252 if (!drop_data.text.is_null()) { | 253 if (!drop_data.text.is_null()) { |
| 253 WebDragData::Item item; | 254 WebDragData::Item item; |
| 254 item.storageType = WebDragData::Item::StorageTypeString; | 255 item.storageType = WebDragData::Item::StorageTypeString; |
| 255 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText); | 256 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText); |
| 256 item.stringData = drop_data.text.string(); | 257 item.stringData = WebString::fromUTF16(drop_data.text.string()); |
| 257 item_list.push_back(item); | 258 item_list.push_back(item); |
| 258 } | 259 } |
| 259 | 260 |
| 260 if (!drop_data.url.is_empty()) { | 261 if (!drop_data.url.is_empty()) { |
| 261 WebDragData::Item item; | 262 WebDragData::Item item; |
| 262 item.storageType = WebDragData::Item::StorageTypeString; | 263 item.storageType = WebDragData::Item::StorageTypeString; |
| 263 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList); | 264 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList); |
| 264 item.stringData = WebString::fromUTF8(drop_data.url.spec()); | 265 item.stringData = WebString::fromUTF8(drop_data.url.spec()); |
| 265 item.title = drop_data.url_title; | 266 item.title = WebString::fromUTF16(drop_data.url_title); |
| 266 item_list.push_back(item); | 267 item_list.push_back(item); |
| 267 } | 268 } |
| 268 | 269 |
| 269 if (!drop_data.html.is_null()) { | 270 if (!drop_data.html.is_null()) { |
| 270 WebDragData::Item item; | 271 WebDragData::Item item; |
| 271 item.storageType = WebDragData::Item::StorageTypeString; | 272 item.storageType = WebDragData::Item::StorageTypeString; |
| 272 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML); | 273 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML); |
| 273 item.stringData = drop_data.html.string(); | 274 item.stringData = WebString::fromUTF16(drop_data.html.string()); |
| 274 item.baseURL = drop_data.html_base_url; | 275 item.baseURL = drop_data.html_base_url; |
| 275 item_list.push_back(item); | 276 item_list.push_back(item); |
| 276 } | 277 } |
| 277 | 278 |
| 278 for (std::vector<ui::FileInfo>::const_iterator it = | 279 for (std::vector<ui::FileInfo>::const_iterator it = |
| 279 drop_data.filenames.begin(); | 280 drop_data.filenames.begin(); |
| 280 it != drop_data.filenames.end(); | 281 it != drop_data.filenames.end(); |
| 281 ++it) { | 282 ++it) { |
| 282 WebDragData::Item item; | 283 WebDragData::Item item; |
| 283 item.storageType = WebDragData::Item::StorageTypeFilename; | 284 item.storageType = WebDragData::Item::StorageTypeFilename; |
| 284 item.filenameData = it->path.AsUTF16Unsafe(); | 285 item.filenameData = blink::FilePathToWebString(it->path); |
| 285 item.displayNameData = it->display_name.AsUTF16Unsafe(); | 286 item.displayNameData = |
| 287 blink::FilePathToWebString(base::FilePath(it->display_name)); |
| 286 item_list.push_back(item); | 288 item_list.push_back(item); |
| 287 } | 289 } |
| 288 | 290 |
| 289 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it = | 291 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it = |
| 290 drop_data.file_system_files.begin(); | 292 drop_data.file_system_files.begin(); |
| 291 it != drop_data.file_system_files.end(); | 293 it != drop_data.file_system_files.end(); |
| 292 ++it) { | 294 ++it) { |
| 293 WebDragData::Item item; | 295 WebDragData::Item item; |
| 294 item.storageType = WebDragData::Item::StorageTypeFileSystemFile; | 296 item.storageType = WebDragData::Item::StorageTypeFileSystemFile; |
| 295 item.fileSystemURL = it->url; | 297 item.fileSystemURL = it->url; |
| 296 item.fileSystemFileSize = it->size; | 298 item.fileSystemFileSize = it->size; |
| 297 item_list.push_back(item); | 299 item_list.push_back(item); |
| 298 } | 300 } |
| 299 | 301 |
| 300 for (std::map<base::string16, base::string16>::const_iterator it = | 302 for (std::map<base::string16, base::string16>::const_iterator it = |
| 301 drop_data.custom_data.begin(); | 303 drop_data.custom_data.begin(); |
| 302 it != drop_data.custom_data.end(); | 304 it != drop_data.custom_data.end(); |
| 303 ++it) { | 305 ++it) { |
| 304 WebDragData::Item item; | 306 WebDragData::Item item; |
| 305 item.storageType = WebDragData::Item::StorageTypeString; | 307 item.storageType = WebDragData::Item::StorageTypeString; |
| 306 item.stringType = it->first; | 308 item.stringType = WebString::fromUTF16(it->first); |
| 307 item.stringData = it->second; | 309 item.stringData = WebString::fromUTF16(it->second); |
| 308 item_list.push_back(item); | 310 item_list.push_back(item); |
| 309 } | 311 } |
| 310 | 312 |
| 311 WebDragData result; | 313 WebDragData result; |
| 312 result.initialize(); | 314 result.initialize(); |
| 313 result.setItems(item_list); | 315 result.setItems(item_list); |
| 314 result.setFilesystemId(drop_data.filesystem_id); | 316 result.setFilesystemId(WebString::fromUTF16(drop_data.filesystem_id)); |
| 315 return result; | 317 return result; |
| 316 } | 318 } |
| 317 | 319 |
| 318 content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget = | 320 content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget = |
| 319 nullptr; | 321 nullptr; |
| 320 | 322 |
| 321 content::RenderWidget::RenderWidgetInitializedCallback | 323 content::RenderWidget::RenderWidgetInitializedCallback |
| 322 g_render_widget_initialized = nullptr; | 324 g_render_widget_initialized = nullptr; |
| 323 | 325 |
| 324 ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) { | 326 ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) { |
| (...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1477 } | 1479 } |
| 1478 | 1480 |
| 1479 WebRect RenderWidget::viewRect() { | 1481 WebRect RenderWidget::viewRect() { |
| 1480 WebRect rect = view_screen_rect_; | 1482 WebRect rect = view_screen_rect_; |
| 1481 ScreenRectToEmulatedIfNeeded(&rect); | 1483 ScreenRectToEmulatedIfNeeded(&rect); |
| 1482 return rect; | 1484 return rect; |
| 1483 } | 1485 } |
| 1484 | 1486 |
| 1485 void RenderWidget::setToolTipText(const blink::WebString& text, | 1487 void RenderWidget::setToolTipText(const blink::WebString& text, |
| 1486 WebTextDirection hint) { | 1488 WebTextDirection hint) { |
| 1487 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint)); | 1489 Send(new ViewHostMsg_SetTooltipText(routing_id_, text.utf16(), hint)); |
| 1488 } | 1490 } |
| 1489 | 1491 |
| 1490 void RenderWidget::setWindowRect(const WebRect& rect_in_screen) { | 1492 void RenderWidget::setWindowRect(const WebRect& rect_in_screen) { |
| 1491 WebRect window_rect = rect_in_screen; | 1493 WebRect window_rect = rect_in_screen; |
| 1492 EmulatedToScreenRectIfNeeded(&window_rect); | 1494 EmulatedToScreenRectIfNeeded(&window_rect); |
| 1493 | 1495 |
| 1494 if (!resizing_mode_selector_->is_synchronous_mode()) { | 1496 if (!resizing_mode_selector_->is_synchronous_mode()) { |
| 1495 if (did_show_) { | 1497 if (did_show_) { |
| 1496 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect)); | 1498 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect)); |
| 1497 SetPendingWindowRect(window_rect); | 1499 SetPendingWindowRect(window_rect); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1532 WebRange(replacement_range.start(), replacement_range.length())); | 1534 WebRange(replacement_range.start(), replacement_range.length())); |
| 1533 } | 1535 } |
| 1534 | 1536 |
| 1535 if (!ShouldHandleImeEvent()) | 1537 if (!ShouldHandleImeEvent()) |
| 1536 return; | 1538 return; |
| 1537 ImeEventGuard guard(this); | 1539 ImeEventGuard guard(this); |
| 1538 blink::WebInputMethodController* controller = GetInputMethodController(); | 1540 blink::WebInputMethodController* controller = GetInputMethodController(); |
| 1539 DCHECK(controller); | 1541 DCHECK(controller); |
| 1540 if (!controller || | 1542 if (!controller || |
| 1541 !controller->setComposition( | 1543 !controller->setComposition( |
| 1542 text, WebVector<WebCompositionUnderline>(underlines), selection_start, | 1544 WebString::fromUTF16(text), |
| 1545 WebVector<WebCompositionUnderline>(underlines), selection_start, |
| 1543 selection_end)) { | 1546 selection_end)) { |
| 1544 // If we failed to set the composition text, then we need to let the browser | 1547 // If we failed to set the composition text, then we need to let the browser |
| 1545 // process to cancel the input method's ongoing composition session, to make | 1548 // process to cancel the input method's ongoing composition session, to make |
| 1546 // sure we are in a consistent state. | 1549 // sure we are in a consistent state. |
| 1547 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1550 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
| 1548 } | 1551 } |
| 1549 UpdateCompositionInfo(false /* not an immediate request */); | 1552 UpdateCompositionInfo(false /* not an immediate request */); |
| 1550 } | 1553 } |
| 1551 | 1554 |
| 1552 void RenderWidget::OnImeCommitText(const base::string16& text, | 1555 void RenderWidget::OnImeCommitText(const base::string16& text, |
| 1553 const gfx::Range& replacement_range, | 1556 const gfx::Range& replacement_range, |
| 1554 int relative_cursor_pos) { | 1557 int relative_cursor_pos) { |
| 1555 #if BUILDFLAG(ENABLE_PLUGINS) | 1558 #if BUILDFLAG(ENABLE_PLUGINS) |
| 1556 if (focused_pepper_plugin_) { | 1559 if (focused_pepper_plugin_) { |
| 1557 focused_pepper_plugin_->render_frame()->OnImeCommitText( | 1560 focused_pepper_plugin_->render_frame()->OnImeCommitText( |
| 1558 text, replacement_range, relative_cursor_pos); | 1561 text, replacement_range, relative_cursor_pos); |
| 1559 return; | 1562 return; |
| 1560 } | 1563 } |
| 1561 #endif | 1564 #endif |
| 1562 if (replacement_range.IsValid()) { | 1565 if (replacement_range.IsValid()) { |
| 1563 GetWebWidget()->applyReplacementRange( | 1566 GetWebWidget()->applyReplacementRange( |
| 1564 WebRange(replacement_range.start(), replacement_range.length())); | 1567 WebRange(replacement_range.start(), replacement_range.length())); |
| 1565 } | 1568 } |
| 1566 | 1569 |
| 1567 if (!ShouldHandleImeEvent()) | 1570 if (!ShouldHandleImeEvent()) |
| 1568 return; | 1571 return; |
| 1569 ImeEventGuard guard(this); | 1572 ImeEventGuard guard(this); |
| 1570 input_handler_->set_handling_input_event(true); | 1573 input_handler_->set_handling_input_event(true); |
| 1571 if (auto* controller = GetInputMethodController()) | 1574 if (auto* controller = GetInputMethodController()) |
| 1572 controller->commitText(text, relative_cursor_pos); | 1575 controller->commitText(WebString::fromUTF16(text), relative_cursor_pos); |
| 1573 input_handler_->set_handling_input_event(false); | 1576 input_handler_->set_handling_input_event(false); |
| 1574 UpdateCompositionInfo(false /* not an immediate request */); | 1577 UpdateCompositionInfo(false /* not an immediate request */); |
| 1575 } | 1578 } |
| 1576 | 1579 |
| 1577 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { | 1580 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { |
| 1578 #if BUILDFLAG(ENABLE_PLUGINS) | 1581 #if BUILDFLAG(ENABLE_PLUGINS) |
| 1579 if (focused_pepper_plugin_) { | 1582 if (focused_pepper_plugin_) { |
| 1580 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText( | 1583 focused_pepper_plugin_->render_frame()->OnImeFinishComposingText( |
| 1581 keep_selection); | 1584 keep_selection); |
| 1582 return; | 1585 return; |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2309 blink::WebInputMethodController* RenderWidget::GetInputMethodController() | 2312 blink::WebInputMethodController* RenderWidget::GetInputMethodController() |
| 2310 const { | 2313 const { |
| 2311 // TODO(ekaramad): Remove this CHECK when GetWebWidget() is | 2314 // TODO(ekaramad): Remove this CHECK when GetWebWidget() is |
| 2312 // always a WebFrameWidget. | 2315 // always a WebFrameWidget. |
| 2313 CHECK(GetWebWidget()->isWebFrameWidget()); | 2316 CHECK(GetWebWidget()->isWebFrameWidget()); |
| 2314 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) | 2317 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) |
| 2315 ->getActiveWebInputMethodController(); | 2318 ->getActiveWebInputMethodController(); |
| 2316 } | 2319 } |
| 2317 | 2320 |
| 2318 } // namespace content | 2321 } // namespace content |
| OLD | NEW |