summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download
diff options
context:
space:
mode:
authorxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-29 22:03:57 +0000
committerxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-29 22:03:57 +0000
commit274e42bf367cc47931bdac85837cfc2c8259f8a1 (patch)
tree75dc09021e2b1e85d416928773b351de33b7fae3 /chrome/browser/download
parenta9aca52ac15959a2c71a4ee22539a2392d3ee06b (diff)
downloadchromium_src-274e42bf367cc47931bdac85837cfc2c8259f8a1.zip
chromium_src-274e42bf367cc47931bdac85837cfc2c8259f8a1.tar.gz
chromium_src-274e42bf367cc47931bdac85837cfc2c8259f8a1.tar.bz2
Replace GtkFileChooser with file browser for ChromeOS
- Remove dialogs_gtk.cc and add select_file_dialog.cc for chrome os build; - select_file_dialog.cc provides a SelectFileDialogImpl that serves file browse html via HTMLDialogUI; BUG=none TEST=none Review URL: http://codereview.chromium.org/543137 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37547 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
-rw-r--r--chrome/browser/download/download_util.cc105
-rw-r--r--chrome/browser/download/download_util.h10
2 files changed, 115 insertions, 0 deletions
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc
index 7662bc7..711c24c 100644
--- a/chrome/browser/download/download_util.cc
+++ b/chrome/browser/download/download_util.cc
@@ -13,11 +13,14 @@
#include "app/resource_bundle.h"
#include "base/file_util.h"
#include "base/gfx/rect.h"
+#include "base/i18n/time_formatting.h"
#include "base/string_util.h"
+#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/download_item_model.h"
#include "chrome/browser/download/download_manager.h"
#include "chrome/common/extensions/extension.h"
+#include "chrome/common/time_format.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
#include "grit/theme_resources.h"
@@ -295,4 +298,106 @@ void DragDownload(const DownloadItem* download,
}
#endif // OS_LINUX
+DictionaryValue* CreateDownloadItemValue(DownloadItem* download, int id) {
+ DictionaryValue* file_value = new DictionaryValue();
+
+ file_value->SetInteger(L"started",
+ static_cast<int>(download->start_time().ToTimeT()));
+ file_value->SetString(L"since_string",
+ TimeFormat::RelativeDate(download->start_time(), NULL));
+ file_value->SetString(L"date_string",
+ base::TimeFormatShortDate(download->start_time()));
+ file_value->SetInteger(L"id", id);
+ file_value->SetString(L"file_path", download->full_path().ToWStringHack());
+ // Keep file names as LTR.
+ std::wstring file_name = download->GetFileName().ToWStringHack();
+ if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT)
+ l10n_util::WrapStringWithLTRFormatting(&file_name);
+ file_value->SetString(L"file_name", file_name);
+ file_value->SetString(L"url", download->url().spec());
+
+ if (download->state() == DownloadItem::IN_PROGRESS) {
+ if (download->safety_state() == DownloadItem::DANGEROUS) {
+ file_value->SetString(L"state", L"DANGEROUS");
+ } else if (download->is_paused()) {
+ file_value->SetString(L"state", L"PAUSED");
+ } else {
+ file_value->SetString(L"state", L"IN_PROGRESS");
+ }
+
+ file_value->SetString(L"progress_status_text",
+ GetProgressStatusText(download));
+
+ file_value->SetInteger(L"percent",
+ static_cast<int>(download->PercentComplete()));
+ file_value->SetInteger(L"received",
+ static_cast<int>(download->received_bytes()));
+ } else if (download->state() == DownloadItem::CANCELLED) {
+ file_value->SetString(L"state", L"CANCELLED");
+ } else if (download->state() == DownloadItem::COMPLETE) {
+ if (download->safety_state() == DownloadItem::DANGEROUS) {
+ file_value->SetString(L"state", L"DANGEROUS");
+ } else {
+ file_value->SetString(L"state", L"COMPLETE");
+ }
+ }
+
+ file_value->SetInteger(L"total",
+ static_cast<int>(download->total_bytes()));
+
+ return file_value;
+}
+
+std::wstring GetProgressStatusText(DownloadItem* download) {
+ int64 total = download->total_bytes();
+ int64 size = download->received_bytes();
+ DataUnits amount_units = GetByteDisplayUnits(size);
+ std::wstring received_size = FormatBytes(size, amount_units, true);
+ std::wstring amount = received_size;
+
+ // Adjust both strings for the locale direction since we don't yet know which
+ // string we'll end up using for constructing the final progress string.
+ std::wstring amount_localized;
+ if (l10n_util::AdjustStringForLocaleDirection(amount, &amount_localized)) {
+ amount.assign(amount_localized);
+ received_size.assign(amount_localized);
+ }
+
+ if (total) {
+ amount_units = GetByteDisplayUnits(total);
+ std::wstring total_text = FormatBytes(total, amount_units, true);
+ std::wstring total_text_localized;
+ if (l10n_util::AdjustStringForLocaleDirection(total_text,
+ &total_text_localized))
+ total_text.assign(total_text_localized);
+
+ amount = l10n_util::GetStringF(IDS_DOWNLOAD_TAB_PROGRESS_SIZE,
+ received_size,
+ total_text);
+ } else {
+ amount.assign(received_size);
+ }
+ amount_units = GetByteDisplayUnits(download->CurrentSpeed());
+ std::wstring speed_text = FormatSpeed(download->CurrentSpeed(),
+ amount_units, true);
+ std::wstring speed_text_localized;
+ if (l10n_util::AdjustStringForLocaleDirection(speed_text,
+ &speed_text_localized))
+ speed_text.assign(speed_text_localized);
+
+ base::TimeDelta remaining;
+ std::wstring time_remaining;
+ if (download->is_paused())
+ time_remaining = l10n_util::GetString(IDS_DOWNLOAD_PROGRESS_PAUSED);
+ else if (download->TimeRemaining(&remaining))
+ time_remaining = TimeFormat::TimeRemaining(remaining);
+
+ if (time_remaining.empty()) {
+ return l10n_util::GetStringF(IDS_DOWNLOAD_TAB_PROGRESS_STATUS_TIME_UNKNOWN,
+ speed_text, amount);
+ }
+ return l10n_util::GetStringF(IDS_DOWNLOAD_TAB_PROGRESS_STATUS, speed_text,
+ amount, time_remaining);
+}
+
} // namespace download_util
diff --git a/chrome/browser/download/download_util.h b/chrome/browser/download/download_util.h
index 7636b55..93114fe 100644
--- a/chrome/browser/download/download_util.h
+++ b/chrome/browser/download/download_util.h
@@ -23,6 +23,7 @@ class Canvas;
}
class BaseDownloadItemModel;
+class DictionaryValue;
class DownloadItem;
class SkBitmap;
@@ -134,6 +135,15 @@ void DragDownload(const DownloadItem* download,
// Determine if the specified extension is an executable extension.
bool IsExecutableExtension(const std::string& extension);
+// Helpers ---------------------------------------------------------------------
+
+// Creates a representation of a download in a format that the downloads
+// HTML page can understand.
+DictionaryValue* CreateDownloadItemValue(DownloadItem* download, int id);
+
+// Get the localized status text for an in-progress download.
+std::wstring GetProgressStatusText(DownloadItem* download);
+
} // namespace download_util
#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_