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 11 matching lines...) Expand all Loading... | |
22 #include "chrome/common/extensions/extension_messages.h" | 22 #include "chrome/common/extensions/extension_messages.h" |
23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/child_process_security_policy.h" | 24 #include "content/public/browser/child_process_security_policy.h" |
25 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
27 #include "net/base/mime_util.h" | 27 #include "net/base/mime_util.h" |
28 #include "net/base/net_util.h" | 28 #include "net/base/net_util.h" |
29 #include "webkit/fileapi/file_system_types.h" | 29 #include "webkit/fileapi/file_system_types.h" |
30 #include "webkit/fileapi/isolated_context.h" | 30 #include "webkit/fileapi/isolated_context.h" |
31 | 31 |
32 #if defined(OS_CHROMEOS) | |
33 #include "chrome/browser/chromeos/drive/drive_file_error.h" | |
34 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" | |
35 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" | |
36 #include "chrome/browser/chromeos/drive/drive_system_service.h" | |
37 #endif | |
38 | |
32 using content::BrowserThread; | 39 using content::BrowserThread; |
33 using extensions::app_file_handler_util::FileHandlerForId; | 40 using extensions::app_file_handler_util::FileHandlerForId; |
34 using extensions::app_file_handler_util::FileHandlerCanHandleFileWithMimeType; | 41 using extensions::app_file_handler_util::FileHandlerCanHandleFileWithMimeType; |
35 using extensions::app_file_handler_util::FirstFileHandlerForMimeType; | 42 using extensions::app_file_handler_util::FirstFileHandlerForMimeType; |
36 | 43 |
37 namespace extensions { | 44 namespace extensions { |
38 | 45 |
39 namespace { | 46 namespace { |
40 | 47 |
41 bool MakePathAbsolute(const base::FilePath& current_directory, | 48 bool MakePathAbsolute(const base::FilePath& current_directory, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 // outstanding tasks are completed it will be deleted. | 92 // outstanding tasks are completed it will be deleted. |
86 class PlatformAppPathLauncher | 93 class PlatformAppPathLauncher |
87 : public base::RefCountedThreadSafe<PlatformAppPathLauncher> { | 94 : public base::RefCountedThreadSafe<PlatformAppPathLauncher> { |
88 public: | 95 public: |
89 PlatformAppPathLauncher(Profile* profile, | 96 PlatformAppPathLauncher(Profile* profile, |
90 const Extension* extension, | 97 const Extension* extension, |
91 const base::FilePath& file_path) | 98 const base::FilePath& file_path) |
92 : profile_(profile), | 99 : profile_(profile), |
93 extension_(extension), | 100 extension_(extension), |
94 file_path_(file_path), | 101 file_path_(file_path), |
102 file_system_type_(fileapi::kFileSystemTypeUnknown), | |
95 handler_id_("") {} | 103 handler_id_("") {} |
96 | 104 |
97 void Launch() { | 105 void Launch() { |
98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
99 if (file_path_.empty()) { | 107 if (file_path_.empty()) { |
100 LaunchPlatformAppWithNoData(profile_, extension_); | 108 LaunchPlatformAppWithNoData(profile_, extension_); |
101 return; | 109 return; |
102 } | 110 } |
103 | 111 |
104 DCHECK(file_path_.IsAbsolute()); | 112 DCHECK(file_path_.IsAbsolute()); |
113 #if defined(OS_CHROMEOS) | |
114 if (drive::util::IsUnderDriveMountPoint(file_path_)) { | |
115 file_system_type_ = fileapi::kFileSystemTypeDrive; | |
116 GetMimeTypeAndLaunchForDriveFile(); | |
117 return; | |
118 } | |
119 #endif | |
120 file_system_type_ = fileapi::kFileSystemTypeNativeLocal; | |
105 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind( | 121 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind( |
106 &PlatformAppPathLauncher::GetMimeTypeAndLaunch, this)); | 122 &PlatformAppPathLauncher::GetMimeTypeAndLaunch, this)); |
107 } | 123 } |
108 | 124 |
109 void LaunchWithHandler(const std::string& handler_id) { | 125 void LaunchWithHandler(const std::string& handler_id) { |
110 handler_id_ = handler_id; | 126 handler_id_ = handler_id; |
111 Launch(); | 127 Launch(); |
112 } | 128 } |
113 | 129 |
114 private: | 130 private: |
(...skipping 19 matching lines...) Expand all Loading... | |
134 LOG(WARNING) << "Could not obtain MIME type for " | 150 LOG(WARNING) << "Could not obtain MIME type for " |
135 << file_path_.value(); | 151 << file_path_.value(); |
136 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 152 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
137 &PlatformAppPathLauncher::LaunchWithNoLaunchData, this)); | 153 &PlatformAppPathLauncher::LaunchWithNoLaunchData, this)); |
138 return; | 154 return; |
139 } | 155 } |
140 | 156 |
141 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 157 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
142 &PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type)); | 158 &PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type)); |
143 } | 159 } |
160 #if defined(OS_CHROMEOS) | |
161 void GetMimeTypeAndLaunchForDriveFile() { | |
benwells
2013/03/04 01:27:39
Can this run on any thread? It is currently on UI,
tbarzic
2013/03/06 01:45:10
It _must_ run on UI thread, added DCHECK.
| |
162 drive::DriveSystemService* service = | |
163 drive::DriveSystemServiceFactory::FindForProfile(profile_); | |
164 if (!service) { | |
165 LaunchWithNoLaunchData(); | |
166 return; | |
167 } | |
168 | |
169 service->file_system()->GetFileByPath( | |
170 drive::util::ExtractDrivePath(file_path_), | |
171 base::Bind(&PlatformAppPathLauncher::OnGotDriveFile, this)); | |
172 } | |
173 | |
174 void OnGotDriveFile(drive::DriveFileError error, | |
benwells
2013/03/04 01:27:39
Same question here about threads. This file is pre
tbarzic
2013/03/06 01:45:10
Done.
| |
175 const base::FilePath& file_path, | |
176 const std::string& mime_type, | |
177 drive::DriveFileType file_type) { | |
178 if (error != drive::DRIVE_FILE_OK || mime_type.empty() || | |
179 file_type != drive::REGULAR_FILE) { | |
180 LaunchWithNoLaunchData(); | |
181 return; | |
182 } | |
183 | |
184 LaunchWithMimeType(mime_type); | |
185 } | |
186 #endif // defined(OS_CHROMEOS) | |
144 | 187 |
145 void LaunchWithNoLaunchData() { | 188 void LaunchWithNoLaunchData() { |
146 // This method is required as an entry point on the UI thread. | 189 // This method is required as an entry point on the UI thread. |
147 LaunchPlatformAppWithNoData(profile_, extension_); | 190 LaunchPlatformAppWithNoData(profile_, extension_); |
148 } | 191 } |
149 | 192 |
150 void LaunchWithMimeType(const std::string& mime_type) { | 193 void LaunchWithMimeType(const std::string& mime_type) { |
151 // Find file handler from the platform app for the file being opened. | 194 // Find file handler from the platform app for the file being opened. |
152 const FileHandlerInfo* handler = NULL; | 195 const FileHandlerInfo* handler = NULL; |
153 if (!handler_id_.empty()) | 196 if (!handler_id_.empty()) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 // regranted, as this would overwrite any other permissions which the | 253 // regranted, as this would overwrite any other permissions which the |
211 // renderer may already have. | 254 // renderer may already have. |
212 if (!policy->CanReadFile(renderer_id, file_path_)) | 255 if (!policy->CanReadFile(renderer_id, file_path_)) |
213 policy->GrantReadFile(renderer_id, file_path_); | 256 policy->GrantReadFile(renderer_id, file_path_); |
214 | 257 |
215 std::string registered_name; | 258 std::string registered_name; |
216 fileapi::IsolatedContext* isolated_context = | 259 fileapi::IsolatedContext* isolated_context = |
217 fileapi::IsolatedContext::GetInstance(); | 260 fileapi::IsolatedContext::GetInstance(); |
218 DCHECK(isolated_context); | 261 DCHECK(isolated_context); |
219 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( | 262 std::string filesystem_id = isolated_context->RegisterFileSystemForPath( |
220 fileapi::kFileSystemTypeNativeLocal, file_path_, ®istered_name); | 263 file_system_type_, file_path_, ®istered_name); |
benwells
2013/03/04 01:27:39
There will need to be a similar type of addition t
tbarzic
2013/03/06 01:45:10
yes, I know.. or fileapi layer should be changed s
kinaba
2013/03/06 02:00:42
I feel it a little strange that the client code of
tbarzic
2013/03/06 02:13:00
yeah, I agree, that's the biggest issue I have wit
| |
221 // Granting read file system permission as well to allow file-system | 264 // Granting read file system permission as well to allow file-system |
222 // read operations. | 265 // read operations. |
223 policy->GrantReadFileSystem(renderer_id, filesystem_id); | 266 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
224 | 267 |
225 AppEventRouter::DispatchOnLaunchedEventWithFileEntry( | 268 AppEventRouter::DispatchOnLaunchedEventWithFileEntry( |
226 profile_, extension_, handler_id_, mime_type, filesystem_id, | 269 profile_, extension_, handler_id_, mime_type, filesystem_id, |
227 registered_name); | 270 registered_name); |
228 } | 271 } |
229 | 272 |
230 // The profile the app should be run in. | 273 // The profile the app should be run in. |
231 Profile* profile_; | 274 Profile* profile_; |
232 // The extension providing the app. | 275 // The extension providing the app. |
233 const Extension* extension_; | 276 const Extension* extension_; |
234 // The path to be passed through to the app. | 277 // The path to be passed through to the app. |
235 const base::FilePath file_path_; | 278 const base::FilePath file_path_; |
279 // The file system type for the path passed through to the app. | |
280 fileapi::FileSystemType file_system_type_; | |
236 // The ID of the file handler used to launch the app. | 281 // The ID of the file handler used to launch the app. |
237 std::string handler_id_; | 282 std::string handler_id_; |
238 | 283 |
239 DISALLOW_COPY_AND_ASSIGN(PlatformAppPathLauncher); | 284 DISALLOW_COPY_AND_ASSIGN(PlatformAppPathLauncher); |
240 }; | 285 }; |
241 | 286 |
242 } // namespace | 287 } // namespace |
243 | 288 |
244 void LaunchPlatformApp(Profile* profile, | 289 void LaunchPlatformApp(Profile* profile, |
245 const Extension* extension, | 290 const Extension* extension, |
(...skipping 23 matching lines...) Expand all Loading... | |
269 void LaunchPlatformAppWithFileHandler(Profile* profile, | 314 void LaunchPlatformAppWithFileHandler(Profile* profile, |
270 const Extension* extension, | 315 const Extension* extension, |
271 const std::string& handler_id, | 316 const std::string& handler_id, |
272 const base::FilePath& file_path) { | 317 const base::FilePath& file_path) { |
273 scoped_refptr<PlatformAppPathLauncher> launcher = | 318 scoped_refptr<PlatformAppPathLauncher> launcher = |
274 new PlatformAppPathLauncher(profile, extension, file_path); | 319 new PlatformAppPathLauncher(profile, extension, file_path); |
275 launcher->LaunchWithHandler(handler_id); | 320 launcher->LaunchWithHandler(handler_id); |
276 } | 321 } |
277 | 322 |
278 } // namespace extensions | 323 } // namespace extensions |
OLD | NEW |