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