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/extensions/platform_app_launcher.h" | 5 #include "chrome/browser/extensions/platform_app_launcher.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 using extensions::app_file_handler_util::FileHandlerCanHandleFileWithMimeType; | 49 using extensions::app_file_handler_util::FileHandlerCanHandleFileWithMimeType; |
50 using extensions::app_file_handler_util::FirstFileHandlerForMimeType; | 50 using extensions::app_file_handler_util::FirstFileHandlerForMimeType; |
51 using extensions::app_file_handler_util::CreateFileEntry; | 51 using extensions::app_file_handler_util::CreateFileEntry; |
52 using extensions::app_file_handler_util::GrantedFileEntry; | 52 using extensions::app_file_handler_util::GrantedFileEntry; |
53 using extensions::app_file_handler_util::SavedFileEntry; | 53 using extensions::app_file_handler_util::SavedFileEntry; |
54 | 54 |
55 namespace extensions { | 55 namespace extensions { |
56 | 56 |
57 namespace { | 57 namespace { |
58 | 58 |
59 const char kFallbackMimeType[] = "application/octet-stream"; | |
60 | |
59 bool MakePathAbsolute(const base::FilePath& current_directory, | 61 bool MakePathAbsolute(const base::FilePath& current_directory, |
60 base::FilePath* file_path) { | 62 base::FilePath* file_path) { |
61 DCHECK(file_path); | 63 DCHECK(file_path); |
62 if (file_path->IsAbsolute()) | 64 if (file_path->IsAbsolute()) |
63 return true; | 65 return true; |
64 | 66 |
65 if (current_directory.empty()) { | 67 if (current_directory.empty()) { |
66 *file_path = base::MakeAbsoluteFilePath(*file_path); | 68 *file_path = base::MakeAbsoluteFilePath(*file_path); |
67 return !file_path->empty(); | 69 return !file_path->empty(); |
68 } | 70 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 // If the file doesn't exist, or is a directory, launch with no launch data. | 149 // If the file doesn't exist, or is a directory, launch with no launch data. |
148 if (!file_util::PathExists(file_path_) || | 150 if (!file_util::PathExists(file_path_) || |
149 file_util::DirectoryExists(file_path_)) { | 151 file_util::DirectoryExists(file_path_)) { |
150 LOG(WARNING) << "No file exists with path " << file_path_.value(); | 152 LOG(WARNING) << "No file exists with path " << file_path_.value(); |
151 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 153 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
152 &PlatformAppPathLauncher::LaunchWithNoLaunchData, this)); | 154 &PlatformAppPathLauncher::LaunchWithNoLaunchData, this)); |
153 return; | 155 return; |
154 } | 156 } |
155 | 157 |
156 std::string mime_type; | 158 std::string mime_type; |
157 // If we cannot obtain the MIME type, launch with no launch data. | |
158 if (!net::GetMimeTypeFromFile(file_path_, &mime_type)) { | 159 if (!net::GetMimeTypeFromFile(file_path_, &mime_type)) { |
koz (OOO until 15th September)
2013/04/16 04:56:18
nit: curlies are unnecessary now
Sam McNally
2013/04/16 05:17:33
Done.
| |
159 LOG(WARNING) << "Could not obtain MIME type for " | 160 mime_type.assign(kFallbackMimeType); |
koz (OOO until 15th September)
2013/04/16 04:56:18
Is this different to
mime_type = kFallbackMimeTyp
Sam McNally
2013/04/16 05:17:33
No. Changed to assignment as it's probably clearer
| |
160 << file_path_.value(); | |
161 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | |
162 &PlatformAppPathLauncher::LaunchWithNoLaunchData, this)); | |
163 return; | |
164 } | 161 } |
165 | 162 |
166 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 163 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
167 &PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type)); | 164 &PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type)); |
168 } | 165 } |
169 | 166 |
170 #if defined(OS_CHROMEOS) | 167 #if defined(OS_CHROMEOS) |
171 void GetMimeTypeAndLaunchForDriveFile() { | 168 void GetMimeTypeAndLaunchForDriveFile() { |
172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
173 | 170 |
174 drive::DriveSystemService* service = | 171 drive::DriveSystemService* service = |
175 drive::DriveSystemServiceFactory::FindForProfile(profile_); | 172 drive::DriveSystemServiceFactory::FindForProfile(profile_); |
176 if (!service) { | 173 if (!service) { |
177 LaunchWithNoLaunchData(); | 174 LaunchWithNoLaunchData(); |
178 return; | 175 return; |
179 } | 176 } |
180 | 177 |
181 service->file_system()->GetFileByPath( | 178 service->file_system()->GetFileByPath( |
182 drive::util::ExtractDrivePath(file_path_), | 179 drive::util::ExtractDrivePath(file_path_), |
183 base::Bind(&PlatformAppPathLauncher::OnGotDriveFile, this)); | 180 base::Bind(&PlatformAppPathLauncher::OnGotDriveFile, this)); |
184 } | 181 } |
185 | 182 |
186 void OnGotDriveFile(drive::DriveFileError error, | 183 void OnGotDriveFile(drive::DriveFileError error, |
187 const base::FilePath& file_path, | 184 const base::FilePath& file_path, |
188 const std::string& mime_type, | 185 const std::string& mime_type, |
189 drive::DriveFileType file_type) { | 186 drive::DriveFileType file_type) { |
190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
191 | 188 |
192 if (error != drive::DRIVE_FILE_OK || mime_type.empty() || | 189 if (error != drive::DRIVE_FILE_OK || file_type != drive::REGULAR_FILE) { |
193 file_type != drive::REGULAR_FILE) { | |
194 LaunchWithNoLaunchData(); | 190 LaunchWithNoLaunchData(); |
195 return; | 191 return; |
196 } | 192 } |
197 | 193 |
198 LaunchWithMimeType(mime_type); | 194 if (mime_type.empty()) { |
koz (OOO until 15th September)
2013/04/16 04:56:18
nit: remove curlies
Sam McNally
2013/04/16 05:17:33
Done.
| |
195 LaunchWithMimeType(kFallbackMimeType); | |
koz (OOO until 15th September)
2013/04/16 04:56:18
nit: I think
LaunchWithMimeType(mime_type.empty()
Sam McNally
2013/04/16 05:17:33
Done.
| |
196 } else { | |
197 LaunchWithMimeType(mime_type); | |
198 } | |
199 } | 199 } |
200 #endif // defined(OS_CHROMEOS) | 200 #endif // defined(OS_CHROMEOS) |
201 | 201 |
202 void LaunchWithNoLaunchData() { | 202 void LaunchWithNoLaunchData() { |
203 // This method is required as an entry point on the UI thread. | 203 // This method is required as an entry point on the UI thread. |
204 LaunchPlatformAppWithNoData(profile_, extension_); | 204 LaunchPlatformAppWithNoData(profile_, extension_); |
205 } | 205 } |
206 | 206 |
207 void LaunchWithMimeType(const std::string& mime_type) { | 207 void LaunchWithMimeType(const std::string& mime_type) { |
208 // Find file handler from the platform app for the file being opened. | 208 // Find file handler from the platform app for the file being opened. |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 void RestartPlatformAppWithFileEntries( | 419 void RestartPlatformAppWithFileEntries( |
420 Profile* profile, | 420 Profile* profile, |
421 const Extension* extension, | 421 const Extension* extension, |
422 const std::vector<SavedFileEntry>& file_entries) { | 422 const std::vector<SavedFileEntry>& file_entries) { |
423 scoped_refptr<SavedFileEntryLauncher> launcher = new SavedFileEntryLauncher( | 423 scoped_refptr<SavedFileEntryLauncher> launcher = new SavedFileEntryLauncher( |
424 profile, extension, file_entries); | 424 profile, extension, file_entries); |
425 launcher->Launch(); | 425 launcher->Launch(); |
426 } | 426 } |
427 | 427 |
428 } // namespace extensions | 428 } // namespace extensions |
OLD | NEW |