| Index: chrome/browser/download/download_util.cc
|
| ===================================================================
|
| --- chrome/browser/download/download_util.cc (revision 134373)
|
| +++ chrome/browser/download/download_util.cc (working copy)
|
| @@ -4,11 +4,11 @@
|
| //
|
| // Download utility implementation
|
|
|
| +#define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first.
|
| +
|
| #include "chrome/browser/download/download_util.h"
|
|
|
| -#if defined(OS_WIN)
|
| -#include <shobjidl.h>
|
| -#endif
|
| +#include <cmath>
|
| #include <string>
|
|
|
| #include "base/file_util.h"
|
| @@ -24,7 +24,6 @@
|
| #include "base/utf_string_conversions.h"
|
| #include "base/value_conversions.h"
|
| #include "base/values.h"
|
| -#include "base/win/windows_version.h"
|
| #include "chrome/browser/download/download_extensions.h"
|
| #include "chrome/browser/download/download_item_model.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| @@ -52,6 +51,12 @@
|
| #include "ui/gfx/image/image.h"
|
| #include "ui/gfx/rect.h"
|
|
|
| +#if defined(OS_WIN)
|
| +#include <shobjidl.h>
|
| +
|
| +#include "base/win/windows_version.h"
|
| +#endif
|
| +
|
| #if defined(TOOLKIT_VIEWS)
|
| #include "ui/base/dragdrop/drag_utils.h"
|
| #include "ui/base/dragdrop/os_exchange_data.h"
|
| @@ -73,12 +78,6 @@
|
| #include "ui/base/dragdrop/os_exchange_data_provider_win.h"
|
| #endif
|
|
|
| -// TODO(phajdan.jr): Find some standard location for this, maintaining
|
| -// the same value on all platforms.
|
| -static const double PI = 3.141592653589793;
|
| -
|
| -using content::DownloadItem;
|
| -
|
| namespace {
|
|
|
| // Returns a string constant to be used as the |danger_type| value in
|
| @@ -103,13 +102,24 @@
|
| }
|
| }
|
|
|
| +// Get the opacity based on |animation_progress|, with values in [0.0, 1.0].
|
| +// Range of return value is [0, 255].
|
| +int GetOpacity(double animation_progress) {
|
| + DCHECK(animation_progress >= 0 && animation_progress <= 1);
|
| +
|
| + // How many times to cycle the complete animation. This should be an odd
|
| + // number so that the animation ends faded out.
|
| + static const int kCompleteAnimationCycles = 5;
|
| + double temp = animation_progress * kCompleteAnimationCycles * M_PI + M_PI_2;
|
| + temp = sin(temp) / 2 + 0.5;
|
| + return static_cast<int>(255.0 * temp);
|
| +}
|
| +
|
| } // namespace
|
|
|
| namespace download_util {
|
|
|
| -// How many times to cycle the complete animation. This should be an odd number
|
| -// so that the animation ends faded out.
|
| -static const int kCompleteAnimationCycles = 5;
|
| +using content::DownloadItem;
|
|
|
| // Download temporary file creation --------------------------------------------
|
|
|
| @@ -122,6 +132,8 @@
|
| NOTREACHED();
|
| }
|
| if (DownloadPathIsDangerous(path_)) {
|
| + // This is only useful on platforms that support
|
| + // DIR_DEFAULT_DOWNLOADS_SAFE.
|
| if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS_SAFE, &path_)) {
|
| NOTREACHED();
|
| }
|
| @@ -138,7 +150,16 @@
|
| return g_default_download_directory.Get().path();
|
| }
|
|
|
| +// Consider downloads 'dangerous' if they go to the home directory on Linux and
|
| +// to the desktop on any platform.
|
| bool DownloadPathIsDangerous(const FilePath& download_path) {
|
| +#if defined(OS_LINUX)
|
| + FilePath home_dir = file_util::GetHomeDir();
|
| + if (download_path == home_dir) {
|
| + return true;
|
| + }
|
| +#endif
|
| +
|
| FilePath desktop_dir;
|
| if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_dir)) {
|
| NOTREACHED();
|
| @@ -295,10 +316,7 @@
|
|
|
| // Start at full opacity, then loop back and forth five times before ending
|
| // at zero opacity.
|
| - double opacity = sin(animation_progress * PI * kCompleteAnimationCycles +
|
| - PI/2) / 2 + 0.5;
|
| -
|
| - canvas->SaveLayerAlpha(static_cast<int>(255.0 * opacity), complete_bounds);
|
| + canvas->SaveLayerAlpha(GetOpacity(animation_progress), complete_bounds);
|
| canvas->sk_canvas()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode);
|
| canvas->DrawBitmapInt(*complete, complete_bounds.x(), complete_bounds.y());
|
| canvas->Restore();
|
| @@ -330,11 +348,7 @@
|
|
|
| // 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->SaveLayerAlpha(GetOpacity(1.0 - animation_progress), complete_bounds);
|
| canvas->sk_canvas()->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode);
|
| canvas->DrawBitmapInt(*complete, complete_bounds.x(), complete_bounds.y());
|
| canvas->Restore();
|
| @@ -397,7 +411,7 @@
|
| // we pass NULL to RunShellDrag for the source view.
|
| widget->RunShellDrag(NULL, data, location,
|
| ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK);
|
| -#else // We are on WIN without AURA
|
| +#else // We are on WIN without AURA
|
| // We cannot use Widget::RunShellDrag on WIN since the |view| is backed by a
|
| // TabContentsViewWin, not a NativeWidgetWin.
|
| scoped_refptr<ui::DragSource> drag_source(new ui::DragSource);
|
|
|