[email protected] | 66620503 | 2010-10-21 20:56:58 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/dom_ui/filebrowse_ui.h" |
| 6 | |
| 7 | #include "app/l10n_util.h" |
| 8 | #include "app/resource_bundle.h" |
[email protected] | 2041cf34 | 2010-02-19 03:15:59 | [diff] [blame] | 9 | #include "base/callback.h" |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 10 | #include "base/command_line.h" |
[email protected] | 23ebd230 | 2010-11-04 16:23:20 | [diff] [blame] | 11 | #include "base/file_util.h" |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 12 | #include "base/logging.h" |
| 13 | #include "base/message_loop.h" |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 14 | #include "base/path_service.h" |
[email protected] | 5c4c740 | 2009-10-30 19:58:06 | [diff] [blame] | 15 | #include "base/singleton.h" |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 16 | #include "base/string_piece.h" |
| 17 | #include "base/string_util.h" |
| 18 | #include "base/thread.h" |
| 19 | #include "base/time.h" |
[email protected] | be1ce6a7 | 2010-08-03 14:35:22 | [diff] [blame] | 20 | #include "base/utf_string_conversions.h" |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 21 | #include "base/values.h" |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 22 | #include "base/weak_ptr.h" |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 23 | #include "chrome/browser/bookmarks/bookmark_model.h" |
[email protected] | facac153 | 2010-10-11 22:59:50 | [diff] [blame] | 24 | #include "chrome/browser/browser_thread.h" |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 25 | #include "chrome/browser/dom_ui/dom_ui_favicon_source.h" |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 26 | #include "chrome/browser/dom_ui/mediaplayer_ui.h" |
[email protected] | 7598661 | 2010-07-16 22:23:57 | [diff] [blame] | 27 | #include "chrome/browser/download/download_item.h" |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 28 | #include "chrome/browser/download/download_manager.h" |
| 29 | #include "chrome/browser/download/download_util.h" |
[email protected] | 1717246f | 2010-02-10 17:08:15 | [diff] [blame] | 30 | #include "chrome/browser/history/history_types.h" |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 31 | #include "chrome/browser/metrics/user_metrics.h" |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 32 | #include "chrome/browser/profile.h" |
[email protected] | 1717246f | 2010-02-10 17:08:15 | [diff] [blame] | 33 | #include "chrome/browser/tab_contents/tab_contents.h" |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 34 | #include "chrome/browser/tabs/tab_strip_model.h" |
[email protected] | 2ad4a90 | 2010-11-17 06:05:13 | [diff] [blame] | 35 | #include "chrome/browser/ui/browser.h" |
| 36 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | 339d6dd | 2010-11-12 00:41:58 | [diff] [blame] | 37 | #include "chrome/browser/ui/browser_navigator.h" |
[email protected] | 2ad4a90 | 2010-11-17 06:05:13 | [diff] [blame] | 38 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 39 | #include "chrome/common/chrome_paths.h" |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 40 | #include "chrome/common/chrome_switches.h" |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 41 | #include "chrome/common/jstemplate_builder.h" |
[email protected] | 68d2a05f | 2010-05-07 21:39:55 | [diff] [blame] | 42 | #include "chrome/common/net/url_fetcher.h" |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 43 | #include "chrome/common/time_format.h" |
| 44 | #include "chrome/common/url_constants.h" |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 45 | #include "grit/browser_resources.h" |
| 46 | #include "grit/chromium_strings.h" |
| 47 | #include "grit/generated_resources.h" |
| 48 | #include "grit/locale_settings.h" |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 49 | #include "net/base/escape.h" |
[email protected] | df53d2d | 2010-11-19 08:56:12 | [diff] [blame^] | 50 | #include "net/url_request/url_request_file_job.h" |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 51 | |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 52 | #if defined(OS_CHROMEOS) |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 53 | #include "chrome/browser/chromeos/cros/cros_library.h" |
[email protected] | 268b02f | 2010-02-04 21:07:15 | [diff] [blame] | 54 | #include "chrome/browser/chromeos/cros/mount_library.h" |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 55 | #include "chrome/browser/chromeos/login/user_manager.h" |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 56 | #endif |
| 57 | |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 58 | // Maximum number of search results to return in a given search. We should |
| 59 | // eventually remove this. |
| 60 | static const int kMaxSearchResults = 100; |
[email protected] | e4fbe8e | 2010-08-07 07:00:46 | [diff] [blame] | 61 | static const char kPropertyPath[] = "path"; |
| 62 | static const char kPropertyTitle[] = "title"; |
| 63 | static const char kPropertyDirectory[] = "isDirectory"; |
| 64 | static const char kPicasawebUserPrefix[] = |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 65 | "http://picasaweb.google.com/data/feed/api/user/"; |
[email protected] | e4fbe8e | 2010-08-07 07:00:46 | [diff] [blame] | 66 | static const char kPicasawebDefault[] = "/albumid/default"; |
| 67 | static const char kPicasawebDropBox[] = "/home"; |
| 68 | static const char kPicasawebBaseUrl[] = "http://picasaweb.google.com/"; |
| 69 | static const char kMediaPath[] = "/media"; |
| 70 | static const char kFilebrowseURLHash[] = "chrome://filebrowse#"; |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 71 | static const int kPopupLeft = 0; |
| 72 | static const int kPopupTop = 0; |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 73 | |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 74 | class FileBrowseUIHTMLSource : public ChromeURLDataManager::DataSource { |
| 75 | public: |
| 76 | FileBrowseUIHTMLSource(); |
| 77 | |
| 78 | // Called when the network layer has requested a resource underneath |
| 79 | // the path we registered. |
[email protected] | f09d9379 | 2009-11-17 00:10:36 | [diff] [blame] | 80 | virtual void StartDataRequest(const std::string& path, |
| 81 | bool is_off_the_record, |
| 82 | int request_id); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 83 | virtual std::string GetMimeType(const std::string&) const { |
| 84 | return "text/html"; |
| 85 | } |
| 86 | |
| 87 | private: |
[email protected] | 8de85a6 | 2009-11-06 08:32:17 | [diff] [blame] | 88 | ~FileBrowseUIHTMLSource() {} |
| 89 | |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 90 | DISALLOW_COPY_AND_ASSIGN(FileBrowseUIHTMLSource); |
| 91 | }; |
| 92 | |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 93 | class TaskProxy; |
| 94 | |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 95 | // The handler for Javascript messages related to the "filebrowse" view. |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 96 | class FilebrowseHandler : public net::DirectoryLister::DirectoryListerDelegate, |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 97 | public DOMMessageHandler, |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 98 | #if defined(OS_CHROMEOS) |
| 99 | public chromeos::MountLibrary::Observer, |
| 100 | #endif |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 101 | public base::SupportsWeakPtr<FilebrowseHandler>, |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 102 | public URLFetcher::Delegate, |
| 103 | public DownloadManager::Observer, |
| 104 | public DownloadItem::Observer { |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 105 | public: |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 106 | FilebrowseHandler(); |
| 107 | virtual ~FilebrowseHandler(); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 108 | |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 109 | // Init work after Attach. |
| 110 | void Init(); |
| 111 | |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 112 | // DirectoryLister::DirectoryListerDelegate methods: |
[email protected] | 9ee2c8d | 2010-08-21 23:25:22 | [diff] [blame] | 113 | virtual void OnListFile( |
| 114 | const net::DirectoryLister::DirectoryListerData& data); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 115 | virtual void OnListDone(int error); |
| 116 | |
| 117 | // DOMMessageHandler implementation. |
| 118 | virtual DOMMessageHandler* Attach(DOMUI* dom_ui); |
| 119 | virtual void RegisterMessages(); |
| 120 | |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 121 | #if defined(OS_CHROMEOS) |
| 122 | void MountChanged(chromeos::MountLibrary* obj, |
| 123 | chromeos::MountEventType evt, |
| 124 | const std::string& path); |
| 125 | #endif |
| 126 | |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 127 | // DownloadItem::Observer interface |
| 128 | virtual void OnDownloadUpdated(DownloadItem* download); |
| 129 | virtual void OnDownloadFileCompleted(DownloadItem* download) { } |
| 130 | virtual void OnDownloadOpened(DownloadItem* download) { } |
| 131 | |
| 132 | // DownloadManager::Observer interface |
| 133 | virtual void ModelChanged(); |
[email protected] | 82f37b0 | 2010-07-29 22:04:57 | [diff] [blame] | 134 | |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 135 | // Callback for the "getRoots" message. |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 136 | void HandleGetRoots(const ListValue* args); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 137 | |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 138 | void GetChildrenForPath(FilePath& path, bool is_refresh); |
| 139 | |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 140 | void OnURLFetchComplete(const URLFetcher* source, |
| 141 | const GURL& url, |
| 142 | const URLRequestStatus& status, |
| 143 | int response_code, |
| 144 | const ResponseCookies& cookies, |
| 145 | const std::string& data); |
| 146 | |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 147 | // Callback for the "getChildren" message. |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 148 | void HandleGetChildren(const ListValue* args); |
[email protected] | c4a530b | 2010-03-08 17:33:03 | [diff] [blame] | 149 | // Callback for the "refreshDirectory" message. |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 150 | void HandleRefreshDirectory(const ListValue* args); |
| 151 | void HandleIsAdvancedEnabled(const ListValue* args); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 152 | |
| 153 | // Callback for the "getMetadata" message. |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 154 | void HandleGetMetadata(const ListValue* args); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 155 | |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 156 | // Callback for the "openNewWindow" message. |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 157 | void OpenNewFullWindow(const ListValue* args); |
| 158 | void OpenNewPopupWindow(const ListValue* args); |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 159 | |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 160 | // Callback for the "uploadToPicasaweb" message. |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 161 | void UploadToPicasaweb(const ListValue* args); |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 162 | |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 163 | // Callback for the "getDownloads" message. |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 164 | void HandleGetDownloads(const ListValue* args); |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 165 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 166 | void HandleCreateNewFolder(const ListValue* args); |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 167 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 168 | void PlayMediaFile(const ListValue* args); |
| 169 | void EnqueueMediaFile(const ListValue* args); |
[email protected] | 17496bb | 2010-03-10 19:48:23 | [diff] [blame] | 170 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 171 | void HandleDeleteFile(const ListValue* args); |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 172 | void HandleCopyFile(const ListValue* value); |
| 173 | void CopyFile(const FilePath& src, const FilePath& dest); |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 174 | void DeleteFile(const FilePath& path); |
| 175 | void FireDeleteComplete(const FilePath& path); |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 176 | void FireCopyComplete(const FilePath& src, const FilePath& dest); |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 177 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 178 | void HandlePauseToggleDownload(const ListValue* args); |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 179 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 180 | void HandleCancelDownload(const ListValue* args); |
| 181 | void HandleAllowDownload(const ListValue* args); |
[email protected] | c4a530b | 2010-03-08 17:33:03 | [diff] [blame] | 182 | |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 183 | void ReadInFile(); |
| 184 | void FireUploadComplete(); |
| 185 | |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 186 | void SendPicasawebRequest(); |
[email protected] | 23ebd230 | 2010-11-04 16:23:20 | [diff] [blame] | 187 | |
| 188 | // Callback for the "validateSavePath" message. |
| 189 | void HandleValidateSavePath(const ListValue* args); |
| 190 | |
| 191 | // Validate a save path on file thread. |
| 192 | void ValidateSavePathOnFileThread(const FilePath& save_path); |
| 193 | |
| 194 | // Fire save path validation result to JS onValidatedSavePath. |
| 195 | void FireOnValidatedSavePathOnUIThread(bool valid, const FilePath& save_path); |
| 196 | |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 197 | private: |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 198 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 199 | void OpenNewWindow(const ListValue* args, bool popup); |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 200 | |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 201 | // Clear all download items and their observers. |
| 202 | void ClearDownloadItems(); |
| 203 | |
| 204 | // Send the current list of downloads to the page. |
| 205 | void SendCurrentDownloads(); |
| 206 | |
[email protected] | 377b4cc | 2010-05-18 17:25:19 | [diff] [blame] | 207 | void SendNewDownload(DownloadItem* download); |
| 208 | |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 209 | scoped_ptr<ListValue> filelist_value_; |
| 210 | FilePath currentpath_; |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 211 | Profile* profile_; |
[email protected] | 93a58bf7 | 2010-06-04 23:01:20 | [diff] [blame] | 212 | TabContents* tab_contents_; |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 213 | std::string current_file_contents_; |
| 214 | std::string current_file_uploaded_; |
| 215 | int upload_response_code_; |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 216 | TaskProxy* current_task_; |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 217 | scoped_refptr<net::DirectoryLister> lister_; |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 218 | bool is_refresh_; |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 219 | scoped_ptr<URLFetcher> fetch_; |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 220 | |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 221 | DownloadManager* download_manager_; |
| 222 | typedef std::vector<DownloadItem*> DownloadList; |
[email protected] | 377b4cc | 2010-05-18 17:25:19 | [diff] [blame] | 223 | DownloadList active_download_items_; |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 224 | DownloadList download_items_; |
[email protected] | 377b4cc | 2010-05-18 17:25:19 | [diff] [blame] | 225 | bool got_first_download_list_; |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 226 | DISALLOW_COPY_AND_ASSIGN(FilebrowseHandler); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 227 | }; |
| 228 | |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 229 | class TaskProxy : public base::RefCountedThreadSafe<TaskProxy> { |
| 230 | public: |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 231 | TaskProxy(const base::WeakPtr<FilebrowseHandler>& handler, |
| 232 | const FilePath& path, const FilePath& dest) |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 233 | : handler_(handler), |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 234 | src_(path), |
| 235 | dest_(dest) {} |
| 236 | TaskProxy(const base::WeakPtr<FilebrowseHandler>& handler, |
| 237 | const FilePath& path) |
| 238 | : handler_(handler), |
| 239 | src_(path) {} |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 240 | void ReadInFileProxy() { |
| 241 | if (handler_) { |
| 242 | handler_->ReadInFile(); |
| 243 | } |
| 244 | } |
[email protected] | 068a71f | 2010-05-11 22:35:48 | [diff] [blame] | 245 | void DeleteFetcher(URLFetcher* fetch) { |
| 246 | delete fetch; |
| 247 | } |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 248 | void SendPicasawebRequestProxy() { |
| 249 | if (handler_) { |
| 250 | handler_->SendPicasawebRequest(); |
| 251 | } |
| 252 | } |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 253 | void FireUploadCompleteProxy() { |
| 254 | if (handler_) { |
| 255 | handler_->FireUploadComplete(); |
| 256 | } |
| 257 | } |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 258 | |
| 259 | void DeleteFileProxy() { |
| 260 | if (handler_) { |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 261 | handler_->DeleteFile(src_); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | void CopyFileProxy() { |
| 266 | if (handler_) { |
| 267 | handler_->CopyFile(src_, dest_); |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | |
| 271 | void FireDeleteCompleteProxy() { |
| 272 | if (handler_) { |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 273 | handler_->FireDeleteComplete(src_); |
| 274 | } |
| 275 | } |
| 276 | void FireCopyCompleteProxy() { |
| 277 | if (handler_) { |
| 278 | handler_->FireCopyComplete(src_, dest_); |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 279 | } |
| 280 | } |
[email protected] | 23ebd230 | 2010-11-04 16:23:20 | [diff] [blame] | 281 | |
| 282 | void ValidateSavePathOnFileThread() { |
| 283 | if (handler_) |
| 284 | handler_->ValidateSavePathOnFileThread(src_); |
| 285 | } |
| 286 | void FireOnValidatedSavePathOnUIThread(bool valid, |
| 287 | const FilePath& save_path) { |
| 288 | if (handler_) |
| 289 | handler_->FireOnValidatedSavePathOnUIThread(valid, save_path); |
| 290 | } |
| 291 | |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 292 | private: |
| 293 | base::WeakPtr<FilebrowseHandler> handler_; |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 294 | FilePath src_; |
| 295 | FilePath dest_; |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 296 | friend class base::RefCountedThreadSafe<TaskProxy>; |
[email protected] | 068a71f | 2010-05-11 22:35:48 | [diff] [blame] | 297 | DISALLOW_COPY_AND_ASSIGN(TaskProxy); |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 298 | }; |
| 299 | |
| 300 | |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 301 | //////////////////////////////////////////////////////////////////////////////// |
| 302 | // |
| 303 | // FileBrowseHTMLSource |
| 304 | // |
| 305 | //////////////////////////////////////////////////////////////////////////////// |
| 306 | |
| 307 | FileBrowseUIHTMLSource::FileBrowseUIHTMLSource() |
| 308 | : DataSource(chrome::kChromeUIFileBrowseHost, MessageLoop::current()) { |
| 309 | } |
| 310 | |
| 311 | void FileBrowseUIHTMLSource::StartDataRequest(const std::string& path, |
[email protected] | e42ae9b | 2010-03-28 00:55:05 | [diff] [blame] | 312 | bool is_off_the_record, |
| 313 | int request_id) { |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 314 | DictionaryValue localized_strings; |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 315 | // TODO(dhg): Add stirings to localized strings, also add more strings |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 316 | // that are currently hardcoded. |
[email protected] | e4fbe8e | 2010-08-07 07:00:46 | [diff] [blame] | 317 | localized_strings.SetString("title", |
| 318 | l10n_util::GetStringUTF16(IDS_FILEBROWSER_TITLE)); |
| 319 | localized_strings.SetString("pause", |
| 320 | l10n_util::GetStringUTF16(IDS_FILEBROWSER_PAUSE)); |
| 321 | localized_strings.SetString("resume", |
| 322 | l10n_util::GetStringUTF16(IDS_FILEBROWSER_RESUME)); |
| 323 | localized_strings.SetString("scanning", |
| 324 | l10n_util::GetStringUTF16(IDS_FILEBROWSER_SCANNING)); |
| 325 | localized_strings.SetString("confirmdelete", |
| 326 | l10n_util::GetStringUTF16(IDS_FILEBROWSER_CONFIRM_DELETE)); |
| 327 | localized_strings.SetString("confirmyes", |
| 328 | l10n_util::GetStringUTF16(IDS_FILEBROWSER_CONFIRM_YES)); |
| 329 | localized_strings.SetString("confirmcancel", |
| 330 | l10n_util::GetStringUTF16(IDS_FILEBROWSER_CONFIRM_CANCEL)); |
| 331 | localized_strings.SetString("allowdownload", |
| 332 | l10n_util::GetStringUTF16(IDS_FILEBROWSER_CONFIRM_DOWNLOAD)); |
| 333 | localized_strings.SetString("filenameprompt", |
| 334 | l10n_util::GetStringUTF16(IDS_FILEBROWSER_PROMPT_FILENAME)); |
| 335 | localized_strings.SetString("save", |
| 336 | l10n_util::GetStringUTF16(IDS_FILEBROWSER_SAVE)); |
| 337 | localized_strings.SetString("newfolder", |
| 338 | l10n_util::GetStringUTF16(IDS_FILEBROWSER_NEW_FOLDER)); |
| 339 | localized_strings.SetString("open", |
| 340 | l10n_util::GetStringUTF16(IDS_FILEBROWSER_OPEN)); |
| 341 | localized_strings.SetString("picasaweb", |
| 342 | l10n_util::GetStringUTF16(IDS_FILEBROWSER_UPLOAD_PICASAWEB)); |
| 343 | localized_strings.SetString("flickr", |
| 344 | l10n_util::GetStringUTF16(IDS_FILEBROWSER_UPLOAD_FLICKR)); |
| 345 | localized_strings.SetString("email", |
| 346 | l10n_util::GetStringUTF16(IDS_FILEBROWSER_UPLOAD_EMAIL)); |
| 347 | localized_strings.SetString("delete", |
| 348 | l10n_util::GetStringUTF16(IDS_FILEBROWSER_DELETE)); |
| 349 | localized_strings.SetString("enqueue", |
| 350 | l10n_util::GetStringUTF16(IDS_FILEBROWSER_ENQUEUE)); |
| 351 | localized_strings.SetString("mediapath", kMediaPath); |
[email protected] | 88f03da0 | 2010-06-10 16:21:13 | [diff] [blame] | 352 | FilePath default_download_path; |
| 353 | if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, |
| 354 | &default_download_path)) { |
| 355 | NOTREACHED(); |
| 356 | } |
[email protected] | e4fbe8e | 2010-08-07 07:00:46 | [diff] [blame] | 357 | // TODO(viettrungluu): this is wrong -- FilePath's need not be Unicode. |
| 358 | localized_strings.SetString("downloadpath", default_download_path.value()); |
| 359 | localized_strings.SetString("error_unknown_file_type", |
| 360 | l10n_util::GetStringUTF16(IDS_FILEBROWSER_ERROR_UNKNOWN_FILE_TYPE)); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 361 | SetFontAndTextDirection(&localized_strings); |
| 362 | |
| 363 | static const base::StringPiece filebrowse_html( |
| 364 | ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 365 | IDR_FILEBROWSE_HTML)); |
| 366 | const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( |
| 367 | filebrowse_html, &localized_strings); |
| 368 | |
| 369 | scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); |
| 370 | html_bytes->data.resize(full_html.size()); |
| 371 | std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); |
| 372 | |
| 373 | SendResponse(request_id, html_bytes); |
| 374 | } |
| 375 | |
| 376 | //////////////////////////////////////////////////////////////////////////////// |
| 377 | // |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 378 | // FilebrowseHandler |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 379 | // |
| 380 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 381 | FilebrowseHandler::FilebrowseHandler() |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 382 | : profile_(NULL), |
[email protected] | 93a58bf7 | 2010-06-04 23:01:20 | [diff] [blame] | 383 | tab_contents_(NULL), |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 384 | is_refresh_(false), |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 385 | fetch_(NULL), |
[email protected] | 377b4cc | 2010-05-18 17:25:19 | [diff] [blame] | 386 | download_manager_(NULL), |
| 387 | got_first_download_list_(false) { |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 388 | lister_ = NULL; |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 389 | #if defined(OS_CHROMEOS) |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 390 | chromeos::MountLibrary* lib = |
| 391 | chromeos::CrosLibrary::Get()->GetMountLibrary(); |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 392 | lib->AddObserver(this); |
| 393 | #endif |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 394 | } |
| 395 | |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 396 | FilebrowseHandler::~FilebrowseHandler() { |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 397 | #if defined(OS_CHROMEOS) |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 398 | chromeos::MountLibrary* lib = |
| 399 | chromeos::CrosLibrary::Get()->GetMountLibrary(); |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 400 | lib->RemoveObserver(this); |
| 401 | #endif |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 402 | if (lister_.get()) { |
| 403 | lister_->Cancel(); |
| 404 | lister_->set_delegate(NULL); |
| 405 | } |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 406 | |
| 407 | ClearDownloadItems(); |
| 408 | download_manager_->RemoveObserver(this); |
[email protected] | 068a71f | 2010-05-11 22:35:48 | [diff] [blame] | 409 | URLFetcher* fetch = fetch_.release(); |
| 410 | if (fetch) { |
| 411 | TaskProxy* task = new TaskProxy(AsWeakPtr(), currentpath_); |
| 412 | task->AddRef(); |
[email protected] | 2dc383ce | 2010-10-09 03:54:00 | [diff] [blame] | 413 | BrowserThread::PostTask( |
| 414 | BrowserThread::FILE, FROM_HERE, |
[email protected] | 068a71f | 2010-05-11 22:35:48 | [diff] [blame] | 415 | NewRunnableMethod( |
| 416 | task, &TaskProxy::DeleteFetcher, fetch)); |
| 417 | } |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 418 | } |
| 419 | |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 420 | DOMMessageHandler* FilebrowseHandler::Attach(DOMUI* dom_ui) { |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 421 | // Create our favicon data source. |
[email protected] | 2dc383ce | 2010-10-09 03:54:00 | [diff] [blame] | 422 | BrowserThread::PostTask( |
| 423 | BrowserThread::IO, FROM_HERE, |
[email protected] | fae2079 | 2009-10-28 20:31:58 | [diff] [blame] | 424 | NewRunnableMethod( |
[email protected] | 576a4ca | 2009-11-05 01:41:09 | [diff] [blame] | 425 | Singleton<ChromeURLDataManager>::get(), |
[email protected] | fae2079 | 2009-10-28 20:31:58 | [diff] [blame] | 426 | &ChromeURLDataManager::AddDataSource, |
[email protected] | f8f8250 | 2009-11-20 23:14:23 | [diff] [blame] | 427 | make_scoped_refptr(new DOMUIFavIconSource(dom_ui->GetProfile())))); |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 428 | profile_ = dom_ui->GetProfile(); |
[email protected] | 93a58bf7 | 2010-06-04 23:01:20 | [diff] [blame] | 429 | tab_contents_ = dom_ui->tab_contents(); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 430 | return DOMMessageHandler::Attach(dom_ui); |
| 431 | } |
| 432 | |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 433 | void FilebrowseHandler::Init() { |
[email protected] | f7e9fd6 | 2010-09-28 15:45:06 | [diff] [blame] | 434 | download_manager_ = profile_->GetDownloadManager(); |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 435 | download_manager_->AddObserver(this); |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 436 | TaskProxy* task = new TaskProxy(AsWeakPtr(), currentpath_); |
| 437 | task->AddRef(); |
| 438 | current_task_ = task; |
| 439 | static bool sent_request = false; |
| 440 | if (!sent_request) { |
| 441 | // If we have not sent a request before, we should do one in order to |
| 442 | // ensure that we have the correct cookies. This is for uploads. |
[email protected] | 2dc383ce | 2010-10-09 03:54:00 | [diff] [blame] | 443 | BrowserThread::PostTask( |
| 444 | BrowserThread::FILE, FROM_HERE, |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 445 | NewRunnableMethod( |
| 446 | task, &TaskProxy::SendPicasawebRequestProxy)); |
| 447 | sent_request = true; |
| 448 | } |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 449 | } |
| 450 | |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 451 | void FilebrowseHandler::RegisterMessages() { |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 452 | dom_ui_->RegisterMessageCallback("getRoots", |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 453 | NewCallback(this, &FilebrowseHandler::HandleGetRoots)); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 454 | dom_ui_->RegisterMessageCallback("getChildren", |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 455 | NewCallback(this, &FilebrowseHandler::HandleGetChildren)); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 456 | dom_ui_->RegisterMessageCallback("getMetadata", |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 457 | NewCallback(this, &FilebrowseHandler::HandleGetMetadata)); |
| 458 | dom_ui_->RegisterMessageCallback("openNewPopupWindow", |
| 459 | NewCallback(this, &FilebrowseHandler::OpenNewPopupWindow)); |
| 460 | dom_ui_->RegisterMessageCallback("openNewFullWindow", |
| 461 | NewCallback(this, &FilebrowseHandler::OpenNewFullWindow)); |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 462 | dom_ui_->RegisterMessageCallback("uploadToPicasaweb", |
| 463 | NewCallback(this, &FilebrowseHandler::UploadToPicasaweb)); |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 464 | dom_ui_->RegisterMessageCallback("getDownloads", |
| 465 | NewCallback(this, &FilebrowseHandler::HandleGetDownloads)); |
| 466 | dom_ui_->RegisterMessageCallback("createNewFolder", |
| 467 | NewCallback(this, &FilebrowseHandler::HandleCreateNewFolder)); |
[email protected] | 17496bb | 2010-03-10 19:48:23 | [diff] [blame] | 468 | dom_ui_->RegisterMessageCallback("playMediaFile", |
| 469 | NewCallback(this, &FilebrowseHandler::PlayMediaFile)); |
[email protected] | 89a7e381 | 2010-06-02 19:38:07 | [diff] [blame] | 470 | dom_ui_->RegisterMessageCallback("enqueueMediaFile", |
| 471 | NewCallback(this, &FilebrowseHandler::EnqueueMediaFile)); |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 472 | dom_ui_->RegisterMessageCallback("pauseToggleDownload", |
| 473 | NewCallback(this, &FilebrowseHandler::HandlePauseToggleDownload)); |
| 474 | dom_ui_->RegisterMessageCallback("deleteFile", |
| 475 | NewCallback(this, &FilebrowseHandler::HandleDeleteFile)); |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 476 | dom_ui_->RegisterMessageCallback("copyFile", |
| 477 | NewCallback(this, &FilebrowseHandler::HandleCopyFile)); |
[email protected] | c4a530b | 2010-03-08 17:33:03 | [diff] [blame] | 478 | dom_ui_->RegisterMessageCallback("cancelDownload", |
| 479 | NewCallback(this, &FilebrowseHandler::HandleCancelDownload)); |
| 480 | dom_ui_->RegisterMessageCallback("allowDownload", |
| 481 | NewCallback(this, &FilebrowseHandler::HandleAllowDownload)); |
| 482 | dom_ui_->RegisterMessageCallback("refreshDirectory", |
| 483 | NewCallback(this, &FilebrowseHandler::HandleRefreshDirectory)); |
[email protected] | 6ba198f | 2010-07-02 20:32:05 | [diff] [blame] | 484 | dom_ui_->RegisterMessageCallback("isAdvancedEnabled", |
| 485 | NewCallback(this, &FilebrowseHandler::HandleIsAdvancedEnabled)); |
[email protected] | 23ebd230 | 2010-11-04 16:23:20 | [diff] [blame] | 486 | dom_ui_->RegisterMessageCallback("validateSavePath", |
| 487 | NewCallback(this, &FilebrowseHandler::HandleValidateSavePath)); |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 488 | } |
| 489 | |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 490 | |
| 491 | void FilebrowseHandler::FireDeleteComplete(const FilePath& path) { |
| 492 | // We notify the UI by telling it to refresh its contents. |
| 493 | FilePath dir_path = path.DirName(); |
| 494 | GetChildrenForPath(dir_path, true); |
| 495 | }; |
| 496 | |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 497 | void FilebrowseHandler::FireCopyComplete(const FilePath& src, |
| 498 | const FilePath& dest) { |
| 499 | // Notify the UI somehow. |
| 500 | FilePath dir_path = dest.DirName(); |
| 501 | GetChildrenForPath(dir_path, true); |
| 502 | }; |
| 503 | |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 504 | void FilebrowseHandler::FireUploadComplete() { |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 505 | #if defined(OS_CHROMEOS) |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 506 | DictionaryValue info_value; |
[email protected] | e4fbe8e | 2010-08-07 07:00:46 | [diff] [blame] | 507 | info_value.SetString("path", current_file_uploaded_); |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 508 | |
| 509 | std::string username; |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 510 | chromeos::UserManager* user_man = chromeos::UserManager::Get(); |
| 511 | username = user_man->logged_in_user().email(); |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 512 | |
| 513 | if (username.empty()) { |
| 514 | LOG(ERROR) << "Unable to get username"; |
| 515 | return; |
| 516 | } |
| 517 | int location = username.find_first_of('@',0); |
| 518 | if (location <= 0) { |
| 519 | LOG(ERROR) << "Username not formatted correctly"; |
| 520 | return; |
| 521 | } |
| 522 | username = username.erase(username.find_first_of('@',0)); |
[email protected] | e4fbe8e | 2010-08-07 07:00:46 | [diff] [blame] | 523 | std::string picture_url = kPicasawebBaseUrl; |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 524 | picture_url += username; |
| 525 | picture_url += kPicasawebDropBox; |
[email protected] | e4fbe8e | 2010-08-07 07:00:46 | [diff] [blame] | 526 | info_value.SetString("url", picture_url); |
| 527 | info_value.SetInteger("status_code", upload_response_code_); |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 528 | dom_ui_->CallJavascriptFunction(L"uploadComplete", info_value); |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 529 | #endif |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 530 | } |
| 531 | |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 532 | #if defined(OS_CHROMEOS) |
| 533 | void FilebrowseHandler::MountChanged(chromeos::MountLibrary* obj, |
| 534 | chromeos::MountEventType evt, |
| 535 | const std::string& path) { |
| 536 | if (evt == chromeos::DISK_REMOVED || |
| 537 | evt == chromeos::DISK_CHANGED) { |
| 538 | dom_ui_->CallJavascriptFunction(L"rootsChanged"); |
| 539 | } |
| 540 | } |
| 541 | #endif |
| 542 | |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 543 | void FilebrowseHandler::OnURLFetchComplete(const URLFetcher* source, |
| 544 | const GURL& url, |
| 545 | const URLRequestStatus& status, |
| 546 | int response_code, |
| 547 | const ResponseCookies& cookies, |
| 548 | const std::string& data) { |
| 549 | upload_response_code_ = response_code; |
[email protected] | 66620503 | 2010-10-21 20:56:58 | [diff] [blame] | 550 | VLOG(1) << "Response code: " << response_code; |
| 551 | VLOG(1) << "Request url: " << url; |
[email protected] | 068a71f | 2010-05-11 22:35:48 | [diff] [blame] | 552 | if (StartsWithASCII(url.spec(), kPicasawebUserPrefix, true)) { |
[email protected] | 2dc383ce | 2010-10-09 03:54:00 | [diff] [blame] | 553 | BrowserThread::PostTask( |
| 554 | BrowserThread::UI, FROM_HERE, |
[email protected] | 068a71f | 2010-05-11 22:35:48 | [diff] [blame] | 555 | NewRunnableMethod(current_task_, &TaskProxy::FireUploadCompleteProxy)); |
| 556 | } |
| 557 | fetch_.reset(); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 558 | } |
| 559 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 560 | void FilebrowseHandler::HandleGetRoots(const ListValue* args) { |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 561 | ListValue results_value; |
| 562 | DictionaryValue info_value; |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 563 | // TODO(dhg): add other entries, make this more general |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 564 | #if defined(OS_CHROMEOS) |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 565 | chromeos::MountLibrary* lib = |
| 566 | chromeos::CrosLibrary::Get()->GetMountLibrary(); |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 567 | const chromeos::MountLibrary::DiskVector& disks = lib->disks(); |
| 568 | |
| 569 | for (size_t i = 0; i < disks.size(); ++i) { |
| 570 | if (!disks[i].mount_path.empty()) { |
| 571 | DictionaryValue* page_value = new DictionaryValue(); |
| 572 | page_value->SetString(kPropertyPath, disks[i].mount_path); |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 573 | FilePath currentpath(disks[i].mount_path); |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 574 | std::string filename; |
| 575 | filename = currentpath.BaseName().value(); |
| 576 | page_value->SetString(kPropertyTitle, filename); |
| 577 | page_value->SetBoolean(kPropertyDirectory, true); |
| 578 | results_value.Append(page_value); |
| 579 | } |
| 580 | } |
| 581 | #else |
| 582 | DictionaryValue* page_value = new DictionaryValue(); |
| 583 | page_value->SetString(kPropertyPath, "/media"); |
| 584 | page_value->SetString(kPropertyTitle, "Removeable"); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 585 | page_value->SetBoolean(kPropertyDirectory, true); |
| 586 | |
| 587 | results_value.Append(page_value); |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 588 | #endif |
| 589 | FilePath default_download_path; |
| 590 | if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, |
| 591 | &default_download_path)) { |
| 592 | NOTREACHED(); |
| 593 | } |
| 594 | |
| 595 | DictionaryValue* download_value = new DictionaryValue(); |
| 596 | download_value->SetString(kPropertyPath, default_download_path.value()); |
| 597 | download_value->SetString(kPropertyTitle, "File Shelf"); |
| 598 | download_value->SetBoolean(kPropertyDirectory, true); |
| 599 | |
| 600 | results_value.Append(download_value); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 601 | |
[email protected] | e4fbe8e | 2010-08-07 07:00:46 | [diff] [blame] | 602 | info_value.SetString("functionCall", "getRoots"); |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 603 | info_value.SetString(kPropertyPath, ""); |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 604 | dom_ui_->CallJavascriptFunction(L"browseFileResult", |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 605 | info_value, results_value); |
| 606 | } |
| 607 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 608 | void FilebrowseHandler::HandleCreateNewFolder(const ListValue* args) { |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 609 | #if defined(OS_CHROMEOS) |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 610 | std::string path = WideToUTF8(ExtractStringValue(args)); |
| 611 | FilePath currentpath(path); |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 612 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 613 | if (!file_util::CreateDirectory(currentpath)) |
| 614 | LOG(ERROR) << "unable to create directory"; |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 615 | #endif |
| 616 | } |
| 617 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 618 | void FilebrowseHandler::PlayMediaFile(const ListValue* args) { |
[email protected] | 17496bb | 2010-03-10 19:48:23 | [diff] [blame] | 619 | #if defined(OS_CHROMEOS) |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 620 | std::string url = WideToUTF8(ExtractStringValue(args)); |
| 621 | GURL gurl(url); |
[email protected] | 17496bb | 2010-03-10 19:48:23 | [diff] [blame] | 622 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 623 | Browser* browser = Browser::GetBrowserForController( |
| 624 | &tab_contents_->controller(), NULL); |
| 625 | MediaPlayer* mediaplayer = MediaPlayer::Get(); |
| 626 | mediaplayer->ForcePlayMediaURL(gurl, browser); |
[email protected] | 89a7e381 | 2010-06-02 19:38:07 | [diff] [blame] | 627 | #endif |
| 628 | } |
| 629 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 630 | void FilebrowseHandler::EnqueueMediaFile(const ListValue* args) { |
[email protected] | 89a7e381 | 2010-06-02 19:38:07 | [diff] [blame] | 631 | #if defined(OS_CHROMEOS) |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 632 | std::string url = WideToUTF8(ExtractStringValue(args)); |
| 633 | GURL gurl(url); |
[email protected] | 89a7e381 | 2010-06-02 19:38:07 | [diff] [blame] | 634 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 635 | Browser* browser = Browser::GetBrowserForController( |
| 636 | &tab_contents_->controller(), NULL); |
| 637 | MediaPlayer* mediaplayer = MediaPlayer::Get(); |
| 638 | mediaplayer->EnqueueMediaURL(gurl, browser); |
[email protected] | 17496bb | 2010-03-10 19:48:23 | [diff] [blame] | 639 | #endif |
| 640 | } |
| 641 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 642 | void FilebrowseHandler::HandleIsAdvancedEnabled(const ListValue* args) { |
[email protected] | 6ba198f | 2010-07-02 20:32:05 | [diff] [blame] | 643 | #if defined(OS_CHROMEOS) |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 644 | bool is_enabled = CommandLine::ForCurrentProcess()->HasSwitch( |
| 645 | switches::kEnableAdvancedFileSystem); |
| 646 | bool mp_enabled = CommandLine::ForCurrentProcess()->HasSwitch( |
| 647 | switches::kEnableMediaPlayer); |
[email protected] | 6ba198f | 2010-07-02 20:32:05 | [diff] [blame] | 648 | DictionaryValue info_value; |
[email protected] | e4fbe8e | 2010-08-07 07:00:46 | [diff] [blame] | 649 | info_value.SetBoolean("enabled", is_enabled); |
| 650 | info_value.SetBoolean("mpEnabled", mp_enabled); |
[email protected] | 6ba198f | 2010-07-02 20:32:05 | [diff] [blame] | 651 | dom_ui_->CallJavascriptFunction(L"enabledResult", |
| 652 | info_value); |
[email protected] | f872b3e | 2010-08-13 16:26:10 | [diff] [blame] | 653 | |
[email protected] | 6ba198f | 2010-07-02 20:32:05 | [diff] [blame] | 654 | #endif |
| 655 | } |
[email protected] | c4a530b | 2010-03-08 17:33:03 | [diff] [blame] | 656 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 657 | void FilebrowseHandler::HandleRefreshDirectory(const ListValue* args) { |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 658 | #if defined(OS_CHROMEOS) |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 659 | std::string path = WideToUTF8(ExtractStringValue(args)); |
| 660 | FilePath currentpath(path); |
| 661 | GetChildrenForPath(currentpath, true); |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 662 | #endif |
| 663 | } |
| 664 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 665 | void FilebrowseHandler::HandlePauseToggleDownload(const ListValue* args) { |
[email protected] | c4a530b | 2010-03-08 17:33:03 | [diff] [blame] | 666 | #if defined(OS_CHROMEOS) |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 667 | int id; |
| 668 | ExtractIntegerValue(args, &id); |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 669 | if ((id - 1) >= (int)active_download_items_.size()) { |
| 670 | return; |
| 671 | } |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 672 | DownloadItem* item = active_download_items_[id]; |
| 673 | item->TogglePause(); |
[email protected] | c4a530b | 2010-03-08 17:33:03 | [diff] [blame] | 674 | #endif |
| 675 | } |
| 676 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 677 | void FilebrowseHandler::HandleAllowDownload(const ListValue* args) { |
[email protected] | c4a530b | 2010-03-08 17:33:03 | [diff] [blame] | 678 | #if defined(OS_CHROMEOS) |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 679 | int id; |
| 680 | ExtractIntegerValue(args, &id); |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 681 | if ((id - 1) >= (int)active_download_items_.size()) { |
| 682 | return; |
| 683 | } |
| 684 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 685 | DownloadItem* item = active_download_items_[id]; |
| 686 | download_manager_->DangerousDownloadValidated(item); |
[email protected] | c4a530b | 2010-03-08 17:33:03 | [diff] [blame] | 687 | #endif |
| 688 | } |
| 689 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 690 | void FilebrowseHandler::HandleCancelDownload(const ListValue* args) { |
| 691 | #if defined(OS_CHROMEOS) |
| 692 | int id; |
| 693 | ExtractIntegerValue(args, &id); |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 694 | if ((id - 1) >= (int)active_download_items_.size()) { |
| 695 | return; |
| 696 | } |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 697 | DownloadItem* item = active_download_items_[id]; |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 698 | FilePath path = item->full_path(); |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 699 | item->Cancel(true); |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 700 | FilePath dir_path = path.DirName(); |
| 701 | item->Remove(true); |
| 702 | GetChildrenForPath(dir_path, true); |
| 703 | #endif |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 704 | } |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 705 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 706 | void FilebrowseHandler::OpenNewFullWindow(const ListValue* args) { |
| 707 | OpenNewWindow(args, false); |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 708 | } |
| 709 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 710 | void FilebrowseHandler::OpenNewPopupWindow(const ListValue* args) { |
| 711 | OpenNewWindow(args, true); |
| 712 | } |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 713 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 714 | void FilebrowseHandler::OpenNewWindow(const ListValue* args, bool popup) { |
| 715 | std::string url = WideToUTF8(ExtractStringValue(args)); |
| 716 | Browser* browser = popup ? |
| 717 | Browser::CreateForType(Browser::TYPE_APP_PANEL, profile_) : |
| 718 | BrowserList::GetLastActive(); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 719 | browser::NavigateParams params(browser, GURL(url), PageTransition::LINK); |
| 720 | params.disposition = NEW_FOREGROUND_TAB; |
| 721 | browser::Navigate(¶ms); |
| 722 | // TODO(beng): The following two calls should be automatic by Navigate(). |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 723 | if (popup) { |
| 724 | // TODO(dhg): Remove these from being hardcoded. Allow javascript |
| 725 | // to specify. |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 726 | params.browser->window()->SetBounds(gfx::Rect(0, 0, 400, 300)); |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 727 | } |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 728 | params.browser->window()->Show(); |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 729 | } |
| 730 | |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 731 | void FilebrowseHandler::SendPicasawebRequest() { |
[email protected] | 068a71f | 2010-05-11 22:35:48 | [diff] [blame] | 732 | #if defined(OS_CHROMEOS) |
| 733 | chromeos::UserManager* user_man = chromeos::UserManager::Get(); |
| 734 | std::string username = user_man->logged_in_user().email(); |
| 735 | |
| 736 | if (username.empty()) { |
| 737 | LOG(ERROR) << "Unable to get username"; |
| 738 | return; |
| 739 | } |
| 740 | |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 741 | fetch_.reset(URLFetcher::Create(0, |
| 742 | GURL(kPicasawebBaseUrl), |
| 743 | URLFetcher::GET, |
[email protected] | 068a71f | 2010-05-11 22:35:48 | [diff] [blame] | 744 | this)); |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 745 | fetch_->set_request_context(profile_->GetRequestContext()); |
| 746 | fetch_->Start(); |
[email protected] | 068a71f | 2010-05-11 22:35:48 | [diff] [blame] | 747 | #endif |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 748 | } |
| 749 | |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 750 | void FilebrowseHandler::ReadInFile() { |
| 751 | #if defined(OS_CHROMEOS) |
| 752 | // Get the users username |
| 753 | std::string username; |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 754 | chromeos::UserManager* user_man = chromeos::UserManager::Get(); |
| 755 | username = user_man->logged_in_user().email(); |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 756 | |
| 757 | if (username.empty()) { |
| 758 | LOG(ERROR) << "Unable to get username"; |
| 759 | return; |
| 760 | } |
| 761 | int location = username.find_first_of('@',0); |
| 762 | if (location <= 0) { |
| 763 | LOG(ERROR) << "Username not formatted correctly"; |
| 764 | return; |
| 765 | } |
| 766 | username = username.erase(username.find_first_of('@',0)); |
| 767 | std::string url = kPicasawebUserPrefix; |
| 768 | url += username; |
| 769 | url += kPicasawebDefault; |
| 770 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 771 | FilePath currentpath(current_file_uploaded_); |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 772 | // Get the filename |
| 773 | std::string filename; |
| 774 | filename = currentpath.BaseName().value(); |
| 775 | std::string filecontents; |
| 776 | if (!file_util::ReadFileToString(currentpath, &filecontents)) { |
| 777 | LOG(ERROR) << "Unable to read this file:" << currentpath.value(); |
| 778 | return; |
| 779 | } |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 780 | fetch_.reset(URLFetcher::Create(0, |
| 781 | GURL(url), |
| 782 | URLFetcher::POST, |
| 783 | this)); |
| 784 | fetch_->set_upload_data("image/jpeg", filecontents); |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 785 | // Set the filename on the server |
| 786 | std::string slug = "Slug: "; |
| 787 | slug += filename; |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 788 | fetch_->set_extra_request_headers(slug); |
| 789 | fetch_->set_request_context(profile_->GetRequestContext()); |
| 790 | fetch_->Start(); |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 791 | #endif |
| 792 | } |
| 793 | |
| 794 | // This is just a prototype for allowing generic uploads to various sites |
| 795 | // TODO(dhg): Remove this and implement general upload. |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 796 | void FilebrowseHandler::UploadToPicasaweb(const ListValue* args) { |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 797 | #if defined(OS_CHROMEOS) |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 798 | std::string search_string = WideToUTF8(ExtractStringValue(args)); |
| 799 | current_file_uploaded_ = search_string; |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 800 | // ReadInFile(); |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 801 | FilePath current_path(search_string); |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 802 | TaskProxy* task = new TaskProxy(AsWeakPtr(), current_path); |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 803 | task->AddRef(); |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 804 | current_task_ = task; |
[email protected] | 2dc383ce | 2010-10-09 03:54:00 | [diff] [blame] | 805 | BrowserThread::PostTask( |
| 806 | BrowserThread::FILE, FROM_HERE, |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 807 | NewRunnableMethod( |
| 808 | task, &TaskProxy::ReadInFileProxy)); |
| 809 | #endif |
| 810 | } |
| 811 | |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 812 | void FilebrowseHandler::GetChildrenForPath(FilePath& path, bool is_refresh) { |
| 813 | filelist_value_.reset(new ListValue()); |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 814 | currentpath_ = path; |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 815 | |
| 816 | if (lister_.get()) { |
| 817 | lister_->Cancel(); |
| 818 | lister_->set_delegate(NULL); |
| 819 | lister_ = NULL; |
| 820 | } |
| 821 | |
| 822 | is_refresh_ = is_refresh; |
[email protected] | df53d2d | 2010-11-19 08:56:12 | [diff] [blame^] | 823 | |
| 824 | #if defined(OS_CHROMEOS) |
| 825 | // Don't allow listing files in inaccessible dirs. |
| 826 | if (URLRequestFileJob::AccessDisabled(path)) |
| 827 | return; |
| 828 | #endif // OS_CHROMEOS |
| 829 | |
[email protected] | f872b3e | 2010-08-13 16:26:10 | [diff] [blame] | 830 | FilePath default_download_path; |
| 831 | if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, |
| 832 | &default_download_path)) { |
| 833 | NOTREACHED(); |
| 834 | } |
| 835 | if (currentpath_ == default_download_path) { |
| 836 | lister_ = new net::DirectoryLister(currentpath_, |
[email protected] | 9ee2c8d | 2010-08-21 23:25:22 | [diff] [blame] | 837 | false, |
[email protected] | f872b3e | 2010-08-13 16:26:10 | [diff] [blame] | 838 | net::DirectoryLister::DATE, |
| 839 | this); |
| 840 | } else { |
| 841 | lister_ = new net::DirectoryLister(currentpath_, this); |
| 842 | } |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 843 | lister_->Start(); |
| 844 | } |
| 845 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 846 | void FilebrowseHandler::HandleGetChildren(const ListValue* args) { |
| 847 | #if defined(OS_CHROMEOS) |
| 848 | std::string path = WideToUTF8(ExtractStringValue(args)); |
| 849 | FilePath currentpath(path); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 850 | filelist_value_.reset(new ListValue()); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 851 | |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 852 | GetChildrenForPath(currentpath, false); |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 853 | #endif |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 854 | } |
| 855 | |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 856 | void FilebrowseHandler::OnListFile( |
[email protected] | 9ee2c8d | 2010-08-21 23:25:22 | [diff] [blame] | 857 | const net::DirectoryLister::DirectoryListerData& data) { |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 858 | #if defined(OS_WIN) |
[email protected] | 9ee2c8d | 2010-08-21 23:25:22 | [diff] [blame] | 859 | if (data.info.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) { |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 860 | return; |
| 861 | } |
| 862 | #elif defined(OS_POSIX) |
[email protected] | 9ee2c8d | 2010-08-21 23:25:22 | [diff] [blame] | 863 | if (data.info.filename[0] == '.') { |
[email protected] | 07046ab | 2010-01-20 21:42:44 | [diff] [blame] | 864 | return; |
| 865 | } |
| 866 | #endif |
| 867 | |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 868 | DictionaryValue* file_value = new DictionaryValue(); |
| 869 | |
| 870 | #if defined(OS_WIN) |
[email protected] | 9ee2c8d | 2010-08-21 23:25:22 | [diff] [blame] | 871 | int64 size = (static_cast<int64>(data.info.nFileSizeHigh) << 32) | |
| 872 | data.info.nFileSizeLow; |
| 873 | file_value->SetString(kPropertyTitle, data.info.cFileName); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 874 | file_value->SetString(kPropertyPath, |
[email protected] | 9ee2c8d | 2010-08-21 23:25:22 | [diff] [blame] | 875 | currentpath_.Append(data.info.cFileName).value()); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 876 | file_value->SetBoolean(kPropertyDirectory, |
[email protected] | 9ee2c8d | 2010-08-21 23:25:22 | [diff] [blame] | 877 | (data.info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? true : false); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 878 | #elif defined(OS_POSIX) |
[email protected] | 9ee2c8d | 2010-08-21 23:25:22 | [diff] [blame] | 879 | file_value->SetString(kPropertyTitle, data.info.filename); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 880 | file_value->SetString(kPropertyPath, |
[email protected] | 9ee2c8d | 2010-08-21 23:25:22 | [diff] [blame] | 881 | currentpath_.Append(data.info.filename).value()); |
| 882 | file_value->SetBoolean(kPropertyDirectory, S_ISDIR(data.info.stat.st_mode)); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 883 | #endif |
| 884 | filelist_value_->Append(file_value); |
| 885 | } |
| 886 | |
[email protected] | dcd23fe | 2009-11-12 20:21:18 | [diff] [blame] | 887 | void FilebrowseHandler::OnListDone(int error) { |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 888 | DictionaryValue info_value; |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 889 | if (is_refresh_) { |
[email protected] | e4fbe8e | 2010-08-07 07:00:46 | [diff] [blame] | 890 | info_value.SetString("functionCall", "refresh"); |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 891 | } else { |
[email protected] | e4fbe8e | 2010-08-07 07:00:46 | [diff] [blame] | 892 | info_value.SetString("functionCall", "getChildren"); |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 893 | } |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 894 | info_value.SetString(kPropertyPath, currentpath_.value()); |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 895 | dom_ui_->CallJavascriptFunction(L"browseFileResult", |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 896 | info_value, *(filelist_value_.get())); |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 897 | SendCurrentDownloads(); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 898 | } |
| 899 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 900 | void FilebrowseHandler::HandleGetMetadata(const ListValue* args) { |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 901 | } |
| 902 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 903 | void FilebrowseHandler::HandleGetDownloads(const ListValue* args) { |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 904 | ModelChanged(); |
| 905 | } |
| 906 | |
| 907 | void FilebrowseHandler::ModelChanged() { |
| 908 | ClearDownloadItems(); |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 909 | |
[email protected] | 0e2b59a | 2010-07-29 22:27:05 | [diff] [blame] | 910 | std::vector<DownloadItem*> downloads; |
| 911 | download_manager_->GetAllDownloads(FilePath(), &downloads); |
| 912 | |
[email protected] | 377b4cc | 2010-05-18 17:25:19 | [diff] [blame] | 913 | std::vector<DownloadItem*> new_downloads; |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 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); |
[email protected] | 377b4cc | 2010-05-18 17:25:19 | [diff] [blame] | 923 | active_download_items_.push_back(download); |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 924 | } |
[email protected] | 377b4cc | 2010-05-18 17:25:19 | [diff] [blame] | 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); |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 932 | } |
[email protected] | 377b4cc | 2010-05-18 17:25:19 | [diff] [blame] | 933 | download_items_.swap(new_downloads); |
| 934 | got_first_download_list_ = true; |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 935 | SendCurrentDownloads(); |
| 936 | } |
| 937 | |
[email protected] | 377b4cc | 2010-05-18 17:25:19 | [diff] [blame] | 938 | void FilebrowseHandler::SendNewDownload(DownloadItem* download) { |
| 939 | ListValue results_value; |
| 940 | results_value.Append(download_util::CreateDownloadItemValue(download, -1)); |
| 941 | dom_ui_->CallJavascriptFunction(L"newDownload", results_value); |
| 942 | } |
| 943 | |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 944 | void FilebrowseHandler::DeleteFile(const FilePath& path) { |
| 945 | if (!file_util::Delete(path, true)) { |
| 946 | LOG(ERROR) << "unable to delete directory"; |
| 947 | } |
[email protected] | 2dc383ce | 2010-10-09 03:54:00 | [diff] [blame] | 948 | BrowserThread::PostTask( |
| 949 | BrowserThread::UI, FROM_HERE, |
[email protected] | d52bb8a | 2010-05-10 21:05:35 | [diff] [blame] | 950 | NewRunnableMethod(current_task_, &TaskProxy::FireDeleteCompleteProxy)); |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 951 | } |
| 952 | |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 953 | void FilebrowseHandler::CopyFile(const FilePath& src, const FilePath& dest) { |
| 954 | if (file_util::DirectoryExists(src)) { |
| 955 | if (!file_util::CopyDirectory(src, dest, true)) { |
| 956 | LOG(ERROR) << "unable to copy directory:" << src.value(); |
| 957 | } |
| 958 | } else { |
| 959 | if (!file_util::CopyFile(src, dest)) { |
| 960 | LOG(ERROR) << "unable to copy file" << src.value(); |
| 961 | } |
| 962 | } |
[email protected] | 2dc383ce | 2010-10-09 03:54:00 | [diff] [blame] | 963 | BrowserThread::PostTask( |
| 964 | BrowserThread::UI, FROM_HERE, |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 965 | NewRunnableMethod(current_task_, &TaskProxy::FireCopyCompleteProxy)); |
| 966 | } |
| 967 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 968 | void FilebrowseHandler::HandleDeleteFile(const ListValue* args) { |
| 969 | #if defined(OS_CHROMEOS) |
| 970 | std::string path = WideToUTF8(ExtractStringValue(args)); |
| 971 | FilePath currentpath(path); |
[email protected] | df53d2d | 2010-11-19 08:56:12 | [diff] [blame^] | 972 | |
| 973 | // Don't allow file deletion in inaccessible dirs. |
| 974 | if (URLRequestFileJob::AccessDisabled(currentpath)) |
| 975 | return; |
| 976 | |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 977 | for (unsigned int x = 0; x < active_download_items_.size(); x++) { |
| 978 | FilePath item = active_download_items_[x]->full_path(); |
| 979 | if (item == currentpath) { |
| 980 | active_download_items_[x]->Cancel(true); |
| 981 | active_download_items_[x]->Remove(true); |
| 982 | FilePath dir_path = item.DirName(); |
| 983 | GetChildrenForPath(dir_path, true); |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 984 | return; |
| 985 | } |
| 986 | } |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 987 | TaskProxy* task = new TaskProxy(AsWeakPtr(), currentpath); |
| 988 | task->AddRef(); |
| 989 | current_task_ = task; |
[email protected] | 2dc383ce | 2010-10-09 03:54:00 | [diff] [blame] | 990 | BrowserThread::PostTask( |
| 991 | BrowserThread::FILE, FROM_HERE, |
[email protected] | 88942a2 | 2010-08-19 20:34:43 | [diff] [blame] | 992 | NewRunnableMethod( |
| 993 | task, &TaskProxy::DeleteFileProxy)); |
[email protected] | a67fa08e | 2010-02-12 20:43:55 | [diff] [blame] | 994 | #endif |
| 995 | } |
| 996 | |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 997 | void FilebrowseHandler::HandleCopyFile(const ListValue* value) { |
| 998 | #if defined(OS_CHROMEOS) |
| 999 | if (value && value->GetType() == Value::TYPE_LIST) { |
| 1000 | const ListValue* list_value = static_cast<const ListValue*>(value); |
| 1001 | std::string src; |
| 1002 | std::string dest; |
| 1003 | |
| 1004 | // Get path string. |
| 1005 | if (list_value->GetString(0, &src) && |
| 1006 | list_value->GetString(1, &dest)) { |
| 1007 | FilePath SrcPath = FilePath(src); |
| 1008 | FilePath DestPath = FilePath(dest); |
| 1009 | |
[email protected] | df53d2d | 2010-11-19 08:56:12 | [diff] [blame^] | 1010 | // Don't allow file copy to inaccessible dirs. |
| 1011 | if (URLRequestFileJob::AccessDisabled(DestPath)) |
| 1012 | return; |
| 1013 | |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 1014 | TaskProxy* task = new TaskProxy(AsWeakPtr(), SrcPath, DestPath); |
| 1015 | task->AddRef(); |
| 1016 | current_task_ = task; |
[email protected] | 2dc383ce | 2010-10-09 03:54:00 | [diff] [blame] | 1017 | BrowserThread::PostTask( |
| 1018 | BrowserThread::FILE, FROM_HERE, |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 1019 | NewRunnableMethod( |
| 1020 | task, &TaskProxy::CopyFileProxy)); |
| 1021 | } else { |
| 1022 | LOG(ERROR) << "Unable to get string"; |
| 1023 | return; |
| 1024 | } |
| 1025 | } |
| 1026 | #endif |
| 1027 | } |
| 1028 | |
[email protected] | 23ebd230 | 2010-11-04 16:23:20 | [diff] [blame] | 1029 | void FilebrowseHandler::HandleValidateSavePath(const ListValue* args) { |
| 1030 | std::string string_path; |
| 1031 | if (!args || !args->GetString(0, &string_path)) { |
| 1032 | FireOnValidatedSavePathOnUIThread(false, FilePath()); // Invalid save path. |
| 1033 | return; |
| 1034 | } |
| 1035 | |
| 1036 | FilePath save_path(string_path); |
| 1037 | |
| 1038 | #if defined(OS_CHROMEOS) |
| 1039 | scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), save_path); |
| 1040 | BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 1041 | NewRunnableMethod(task.get(), &TaskProxy::ValidateSavePathOnFileThread)); |
| 1042 | #else |
| 1043 | // No save path checking for non-ChromeOS platforms. |
| 1044 | FireOnValidatedSavePathOnUIThread(true, save_path); |
| 1045 | #endif |
| 1046 | } |
| 1047 | |
| 1048 | void FilebrowseHandler::ValidateSavePathOnFileThread( |
| 1049 | const FilePath& save_path) { |
| 1050 | #if defined(OS_CHROMEOS) |
| 1051 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 1052 | |
| 1053 | FilePath default_download_path; |
| 1054 | if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, |
| 1055 | &default_download_path)) { |
| 1056 | NOTREACHED(); |
| 1057 | } |
| 1058 | |
| 1059 | // Get containing folder of save_path. |
| 1060 | FilePath save_dir = save_path.DirName(); |
| 1061 | |
| 1062 | // Valid save path must be inside default download dir. |
| 1063 | bool valid = default_download_path == save_dir || |
| 1064 | file_util::ContainsPath(default_download_path, save_dir); |
| 1065 | |
| 1066 | scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr(), save_path); |
| 1067 | BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 1068 | NewRunnableMethod(task.get(), |
| 1069 | &TaskProxy::FireOnValidatedSavePathOnUIThread, |
| 1070 | valid, save_path)); |
| 1071 | #endif |
| 1072 | } |
| 1073 | |
| 1074 | void FilebrowseHandler::FireOnValidatedSavePathOnUIThread(bool valid, |
| 1075 | const FilePath& save_path) { |
| 1076 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1077 | |
| 1078 | FundamentalValue valid_value(valid); |
| 1079 | StringValue path_value(save_path.value()); |
| 1080 | dom_ui_->CallJavascriptFunction(L"onValidatedSavePath", |
| 1081 | valid_value, path_value); |
| 1082 | } |
[email protected] | d3d9b4fb | 2010-09-24 16:24:27 | [diff] [blame] | 1083 | |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 1084 | void FilebrowseHandler::OnDownloadUpdated(DownloadItem* download) { |
[email protected] | 377b4cc | 2010-05-18 17:25:19 | [diff] [blame] | 1085 | DownloadList::iterator it = find(active_download_items_.begin(), |
| 1086 | active_download_items_.end(), |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 1087 | download); |
[email protected] | 377b4cc | 2010-05-18 17:25:19 | [diff] [blame] | 1088 | if (it == active_download_items_.end()) |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 1089 | return; |
[email protected] | 377b4cc | 2010-05-18 17:25:19 | [diff] [blame] | 1090 | const int id = static_cast<int>(it - active_download_items_.begin()); |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 1091 | |
[email protected] | 499d97c | 2010-10-25 23:12:15 | [diff] [blame] | 1092 | scoped_ptr<DictionaryValue> download_item( |
| 1093 | download_util::CreateDownloadItemValue(download, id)); |
| 1094 | dom_ui_->CallJavascriptFunction(L"downloadUpdated", *download_item.get()); |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | void FilebrowseHandler::ClearDownloadItems() { |
[email protected] | 377b4cc | 2010-05-18 17:25:19 | [diff] [blame] | 1098 | for (DownloadList::iterator it = active_download_items_.begin(); |
| 1099 | it != active_download_items_.end(); ++it) { |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 1100 | (*it)->RemoveObserver(this); |
| 1101 | } |
[email protected] | 377b4cc | 2010-05-18 17:25:19 | [diff] [blame] | 1102 | active_download_items_.clear(); |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | void FilebrowseHandler::SendCurrentDownloads() { |
| 1106 | ListValue results_value; |
[email protected] | 377b4cc | 2010-05-18 17:25:19 | [diff] [blame] | 1107 | for (DownloadList::iterator it = active_download_items_.begin(); |
| 1108 | it != active_download_items_.end(); ++it) { |
| 1109 | int index = static_cast<int>(it - active_download_items_.begin()); |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 1110 | results_value.Append(download_util::CreateDownloadItemValue(*it, index)); |
| 1111 | } |
| 1112 | |
| 1113 | dom_ui_->CallJavascriptFunction(L"downloadsList", results_value); |
| 1114 | } |
| 1115 | |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 1116 | //////////////////////////////////////////////////////////////////////////////// |
| 1117 | // |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 1118 | // FileBrowseUI |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 1119 | // |
| 1120 | //////////////////////////////////////////////////////////////////////////////// |
| 1121 | |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 1122 | FileBrowseUI::FileBrowseUI(TabContents* contents) : HtmlDialogUI(contents) { |
[email protected] | 9d6b9aff | 2009-12-11 17:39:18 | [diff] [blame] | 1123 | FilebrowseHandler* handler = new FilebrowseHandler(); |
| 1124 | AddMessageHandler((handler)->Attach(this)); |
[email protected] | 274e42b | 2010-01-29 22:03:57 | [diff] [blame] | 1125 | handler->Init(); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 1126 | FileBrowseUIHTMLSource* html_source = new FileBrowseUIHTMLSource(); |
| 1127 | |
| 1128 | // Set up the chrome://filebrowse/ source. |
[email protected] | 2dc383ce | 2010-10-09 03:54:00 | [diff] [blame] | 1129 | BrowserThread::PostTask( |
| 1130 | BrowserThread::IO, FROM_HERE, |
[email protected] | fae2079 | 2009-10-28 20:31:58 | [diff] [blame] | 1131 | NewRunnableMethod( |
[email protected] | 576a4ca | 2009-11-05 01:41:09 | [diff] [blame] | 1132 | Singleton<ChromeURLDataManager>::get(), |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 1133 | &ChromeURLDataManager::AddDataSource, |
[email protected] | f8f8250 | 2009-11-20 23:14:23 | [diff] [blame] | 1134 | make_scoped_refptr(html_source))); |
[email protected] | 698601e | 2009-10-21 22:43:37 | [diff] [blame] | 1135 | } |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 1136 | |
| 1137 | // static |
[email protected] | 1717246f | 2010-02-10 17:08:15 | [diff] [blame] | 1138 | Browser* FileBrowseUI::OpenPopup(Profile* profile, |
[email protected] | 46729329 | 2010-04-16 19:41:56 | [diff] [blame] | 1139 | const std::string& hashArgument, |
| 1140 | int width, |
| 1141 | int height) { |
[email protected] | 1717246f | 2010-02-10 17:08:15 | [diff] [blame] | 1142 | // Get existing pop up for given hashArgument. |
[email protected] | f7e9fd6 | 2010-09-28 15:45:06 | [diff] [blame] | 1143 | Browser* browser = GetPopupForPath(hashArgument, profile); |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 1144 | |
[email protected] | 1717246f | 2010-02-10 17:08:15 | [diff] [blame] | 1145 | // Create new browser if no matching pop up found. |
| 1146 | if (browser == NULL) { |
[email protected] | 9ee17e8c | 2010-08-10 19:17:31 | [diff] [blame] | 1147 | browser = Browser::CreateForType(Browser::TYPE_APP_PANEL, profile); |
[email protected] | f59f116 | 2010-04-23 21:19:29 | [diff] [blame] | 1148 | std::string url; |
| 1149 | if (hashArgument.empty()) { |
| 1150 | url = chrome::kChromeUIFileBrowseURL; |
| 1151 | } else { |
| 1152 | url = kFilebrowseURLHash; |
| 1153 | url.append(hashArgument); |
| 1154 | } |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 1155 | |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1156 | browser::NavigateParams params(browser, GURL(url), PageTransition::LINK); |
| 1157 | params.disposition = NEW_FOREGROUND_TAB; |
| 1158 | browser::Navigate(¶ms); |
| 1159 | // TODO(beng): The following two calls should be automatic by Navigate(). |
| 1160 | params.browser->window()->SetBounds(gfx::Rect(kPopupLeft, |
| 1161 | kPopupTop, |
| 1162 | width, |
| 1163 | height)); |
[email protected] | 1717246f | 2010-02-10 17:08:15 | [diff] [blame] | 1164 | |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1165 | params.browser->window()->Show(); |
[email protected] | 9ee17e8c | 2010-08-10 19:17:31 | [diff] [blame] | 1166 | } else { |
| 1167 | browser->window()->Show(); |
[email protected] | 1717246f | 2010-02-10 17:08:15 | [diff] [blame] | 1168 | } |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 1169 | |
| 1170 | return browser; |
| 1171 | } |
[email protected] | 1717246f | 2010-02-10 17:08:15 | [diff] [blame] | 1172 | |
[email protected] | f7e9fd6 | 2010-09-28 15:45:06 | [diff] [blame] | 1173 | Browser* FileBrowseUI::GetPopupForPath(const std::string& path, |
| 1174 | Profile* profile) { |
[email protected] | 9ee17e8c | 2010-08-10 19:17:31 | [diff] [blame] | 1175 | std::string current_path = path; |
| 1176 | if (current_path.empty()) { |
[email protected] | ba816424 | 2010-11-16 21:31:00 | [diff] [blame] | 1177 | bool is_enabled = CommandLine::ForCurrentProcess()->HasSwitch( |
| 1178 | switches::kEnableAdvancedFileSystem); |
[email protected] | 9ee17e8c | 2010-08-10 19:17:31 | [diff] [blame] | 1179 | if (!is_enabled) { |
| 1180 | FilePath default_download_path; |
| 1181 | if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, |
| 1182 | &default_download_path)) { |
| 1183 | NOTREACHED(); |
| 1184 | } |
| 1185 | current_path = default_download_path.value(); |
| 1186 | } |
| 1187 | } |
| 1188 | |
[email protected] | 1717246f | 2010-02-10 17:08:15 | [diff] [blame] | 1189 | for (BrowserList::const_iterator it = BrowserList::begin(); |
| 1190 | it != BrowserList::end(); ++it) { |
[email protected] | 9ee17e8c | 2010-08-10 19:17:31 | [diff] [blame] | 1191 | if (((*it)->type() == Browser::TYPE_APP_PANEL)) { |
[email protected] | d519bed | 2010-05-28 18:42:03 | [diff] [blame] | 1192 | TabContents* tab_contents = (*it)->GetSelectedTabContents(); |
| 1193 | DCHECK(tab_contents); |
| 1194 | if (!tab_contents) |
| 1195 | continue; |
| 1196 | const GURL& url = tab_contents->GetURL(); |
[email protected] | 1717246f | 2010-02-10 17:08:15 | [diff] [blame] | 1197 | |
| 1198 | if (url.SchemeIs(chrome::kChromeUIScheme) && |
| 1199 | url.host() == chrome::kChromeUIFileBrowseHost && |
[email protected] | f7e9fd6 | 2010-09-28 15:45:06 | [diff] [blame] | 1200 | url.ref() == current_path && |
| 1201 | (*it)->profile() == profile) { |
[email protected] | 1717246f | 2010-02-10 17:08:15 | [diff] [blame] | 1202 | return (*it); |
| 1203 | } |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | return NULL; |
| 1208 | } |
[email protected] | 46729329 | 2010-04-16 19:41:56 | [diff] [blame] | 1209 | |
| 1210 | const int FileBrowseUI::kPopupWidth = 250; |
| 1211 | const int FileBrowseUI::kPopupHeight = 300; |
| 1212 | const int FileBrowseUI::kSmallPopupWidth = 250; |
| 1213 | const int FileBrowseUI::kSmallPopupHeight = 50; |