| 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/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" | |
| 10 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 12 #include "content/browser/download/drag_download_util.h" | |
| 13 #include "content/browser/frame_host/interstitial_page_impl.h" | 11 #include "content/browser/frame_host/interstitial_page_impl.h" |
| 14 #include "content/browser/frame_host/navigation_entry_impl.h" | 12 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 15 #include "content/browser/renderer_host/dip_util.h" | 13 #include "content/browser/renderer_host/dip_util.h" |
| 16 #include "content/browser/renderer_host/overscroll_controller.h" | 14 #include "content/browser/renderer_host/overscroll_controller.h" |
| 17 #include "content/browser/renderer_host/render_view_host_factory.h" | 15 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 18 #include "content/browser/renderer_host/render_view_host_impl.h" | 16 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 19 #include "content/browser/renderer_host/render_widget_host_impl.h" | 17 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 20 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 18 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 21 #include "content/browser/web_contents/aura/image_window_delegate.h" | 19 #include "content/browser/web_contents/aura/image_window_delegate.h" |
| 22 #include "content/browser/web_contents/aura/shadow_layer_delegate.h" | 20 #include "content/browser/web_contents/aura/shadow_layer_delegate.h" |
| 23 #include "content/browser/web_contents/aura/window_slider.h" | 21 #include "content/browser/web_contents/aura/window_slider.h" |
| 24 #include "content/browser/web_contents/touch_editable_impl_aura.h" | 22 #include "content/browser/web_contents/touch_editable_impl_aura.h" |
| 25 #include "content/browser/web_contents/web_contents_impl.h" | 23 #include "content/browser/web_contents/web_contents_impl.h" |
| 26 #include "content/public/browser/content_browser_client.h" | |
| 27 #include "content/public/browser/notification_observer.h" | 24 #include "content/public/browser/notification_observer.h" |
| 28 #include "content/public/browser/notification_registrar.h" | 25 #include "content/public/browser/notification_registrar.h" |
| 29 #include "content/public/browser/notification_source.h" | 26 #include "content/public/browser/notification_source.h" |
| 30 #include "content/public/browser/notification_types.h" | 27 #include "content/public/browser/notification_types.h" |
| 31 #include "content/public/browser/overscroll_configuration.h" | 28 #include "content/public/browser/overscroll_configuration.h" |
| 32 #include "content/public/browser/render_view_host.h" | 29 #include "content/public/browser/render_view_host.h" |
| 33 #include "content/public/browser/render_widget_host.h" | 30 #include "content/public/browser/render_widget_host.h" |
| 34 #include "content/public/browser/render_widget_host_view.h" | 31 #include "content/public/browser/render_widget_host_view.h" |
| 35 #include "content/public/browser/web_contents_delegate.h" | 32 #include "content/public/browser/web_contents_delegate.h" |
| 36 #include "content/public/browser/web_contents_observer.h" | 33 #include "content/public/browser/web_contents_observer.h" |
| 37 #include "content/public/browser/web_contents_view_delegate.h" | 34 #include "content/public/browser/web_contents_view_delegate.h" |
| 38 #include "content/public/browser/web_drag_dest_delegate.h" | 35 #include "content/public/browser/web_drag_dest_delegate.h" |
| 39 #include "content/public/common/content_client.h" | |
| 40 #include "content/public/common/content_switches.h" | 36 #include "content/public/common/content_switches.h" |
| 41 #include "content/public/common/drop_data.h" | 37 #include "content/public/common/drop_data.h" |
| 42 #include "net/base/net_util.h" | 38 #include "net/base/net_util.h" |
| 43 #include "third_party/WebKit/public/web/WebInputEvent.h" | 39 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 44 #include "ui/aura/client/aura_constants.h" | 40 #include "ui/aura/client/aura_constants.h" |
| 45 #include "ui/aura/client/drag_drop_client.h" | 41 #include "ui/aura/client/drag_drop_client.h" |
| 46 #include "ui/aura/client/drag_drop_delegate.h" | 42 #include "ui/aura/client/drag_drop_delegate.h" |
| 47 #include "ui/aura/client/window_tree_client.h" | 43 #include "ui/aura/client/window_tree_client.h" |
| 48 #include "ui/aura/env.h" | 44 #include "ui/aura/env.h" |
| 49 #include "ui/aura/root_window.h" | 45 #include "ui/aura/root_window.h" |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 // Images without ALT text will only have a file extension so we need to | 249 // Images without ALT text will only have a file extension so we need to |
| 254 // synthesize one from the provided extension and URL. | 250 // synthesize one from the provided extension and URL. |
| 255 if (file_name.BaseName().RemoveExtension().empty()) { | 251 if (file_name.BaseName().RemoveExtension().empty()) { |
| 256 const string16 extension = file_name.Extension(); | 252 const string16 extension = file_name.Extension(); |
| 257 // Retrieve the name from the URL. | 253 // Retrieve the name from the URL. |
| 258 file_name = base::FilePath(net::GetSuggestedFilename( | 254 file_name = base::FilePath(net::GetSuggestedFilename( |
| 259 drop_data.url, "", "", "", "", "")).ReplaceExtension(extension); | 255 drop_data.url, "", "", "", "", "")).ReplaceExtension(extension); |
| 260 } | 256 } |
| 261 provider->SetFileContents(file_name, drop_data.file_contents); | 257 provider->SetFileContents(file_name, drop_data.file_contents); |
| 262 } | 258 } |
| 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 (!base::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 } | |
| 322 #endif | 259 #endif |
| 323 | 260 |
| 324 // Utility to fill a ui::OSExchangeDataProvider object from DropData. | 261 // Utility to fill a ui::OSExchangeDataProvider object from DropData. |
| 325 void PrepareDragData(const DropData& drop_data, | 262 void PrepareDragData(const DropData& drop_data, |
| 326 ui::OSExchangeData::Provider* provider, | 263 ui::OSExchangeData::Provider* provider) { |
| 327 WebContentsImpl* web_contents) { | |
| 328 #if defined(OS_WIN) | 264 #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); | |
| 333 // We set the file contents before the URL because the URL also sets file | 265 // We set the file contents before the URL because the URL also sets file |
| 334 // contents (to a .URL shortcut). We want to prefer file content data over | 266 // contents (to a .URL shortcut). We want to prefer file content data over |
| 335 // a shortcut so we add it first. | 267 // a shortcut so we add it first. |
| 336 if (!drop_data.file_contents.empty()) | 268 if (!drop_data.file_contents.empty()) |
| 337 PrepareDragForFileContents(drop_data, provider); | 269 PrepareDragForFileContents(drop_data, provider); |
| 338 #endif | 270 #endif |
| 339 if (!drop_data.text.string().empty()) | 271 if (!drop_data.text.string().empty()) |
| 340 provider->SetString(drop_data.text.string()); | 272 provider->SetString(drop_data.text.string()); |
| 341 if (drop_data.url.is_valid()) | 273 if (drop_data.url.is_valid()) |
| 342 provider->SetURL(drop_data.url, drop_data.url_title); | 274 provider->SetURL(drop_data.url, drop_data.url_title); |
| (...skipping 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1424 aura::Window* root_window = GetNativeView()->GetRootWindow(); | 1356 aura::Window* root_window = GetNativeView()->GetRootWindow(); |
| 1425 if (!aura::client::GetDragDropClient(root_window)) { | 1357 if (!aura::client::GetDragDropClient(root_window)) { |
| 1426 web_contents_->SystemDragEnded(); | 1358 web_contents_->SystemDragEnded(); |
| 1427 return; | 1359 return; |
| 1428 } | 1360 } |
| 1429 | 1361 |
| 1430 if (touch_editable_) | 1362 if (touch_editable_) |
| 1431 touch_editable_->EndTouchEditing(); | 1363 touch_editable_->EndTouchEditing(); |
| 1432 | 1364 |
| 1433 ui::OSExchangeData::Provider* provider = ui::OSExchangeData::CreateProvider(); | 1365 ui::OSExchangeData::Provider* provider = ui::OSExchangeData::CreateProvider(); |
| 1434 PrepareDragData(drop_data, provider, web_contents_); | 1366 PrepareDragData(drop_data, provider); |
| 1435 | 1367 |
| 1436 ui::OSExchangeData data(provider); // takes ownership of |provider|. | 1368 ui::OSExchangeData data(provider); // takes ownership of |provider|. |
| 1437 | 1369 |
| 1438 if (!image.isNull()) { | 1370 if (!image.isNull()) { |
| 1439 drag_utils::SetDragImageOnDataObject(image, | 1371 drag_utils::SetDragImageOnDataObject(image, |
| 1440 gfx::Size(image.width(), image.height()), image_offset, &data); | 1372 gfx::Size(image.width(), image.height()), image_offset, &data); |
| 1441 } | 1373 } |
| 1442 | 1374 |
| 1443 scoped_ptr<WebDragSourceAura> drag_source( | 1375 scoped_ptr<WebDragSourceAura> drag_source( |
| 1444 new WebDragSourceAura(GetNativeView(), web_contents_)); | 1376 new WebDragSourceAura(GetNativeView(), web_contents_)); |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1785 event.location(), | 1717 event.location(), |
| 1786 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), | 1718 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
| 1787 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1719 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
| 1788 if (drag_dest_delegate_) | 1720 if (drag_dest_delegate_) |
| 1789 drag_dest_delegate_->OnDrop(); | 1721 drag_dest_delegate_->OnDrop(); |
| 1790 current_drop_data_.reset(); | 1722 current_drop_data_.reset(); |
| 1791 return current_drag_op_; | 1723 return current_drag_op_; |
| 1792 } | 1724 } |
| 1793 | 1725 |
| 1794 } // namespace content | 1726 } // namespace content |
| OLD | NEW |