summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/download/download_util.cc60
-rw-r--r--chrome/common/chrome_paths.cc2
-rw-r--r--chrome/common/chrome_paths.h3
-rw-r--r--chrome/common/chrome_paths_internal.h4
-rw-r--r--chrome/common/chrome_paths_linux.cc23
5 files changed, 49 insertions, 43 deletions
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc
index d6f2a79..1cd21a4 100644
--- a/chrome/browser/download/download_util.cc
+++ b/chrome/browser/download/download_util.cc
@@ -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 @@ const char* GetDangerTypeString(content::DownloadDangerType danger_type) {
}
}
+// 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 @@ class DefaultDownloadDirectory {
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 @@ const FilePath& GetDefaultDownloadDirectory() {
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 @@ void PaintDownloadComplete(gfx::Canvas* canvas,
// 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 @@ void PaintDownloadInterrupted(gfx::Canvas* canvas,
// 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 @@ void DragDownload(const DownloadItem* download,
// 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);
diff --git a/chrome/common/chrome_paths.cc b/chrome/common/chrome_paths.cc
index 6d4849e..3cacef7 100644
--- a/chrome/common/chrome_paths.cc
+++ b/chrome/common/chrome_paths.cc
@@ -144,7 +144,7 @@ bool PathProvider(int key, FilePath* result) {
create_dir = true;
break;
case chrome::DIR_DEFAULT_DOWNLOADS_SAFE:
-#if defined(OS_WIN)
+#if defined(OS_WIN) || defined(OS_LINUX)
if (!GetUserDownloadsDirectorySafe(&cur))
return false;
break;
diff --git a/chrome/common/chrome_paths.h b/chrome/common/chrome_paths.h
index 09988fc..9d6af14 100644
--- a/chrome/common/chrome_paths.h
+++ b/chrome/common/chrome_paths.h
@@ -27,7 +27,8 @@ enum {
DIR_APP_DICTIONARIES, // Directory where the global dictionaries are.
DIR_USER_DOCUMENTS, // Directory for a user's "My Documents".
DIR_DEFAULT_DOWNLOADS_SAFE, // Directory for a user's
- // "My Documents/Downloads".
+ // "My Documents/Downloads", (Windows) or
+ // "Downloads". (Linux)
DIR_DEFAULT_DOWNLOADS, // Directory for a user's downloads.
DIR_USER_DATA_TEMP, // A temp directory within DIR_USER_DATA. Use
// this when a temporary file or directory will
diff --git a/chrome/common/chrome_paths_internal.h b/chrome/common/chrome_paths_internal.h
index 23c3ec4..d4a1151 100644
--- a/chrome/common/chrome_paths_internal.h
+++ b/chrome/common/chrome_paths_internal.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -41,7 +41,7 @@ void GetUserCacheDirectory(const FilePath& profile_dir, FilePath* result);
// Get the path to the user's documents directory.
bool GetUserDocumentsDirectory(FilePath* result);
-#if defined (OS_WIN)
+#if defined(OS_WIN) || defined(OS_LINUX)
// Gets the path to a safe default download directory for a user.
bool GetUserDownloadsDirectorySafe(FilePath* result);
#endif
diff --git a/chrome/common/chrome_paths_linux.cc b/chrome/common/chrome_paths_linux.cc
index f5d4549..acfebc1 100644
--- a/chrome/common/chrome_paths_linux.cc
+++ b/chrome/common/chrome_paths_linux.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -84,25 +84,16 @@ bool GetUserDocumentsDirectory(FilePath* result) {
return true;
}
-// We respect the user's preferred download location, unless it is
-// ~ or their desktop directory, in which case we default to ~/Downloads.
+bool GetUserDownloadsDirectorySafe(FilePath* result) {
+ FilePath home = file_util::GetHomeDir();
+ *result = home.Append(kDownloadsDir);
+ return true;
+}
+
bool GetUserDownloadsDirectory(FilePath* result) {
scoped_ptr<base::Environment> env(base::Environment::Create());
*result = base::nix::GetXDGUserDirectory(env.get(), "DOWNLOAD",
kDownloadsDir);
-
- FilePath home = file_util::GetHomeDir();
- if (*result == home) {
- *result = home.Append(kDownloadsDir);
- return true;
- }
-
- FilePath desktop;
- GetUserDesktop(&desktop);
- if (*result == desktop) {
- *result = home.Append(kDownloadsDir);
- }
-
return true;
}