Index: chrome/browser/download/download_util.cc |
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc |
index 5747e510b2f107efe855a35d604efb795f05e4b1..cd64bf5bd3a2fe18cc10e07a4a7c8db9f27e8b98 100644 |
--- a/chrome/browser/download/download_util.cc |
+++ b/chrome/browser/download/download_util.cc |
@@ -13,6 +13,7 @@ |
#include "app/l10n_util.h" |
#include "app/resource_bundle.h" |
+#include "base/file_path.h" |
#include "base/file_util.h" |
#include "base/i18n/rtl.h" |
#include "base/i18n/time_formatting.h" |
@@ -30,6 +31,7 @@ |
#include "chrome/browser/download/download_item.h" |
#include "chrome/browser/download/download_item_model.h" |
#include "chrome/browser/download/download_manager.h" |
+#include "chrome/browser/download/download_types.h" |
#include "chrome/browser/extensions/crx_installer.h" |
#include "chrome/browser/extensions/extension_install_ui.h" |
#include "chrome/browser/extensions/extensions_service.h" |
@@ -78,6 +80,8 @@ |
#include "chrome/browser/views/frame/browser_view.h" |
#endif |
+static const double PI = 3.141592653589793; |
+ |
namespace download_util { |
// How many times to cycle the complete animation. This should be an odd number |
@@ -452,7 +456,6 @@ void PaintDownloadComplete(gfx::Canvas* canvas, |
// Start at full opacity, then loop back and forth five times before ending |
// at zero opacity. |
- static const double PI = 3.141592653589793; |
double opacity = sin(animation_progress * PI * kCompleteAnimationCycles + |
PI/2) / 2 + 0.5; |
@@ -462,6 +465,43 @@ void PaintDownloadComplete(gfx::Canvas* canvas, |
canvas->Restore(); |
} |
+void PaintDownloadInterrupted(gfx::Canvas* canvas, |
+#if defined(TOOLKIT_VIEWS) |
+ views::View* containing_view, |
+#endif |
+ int origin_x, |
+ int origin_y, |
+ double animation_progress, |
+ PaintDownloadProgressSize size) { |
+ // Load up our common bitmaps. |
+ if (!g_foreground_16) { |
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
+ g_foreground_16 = rb.GetBitmapNamed(IDR_DOWNLOAD_PROGRESS_FOREGROUND_16); |
+ g_foreground_32 = rb.GetBitmapNamed(IDR_DOWNLOAD_PROGRESS_FOREGROUND_32); |
+ } |
+ |
+ SkBitmap* complete = (size == BIG) ? g_foreground_32 : g_foreground_16; |
+ |
+ gfx::Rect complete_bounds(origin_x, origin_y, |
+ complete->width(), complete->height()); |
+#if defined(TOOLKIT_VIEWS) |
+ // Mirror the positions if necessary. |
+ complete_bounds.set_x( |
+ containing_view->MirroredLeftPointForRect(complete_bounds)); |
+#endif |
+ |
+ // Start at zero opacity, then loop back and forth five times before ending |
+ // at full opacity. |
+ double opacity = |
+ sin((1.0 - animation_progress) * PI * kCompleteAnimationCycles + |
+ PI/2) / 2 + 0.5; |
+ |
+ canvas->SaveLayerAlpha(static_cast<int>(255.0 * opacity), complete_bounds); |
+ canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode); |
+ canvas->DrawBitmapInt(*complete, complete_bounds.x(), complete_bounds.y()); |
+ canvas->Restore(); |
+} |
+ |
// Load a language dependent height so that the dangerous download confirmation |
// message doesn't overlap with the download link label. |
int GetBigProgressIconSize() { |
@@ -573,6 +613,20 @@ DictionaryValue* CreateDownloadItemValue(DownloadItem* download, int id) { |
static_cast<int>(download->PercentComplete())); |
file_value->SetInteger("received", |
static_cast<int>(download->received_bytes())); |
+ } else if (download->state() == DownloadItem::INTERRUPTED) { |
+ if (download->safety_state() == DownloadItem::DANGEROUS) { |
+ file_value->SetString("state", "DANGEROUS"); |
+ } else { |
+ file_value->SetString("state", "INTERRUPTED"); |
+ } |
+ |
+ file_value->SetString("progress_status_text", |
+ WideToUTF16Hack(GetProgressStatusText(download))); |
+ |
+ file_value->SetInteger("percent", |
+ static_cast<int>(download->PercentComplete())); |
+ file_value->SetInteger("received", |
+ static_cast<int>(download->received_bytes())); |
} else if (download->state() == DownloadItem::CANCELLED) { |
file_value->SetString("state", "CANCELLED"); |
} else if (download->state() == DownloadItem::COMPLETE) { |
@@ -729,7 +783,72 @@ void DownloadUrl( |
true, // Show "Save as" UI. |
render_process_host_id, |
render_view_id, |
- context); |
+ context, |
+ 0); |
+} |
+ |
+static void PostBeginDownload(ResourceDispatcherHost* rdh, |
+ const GURL& url, |
+ const GURL& referrer, |
+ const DownloadSaveInfo& save_info, |
+ int render_process_host_id, |
+ int render_view_id, |
+ uint64 start_offset) { |
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
+ URLRequestContextGetter* context_getter = Profile::GetDefaultRequestContext(); |
+ if (context_getter) { |
+ URLRequestContext* context = context_getter->GetURLRequestContext(); |
+ // |referrer_charset| is used to construct suggested filename, but we are |
+ // using an existing file so we don't need to set it. |
+ |
+ rdh->BeginDownload(url, |
+ referrer, |
+ save_info, |
+ false, // Don't show "Save as" UI. |
+ render_process_host_id, |
+ render_view_id, |
+ context, |
+ start_offset); |
+ } |
+} |
+ |
+void RestartDownloadUrl( |
+ ResourceDispatcherHost* rdh, |
+ const GURL& url, |
+ const GURL& referrer, |
+ const FilePath& path, |
+ int64 start_offset, |
+ int render_process_host_id, |
+ int render_view_id) { |
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
+ |
+ // Get the temporary file and rename it to the original value. |
+ FilePath crpath = download_util::GetCrDownloadPath(path); |
+ |
+ // Validate the start offset. |
+ int64 end = 0; |
+ if (file_util::GetFileSize(crpath, &end)) { |
+ if (end != start_offset) { |
+ LOG(WARNING) << " File size (" << end |
+ << ") is different from the expected size (" << start_offset |
+ << ") for \"" << path.value() << "\""; |
+ } |
+ } |
+ |
+ DownloadSaveInfo save_info; |
+ save_info.file_path = path; |
+ |
+ ChromeThread::PostTask( |
+ ChromeThread::IO, |
+ FROM_HERE, |
+ NewRunnableFunction(&PostBeginDownload, |
+ rdh, |
+ url, |
+ referrer, |
+ save_info, |
+ render_process_host_id, |
+ render_view_id, |
+ end)); |
} |
void CancelDownloadRequest(ResourceDispatcherHost* rdh, |
@@ -766,4 +885,23 @@ FilePath GetCrDownloadPath(const FilePath& suggested_path) { |
return FilePath(file_name); |
} |
+FilePath RemoveCrDownloadPath(const FilePath& cr_path) { |
+ FilePath::StringType file_name = cr_path.value(); |
+ size_t pos = file_name.find(FILE_PATH_LITERAL(".crdownload")); |
+ if (pos != std::string::npos) |
+ file_name = file_name.substr(0, pos); |
+ return FilePath(file_name); |
+} |
+ |
+bool IsCrDownloadPath(const FilePath& path) { |
+ FilePath::StringType file_name = path.value(); |
+ FilePath::StringType extension = FILE_PATH_LITERAL(".crdownload"); |
+ FilePath::StringType::size_type name_len = file_name.length(); |
+ FilePath::StringType::size_type ext_len = extension.length(); |
+ if (ext_len > name_len) |
+ return false; |
+ |
+ return file_name.substr(name_len - ext_len, ext_len) == extension; |
+} |
+ |
} // namespace download_util |