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 14 matching lines...) Expand all Loading... |
25 #include "chrome/common/extensions/extension_messages.h" | 25 #include "chrome/common/extensions/extension_messages.h" |
26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/child_process_security_policy.h" | 27 #include "content/public/browser/child_process_security_policy.h" |
28 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
30 #include "net/base/mime_util.h" | 30 #include "net/base/mime_util.h" |
31 #include "net/base/net_util.h" | 31 #include "net/base/net_util.h" |
32 #include "webkit/fileapi/file_system_types.h" | 32 #include "webkit/fileapi/file_system_types.h" |
33 #include "webkit/fileapi/isolated_context.h" | 33 #include "webkit/fileapi/isolated_context.h" |
34 | 34 |
| 35 #if defined(OS_CHROMEOS) |
| 36 #include "chrome/browser/chromeos/drive/drive_file_error.h" |
| 37 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" |
| 38 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" |
| 39 #include "chrome/browser/chromeos/drive/drive_system_service.h" |
| 40 #endif |
| 41 |
35 using content::BrowserThread; | 42 using content::BrowserThread; |
36 using extensions::app_file_handler_util::FileHandlerForId; | 43 using extensions::app_file_handler_util::FileHandlerForId; |
37 using extensions::app_file_handler_util::FileHandlerCanHandleFileWithMimeType; | 44 using extensions::app_file_handler_util::FileHandlerCanHandleFileWithMimeType; |
38 using extensions::app_file_handler_util::FirstFileHandlerForMimeType; | 45 using extensions::app_file_handler_util::FirstFileHandlerForMimeType; |
39 using extensions::app_file_handler_util::CreateFileEntry; | 46 using extensions::app_file_handler_util::CreateFileEntry; |
40 using extensions::app_file_handler_util::GrantedFileEntry; | 47 using extensions::app_file_handler_util::GrantedFileEntry; |
41 using extensions::app_file_handler_util::SavedFileEntry; | 48 using extensions::app_file_handler_util::SavedFileEntry; |
42 | 49 |
43 namespace extensions { | 50 namespace extensions { |
44 | 51 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 handler_id_("") {} | 108 handler_id_("") {} |
102 | 109 |
103 void Launch() { | 110 void Launch() { |
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
105 if (file_path_.empty()) { | 112 if (file_path_.empty()) { |
106 LaunchPlatformAppWithNoData(profile_, extension_); | 113 LaunchPlatformAppWithNoData(profile_, extension_); |
107 return; | 114 return; |
108 } | 115 } |
109 | 116 |
110 DCHECK(file_path_.IsAbsolute()); | 117 DCHECK(file_path_.IsAbsolute()); |
| 118 |
| 119 #if defined(OS_CHROMEOS) |
| 120 if (drive::util::IsUnderDriveMountPoint(file_path_)) { |
| 121 GetMimeTypeAndLaunchForDriveFile(); |
| 122 return; |
| 123 } |
| 124 #endif |
| 125 |
111 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind( | 126 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind( |
112 &PlatformAppPathLauncher::GetMimeTypeAndLaunch, this)); | 127 &PlatformAppPathLauncher::GetMimeTypeAndLaunch, this)); |
113 } | 128 } |
114 | 129 |
115 void LaunchWithHandler(const std::string& handler_id) { | 130 void LaunchWithHandler(const std::string& handler_id) { |
116 handler_id_ = handler_id; | 131 handler_id_ = handler_id; |
117 Launch(); | 132 Launch(); |
118 } | 133 } |
119 | 134 |
120 private: | 135 private: |
(...skipping 20 matching lines...) Expand all Loading... |
141 << file_path_.value(); | 156 << file_path_.value(); |
142 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 157 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
143 &PlatformAppPathLauncher::LaunchWithNoLaunchData, this)); | 158 &PlatformAppPathLauncher::LaunchWithNoLaunchData, this)); |
144 return; | 159 return; |
145 } | 160 } |
146 | 161 |
147 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 162 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
148 &PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type)); | 163 &PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type)); |
149 } | 164 } |
150 | 165 |
| 166 #if defined(OS_CHROMEOS) |
| 167 void GetMimeTypeAndLaunchForDriveFile() { |
| 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 169 |
| 170 drive::DriveSystemService* service = |
| 171 drive::DriveSystemServiceFactory::FindForProfile(profile_); |
| 172 if (!service) { |
| 173 LaunchWithNoLaunchData(); |
| 174 return; |
| 175 } |
| 176 |
| 177 service->file_system()->GetFileByPath( |
| 178 drive::util::ExtractDrivePath(file_path_), |
| 179 base::Bind(&PlatformAppPathLauncher::OnGotDriveFile, this)); |
| 180 } |
| 181 |
| 182 void OnGotDriveFile(drive::DriveFileError error, |
| 183 const base::FilePath& file_path, |
| 184 const std::string& mime_type, |
| 185 drive::DriveFileType file_type) { |
| 186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 187 |
| 188 if (error != drive::DRIVE_FILE_OK || mime_type.empty() || |
| 189 file_type != drive::REGULAR_FILE) { |
| 190 LaunchWithNoLaunchData(); |
| 191 return; |
| 192 } |
| 193 |
| 194 LaunchWithMimeType(mime_type); |
| 195 } |
| 196 #endif // defined(OS_CHROMEOS) |
| 197 |
151 void LaunchWithNoLaunchData() { | 198 void LaunchWithNoLaunchData() { |
152 // This method is required as an entry point on the UI thread. | 199 // This method is required as an entry point on the UI thread. |
153 LaunchPlatformAppWithNoData(profile_, extension_); | 200 LaunchPlatformAppWithNoData(profile_, extension_); |
154 } | 201 } |
155 | 202 |
156 void LaunchWithMimeType(const std::string& mime_type) { | 203 void LaunchWithMimeType(const std::string& mime_type) { |
157 // Find file handler from the platform app for the file being opened. | 204 // Find file handler from the platform app for the file being opened. |
158 const FileHandlerInfo* handler = NULL; | 205 const FileHandlerInfo* handler = NULL; |
159 if (!handler_id_.empty()) | 206 if (!handler_id_.empty()) |
160 handler = FileHandlerForId(*extension_, handler_id_); | 207 handler = FileHandlerForId(*extension_, handler_id_); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 // regranted, as this would overwrite any other permissions which the | 263 // regranted, as this would overwrite any other permissions which the |
217 // renderer may already have. | 264 // renderer may already have. |
218 if (!policy->CanReadFile(renderer_id, file_path_)) | 265 if (!policy->CanReadFile(renderer_id, file_path_)) |
219 policy->GrantReadFile(renderer_id, file_path_); | 266 policy->GrantReadFile(renderer_id, file_path_); |
220 | 267 |
221 std::string registered_name; | 268 std::string registered_name; |
222 fileapi::IsolatedContext* isolated_context = | 269 fileapi::IsolatedContext* isolated_context = |
223 fileapi::IsolatedContext::GetInstance(); | 270 fileapi::IsolatedContext::GetInstance(); |
224 DCHECK(isolated_context); | 271 DCHECK(isolated_context); |
225 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( | 272 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( |
226 fileapi::kFileSystemTypeNativeLocal, file_path_, ®istered_name); | 273 fileapi::kFileSystemTypeNativeForPlatformApp, file_path_, |
| 274 ®istered_name); |
227 // Granting read file system permission as well to allow file-system | 275 // Granting read file system permission as well to allow file-system |
228 // read operations. | 276 // read operations. |
229 policy->GrantReadFileSystem(renderer_id, filesystem_id); | 277 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
230 | 278 |
231 AppEventRouter::DispatchOnLaunchedEventWithFileEntry( | 279 AppEventRouter::DispatchOnLaunchedEventWithFileEntry( |
232 profile_, extension_, handler_id_, mime_type, filesystem_id, | 280 profile_, extension_, handler_id_, mime_type, filesystem_id, |
233 registered_name); | 281 registered_name); |
234 } | 282 } |
235 | 283 |
236 // The profile the app should be run in. | 284 // The profile the app should be run in. |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 void RestartPlatformAppWithFileEntries( | 396 void RestartPlatformAppWithFileEntries( |
349 Profile* profile, | 397 Profile* profile, |
350 const Extension* extension, | 398 const Extension* extension, |
351 const std::vector<SavedFileEntry>& file_entries) { | 399 const std::vector<SavedFileEntry>& file_entries) { |
352 scoped_refptr<SavedFileEntryLauncher> launcher = new SavedFileEntryLauncher( | 400 scoped_refptr<SavedFileEntryLauncher> launcher = new SavedFileEntryLauncher( |
353 profile, extension, file_entries); | 401 profile, extension, file_entries); |
354 launcher->Launch(); | 402 launcher->Launch(); |
355 } | 403 } |
356 | 404 |
357 } // namespace extensions | 405 } // namespace extensions |
OLD | NEW |