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

Side by Side Diff: chrome/browser/tab_contents/web_contents_view_win.cc

Issue 19417: Generate a file name when dragging an image to the desktop (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | chrome/common/render_messages.h » ('j') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/browser/tab_contents/web_contents_view_win.h" 5 #include "chrome/browser/tab_contents/web_contents_view_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "chrome/browser/bookmarks/bookmark_drag_data.h" 9 #include "chrome/browser/bookmarks/bookmark_drag_data.h"
10 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful. 10 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful.
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/download/download_request_manager.h" 12 #include "chrome/browser/download/download_request_manager.h"
13 #include "chrome/browser/renderer_host/render_process_host.h" 13 #include "chrome/browser/renderer_host/render_process_host.h"
14 #include "chrome/browser/renderer_host/render_view_host.h" 14 #include "chrome/browser/renderer_host/render_view_host.h"
15 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" 15 #include "chrome/browser/renderer_host/render_widget_host_view_win.h"
16 #include "chrome/browser/tab_contents/render_view_context_menu.h" 16 #include "chrome/browser/tab_contents/render_view_context_menu.h"
17 #include "chrome/browser/tab_contents/render_view_context_menu_controller.h" 17 #include "chrome/browser/tab_contents/render_view_context_menu_controller.h"
18 #include "chrome/browser/tab_contents/interstitial_page.h" 18 #include "chrome/browser/tab_contents/interstitial_page.h"
19 #include "chrome/browser/tab_contents/tab_contents_delegate.h" 19 #include "chrome/browser/tab_contents/tab_contents_delegate.h"
20 #include "chrome/browser/tab_contents/web_contents.h" 20 #include "chrome/browser/tab_contents/web_contents.h"
21 #include "chrome/browser/tab_contents/web_drag_source.h" 21 #include "chrome/browser/tab_contents/web_drag_source.h"
22 #include "chrome/browser/tab_contents/web_drop_target.h" 22 #include "chrome/browser/tab_contents/web_drop_target.h"
23 #include "chrome/browser/views/find_bar_win.h" 23 #include "chrome/browser/views/find_bar_win.h"
24 #include "chrome/browser/views/sad_tab_view.h" 24 #include "chrome/browser/views/sad_tab_view.h"
25 #include "chrome/common/gfx/chrome_canvas.h" 25 #include "chrome/common/gfx/chrome_canvas.h"
26 #include "chrome/common/os_exchange_data.h" 26 #include "chrome/common/os_exchange_data.h"
27 #include "net/base/net_util.h"
27 #include "webkit/glue/plugins/webplugin_delegate_impl.h" 28 #include "webkit/glue/plugins/webplugin_delegate_impl.h"
28 29
29 namespace { 30 namespace {
30 31
31 // Windows callback for OnDestroy to detach the plugin windows. 32 // Windows callback for OnDestroy to detach the plugin windows.
32 BOOL CALLBACK DetachPluginWindowsCallback(HWND window, LPARAM param) { 33 BOOL CALLBACK DetachPluginWindowsCallback(HWND window, LPARAM param) {
33 if (WebPluginDelegateImpl::IsPluginDelegateWindow(window)) { 34 if (WebPluginDelegateImpl::IsPluginDelegateWindow(window)) {
34 ::ShowWindow(window, SW_HIDE); 35 ::ShowWindow(window, SW_HIDE);
35 SetParent(window, NULL); 36 SetParent(window, NULL);
36 } 37 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 90
90 void WebContentsViewWin::StartDragging(const WebDropData& drop_data) { 91 void WebContentsViewWin::StartDragging(const WebDropData& drop_data) {
91 scoped_refptr<OSExchangeData> data(new OSExchangeData); 92 scoped_refptr<OSExchangeData> data(new OSExchangeData);
92 93
93 // TODO(tc): Generate an appropriate drag image. 94 // TODO(tc): Generate an appropriate drag image.
94 95
95 // We set the file contents before the URL because the URL also sets file 96 // We set the file contents before the URL because the URL also sets file
96 // contents (to a .URL shortcut). We want to prefer file content data over a 97 // contents (to a .URL shortcut). We want to prefer file content data over a
97 // shortcut so we add it first. 98 // shortcut so we add it first.
98 if (!drop_data.file_contents.empty()) { 99 if (!drop_data.file_contents.empty()) {
99 data->SetFileContents(drop_data.file_description_filename, 100 // Images without ALT text will only have a file extension so we need to
100 drop_data.file_contents); 101 // synthesize one from the provided extension and URL.
102 FilePath file_name(drop_data.file_description_filename);
103 file_name = file_name.BaseName().RemoveExtension();
104 if (file_name.value().empty()) {
105 // Retrieve the name from the URL.
106 file_name = FilePath::FromWStringHack(
107 net::GetSuggestedFilename(drop_data.url, L"", L""));
108 }
109 file_name = file_name.ReplaceExtension(drop_data.file_extension);
110 data->SetFileContents(file_name.value(), drop_data.file_contents);
101 } 111 }
102 if (!drop_data.text_html.empty()) 112 if (!drop_data.text_html.empty())
103 data->SetHtml(drop_data.text_html, drop_data.html_base_url); 113 data->SetHtml(drop_data.text_html, drop_data.html_base_url);
104 if (drop_data.url.is_valid()) { 114 if (drop_data.url.is_valid()) {
105 if (drop_data.url.SchemeIs("javascript")) { 115 if (drop_data.url.SchemeIs("javascript")) {
106 // We don't want to allow javascript URLs to be dragged to the desktop, 116 // We don't want to allow javascript URLs to be dragged to the desktop,
107 // but we do want to allow them to be added to the bookmarks bar 117 // but we do want to allow them to be added to the bookmarks bar
108 // (bookmarklets). 118 // (bookmarklets).
109 BookmarkDragData::Element bm_elt; 119 BookmarkDragData::Element bm_elt;
110 bm_elt.is_url = true; 120 bm_elt.is_url = true;
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 } 661 }
652 return false; 662 return false;
653 } 663 }
654 664
655 void WebContentsViewWin::WheelZoom(int distance) { 665 void WebContentsViewWin::WheelZoom(int distance) {
656 if (web_contents_->delegate()) { 666 if (web_contents_->delegate()) {
657 bool zoom_in = distance > 0; 667 bool zoom_in = distance > 0;
658 web_contents_->delegate()->ContentsZoomChange(zoom_in); 668 web_contents_->delegate()->ContentsZoomChange(zoom_in);
659 } 669 }
660 } 670 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/render_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698