| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 private: | 87 private: |
| 88 ~FileBrowseUIHTMLSource() {} | 88 ~FileBrowseUIHTMLSource() {} |
| 89 | 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(FileBrowseUIHTMLSource); | 90 DISALLOW_COPY_AND_ASSIGN(FileBrowseUIHTMLSource); |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 class TaskProxy; | 93 class TaskProxy; |
| 94 | 94 |
| 95 // The handler for Javascript messages related to the "filebrowse" view. | 95 // The handler for Javascript messages related to the "filebrowse" view. |
| 96 class FilebrowseHandler : public net::DirectoryLister::DirectoryListerDelegate, | 96 class FilebrowseHandler : public net::DirectoryLister::Delegate, |
| 97 public DOMMessageHandler, | 97 public DOMMessageHandler, |
| 98 #if defined(OS_CHROMEOS) | 98 #if defined(OS_CHROMEOS) |
| 99 public chromeos::MountLibrary::Observer, | 99 public chromeos::MountLibrary::Observer, |
| 100 #endif | 100 #endif |
| 101 public base::SupportsWeakPtr<FilebrowseHandler>, | 101 public base::SupportsWeakPtr<FilebrowseHandler>, |
| 102 public URLFetcher::Delegate, | 102 public URLFetcher::Delegate, |
| 103 public DownloadManager::Observer, | 103 public DownloadManager::Observer, |
| 104 public DownloadItem::Observer { | 104 public DownloadItem::Observer { |
| 105 public: | 105 public: |
| 106 FilebrowseHandler(); | 106 FilebrowseHandler(); |
| 107 virtual ~FilebrowseHandler(); | 107 virtual ~FilebrowseHandler(); |
| 108 | 108 |
| 109 // Init work after Attach. | 109 // Init work after Attach. |
| 110 void Init(); | 110 void Init(); |
| 111 | 111 |
| 112 // DirectoryLister::DirectoryListerDelegate methods: | 112 // DirectoryLister::Delegate methods: |
| 113 virtual void OnListFile( | 113 virtual void OnListFile(const net::DirectoryLister::Data& data); |
| 114 const net::DirectoryLister::DirectoryListerData& data); | |
| 115 virtual void OnListDone(int error); | 114 virtual void OnListDone(int error); |
| 116 | 115 |
| 117 // DOMMessageHandler implementation. | 116 // DOMMessageHandler implementation. |
| 118 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); | 117 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); |
| 119 virtual void RegisterMessages(); | 118 virtual void RegisterMessages(); |
| 120 | 119 |
| 121 #if defined(OS_CHROMEOS) | 120 #if defined(OS_CHROMEOS) |
| 122 void MountChanged(chromeos::MountLibrary* obj, | 121 void MountChanged(chromeos::MountLibrary* obj, |
| 123 chromeos::MountEventType evt, | 122 chromeos::MountEventType evt, |
| 124 const std::string& path); | 123 const std::string& path); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 void SendNewDownload(DownloadItem* download); | 206 void SendNewDownload(DownloadItem* download); |
| 208 | 207 |
| 209 scoped_ptr<ListValue> filelist_value_; | 208 scoped_ptr<ListValue> filelist_value_; |
| 210 FilePath currentpath_; | 209 FilePath currentpath_; |
| 211 Profile* profile_; | 210 Profile* profile_; |
| 212 TabContents* tab_contents_; | 211 TabContents* tab_contents_; |
| 213 std::string current_file_contents_; | 212 std::string current_file_contents_; |
| 214 std::string current_file_uploaded_; | 213 std::string current_file_uploaded_; |
| 215 int upload_response_code_; | 214 int upload_response_code_; |
| 216 TaskProxy* current_task_; | 215 TaskProxy* current_task_; |
| 217 scoped_refptr<net::DirectoryLister> lister_; | 216 scoped_ptr<net::DirectoryLister> lister_; |
| 218 bool is_refresh_; | 217 bool is_refresh_; |
| 219 scoped_ptr<URLFetcher> fetch_; | 218 scoped_ptr<URLFetcher> fetch_; |
| 220 | 219 |
| 221 DownloadManager* download_manager_; | 220 DownloadManager* download_manager_; |
| 222 typedef std::vector<DownloadItem*> DownloadList; | 221 typedef std::vector<DownloadItem*> DownloadList; |
| 223 DownloadList active_download_items_; | 222 DownloadList active_download_items_; |
| 224 DownloadList download_items_; | 223 DownloadList download_items_; |
| 225 bool got_first_download_list_; | 224 bool got_first_download_list_; |
| 226 DISALLOW_COPY_AND_ASSIGN(FilebrowseHandler); | 225 DISALLOW_COPY_AND_ASSIGN(FilebrowseHandler); |
| 227 }; | 226 }; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 // FilebrowseHandler | 377 // FilebrowseHandler |
| 379 // | 378 // |
| 380 //////////////////////////////////////////////////////////////////////////////// | 379 //////////////////////////////////////////////////////////////////////////////// |
| 381 FilebrowseHandler::FilebrowseHandler() | 380 FilebrowseHandler::FilebrowseHandler() |
| 382 : profile_(NULL), | 381 : profile_(NULL), |
| 383 tab_contents_(NULL), | 382 tab_contents_(NULL), |
| 384 is_refresh_(false), | 383 is_refresh_(false), |
| 385 fetch_(NULL), | 384 fetch_(NULL), |
| 386 download_manager_(NULL), | 385 download_manager_(NULL), |
| 387 got_first_download_list_(false) { | 386 got_first_download_list_(false) { |
| 388 lister_ = NULL; | |
| 389 #if defined(OS_CHROMEOS) | 387 #if defined(OS_CHROMEOS) |
| 390 chromeos::MountLibrary* lib = | 388 chromeos::MountLibrary* lib = |
| 391 chromeos::CrosLibrary::Get()->GetMountLibrary(); | 389 chromeos::CrosLibrary::Get()->GetMountLibrary(); |
| 392 lib->AddObserver(this); | 390 lib->AddObserver(this); |
| 393 #endif | 391 #endif |
| 394 } | 392 } |
| 395 | 393 |
| 396 FilebrowseHandler::~FilebrowseHandler() { | 394 FilebrowseHandler::~FilebrowseHandler() { |
| 397 #if defined(OS_CHROMEOS) | 395 #if defined(OS_CHROMEOS) |
| 398 chromeos::MountLibrary* lib = | 396 chromeos::MountLibrary* lib = |
| 399 chromeos::CrosLibrary::Get()->GetMountLibrary(); | 397 chromeos::CrosLibrary::Get()->GetMountLibrary(); |
| 400 lib->RemoveObserver(this); | 398 lib->RemoveObserver(this); |
| 401 #endif | 399 #endif |
| 402 if (lister_.get()) { | |
| 403 lister_->Cancel(); | |
| 404 lister_->set_delegate(NULL); | |
| 405 } | |
| 406 | 400 |
| 407 ClearDownloadItems(); | 401 ClearDownloadItems(); |
| 408 download_manager_->RemoveObserver(this); | 402 download_manager_->RemoveObserver(this); |
| 409 URLFetcher* fetch = fetch_.release(); | 403 URLFetcher* fetch = fetch_.release(); |
| 410 if (fetch) { | 404 if (fetch) { |
| 411 TaskProxy* task = new TaskProxy(AsWeakPtr(), currentpath_); | 405 TaskProxy* task = new TaskProxy(AsWeakPtr(), currentpath_); |
| 412 task->AddRef(); | 406 task->AddRef(); |
| 413 BrowserThread::PostTask( | 407 BrowserThread::PostTask( |
| 414 BrowserThread::FILE, FROM_HERE, | 408 BrowserThread::FILE, FROM_HERE, |
| 415 NewRunnableMethod( | 409 NewRunnableMethod( |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 BrowserThread::FILE, FROM_HERE, | 800 BrowserThread::FILE, FROM_HERE, |
| 807 NewRunnableMethod( | 801 NewRunnableMethod( |
| 808 task, &TaskProxy::ReadInFileProxy)); | 802 task, &TaskProxy::ReadInFileProxy)); |
| 809 #endif | 803 #endif |
| 810 } | 804 } |
| 811 | 805 |
| 812 void FilebrowseHandler::GetChildrenForPath(FilePath& path, bool is_refresh) { | 806 void FilebrowseHandler::GetChildrenForPath(FilePath& path, bool is_refresh) { |
| 813 filelist_value_.reset(new ListValue()); | 807 filelist_value_.reset(new ListValue()); |
| 814 currentpath_ = path; | 808 currentpath_ = path; |
| 815 | 809 |
| 816 if (lister_.get()) { | 810 lister_.reset(); |
| 817 lister_->Cancel(); | |
| 818 lister_->set_delegate(NULL); | |
| 819 lister_ = NULL; | |
| 820 } | |
| 821 | |
| 822 is_refresh_ = is_refresh; | 811 is_refresh_ = is_refresh; |
| 823 | 812 |
| 824 #if defined(OS_CHROMEOS) | 813 #if defined(OS_CHROMEOS) |
| 825 // Don't allow listing files in inaccessible dirs. | 814 // Don't allow listing files in inaccessible dirs. |
| 826 if (URLRequestFileJob::AccessDisabled(path)) | 815 if (URLRequestFileJob::AccessDisabled(path)) |
| 827 return; | 816 return; |
| 828 #endif // OS_CHROMEOS | 817 #endif // OS_CHROMEOS |
| 829 | 818 |
| 830 FilePath default_download_path; | 819 FilePath default_download_path; |
| 831 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, | 820 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, |
| 832 &default_download_path)) { | 821 &default_download_path)) { |
| 833 NOTREACHED(); | 822 NOTREACHED(); |
| 834 } | 823 } |
| 835 if (currentpath_ == default_download_path) { | 824 if (currentpath_ == default_download_path) { |
| 836 lister_ = new net::DirectoryLister(currentpath_, | 825 lister_.reset(new net::DirectoryLister(currentpath_, |
| 837 false, | 826 false, |
| 838 net::DirectoryLister::DATE, | 827 net::DirectoryLister::DATE, |
| 839 this); | 828 this)); |
| 840 } else { | 829 } else { |
| 841 lister_ = new net::DirectoryLister(currentpath_, this); | 830 lister_.reset(new net::DirectoryLister(currentpath_, this)); |
| 842 } | 831 } |
| 843 lister_->Start(); | 832 lister_->Start(); |
| 844 } | 833 } |
| 845 | 834 |
| 846 void FilebrowseHandler::HandleGetChildren(const ListValue* args) { | 835 void FilebrowseHandler::HandleGetChildren(const ListValue* args) { |
| 847 #if defined(OS_CHROMEOS) | 836 #if defined(OS_CHROMEOS) |
| 848 std::string path = WideToUTF8(ExtractStringValue(args)); | 837 std::string path = WideToUTF8(ExtractStringValue(args)); |
| 849 FilePath currentpath(path); | 838 FilePath currentpath(path); |
| 850 filelist_value_.reset(new ListValue()); | 839 filelist_value_.reset(new ListValue()); |
| 851 | 840 |
| 852 GetChildrenForPath(currentpath, false); | 841 GetChildrenForPath(currentpath, false); |
| 853 #endif | 842 #endif |
| 854 } | 843 } |
| 855 | 844 |
| 856 void FilebrowseHandler::OnListFile( | 845 void FilebrowseHandler::OnListFile(const net::DirectoryLister::Data& data) { |
| 857 const net::DirectoryLister::DirectoryListerData& data) { | |
| 858 #if defined(OS_WIN) | 846 #if defined(OS_WIN) |
| 859 if (data.info.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) { | 847 if (data.info.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) { |
| 860 return; | 848 return; |
| 861 } | 849 } |
| 862 #elif defined(OS_POSIX) | 850 #elif defined(OS_POSIX) |
| 863 if (data.info.filename[0] == '.') { | 851 if (data.info.filename[0] == '.') { |
| 864 return; | 852 return; |
| 865 } | 853 } |
| 866 #endif | 854 #endif |
| 867 | 855 |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1204 } | 1192 } |
| 1205 } | 1193 } |
| 1206 | 1194 |
| 1207 return NULL; | 1195 return NULL; |
| 1208 } | 1196 } |
| 1209 | 1197 |
| 1210 const int FileBrowseUI::kPopupWidth = 250; | 1198 const int FileBrowseUI::kPopupWidth = 250; |
| 1211 const int FileBrowseUI::kPopupHeight = 300; | 1199 const int FileBrowseUI::kPopupHeight = 300; |
| 1212 const int FileBrowseUI::kSmallPopupWidth = 250; | 1200 const int FileBrowseUI::kSmallPopupWidth = 250; |
| 1213 const int FileBrowseUI::kSmallPopupHeight = 50; | 1201 const int FileBrowseUI::kSmallPopupHeight = 50; |
| OLD | NEW |