| 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/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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 #include "content/public/browser/notification_types.h" | 69 #include "content/public/browser/notification_types.h" |
| 70 #include "content/public/browser/render_widget_host_iterator.h" | 70 #include "content/public/browser/render_widget_host_iterator.h" |
| 71 #include "content/public/browser/storage_partition.h" | 71 #include "content/public/browser/storage_partition.h" |
| 72 #include "content/public/common/content_constants.h" | 72 #include "content/public/common/content_constants.h" |
| 73 #include "content/public/common/content_switches.h" | 73 #include "content/public/common/content_switches.h" |
| 74 #include "content/public/common/result_codes.h" | 74 #include "content/public/common/result_codes.h" |
| 75 #include "content/public/common/web_preferences.h" | 75 #include "content/public/common/web_preferences.h" |
| 76 #include "gpu/GLES2/gl2extchromium.h" | 76 #include "gpu/GLES2/gl2extchromium.h" |
| 77 #include "gpu/command_buffer/service/gpu_switches.h" | 77 #include "gpu/command_buffer/service/gpu_switches.h" |
| 78 #include "gpu/ipc/common/gpu_messages.h" | 78 #include "gpu/ipc/common/gpu_messages.h" |
| 79 #include "net/base/filename_util.h" |
| 79 #include "skia/ext/image_operations.h" | 80 #include "skia/ext/image_operations.h" |
| 80 #include "skia/ext/platform_canvas.h" | 81 #include "skia/ext/platform_canvas.h" |
| 82 #include "storage/browser/fileapi/isolated_context.h" |
| 81 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" | 83 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" |
| 84 #include "ui/base/clipboard/clipboard.h" |
| 82 #include "ui/events/blink/web_input_event_traits.h" | 85 #include "ui/events/blink/web_input_event_traits.h" |
| 83 #include "ui/events/event.h" | 86 #include "ui/events/event.h" |
| 84 #include "ui/events/keycodes/keyboard_codes.h" | 87 #include "ui/events/keycodes/keyboard_codes.h" |
| 85 #include "ui/gfx/color_space.h" | 88 #include "ui/gfx/color_space.h" |
| 86 #include "ui/gfx/geometry/size_conversions.h" | 89 #include "ui/gfx/geometry/size_conversions.h" |
| 87 #include "ui/gfx/geometry/vector2d_conversions.h" | 90 #include "ui/gfx/geometry/vector2d_conversions.h" |
| 88 #include "ui/gfx/image/image_skia.h" | 91 #include "ui/gfx/image/image_skia.h" |
| 89 #include "ui/gfx/skbitmap_operations.h" | 92 #include "ui/gfx/skbitmap_operations.h" |
| 90 #include "ui/snapshot/snapshot.h" | 93 #include "ui/snapshot/snapshot.h" |
| 91 | 94 |
| 92 #if defined(OS_MACOSX) | 95 #if defined(OS_MACOSX) |
| 93 #include "device/power_save_blocker/power_save_blocker.h" | 96 #include "device/power_save_blocker/power_save_blocker.h" |
| 94 #include "ui/accelerated_widget_mac/window_resize_helper_mac.h" | 97 #include "ui/accelerated_widget_mac/window_resize_helper_mac.h" |
| 95 #endif | 98 #endif |
| 96 | 99 |
| 97 using base::Time; | 100 using base::Time; |
| 98 using base::TimeDelta; | 101 using base::TimeDelta; |
| 99 using base::TimeTicks; | 102 using base::TimeTicks; |
| 103 using blink::WebDragOperationsMask; |
| 100 using blink::WebGestureEvent; | 104 using blink::WebGestureEvent; |
| 101 using blink::WebInputEvent; | 105 using blink::WebInputEvent; |
| 102 using blink::WebKeyboardEvent; | 106 using blink::WebKeyboardEvent; |
| 103 using blink::WebMouseEvent; | 107 using blink::WebMouseEvent; |
| 104 using blink::WebMouseWheelEvent; | 108 using blink::WebMouseWheelEvent; |
| 105 using blink::WebTextDirection; | 109 using blink::WebTextDirection; |
| 106 | 110 |
| 107 namespace content { | 111 namespace content { |
| 108 namespace { | 112 namespace { |
| 109 | 113 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 wrap_gesture_scroll_end.type = blink::WebInputEvent::GestureScrollEnd; | 179 wrap_gesture_scroll_end.type = blink::WebInputEvent::GestureScrollEnd; |
| 176 wrap_gesture_scroll_end.timeStampSeconds = gesture_event.timeStampSeconds; | 180 wrap_gesture_scroll_end.timeStampSeconds = gesture_event.timeStampSeconds; |
| 177 wrap_gesture_scroll_end.sourceDevice = gesture_event.sourceDevice; | 181 wrap_gesture_scroll_end.sourceDevice = gesture_event.sourceDevice; |
| 178 wrap_gesture_scroll_end.resendingPluginId = gesture_event.resendingPluginId; | 182 wrap_gesture_scroll_end.resendingPluginId = gesture_event.resendingPluginId; |
| 179 wrap_gesture_scroll_end.data.scrollEnd.deltaUnits = | 183 wrap_gesture_scroll_end.data.scrollEnd.deltaUnits = |
| 180 gesture_event.data.scrollUpdate.deltaUnits; | 184 gesture_event.data.scrollUpdate.deltaUnits; |
| 181 | 185 |
| 182 return wrap_gesture_scroll_end; | 186 return wrap_gesture_scroll_end; |
| 183 } | 187 } |
| 184 | 188 |
| 189 std::vector<DropData::Metadata> DropDataToMetaData(const DropData& drop_data) { |
| 190 std::vector<DropData::Metadata> metadata; |
| 191 if (!drop_data.text.is_null()) { |
| 192 metadata.push_back(DropData::Metadata::CreateForMimeType( |
| 193 DropData::Kind::STRING, |
| 194 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeText))); |
| 195 } |
| 196 |
| 197 if (drop_data.url.is_valid()) { |
| 198 metadata.push_back(DropData::Metadata::CreateForMimeType( |
| 199 DropData::Kind::STRING, |
| 200 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeURIList))); |
| 201 } |
| 202 |
| 203 if (!drop_data.html.is_null()) { |
| 204 metadata.push_back(DropData::Metadata::CreateForMimeType( |
| 205 DropData::Kind::STRING, |
| 206 base::ASCIIToUTF16(ui::Clipboard::kMimeTypeHTML))); |
| 207 } |
| 208 |
| 209 // On Aura, filenames are available before drop. |
| 210 for (const auto& file_info : drop_data.filenames) { |
| 211 if (!file_info.path.empty()) { |
| 212 metadata.push_back(DropData::Metadata::CreateForFilePath(file_info.path)); |
| 213 } |
| 214 } |
| 215 |
| 216 // On Android, only files' mime types are available before drop. |
| 217 for (const auto& mime_type : drop_data.file_mime_types) { |
| 218 if (!mime_type.empty()) { |
| 219 metadata.push_back(DropData::Metadata::CreateForMimeType( |
| 220 DropData::Kind::FILENAME, mime_type)); |
| 221 } |
| 222 } |
| 223 |
| 224 for (const auto& file_system_file : drop_data.file_system_files) { |
| 225 if (!file_system_file.url.is_empty()) { |
| 226 metadata.push_back( |
| 227 DropData::Metadata::CreateForFileSystemUrl(file_system_file.url)); |
| 228 } |
| 229 } |
| 230 |
| 231 for (const auto& custom_data_item : drop_data.custom_data) { |
| 232 metadata.push_back(DropData::Metadata::CreateForMimeType( |
| 233 DropData::Kind::STRING, custom_data_item.first)); |
| 234 } |
| 235 |
| 236 return metadata; |
| 237 } |
| 238 |
| 185 } // namespace | 239 } // namespace |
| 186 | 240 |
| 187 /////////////////////////////////////////////////////////////////////////////// | 241 /////////////////////////////////////////////////////////////////////////////// |
| 188 // RenderWidgetHostImpl | 242 // RenderWidgetHostImpl |
| 189 | 243 |
| 190 RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, | 244 RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, |
| 191 RenderProcessHost* process, | 245 RenderProcessHost* process, |
| 192 int32_t routing_id, | 246 int32_t routing_id, |
| 193 bool hidden) | 247 bool hidden) |
| 194 : renderer_initialized_(false), | 248 : renderer_initialized_(false), |
| (...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1270 if (IsUseZoomForDSFEnabled()) | 1324 if (IsUseZoomForDSFEnabled()) |
| 1271 input_router_->SetDeviceScaleFactor(result->device_scale_factor); | 1325 input_router_->SetDeviceScaleFactor(result->device_scale_factor); |
| 1272 } | 1326 } |
| 1273 | 1327 |
| 1274 void RenderWidgetHostImpl::HandleCompositorProto( | 1328 void RenderWidgetHostImpl::HandleCompositorProto( |
| 1275 const std::vector<uint8_t>& proto) { | 1329 const std::vector<uint8_t>& proto) { |
| 1276 DCHECK(!proto.empty()); | 1330 DCHECK(!proto.empty()); |
| 1277 Send(new ViewMsg_HandleCompositorProto(GetRoutingID(), proto)); | 1331 Send(new ViewMsg_HandleCompositorProto(GetRoutingID(), proto)); |
| 1278 } | 1332 } |
| 1279 | 1333 |
| 1334 void RenderWidgetHostImpl::DragTargetDragEnter( |
| 1335 const DropData& drop_data, |
| 1336 const gfx::Point& client_pt, |
| 1337 const gfx::Point& screen_pt, |
| 1338 WebDragOperationsMask operations_allowed, |
| 1339 int key_modifiers) { |
| 1340 std::vector<DropData::Metadata> metadata = DropDataToMetaData(drop_data); |
| 1341 Send(new DragMsg_TargetDragEnter(GetRoutingID(), metadata, client_pt, |
| 1342 screen_pt, operations_allowed, |
| 1343 key_modifiers)); |
| 1344 } |
| 1345 |
| 1346 void RenderWidgetHostImpl::DragTargetDragOver( |
| 1347 const gfx::Point& client_pt, |
| 1348 const gfx::Point& screen_pt, |
| 1349 WebDragOperationsMask operations_allowed, |
| 1350 int key_modifiers) { |
| 1351 Send(new DragMsg_TargetDragOver(GetRoutingID(), client_pt, screen_pt, |
| 1352 operations_allowed, key_modifiers)); |
| 1353 } |
| 1354 |
| 1355 void RenderWidgetHostImpl::DragTargetDragLeave() { |
| 1356 Send(new DragMsg_TargetDragLeave(GetRoutingID())); |
| 1357 } |
| 1358 |
| 1359 void RenderWidgetHostImpl::DragTargetDrop(const DropData& drop_data, |
| 1360 const gfx::Point& client_pt, |
| 1361 const gfx::Point& screen_pt, |
| 1362 int key_modifiers) { |
| 1363 DropData drop_data_with_permissions(drop_data); |
| 1364 GrantFileAccessFromDropData(&drop_data_with_permissions); |
| 1365 Send(new DragMsg_TargetDrop(GetRoutingID(), drop_data_with_permissions, |
| 1366 client_pt, screen_pt, key_modifiers)); |
| 1367 } |
| 1368 |
| 1369 void RenderWidgetHostImpl::FilterDropData(DropData* drop_data) { |
| 1370 #if DCHECK_IS_ON() |
| 1371 drop_data->view_id = GetRoutingID(); |
| 1372 #endif // DCHECK_IS_ON() |
| 1373 |
| 1374 GetProcess()->FilterURL(true, &drop_data->url); |
| 1375 if (drop_data->did_originate_from_renderer) { |
| 1376 drop_data->filenames.clear(); |
| 1377 } |
| 1378 } |
| 1379 |
| 1280 void RenderWidgetHostImpl::NotifyScreenInfoChanged() { | 1380 void RenderWidgetHostImpl::NotifyScreenInfoChanged() { |
| 1281 if (delegate_) | 1381 if (delegate_) |
| 1282 delegate_->ScreenInfoChanged(); | 1382 delegate_->ScreenInfoChanged(); |
| 1283 | 1383 |
| 1284 // The resize message (which may not happen immediately) will carry with it | 1384 // The resize message (which may not happen immediately) will carry with it |
| 1285 // the screen info as well as the new size (if the screen has changed scale | 1385 // the screen info as well as the new size (if the screen has changed scale |
| 1286 // factor). | 1386 // factor). |
| 1287 WasResized(); | 1387 WasResized(); |
| 1288 } | 1388 } |
| 1289 | 1389 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1344 if (view_) | 1444 if (view_) |
| 1345 view_->SetNeedsBeginFrames(needs_begin_frames); | 1445 view_->SetNeedsBeginFrames(needs_begin_frames); |
| 1346 } | 1446 } |
| 1347 | 1447 |
| 1348 void RenderWidgetHostImpl::OnStartDragging( | 1448 void RenderWidgetHostImpl::OnStartDragging( |
| 1349 const DropData& drop_data, | 1449 const DropData& drop_data, |
| 1350 blink::WebDragOperationsMask drag_operations_mask, | 1450 blink::WebDragOperationsMask drag_operations_mask, |
| 1351 const SkBitmap& bitmap, | 1451 const SkBitmap& bitmap, |
| 1352 const gfx::Vector2d& bitmap_offset_in_dip, | 1452 const gfx::Vector2d& bitmap_offset_in_dip, |
| 1353 const DragEventSourceInfo& event_info) { | 1453 const DragEventSourceInfo& event_info) { |
| 1454 // TODO(paulmeyer): Stop relying on RenderViewHost once |
| 1455 // DragSourceSystemDragEnded is moved into RenderWidgetHost. |
| 1354 RenderViewHost* rvh = RenderViewHost::From(this); | 1456 RenderViewHost* rvh = RenderViewHost::From(this); |
| 1355 if (!rvh) | 1457 if (!rvh) |
| 1356 return; | 1458 return; |
| 1357 | 1459 |
| 1358 RenderViewHostDelegateView* view = delegate_->GetDelegateView(); | 1460 RenderViewHostDelegateView* view = delegate_->GetDelegateView(); |
| 1359 if (!view) { | 1461 if (!view) { |
| 1360 // Need to clear drag and drop state in blink. | 1462 // Need to clear drag and drop state in blink. |
| 1361 rvh->DragSourceSystemDragEnded(); | 1463 rvh->DragSourceSystemDragEnded(); |
| 1362 return; | 1464 return; |
| 1363 } | 1465 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1379 // 3. DnD operation immediately ends since mouse is not held down. DnD events | 1481 // 3. DnD operation immediately ends since mouse is not held down. DnD events |
| 1380 // still fire though, which causes read permissions to be granted to the | 1482 // still fire though, which causes read permissions to be granted to the |
| 1381 // renderer for any file paths in the drop. | 1483 // renderer for any file paths in the drop. |
| 1382 filtered_data.filenames.clear(); | 1484 filtered_data.filenames.clear(); |
| 1383 for (const auto& file_info : drop_data.filenames) { | 1485 for (const auto& file_info : drop_data.filenames) { |
| 1384 if (policy->CanReadFile(GetProcess()->GetID(), file_info.path)) | 1486 if (policy->CanReadFile(GetProcess()->GetID(), file_info.path)) |
| 1385 filtered_data.filenames.push_back(file_info); | 1487 filtered_data.filenames.push_back(file_info); |
| 1386 } | 1488 } |
| 1387 | 1489 |
| 1388 storage::FileSystemContext* file_system_context = | 1490 storage::FileSystemContext* file_system_context = |
| 1389 BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(), | 1491 GetProcess()->GetStoragePartition()->GetFileSystemContext(); |
| 1390 rvh->GetSiteInstance()) | |
| 1391 ->GetFileSystemContext(); | |
| 1392 filtered_data.file_system_files.clear(); | 1492 filtered_data.file_system_files.clear(); |
| 1393 for (size_t i = 0; i < drop_data.file_system_files.size(); ++i) { | 1493 for (size_t i = 0; i < drop_data.file_system_files.size(); ++i) { |
| 1394 storage::FileSystemURL file_system_url = | 1494 storage::FileSystemURL file_system_url = |
| 1395 file_system_context->CrackURL(drop_data.file_system_files[i].url); | 1495 file_system_context->CrackURL(drop_data.file_system_files[i].url); |
| 1396 if (policy->CanReadFileSystemFile(GetProcess()->GetID(), file_system_url)) | 1496 if (policy->CanReadFileSystemFile(GetProcess()->GetID(), file_system_url)) |
| 1397 filtered_data.file_system_files.push_back(drop_data.file_system_files[i]); | 1497 filtered_data.file_system_files.push_back(drop_data.file_system_files[i]); |
| 1398 } | 1498 } |
| 1399 | 1499 |
| 1400 float scale = GetScaleFactorForView(GetView()); | 1500 float scale = GetScaleFactorForView(GetView()); |
| 1401 gfx::ImageSkia image(gfx::ImageSkiaRep(bitmap, scale)); | 1501 gfx::ImageSkia image(gfx::ImageSkiaRep(bitmap, scale)); |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2271 RenderWidgetHostImpl::GetRootBrowserAccessibilityManager() { | 2371 RenderWidgetHostImpl::GetRootBrowserAccessibilityManager() { |
| 2272 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL; | 2372 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL; |
| 2273 } | 2373 } |
| 2274 | 2374 |
| 2275 BrowserAccessibilityManager* | 2375 BrowserAccessibilityManager* |
| 2276 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() { | 2376 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() { |
| 2277 return delegate_ ? | 2377 return delegate_ ? |
| 2278 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL; | 2378 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL; |
| 2279 } | 2379 } |
| 2280 | 2380 |
| 2381 void RenderWidgetHostImpl::GrantFileAccessFromDropData(DropData* drop_data) { |
| 2382 DCHECK_EQ(GetRoutingID(), drop_data->view_id); |
| 2383 const int renderer_id = GetProcess()->GetID(); |
| 2384 ChildProcessSecurityPolicyImpl* policy = |
| 2385 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 2386 |
| 2387 #if defined(OS_CHROMEOS) |
| 2388 // The externalfile:// scheme is used in Chrome OS to open external files in a |
| 2389 // browser tab. |
| 2390 if (drop_data->url.SchemeIs(content::kExternalFileScheme)) |
| 2391 policy->GrantRequestURL(renderer_id, drop_data->url); |
| 2392 #endif |
| 2393 |
| 2394 // The filenames vector represents a capability to access the given files. |
| 2395 storage::IsolatedContext::FileInfoSet files; |
| 2396 for (auto& filename : drop_data->filenames) { |
| 2397 // Make sure we have the same display_name as the one we register. |
| 2398 if (filename.display_name.empty()) { |
| 2399 std::string name; |
| 2400 files.AddPath(filename.path, &name); |
| 2401 filename.display_name = base::FilePath::FromUTF8Unsafe(name); |
| 2402 } else { |
| 2403 files.AddPathWithName(filename.path, |
| 2404 filename.display_name.AsUTF8Unsafe()); |
| 2405 } |
| 2406 // A dragged file may wind up as the value of an input element, or it |
| 2407 // may be used as the target of a navigation instead. We don't know |
| 2408 // which will happen at this point, so generously grant both access |
| 2409 // and request permissions to the specific file to cover both cases. |
| 2410 // We do not give it the permission to request all file:// URLs. |
| 2411 policy->GrantRequestSpecificFileURL(renderer_id, |
| 2412 net::FilePathToFileURL(filename.path)); |
| 2413 |
| 2414 // If the renderer already has permission to read these paths, we don't need |
| 2415 // to re-grant them. This prevents problems with DnD for files in the CrOS |
| 2416 // file manager--the file manager already had read/write access to those |
| 2417 // directories, but dragging a file would cause the read/write access to be |
| 2418 // overwritten with read-only access, making them impossible to delete or |
| 2419 // rename until the renderer was killed. |
| 2420 if (!policy->CanReadFile(renderer_id, filename.path)) |
| 2421 policy->GrantReadFile(renderer_id, filename.path); |
| 2422 } |
| 2423 |
| 2424 storage::IsolatedContext* isolated_context = |
| 2425 storage::IsolatedContext::GetInstance(); |
| 2426 DCHECK(isolated_context); |
| 2427 |
| 2428 if (!files.fileset().empty()) { |
| 2429 std::string filesystem_id = |
| 2430 isolated_context->RegisterDraggedFileSystem(files); |
| 2431 if (!filesystem_id.empty()) { |
| 2432 // Grant the permission iff the ID is valid. |
| 2433 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
| 2434 } |
| 2435 drop_data->filesystem_id = base::UTF8ToUTF16(filesystem_id); |
| 2436 } |
| 2437 |
| 2438 storage::FileSystemContext* file_system_context = |
| 2439 GetProcess()->GetStoragePartition()->GetFileSystemContext(); |
| 2440 for (auto& file_system_file : drop_data->file_system_files) { |
| 2441 storage::FileSystemURL file_system_url = |
| 2442 file_system_context->CrackURL(file_system_file.url); |
| 2443 |
| 2444 std::string register_name; |
| 2445 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( |
| 2446 file_system_url.type(), file_system_url.filesystem_id(), |
| 2447 file_system_url.path(), ®ister_name); |
| 2448 |
| 2449 if (!filesystem_id.empty()) { |
| 2450 // Grant the permission iff the ID is valid. |
| 2451 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
| 2452 } |
| 2453 |
| 2454 // Note: We are using the origin URL provided by the sender here. It may be |
| 2455 // different from the receiver's. |
| 2456 file_system_file.url = |
| 2457 GURL(storage::GetIsolatedFileSystemRootURIString( |
| 2458 file_system_url.origin(), filesystem_id, std::string()) |
| 2459 .append(register_name)); |
| 2460 } |
| 2461 } |
| 2462 |
| 2281 } // namespace content | 2463 } // namespace content |
| OLD | NEW |