OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "apps/launcher.h" | 5 #include "apps/launcher.h" |
6 | 6 |
7 #include "apps/browser/api/app_runtime/app_runtime_api.h" | 7 #include "apps/browser/api/app_runtime/app_runtime_api.h" |
8 #include "apps/browser/file_handler_util.h" | 8 #include "apps/browser/file_handler_util.h" |
9 #include "apps/common/api/app_runtime.h" | 9 #include "apps/common/api/app_runtime.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 #include "extensions/common/extension.h" | 31 #include "extensions/common/extension.h" |
32 #include "extensions/common/extension_messages.h" | 32 #include "extensions/common/extension_messages.h" |
33 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" | 33 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" |
34 #include "net/base/filename_util.h" | 34 #include "net/base/filename_util.h" |
35 #include "net/base/mime_sniffer.h" | 35 #include "net/base/mime_sniffer.h" |
36 #include "net/base/mime_util.h" | 36 #include "net/base/mime_util.h" |
37 #include "net/base/net_util.h" | 37 #include "net/base/net_util.h" |
38 #include "url/gurl.h" | 38 #include "url/gurl.h" |
39 | 39 |
40 #if defined(OS_CHROMEOS) | 40 #if defined(OS_CHROMEOS) |
41 #include "chrome/browser/chromeos/drive/file_errors.h" | 41 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" |
42 #include "chrome/browser/chromeos/drive/file_system_interface.h" | |
43 #include "chrome/browser/chromeos/drive/file_system_util.h" | |
44 #include "chrome/browser/chromeos/login/users/user_manager.h" | 42 #include "chrome/browser/chromeos/login/users/user_manager.h" |
45 #endif | 43 #endif |
46 | 44 |
47 namespace app_runtime = apps::api::app_runtime; | 45 namespace app_runtime = apps::api::app_runtime; |
48 | 46 |
49 using apps::file_handler_util::GrantedFileEntry; | 47 using apps::file_handler_util::GrantedFileEntry; |
50 using content::BrowserThread; | 48 using content::BrowserThread; |
51 using extensions::app_file_handler_util::CheckWritableFiles; | 49 using extensions::app_file_handler_util::CheckWritableFiles; |
52 using extensions::app_file_handler_util::FileHandlerForId; | 50 using extensions::app_file_handler_util::FileHandlerForId; |
53 using extensions::app_file_handler_util::FileHandlerCanHandleFile; | 51 using extensions::app_file_handler_util::FileHandlerCanHandleFile; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 file_path_ = base::FilePath(); | 153 file_path_ = base::FilePath(); |
156 } | 154 } |
157 | 155 |
158 BrowserThread::PostTask(BrowserThread::UI, | 156 BrowserThread::PostTask(BrowserThread::UI, |
159 FROM_HERE, | 157 FROM_HERE, |
160 base::Bind(&PlatformAppPathLauncher::Launch, this)); | 158 base::Bind(&PlatformAppPathLauncher::Launch, this)); |
161 } | 159 } |
162 | 160 |
163 void OnFileValid() { | 161 void OnFileValid() { |
164 #if defined(OS_CHROMEOS) | 162 #if defined(OS_CHROMEOS) |
165 if (drive::util::IsUnderDriveMountPoint(file_path_)) { | 163 if (file_manager::util::IsUnderSpecialPath(profile_, file_path_)) { |
166 PlatformAppPathLauncher::GetMimeTypeAndLaunchForDriveFile(); | 164 file_manager::util::GetSpecialPathMimeType( |
165 profile_, | |
166 file_path_, | |
167 base::Bind(&PlatformAppPathLauncher::OnGotMimeType, this)); | |
167 return; | 168 return; |
168 } | 169 } |
169 #endif | 170 #endif |
170 | 171 |
171 BrowserThread::PostTask( | 172 BrowserThread::PostTask( |
172 BrowserThread::FILE, | 173 BrowserThread::FILE, |
173 FROM_HERE, | 174 FROM_HERE, |
174 base::Bind(&PlatformAppPathLauncher::GetMimeTypeAndLaunch, this)); | 175 base::Bind(&PlatformAppPathLauncher::GetMimeTypeAndLaunch, this)); |
175 } | 176 } |
176 | 177 |
(...skipping 27 matching lines...) Expand all Loading... | |
204 &mime_type); | 205 &mime_type); |
205 } | 206 } |
206 if (mime_type.empty()) | 207 if (mime_type.empty()) |
207 mime_type = kFallbackMimeType; | 208 mime_type = kFallbackMimeType; |
208 } | 209 } |
209 | 210 |
210 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 211 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
211 &PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type)); | 212 &PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type)); |
212 } | 213 } |
213 | 214 |
214 #if defined(OS_CHROMEOS) | 215 void OnGotMimeType(bool success, const std::string& mime_type) { |
mtomasz
2014/05/26 05:54:15
nit: In app_file_handler_util.cc, chromeos-only me
benwells
2014/05/27 03:21:20
Let's #if it out.
kinaba
2014/05/27 05:39:28
Done.
| |
215 void GetMimeTypeAndLaunchForDriveFile() { | 216 if (!success) { |
216 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
217 | |
218 drive::FileSystemInterface* file_system = | |
219 drive::util::GetFileSystemByProfile(profile_); | |
220 if (!file_system) { | |
221 LaunchWithNoLaunchData(); | 217 LaunchWithNoLaunchData(); |
222 return; | 218 return; |
223 } | 219 } |
224 | |
225 file_system->GetFile( | |
226 drive::util::ExtractDrivePath(file_path_), | |
227 base::Bind(&PlatformAppPathLauncher::OnGotDriveFile, this)); | |
228 } | |
229 | |
230 void OnGotDriveFile(drive::FileError error, | |
231 const base::FilePath& file_path, | |
232 scoped_ptr<drive::ResourceEntry> entry) { | |
233 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
234 | |
235 if (error != drive::FILE_ERROR_OK || | |
236 !entry || entry->file_specific_info().is_hosted_document()) { | |
237 LaunchWithNoLaunchData(); | |
238 return; | |
239 } | |
240 | |
241 const std::string& mime_type = | |
242 entry->file_specific_info().content_mime_type(); | |
243 LaunchWithMimeType(mime_type.empty() ? kFallbackMimeType : mime_type); | 220 LaunchWithMimeType(mime_type.empty() ? kFallbackMimeType : mime_type); |
244 } | 221 } |
245 #endif // defined(OS_CHROMEOS) | |
246 | 222 |
247 void LaunchWithNoLaunchData() { | 223 void LaunchWithNoLaunchData() { |
248 // This method is required as an entry point on the UI thread. | 224 // This method is required as an entry point on the UI thread. |
249 LaunchPlatformAppWithNoData(profile_, extension_); | 225 LaunchPlatformAppWithNoData(profile_, extension_); |
250 } | 226 } |
251 | 227 |
252 void LaunchWithMimeType(const std::string& mime_type) { | 228 void LaunchWithMimeType(const std::string& mime_type) { |
253 // Find file handler from the platform app for the file being opened. | 229 // Find file handler from the platform app for the file being opened. |
254 const extensions::FileHandlerInfo* handler = NULL; | 230 const extensions::FileHandlerInfo* handler = NULL; |
255 if (!handler_id_.empty()) | 231 if (!handler_id_.empty()) |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 void LaunchPlatformAppWithUrl(Profile* profile, | 402 void LaunchPlatformAppWithUrl(Profile* profile, |
427 const Extension* extension, | 403 const Extension* extension, |
428 const std::string& handler_id, | 404 const std::string& handler_id, |
429 const GURL& url, | 405 const GURL& url, |
430 const GURL& referrer_url) { | 406 const GURL& referrer_url) { |
431 AppEventRouter::DispatchOnLaunchedEventWithUrl( | 407 AppEventRouter::DispatchOnLaunchedEventWithUrl( |
432 profile, extension, handler_id, url, referrer_url); | 408 profile, extension, handler_id, url, referrer_url); |
433 } | 409 } |
434 | 410 |
435 } // namespace apps | 411 } // namespace apps |
OLD | NEW |