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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/web_contents/web_contents_view_aura.h" 5 #include "content/browser/web_contents/web_contents_view_aura.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 17 matching lines...) Expand all
28 #include "content/public/browser/overscroll_configuration.h" 28 #include "content/public/browser/overscroll_configuration.h"
29 #include "content/public/browser/render_view_host.h" 29 #include "content/public/browser/render_view_host.h"
30 #include "content/public/browser/render_widget_host.h" 30 #include "content/public/browser/render_widget_host.h"
31 #include "content/public/browser/render_widget_host_view.h" 31 #include "content/public/browser/render_widget_host_view.h"
32 #include "content/public/browser/web_contents_delegate.h" 32 #include "content/public/browser/web_contents_delegate.h"
33 #include "content/public/browser/web_contents_observer.h" 33 #include "content/public/browser/web_contents_observer.h"
34 #include "content/public/browser/web_contents_view_delegate.h" 34 #include "content/public/browser/web_contents_view_delegate.h"
35 #include "content/public/browser/web_drag_dest_delegate.h" 35 #include "content/public/browser/web_drag_dest_delegate.h"
36 #include "content/public/common/content_switches.h" 36 #include "content/public/common/content_switches.h"
37 #include "content/public/common/drop_data.h" 37 #include "content/public/common/drop_data.h"
38 #include "net/base/net_util.h"
38 #include "third_party/WebKit/public/web/WebInputEvent.h" 39 #include "third_party/WebKit/public/web/WebInputEvent.h"
39 #include "ui/aura/client/aura_constants.h" 40 #include "ui/aura/client/aura_constants.h"
40 #include "ui/aura/client/drag_drop_client.h" 41 #include "ui/aura/client/drag_drop_client.h"
41 #include "ui/aura/client/drag_drop_delegate.h" 42 #include "ui/aura/client/drag_drop_delegate.h"
42 #include "ui/aura/root_window.h" 43 #include "ui/aura/root_window.h"
43 #include "ui/aura/root_window_observer.h" 44 #include "ui/aura/root_window_observer.h"
44 #include "ui/aura/window.h" 45 #include "ui/aura/window.h"
45 #include "ui/aura/window_observer.h" 46 #include "ui/aura/window_observer.h"
46 #include "ui/base/clipboard/clipboard.h" 47 #include "ui/base/clipboard/clipboard.h"
47 #include "ui/base/clipboard/custom_data_helper.h" 48 #include "ui/base/clipboard/custom_data_helper.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 aura::Window* window() const { return window_; } 229 aura::Window* window() const { return window_; }
229 230
230 private: 231 private:
231 aura::Window* window_; 232 aura::Window* window_;
232 WebContentsImpl* contents_; 233 WebContentsImpl* contents_;
233 NotificationRegistrar registrar_; 234 NotificationRegistrar registrar_;
234 235
235 DISALLOW_COPY_AND_ASSIGN(WebDragSourceAura); 236 DISALLOW_COPY_AND_ASSIGN(WebDragSourceAura);
236 }; 237 };
237 238
239 void PrepareDragForFileContents(const DropData& drop_data,
sky 2013/09/05 15:42:02 Add a description.
240 ui::OSExchangeData::Provider* provider) {
241 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
242 base::FilePath file_name(drop_data.file_description_filename);
243
244 // Images without ALT text will only have a file extension so we need to
245 // synthesize one from the provided extension and URL.
246 if (file_name.BaseName().RemoveExtension().empty()) {
247 const string16 extension = file_name.Extension();
248 // Retrieve the name from the URL.
249 file_name = base::FilePath(
250 net::GetSuggestedFilename(drop_data.url, "", "", "", "", ""));
251 if (file_name.value().size() + extension.size() > kMaxFilenameLength) {
252 file_name = base::FilePath(file_name.value().substr(
253 0, kMaxFilenameLength - extension.size()));
sky 2013/09/05 15:42:02 What if extension.size() > kMaxFilenameLength?
254 }
255 file_name = file_name.ReplaceExtension(extension);
256 }
257 provider->SetFileContents(file_name, drop_data.file_contents);
258 }
259
238 // Utility to fill a ui::OSExchangeDataProvider object from DropData. 260 // Utility to fill a ui::OSExchangeDataProvider object from DropData.
239 void PrepareDragData(const DropData& drop_data, 261 void PrepareDragData(const DropData& drop_data,
240 ui::OSExchangeData::Provider* provider) { 262 ui::OSExchangeData::Provider* provider) {
263 // We set the file contents before the URL because the URL also sets file
264 // contents (to a .URL shortcut). We want to prefer file content data over
265 // a shortcut so we add it first.
266 if (!drop_data.file_contents.empty())
267 PrepareDragForFileContents(drop_data, provider);
241 if (!drop_data.text.string().empty()) 268 if (!drop_data.text.string().empty())
242 provider->SetString(drop_data.text.string()); 269 provider->SetString(drop_data.text.string());
243 if (drop_data.url.is_valid()) 270 if (drop_data.url.is_valid())
244 provider->SetURL(drop_data.url, drop_data.url_title); 271 provider->SetURL(drop_data.url, drop_data.url_title);
245 if (!drop_data.html.string().empty()) 272 if (!drop_data.html.string().empty())
246 provider->SetHtml(drop_data.html.string(), drop_data.html_base_url); 273 provider->SetHtml(drop_data.html.string(), drop_data.html_base_url);
247 if (!drop_data.filenames.empty()) { 274 if (!drop_data.filenames.empty()) {
248 std::vector<ui::OSExchangeData::FileInfo> filenames; 275 std::vector<ui::OSExchangeData::FileInfo> filenames;
249 for (std::vector<DropData::FileInfo>::const_iterator it = 276 for (std::vector<DropData::FileInfo>::const_iterator it =
250 drop_data.filenames.begin(); 277 drop_data.filenames.begin();
(...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 event.location(), 1632 event.location(),
1606 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), 1633 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(),
1607 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 1634 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
1608 if (drag_dest_delegate_) 1635 if (drag_dest_delegate_)
1609 drag_dest_delegate_->OnDrop(); 1636 drag_dest_delegate_->OnDrop();
1610 current_drop_data_.reset(); 1637 current_drop_data_.reset();
1611 return current_drag_op_; 1638 return current_drag_op_;
1612 } 1639 }
1613 1640
1614 } // namespace content 1641 } // namespace content
OLDNEW
« 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