summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history
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 /chrome/browser/history
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 'chrome/browser/history')
-rw-r--r--chrome/browser/history/download_database.cc14
-rw-r--r--chrome/browser/history/download_database.h3
-rw-r--r--chrome/browser/history/download_types.h7
-rw-r--r--chrome/browser/history/history.cc6
-rw-r--r--chrome/browser/history/history.h4
-rw-r--r--chrome/browser/history/history_backend.cc7
-rw-r--r--chrome/browser/history/history_backend.h1
7 files changed, 41 insertions, 1 deletions
diff --git a/chrome/browser/history/download_database.cc b/chrome/browser/history/download_database.cc
index 1baf976..e604e5d 100644
--- a/chrome/browser/history/download_database.cc
+++ b/chrome/browser/history/download_database.cc
@@ -93,6 +93,20 @@ bool DownloadDatabase::UpdateDownload(int64 received_bytes,
return statement->step() == SQLITE_DONE;
}
+bool DownloadDatabase::UpdateDownloadPath(const std::wstring& path,
+ DownloadID db_handle) {
+ DCHECK(db_handle > 0);
+ SQLITE_UNIQUE_STATEMENT(statement, GetStatementCache(),
+ "UPDATE downloads "
+ "SET full_path=? WHERE id=?");
+ if (!statement.is_valid())
+ return false;
+
+ statement->bind_wstring(0, path);
+ statement->bind_int64(1, db_handle);
+ return statement->step() == SQLITE_DONE;
+}
+
int64 DownloadDatabase::CreateDownload(const DownloadCreateInfo& info) {
SQLITE_UNIQUE_STATEMENT(statement, GetStatementCache(),
"INSERT INTO downloads "
diff --git a/chrome/browser/history/download_database.h b/chrome/browser/history/download_database.h
index 1fc9812..d733546 100644
--- a/chrome/browser/history/download_database.h
+++ b/chrome/browser/history/download_database.h
@@ -27,6 +27,9 @@ class DownloadDatabase {
// Update the state of one download. Returns true if successful.
bool UpdateDownload(int64 received_bytes, int32 state, DownloadID db_handle);
+ // Update the path of one download. Returns true if successful.
+ bool UpdateDownloadPath(const std::wstring& path, DownloadID db_handle);
+
// Create a new database entry for one download and return its primary db id.
int64 CreateDownload(const DownloadCreateInfo& info);
diff --git a/chrome/browser/history/download_types.h b/chrome/browser/history/download_types.h
index 16f3ad7..5b6e5b4 100644
--- a/chrome/browser/history/download_types.h
+++ b/chrome/browser/history/download_types.h
@@ -37,7 +37,8 @@ struct DownloadCreateInfo {
render_view_id(-1),
request_id(-1),
db_handle(0),
- save_as(false) {
+ save_as(false),
+ is_dangerous(false) {
}
DownloadCreateInfo() : download_id(-1) {}
@@ -59,6 +60,10 @@ struct DownloadCreateInfo {
std::string content_disposition;
std::string mime_type;
bool save_as;
+ // Whether this download is potentially dangerous (ex: exe, dll, ...).
+ bool is_dangerous;
+ // The original name for a dangerous download.
+ std::wstring original_name;
};
#endif // CHROME_BROWSER_DOWNLOAD_TYPES_H__
diff --git a/chrome/browser/history/history.cc b/chrome/browser/history/history.cc
index db04446..92bea22 100644
--- a/chrome/browser/history/history.cc
+++ b/chrome/browser/history/history.cc
@@ -469,6 +469,12 @@ void HistoryService::UpdateDownload(int64 received_bytes,
received_bytes, state, db_handle);
}
+void HistoryService::UpdateDownloadPath(const std::wstring& path,
+ int64 db_handle) {
+ ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::UpdateDownloadPath,
+ path, db_handle);
+}
+
void HistoryService::RemoveDownload(int64 db_handle) {
ScheduleAndForget(PRIORITY_NORMAL,
&HistoryBackend::RemoveDownload, db_handle);
diff --git a/chrome/browser/history/history.h b/chrome/browser/history/history.h
index 74ef67b..2aee029 100644
--- a/chrome/browser/history/history.h
+++ b/chrome/browser/history/history.h
@@ -421,6 +421,10 @@ class HistoryService : public CancelableRequestProvider,
// the database with no need for a callback.
void UpdateDownload(int64 received_bytes, int32 state, int64 db_handle);
+ // Called to update the history service about the path of a download.
+ // This is a 'fire and forget' query.
+ void UpdateDownloadPath(const std::wstring& path, int64 db_handle);
+
// Permanently remove a download from the history system. This is a 'fire and
// forget' operation.
void RemoveDownload(int64 db_handle);
diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc
index 21f77fb..f8e6449 100644
--- a/chrome/browser/history/history_backend.cc
+++ b/chrome/browser/history/history_backend.cc
@@ -934,6 +934,13 @@ void HistoryBackend::UpdateDownload(int64 received_bytes,
db_->UpdateDownload(received_bytes, state, db_handle);
}
+// Update the path of a particular download entry.
+void HistoryBackend::UpdateDownloadPath(const std::wstring& path,
+ int64 db_handle) {
+ if (db_.get())
+ db_->UpdateDownloadPath(path, db_handle);
+}
+
// Create a new download entry and pass back the db_handle to it.
void HistoryBackend::CreateDownload(
scoped_refptr<DownloadCreateRequest> request,
diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h
index dd37c3e..e646570 100644
--- a/chrome/browser/history/history_backend.h
+++ b/chrome/browser/history/history_backend.h
@@ -193,6 +193,7 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
void QueryDownloads(scoped_refptr<DownloadQueryRequest> request);
void UpdateDownload(int64 received_bytes, int32 state, int64 db_handle);
+ void UpdateDownloadPath(const std::wstring& path, int64 db_handle);
void CreateDownload(scoped_refptr<DownloadCreateRequest> request,
const DownloadCreateInfo& info);
void RemoveDownload(int64 db_handle);