OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/file_manager/open_util.h" | 5 #include "chrome/browser/chromeos/file_manager/open_util.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 } | 120 } |
121 } | 121 } |
122 | 122 |
123 ExecuteFileTaskForUrl(profile, chosen_task->task_descriptor(), url); | 123 ExecuteFileTaskForUrl(profile, chosen_task->task_descriptor(), url); |
124 callback.Run(true); | 124 callback.Run(true); |
125 } | 125 } |
126 | 126 |
127 // Opens the file specified by |url| by finding and executing a file task for | 127 // Opens the file specified by |url| by finding and executing a file task for |
128 // the file. In case of success, calls |callback| with true. Otherwise the | 128 // the file. In case of success, calls |callback| with true. Otherwise the |
129 // returned value is false. | 129 // returned value is false. |
130 void OpenFile(Profile* profile, | 130 void OpenFileInternal(Profile* profile, |
131 const base::FilePath& path, | 131 const base::FilePath& path, |
132 const GURL& url, | 132 const GURL& url, |
133 const base::Callback<void(bool)>& callback) { | 133 const base::Callback<void(bool)>& callback) { |
134 extensions::app_file_handler_util::GetMimeTypeForLocalPath( | 134 extensions::app_file_handler_util::GetMimeTypeForLocalPath( |
135 profile, | 135 profile, |
136 path, | 136 path, |
137 base::Bind(&OpenFileWithMimeType, profile, path, url, callback)); | 137 base::Bind(&OpenFileWithMimeType, profile, path, url, callback)); |
138 } | 138 } |
139 | 139 |
140 // Called when execution of ContinueOpenItem() is completed. | 140 // Called when execution of ContinueOpenItem() is completed. |
141 void OnContinueOpenItemCompleted(Profile* profile, | 141 void OnContinueOpenFileCompleted(Profile* profile, |
142 const base::FilePath& file_path, | 142 const base::FilePath& file_path, |
143 bool result) { | 143 bool result) { |
144 if (!result) { | 144 if (!result) { |
145 int message; | 145 int message; |
146 if (file_path.Extension() == FILE_PATH_LITERAL(".dmg")) | 146 if (file_path.Extension() == FILE_PATH_LITERAL(".dmg")) |
147 message = IDS_FILE_BROWSER_ERROR_VIEWING_FILE_FOR_DMG; | 147 message = IDS_FILE_BROWSER_ERROR_VIEWING_FILE_FOR_DMG; |
148 else if (file_path.Extension() == FILE_PATH_LITERAL(".exe") || | 148 else if (file_path.Extension() == FILE_PATH_LITERAL(".exe") || |
149 file_path.Extension() == FILE_PATH_LITERAL(".msi")) | 149 file_path.Extension() == FILE_PATH_LITERAL(".msi")) |
150 message = IDS_FILE_BROWSER_ERROR_VIEWING_FILE_FOR_EXECUTABLE; | 150 message = IDS_FILE_BROWSER_ERROR_VIEWING_FILE_FOR_EXECUTABLE; |
151 else | 151 else |
152 message = IDS_FILE_BROWSER_ERROR_VIEWING_FILE; | 152 message = IDS_FILE_BROWSER_ERROR_VIEWING_FILE; |
153 ShowWarningMessageBox(profile, file_path, message); | 153 ShowWarningMessageBox(profile, file_path, message); |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 // Used to implement OpenItem(). | 157 void ContinueOpenFile(Profile* profile, |
158 void ContinueOpenItem(Profile* profile, | |
159 const base::FilePath& file_path, | 158 const base::FilePath& file_path, |
160 const GURL& url, | 159 const GURL& url, |
161 base::File::Error error) { | 160 base::File::Error folder_check_result) { |
162 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 161 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
163 | 162 |
164 if (error == base::File::FILE_OK) { | 163 if (folder_check_result == base::File::FILE_OK) { |
165 // A directory exists at |url|. Open it with the file manager. | 164 OnContinueOpenFileCompleted(profile, file_path, false); |
166 OpenFileManagerWithInternalActionId(profile, url, "open"); | 165 return; |
167 } else { | |
168 // |url| should be a file. Open it. | |
169 OpenFile(profile, | |
170 file_path, | |
171 url, | |
172 base::Bind(&OnContinueOpenItemCompleted, profile, file_path)); | |
173 } | 166 } |
167 OpenFileInternal( | |
168 profile, | |
169 file_path, | |
170 url, | |
171 base::Bind(&OnContinueOpenFileCompleted, profile, file_path)); | |
172 } | |
173 | |
174 void ContinueOpenFolder(Profile* profile, | |
175 const GURL& url, | |
176 base::File::Error folder_check_result) { | |
177 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
178 if (folder_check_result != base::File::FILE_OK) | |
179 return; | |
180 OpenFileManagerWithInternalActionId(profile, url, "open"); | |
hashimoto
2014/09/26 06:12:43
Sorry, I should have noticed this before.
Does thi
hashimoto
2014/09/26 06:37:20
hirono@ said OpenFileManagerWithInternalActionId()
asanka
2014/09/26 19:35:41
Thanks! Done.
| |
174 } | 181 } |
175 | 182 |
176 // Converts the |given_path| passed from external callers to the form that the | 183 // Converts the |given_path| passed from external callers to the form that the |
177 // file manager can correctly handle. It first migrates old Drive/Download | 184 // file manager can correctly handle. It first migrates old Drive/Download |
178 // folder path to the new formats, and then converts path to filesystem URL. | 185 // folder path to the new formats, and then converts path to filesystem URL. |
179 // | 186 // |
180 // When conversion fails, it shows a warning dialog UI and returns false. | 187 // When conversion fails, it shows a warning dialog UI and returns false. |
181 bool ConvertPath(Profile* profile, | 188 bool ConvertPath(Profile* profile, |
182 const base::FilePath& given_path, | 189 const base::FilePath& given_path, |
183 base::FilePath* path, | 190 base::FilePath* path, |
(...skipping 19 matching lines...) Expand all Loading... | |
203 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 210 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
204 | 211 |
205 base::FilePath converted_path; | 212 base::FilePath converted_path; |
206 GURL url; | 213 GURL url; |
207 if (!ConvertPath(profile, file_path, &converted_path, &url)) | 214 if (!ConvertPath(profile, file_path, &converted_path, &url)) |
208 return; | 215 return; |
209 | 216 |
210 OpenFileManagerWithInternalActionId(profile, url, "auto-open"); | 217 OpenFileManagerWithInternalActionId(profile, url, "auto-open"); |
211 } | 218 } |
212 | 219 |
213 void OpenItem(Profile* profile, const base::FilePath& file_path) { | 220 void OpenFile(Profile* profile, const base::FilePath& file_path) { |
214 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 221 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
215 | 222 |
216 base::FilePath converted_path; | 223 base::FilePath converted_path; |
224 GURL url; | |
225 if (!ConvertPath(profile, file_path, &converted_path, &url)) | |
226 return; | |
227 | |
228 CheckIfDirectoryExists( | |
229 GetFileSystemContextForExtensionId(profile, kFileManagerAppId), | |
230 url, | |
231 base::Bind(&ContinueOpenFile, profile, converted_path, url)); | |
232 } | |
233 | |
234 void OpenFolder(Profile* profile, const base::FilePath& file_path) { | |
235 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
236 | |
237 base::FilePath converted_path; | |
217 GURL url; | 238 GURL url; |
218 if (!ConvertPath(profile, file_path, &converted_path, &url)) | 239 if (!ConvertPath(profile, file_path, &converted_path, &url)) |
219 return; | 240 return; |
220 | 241 |
221 CheckIfDirectoryExists( | 242 CheckIfDirectoryExists( |
222 GetFileSystemContextForExtensionId(profile, kFileManagerAppId), | 243 GetFileSystemContextForExtensionId(profile, kFileManagerAppId), |
223 url, | 244 url, |
224 base::Bind(&ContinueOpenItem, profile, converted_path, url)); | 245 base::Bind(&ContinueOpenFolder, profile, url)); |
225 } | 246 } |
226 | 247 |
227 void ShowItemInFolder(Profile* profile, const base::FilePath& file_path) { | 248 void ShowItemInFolder(Profile* profile, const base::FilePath& file_path) { |
228 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 249 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
229 | 250 |
230 base::FilePath converted_path; | 251 base::FilePath converted_path; |
231 GURL url; | 252 GURL url; |
232 if (!ConvertPath(profile, file_path, &converted_path, &url)) | 253 if (!ConvertPath(profile, file_path, &converted_path, &url)) |
233 return; | 254 return; |
234 | 255 |
235 // This action changes the selection so we do not reuse existing tabs. | 256 // This action changes the selection so we do not reuse existing tabs. |
236 OpenFileManagerWithInternalActionId(profile, url, "select"); | 257 OpenFileManagerWithInternalActionId(profile, url, "select"); |
237 } | 258 } |
238 | 259 |
239 } // namespace util | 260 } // namespace util |
240 } // namespace file_manager | 261 } // namespace file_manager |
OLD | NEW |