summaryrefslogtreecommitdiffstats
path: root/base/string_util.cc
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-10 18:50:32 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-10 18:50:32 +0000
commit9ccbb370aa45f477941e0599d4ce7c89fac64101 (patch)
tree8b21818fa95d05ff00dfe5b9986d1d39eb4be722 /base/string_util.cc
parenta9acde54584ff37bcc5fad73cf25dce5d85348bc (diff)
downloadchromium_src-9ccbb370aa45f477941e0599d4ce7c89fac64101.zip
chromium_src-9ccbb370aa45f477941e0599d4ce7c89fac64101.tar.gz
chromium_src-9ccbb370aa45f477941e0599d4ce7c89fac64101.tar.bz2
This CL adds prompting for dangerous types of files (executable) when they are automatically downloaded.
The file is saved with a temporary name (dangerous_download_xxxx.download) in the download directory and the user is presented (in the download shelf and the download tab if opened) with a warning message and buttons to save/discard the download. If discarded the download is removed (and its file deleted). If saved, download goes as usual. Dangerous downloads not confirmed by the user are deleted on shutdown. TEST=Download a small exe file, try using the save/discard button from the download shelf and from the download tab (the intent is that the file has been entirely downloaded by the time you take action). Try again with a slow/big download (that time the download is expected not to be finished when approved/discarded). Review URL: http://codereview.chromium.org/6043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3228 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/string_util.cc')
-rw-r--r--base/string_util.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/base/string_util.cc b/base/string_util.cc
index 223c485..5fa2f75 100644
--- a/base/string_util.cc
+++ b/base/string_util.cc
@@ -1434,3 +1434,39 @@ size_t base::wcslcpy(wchar_t* dst, const wchar_t* src, size_t dst_size) {
return lcpyT<wchar_t>(dst, src, dst_size);
}
+bool ElideString(const std::wstring& input, int max_len, std::wstring* output) {
+ DCHECK(max_len >= 0);
+ if (static_cast<int>(input.length()) <= max_len) {
+ output->assign(input);
+ return false;
+ }
+
+ switch (max_len) {
+ case 0:
+ output->clear();
+ break;
+ case 1:
+ output->assign(input.substr(0, 1));
+ break;
+ case 2:
+ output->assign(input.substr(0, 2));
+ break;
+ case 3:
+ output->assign(input.substr(0, 1) + L"." +
+ input.substr(input.length() - 1));
+ break;
+ case 4:
+ output->assign(input.substr(0, 1) + L".." +
+ input.substr(input.length() - 1));
+ break;
+ default: {
+ int rstr_len = (max_len - 3) / 2;
+ int lstr_len = rstr_len + ((max_len - 3) % 2);
+ output->assign(input.substr(0, lstr_len) + L"..." +
+ input.substr(input.length() - rstr_len));
+ break;
+ }
+ }
+
+ return true;
+}