Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1214)

Side by Side Diff: chrome/browser/extensions/platform_app_launcher.cc

Issue 12258021: Fix filesystem API file_handlers to work for drive on ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 handler_id_("") {} 102 handler_id_("") {}
96 103
97 void Launch() { 104 void Launch() {
98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
99 if (file_path_.empty()) { 106 if (file_path_.empty()) {
100 LaunchPlatformAppWithNoData(profile_, extension_); 107 LaunchPlatformAppWithNoData(profile_, extension_);
101 return; 108 return;
102 } 109 }
103 110
104 DCHECK(file_path_.IsAbsolute()); 111 DCHECK(file_path_.IsAbsolute());
112
113 #if defined(OS_CHROMEOS)
114 if (drive::util::IsUnderDriveMountPoint(file_path_)) {
115 GetMimeTypeAndLaunchForDriveFile();
116 return;
117 }
118 #endif
119
105 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind( 120 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind(
106 &PlatformAppPathLauncher::GetMimeTypeAndLaunch, this)); 121 &PlatformAppPathLauncher::GetMimeTypeAndLaunch, this));
107 } 122 }
108 123
109 void LaunchWithHandler(const std::string& handler_id) { 124 void LaunchWithHandler(const std::string& handler_id) {
110 handler_id_ = handler_id; 125 handler_id_ = handler_id;
111 Launch(); 126 Launch();
112 } 127 }
113 128
114 private: 129 private:
(...skipping 20 matching lines...) Expand all
135 << file_path_.value(); 150 << file_path_.value();
136 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( 151 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
137 &PlatformAppPathLauncher::LaunchWithNoLaunchData, this)); 152 &PlatformAppPathLauncher::LaunchWithNoLaunchData, this));
138 return; 153 return;
139 } 154 }
140 155
141 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( 156 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
142 &PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type)); 157 &PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type));
143 } 158 }
144 159
160 #if defined(OS_CHROMEOS)
161 void GetMimeTypeAndLaunchForDriveFile() {
162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
163
164 drive::DriveSystemService* service =
165 drive::DriveSystemServiceFactory::FindForProfile(profile_);
166 if (!service) {
167 LaunchWithNoLaunchData();
168 return;
169 }
170
171 service->file_system()->GetFileByPath(
172 drive::util::ExtractDrivePath(file_path_),
173 base::Bind(&PlatformAppPathLauncher::OnGotDriveFile, this));
174 }
175
176 void OnGotDriveFile(drive::DriveFileError error,
177 const base::FilePath& file_path,
178 const std::string& mime_type,
179 drive::DriveFileType file_type) {
180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
181
182 if (error != drive::DRIVE_FILE_OK || mime_type.empty() ||
183 file_type != drive::REGULAR_FILE) {
184 LaunchWithNoLaunchData();
185 return;
186 }
187
188 LaunchWithMimeType(mime_type);
189 }
190 #endif // defined(OS_CHROMEOS)
191
145 void LaunchWithNoLaunchData() { 192 void LaunchWithNoLaunchData() {
146 // This method is required as an entry point on the UI thread. 193 // This method is required as an entry point on the UI thread.
147 LaunchPlatformAppWithNoData(profile_, extension_); 194 LaunchPlatformAppWithNoData(profile_, extension_);
148 } 195 }
149 196
150 void LaunchWithMimeType(const std::string& mime_type) { 197 void LaunchWithMimeType(const std::string& mime_type) {
151 // Find file handler from the platform app for the file being opened. 198 // Find file handler from the platform app for the file being opened.
152 const FileHandlerInfo* handler = NULL; 199 const FileHandlerInfo* handler = NULL;
153 if (!handler_id_.empty()) 200 if (!handler_id_.empty())
154 handler = FileHandlerForId(*extension_, handler_id_); 201 handler = FileHandlerForId(*extension_, handler_id_);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 void LaunchPlatformAppWithFileHandler(Profile* profile, 316 void LaunchPlatformAppWithFileHandler(Profile* profile,
270 const Extension* extension, 317 const Extension* extension,
271 const std::string& handler_id, 318 const std::string& handler_id,
272 const base::FilePath& file_path) { 319 const base::FilePath& file_path) {
273 scoped_refptr<PlatformAppPathLauncher> launcher = 320 scoped_refptr<PlatformAppPathLauncher> launcher =
274 new PlatformAppPathLauncher(profile, extension, file_path); 321 new PlatformAppPathLauncher(profile, extension, file_path);
275 launcher->LaunchWithHandler(handler_id); 322 launcher->LaunchWithHandler(handler_id);
276 } 323 }
277 324
278 } // namespace extensions 325 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698