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

Side by Side Diff: chrome/browser/ui/webui/filebrowse_ui.cc

Issue 6674043: Rewritten MountLibrary to work with non-blocking mount API calls in libcros.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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 | « chrome/browser/ui/browser_init.cc ('k') | 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/ui/webui/filebrowse_ui.h" 5 #include "chrome/browser/ui/webui/filebrowse_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 #include "chrome/browser/chromeos/cros/mount_library.h" 57 #include "chrome/browser/chromeos/cros/mount_library.h"
58 #include "chrome/browser/chromeos/login/user_manager.h" 58 #include "chrome/browser/chromeos/login/user_manager.h"
59 #endif 59 #endif
60 60
61 // Maximum number of search results to return in a given search. We should 61 // Maximum number of search results to return in a given search. We should
62 // eventually remove this. 62 // eventually remove this.
63 static const int kMaxSearchResults = 100; 63 static const int kMaxSearchResults = 100;
64 static const char kPropertyPath[] = "path"; 64 static const char kPropertyPath[] = "path";
65 static const char kPropertyTitle[] = "title"; 65 static const char kPropertyTitle[] = "title";
66 static const char kPropertyDirectory[] = "isDirectory"; 66 static const char kPropertyDirectory[] = "isDirectory";
67 static const char kPicasawebUserPrefix[] =
68 "http://picasaweb.google.com/data/feed/api/user/";
69 static const char kPicasawebDefault[] = "/albumid/default";
70 static const char kPicasawebDropBox[] = "/home";
71 static const char kPicasawebBaseUrl[] = "http://picasaweb.google.com/";
72 static const char kMediaPath[] = "/media"; 67 static const char kMediaPath[] = "/media";
73 static const char kFilebrowseURLHash[] = "chrome://filebrowse#"; 68 static const char kFilebrowseURLHash[] = "chrome://filebrowse#";
74 static const int kPopupLeft = 0; 69 static const int kPopupLeft = 0;
75 static const int kPopupTop = 0; 70 static const int kPopupTop = 0;
76 71
77 class FileBrowseUIHTMLSource : public ChromeURLDataManager::DataSource { 72 class FileBrowseUIHTMLSource : public ChromeURLDataManager::DataSource {
78 public: 73 public:
79 FileBrowseUIHTMLSource(); 74 FileBrowseUIHTMLSource();
80 75
81 // Called when the network layer has requested a resource underneath 76 // Called when the network layer has requested a resource underneath
(...skipping 13 matching lines...) Expand all
95 90
96 class TaskProxy; 91 class TaskProxy;
97 92
98 // The handler for Javascript messages related to the "filebrowse" view. 93 // The handler for Javascript messages related to the "filebrowse" view.
99 class FilebrowseHandler : public net::DirectoryLister::DirectoryListerDelegate, 94 class FilebrowseHandler : public net::DirectoryLister::DirectoryListerDelegate,
100 public WebUIMessageHandler, 95 public WebUIMessageHandler,
101 #if defined(OS_CHROMEOS) 96 #if defined(OS_CHROMEOS)
102 public chromeos::MountLibrary::Observer, 97 public chromeos::MountLibrary::Observer,
103 #endif 98 #endif
104 public base::SupportsWeakPtr<FilebrowseHandler>, 99 public base::SupportsWeakPtr<FilebrowseHandler>,
105 public URLFetcher::Delegate,
106 public DownloadManager::Observer, 100 public DownloadManager::Observer,
107 public DownloadItem::Observer { 101 public DownloadItem::Observer {
108 public: 102 public:
109 FilebrowseHandler(); 103 FilebrowseHandler();
110 virtual ~FilebrowseHandler(); 104 virtual ~FilebrowseHandler();
111 105
112 // Init work after Attach. 106 // Init work after Attach.
113 void Init(); 107 void Init();
114 108
115 // DirectoryLister::DirectoryListerDelegate methods: 109 // DirectoryLister::DirectoryListerDelegate methods:
116 virtual void OnListFile( 110 virtual void OnListFile(
117 const net::DirectoryLister::DirectoryListerData& data); 111 const net::DirectoryLister::DirectoryListerData& data);
118 virtual void OnListDone(int error); 112 virtual void OnListDone(int error);
119 113
120 // WebUIMessageHandler implementation. 114 // WebUIMessageHandler implementation.
121 virtual WebUIMessageHandler* Attach(WebUI* web_ui); 115 virtual WebUIMessageHandler* Attach(WebUI* web_ui);
122 virtual void RegisterMessages(); 116 virtual void RegisterMessages();
123 117
124 #if defined(OS_CHROMEOS) 118 #if defined(OS_CHROMEOS)
125 void MountChanged(chromeos::MountLibrary* obj, 119 // chromeos::MountLibrary::Observer interface
126 chromeos::MountEventType evt, 120 virtual void DiskChanged(chromeos::MountLibraryEventType event,
127 const std::string& path); 121 const chromeos::MountLibrary::Disk* disk);
122 virtual void DeviceChanged(chromeos::MountLibraryEventType event,
123 const std::string& device_path);
128 #endif 124 #endif
129 125
130 // DownloadItem::Observer interface 126 // DownloadItem::Observer interface
131 virtual void OnDownloadUpdated(DownloadItem* download); 127 virtual void OnDownloadUpdated(DownloadItem* download);
132 virtual void OnDownloadFileCompleted(DownloadItem* download); 128 virtual void OnDownloadFileCompleted(DownloadItem* download);
133 virtual void OnDownloadOpened(DownloadItem* download) { } 129 virtual void OnDownloadOpened(DownloadItem* download) { }
134 130
135 // DownloadManager::Observer interface 131 // DownloadManager::Observer interface
136 virtual void ModelChanged(); 132 virtual void ModelChanged();
137 133
138 // Callback for the "getRoots" message. 134 // Callback for the "getRoots" message.
139 void HandleGetRoots(const ListValue* args); 135 void HandleGetRoots(const ListValue* args);
140 136
141 void GetChildrenForPath(const FilePath& path, bool is_refresh); 137 void GetChildrenForPath(const FilePath& path, bool is_refresh);
142 138
143 void OnURLFetchComplete(const URLFetcher* source,
144 const GURL& url,
145 const net::URLRequestStatus& status,
146 int response_code,
147 const ResponseCookies& cookies,
148 const std::string& data);
149
150 // Callback for the "getChildren" message. 139 // Callback for the "getChildren" message.
151 void HandleGetChildren(const ListValue* args); 140 void HandleGetChildren(const ListValue* args);
152 // Callback for the "refreshDirectory" message. 141 // Callback for the "refreshDirectory" message.
153 void HandleRefreshDirectory(const ListValue* args); 142 void HandleRefreshDirectory(const ListValue* args);
154 void HandleIsAdvancedEnabled(const ListValue* args); 143 void HandleIsAdvancedEnabled(const ListValue* args);
155 144
156 // Callback for the "getMetadata" message. 145 // Callback for the "getMetadata" message.
157 void HandleGetMetadata(const ListValue* args); 146 void HandleGetMetadata(const ListValue* args);
158 147
159 // Callback for the "openNewWindow" message. 148 // Callback for the "openNewWindow" message.
160 void OpenNewFullWindow(const ListValue* args); 149 void OpenNewFullWindow(const ListValue* args);
161 void OpenNewPopupWindow(const ListValue* args); 150 void OpenNewPopupWindow(const ListValue* args);
162 151
163 // Callback for the "uploadToPicasaweb" message.
164 void UploadToPicasaweb(const ListValue* args);
165
166 // Callback for the "getDownloads" message. 152 // Callback for the "getDownloads" message.
167 void HandleGetDownloads(const ListValue* args); 153 void HandleGetDownloads(const ListValue* args);
168 154
169 void HandleCreateNewFolder(const ListValue* args); 155 void HandleCreateNewFolder(const ListValue* args);
170 156
171 void PlayMediaFile(const ListValue* args); 157 void PlayMediaFile(const ListValue* args);
172 void EnqueueMediaFile(const ListValue* args); 158 void EnqueueMediaFile(const ListValue* args);
173 159
174 void HandleDeleteFile(const ListValue* args); 160 void HandleDeleteFile(const ListValue* args);
175 void HandleCopyFile(const ListValue* value); 161 void HandleCopyFile(const ListValue* value);
176 void CopyFile(const FilePath& src, const FilePath& dest, TaskProxy* task); 162 void CopyFile(const FilePath& src, const FilePath& dest, TaskProxy* task);
177 void DeleteFile(const FilePath& path, TaskProxy* task); 163 void DeleteFile(const FilePath& path, TaskProxy* task);
178 void FireDeleteComplete(const FilePath& path); 164 void FireDeleteComplete(const FilePath& path);
179 void FireCopyComplete(const FilePath& src, const FilePath& dest); 165 void FireCopyComplete(const FilePath& src, const FilePath& dest);
180 166
181 void HandlePauseToggleDownload(const ListValue* args); 167 void HandlePauseToggleDownload(const ListValue* args);
182 168
183 void HandleCancelDownload(const ListValue* args); 169 void HandleCancelDownload(const ListValue* args);
184 void HandleAllowDownload(const ListValue* args); 170 void HandleAllowDownload(const ListValue* args);
185 171
186 void CreateNewFolder(const FilePath& path) const; 172 void CreateNewFolder(const FilePath& path) const;
187 173
188 void ReadInFile();
189 void FireUploadComplete();
190
191 void SendPicasawebRequest(URLRequestContextGetter* request_context);
192
193 // Callback for the "validateSavePath" message. 174 // Callback for the "validateSavePath" message.
194 void HandleValidateSavePath(const ListValue* args); 175 void HandleValidateSavePath(const ListValue* args);
195 176
196 // Validate a save path on file thread. 177 // Validate a save path on file thread.
197 void ValidateSavePathOnFileThread(const FilePath& save_path, TaskProxy* task); 178 void ValidateSavePathOnFileThread(const FilePath& save_path, TaskProxy* task);
198 179
199 // Fire save path validation result to JS onValidatedSavePath. 180 // Fire save path validation result to JS onValidatedSavePath.
200 void FireOnValidatedSavePathOnUIThread(bool valid, const FilePath& save_path); 181 void FireOnValidatedSavePathOnUIThread(bool valid, const FilePath& save_path);
201 182
202 private: 183 private:
(...skipping 12 matching lines...) Expand all
215 void SendNewDownload(DownloadItem* download); 196 void SendNewDownload(DownloadItem* download);
216 197
217 bool ValidateSaveDir(const FilePath& save_dir, bool exists) const; 198 bool ValidateSaveDir(const FilePath& save_dir, bool exists) const;
218 bool AccessDisabled(const FilePath& path) const; 199 bool AccessDisabled(const FilePath& path) const;
219 200
220 scoped_ptr<ListValue> filelist_value_; 201 scoped_ptr<ListValue> filelist_value_;
221 FilePath currentpath_; 202 FilePath currentpath_;
222 Profile* profile_; 203 Profile* profile_;
223 TabContents* tab_contents_; 204 TabContents* tab_contents_;
224 std::string current_file_contents_; 205 std::string current_file_contents_;
225 std::string current_file_uploaded_;
226 int upload_response_code_;
227 TaskProxy* current_task_; 206 TaskProxy* current_task_;
228 scoped_refptr<net::DirectoryLister> lister_; 207 scoped_refptr<net::DirectoryLister> lister_;
229 bool is_refresh_; 208 bool is_refresh_;
230 scoped_ptr<URLFetcher> fetch_;
231 209
232 DownloadManager* download_manager_; 210 DownloadManager* download_manager_;
233 typedef std::vector<DownloadItem*> DownloadList; 211 typedef std::vector<DownloadItem*> DownloadList;
234 DownloadList active_download_items_; 212 DownloadList active_download_items_;
235 DownloadList download_items_; 213 DownloadList download_items_;
236 bool got_first_download_list_; 214 bool got_first_download_list_;
237 DISALLOW_COPY_AND_ASSIGN(FilebrowseHandler); 215 DISALLOW_COPY_AND_ASSIGN(FilebrowseHandler);
238 }; 216 };
239 217
240 class TaskProxy : public base::RefCountedThreadSafe<TaskProxy> { 218 class TaskProxy : public base::RefCountedThreadSafe<TaskProxy> {
(...skipping 11 matching lines...) Expand all
252 // TaskProxy is created on the UI thread, so in some cases, 230 // TaskProxy is created on the UI thread, so in some cases,
253 // we need to post back to the UI thread for destruction. 231 // we need to post back to the UI thread for destruction.
254 void DeleteOnUIThread() { 232 void DeleteOnUIThread() {
255 BrowserThread::PostTask( 233 BrowserThread::PostTask(
256 BrowserThread::UI, FROM_HERE, 234 BrowserThread::UI, FROM_HERE,
257 NewRunnableMethod(this, &TaskProxy::DoNothing)); 235 NewRunnableMethod(this, &TaskProxy::DoNothing));
258 } 236 }
259 237
260 void DoNothing() {} 238 void DoNothing() {}
261 239
262 void ReadInFileProxy() {
263 if (handler_)
264 handler_->ReadInFile();
265 DeleteOnUIThread();
266 }
267
268 void DeleteFetcher(URLFetcher* fetch) {
269 delete fetch;
270 }
271
272 void SendPicasawebRequestProxy(URLRequestContextGetter* request_context) {
273 if (handler_)
274 handler_->SendPicasawebRequest(request_context);
275 DeleteOnUIThread();
276 }
277
278 void FireUploadCompleteProxy() {
279 if (handler_)
280 handler_->FireUploadComplete();
281 }
282
283 void DeleteFileProxy() { 240 void DeleteFileProxy() {
284 if (handler_) 241 if (handler_)
285 handler_->DeleteFile(src_, this); 242 handler_->DeleteFile(src_, this);
286 } 243 }
287 244
288 void CopyFileProxy() { 245 void CopyFileProxy() {
289 if (handler_) 246 if (handler_)
290 handler_->CopyFile(src_, dest_, this); 247 handler_->CopyFile(src_, dest_, this);
291 } 248 }
292 249
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 localized_strings.SetString("allowdownload", 314 localized_strings.SetString("allowdownload",
358 l10n_util::GetStringUTF16(IDS_FILEBROWSER_CONFIRM_DOWNLOAD)); 315 l10n_util::GetStringUTF16(IDS_FILEBROWSER_CONFIRM_DOWNLOAD));
359 localized_strings.SetString("filenameprompt", 316 localized_strings.SetString("filenameprompt",
360 l10n_util::GetStringUTF16(IDS_FILEBROWSER_PROMPT_FILENAME)); 317 l10n_util::GetStringUTF16(IDS_FILEBROWSER_PROMPT_FILENAME));
361 localized_strings.SetString("save", 318 localized_strings.SetString("save",
362 l10n_util::GetStringUTF16(IDS_FILEBROWSER_SAVE)); 319 l10n_util::GetStringUTF16(IDS_FILEBROWSER_SAVE));
363 localized_strings.SetString("newfolder", 320 localized_strings.SetString("newfolder",
364 l10n_util::GetStringUTF16(IDS_FILEBROWSER_NEW_FOLDER)); 321 l10n_util::GetStringUTF16(IDS_FILEBROWSER_NEW_FOLDER));
365 localized_strings.SetString("open", 322 localized_strings.SetString("open",
366 l10n_util::GetStringUTF16(IDS_FILEBROWSER_OPEN)); 323 l10n_util::GetStringUTF16(IDS_FILEBROWSER_OPEN));
367 localized_strings.SetString("picasaweb",
368 l10n_util::GetStringUTF16(IDS_FILEBROWSER_UPLOAD_PICASAWEB));
369 localized_strings.SetString("flickr",
370 l10n_util::GetStringUTF16(IDS_FILEBROWSER_UPLOAD_FLICKR));
371 localized_strings.SetString("email",
372 l10n_util::GetStringUTF16(IDS_FILEBROWSER_UPLOAD_EMAIL));
373 localized_strings.SetString("delete", 324 localized_strings.SetString("delete",
374 l10n_util::GetStringUTF16(IDS_FILEBROWSER_DELETE)); 325 l10n_util::GetStringUTF16(IDS_FILEBROWSER_DELETE));
375 localized_strings.SetString("enqueue", 326 localized_strings.SetString("enqueue",
376 l10n_util::GetStringUTF16(IDS_FILEBROWSER_ENQUEUE)); 327 l10n_util::GetStringUTF16(IDS_FILEBROWSER_ENQUEUE));
377 localized_strings.SetString("mediapath", kMediaPath); 328 localized_strings.SetString("mediapath", kMediaPath);
378 FilePath default_download_path; 329 FilePath default_download_path;
379 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, 330 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS,
380 &default_download_path)) { 331 &default_download_path)) {
381 NOTREACHED(); 332 NOTREACHED();
382 } 333 }
(...skipping 18 matching lines...) Expand all
401 352
402 //////////////////////////////////////////////////////////////////////////////// 353 ////////////////////////////////////////////////////////////////////////////////
403 // 354 //
404 // FilebrowseHandler 355 // FilebrowseHandler
405 // 356 //
406 //////////////////////////////////////////////////////////////////////////////// 357 ////////////////////////////////////////////////////////////////////////////////
407 FilebrowseHandler::FilebrowseHandler() 358 FilebrowseHandler::FilebrowseHandler()
408 : profile_(NULL), 359 : profile_(NULL),
409 tab_contents_(NULL), 360 tab_contents_(NULL),
410 is_refresh_(false), 361 is_refresh_(false),
411 fetch_(NULL),
412 download_manager_(NULL), 362 download_manager_(NULL),
413 got_first_download_list_(false) { 363 got_first_download_list_(false) {
414 lister_ = NULL; 364 lister_ = NULL;
415 #if defined(OS_CHROMEOS) 365 #if defined(OS_CHROMEOS)
416 chromeos::MountLibrary* lib = 366 chromeos::MountLibrary* lib =
417 chromeos::CrosLibrary::Get()->GetMountLibrary(); 367 chromeos::CrosLibrary::Get()->GetMountLibrary();
418 lib->AddObserver(this); 368 lib->AddObserver(this);
419 #endif 369 #endif
420 } 370 }
421 371
422 FilebrowseHandler::~FilebrowseHandler() { 372 FilebrowseHandler::~FilebrowseHandler() {
423 #if defined(OS_CHROMEOS) 373 #if defined(OS_CHROMEOS)
424 chromeos::MountLibrary* lib = 374 chromeos::MountLibrary* lib =
425 chromeos::CrosLibrary::Get()->GetMountLibrary(); 375 chromeos::CrosLibrary::Get()->GetMountLibrary();
426 lib->RemoveObserver(this); 376 lib->RemoveObserver(this);
427 #endif 377 #endif
428 if (lister_.get()) { 378 if (lister_.get()) {
429 lister_->Cancel(); 379 lister_->Cancel();
430 lister_->set_delegate(NULL); 380 lister_->set_delegate(NULL);
431 } 381 }
432 382
433 ClearDownloadItems(); 383 ClearDownloadItems();
434 download_manager_->RemoveObserver(this); 384 download_manager_->RemoveObserver(this);
435 URLFetcher* fetch = fetch_.release();
436 if (fetch) {
437 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), currentpath_);
438 BrowserThread::PostTask(
439 BrowserThread::FILE, FROM_HERE,
440 NewRunnableMethod(
441 task.get(), &TaskProxy::DeleteFetcher, fetch));
442 }
443 } 385 }
444 386
445 WebUIMessageHandler* FilebrowseHandler::Attach(WebUI* web_ui) { 387 WebUIMessageHandler* FilebrowseHandler::Attach(WebUI* web_ui) {
446 // Create our favicon data source. 388 // Create our favicon data source.
447 profile_ = web_ui->GetProfile(); 389 profile_ = web_ui->GetProfile();
448 profile_->GetChromeURLDataManager()->AddDataSource( 390 profile_->GetChromeURLDataManager()->AddDataSource(
449 new FaviconSource(profile_)); 391 new FaviconSource(profile_));
450 tab_contents_ = web_ui->tab_contents(); 392 tab_contents_ = web_ui->tab_contents();
451 return WebUIMessageHandler::Attach(web_ui); 393 return WebUIMessageHandler::Attach(web_ui);
452 } 394 }
453 395
454 void FilebrowseHandler::Init() { 396 void FilebrowseHandler::Init() {
455 download_manager_ = profile_->GetDownloadManager(); 397 download_manager_ = profile_->GetDownloadManager();
456 download_manager_->AddObserver(this); 398 download_manager_->AddObserver(this);
457 static bool sent_request = false;
458 if (!sent_request &&
459 !chromeos::UserManager::Get()->logged_in_user().email().empty()) {
460 // If we have not sent a request before, we should do one in order to
461 // ensure that we have the correct cookies. This is for uploads.
462 scoped_refptr<TaskProxy> task =
463 new TaskProxy(AsWeakPtr(), currentpath_);
464 current_task_ = task;
465 BrowserThread::PostTask(
466 BrowserThread::FILE, FROM_HERE,
467 NewRunnableMethod(task.get(),
468 &TaskProxy::SendPicasawebRequestProxy,
469 profile_->GetRequestContext()));
470 sent_request = true;
471 }
472 } 399 }
473 400
474 void FilebrowseHandler::RegisterMessages() { 401 void FilebrowseHandler::RegisterMessages() {
475 web_ui_->RegisterMessageCallback("getRoots", 402 web_ui_->RegisterMessageCallback("getRoots",
476 NewCallback(this, &FilebrowseHandler::HandleGetRoots)); 403 NewCallback(this, &FilebrowseHandler::HandleGetRoots));
477 web_ui_->RegisterMessageCallback("getChildren", 404 web_ui_->RegisterMessageCallback("getChildren",
478 NewCallback(this, &FilebrowseHandler::HandleGetChildren)); 405 NewCallback(this, &FilebrowseHandler::HandleGetChildren));
479 web_ui_->RegisterMessageCallback("getMetadata", 406 web_ui_->RegisterMessageCallback("getMetadata",
480 NewCallback(this, &FilebrowseHandler::HandleGetMetadata)); 407 NewCallback(this, &FilebrowseHandler::HandleGetMetadata));
481 web_ui_->RegisterMessageCallback("openNewPopupWindow", 408 web_ui_->RegisterMessageCallback("openNewPopupWindow",
482 NewCallback(this, &FilebrowseHandler::OpenNewPopupWindow)); 409 NewCallback(this, &FilebrowseHandler::OpenNewPopupWindow));
483 web_ui_->RegisterMessageCallback("openNewFullWindow", 410 web_ui_->RegisterMessageCallback("openNewFullWindow",
484 NewCallback(this, &FilebrowseHandler::OpenNewFullWindow)); 411 NewCallback(this, &FilebrowseHandler::OpenNewFullWindow));
485 web_ui_->RegisterMessageCallback("uploadToPicasaweb",
486 NewCallback(this, &FilebrowseHandler::UploadToPicasaweb));
487 web_ui_->RegisterMessageCallback("getDownloads", 412 web_ui_->RegisterMessageCallback("getDownloads",
488 NewCallback(this, &FilebrowseHandler::HandleGetDownloads)); 413 NewCallback(this, &FilebrowseHandler::HandleGetDownloads));
489 web_ui_->RegisterMessageCallback("createNewFolder", 414 web_ui_->RegisterMessageCallback("createNewFolder",
490 NewCallback(this, &FilebrowseHandler::HandleCreateNewFolder)); 415 NewCallback(this, &FilebrowseHandler::HandleCreateNewFolder));
491 web_ui_->RegisterMessageCallback("playMediaFile", 416 web_ui_->RegisterMessageCallback("playMediaFile",
492 NewCallback(this, &FilebrowseHandler::PlayMediaFile)); 417 NewCallback(this, &FilebrowseHandler::PlayMediaFile));
493 web_ui_->RegisterMessageCallback("enqueueMediaFile", 418 web_ui_->RegisterMessageCallback("enqueueMediaFile",
494 NewCallback(this, &FilebrowseHandler::EnqueueMediaFile)); 419 NewCallback(this, &FilebrowseHandler::EnqueueMediaFile));
495 web_ui_->RegisterMessageCallback("pauseToggleDownload", 420 web_ui_->RegisterMessageCallback("pauseToggleDownload",
496 NewCallback(this, &FilebrowseHandler::HandlePauseToggleDownload)); 421 NewCallback(this, &FilebrowseHandler::HandlePauseToggleDownload));
(...skipping 20 matching lines...) Expand all
517 GetChildrenForPath(dir_path, true); 442 GetChildrenForPath(dir_path, true);
518 }; 443 };
519 444
520 void FilebrowseHandler::FireCopyComplete(const FilePath& src, 445 void FilebrowseHandler::FireCopyComplete(const FilePath& src,
521 const FilePath& dest) { 446 const FilePath& dest) {
522 // Notify the UI somehow. 447 // Notify the UI somehow.
523 FilePath dir_path = dest.DirName(); 448 FilePath dir_path = dest.DirName();
524 GetChildrenForPath(dir_path, true); 449 GetChildrenForPath(dir_path, true);
525 }; 450 };
526 451
527 void FilebrowseHandler::FireUploadComplete() {
528 #if defined(OS_CHROMEOS) 452 #if defined(OS_CHROMEOS)
529 DictionaryValue info_value; 453 void FilebrowseHandler::DiskChanged(chromeos::MountLibraryEventType event,
530 info_value.SetString("path", current_file_uploaded_); 454 const chromeos::MountLibrary::Disk* disk) {
531 455 if (event == chromeos::MOUNT_DISK_REMOVED ||
532 std::string username; 456 event == chromeos::MOUNT_DISK_CHANGED) {
533 chromeos::UserManager* user_man = chromeos::UserManager::Get();
534 username = user_man->logged_in_user().email();
535
536 if (username.empty()) {
537 LOG(ERROR) << "Unable to get username";
538 return;
539 }
540 int location = username.find_first_of('@', 0);
541 if (location <= 0) {
542 LOG(ERROR) << "Username not formatted correctly";
543 return;
544 }
545 username = username.erase(username.find_first_of('@', 0));
546 std::string picture_url = kPicasawebBaseUrl;
547 picture_url += username;
548 picture_url += kPicasawebDropBox;
549 info_value.SetString("url", picture_url);
550 info_value.SetInteger("status_code", upload_response_code_);
551 web_ui_->CallJavascriptFunction("uploadComplete", info_value);
552 #endif
553 }
554
555 #if defined(OS_CHROMEOS)
556 void FilebrowseHandler::MountChanged(chromeos::MountLibrary* obj,
557 chromeos::MountEventType evt,
558 const std::string& path) {
559 if (evt == chromeos::DISK_REMOVED ||
560 evt == chromeos::DISK_CHANGED) {
561 web_ui_->CallJavascriptFunction("rootsChanged"); 457 web_ui_->CallJavascriptFunction("rootsChanged");
562 } 458 }
563 } 459 }
460
461 void FilebrowseHandler::DeviceChanged(chromeos::MountLibraryEventType event,
462 const std::string& device_path) {
463 }
564 #endif 464 #endif
565 465
566 void FilebrowseHandler::OnURLFetchComplete(const URLFetcher* source,
567 const GURL& url,
568 const net::URLRequestStatus& status,
569 int response_code,
570 const ResponseCookies& cookies,
571 const std::string& data) {
572 upload_response_code_ = response_code;
573 VLOG(1) << "Response code: " << response_code;
574 VLOG(1) << "Request url: " << url;
575 if (StartsWithASCII(url.spec(), kPicasawebUserPrefix, true)) {
576 BrowserThread::PostTask(
577 BrowserThread::UI, FROM_HERE,
578 NewRunnableMethod(current_task_, &TaskProxy::FireUploadCompleteProxy));
579 }
580 fetch_.reset();
581 }
582
583 void FilebrowseHandler::HandleGetRoots(const ListValue* args) { 466 void FilebrowseHandler::HandleGetRoots(const ListValue* args) {
584 ListValue results_value; 467 ListValue results_value;
585 DictionaryValue info_value; 468 DictionaryValue info_value;
586 // TODO(dhg): add other entries, make this more general 469 // TODO(dhg): add other entries, make this more general
587 #if defined(OS_CHROMEOS) 470 #if defined(OS_CHROMEOS)
588 chromeos::MountLibrary* lib = 471 chromeos::MountLibrary* lib = chromeos::CrosLibrary::Get()->GetMountLibrary();
589 chromeos::CrosLibrary::Get()->GetMountLibrary(); 472 for (chromeos::MountLibrary::DiskMap::const_iterator iter =
590 const chromeos::MountLibrary::DiskVector& disks = lib->disks(); 473 lib->disks().begin();
591 474 iter != lib->disks().end();
592 for (size_t i = 0; i < disks.size(); ++i) { 475 ++iter) {
593 if (!disks[i].mount_path.empty()) { 476 const chromeos::MountLibrary::Disk* disk = iter->second;
477 if (!disk->mount_path().empty()) {
594 DictionaryValue* page_value = new DictionaryValue(); 478 DictionaryValue* page_value = new DictionaryValue();
595 page_value->SetString(kPropertyPath, disks[i].mount_path); 479 page_value->SetString(kPropertyPath, disk->mount_path());
596 FilePath currentpath(disks[i].mount_path); 480 FilePath currentpath(disk->mount_path());
597 std::string filename; 481 std::string filename;
598 filename = currentpath.BaseName().value(); 482 filename = currentpath.BaseName().value();
599 page_value->SetString(kPropertyTitle, filename); 483 page_value->SetString(kPropertyTitle, filename);
600 page_value->SetBoolean(kPropertyDirectory, true); 484 page_value->SetBoolean(kPropertyDirectory, true);
601 results_value.Append(page_value); 485 results_value.Append(page_value);
602 } 486 }
603 } 487 }
604 #else 488 #else
605 DictionaryValue* page_value = new DictionaryValue(); 489 DictionaryValue* page_value = new DictionaryValue();
606 page_value->SetString(kPropertyPath, "/media"); 490 page_value->SetString(kPropertyPath, "/media");
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 browser::Navigate(&params); 636 browser::Navigate(&params);
753 // TODO(beng): The following two calls should be automatic by Navigate(). 637 // TODO(beng): The following two calls should be automatic by Navigate().
754 if (popup) { 638 if (popup) {
755 // TODO(dhg): Remove these from being hardcoded. Allow javascript 639 // TODO(dhg): Remove these from being hardcoded. Allow javascript
756 // to specify. 640 // to specify.
757 params.browser->window()->SetBounds(gfx::Rect(0, 0, 400, 300)); 641 params.browser->window()->SetBounds(gfx::Rect(0, 0, 400, 300));
758 } 642 }
759 params.browser->window()->Show(); 643 params.browser->window()->Show();
760 } 644 }
761 645
762 void FilebrowseHandler::SendPicasawebRequest(
763 URLRequestContextGetter* request_context) {
764 #if defined(OS_CHROMEOS)
765 fetch_.reset(URLFetcher::Create(0,
766 GURL(kPicasawebBaseUrl),
767 URLFetcher::GET,
768 this));
769 fetch_->set_request_context(request_context);
770 fetch_->Start();
771 #endif
772 }
773
774 void FilebrowseHandler::ReadInFile() {
775 #if defined(OS_CHROMEOS)
776 // Get the users username
777 std::string username;
778 chromeos::UserManager* user_man = chromeos::UserManager::Get();
779 username = user_man->logged_in_user().email();
780
781 if (username.empty()) {
782 LOG(ERROR) << "Unable to get username";
783 return;
784 }
785 int location = username.find_first_of('@', 0);
786 if (location <= 0) {
787 LOG(ERROR) << "Username not formatted correctly";
788 return;
789 }
790 username = username.erase(username.find_first_of('@', 0));
791 std::string url = kPicasawebUserPrefix;
792 url += username;
793 url += kPicasawebDefault;
794
795 FilePath currentpath(current_file_uploaded_);
796 // Get the filename
797 std::string filename;
798 filename = currentpath.BaseName().value();
799 std::string filecontents;
800 if (!file_util::ReadFileToString(currentpath, &filecontents)) {
801 LOG(ERROR) << "Unable to read this file:" << currentpath.value();
802 return;
803 }
804 fetch_.reset(URLFetcher::Create(0,
805 GURL(url),
806 URLFetcher::POST,
807 this));
808 fetch_->set_upload_data("image/jpeg", filecontents);
809 // Set the filename on the server
810 std::string slug = "Slug: ";
811 slug += filename;
812 fetch_->set_extra_request_headers(slug);
813 fetch_->set_request_context(profile_->GetRequestContext());
814 fetch_->Start();
815 #endif
816 }
817
818 // This is just a prototype for allowing generic uploads to various sites
819 // TODO(dhg): Remove this and implement general upload.
820 void FilebrowseHandler::UploadToPicasaweb(const ListValue* args) {
821 #if defined(OS_CHROMEOS)
822 std::string search_string = UTF16ToUTF8(ExtractStringValue(args));
823 current_file_uploaded_ = search_string;
824 // ReadInFile();
825 FilePath current_path(search_string);
826 scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), current_path);
827 current_task_ = task;
828 BrowserThread::PostTask(
829 BrowserThread::FILE, FROM_HERE,
830 NewRunnableMethod(
831 task.get(), &TaskProxy::ReadInFileProxy));
832 #endif
833 }
834 646
835 void FilebrowseHandler::GetChildrenForPath(const FilePath& path, 647 void FilebrowseHandler::GetChildrenForPath(const FilePath& path,
836 bool is_refresh) { 648 bool is_refresh) {
837 if (path.empty()) 649 if (path.empty())
838 return; 650 return;
839 651
840 filelist_value_.reset(new ListValue()); 652 filelist_value_.reset(new ListValue());
841 currentpath_ = path; 653 currentpath_ = path;
842 654
843 if (lister_.get()) { 655 if (lister_.get()) {
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 } 1071 }
1260 } 1072 }
1261 1073
1262 return NULL; 1074 return NULL;
1263 } 1075 }
1264 1076
1265 const int FileBrowseUI::kPopupWidth = 250; 1077 const int FileBrowseUI::kPopupWidth = 250;
1266 const int FileBrowseUI::kPopupHeight = 300; 1078 const int FileBrowseUI::kPopupHeight = 300;
1267 const int FileBrowseUI::kSmallPopupWidth = 250; 1079 const int FileBrowseUI::kSmallPopupWidth = 250;
1268 const int FileBrowseUI::kSmallPopupHeight = 50; 1080 const int FileBrowseUI::kSmallPopupHeight = 50;
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_init.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698