OLD | NEW |
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 // Download utility implementation | 5 // Download utility implementation |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "chrome/browser/download/download_util.h" | 9 #include "chrome/browser/download/download_util.h" |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 // How many times to cycle the complete animation. This should be an odd number | 41 // How many times to cycle the complete animation. This should be an odd number |
42 // so that the animation ends faded out. | 42 // so that the animation ends faded out. |
43 static const int kCompleteAnimationCycles = 5; | 43 static const int kCompleteAnimationCycles = 5; |
44 | 44 |
45 bool BaseContextMenu::IsItemChecked(int id) const { | 45 bool BaseContextMenu::IsItemChecked(int id) const { |
46 switch (id) { | 46 switch (id) { |
47 case OPEN_WHEN_COMPLETE: | 47 case OPEN_WHEN_COMPLETE: |
48 return download_->open_when_complete(); | 48 return download_->open_when_complete(); |
49 case ALWAYS_OPEN_TYPE: { | 49 case ALWAYS_OPEN_TYPE: { |
50 const std::wstring extension = | 50 const FilePath::StringType extension = |
51 file_util::GetFileExtensionFromPath(download_->full_path()); | 51 file_util::GetFileExtensionFromPath(download_->full_path()); |
52 return download_->manager()->ShouldOpenFileExtension(extension); | 52 return download_->manager()->ShouldOpenFileExtension(extension); |
53 } | 53 } |
54 } | 54 } |
55 return false; | 55 return false; |
56 } | 56 } |
57 | 57 |
58 bool BaseContextMenu::IsItemDefault(int id) const { | 58 bool BaseContextMenu::IsItemDefault(int id) const { |
59 return false; | 59 return false; |
60 } | 60 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 void BaseContextMenu::ExecuteCommand(int id) { | 108 void BaseContextMenu::ExecuteCommand(int id) { |
109 ScopedClipboardWriter scw(g_browser_process->clipboard_service()); | 109 ScopedClipboardWriter scw(g_browser_process->clipboard_service()); |
110 switch (id) { | 110 switch (id) { |
111 case SHOW_IN_FOLDER: | 111 case SHOW_IN_FOLDER: |
112 download_->manager()->ShowDownloadInShell(download_); | 112 download_->manager()->ShowDownloadInShell(download_); |
113 break; | 113 break; |
114 case COPY_LINK: | 114 case COPY_LINK: |
115 scw.WriteText(download_->url()); | 115 scw.WriteText(download_->url()); |
116 break; | 116 break; |
117 case COPY_PATH: | 117 case COPY_PATH: |
118 scw.WriteText(download_->full_path()); | 118 scw.WriteText(download_->full_path().ToWStringHack()); |
119 break; | 119 break; |
120 case COPY_FILE: | 120 case COPY_FILE: |
121 // TODO(paulg): Move to OSExchangeData when implementing drag and drop? | 121 // TODO(paulg): Move to OSExchangeData when implementing drag and drop? |
122 scw.WriteFile(download_->full_path()); | 122 scw.WriteFile(download_->full_path().ToWStringHack()); |
123 break; | 123 break; |
124 case OPEN_WHEN_COMPLETE: | 124 case OPEN_WHEN_COMPLETE: |
125 OpenDownload(download_); | 125 OpenDownload(download_); |
126 break; | 126 break; |
127 case ALWAYS_OPEN_TYPE: { | 127 case ALWAYS_OPEN_TYPE: { |
128 const std::wstring extension = | 128 const FilePath::StringType extension = |
129 file_util::GetFileExtensionFromPath(download_->full_path()); | 129 file_util::GetFileExtensionFromPath(download_->full_path()); |
130 download_->manager()->OpenFilesOfExtension( | 130 download_->manager()->OpenFilesOfExtension( |
131 extension, !IsItemChecked(ALWAYS_OPEN_TYPE)); | 131 extension, !IsItemChecked(ALWAYS_OPEN_TYPE)); |
132 break; | 132 break; |
133 } | 133 } |
134 case REMOVE_ITEM: | 134 case REMOVE_ITEM: |
135 download_->Remove(false); | 135 download_->Remove(false); |
136 break; | 136 break; |
137 case CANCEL: | 137 case CANCEL: |
138 download_->Cancel(true); | 138 download_->Cancel(true); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 context_menu.AppendMenuItem(REMOVE_ITEM, L"", Menu::NORMAL); | 214 context_menu.AppendMenuItem(REMOVE_ITEM, L"", Menu::NORMAL); |
215 context_menu.RunMenuAt(point.x, point.y); | 215 context_menu.RunMenuAt(point.x, point.y); |
216 } | 216 } |
217 | 217 |
218 DownloadDestinationContextMenu::~DownloadDestinationContextMenu() { | 218 DownloadDestinationContextMenu::~DownloadDestinationContextMenu() { |
219 } | 219 } |
220 | 220 |
221 // Download opening ------------------------------------------------------------ | 221 // Download opening ------------------------------------------------------------ |
222 | 222 |
223 bool CanOpenDownload(DownloadItem* download) { | 223 bool CanOpenDownload(DownloadItem* download) { |
224 std::wstring file_to_use = download->full_path(); | 224 FilePath file_to_use = download->full_path(); |
225 if (!download->original_name().empty()) | 225 if (!download->original_name().value().empty()) |
226 file_to_use = download->original_name(); | 226 file_to_use = download->original_name(); |
227 | 227 |
228 const std::wstring extension = | 228 const FilePath::StringType extension = |
229 file_util::GetFileExtensionFromPath(file_to_use); | 229 file_util::GetFileExtensionFromPath(file_to_use); |
230 return !download->manager()->IsExecutable(extension); | 230 return !download->manager()->IsExecutable(extension); |
231 } | 231 } |
232 | 232 |
233 void OpenDownload(DownloadItem* download) { | 233 void OpenDownload(DownloadItem* download) { |
234 if (download->state() == DownloadItem::IN_PROGRESS) | 234 if (download->state() == DownloadItem::IN_PROGRESS) |
235 download->set_open_when_complete(!download->open_when_complete()); | 235 download->set_open_when_complete(!download->open_when_complete()); |
236 else if (download->state() == DownloadItem::COMPLETE) | 236 else if (download->state() == DownloadItem::COMPLETE) |
237 download->manager()->OpenDownloadInShell(download, NULL); | 237 download->manager()->OpenDownloadInShell(download, NULL); |
238 } | 238 } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 return (GetBigProgressIconSize() - kBigIconSize) / 2; | 409 return (GetBigProgressIconSize() - kBigIconSize) / 2; |
410 } | 410 } |
411 | 411 |
412 // Download dragging | 412 // Download dragging |
413 void DragDownload(const DownloadItem* download, SkBitmap* icon) { | 413 void DragDownload(const DownloadItem* download, SkBitmap* icon) { |
414 DCHECK(download); | 414 DCHECK(download); |
415 | 415 |
416 // Set up our OLE machinery | 416 // Set up our OLE machinery |
417 scoped_refptr<OSExchangeData> data(new OSExchangeData); | 417 scoped_refptr<OSExchangeData> data(new OSExchangeData); |
418 if (icon) | 418 if (icon) |
419 drag_utils::CreateDragImageForFile(download->file_name(), icon, data); | 419 drag_utils::CreateDragImageForFile(download->file_name().ToWStringHack(), |
420 data->SetFilename(download->full_path()); | 420 icon, data); |
| 421 data->SetFilename(download->full_path().ToWStringHack()); |
421 scoped_refptr<BaseDragSource> drag_source(new BaseDragSource); | 422 scoped_refptr<BaseDragSource> drag_source(new BaseDragSource); |
422 | 423 |
423 // Run the drag and drop loop | 424 // Run the drag and drop loop |
424 DWORD effects; | 425 DWORD effects; |
425 DoDragDrop(data.get(), drag_source.get(), DROPEFFECT_COPY | DROPEFFECT_LINK, | 426 DoDragDrop(data.get(), drag_source.get(), DROPEFFECT_COPY | DROPEFFECT_LINK, |
426 &effects); | 427 &effects); |
427 } | 428 } |
428 | 429 |
429 | |
430 } // namespace download_util | 430 } // namespace download_util |
431 | |
OLD | NEW |