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/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" | |
|
dcheng
2016/11/09 20:23:17
I think the corresponding includes here can be cle
paulmeyer
2016/11/09 23:19:11
Done.
| |
| 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 | |
| 1280 void RenderWidgetHostImpl::NotifyScreenInfoChanged() { | 1369 void RenderWidgetHostImpl::NotifyScreenInfoChanged() { |
| 1281 if (delegate_) | 1370 if (delegate_) |
| 1282 delegate_->ScreenInfoChanged(); | 1371 delegate_->ScreenInfoChanged(); |
| 1283 | 1372 |
| 1284 // The resize message (which may not happen immediately) will carry with it | 1373 // 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 | 1374 // the screen info as well as the new size (if the screen has changed scale |
| 1286 // factor). | 1375 // factor). |
| 1287 WasResized(); | 1376 WasResized(); |
| 1288 } | 1377 } |
| 1289 | 1378 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1344 if (view_) | 1433 if (view_) |
| 1345 view_->SetNeedsBeginFrames(needs_begin_frames); | 1434 view_->SetNeedsBeginFrames(needs_begin_frames); |
| 1346 } | 1435 } |
| 1347 | 1436 |
| 1348 void RenderWidgetHostImpl::OnStartDragging( | 1437 void RenderWidgetHostImpl::OnStartDragging( |
| 1349 const DropData& drop_data, | 1438 const DropData& drop_data, |
| 1350 blink::WebDragOperationsMask drag_operations_mask, | 1439 blink::WebDragOperationsMask drag_operations_mask, |
| 1351 const SkBitmap& bitmap, | 1440 const SkBitmap& bitmap, |
| 1352 const gfx::Vector2d& bitmap_offset_in_dip, | 1441 const gfx::Vector2d& bitmap_offset_in_dip, |
| 1353 const DragEventSourceInfo& event_info) { | 1442 const DragEventSourceInfo& event_info) { |
| 1443 // TODO(paulmeyer): Stop relying on RenderViewHost once | |
| 1444 // DragSourceSystemDragEnded is moved into RenderWidgetHost. | |
| 1354 RenderViewHost* rvh = RenderViewHost::From(this); | 1445 RenderViewHost* rvh = RenderViewHost::From(this); |
| 1355 if (!rvh) | 1446 if (!rvh) |
| 1356 return; | 1447 return; |
| 1357 | 1448 |
| 1358 RenderViewHostDelegateView* view = delegate_->GetDelegateView(); | 1449 RenderViewHostDelegateView* view = delegate_->GetDelegateView(); |
| 1359 if (!view) { | 1450 if (!view) { |
| 1360 // Need to clear drag and drop state in blink. | 1451 // Need to clear drag and drop state in blink. |
| 1361 rvh->DragSourceSystemDragEnded(); | 1452 rvh->DragSourceSystemDragEnded(); |
| 1362 return; | 1453 return; |
| 1363 } | 1454 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1379 // 3. DnD operation immediately ends since mouse is not held down. DnD events | 1470 // 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 | 1471 // still fire though, which causes read permissions to be granted to the |
| 1381 // renderer for any file paths in the drop. | 1472 // renderer for any file paths in the drop. |
| 1382 filtered_data.filenames.clear(); | 1473 filtered_data.filenames.clear(); |
| 1383 for (const auto& file_info : drop_data.filenames) { | 1474 for (const auto& file_info : drop_data.filenames) { |
| 1384 if (policy->CanReadFile(GetProcess()->GetID(), file_info.path)) | 1475 if (policy->CanReadFile(GetProcess()->GetID(), file_info.path)) |
| 1385 filtered_data.filenames.push_back(file_info); | 1476 filtered_data.filenames.push_back(file_info); |
| 1386 } | 1477 } |
| 1387 | 1478 |
| 1388 storage::FileSystemContext* file_system_context = | 1479 storage::FileSystemContext* file_system_context = |
| 1389 BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(), | 1480 GetProcess()->GetStoragePartition()->GetFileSystemContext(); |
| 1390 rvh->GetSiteInstance()) | |
| 1391 ->GetFileSystemContext(); | |
| 1392 filtered_data.file_system_files.clear(); | 1481 filtered_data.file_system_files.clear(); |
| 1393 for (size_t i = 0; i < drop_data.file_system_files.size(); ++i) { | 1482 for (size_t i = 0; i < drop_data.file_system_files.size(); ++i) { |
| 1394 storage::FileSystemURL file_system_url = | 1483 storage::FileSystemURL file_system_url = |
| 1395 file_system_context->CrackURL(drop_data.file_system_files[i].url); | 1484 file_system_context->CrackURL(drop_data.file_system_files[i].url); |
| 1396 if (policy->CanReadFileSystemFile(GetProcess()->GetID(), file_system_url)) | 1485 if (policy->CanReadFileSystemFile(GetProcess()->GetID(), file_system_url)) |
| 1397 filtered_data.file_system_files.push_back(drop_data.file_system_files[i]); | 1486 filtered_data.file_system_files.push_back(drop_data.file_system_files[i]); |
| 1398 } | 1487 } |
| 1399 | 1488 |
| 1400 float scale = GetScaleFactorForView(GetView()); | 1489 float scale = GetScaleFactorForView(GetView()); |
| 1401 gfx::ImageSkia image(gfx::ImageSkiaRep(bitmap, scale)); | 1490 gfx::ImageSkia image(gfx::ImageSkiaRep(bitmap, scale)); |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2271 RenderWidgetHostImpl::GetRootBrowserAccessibilityManager() { | 2360 RenderWidgetHostImpl::GetRootBrowserAccessibilityManager() { |
| 2272 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL; | 2361 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL; |
| 2273 } | 2362 } |
| 2274 | 2363 |
| 2275 BrowserAccessibilityManager* | 2364 BrowserAccessibilityManager* |
| 2276 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() { | 2365 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() { |
| 2277 return delegate_ ? | 2366 return delegate_ ? |
| 2278 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL; | 2367 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL; |
| 2279 } | 2368 } |
| 2280 | 2369 |
| 2370 void RenderWidgetHostImpl::GrantFileAccessFromDropData(DropData* drop_data) { | |
| 2371 DCHECK_EQ(GetRoutingID(), drop_data->view_id); | |
| 2372 const int renderer_id = GetProcess()->GetID(); | |
| 2373 ChildProcessSecurityPolicyImpl* policy = | |
| 2374 ChildProcessSecurityPolicyImpl::GetInstance(); | |
| 2375 | |
| 2376 #if defined(OS_CHROMEOS) | |
| 2377 // The externalfile:// scheme is used in Chrome OS to open external files in a | |
| 2378 // browser tab. | |
| 2379 if (drop_data->url.SchemeIs(content::kExternalFileScheme)) | |
| 2380 policy->GrantRequestURL(renderer_id, drop_data->url); | |
| 2381 #endif | |
| 2382 | |
| 2383 // The filenames vector represents a capability to access the given files. | |
| 2384 storage::IsolatedContext::FileInfoSet files; | |
| 2385 for (auto& filename : drop_data->filenames) { | |
| 2386 // Make sure we have the same display_name as the one we register. | |
| 2387 if (filename.display_name.empty()) { | |
| 2388 std::string name; | |
| 2389 files.AddPath(filename.path, &name); | |
| 2390 filename.display_name = base::FilePath::FromUTF8Unsafe(name); | |
| 2391 } else { | |
| 2392 files.AddPathWithName(filename.path, | |
| 2393 filename.display_name.AsUTF8Unsafe()); | |
| 2394 } | |
| 2395 // A dragged file may wind up as the value of an input element, or it | |
| 2396 // may be used as the target of a navigation instead. We don't know | |
| 2397 // which will happen at this point, so generously grant both access | |
| 2398 // and request permissions to the specific file to cover both cases. | |
| 2399 // We do not give it the permission to request all file:// URLs. | |
| 2400 policy->GrantRequestSpecificFileURL(renderer_id, | |
| 2401 net::FilePathToFileURL(filename.path)); | |
| 2402 | |
| 2403 // If the renderer already has permission to read these paths, we don't need | |
| 2404 // to re-grant them. This prevents problems with DnD for files in the CrOS | |
| 2405 // file manager--the file manager already had read/write access to those | |
| 2406 // directories, but dragging a file would cause the read/write access to be | |
| 2407 // overwritten with read-only access, making them impossible to delete or | |
| 2408 // rename until the renderer was killed. | |
| 2409 if (!policy->CanReadFile(renderer_id, filename.path)) | |
| 2410 policy->GrantReadFile(renderer_id, filename.path); | |
| 2411 } | |
| 2412 | |
| 2413 storage::IsolatedContext* isolated_context = | |
| 2414 storage::IsolatedContext::GetInstance(); | |
| 2415 DCHECK(isolated_context); | |
| 2416 | |
| 2417 if (!files.fileset().empty()) { | |
| 2418 std::string filesystem_id = | |
| 2419 isolated_context->RegisterDraggedFileSystem(files); | |
| 2420 if (!filesystem_id.empty()) { | |
| 2421 // Grant the permission iff the ID is valid. | |
| 2422 policy->GrantReadFileSystem(renderer_id, filesystem_id); | |
| 2423 } | |
| 2424 drop_data->filesystem_id = base::UTF8ToUTF16(filesystem_id); | |
| 2425 } | |
| 2426 | |
| 2427 storage::FileSystemContext* file_system_context = | |
| 2428 GetProcess()->GetStoragePartition()->GetFileSystemContext(); | |
| 2429 for (auto& file_system_file : drop_data->file_system_files) { | |
| 2430 storage::FileSystemURL file_system_url = | |
| 2431 file_system_context->CrackURL(file_system_file.url); | |
| 2432 | |
| 2433 std::string register_name; | |
| 2434 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( | |
| 2435 file_system_url.type(), file_system_url.filesystem_id(), | |
| 2436 file_system_url.path(), ®ister_name); | |
| 2437 | |
| 2438 if (!filesystem_id.empty()) { | |
| 2439 // Grant the permission iff the ID is valid. | |
| 2440 policy->GrantReadFileSystem(renderer_id, filesystem_id); | |
| 2441 } | |
| 2442 | |
| 2443 // Note: We are using the origin URL provided by the sender here. It may be | |
| 2444 // different from the receiver's. | |
| 2445 file_system_file.url = | |
| 2446 GURL(storage::GetIsolatedFileSystemRootURIString( | |
| 2447 file_system_url.origin(), filesystem_id, std::string()) | |
| 2448 .append(register_name)); | |
| 2449 } | |
| 2450 } | |
| 2451 | |
| 2281 } // namespace content | 2452 } // namespace content |
| OLD | NEW |