Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 2475443003: Drag-and-drop: Move startDrag out of WebView/RenderView. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/browser/renderer_host/render_widget_host_impl.h" 5 #include "content/browser/renderer_host/render_widget_host_impl.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <set> 9 #include <set>
10 #include <tuple> 10 #include <tuple>
(...skipping 15 matching lines...) Expand all
26 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
27 #include "base/threading/thread_task_runner_handle.h" 27 #include "base/threading/thread_task_runner_handle.h"
28 #include "base/trace_event/trace_event.h" 28 #include "base/trace_event/trace_event.h"
29 #include "build/build_config.h" 29 #include "build/build_config.h"
30 #include "cc/base/switches.h" 30 #include "cc/base/switches.h"
31 #include "cc/output/compositor_frame.h" 31 #include "cc/output/compositor_frame.h"
32 #include "content/browser/accessibility/accessibility_mode_helper.h" 32 #include "content/browser/accessibility/accessibility_mode_helper.h"
33 #include "content/browser/accessibility/browser_accessibility_state_impl.h" 33 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
34 #include "content/browser/bad_message.h" 34 #include "content/browser/bad_message.h"
35 #include "content/browser/browser_plugin/browser_plugin_guest.h" 35 #include "content/browser/browser_plugin/browser_plugin_guest.h"
36 #include "content/browser/child_process_security_policy_impl.h"
36 #include "content/browser/gpu/compositor_util.h" 37 #include "content/browser/gpu/compositor_util.h"
37 #include "content/browser/renderer_host/dip_util.h" 38 #include "content/browser/renderer_host/dip_util.h"
38 #include "content/browser/renderer_host/frame_metadata_util.h" 39 #include "content/browser/renderer_host/frame_metadata_util.h"
39 #include "content/browser/renderer_host/input/input_router_config_helper.h" 40 #include "content/browser/renderer_host/input/input_router_config_helper.h"
40 #include "content/browser/renderer_host/input/input_router_impl.h" 41 #include "content/browser/renderer_host/input/input_router_impl.h"
41 #include "content/browser/renderer_host/input/synthetic_gesture.h" 42 #include "content/browser/renderer_host/input/synthetic_gesture.h"
42 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" 43 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h"
43 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" 44 #include "content/browser/renderer_host/input/synthetic_gesture_target.h"
44 #include "content/browser/renderer_host/input/timeout_monitor.h" 45 #include "content/browser/renderer_host/input/timeout_monitor.h"
45 #include "content/browser/renderer_host/input/touch_emulator.h" 46 #include "content/browser/renderer_host/input/touch_emulator.h"
46 #include "content/browser/renderer_host/render_process_host_impl.h" 47 #include "content/browser/renderer_host/render_process_host_impl.h"
48 #include "content/browser/renderer_host/render_view_host_delegate.h"
49 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
47 #include "content/browser/renderer_host/render_view_host_impl.h" 50 #include "content/browser/renderer_host/render_view_host_impl.h"
48 #include "content/browser/renderer_host/render_widget_helper.h" 51 #include "content/browser/renderer_host/render_widget_helper.h"
49 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" 52 #include "content/browser/renderer_host/render_widget_host_input_event_router.h"
50 #include "content/browser/renderer_host/render_widget_host_owner_delegate.h" 53 #include "content/browser/renderer_host/render_widget_host_owner_delegate.h"
51 #include "content/browser/renderer_host/render_widget_host_view_base.h" 54 #include "content/browser/renderer_host/render_widget_host_view_base.h"
52 #include "content/browser/service_worker/service_worker_context_wrapper.h" 55 #include "content/browser/service_worker/service_worker_context_wrapper.h"
53 #include "content/common/content_constants_internal.h" 56 #include "content/common/content_constants_internal.h"
54 #include "content/common/content_switches_internal.h" 57 #include "content/common/content_switches_internal.h"
55 #include "content/common/cursors/webcursor.h" 58 #include "content/common/cursors/webcursor.h"
59 #include "content/common/drag_messages.h"
56 #include "content/common/frame_messages.h" 60 #include "content/common/frame_messages.h"
57 #include "content/common/host_shared_bitmap_manager.h" 61 #include "content/common/host_shared_bitmap_manager.h"
58 #include "content/common/input_messages.h" 62 #include "content/common/input_messages.h"
59 #include "content/common/resize_params.h" 63 #include "content/common/resize_params.h"
60 #include "content/common/text_input_state.h" 64 #include "content/common/text_input_state.h"
61 #include "content/common/view_messages.h" 65 #include "content/common/view_messages.h"
66 #include "content/public/browser/browser_context.h"
62 #include "content/public/browser/native_web_keyboard_event.h" 67 #include "content/public/browser/native_web_keyboard_event.h"
63 #include "content/public/browser/notification_service.h" 68 #include "content/public/browser/notification_service.h"
64 #include "content/public/browser/notification_types.h" 69 #include "content/public/browser/notification_types.h"
65 #include "content/public/browser/render_widget_host_iterator.h" 70 #include "content/public/browser/render_widget_host_iterator.h"
66 #include "content/public/browser/storage_partition.h" 71 #include "content/public/browser/storage_partition.h"
67 #include "content/public/common/content_constants.h" 72 #include "content/public/common/content_constants.h"
68 #include "content/public/common/content_switches.h" 73 #include "content/public/common/content_switches.h"
69 #include "content/public/common/result_codes.h" 74 #include "content/public/common/result_codes.h"
70 #include "content/public/common/web_preferences.h" 75 #include "content/public/common/web_preferences.h"
71 #include "gpu/GLES2/gl2extchromium.h" 76 #include "gpu/GLES2/gl2extchromium.h"
72 #include "gpu/command_buffer/service/gpu_switches.h" 77 #include "gpu/command_buffer/service/gpu_switches.h"
73 #include "gpu/ipc/common/gpu_messages.h" 78 #include "gpu/ipc/common/gpu_messages.h"
74 #include "skia/ext/image_operations.h" 79 #include "skia/ext/image_operations.h"
75 #include "skia/ext/platform_canvas.h" 80 #include "skia/ext/platform_canvas.h"
76 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" 81 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
77 #include "ui/events/blink/web_input_event_traits.h" 82 #include "ui/events/blink/web_input_event_traits.h"
78 #include "ui/events/event.h" 83 #include "ui/events/event.h"
79 #include "ui/events/keycodes/keyboard_codes.h" 84 #include "ui/events/keycodes/keyboard_codes.h"
80 #include "ui/gfx/color_space.h" 85 #include "ui/gfx/color_space.h"
81 #include "ui/gfx/geometry/size_conversions.h" 86 #include "ui/gfx/geometry/size_conversions.h"
82 #include "ui/gfx/geometry/vector2d_conversions.h" 87 #include "ui/gfx/geometry/vector2d_conversions.h"
88 #include "ui/gfx/image/image_skia.h"
83 #include "ui/gfx/skbitmap_operations.h" 89 #include "ui/gfx/skbitmap_operations.h"
84 #include "ui/snapshot/snapshot.h" 90 #include "ui/snapshot/snapshot.h"
85 91
86 #if defined(OS_MACOSX) 92 #if defined(OS_MACOSX)
87 #include "device/power_save_blocker/power_save_blocker.h" 93 #include "device/power_save_blocker/power_save_blocker.h"
88 #include "ui/accelerated_widget_mac/window_resize_helper_mac.h" 94 #include "ui/accelerated_widget_mac/window_resize_helper_mac.h"
89 #endif 95 #endif
90 96
91 using base::Time; 97 using base::Time;
92 using base::TimeDelta; 98 using base::TimeDelta;
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 OnShowDisambiguationPopup) 495 OnShowDisambiguationPopup)
490 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionBoundsChanged, 496 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionBoundsChanged,
491 OnSelectionBoundsChanged) 497 OnSelectionBoundsChanged)
492 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged, 498 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged,
493 OnImeCompositionRangeChanged) 499 OnImeCompositionRangeChanged)
494 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstPaintAfterLoad, 500 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstPaintAfterLoad,
495 OnFirstPaintAfterLoad) 501 OnFirstPaintAfterLoad)
496 IPC_MESSAGE_HANDLER(ViewHostMsg_ForwardCompositorProto, 502 IPC_MESSAGE_HANDLER(ViewHostMsg_ForwardCompositorProto,
497 OnForwardCompositorProto) 503 OnForwardCompositorProto)
498 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrames, OnSetNeedsBeginFrames) 504 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrames, OnSetNeedsBeginFrames)
505 IPC_MESSAGE_HANDLER(DragHostMsg_StartDragging, OnStartDragging)
499 IPC_MESSAGE_UNHANDLED(handled = false) 506 IPC_MESSAGE_UNHANDLED(handled = false)
500 IPC_END_MESSAGE_MAP() 507 IPC_END_MESSAGE_MAP()
501 508
502 if (!handled && input_router_ && input_router_->OnMessageReceived(msg)) 509 if (!handled && input_router_ && input_router_->OnMessageReceived(msg))
503 return true; 510 return true;
504 511
505 if (!handled && view_ && view_->OnMessageReceived(msg)) 512 if (!handled && view_ && view_->OnMessageReceived(msg))
506 return true; 513 return true;
507 514
508 return handled; 515 return handled;
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 1349
1343 void RenderWidgetHostImpl::OnSetNeedsBeginFrames(bool needs_begin_frames) { 1350 void RenderWidgetHostImpl::OnSetNeedsBeginFrames(bool needs_begin_frames) {
1344 if (needs_begin_frames_ == needs_begin_frames) 1351 if (needs_begin_frames_ == needs_begin_frames)
1345 return; 1352 return;
1346 1353
1347 needs_begin_frames_ = needs_begin_frames; 1354 needs_begin_frames_ = needs_begin_frames;
1348 if (view_) 1355 if (view_)
1349 view_->SetNeedsBeginFrames(needs_begin_frames); 1356 view_->SetNeedsBeginFrames(needs_begin_frames);
1350 } 1357 }
1351 1358
1359 void RenderWidgetHostImpl::OnStartDragging(
1360 const DropData& drop_data,
1361 blink::WebDragOperationsMask drag_operations_mask,
1362 const SkBitmap& bitmap,
1363 const gfx::Vector2d& bitmap_offset_in_dip,
1364 const DragEventSourceInfo& event_info) {
1365 RenderViewHost* rvh = delegate_->GetRenderViewHost();
1366 if (!rvh)
1367 return;
1368 RenderViewHostDelegateView* view = rvh->GetDelegate()->GetDelegateView();
1369 if (!view) {
1370 // Need to clear drag and drop state in blink.
1371 rvh->DragSourceSystemDragEnded();
1372 return;
1373 }
1374
1375 DropData filtered_data(drop_data);
1376 RenderProcessHost* process = GetProcess();
1377 ChildProcessSecurityPolicyImpl* policy =
1378 ChildProcessSecurityPolicyImpl::GetInstance();
1379
1380 // Allow drag of Javascript URLs to enable bookmarklet drag to bookmark bar.
1381 if (!filtered_data.url.SchemeIs(url::kJavaScriptScheme))
1382 process->FilterURL(true, &filtered_data.url);
1383 process->FilterURL(false, &filtered_data.html_base_url);
1384 // Filter out any paths that the renderer didn't have access to. This prevents
1385 // the following attack on a malicious renderer:
1386 // 1. StartDragging IPC sent with renderer-specified filesystem paths that it
1387 // doesn't have read permissions for.
1388 // 2. We initiate a native DnD operation.
1389 // 3. DnD operation immediately ends since mouse is not held down. DnD events
1390 // still fire though, which causes read permissions to be granted to the
1391 // renderer for any file paths in the drop.
1392 filtered_data.filenames.clear();
1393 for (std::vector<ui::FileInfo>::const_iterator it =
1394 drop_data.filenames.begin();
1395 it != drop_data.filenames.end();
1396 ++it) {
1397 if (policy->CanReadFile(GetProcess()->GetID(), it->path))
1398 filtered_data.filenames.push_back(*it);
1399 }
1400
1401 storage::FileSystemContext* file_system_context =
1402 BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(),
1403 rvh->GetSiteInstance())
1404 ->GetFileSystemContext();
1405 filtered_data.file_system_files.clear();
1406 for (size_t i = 0; i < drop_data.file_system_files.size(); ++i) {
1407 storage::FileSystemURL file_system_url =
1408 file_system_context->CrackURL(drop_data.file_system_files[i].url);
1409 if (policy->CanReadFileSystemFile(GetProcess()->GetID(), file_system_url))
1410 filtered_data.file_system_files.push_back(drop_data.file_system_files[i]);
1411 }
1412
1413 float scale = GetScaleFactorForView(GetView());
1414 gfx::ImageSkia image(gfx::ImageSkiaRep(bitmap, scale));
1415 view->StartDragging(filtered_data, drag_operations_mask, image,
1416 bitmap_offset_in_dip, event_info);
1417 }
1418
1352 void RenderWidgetHostImpl::RendererExited(base::TerminationStatus status, 1419 void RenderWidgetHostImpl::RendererExited(base::TerminationStatus status,
1353 int exit_code) { 1420 int exit_code) {
1354 if (!renderer_initialized_) 1421 if (!renderer_initialized_)
1355 return; 1422 return;
1356 1423
1357 // Clearing this flag causes us to re-create the renderer when recovering 1424 // Clearing this flag causes us to re-create the renderer when recovering
1358 // from a crashed renderer. 1425 // from a crashed renderer.
1359 renderer_initialized_ = false; 1426 renderer_initialized_ = false;
1360 1427
1361 waiting_for_screen_rects_ack_ = false; 1428 waiting_for_screen_rects_ack_ = false;
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after
2223 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL; 2290 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL;
2224 } 2291 }
2225 2292
2226 BrowserAccessibilityManager* 2293 BrowserAccessibilityManager*
2227 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() { 2294 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() {
2228 return delegate_ ? 2295 return delegate_ ?
2229 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL; 2296 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL;
2230 } 2297 }
2231 2298
2232 } // namespace content 2299 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698