| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 #include "content/renderer/render_process.h" | 57 #include "content/renderer/render_process.h" |
| 58 #include "content/renderer/render_thread_impl.h" | 58 #include "content/renderer/render_thread_impl.h" |
| 59 #include "content/renderer/render_view_impl.h" | 59 #include "content/renderer/render_view_impl.h" |
| 60 #include "content/renderer/render_widget_owner_delegate.h" | 60 #include "content/renderer/render_widget_owner_delegate.h" |
| 61 #include "content/renderer/renderer_blink_platform_impl.h" | 61 #include "content/renderer/renderer_blink_platform_impl.h" |
| 62 #include "content/renderer/resizing_mode_selector.h" | 62 #include "content/renderer/resizing_mode_selector.h" |
| 63 #include "ipc/ipc_message_start.h" | 63 #include "ipc/ipc_message_start.h" |
| 64 #include "ipc/ipc_sync_message.h" | 64 #include "ipc/ipc_sync_message.h" |
| 65 #include "ppapi/features/features.h" | 65 #include "ppapi/features/features.h" |
| 66 #include "skia/ext/platform_canvas.h" | 66 #include "skia/ext/platform_canvas.h" |
| 67 #include "third_party/WebKit/public/platform/FilePathConversion.h" |
| 67 #include "third_party/WebKit/public/platform/WebCursorInfo.h" | 68 #include "third_party/WebKit/public/platform/WebCursorInfo.h" |
| 68 #include "third_party/WebKit/public/platform/WebDragData.h" | 69 #include "third_party/WebKit/public/platform/WebDragData.h" |
| 69 #include "third_party/WebKit/public/platform/WebDragOperation.h" | 70 #include "third_party/WebKit/public/platform/WebDragOperation.h" |
| 70 #include "third_party/WebKit/public/platform/WebMouseEvent.h" | 71 #include "third_party/WebKit/public/platform/WebMouseEvent.h" |
| 71 #include "third_party/WebKit/public/platform/WebPoint.h" | 72 #include "third_party/WebKit/public/platform/WebPoint.h" |
| 72 #include "third_party/WebKit/public/platform/WebRect.h" | 73 #include "third_party/WebKit/public/platform/WebRect.h" |
| 73 #include "third_party/WebKit/public/platform/WebSize.h" | 74 #include "third_party/WebKit/public/platform/WebSize.h" |
| 74 #include "third_party/WebKit/public/platform/WebString.h" | 75 #include "third_party/WebKit/public/platform/WebString.h" |
| 75 #include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_sc
heduling_state.h" | 76 #include "third_party/WebKit/public/platform/scheduler/renderer/render_widget_sc
heduling_state.h" |
| 76 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul
er.h" | 77 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul
er.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK; | 182 type == ui::TEXT_INPUT_TYPE_TIME || type == ui::TEXT_INPUT_TYPE_WEEK; |
| 182 } | 183 } |
| 183 | 184 |
| 184 WebDragData DropMetaDataToWebDragData( | 185 WebDragData DropMetaDataToWebDragData( |
| 185 const std::vector<DropData::Metadata>& drop_meta_data) { | 186 const std::vector<DropData::Metadata>& drop_meta_data) { |
| 186 std::vector<WebDragData::Item> item_list; | 187 std::vector<WebDragData::Item> item_list; |
| 187 for (const auto& meta_data_item : drop_meta_data) { | 188 for (const auto& meta_data_item : drop_meta_data) { |
| 188 if (meta_data_item.kind == DropData::Kind::STRING) { | 189 if (meta_data_item.kind == DropData::Kind::STRING) { |
| 189 WebDragData::Item item; | 190 WebDragData::Item item; |
| 190 item.storageType = WebDragData::Item::StorageTypeString; | 191 item.storageType = WebDragData::Item::StorageTypeString; |
| 191 item.stringType = meta_data_item.mime_type; | 192 item.stringType = WebString::fromUTF16(meta_data_item.mime_type); |
| 192 // Have to pass a dummy URL here instead of an empty URL because the | 193 // Have to pass a dummy URL here instead of an empty URL because the |
| 193 // DropData received by browser_plugins goes through a round trip: | 194 // DropData received by browser_plugins goes through a round trip: |
| 194 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData | 195 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData |
| 195 // will contain an empty URL (which means no URL is dragged) if the URL in | 196 // will contain an empty URL (which means no URL is dragged) if the URL in |
| 196 // WebDragData is empty. | 197 // WebDragData is empty. |
| 197 if (base::EqualsASCII(meta_data_item.mime_type, | 198 if (base::EqualsASCII(meta_data_item.mime_type, |
| 198 ui::Clipboard::kMimeTypeURIList)) { | 199 ui::Clipboard::kMimeTypeURIList)) { |
| 199 item.stringData = WebString::fromUTF8("about:dragdrop-placeholder"); | 200 item.stringData = WebString::fromUTF8("about:dragdrop-placeholder"); |
| 200 } | 201 } |
| 201 item_list.push_back(item); | 202 item_list.push_back(item); |
| 202 continue; | 203 continue; |
| 203 } | 204 } |
| 204 | 205 |
| 205 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with | 206 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with |
| 206 // just the mimetype. This is needed to drag files to WebView on Android | 207 // just the mimetype. This is needed to drag files to WebView on Android |
| 207 // platform. | 208 // platform. |
| 208 if ((meta_data_item.kind == DropData::Kind::FILENAME) && | 209 if ((meta_data_item.kind == DropData::Kind::FILENAME) && |
| 209 !meta_data_item.filename.empty()) { | 210 !meta_data_item.filename.empty()) { |
| 210 WebDragData::Item item; | 211 WebDragData::Item item; |
| 211 item.storageType = WebDragData::Item::StorageTypeFilename; | 212 item.storageType = WebDragData::Item::StorageTypeFilename; |
| 212 item.filenameData = meta_data_item.filename.AsUTF16Unsafe(); | 213 item.filenameData = blink::FilePathToWebString(meta_data_item.filename); |
| 213 item_list.push_back(item); | 214 item_list.push_back(item); |
| 214 continue; | 215 continue; |
| 215 } | 216 } |
| 216 | 217 |
| 217 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) { | 218 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) { |
| 218 WebDragData::Item item; | 219 WebDragData::Item item; |
| 219 item.storageType = WebDragData::Item::StorageTypeFileSystemFile; | 220 item.storageType = WebDragData::Item::StorageTypeFileSystemFile; |
| 220 item.fileSystemURL = meta_data_item.file_system_url; | 221 item.fileSystemURL = meta_data_item.file_system_url; |
| 221 item_list.push_back(item); | 222 item_list.push_back(item); |
| 222 continue; | 223 continue; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 234 | 235 |
| 235 // These fields are currently unused when dragging into WebKit. | 236 // These fields are currently unused when dragging into WebKit. |
| 236 DCHECK(drop_data.download_metadata.empty()); | 237 DCHECK(drop_data.download_metadata.empty()); |
| 237 DCHECK(drop_data.file_contents.empty()); | 238 DCHECK(drop_data.file_contents.empty()); |
| 238 DCHECK(drop_data.file_description_filename.empty()); | 239 DCHECK(drop_data.file_description_filename.empty()); |
| 239 | 240 |
| 240 if (!drop_data.text.is_null()) { | 241 if (!drop_data.text.is_null()) { |
| 241 WebDragData::Item item; | 242 WebDragData::Item item; |
| 242 item.storageType = WebDragData::Item::StorageTypeString; | 243 item.storageType = WebDragData::Item::StorageTypeString; |
| 243 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText); | 244 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText); |
| 244 item.stringData = drop_data.text.string(); | 245 item.stringData = WebString::fromUTF16(drop_data.text.string()); |
| 245 item_list.push_back(item); | 246 item_list.push_back(item); |
| 246 } | 247 } |
| 247 | 248 |
| 248 if (!drop_data.url.is_empty()) { | 249 if (!drop_data.url.is_empty()) { |
| 249 WebDragData::Item item; | 250 WebDragData::Item item; |
| 250 item.storageType = WebDragData::Item::StorageTypeString; | 251 item.storageType = WebDragData::Item::StorageTypeString; |
| 251 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList); | 252 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList); |
| 252 item.stringData = WebString::fromUTF8(drop_data.url.spec()); | 253 item.stringData = WebString::fromUTF8(drop_data.url.spec()); |
| 253 item.title = drop_data.url_title; | 254 item.title = WebString::fromUTF16(drop_data.url_title); |
| 254 item_list.push_back(item); | 255 item_list.push_back(item); |
| 255 } | 256 } |
| 256 | 257 |
| 257 if (!drop_data.html.is_null()) { | 258 if (!drop_data.html.is_null()) { |
| 258 WebDragData::Item item; | 259 WebDragData::Item item; |
| 259 item.storageType = WebDragData::Item::StorageTypeString; | 260 item.storageType = WebDragData::Item::StorageTypeString; |
| 260 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML); | 261 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML); |
| 261 item.stringData = drop_data.html.string(); | 262 item.stringData = WebString::fromUTF16(drop_data.html.string()); |
| 262 item.baseURL = drop_data.html_base_url; | 263 item.baseURL = drop_data.html_base_url; |
| 263 item_list.push_back(item); | 264 item_list.push_back(item); |
| 264 } | 265 } |
| 265 | 266 |
| 266 for (std::vector<ui::FileInfo>::const_iterator it = | 267 for (std::vector<ui::FileInfo>::const_iterator it = |
| 267 drop_data.filenames.begin(); | 268 drop_data.filenames.begin(); |
| 268 it != drop_data.filenames.end(); | 269 it != drop_data.filenames.end(); |
| 269 ++it) { | 270 ++it) { |
| 270 WebDragData::Item item; | 271 WebDragData::Item item; |
| 271 item.storageType = WebDragData::Item::StorageTypeFilename; | 272 item.storageType = WebDragData::Item::StorageTypeFilename; |
| 272 item.filenameData = it->path.AsUTF16Unsafe(); | 273 item.filenameData = blink::FilePathToWebString(it->path); |
| 273 item.displayNameData = it->display_name.AsUTF16Unsafe(); | 274 item.displayNameData = |
| 275 blink::FilePathToWebString(base::FilePath(it->display_name)); |
| 274 item_list.push_back(item); | 276 item_list.push_back(item); |
| 275 } | 277 } |
| 276 | 278 |
| 277 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it = | 279 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it = |
| 278 drop_data.file_system_files.begin(); | 280 drop_data.file_system_files.begin(); |
| 279 it != drop_data.file_system_files.end(); | 281 it != drop_data.file_system_files.end(); |
| 280 ++it) { | 282 ++it) { |
| 281 WebDragData::Item item; | 283 WebDragData::Item item; |
| 282 item.storageType = WebDragData::Item::StorageTypeFileSystemFile; | 284 item.storageType = WebDragData::Item::StorageTypeFileSystemFile; |
| 283 item.fileSystemURL = it->url; | 285 item.fileSystemURL = it->url; |
| 284 item.fileSystemFileSize = it->size; | 286 item.fileSystemFileSize = it->size; |
| 285 item.fileSystemId = blink::WebString::fromASCII(it->filesystem_id); | 287 item.fileSystemId = blink::WebString::fromASCII(it->filesystem_id); |
| 286 item_list.push_back(item); | 288 item_list.push_back(item); |
| 287 } | 289 } |
| 288 | 290 |
| 289 for (std::map<base::string16, base::string16>::const_iterator it = | 291 for (std::map<base::string16, base::string16>::const_iterator it = |
| 290 drop_data.custom_data.begin(); | 292 drop_data.custom_data.begin(); |
| 291 it != drop_data.custom_data.end(); | 293 it != drop_data.custom_data.end(); |
| 292 ++it) { | 294 ++it) { |
| 293 WebDragData::Item item; | 295 WebDragData::Item item; |
| 294 item.storageType = WebDragData::Item::StorageTypeString; | 296 item.storageType = WebDragData::Item::StorageTypeString; |
| 295 item.stringType = it->first; | 297 item.stringType = WebString::fromUTF16(it->first); |
| 296 item.stringData = it->second; | 298 item.stringData = WebString::fromUTF16(it->second); |
| 297 item_list.push_back(item); | 299 item_list.push_back(item); |
| 298 } | 300 } |
| 299 | 301 |
| 300 WebDragData result; | 302 WebDragData result; |
| 301 result.initialize(); | 303 result.initialize(); |
| 302 result.setItems(item_list); | 304 result.setItems(item_list); |
| 303 result.setFilesystemId(drop_data.filesystem_id); | 305 result.setFilesystemId(WebString::fromUTF16(drop_data.filesystem_id)); |
| 304 return result; | 306 return result; |
| 305 } | 307 } |
| 306 | 308 |
| 307 content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget = | 309 content::RenderWidget::CreateRenderWidgetFunction g_create_render_widget = |
| 308 nullptr; | 310 nullptr; |
| 309 | 311 |
| 310 content::RenderWidget::RenderWidgetInitializedCallback | 312 content::RenderWidget::RenderWidgetInitializedCallback |
| 311 g_render_widget_initialized = nullptr; | 313 g_render_widget_initialized = nullptr; |
| 312 | 314 |
| 313 ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) { | 315 ui::TextInputType ConvertWebTextInputType(blink::WebTextInputType type) { |
| (...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1483 } | 1485 } |
| 1484 | 1486 |
| 1485 WebRect RenderWidget::viewRect() { | 1487 WebRect RenderWidget::viewRect() { |
| 1486 WebRect rect = view_screen_rect_; | 1488 WebRect rect = view_screen_rect_; |
| 1487 ScreenRectToEmulatedIfNeeded(&rect); | 1489 ScreenRectToEmulatedIfNeeded(&rect); |
| 1488 return rect; | 1490 return rect; |
| 1489 } | 1491 } |
| 1490 | 1492 |
| 1491 void RenderWidget::setToolTipText(const blink::WebString& text, | 1493 void RenderWidget::setToolTipText(const blink::WebString& text, |
| 1492 WebTextDirection hint) { | 1494 WebTextDirection hint) { |
| 1493 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint)); | 1495 Send(new ViewHostMsg_SetTooltipText(routing_id_, text.utf16(), hint)); |
| 1494 } | 1496 } |
| 1495 | 1497 |
| 1496 void RenderWidget::setWindowRect(const WebRect& rect_in_screen) { | 1498 void RenderWidget::setWindowRect(const WebRect& rect_in_screen) { |
| 1497 WebRect window_rect = rect_in_screen; | 1499 WebRect window_rect = rect_in_screen; |
| 1498 EmulatedToScreenRectIfNeeded(&window_rect); | 1500 EmulatedToScreenRectIfNeeded(&window_rect); |
| 1499 | 1501 |
| 1500 if (!resizing_mode_selector_->is_synchronous_mode()) { | 1502 if (!resizing_mode_selector_->is_synchronous_mode()) { |
| 1501 if (did_show_) { | 1503 if (did_show_) { |
| 1502 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect)); | 1504 Send(new ViewHostMsg_RequestMove(routing_id_, window_rect)); |
| 1503 SetPendingWindowRect(window_rect); | 1505 SetPendingWindowRect(window_rect); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1540 GetWebWidget()->applyReplacementRange( | 1542 GetWebWidget()->applyReplacementRange( |
| 1541 WebRange(replacement_range.start(), replacement_range.length())); | 1543 WebRange(replacement_range.start(), replacement_range.length())); |
| 1542 } | 1544 } |
| 1543 | 1545 |
| 1544 if (!GetWebWidget()) | 1546 if (!GetWebWidget()) |
| 1545 return; | 1547 return; |
| 1546 ImeEventGuard guard(this); | 1548 ImeEventGuard guard(this); |
| 1547 blink::WebInputMethodController* controller = GetInputMethodController(); | 1549 blink::WebInputMethodController* controller = GetInputMethodController(); |
| 1548 if (!controller || | 1550 if (!controller || |
| 1549 !controller->setComposition( | 1551 !controller->setComposition( |
| 1550 text, WebVector<WebCompositionUnderline>(underlines), selection_start, | 1552 WebString::fromUTF16(text), |
| 1553 WebVector<WebCompositionUnderline>(underlines), selection_start, |
| 1551 selection_end)) { | 1554 selection_end)) { |
| 1552 // If we failed to set the composition text, then we need to let the browser | 1555 // If we failed to set the composition text, then we need to let the browser |
| 1553 // process to cancel the input method's ongoing composition session, to make | 1556 // process to cancel the input method's ongoing composition session, to make |
| 1554 // sure we are in a consistent state. | 1557 // sure we are in a consistent state. |
| 1555 Send(new InputHostMsg_ImeCancelComposition(routing_id())); | 1558 Send(new InputHostMsg_ImeCancelComposition(routing_id())); |
| 1556 } | 1559 } |
| 1557 UpdateCompositionInfo(false /* not an immediate request */); | 1560 UpdateCompositionInfo(false /* not an immediate request */); |
| 1558 } | 1561 } |
| 1559 | 1562 |
| 1560 void RenderWidget::OnImeCommitText( | 1563 void RenderWidget::OnImeCommitText( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1575 if (replacement_range.IsValid()) { | 1578 if (replacement_range.IsValid()) { |
| 1576 GetWebWidget()->applyReplacementRange( | 1579 GetWebWidget()->applyReplacementRange( |
| 1577 WebRange(replacement_range.start(), replacement_range.length())); | 1580 WebRange(replacement_range.start(), replacement_range.length())); |
| 1578 } | 1581 } |
| 1579 | 1582 |
| 1580 if (!GetWebWidget()) | 1583 if (!GetWebWidget()) |
| 1581 return; | 1584 return; |
| 1582 ImeEventGuard guard(this); | 1585 ImeEventGuard guard(this); |
| 1583 input_handler_->set_handling_input_event(true); | 1586 input_handler_->set_handling_input_event(true); |
| 1584 if (auto* controller = GetInputMethodController()) | 1587 if (auto* controller = GetInputMethodController()) |
| 1585 controller->commitText(text, WebVector<WebCompositionUnderline>(underlines), | 1588 controller->commitText(WebString::fromUTF16(text), |
| 1589 WebVector<WebCompositionUnderline>(underlines), |
| 1586 relative_cursor_pos); | 1590 relative_cursor_pos); |
| 1587 input_handler_->set_handling_input_event(false); | 1591 input_handler_->set_handling_input_event(false); |
| 1588 UpdateCompositionInfo(false /* not an immediate request */); | 1592 UpdateCompositionInfo(false /* not an immediate request */); |
| 1589 } | 1593 } |
| 1590 | 1594 |
| 1591 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { | 1595 void RenderWidget::OnImeFinishComposingText(bool keep_selection) { |
| 1592 if (!ShouldHandleImeEvents()) | 1596 if (!ShouldHandleImeEvents()) |
| 1593 return; | 1597 return; |
| 1594 | 1598 |
| 1595 #if BUILDFLAG(ENABLE_PLUGINS) | 1599 #if BUILDFLAG(ENABLE_PLUGINS) |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2274 // browser side (https://crbug.com/669219). | 2278 // browser side (https://crbug.com/669219). |
| 2275 // If there is no WebFrameWidget, then there will be no | 2279 // If there is no WebFrameWidget, then there will be no |
| 2276 // InputMethodControllers for a WebLocalFrame. | 2280 // InputMethodControllers for a WebLocalFrame. |
| 2277 return nullptr; | 2281 return nullptr; |
| 2278 } | 2282 } |
| 2279 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) | 2283 return static_cast<blink::WebFrameWidget*>(GetWebWidget()) |
| 2280 ->getActiveWebInputMethodController(); | 2284 ->getActiveWebInputMethodController(); |
| 2281 } | 2285 } |
| 2282 | 2286 |
| 2283 } // namespace content | 2287 } // namespace content |
| OLD | NEW |