summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download/download_item.cc
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-16 23:39:42 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-16 23:39:42 +0000
commitd3b129003402bb0f37d0f22803efa1960bee90a3 (patch)
tree3f6d62d040162549f699df4f67ac6368b4f6edf4 /chrome/browser/download/download_item.cc
parenteb997422bde4133da7db0e1e3ff82d18890de218 (diff)
downloadchromium_src-d3b129003402bb0f37d0f22803efa1960bee90a3.zip
chromium_src-d3b129003402bb0f37d0f22803efa1960bee90a3.tar.gz
chromium_src-d3b129003402bb0f37d0f22803efa1960bee90a3.tar.bz2
Regression fix: Downloads page in Incognito mode works fine now.
Additionally, it fixes another ancient bug that prevented downloads search from working in Incognito mode. The design of DownloadHistory is also nicer now, with no dependencies on DownloadManager. TEST=see bug BUG=51955 Review URL: http://codereview.chromium.org/3112011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56266 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download/download_item.cc')
-rw-r--r--chrome/browser/download/download_item.cc35
1 files changed, 35 insertions, 0 deletions
diff --git a/chrome/browser/download/download_item.cc b/chrome/browser/download/download_item.cc
index 269f0cb..c05823a 100644
--- a/chrome/browser/download/download_item.cc
+++ b/chrome/browser/download/download_item.cc
@@ -4,15 +4,21 @@
#include "chrome/browser/download/download_item.h"
+#include "app/l10n_util.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/timer.h"
+#include "base/utf_string_conversions.h"
+#include "net/base/net_util.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/download/download_history.h"
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/download/download_util.h"
#include "chrome/browser/history/download_types.h"
+#include "chrome/browser/pref_service.h"
+#include "chrome/browser/profile.h"
#include "chrome/common/extensions/extension.h"
+#include "chrome/common/pref_names.h"
namespace {
@@ -298,6 +304,35 @@ void DownloadItem::OnNameFinalized() {
NotifyObserversDownloadFileCompleted();
}
+bool DownloadItem::MatchesQuery(const string16& query) const {
+ if (query.empty())
+ return true;
+
+ DCHECK_EQ(query, l10n_util::ToLower(query));
+
+ string16 url_raw(l10n_util::ToLower(UTF8ToUTF16(url_.spec())));
+ if (url_raw.find(query) != string16::npos)
+ return true;
+
+ // TODO(phajdan.jr): write a test case for the following code.
+ // A good test case would be:
+ // "/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd",
+ // L"/\x4f60\x597d\x4f60\x597d",
+ // "/%E4%BD%A0%E5%A5%BD%E4%BD%A0%E5%A5%BD"
+ PrefService* prefs = download_manager_->profile()->GetPrefs();
+ std::wstring languages(UTF8ToWide(prefs->GetString(prefs::kAcceptLanguages)));
+ string16 url_formatted(
+ l10n_util::ToLower(WideToUTF16(net::FormatUrl(url_, languages))));
+ if (url_formatted.find(query) != string16::npos)
+ return true;
+
+ string16 path(l10n_util::ToLower(WideToUTF16(full_path_.ToWStringHack())));
+ if (path.find(query) != std::wstring::npos)
+ return true;
+
+ return false;
+}
+
FilePath DownloadItem::GetFileName() const {
if (safety_state_ == DownloadItem::SAFE)
return file_name_;