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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 DCHECK(sizes->empty()); | 385 DCHECK(sizes->empty()); |
386 sizes->reserve(web_sizes.size()); | 386 sizes->reserve(web_sizes.size()); |
387 for (size_t i = 0; i < web_sizes.size(); ++i) | 387 for (size_t i = 0; i < web_sizes.size(); ++i) |
388 sizes->push_back(gfx::Size(web_sizes[i])); | 388 sizes->push_back(gfx::Size(web_sizes[i])); |
389 } | 389 } |
390 | 390 |
391 /////////////////////////////////////////////////////////////////////////////// | 391 /////////////////////////////////////////////////////////////////////////////// |
392 | 392 |
393 namespace { | 393 namespace { |
394 | 394 |
| 395 WebDragData DropMetaDataToWebDragData( |
| 396 const std::vector<DropData::Metadata>& drop_meta_data) { |
| 397 std::vector<WebDragData::Item> item_list; |
| 398 for (const auto& meta_data_item : drop_meta_data) { |
| 399 if (meta_data_item.kind == DropData::Kind::STRING) { |
| 400 WebDragData::Item item; |
| 401 item.storageType = WebDragData::Item::StorageTypeString; |
| 402 item.stringType = meta_data_item.mime_type; |
| 403 // Have to pass a dummy URL here instead of an empty URL because the |
| 404 // DropData received by browser_plugins goes through a round trip: |
| 405 // DropData::MetaData --> WebDragData-->DropData. In the end, DropData |
| 406 // will contain an empty URL (which means no URL is dragged) if the URL in |
| 407 // WebDragData is empty. |
| 408 if (base::EqualsASCII(meta_data_item.mime_type, |
| 409 ui::Clipboard::kMimeTypeURIList)) { |
| 410 item.stringData = WebString::fromUTF8("about:dragdrop-placeholder"); |
| 411 } |
| 412 item_list.push_back(item); |
| 413 continue; |
| 414 } |
| 415 |
| 416 // TODO(hush): crbug.com/584789. Blink needs to support creating a file with |
| 417 // just the mimetype. This is needed to drag files to WebView on Android |
| 418 // platform. |
| 419 if ((meta_data_item.kind == DropData::Kind::FILENAME) && |
| 420 !meta_data_item.filename.empty()) { |
| 421 WebDragData::Item item; |
| 422 item.storageType = WebDragData::Item::StorageTypeFilename; |
| 423 item.filenameData = meta_data_item.filename.AsUTF16Unsafe(); |
| 424 item_list.push_back(item); |
| 425 continue; |
| 426 } |
| 427 |
| 428 if (meta_data_item.kind == DropData::Kind::FILESYSTEMFILE) { |
| 429 WebDragData::Item item; |
| 430 item.storageType = WebDragData::Item::StorageTypeFileSystemFile; |
| 431 item.fileSystemURL = meta_data_item.file_system_url; |
| 432 item_list.push_back(item); |
| 433 continue; |
| 434 } |
| 435 } |
| 436 |
| 437 WebDragData result; |
| 438 result.initialize(); |
| 439 result.setItems(item_list); |
| 440 return result; |
| 441 } |
| 442 |
395 WebDragData DropDataToWebDragData(const DropData& drop_data) { | 443 WebDragData DropDataToWebDragData(const DropData& drop_data) { |
396 std::vector<WebDragData::Item> item_list; | 444 std::vector<WebDragData::Item> item_list; |
397 | 445 |
398 // These fields are currently unused when dragging into WebKit. | 446 // These fields are currently unused when dragging into WebKit. |
399 DCHECK(drop_data.download_metadata.empty()); | 447 DCHECK(drop_data.download_metadata.empty()); |
400 DCHECK(drop_data.file_contents.empty()); | 448 DCHECK(drop_data.file_contents.empty()); |
401 DCHECK(drop_data.file_description_filename.empty()); | 449 DCHECK(drop_data.file_description_filename.empty()); |
402 | 450 |
403 if (!drop_data.text.is_null()) { | 451 if (!drop_data.text.is_null()) { |
404 WebDragData::Item item; | 452 WebDragData::Item item; |
405 item.storageType = WebDragData::Item::StorageTypeString; | 453 item.storageType = WebDragData::Item::StorageTypeString; |
406 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText); | 454 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeText); |
407 item.stringData = drop_data.text.string(); | 455 item.stringData = drop_data.text.string(); |
408 item_list.push_back(item); | 456 item_list.push_back(item); |
409 } | 457 } |
410 | 458 |
411 // TODO(dcheng): Do we need to distinguish between null and empty URLs? Is it | |
412 // meaningful to write an empty URL to the clipboard? | |
413 if (!drop_data.url.is_empty()) { | 459 if (!drop_data.url.is_empty()) { |
414 WebDragData::Item item; | 460 WebDragData::Item item; |
415 item.storageType = WebDragData::Item::StorageTypeString; | 461 item.storageType = WebDragData::Item::StorageTypeString; |
416 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList); | 462 item.stringType = WebString::fromUTF8(ui::Clipboard::kMimeTypeURIList); |
417 item.stringData = WebString::fromUTF8(drop_data.url.spec()); | 463 item.stringData = WebString::fromUTF8(drop_data.url.spec()); |
418 item.title = drop_data.url_title; | 464 item.title = drop_data.url_title; |
419 item_list.push_back(item); | 465 item_list.push_back(item); |
420 } | 466 } |
421 | 467 |
422 if (!drop_data.html.is_null()) { | 468 if (!drop_data.html.is_null()) { |
(...skipping 1901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2324 | 2370 |
2325 enabled_bindings_ |= enabled_bindings_flags; | 2371 enabled_bindings_ |= enabled_bindings_flags; |
2326 | 2372 |
2327 // Keep track of the total bindings accumulated in this process. | 2373 // Keep track of the total bindings accumulated in this process. |
2328 RenderProcess::current()->AddBindings(enabled_bindings_flags); | 2374 RenderProcess::current()->AddBindings(enabled_bindings_flags); |
2329 | 2375 |
2330 if (main_render_frame_) | 2376 if (main_render_frame_) |
2331 main_render_frame_->MaybeEnableMojoBindings(); | 2377 main_render_frame_->MaybeEnableMojoBindings(); |
2332 } | 2378 } |
2333 | 2379 |
2334 void RenderViewImpl::OnDragTargetDragEnter(const DropData& drop_data, | 2380 void RenderViewImpl::OnDragTargetDragEnter( |
2335 const gfx::Point& client_point, | 2381 const std::vector<DropData::Metadata>& drop_meta_data, |
2336 const gfx::Point& screen_point, | 2382 const gfx::Point& client_point, |
2337 WebDragOperationsMask ops, | 2383 const gfx::Point& screen_point, |
2338 int key_modifiers) { | 2384 WebDragOperationsMask ops, |
| 2385 int key_modifiers) { |
2339 WebDragOperation operation = webview()->dragTargetDragEnter( | 2386 WebDragOperation operation = webview()->dragTargetDragEnter( |
2340 DropDataToWebDragData(drop_data), | 2387 DropMetaDataToWebDragData(drop_meta_data), client_point, screen_point, |
2341 ConvertWindowPointToViewport(client_point), | 2388 ops, key_modifiers); |
2342 screen_point, | |
2343 ops, | |
2344 key_modifiers); | |
2345 | 2389 |
2346 Send(new DragHostMsg_UpdateDragCursor(GetRoutingID(), operation)); | 2390 Send(new DragHostMsg_UpdateDragCursor(GetRoutingID(), operation)); |
2347 } | 2391 } |
2348 | 2392 |
2349 void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point, | 2393 void RenderViewImpl::OnDragTargetDragOver(const gfx::Point& client_point, |
2350 const gfx::Point& screen_point, | 2394 const gfx::Point& screen_point, |
2351 WebDragOperationsMask ops, | 2395 WebDragOperationsMask ops, |
2352 int key_modifiers) { | 2396 int key_modifiers) { |
2353 WebDragOperation operation = webview()->dragTargetDragOver( | 2397 WebDragOperation operation = webview()->dragTargetDragOver( |
2354 ConvertWindowPointToViewport(client_point), | 2398 ConvertWindowPointToViewport(client_point), |
2355 screen_point, | 2399 screen_point, |
2356 ops, | 2400 ops, |
2357 key_modifiers); | 2401 key_modifiers); |
2358 | 2402 |
2359 Send(new DragHostMsg_UpdateDragCursor(GetRoutingID(), operation)); | 2403 Send(new DragHostMsg_UpdateDragCursor(GetRoutingID(), operation)); |
2360 } | 2404 } |
2361 | 2405 |
2362 void RenderViewImpl::OnDragTargetDragLeave() { | 2406 void RenderViewImpl::OnDragTargetDragLeave() { |
2363 webview()->dragTargetDragLeave(); | 2407 webview()->dragTargetDragLeave(); |
2364 } | 2408 } |
2365 | 2409 |
2366 void RenderViewImpl::OnDragTargetDrop(const gfx::Point& client_point, | 2410 void RenderViewImpl::OnDragTargetDrop(const DropData& drop_data, |
| 2411 const gfx::Point& client_point, |
2367 const gfx::Point& screen_point, | 2412 const gfx::Point& screen_point, |
2368 int key_modifiers) { | 2413 int key_modifiers) { |
2369 webview()->dragTargetDrop( | 2414 webview()->dragTargetDrop(DropDataToWebDragData(drop_data), client_point, |
2370 ConvertWindowPointToViewport(client_point), screen_point, key_modifiers); | 2415 screen_point, key_modifiers); |
2371 } | 2416 } |
2372 | 2417 |
2373 void RenderViewImpl::OnDragSourceEnded(const gfx::Point& client_point, | 2418 void RenderViewImpl::OnDragSourceEnded(const gfx::Point& client_point, |
2374 const gfx::Point& screen_point, | 2419 const gfx::Point& screen_point, |
2375 WebDragOperation op) { | 2420 WebDragOperation op) { |
2376 webview()->dragSourceEndedAt( | 2421 webview()->dragSourceEndedAt( |
2377 ConvertWindowPointToViewport(client_point), screen_point, op); | 2422 ConvertWindowPointToViewport(client_point), screen_point, op); |
2378 } | 2423 } |
2379 | 2424 |
2380 void RenderViewImpl::OnDragSourceSystemDragEnded() { | 2425 void RenderViewImpl::OnDragSourceSystemDragEnded() { |
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3236 return render_frame->focused_pepper_plugin(); | 3281 return render_frame->focused_pepper_plugin(); |
3237 } | 3282 } |
3238 frame = frame->traverseNext(false); | 3283 frame = frame->traverseNext(false); |
3239 } | 3284 } |
3240 | 3285 |
3241 return nullptr; | 3286 return nullptr; |
3242 } | 3287 } |
3243 #endif | 3288 #endif |
3244 | 3289 |
3245 } // namespace content | 3290 } // namespace content |
OLD | NEW |