| 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 2495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2506 } | 2506 } |
| 2507 | 2507 |
| 2508 BrowserAccessibilityManager* | 2508 BrowserAccessibilityManager* |
| 2509 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() { | 2509 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() { |
| 2510 return delegate_ ? | 2510 return delegate_ ? |
| 2511 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL; | 2511 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL; |
| 2512 } | 2512 } |
| 2513 | 2513 |
| 2514 void RenderWidgetHostImpl::GrantFileAccessFromDropData(DropData* drop_data) { | 2514 void RenderWidgetHostImpl::GrantFileAccessFromDropData(DropData* drop_data) { |
| 2515 DCHECK_EQ(GetRoutingID(), drop_data->view_id); | 2515 DCHECK_EQ(GetRoutingID(), drop_data->view_id); |
| 2516 const int renderer_id = GetProcess()->GetID(); | 2516 RenderProcessHost* process = GetProcess(); |
| 2517 ChildProcessSecurityPolicyImpl* policy = | 2517 ChildProcessSecurityPolicyImpl::GetInstance()->GrantFileAccessFromDropData( |
| 2518 ChildProcessSecurityPolicyImpl::GetInstance(); | 2518 process->GetID(), process->GetStoragePartition()->GetFileSystemContext(), |
| 2519 | 2519 drop_data); |
| 2520 #if defined(OS_CHROMEOS) | |
| 2521 // The externalfile:// scheme is used in Chrome OS to open external files in a | |
| 2522 // browser tab. | |
| 2523 if (drop_data->url.SchemeIs(content::kExternalFileScheme)) | |
| 2524 policy->GrantRequestURL(renderer_id, drop_data->url); | |
| 2525 #endif | |
| 2526 | |
| 2527 // The filenames vector represents a capability to access the given files. | |
| 2528 storage::IsolatedContext::FileInfoSet files; | |
| 2529 for (auto& filename : drop_data->filenames) { | |
| 2530 // Make sure we have the same display_name as the one we register. | |
| 2531 if (filename.display_name.empty()) { | |
| 2532 std::string name; | |
| 2533 files.AddPath(filename.path, &name); | |
| 2534 filename.display_name = base::FilePath::FromUTF8Unsafe(name); | |
| 2535 } else { | |
| 2536 files.AddPathWithName(filename.path, | |
| 2537 filename.display_name.AsUTF8Unsafe()); | |
| 2538 } | |
| 2539 // A dragged file may wind up as the value of an input element, or it | |
| 2540 // may be used as the target of a navigation instead. We don't know | |
| 2541 // which will happen at this point, so generously grant both access | |
| 2542 // and request permissions to the specific file to cover both cases. | |
| 2543 // We do not give it the permission to request all file:// URLs. | |
| 2544 policy->GrantRequestSpecificFileURL(renderer_id, | |
| 2545 net::FilePathToFileURL(filename.path)); | |
| 2546 | |
| 2547 // If the renderer already has permission to read these paths, we don't need | |
| 2548 // to re-grant them. This prevents problems with DnD for files in the CrOS | |
| 2549 // file manager--the file manager already had read/write access to those | |
| 2550 // directories, but dragging a file would cause the read/write access to be | |
| 2551 // overwritten with read-only access, making them impossible to delete or | |
| 2552 // rename until the renderer was killed. | |
| 2553 if (!policy->CanReadFile(renderer_id, filename.path)) | |
| 2554 policy->GrantReadFile(renderer_id, filename.path); | |
| 2555 } | |
| 2556 | |
| 2557 storage::IsolatedContext* isolated_context = | |
| 2558 storage::IsolatedContext::GetInstance(); | |
| 2559 DCHECK(isolated_context); | |
| 2560 | |
| 2561 if (!files.fileset().empty()) { | |
| 2562 std::string filesystem_id = | |
| 2563 isolated_context->RegisterDraggedFileSystem(files); | |
| 2564 if (!filesystem_id.empty()) { | |
| 2565 // Grant the permission iff the ID is valid. | |
| 2566 policy->GrantReadFileSystem(renderer_id, filesystem_id); | |
| 2567 } | |
| 2568 drop_data->filesystem_id = base::UTF8ToUTF16(filesystem_id); | |
| 2569 } | |
| 2570 | |
| 2571 storage::FileSystemContext* file_system_context = | |
| 2572 GetProcess()->GetStoragePartition()->GetFileSystemContext(); | |
| 2573 for (auto& file_system_file : drop_data->file_system_files) { | |
| 2574 storage::FileSystemURL file_system_url = | |
| 2575 file_system_context->CrackURL(file_system_file.url); | |
| 2576 | |
| 2577 std::string register_name; | |
| 2578 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( | |
| 2579 file_system_url.type(), file_system_url.filesystem_id(), | |
| 2580 file_system_url.path(), ®ister_name); | |
| 2581 | |
| 2582 if (!filesystem_id.empty()) { | |
| 2583 // Grant the permission iff the ID is valid. | |
| 2584 policy->GrantReadFileSystem(renderer_id, filesystem_id); | |
| 2585 } | |
| 2586 | |
| 2587 // Note: We are using the origin URL provided by the sender here. It may be | |
| 2588 // different from the receiver's. | |
| 2589 file_system_file.url = | |
| 2590 GURL(storage::GetIsolatedFileSystemRootURIString( | |
| 2591 file_system_url.origin(), filesystem_id, std::string()) | |
| 2592 .append(register_name)); | |
| 2593 file_system_file.filesystem_id = filesystem_id; | |
| 2594 } | |
| 2595 } | 2520 } |
| 2596 | 2521 |
| 2597 void RenderWidgetHostImpl::RequestCompositionUpdates(bool immediate_request, | 2522 void RenderWidgetHostImpl::RequestCompositionUpdates(bool immediate_request, |
| 2598 bool monitor_updates) { | 2523 bool monitor_updates) { |
| 2599 if (!immediate_request && monitor_updates == monitoring_composition_info_) | 2524 if (!immediate_request && monitor_updates == monitoring_composition_info_) |
| 2600 return; | 2525 return; |
| 2601 monitoring_composition_info_ = monitor_updates; | 2526 monitoring_composition_info_ = monitor_updates; |
| 2602 Send(new InputMsg_RequestCompositionUpdates(routing_id_, immediate_request, | 2527 Send(new InputMsg_RequestCompositionUpdates(routing_id_, immediate_request, |
| 2603 monitor_updates)); | 2528 monitor_updates)); |
| 2604 } | 2529 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2737 RenderProcessHost* rph = GetProcess(); | 2662 RenderProcessHost* rph = GetProcess(); |
| 2738 for (std::vector<IPC::Message>::const_iterator i = messages.begin(); | 2663 for (std::vector<IPC::Message>::const_iterator i = messages.begin(); |
| 2739 i != messages.end(); ++i) { | 2664 i != messages.end(); ++i) { |
| 2740 rph->OnMessageReceived(*i); | 2665 rph->OnMessageReceived(*i); |
| 2741 if (i->dispatch_error()) | 2666 if (i->dispatch_error()) |
| 2742 rph->OnBadMessageReceived(*i); | 2667 rph->OnBadMessageReceived(*i); |
| 2743 } | 2668 } |
| 2744 } | 2669 } |
| 2745 | 2670 |
| 2746 } // namespace content | 2671 } // namespace content |
| OLD | NEW |