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

Side by Side Diff: content/browser/web_contents/web_contents_view_aura.cc

Issue 137783028: Merge 244355 "Add CF_HDROP path for dragging on Win Aura" (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1700/src/
Patch Set: Created 6 years, 11 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/file_util.h"
9 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "content/browser/download/drag_download_util.h"
11 #include "content/browser/frame_host/interstitial_page_impl.h" 13 #include "content/browser/frame_host/interstitial_page_impl.h"
12 #include "content/browser/frame_host/navigation_entry_impl.h" 14 #include "content/browser/frame_host/navigation_entry_impl.h"
13 #include "content/browser/renderer_host/dip_util.h" 15 #include "content/browser/renderer_host/dip_util.h"
14 #include "content/browser/renderer_host/overscroll_controller.h" 16 #include "content/browser/renderer_host/overscroll_controller.h"
15 #include "content/browser/renderer_host/render_view_host_factory.h" 17 #include "content/browser/renderer_host/render_view_host_factory.h"
16 #include "content/browser/renderer_host/render_view_host_impl.h" 18 #include "content/browser/renderer_host/render_view_host_impl.h"
17 #include "content/browser/renderer_host/render_widget_host_impl.h" 19 #include "content/browser/renderer_host/render_widget_host_impl.h"
18 #include "content/browser/renderer_host/render_widget_host_view_aura.h" 20 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
19 #include "content/browser/web_contents/aura/image_window_delegate.h" 21 #include "content/browser/web_contents/aura/image_window_delegate.h"
20 #include "content/browser/web_contents/aura/shadow_layer_delegate.h" 22 #include "content/browser/web_contents/aura/shadow_layer_delegate.h"
21 #include "content/browser/web_contents/aura/window_slider.h" 23 #include "content/browser/web_contents/aura/window_slider.h"
22 #include "content/browser/web_contents/touch_editable_impl_aura.h" 24 #include "content/browser/web_contents/touch_editable_impl_aura.h"
23 #include "content/browser/web_contents/web_contents_impl.h" 25 #include "content/browser/web_contents/web_contents_impl.h"
26 #include "content/public/browser/content_browser_client.h"
24 #include "content/public/browser/notification_observer.h" 27 #include "content/public/browser/notification_observer.h"
25 #include "content/public/browser/notification_registrar.h" 28 #include "content/public/browser/notification_registrar.h"
26 #include "content/public/browser/notification_source.h" 29 #include "content/public/browser/notification_source.h"
27 #include "content/public/browser/notification_types.h" 30 #include "content/public/browser/notification_types.h"
28 #include "content/public/browser/overscroll_configuration.h" 31 #include "content/public/browser/overscroll_configuration.h"
29 #include "content/public/browser/render_view_host.h" 32 #include "content/public/browser/render_view_host.h"
30 #include "content/public/browser/render_widget_host.h" 33 #include "content/public/browser/render_widget_host.h"
31 #include "content/public/browser/render_widget_host_view.h" 34 #include "content/public/browser/render_widget_host_view.h"
32 #include "content/public/browser/web_contents_delegate.h" 35 #include "content/public/browser/web_contents_delegate.h"
33 #include "content/public/browser/web_contents_observer.h" 36 #include "content/public/browser/web_contents_observer.h"
34 #include "content/public/browser/web_contents_view_delegate.h" 37 #include "content/public/browser/web_contents_view_delegate.h"
35 #include "content/public/browser/web_drag_dest_delegate.h" 38 #include "content/public/browser/web_drag_dest_delegate.h"
39 #include "content/public/common/content_client.h"
36 #include "content/public/common/content_switches.h" 40 #include "content/public/common/content_switches.h"
37 #include "content/public/common/drop_data.h" 41 #include "content/public/common/drop_data.h"
38 #include "net/base/net_util.h" 42 #include "net/base/net_util.h"
39 #include "third_party/WebKit/public/web/WebInputEvent.h" 43 #include "third_party/WebKit/public/web/WebInputEvent.h"
40 #include "ui/aura/client/aura_constants.h" 44 #include "ui/aura/client/aura_constants.h"
41 #include "ui/aura/client/drag_drop_client.h" 45 #include "ui/aura/client/drag_drop_client.h"
42 #include "ui/aura/client/drag_drop_delegate.h" 46 #include "ui/aura/client/drag_drop_delegate.h"
43 #include "ui/aura/client/window_tree_client.h" 47 #include "ui/aura/client/window_tree_client.h"
44 #include "ui/aura/env.h" 48 #include "ui/aura/env.h"
45 #include "ui/aura/root_window.h" 49 #include "ui/aura/root_window.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // Images without ALT text will only have a file extension so we need to 253 // Images without ALT text will only have a file extension so we need to
250 // synthesize one from the provided extension and URL. 254 // synthesize one from the provided extension and URL.
251 if (file_name.BaseName().RemoveExtension().empty()) { 255 if (file_name.BaseName().RemoveExtension().empty()) {
252 const string16 extension = file_name.Extension(); 256 const string16 extension = file_name.Extension();
253 // Retrieve the name from the URL. 257 // Retrieve the name from the URL.
254 file_name = base::FilePath(net::GetSuggestedFilename( 258 file_name = base::FilePath(net::GetSuggestedFilename(
255 drop_data.url, "", "", "", "", "")).ReplaceExtension(extension); 259 drop_data.url, "", "", "", "", "")).ReplaceExtension(extension);
256 } 260 }
257 provider->SetFileContents(file_name, drop_data.file_contents); 261 provider->SetFileContents(file_name, drop_data.file_contents);
258 } 262 }
263
264 void PrepareDragForDownload(
265 const DropData& drop_data,
266 ui::OSExchangeData::Provider* provider,
267 WebContentsImpl* web_contents) {
268 const GURL& page_url = web_contents->GetLastCommittedURL();
269 const std::string& page_encoding = web_contents->GetEncoding();
270
271 // Parse the download metadata.
272 base::string16 mime_type;
273 base::FilePath file_name;
274 GURL download_url;
275 if (!ParseDownloadMetadata(drop_data.download_metadata,
276 &mime_type,
277 &file_name,
278 &download_url))
279 return;
280
281 // Generate the file name based on both mime type and proposed file name.
282 std::string default_name =
283 GetContentClient()->browser()->GetDefaultDownloadName();
284 base::FilePath generated_download_file_name =
285 net::GenerateFileName(download_url,
286 std::string(),
287 std::string(),
288 base::UTF16ToUTF8(file_name.value()),
289 base::UTF16ToUTF8(mime_type),
290 default_name);
291
292 // http://crbug.com/332579
293 base::ThreadRestrictions::ScopedAllowIO allow_file_operations;
294
295 base::FilePath temp_dir_path;
296 if (!file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("chrome_drag"),
297 &temp_dir_path))
298 return;
299
300 base::FilePath download_path =
301 temp_dir_path.Append(generated_download_file_name);
302
303 // We cannot know when the target application will be done using the temporary
304 // file, so schedule it to be deleted after rebooting.
305 base::DeleteFileAfterReboot(download_path);
306 base::DeleteFileAfterReboot(temp_dir_path);
307
308 // Provide the data as file (CF_HDROP). A temporary download file with the
309 // Zone.Identifier ADS (Alternate Data Stream) attached will be created.
310 scoped_refptr<DragDownloadFile> download_file =
311 new DragDownloadFile(
312 download_path,
313 scoped_ptr<net::FileStream>(),
314 download_url,
315 Referrer(page_url, drop_data.referrer_policy),
316 page_encoding,
317 web_contents);
318 ui::OSExchangeData::DownloadFileInfo file_download(base::FilePath(),
319 download_file.get());
320 provider->SetDownloadFileInfo(file_download);
321 }
259 #endif 322 #endif
260 323
261 // Utility to fill a ui::OSExchangeDataProvider object from DropData. 324 // Utility to fill a ui::OSExchangeDataProvider object from DropData.
262 void PrepareDragData(const DropData& drop_data, 325 void PrepareDragData(const DropData& drop_data,
263 ui::OSExchangeData::Provider* provider) { 326 ui::OSExchangeData::Provider* provider,
327 WebContentsImpl* web_contents) {
264 #if defined(OS_WIN) 328 #if defined(OS_WIN)
329 // Put download before file contents to prefer the download of a image over
330 // its thumbnail link.
331 if (!drop_data.download_metadata.empty())
332 PrepareDragForDownload(drop_data, provider, web_contents);
265 // We set the file contents before the URL because the URL also sets file 333 // We set the file contents before the URL because the URL also sets file
266 // contents (to a .URL shortcut). We want to prefer file content data over 334 // contents (to a .URL shortcut). We want to prefer file content data over
267 // a shortcut so we add it first. 335 // a shortcut so we add it first.
268 if (!drop_data.file_contents.empty()) 336 if (!drop_data.file_contents.empty())
269 PrepareDragForFileContents(drop_data, provider); 337 PrepareDragForFileContents(drop_data, provider);
270 #endif 338 #endif
271 if (!drop_data.text.string().empty()) 339 if (!drop_data.text.string().empty())
272 provider->SetString(drop_data.text.string()); 340 provider->SetString(drop_data.text.string());
273 if (drop_data.url.is_valid()) 341 if (drop_data.url.is_valid())
274 provider->SetURL(drop_data.url, drop_data.url_title); 342 provider->SetURL(drop_data.url, drop_data.url_title);
(...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 aura::Window* root_window = GetNativeView()->GetRootWindow(); 1424 aura::Window* root_window = GetNativeView()->GetRootWindow();
1357 if (!aura::client::GetDragDropClient(root_window)) { 1425 if (!aura::client::GetDragDropClient(root_window)) {
1358 web_contents_->SystemDragEnded(); 1426 web_contents_->SystemDragEnded();
1359 return; 1427 return;
1360 } 1428 }
1361 1429
1362 if (touch_editable_) 1430 if (touch_editable_)
1363 touch_editable_->EndTouchEditing(); 1431 touch_editable_->EndTouchEditing();
1364 1432
1365 ui::OSExchangeData::Provider* provider = ui::OSExchangeData::CreateProvider(); 1433 ui::OSExchangeData::Provider* provider = ui::OSExchangeData::CreateProvider();
1366 PrepareDragData(drop_data, provider); 1434 PrepareDragData(drop_data, provider, web_contents_);
1367 1435
1368 ui::OSExchangeData data(provider); // takes ownership of |provider|. 1436 ui::OSExchangeData data(provider); // takes ownership of |provider|.
1369 1437
1370 if (!image.isNull()) { 1438 if (!image.isNull()) {
1371 drag_utils::SetDragImageOnDataObject(image, 1439 drag_utils::SetDragImageOnDataObject(image,
1372 gfx::Size(image.width(), image.height()), image_offset, &data); 1440 gfx::Size(image.width(), image.height()), image_offset, &data);
1373 } 1441 }
1374 1442
1375 scoped_ptr<WebDragSourceAura> drag_source( 1443 scoped_ptr<WebDragSourceAura> drag_source(
1376 new WebDragSourceAura(GetNativeView(), web_contents_)); 1444 new WebDragSourceAura(GetNativeView(), web_contents_));
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 event.location(), 1785 event.location(),
1718 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), 1786 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(),
1719 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 1787 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
1720 if (drag_dest_delegate_) 1788 if (drag_dest_delegate_)
1721 drag_dest_delegate_->OnDrop(); 1789 drag_dest_delegate_->OnDrop();
1722 current_drop_data_.reset(); 1790 current_drop_data_.reset();
1723 return current_drag_op_; 1791 return current_drag_op_;
1724 } 1792 }
1725 1793
1726 } // namespace content 1794 } // 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