| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 and updates the page. |
| 200 void UpdateDownloadList(); |
| 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 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 info_value.SetString(kPropertyPath, currentpath_.value()); | 897 info_value.SetString(kPropertyPath, currentpath_.value()); |
| 895 dom_ui_->CallJavascriptFunction(L"browseFileResult", | 898 dom_ui_->CallJavascriptFunction(L"browseFileResult", |
| 896 info_value, *(filelist_value_.get())); | 899 info_value, *(filelist_value_.get())); |
| 897 SendCurrentDownloads(); | 900 SendCurrentDownloads(); |
| 898 } | 901 } |
| 899 | 902 |
| 900 void FilebrowseHandler::HandleGetMetadata(const ListValue* args) { | 903 void FilebrowseHandler::HandleGetMetadata(const ListValue* args) { |
| 901 } | 904 } |
| 902 | 905 |
| 903 void FilebrowseHandler::HandleGetDownloads(const ListValue* args) { | 906 void FilebrowseHandler::HandleGetDownloads(const ListValue* args) { |
| 904 ModelChanged(); | 907 UpdateDownloadList(); |
| 905 } | 908 } |
| 906 | 909 |
| 907 void FilebrowseHandler::ModelChanged() { | 910 void FilebrowseHandler::ModelChanged() { |
| 911 if (!currentpath_.empty()) |
| 912 GetChildrenForPath(currentpath_, true); |
| 913 else |
| 914 UpdateDownloadList(); |
| 915 } |
| 916 |
| 917 void FilebrowseHandler::UpdateDownloadList() { |
| 908 ClearDownloadItems(); | 918 ClearDownloadItems(); |
| 909 | 919 |
| 910 std::vector<DownloadItem*> downloads; | 920 std::vector<DownloadItem*> downloads; |
| 911 download_manager_->GetAllDownloads(FilePath(), &downloads); | 921 download_manager_->GetAllDownloads(FilePath(), &downloads); |
| 912 | 922 |
| 913 std::vector<DownloadItem*> new_downloads; | 923 std::vector<DownloadItem*> new_downloads; |
| 914 // Scan for any in progress downloads and add ourself to them as an observer. | 924 // Scan for any in progress downloads and add ourself to them as an observer. |
| 915 for (DownloadList::iterator it = downloads.begin(); | 925 for (DownloadList::iterator it = downloads.begin(); |
| 916 it != downloads.end(); ++it) { | 926 it != downloads.end(); ++it) { |
| 917 DownloadItem* download = *it; | 927 DownloadItem* download = *it; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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; |
| OLD | NEW |