Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: chrome/browser/dom_ui/filebrowse_ui.cc

Issue 6320007: Updates filebrowser list when download starts/ends. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: fixing unittests Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/dom_ui/filebrowse_ui.h" 5 #include "chrome/browser/dom_ui/filebrowse_ui.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 virtual void RegisterMessages(); 119 virtual void RegisterMessages();
120 120
121 #if defined(OS_CHROMEOS) 121 #if defined(OS_CHROMEOS)
122 void MountChanged(chromeos::MountLibrary* obj, 122 void MountChanged(chromeos::MountLibrary* obj,
123 chromeos::MountEventType evt, 123 chromeos::MountEventType evt,
124 const std::string& path); 124 const std::string& path);
125 #endif 125 #endif
126 126
127 // DownloadItem::Observer interface 127 // DownloadItem::Observer interface
128 virtual void OnDownloadUpdated(DownloadItem* download); 128 virtual void OnDownloadUpdated(DownloadItem* download);
129 virtual void OnDownloadFileCompleted(DownloadItem* download) { } 129 virtual void OnDownloadFileCompleted(DownloadItem* download);
130 virtual void OnDownloadOpened(DownloadItem* download) { } 130 virtual void OnDownloadOpened(DownloadItem* download) { }
131 131
132 // DownloadManager::Observer interface 132 // DownloadManager::Observer interface
133 virtual void ModelChanged(); 133 virtual void ModelChanged();
134 134
135 // Callback for the "getRoots" message. 135 // Callback for the "getRoots" message.
136 void HandleGetRoots(const ListValue* args); 136 void HandleGetRoots(const ListValue* args);
137 137
138 void GetChildrenForPath(FilePath& path, bool is_refresh); 138 void GetChildrenForPath(FilePath& path, bool is_refresh);
139 139
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 void HandleValidateSavePath(const ListValue* args); 189 void HandleValidateSavePath(const ListValue* args);
190 190
191 // Validate a save path on file thread. 191 // Validate a save path on file thread.
192 void ValidateSavePathOnFileThread(const FilePath& save_path); 192 void ValidateSavePathOnFileThread(const FilePath& save_path);
193 193
194 // Fire save path validation result to JS onValidatedSavePath. 194 // Fire save path validation result to JS onValidatedSavePath.
195 void FireOnValidatedSavePathOnUIThread(bool valid, const FilePath& save_path); 195 void FireOnValidatedSavePathOnUIThread(bool valid, const FilePath& save_path);
196 196
197 private: 197 private:
198 198
199 // Retrieves downloads from the DownloadManager.
200 void GetDownloads();
201
199 void OpenNewWindow(const ListValue* args, bool popup); 202 void OpenNewWindow(const ListValue* args, bool popup);
200 203
201 // Clear all download items and their observers. 204 // Clear all download items and their observers.
202 void ClearDownloadItems(); 205 void ClearDownloadItems();
203 206
204 // Send the current list of downloads to the page. 207 // Send the current list of downloads to the page.
205 void SendCurrentDownloads(); 208 void SendCurrentDownloads();
206 209
207 void SendNewDownload(DownloadItem* download); 210 void SendNewDownload(DownloadItem* download);
208 211
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 } 707 }
705 708
706 void FilebrowseHandler::OpenNewFullWindow(const ListValue* args) { 709 void FilebrowseHandler::OpenNewFullWindow(const ListValue* args) {
707 OpenNewWindow(args, false); 710 OpenNewWindow(args, false);
708 } 711 }
709 712
710 void FilebrowseHandler::OpenNewPopupWindow(const ListValue* args) { 713 void FilebrowseHandler::OpenNewPopupWindow(const ListValue* args) {
711 OpenNewWindow(args, true); 714 OpenNewWindow(args, true);
712 } 715 }
713 716
717 void FilebrowseHandler::GetDownloads() {
achuithb 2011/01/18 17:53:44 Maybe you could move this function to after the de
altimofeev 2011/01/19 10:29:35 Done.
718 ClearDownloadItems();
719
720 std::vector<DownloadItem*> downloads;
721 download_manager_->GetAllDownloads(FilePath(), &downloads);
722
723 std::vector<DownloadItem*> new_downloads;
724 // Scan for any in progress downloads and add ourself to them as an observer.
725 for (DownloadList::iterator it = downloads.begin();
726 it != downloads.end(); ++it) {
727 DownloadItem* download = *it;
728 // We want to know what happens as the download progresses and be notified
729 // when the user validates the dangerous download.
730 if (download->state() == DownloadItem::IN_PROGRESS ||
731 download->safety_state() == DownloadItem::DANGEROUS) {
732 download->AddObserver(this);
733 active_download_items_.push_back(download);
734 }
735 DownloadList::iterator item = find(download_items_.begin(),
736 download_items_.end(),
737 download);
738 if (item == download_items_.end() && got_first_download_list_) {
739 SendNewDownload(download);
740 }
741 new_downloads.push_back(download);
742 }
743 download_items_.swap(new_downloads);
744 got_first_download_list_ = true;
745 SendCurrentDownloads();
746 }
747
714 void FilebrowseHandler::OpenNewWindow(const ListValue* args, bool popup) { 748 void FilebrowseHandler::OpenNewWindow(const ListValue* args, bool popup) {
715 std::string url = WideToUTF8(ExtractStringValue(args)); 749 std::string url = WideToUTF8(ExtractStringValue(args));
716 Browser* browser = popup ? 750 Browser* browser = popup ?
717 Browser::CreateForType(Browser::TYPE_APP_PANEL, profile_) : 751 Browser::CreateForType(Browser::TYPE_APP_PANEL, profile_) :
718 BrowserList::GetLastActive(); 752 BrowserList::GetLastActive();
719 browser::NavigateParams params(browser, GURL(url), PageTransition::LINK); 753 browser::NavigateParams params(browser, GURL(url), PageTransition::LINK);
720 params.disposition = NEW_FOREGROUND_TAB; 754 params.disposition = NEW_FOREGROUND_TAB;
721 browser::Navigate(&params); 755 browser::Navigate(&params);
722 // TODO(beng): The following two calls should be automatic by Navigate(). 756 // TODO(beng): The following two calls should be automatic by Navigate().
723 if (popup) { 757 if (popup) {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 info_value.SetString(kPropertyPath, currentpath_.value()); 928 info_value.SetString(kPropertyPath, currentpath_.value());
895 dom_ui_->CallJavascriptFunction(L"browseFileResult", 929 dom_ui_->CallJavascriptFunction(L"browseFileResult",
896 info_value, *(filelist_value_.get())); 930 info_value, *(filelist_value_.get()));
897 SendCurrentDownloads(); 931 SendCurrentDownloads();
898 } 932 }
899 933
900 void FilebrowseHandler::HandleGetMetadata(const ListValue* args) { 934 void FilebrowseHandler::HandleGetMetadata(const ListValue* args) {
901 } 935 }
902 936
903 void FilebrowseHandler::HandleGetDownloads(const ListValue* args) { 937 void FilebrowseHandler::HandleGetDownloads(const ListValue* args) {
904 ModelChanged(); 938 GetDownloads();
905 } 939 }
906 940
907 void FilebrowseHandler::ModelChanged() { 941 void FilebrowseHandler::ModelChanged() {
908 ClearDownloadItems(); 942 if (!currentpath_.empty())
909 943 GetChildrenForPath(currentpath_, true);
910 std::vector<DownloadItem*> downloads; 944 else
911 download_manager_->GetAllDownloads(FilePath(), &downloads); 945 GetDownloads();
912
913 std::vector<DownloadItem*> new_downloads;
914 // Scan for any in progress downloads and add ourself to them as an observer.
915 for (DownloadList::iterator it = downloads.begin();
916 it != downloads.end(); ++it) {
917 DownloadItem* download = *it;
918 // We want to know what happens as the download progresses and be notified
919 // when the user validates the dangerous download.
920 if (download->state() == DownloadItem::IN_PROGRESS ||
921 download->safety_state() == DownloadItem::DANGEROUS) {
922 download->AddObserver(this);
923 active_download_items_.push_back(download);
924 }
925 DownloadList::iterator item = find(download_items_.begin(),
926 download_items_.end(),
927 download);
928 if (item == download_items_.end() && got_first_download_list_) {
929 SendNewDownload(download);
930 }
931 new_downloads.push_back(download);
932 }
933 download_items_.swap(new_downloads);
934 got_first_download_list_ = true;
935 SendCurrentDownloads();
936 } 946 }
937 947
938 void FilebrowseHandler::SendNewDownload(DownloadItem* download) { 948 void FilebrowseHandler::SendNewDownload(DownloadItem* download) {
939 ListValue results_value; 949 ListValue results_value;
940 results_value.Append(download_util::CreateDownloadItemValue(download, -1)); 950 results_value.Append(download_util::CreateDownloadItemValue(download, -1));
941 dom_ui_->CallJavascriptFunction(L"newDownload", results_value); 951 dom_ui_->CallJavascriptFunction(L"newDownload", results_value);
942 } 952 }
943 953
944 void FilebrowseHandler::DeleteFile(const FilePath& path) { 954 void FilebrowseHandler::DeleteFile(const FilePath& path) {
945 if (!file_util::Delete(path, true)) { 955 if (!file_util::Delete(path, true)) {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 ListValue results_value; 1116 ListValue results_value;
1107 for (DownloadList::iterator it = active_download_items_.begin(); 1117 for (DownloadList::iterator it = active_download_items_.begin();
1108 it != active_download_items_.end(); ++it) { 1118 it != active_download_items_.end(); ++it) {
1109 int index = static_cast<int>(it - active_download_items_.begin()); 1119 int index = static_cast<int>(it - active_download_items_.begin());
1110 results_value.Append(download_util::CreateDownloadItemValue(*it, index)); 1120 results_value.Append(download_util::CreateDownloadItemValue(*it, index));
1111 } 1121 }
1112 1122
1113 dom_ui_->CallJavascriptFunction(L"downloadsList", results_value); 1123 dom_ui_->CallJavascriptFunction(L"downloadsList", results_value);
1114 } 1124 }
1115 1125
1126 void FilebrowseHandler::OnDownloadFileCompleted(DownloadItem* download) {
1127 GetChildrenForPath(currentpath_, true);
1128 }
1129
1116 //////////////////////////////////////////////////////////////////////////////// 1130 ////////////////////////////////////////////////////////////////////////////////
1117 // 1131 //
1118 // FileBrowseUI 1132 // FileBrowseUI
1119 // 1133 //
1120 //////////////////////////////////////////////////////////////////////////////// 1134 ////////////////////////////////////////////////////////////////////////////////
1121 1135
1122 FileBrowseUI::FileBrowseUI(TabContents* contents) : HtmlDialogUI(contents) { 1136 FileBrowseUI::FileBrowseUI(TabContents* contents) : HtmlDialogUI(contents) {
1123 FilebrowseHandler* handler = new FilebrowseHandler(); 1137 FilebrowseHandler* handler = new FilebrowseHandler();
1124 AddMessageHandler((handler)->Attach(this)); 1138 AddMessageHandler((handler)->Attach(this));
1125 handler->Init(); 1139 handler->Init();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 } 1218 }
1205 } 1219 }
1206 1220
1207 return NULL; 1221 return NULL;
1208 } 1222 }
1209 1223
1210 const int FileBrowseUI::kPopupWidth = 250; 1224 const int FileBrowseUI::kPopupWidth = 250;
1211 const int FileBrowseUI::kPopupHeight = 300; 1225 const int FileBrowseUI::kPopupHeight = 300;
1212 const int FileBrowseUI::kSmallPopupWidth = 250; 1226 const int FileBrowseUI::kSmallPopupWidth = 250;
1213 const int FileBrowseUI::kSmallPopupHeight = 50; 1227 const int FileBrowseUI::kSmallPopupHeight = 50;
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698