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

Unified Diff: content/browser/web_contents/web_contents_view_aura.cc

Issue 23591026: Include file contents in drag exchange on aura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/web_contents/web_contents_view_aura.cc
diff --git a/content/browser/web_contents/web_contents_view_aura.cc b/content/browser/web_contents/web_contents_view_aura.cc
index fc7c928c41e4c1df4c184480c8114ea446680663..12cd2e7e2e976b58d03056f39cb65a6e0cfbfb81 100644
--- a/content/browser/web_contents/web_contents_view_aura.cc
+++ b/content/browser/web_contents/web_contents_view_aura.cc
@@ -35,6 +35,7 @@
#include "content/public/browser/web_drag_dest_delegate.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/drop_data.h"
+#include "net/base/net_util.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/drag_drop_client.h"
@@ -235,9 +236,35 @@ class WebDragSourceAura : public base::MessageLoopForUI::Observer,
DISALLOW_COPY_AND_ASSIGN(WebDragSourceAura);
};
+void PrepareDragForFileContents(const DropData& drop_data,
sky 2013/09/05 15:42:02 Add a description.
+ ui::OSExchangeData::Provider* provider) {
+ static const int kMaxFilenameLength = 255; // FAT and NTFS
sky 2013/09/05 15:42:02 Isn't this win specific? Also, isn't there an OS c
+ base::FilePath file_name(drop_data.file_description_filename);
+
+ // Images without ALT text will only have a file extension so we need to
+ // synthesize one from the provided extension and URL.
+ if (file_name.BaseName().RemoveExtension().empty()) {
+ const string16 extension = file_name.Extension();
+ // Retrieve the name from the URL.
+ file_name = base::FilePath(
+ net::GetSuggestedFilename(drop_data.url, "", "", "", "", ""));
+ if (file_name.value().size() + extension.size() > kMaxFilenameLength) {
+ file_name = base::FilePath(file_name.value().substr(
+ 0, kMaxFilenameLength - extension.size()));
sky 2013/09/05 15:42:02 What if extension.size() > kMaxFilenameLength?
+ }
+ file_name = file_name.ReplaceExtension(extension);
+ }
+ provider->SetFileContents(file_name, drop_data.file_contents);
+}
+
// Utility to fill a ui::OSExchangeDataProvider object from DropData.
void PrepareDragData(const DropData& drop_data,
ui::OSExchangeData::Provider* provider) {
+ // We set the file contents before the URL because the URL also sets file
+ // contents (to a .URL shortcut). We want to prefer file content data over
+ // a shortcut so we add it first.
+ if (!drop_data.file_contents.empty())
+ PrepareDragForFileContents(drop_data, provider);
if (!drop_data.text.string().empty())
provider->SetString(drop_data.text.string());
if (drop_data.url.is_valid())
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698