diff options
author | dhg@chromium.org <dhg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-08 17:33:03 +0000 |
---|---|---|
committer | dhg@chromium.org <dhg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-08 17:33:03 +0000 |
commit | c4a530bfedbe1c0c873c62bcf5c54536d319eae3 (patch) | |
tree | a3bafc1dca6fcb9d1ef3af884562a12b3e35078e /chrome/browser | |
parent | 0aae8d4fd17eae16206f8db810accf85481d42a2 (diff) | |
download | chromium_src-c4a530bfedbe1c0c873c62bcf5c54536d319eae3.zip chromium_src-c4a530bfedbe1c0c873c62bcf5c54536d319eae3.tar.gz chromium_src-c4a530bfedbe1c0c873c62bcf5c54536d319eae3.tar.bz2 |
Fixing extension install case. Changing the file browser to only get the list of current downloads, not the history.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/669186
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40903 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser_resources.grd | 2 | ||||
-rw-r--r-- | chrome/browser/dom_ui/filebrowse_ui.cc | 88 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.cc | 18 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.h | 4 | ||||
-rw-r--r-- | chrome/browser/resources/filebrowse.html | 59 |
5 files changed, 162 insertions, 9 deletions
diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index fd1886d..2a23433 100644 --- a/chrome/browser/browser_resources.grd +++ b/chrome/browser/browser_resources.grd @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- This comment is only here because changes to resources are not picked up -without changes to the corresponding grd file. aa1 --> +without changes to the corresponding grd file. tat --> <grit latest_public_release="0" current_release="1"> <outputs> <output filename="grit/browser_resources.h" type="rc_header"> diff --git a/chrome/browser/dom_ui/filebrowse_ui.cc b/chrome/browser/dom_ui/filebrowse_ui.cc index 0ad904f..74f23ed 100644 --- a/chrome/browser/dom_ui/filebrowse_ui.cc +++ b/chrome/browser/dom_ui/filebrowse_ui.cc @@ -138,6 +138,8 @@ class FilebrowseHandler : public net::DirectoryLister::DirectoryListerDelegate, // Callback for the "getChildren" message. void HandleGetChildren(const Value* value); + // Callback for the "refreshDirectory" message. + void HandleRefreshDirectory(const Value* value); // Callback for the "getMetadata" message. void HandleGetMetadata(const Value* value); @@ -160,6 +162,9 @@ class FilebrowseHandler : public net::DirectoryLister::DirectoryListerDelegate, void HandlePauseToggleDownload(const Value* value); + void HandleCancelDownload(const Value* value); + void HandleAllowDownload(const Value* value); + void ReadInFile(); void FireUploadComplete(); @@ -326,6 +331,12 @@ void FilebrowseHandler::RegisterMessages() { NewCallback(this, &FilebrowseHandler::HandlePauseToggleDownload)); dom_ui_->RegisterMessageCallback("deleteFile", NewCallback(this, &FilebrowseHandler::HandleDeleteFile)); + dom_ui_->RegisterMessageCallback("cancelDownload", + NewCallback(this, &FilebrowseHandler::HandleCancelDownload)); + dom_ui_->RegisterMessageCallback("allowDownload", + NewCallback(this, &FilebrowseHandler::HandleAllowDownload)); + dom_ui_->RegisterMessageCallback("refreshDirectory", + NewCallback(this, &FilebrowseHandler::HandleRefreshDirectory)); } @@ -456,6 +467,27 @@ void FilebrowseHandler::HandleCreateNewFolder(const Value* value) { #endif } +void FilebrowseHandler::HandleRefreshDirectory(const Value* value) { + if (value && value->GetType() == Value::TYPE_LIST) { + const ListValue* list_value = static_cast<const ListValue*>(value); + std::string path; + + // Get path string. + if (list_value->GetString(0, &path)) { + FilePath currentpath; +#if defined(OS_WIN) + currentpath = FilePath(ASCIIToWide(path)); +#else + currentpath = FilePath(path); +#endif + GetChildrenForPath(currentpath, true); + } else { + LOG(ERROR) << "Unable to get string"; + return; + } + } +} + void FilebrowseHandler::HandlePauseToggleDownload(const Value* value) { #if defined(OS_CHROMEOS) if (value && value->GetType() == Value::TYPE_LIST) { @@ -475,6 +507,48 @@ void FilebrowseHandler::HandlePauseToggleDownload(const Value* value) { #endif } +void FilebrowseHandler::HandleAllowDownload(const Value* value) { +#if defined(OS_CHROMEOS) + if (value && value->GetType() == Value::TYPE_LIST) { + const ListValue* list_value = static_cast<const ListValue*>(value); + int id; + std::string str_id; + + if (list_value->GetString(0, &str_id)) { + id = atoi(str_id.c_str()); + DownloadItem* item = download_items_[id]; + download_manager_->DangerousDownloadValidated(item); + } else { + LOG(ERROR) << "Unable to get id for download to pause"; + return; + } + } +#endif +} + +void FilebrowseHandler::HandleCancelDownload(const Value* value) { +#if defined(OS_CHROMEOS) + if (value && value->GetType() == Value::TYPE_LIST) { + const ListValue* list_value = static_cast<const ListValue*>(value); + int id; + std::string str_id; + + if (list_value->GetString(0, &str_id)) { + id = atoi(str_id.c_str()); + DownloadItem* item = download_items_[id]; + item->Cancel(true); + FilePath path = item->full_path(); + FilePath dir_path = path.DirName(); + item->Remove(true); + GetChildrenForPath(dir_path, true); + } else { + LOG(ERROR) << "Unable to get id for download to pause"; + return; + } + } +#endif +} + void FilebrowseHandler::OpenNewFullWindow(const Value* value) { OpenNewWindow(value, false); } @@ -702,12 +776,11 @@ void FilebrowseHandler::HandleGetDownloads(const Value* value) { void FilebrowseHandler::ModelChanged() { ClearDownloadItems(); - download_manager_->GetDownloads(this, std::wstring()); + download_manager_->GetCurrentDownloads(this, FilePath()); } void FilebrowseHandler::SetDownloads(std::vector<DownloadItem*>& downloads) { ClearDownloadItems(); - // Scan for any in progress downloads and add ourself to them as an observer. for (DownloadList::iterator it = downloads.begin(); it != downloads.end(); ++it) { @@ -744,7 +817,16 @@ void FilebrowseHandler::HandleDeleteFile(const Value* value) { FilePath currentpath; currentpath = FilePath(path); - + for (unsigned int x = 0; x < download_items_.size(); x++) { + FilePath item = download_items_[x]->full_path(); + if (item == currentpath) { + download_items_[x]->Cancel(true); + download_items_[x]->Remove(true); + FilePath dir_path = item.DirName(); + GetChildrenForPath(dir_path, true); + return; + } + } TaskProxy* task = new TaskProxy(AsWeakPtr(), currentpath); task->AddRef(); CurrentTask_ = task; diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc index ab72b11..c89c77b 100644 --- a/chrome/browser/download/download_manager.cc +++ b/chrome/browser/download/download_manager.cc @@ -552,6 +552,24 @@ void DownloadManager::GetTemporaryDownloads(Observer* observer, observer->SetDownloads(download_copy); } +void DownloadManager::GetCurrentDownloads(Observer* observer, + const FilePath& dir_path) { + DCHECK(observer); + + std::vector<DownloadItem*> download_copy; + + for (DownloadMap::iterator it = downloads_.begin(); + it != downloads_.end(); ++it) { + if (!it->second->is_temporary() && + (it->second->state() == DownloadItem::IN_PROGRESS || + it->second->safety_state() == DownloadItem::DANGEROUS) && + (dir_path.empty() || it->second->full_path().DirName() == dir_path)) + download_copy.push_back(it->second); + } + + observer->SetDownloads(download_copy); +} + // Query the history service for information about all persisted downloads. bool DownloadManager::Init(Profile* profile) { DCHECK(profile); diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h index 4b253bc..e38e130 100644 --- a/chrome/browser/download/download_manager.h +++ b/chrome/browser/download/download_manager.h @@ -385,6 +385,10 @@ class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, void GetTemporaryDownloads(Observer* observer, const FilePath& dir_path); + // Return all non-temporary downloads in the specified directory that are + // either in-progress or finished but still waiting for user confirmation. + void GetCurrentDownloads(Observer* observer, const FilePath& dir_path); + // Returns true if initialized properly. bool Init(Profile* profile); diff --git a/chrome/browser/resources/filebrowse.html b/chrome/browser/resources/filebrowse.html index c00beaf422..ad9b75e 100644 --- a/chrome/browser/resources/filebrowse.html +++ b/chrome/browser/resources/filebrowse.html @@ -59,6 +59,23 @@ div.header { padding: 4px; } +.link { + color: blue; + text-decoration: underline; + float: left; + margin-left: 5px; + margin-right: 5px; +} + +.prompt { + float: left; + text-decoration: none; + color: black; + margin-left: 5px; + margin-right: 5px; + cursor: default; +} + a.iconlink { display: block; /* font-family: helvetica; */ @@ -195,6 +212,7 @@ li.filebrowserow { .downloadstatus { width: 100%; font-size:.6em; + height: 10px; } .downloadpause { @@ -205,7 +223,6 @@ li.filebrowserow { color:blue; text-align: center; position: absolute; - text-decoration:underline; } li.filebrowserow:hover { @@ -647,6 +664,7 @@ function browseFileResult(info, results) { return; } } + chrome.send("getDownloads", []); }; function pathIsVideoFile(path) { @@ -888,11 +906,19 @@ function downloadsList(results) { downloadUpdated(results); }; +function allowDownload(id) { + chrome.send('allowDownload', ['' + id]); +}; + +function cancelDownload(id) { + chrome.send('cancelDownload', ['' + id]); +}; + function downloadUpdated(results) { for (var x = 0; x < results.length; x++) { var element = $(results[x].file_path); if (element) { - if (results[x].percent < 100) { + if (results[x].percent < 100 || results[x].state == 'DANGEROUS') { var progressDiv = null; for (var y = 0; y < element.children.length; y++) { if (element.children[y].className == 'downloadstatus') { @@ -909,7 +935,21 @@ function downloadUpdated(results) { pauseDiv.onclick = new Function('pauseToggleDownload(' + results[x].id + ')'); pauseDiv.className = 'downloadpause'; if (results[x].state == "DANGEROUS") { - pauseDiv.textContent = "danger"; + pauseDiv.onClick = undefined; + var prompt = document.createElement('div'); + prompt.textContent = 'Allow Download?'; + prompt.className = 'prompt'; + pauseDiv.appendChild(prompt); + var yes = document.createElement('div'); + yes.className = 'link'; + yes.textContent = 'yes'; + yes.onclick = new Function('allowDownload(' + results[x].id +')'); + var no = document.createElement('div'); + no.onclick = new Function('cancelDownload(' + results[x].id +')'); + no.textContent = 'no'; + no.className = 'link'; + pauseDiv.appendChild(yes); + pauseDiv.appendChild(no); } else if (results[x].state == "PAUSED") { pauseDiv.textContent = kResumeDownload; } else if (results[x].state == "IN_PROGRESS") { @@ -918,7 +958,10 @@ function downloadUpdated(results) { pauseDiv.id = 'downloaditem' + results[x].id; element.appendChild(pauseDiv); } - progressDiv.textContent = results[x].progress_status_text; + if (results[x].state != "DANGEROUS" || + results[x].percent < 100) { + progressDiv.textContent = results[x].progress_status_text; + } } else { for (var x = 0; x < element.children.length; x++) { @@ -933,6 +976,13 @@ function downloadUpdated(results) { element.className = 'filebrowserow'; } } else { + // Figure out if the item is currently visible + // TODO(dhg): Support multi pane + // This checks to make sure its not mid updating when it does this. + var element = $('dir/' + pathArray[currentNode]); + if (element && results[x].file_path.indexOf(pathArray[currentNode]) >= 0) { + chrome.send("refreshDirectory", [pathArray[currentNode]]); + } // TODO(dhg):Get the new file } } @@ -1238,7 +1288,6 @@ function selectItem(elementid, path) { } }; -// TODO(dhg): Do not use javascript: href, use onclick instead function getFunctionForItem(path, id, isDirectory) { if (isDirectory) { return 'descend("' + path + '", ' + currentNode + ')'; |