Index: content/browser/renderer_host/render_view_host_impl.cc |
diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc |
index a26e5841ed080501ffdc36a023cea8a21701e0a2..889bcac05541c25dd3bbbd09eadf3ef9e99c1322 100644 |
--- a/content/browser/renderer_host/render_view_host_impl.cc |
+++ b/content/browser/renderer_host/render_view_host_impl.cc |
@@ -80,6 +80,7 @@ |
#include "net/url_request/url_request_context_getter.h" |
#include "storage/browser/fileapi/isolated_context.h" |
#include "third_party/skia/include/core/SkBitmap.h" |
+#include "ui/base/clipboard/clipboard.h" |
#include "ui/base/touch/touch_device.h" |
#include "ui/base/touch/touch_enabled.h" |
#include "ui/base/ui_base_switches.h" |
@@ -164,6 +165,56 @@ void GetWindowsSpecificPrefs(RendererPreferences* prefs) { |
} |
#endif |
+void DropDataToMetaData(const DropData& drop_data, |
+ std::vector<MimeTypeKindPair>& meta_data) { |
+ base::string16 string_kind = base::ASCIIToUTF16("string"); |
+ base::string16 filename_kind = base::ASCIIToUTF16("filename"); |
+ base::string16 filesystemfile_kind = base::ASCIIToUTF16("filesystemfile"); |
+ if (!drop_data.text.is_null()) { |
+ MimeTypeKindPair pair = std::make_pair( |
+ base::ASCIIToUTF16(ui::Clipboard::kMimeTypeText), string_kind); |
+ meta_data.push_back(pair); |
+ } |
+ |
+ if (!drop_data.url.is_empty()) { |
+ MimeTypeKindPair pair = std::make_pair( |
+ base::ASCIIToUTF16(ui::Clipboard::kMimeTypeURIList), string_kind); |
+ meta_data.push_back(pair); |
+ } |
+ |
+ if (!drop_data.html.is_null()) { |
+ MimeTypeKindPair pair = std::make_pair( |
+ base::ASCIIToUTF16(ui::Clipboard::kMimeTypeHTML), string_kind); |
+ meta_data.push_back(pair); |
+ } |
+ |
+ for (std::vector<ui::FileInfo>::const_iterator it = |
+ drop_data.filenames.begin(); |
+ it != drop_data.filenames.end(); ++it) { |
+ if (!it->path.empty()) { |
+ MimeTypeKindPair pair = std::make_pair(base::string16(), filename_kind); |
+ meta_data.push_back(pair); |
+ } |
+ } |
+ |
+ for (std::vector<DropData::FileSystemFileInfo>::const_iterator it = |
+ drop_data.file_system_files.begin(); |
+ it != drop_data.file_system_files.end(); ++it) { |
+ if (!it->url.is_empty()) { |
+ MimeTypeKindPair pair = |
+ std::make_pair(base::string16(), filesystemfile_kind); |
+ meta_data.push_back(pair); |
+ } |
+ } |
+ |
+ for (std::map<base::string16, base::string16>::const_iterator it = |
+ drop_data.custom_data.begin(); |
+ it != drop_data.custom_data.end(); ++it) { |
+ MimeTypeKindPair pair = std::make_pair(it->first, string_kind); |
+ meta_data.push_back(pair); |
+ } |
Avi (use Gerrit)
2016/04/08 21:24:08
For these three loops, you easily could do |for (c
hush (inactive)
2016/04/12 00:07:49
Done. This is definitely better with the new synta
|
+} |
+ |
} // namespace |
// static |
@@ -593,11 +644,11 @@ void RenderViewHostImpl::DragTargetDragEnter( |
const gfx::Point& screen_pt, |
WebDragOperationsMask operations_allowed, |
int key_modifiers) { |
+#if defined(OS_CHROMEOS) |
const int renderer_id = GetProcess()->GetID(); |
ChildProcessSecurityPolicyImpl* policy = |
ChildProcessSecurityPolicyImpl::GetInstance(); |
-#if defined(OS_CHROMEOS) |
// The externalfile:// scheme is used in Chrome OS to open external files in a |
// browser tab. |
if (drop_data.url.SchemeIs(content::kExternalFileScheme)) |
@@ -607,80 +658,11 @@ void RenderViewHostImpl::DragTargetDragEnter( |
// The URL could have been cobbled together from any highlighted text string, |
// and can't be interpreted as a capability. |
DropData filtered_data(drop_data); |
- GetProcess()->FilterURL(true, &filtered_data.url); |
- if (drop_data.did_originate_from_renderer) { |
- filtered_data.filenames.clear(); |
- } |
- |
- // The filenames vector, on the other hand, does represent a capability to |
- // access the given files. |
- storage::IsolatedContext::FileInfoSet files; |
- for (std::vector<ui::FileInfo>::iterator iter( |
- filtered_data.filenames.begin()); |
- iter != filtered_data.filenames.end(); |
- ++iter) { |
- // A dragged file may wind up as the value of an input element, or it |
- // may be used as the target of a navigation instead. We don't know |
- // which will happen at this point, so generously grant both access |
- // and request permissions to the specific file to cover both cases. |
- // We do not give it the permission to request all file:// URLs. |
- |
- // Make sure we have the same display_name as the one we register. |
- if (iter->display_name.empty()) { |
- std::string name; |
- files.AddPath(iter->path, &name); |
- iter->display_name = base::FilePath::FromUTF8Unsafe(name); |
- } else { |
- files.AddPathWithName(iter->path, iter->display_name.AsUTF8Unsafe()); |
- } |
- |
- policy->GrantRequestSpecificFileURL(renderer_id, |
- net::FilePathToFileURL(iter->path)); |
+ FilterDropData(filtered_data); |
- // If the renderer already has permission to read these paths, we don't need |
- // to re-grant them. This prevents problems with DnD for files in the CrOS |
- // file manager--the file manager already had read/write access to those |
- // directories, but dragging a file would cause the read/write access to be |
- // overwritten with read-only access, making them impossible to delete or |
- // rename until the renderer was killed. |
- if (!policy->CanReadFile(renderer_id, iter->path)) |
- policy->GrantReadFile(renderer_id, iter->path); |
- } |
- |
- storage::IsolatedContext* isolated_context = |
- storage::IsolatedContext::GetInstance(); |
- DCHECK(isolated_context); |
- std::string filesystem_id = isolated_context->RegisterDraggedFileSystem( |
- files); |
- if (!filesystem_id.empty()) { |
- // Grant the permission iff the ID is valid. |
- policy->GrantReadFileSystem(renderer_id, filesystem_id); |
- } |
- filtered_data.filesystem_id = base::UTF8ToUTF16(filesystem_id); |
- |
- storage::FileSystemContext* file_system_context = |
- BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(), |
- GetSiteInstance()) |
- ->GetFileSystemContext(); |
- for (size_t i = 0; i < filtered_data.file_system_files.size(); ++i) { |
- storage::FileSystemURL file_system_url = |
- file_system_context->CrackURL(filtered_data.file_system_files[i].url); |
- |
- std::string register_name; |
- std::string filesystem_id = isolated_context->RegisterFileSystemForPath( |
- file_system_url.type(), file_system_url.filesystem_id(), |
- file_system_url.path(), ®ister_name); |
- policy->GrantReadFileSystem(renderer_id, filesystem_id); |
- |
- // Note: We are using the origin URL provided by the sender here. It may be |
- // different from the receiver's. |
- filtered_data.file_system_files[i].url = |
- GURL(storage::GetIsolatedFileSystemRootURIString( |
- file_system_url.origin(), filesystem_id, std::string()) |
- .append(register_name)); |
- } |
- |
- Send(new DragMsg_TargetDragEnter(GetRoutingID(), filtered_data, client_pt, |
+ std::vector<MimeTypeKindPair> meta_data; |
+ DropDataToMetaData(filtered_data, meta_data); |
+ Send(new DragMsg_TargetDragEnter(GetRoutingID(), meta_data, client_pt, |
screen_pt, operations_allowed, |
key_modifiers)); |
} |
@@ -698,12 +680,14 @@ void RenderViewHostImpl::DragTargetDragLeave() { |
Send(new DragMsg_TargetDragLeave(GetRoutingID())); |
} |
-void RenderViewHostImpl::DragTargetDrop( |
- const gfx::Point& client_pt, |
- const gfx::Point& screen_pt, |
- int key_modifiers) { |
- Send(new DragMsg_TargetDrop(GetRoutingID(), client_pt, screen_pt, |
- key_modifiers)); |
+void RenderViewHostImpl::DragTargetDrop(const DropData& drop_data, |
+ const gfx::Point& client_pt, |
+ const gfx::Point& screen_pt, |
+ int key_modifiers) { |
+ DropData filtered_data(drop_data); |
+ FilterDropData(filtered_data); |
+ Send(new DragMsg_TargetDrop(GetRoutingID(), filtered_data, client_pt, |
+ screen_pt, key_modifiers)); |
} |
void RenderViewHostImpl::DragSourceEndedAt( |
@@ -1357,4 +1341,82 @@ void RenderViewHostImpl::RenderViewReady() { |
delegate_->RenderViewReady(this); |
} |
+void RenderViewHostImpl::FilterDropData(DropData& filtered_data) { |
+ const int renderer_id = GetProcess()->GetID(); |
+ ChildProcessSecurityPolicyImpl* policy = |
+ ChildProcessSecurityPolicyImpl::GetInstance(); |
+ |
+ GetProcess()->FilterURL(true, &filtered_data.url); |
+ if (filtered_data.did_originate_from_renderer) { |
+ filtered_data.filenames.clear(); |
+ } |
+ |
+ // The filenames vector, on the other hand, does represent a capability to |
+ // access the given files. |
+ storage::IsolatedContext::FileInfoSet files; |
+ for (std::vector<ui::FileInfo>::iterator iter( |
+ filtered_data.filenames.begin()); |
+ iter != filtered_data.filenames.end(); ++iter) { |
Avi (use Gerrit)
2016/04/08 21:24:08
Prefer |for (:)| syntax; it's cleaner and easier t
hush (inactive)
2016/04/12 00:07:49
done
|
+ // A dragged file may wind up as the value of an input element, or it |
+ // may be used as the target of a navigation instead. We don't know |
+ // which will happen at this point, so generously grant both access |
+ // and request permissions to the specific file to cover both cases. |
+ // We do not give it the permission to request all file:// URLs. |
+ |
+ // Make sure we have the same display_name as the one we register. |
+ if (iter->display_name.empty()) { |
+ std::string name; |
+ files.AddPath(iter->path, &name); |
+ iter->display_name = base::FilePath::FromUTF8Unsafe(name); |
+ } else { |
+ files.AddPathWithName(iter->path, iter->display_name.AsUTF8Unsafe()); |
+ } |
+ |
+ policy->GrantRequestSpecificFileURL(renderer_id, |
+ net::FilePathToFileURL(iter->path)); |
+ |
+ // If the renderer already has permission to read these paths, we don't need |
+ // to re-grant them. This prevents problems with DnD for files in the CrOS |
+ // file manager--the file manager already had read/write access to those |
+ // directories, but dragging a file would cause the read/write access to be |
+ // overwritten with read-only access, making them impossible to delete or |
+ // rename until the renderer was killed. |
+ if (!policy->CanReadFile(renderer_id, iter->path)) |
+ policy->GrantReadFile(renderer_id, iter->path); |
+ } |
+ |
+ storage::IsolatedContext* isolated_context = |
+ storage::IsolatedContext::GetInstance(); |
+ DCHECK(isolated_context); |
+ std::string filesystem_id = |
+ isolated_context->RegisterDraggedFileSystem(files); |
+ if (!filesystem_id.empty()) { |
+ // Grant the permission iff the ID is valid. |
+ policy->GrantReadFileSystem(renderer_id, filesystem_id); |
+ } |
+ filtered_data.filesystem_id = base::UTF8ToUTF16(filesystem_id); |
+ |
+ storage::FileSystemContext* file_system_context = |
+ BrowserContext::GetStoragePartition(GetProcess()->GetBrowserContext(), |
+ GetSiteInstance()) |
+ ->GetFileSystemContext(); |
+ for (size_t i = 0; i < filtered_data.file_system_files.size(); ++i) { |
+ storage::FileSystemURL file_system_url = |
+ file_system_context->CrackURL(filtered_data.file_system_files[i].url); |
+ |
+ std::string register_name; |
+ std::string filesystem_id = isolated_context->RegisterFileSystemForPath( |
+ file_system_url.type(), file_system_url.filesystem_id(), |
+ file_system_url.path(), ®ister_name); |
+ policy->GrantReadFileSystem(renderer_id, filesystem_id); |
+ |
+ // Note: We are using the origin URL provided by the sender here. It may be |
+ // different from the receiver's. |
+ filtered_data.file_system_files[i].url = |
+ GURL(storage::GetIsolatedFileSystemRootURIString( |
+ file_system_url.origin(), filesystem_id, std::string()) |
+ .append(register_name)); |
+ } |
+} |
+ |
} // namespace content |