Chromium Code Reviews| 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_view_impl.h" | 5 #include "content/renderer/render_view_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 DCHECK(sizes->empty()); | 372 DCHECK(sizes->empty()); |
| 373 sizes->reserve(web_sizes.size()); | 373 sizes->reserve(web_sizes.size()); |
| 374 for (size_t i = 0; i < web_sizes.size(); ++i) | 374 for (size_t i = 0; i < web_sizes.size(); ++i) |
| 375 sizes->push_back(gfx::Size(web_sizes[i])); | 375 sizes->push_back(gfx::Size(web_sizes[i])); |
| 376 } | 376 } |
| 377 | 377 |
| 378 /////////////////////////////////////////////////////////////////////////////// | 378 /////////////////////////////////////////////////////////////////////////////// |
| 379 | 379 |
| 380 namespace { | 380 namespace { |
| 381 | 381 |
| 382 WebDragData DropMetaDataToWebDragData( | |
| 383 const std::vector<DropData::Metadata>& drop_meta_data) { | |
| 384 std::vector<WebDragData::Item> item_list; | |
| 385 for (const auto& meta_data_item : drop_meta_data) { | |
| 386 if (meta_data_item.kind == DropData::Kind::STRING) { | |
| 387 WebDragData::Item item; | |
| 388 item.storageType = WebDragData::Item::StorageTypeString; | |
| 389 item.stringType = meta_data_item.mime_type; | |
| 390 // Have to pass a dummy URL here instead of an empty URL because the | |
| 391 // DropData received by browser_plugins goes through a round trip: | |
| 392 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData | |
| 393 // will contain an empty URL (which means no URL is dragged) if the URL in | |
| 394 // WebDragData is empty. | |
| 395 if (base::EqualsASCII(meta_data_item.mime_type, | |
| 396 ui::Clipboard::kMimeTypeURIList)) { | |
| 397 item.stringData = WebString::fromUTF8("about:dragdrop-placeholder"); | |
| 398 } | |
| 399 item_list.push_back(item); | |
| 400 continue; | |
| 401 } | |
| 402 | |
| 403 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with | |
| 404 // just the mimetype. This is needed to drag files to WebView on Android | |
| 405 // platform. | |
| 406 if ((meta_data_item.kind == DropData::Kind::FILENAME) && | |
| 407 !meta_data_item.filename.empty()) { | |
| 408 WebDragData::Item item; | |
| 409 item.storageType = WebDragData::Item::StorageTypeFilename; | |
| 410 item.filenameData = meta_data_item.filename.AsUTF16Unsafe(); | |
| 411 item_list.push_back(item); | |
| 412 continue; | |
| 413 } | |
| 414 | |
| 415 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) { | |
| 416 WebDragData::Item item; | |
| 417 item.storageType = WebDragData::Item::StorageTypeFileSystemFile; | |
| 418 item.fileSystemURL = meta_data_item.file_system_url; | |
| 419 item_list.push_back(item); | |
| 420 continue; | |
| 421 } | |
| 422 } | |
| 423 | |
| 424 WebDragData result; | |
| 425 result.initialize(); | |
| 426 result.setItems(item_list); | |
| 427 return result; | |
| 428 } | |
| 429 | |
| 430 WebDragData DropDataToWebDragData(const DropData& drop_data) { | |
| 431 std::vector<WebDragData::Item> item_list; | |
| 432 | |
| 433 // These fields are currently unused when dragging into WebKit. | |
| 434 DCHECK(drop_data.download_metadata.empty()); | |
| 435 DCHECK(drop_data.file_contents.empty()); | |
| 436 DCHECK(drop_data.file_description_filename.empty()); | |
| 437 | |
| 438 if (!drop_data.text.is_null()) { | |
| 439 WebDragData::Item item; | |
| 440 item.storageType = WebDragData::Item::StorageTypeString; | |
| 441 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText); | |
| 442 item.stringData = drop_data.text.string(); | |
| 443 item_list.push_back(item); | |
| 444 } | |
| 445 | |
| 446 if (!drop_data.url.is_empty()) { | |
| 447 WebDragData::Item item; | |
| 448 item.storageType = WebDragData::Item::StorageTypeString; | |
| 449 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList); | |
| 450 item.stringData = WebString::fromUTF8(drop_data.url.spec()); | |
| 451 item.title = drop_data.url_title; | |
| 452 item_list.push_back(item); | |
| 453 } | |
| 454 | |
| 455 if (!drop_data.html.is_null()) { | |
| 456 WebDragData::Item item; | |
| 457 item.storageType = WebDragData::Item::StorageTypeString; | |
| 458 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeHTML); | |
| 459 item.stringData = drop_data.html.string(); | |
| 460 item.baseURL = drop_data.html_base_url; | |
| 461 item_list.push_back(item); | |
| 462 } | |
| 463 | |
| 464 for (std::vector<ui::FileInfo>::const_iterator it = | |
| 465 drop_data.filenames.begin(); | |
| 466 it != drop_data.filenames.end(); | |
| 467 ++it) { | |
| 468 WebDragData::Item item; | |
| 469 item.storageType = WebDragData::Item::StorageTypeFilename; | |
| 470 item.filenameData = it->path.AsUTF16Unsafe(); | |
| 471 item.displayNameData = it->display_name.AsUTF16Unsafe(); | |
| 472 item_list.push_back(item); | |
| 473 } | |
| 474 | |
| 475 for (std::vector<DropData::FileSystemFileInfo>::const_iterator it = | |
| 476 drop_data.file_system_files.begin(); | |
| 477 it != drop_data.file_system_files.end(); | |
| 478 ++it) { | |
| 479 WebDragData::Item item; | |
| 480 item.storageType = WebDragData::Item::StorageTypeFileSystemFile; | |
| 481 item.fileSystemURL = it->url; | |
| 482 item.fileSystemFileSize = it->size; | |
| 483 item_list.push_back(item); | |
| 484 } | |
| 485 | |
| 486 for (std::map<base::string16, base::string16>::const_iterator it = | |
| 487 drop_data.custom_data.begin(); | |
| 488 it != drop_data.custom_data.end(); | |
| 489 ++it) { | |
| 490 WebDragData::Item item; | |
| 491 item.storageType = WebDragData::Item::StorageTypeString; | |
| 492 item.stringType = it->first; | |
| 493 item.stringData = it->second; | |
| 494 item_list.push_back(item); | |
| 495 } | |
| 496 | |
| 497 WebDragData result; | |
| 498 result.initialize(); | |
| 499 result.setItems(item_list); | |
| 500 result.setFilesystemId(drop_data.filesystem_id); | |
| 501 return result; | |
| 502 } | |
| 503 | |
| 504 typedef void (*SetFontFamilyWrapper)(blink::WebSettings*, | 382 typedef void (*SetFontFamilyWrapper)(blink::WebSettings*, |
| 505 const base::string16&, | 383 const base::string16&, |
| 506 UScriptCode); | 384 UScriptCode); |
| 507 | 385 |
| 508 void SetStandardFontFamilyWrapper(WebSettings* settings, | 386 void SetStandardFontFamilyWrapper(WebSettings* settings, |
| 509 const base::string16& font, | 387 const base::string16& font, |
| 510 UScriptCode script) { | 388 UScriptCode script) { |
| 511 settings->setStandardFontFamily(font, script); | 389 settings->setStandardFontFamily(font, script); |
| 512 } | 390 } |
| 513 | 391 |
| (...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1300 } | 1178 } |
| 1301 | 1179 |
| 1302 bool handled = true; | 1180 bool handled = true; |
| 1303 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message) | 1181 IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message) |
| 1304 IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand, OnExecuteEditCommand) | 1182 IPC_MESSAGE_HANDLER(InputMsg_ExecuteEditCommand, OnExecuteEditCommand) |
| 1305 IPC_MESSAGE_HANDLER(InputMsg_MoveCaret, OnMoveCaret) | 1183 IPC_MESSAGE_HANDLER(InputMsg_MoveCaret, OnMoveCaret) |
| 1306 IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect, | 1184 IPC_MESSAGE_HANDLER(InputMsg_ScrollFocusedEditableNodeIntoRect, |
| 1307 OnScrollFocusedEditableNodeIntoRect) | 1185 OnScrollFocusedEditableNodeIntoRect) |
| 1308 IPC_MESSAGE_HANDLER(ViewMsg_SetPageScale, OnSetPageScale) | 1186 IPC_MESSAGE_HANDLER(ViewMsg_SetPageScale, OnSetPageScale) |
| 1309 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) | 1187 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) |
| 1310 IPC_MESSAGE_HANDLER(DragMsg_TargetDragEnter, OnDragTargetDragEnter) | |
| 1311 IPC_MESSAGE_HANDLER(DragMsg_TargetDragOver, OnDragTargetDragOver) | |
| 1312 IPC_MESSAGE_HANDLER(DragMsg_TargetDragLeave, OnDragTargetDragLeave) | |
| 1313 IPC_MESSAGE_HANDLER(DragMsg_TargetDrop, OnDragTargetDrop) | |
| 1314 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded) | 1188 IPC_MESSAGE_HANDLER(DragMsg_SourceEnded, OnDragSourceEnded) |
| 1315 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, | 1189 IPC_MESSAGE_HANDLER(DragMsg_SourceSystemDragEnded, |
| 1316 OnDragSourceSystemDragEnded) | 1190 OnDragSourceSystemDragEnded) |
| 1317 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) | 1191 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) |
| 1318 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) | 1192 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) |
| 1319 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) | 1193 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) |
| 1320 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) | 1194 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) |
| 1321 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, | 1195 IPC_MESSAGE_HANDLER(ViewMsg_EnumerateDirectoryResponse, |
| 1322 OnEnumerateDirectoryResponse) | 1196 OnEnumerateDirectoryResponse) |
| 1323 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) | 1197 IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage) |
| (...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2083 ConvertViewportToWindowViaWidget(&bounding_box_in_window); | 1957 ConvertViewportToWindowViaWidget(&bounding_box_in_window); |
| 2084 return gfx::RectF(bounding_box_in_window); | 1958 return gfx::RectF(bounding_box_in_window); |
| 2085 } | 1959 } |
| 2086 | 1960 |
| 2087 bool RenderViewImpl::HasAddedInputHandler() const { | 1961 bool RenderViewImpl::HasAddedInputHandler() const { |
| 2088 return has_added_input_handler_; | 1962 return has_added_input_handler_; |
| 2089 } | 1963 } |
| 2090 | 1964 |
| 2091 gfx::Point RenderViewImpl::ConvertWindowPointToViewport( | 1965 gfx::Point RenderViewImpl::ConvertWindowPointToViewport( |
| 2092 const gfx::Point& point) { | 1966 const gfx::Point& point) { |
| 2093 blink::WebFloatRect point_in_viewport(point.x(), point.y(), 0, 0); | 1967 return RenderWidget::ConvertWindowPointToViewport(point); |
|
dcheng
2016/11/09 20:23:17
Do we still need to forward this, or can the calle
paulmeyer
2016/11/09 23:19:11
Nope, fixed.
| |
| 2094 convertWindowToViewport(&point_in_viewport); | |
| 2095 return gfx::Point(point_in_viewport.x, point_in_viewport.y); | |
| 2096 } | 1968 } |
| 2097 | 1969 |
| 2098 void RenderViewImpl::didChangeIcon(WebLocalFrame* frame, | 1970 void RenderViewImpl::didChangeIcon(WebLocalFrame* frame, |
| 2099 WebIconURL::Type icon_type) { | 1971 WebIconURL::Type icon_type) { |
| 2100 if (frame->parent()) | 1972 if (frame->parent()) |
| 2101 return; | 1973 return; |
| 2102 | 1974 |
| 2103 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type); | 1975 WebVector<WebIconURL> icon_urls = frame->iconURLs(icon_type); |
| 2104 std::vector<FaviconURL> urls; | 1976 std::vector<FaviconURL> urls; |
| 2105 for (size_t i = 0; i < icon_urls.size(); i++) { | 1977 for (size_t i = 0; i < icon_urls.size(); i++) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2254 | 2126 |
| 2255 enabled_bindings_ |= enabled_bindings_flags; | 2127 enabled_bindings_ |= enabled_bindings_flags; |
| 2256 | 2128 |
| 2257 // Keep track of the total bindings accumulated in this process. | 2129 // Keep track of the total bindings accumulated in this process. |
| 2258 RenderProcess::current()->AddBindings(enabled_bindings_flags); | 2130 RenderProcess::current()->AddBindings(enabled_bindings_flags); |
| 2259 | 2131 |
| 2260 if (main_render_frame_) | 2132 if (main_render_frame_) |
| 2261 main_render_frame_->MaybeEnableMojoBindings(); | 2133 main_render_frame_->MaybeEnableMojoBindings(); |
| 2262 } | 2134 } |
| 2263 | 2135 |
| 2264 void RenderViewImpl::OnDragTargetDragEnter( | |
| 2265 const std::vector<DropData::Metadata>& drop_meta_data, | |
| 2266 const gfx::Point& client_point, | |
| 2267 const gfx::Point& screen_point, | |
| 2268 WebDragOperationsMask ops, | |
| 2269 int key_modifiers) { | |
| 2270 WebDragOperation operation = webview()->dragTargetDragEnter( | |
| 2271 DropMetaDataToWebDragData(drop_meta_data), client_point, screen_point, | |
| 2272 ops, key_modifiers); | |
| 2273 | |
| 2274 Send(new DragHostMsg_UpdateDragCursor(GetRoutingID(), operation)); | |
| 2275 } | |
| 2276 | |
| 2277 void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point, | |
| 2278 const gfx::Point& screen_point, | |
| 2279 WebDragOperationsMask ops, | |
| 2280 int key_modifiers) { | |
| 2281 WebDragOperation operation = webview()->dragTargetDragOver( | |
| 2282 ConvertWindowPointToViewport(client_point), | |
| 2283 screen_point, | |
| 2284 ops, | |
| 2285 key_modifiers); | |
| 2286 | |
| 2287 Send(new DragHostMsg_UpdateDragCursor(GetRoutingID(), operation)); | |
| 2288 } | |
| 2289 | |
| 2290 void RenderViewImpl::OnDragTargetDragLeave() { | |
| 2291 webview()->dragTargetDragLeave(); | |
| 2292 } | |
| 2293 | |
| 2294 void RenderViewImpl::OnDragTargetDrop(const DropData& drop_data, | |
| 2295 const gfx::Point& client_point, | |
| 2296 const gfx::Point& screen_point, | |
| 2297 int key_modifiers) { | |
| 2298 webview()->dragTargetDrop(DropDataToWebDragData(drop_data), | |
| 2299 ConvertWindowPointToViewport(client_point), | |
| 2300 screen_point, key_modifiers); | |
| 2301 } | |
| 2302 | |
| 2303 void RenderViewImpl::OnDragSourceEnded(const gfx::Point& client_point, | 2136 void RenderViewImpl::OnDragSourceEnded(const gfx::Point& client_point, |
| 2304 const gfx::Point& screen_point, | 2137 const gfx::Point& screen_point, |
| 2305 WebDragOperation op) { | 2138 WebDragOperation op) { |
| 2306 webview()->dragSourceEndedAt( | 2139 webview()->dragSourceEndedAt( |
| 2307 ConvertWindowPointToViewport(client_point), screen_point, op); | 2140 ConvertWindowPointToViewport(client_point), screen_point, op); |
| 2308 } | 2141 } |
| 2309 | 2142 |
| 2310 void RenderViewImpl::OnDragSourceSystemDragEnded() { | 2143 void RenderViewImpl::OnDragSourceSystemDragEnded() { |
| 2311 webview()->dragSourceSystemDragEnded(); | 2144 webview()->dragSourceSystemDragEnded(); |
| 2312 } | 2145 } |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2967 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 2800 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 2968 } | 2801 } |
| 2969 | 2802 |
| 2970 std::unique_ptr<InputEventAck> ack( | 2803 std::unique_ptr<InputEventAck> ack( |
| 2971 new InputEventAck(InputEventAckSource::MAIN_THREAD, input_event->type, | 2804 new InputEventAck(InputEventAckSource::MAIN_THREAD, input_event->type, |
| 2972 INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); | 2805 INPUT_EVENT_ACK_STATE_NOT_CONSUMED)); |
| 2973 OnInputEventAck(std::move(ack)); | 2806 OnInputEventAck(std::move(ack)); |
| 2974 } | 2807 } |
| 2975 | 2808 |
| 2976 } // namespace content | 2809 } // namespace content |
| OLD | NEW |