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

Side by Side Diff: chrome/browser/chromeos/extensions/file_handler_util.cc

Issue 10834383: Chrome OS "open with" picker allowing Web Intents (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: benwells' changes Created 8 years, 3 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
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/chromeos/extensions/file_handler_util.h" 5 #include "chrome/browser/chromeos/extensions/file_handler_util.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/chromeos/gdata/gdata_util.h" 14 #include "chrome/browser/chromeos/gdata/gdata_util.h"
15 #include "chrome/browser/chromeos/extensions/file_manager_util.h" 15 #include "chrome/browser/chromeos/extensions/file_manager_util.h"
16 #include "chrome/browser/chromeos/gdata/drive_task_executor.h" 16 #include "chrome/browser/chromeos/gdata/drive_task_executor.h"
17 #include "chrome/browser/extensions/event_router.h" 17 #include "chrome/browser/extensions/event_router.h"
18 #include "chrome/browser/extensions/extension_host.h" 18 #include "chrome/browser/extensions/extension_host.h"
19 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/extensions/extension_system.h" 20 #include "chrome/browser/extensions/extension_system.h"
21 #include "chrome/browser/extensions/extension_tab_util.h" 21 #include "chrome/browser/extensions/extension_tab_util.h"
22 #include "chrome/browser/extensions/lazy_background_task_queue.h" 22 #include "chrome/browser/extensions/lazy_background_task_queue.h"
23 #include "chrome/browser/extensions/platform_app_launcher.h"
23 #include "chrome/browser/prefs/scoped_user_pref_update.h" 24 #include "chrome/browser/prefs/scoped_user_pref_update.h"
24 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/profiles/profile_manager.h" 26 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/browser/ui/browser.h" 27 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_finder.h" 28 #include "chrome/browser/ui/browser_finder.h"
28 #include "chrome/browser/ui/browser_tabstrip.h" 29 #include "chrome/browser/ui/browser_tabstrip.h"
29 #include "chrome/common/extensions/file_browser_handler.h" 30 #include "chrome/common/extensions/file_browser_handler.h"
30 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
31 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/child_process_security_policy.h" 33 #include "content/public/browser/child_process_security_policy.h"
33 #include "content/public/browser/render_process_host.h" 34 #include "content/public/browser/render_process_host.h"
34 #include "content/public/browser/site_instance.h" 35 #include "content/public/browser/site_instance.h"
35 #include "content/public/browser/web_contents.h" 36 #include "content/public/browser/web_contents.h"
36 #include "net/base/escape.h" 37 #include "net/base/escape.h"
37 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" 38 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h"
38 #include "webkit/fileapi/file_system_context.h" 39 #include "webkit/fileapi/file_system_context.h"
39 #include "webkit/fileapi/file_system_url.h" 40 #include "webkit/fileapi/file_system_url.h"
40 #include "webkit/fileapi/file_system_util.h" 41 #include "webkit/fileapi/file_system_util.h"
42 #include "webkit/fileapi/isolated_context.h"
41 43
42 using content::BrowserContext; 44 using content::BrowserContext;
43 using content::BrowserThread; 45 using content::BrowserThread;
44 using content::ChildProcessSecurityPolicy; 46 using content::ChildProcessSecurityPolicy;
45 using content::SiteInstance; 47 using content::SiteInstance;
46 using content::WebContents; 48 using content::WebContents;
47 using extensions::Extension; 49 using extensions::Extension;
48 50
49 namespace file_handler_util { 51 namespace file_handler_util {
50 52
51 // The prefix used to differentiate drive extensions from Chrome extensions.
52 const char FileTaskExecutor::kDriveTaskExtensionPrefix[] = "drive-app:";
53 const size_t FileTaskExecutor::kDriveTaskExtensionPrefixLength =
54 arraysize(FileTaskExecutor::kDriveTaskExtensionPrefix) - 1;
55
56 namespace { 53 namespace {
57 54
58 const int kReadWriteFilePermissions = base::PLATFORM_FILE_OPEN | 55 const int kReadWriteFilePermissions = base::PLATFORM_FILE_OPEN |
59 base::PLATFORM_FILE_CREATE | 56 base::PLATFORM_FILE_CREATE |
60 base::PLATFORM_FILE_OPEN_ALWAYS | 57 base::PLATFORM_FILE_OPEN_ALWAYS |
61 base::PLATFORM_FILE_CREATE_ALWAYS | 58 base::PLATFORM_FILE_CREATE_ALWAYS |
62 base::PLATFORM_FILE_OPEN_TRUNCATED | 59 base::PLATFORM_FILE_OPEN_TRUNCATED |
63 base::PLATFORM_FILE_READ | 60 base::PLATFORM_FILE_READ |
64 base::PLATFORM_FILE_WRITE | 61 base::PLATFORM_FILE_WRITE |
65 base::PLATFORM_FILE_EXCLUSIVE_READ | 62 base::PLATFORM_FILE_EXCLUSIVE_READ |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 extension->file_browser_handlers()->begin(); 110 extension->file_browser_handlers()->begin();
114 action_iter != extension->file_browser_handlers()->end(); 111 action_iter != extension->file_browser_handlers()->end();
115 ++action_iter) { 112 ++action_iter) {
116 if (action_iter->get()->id() == action_id) 113 if (action_iter->get()->id() == action_id)
117 return action_iter->get(); 114 return action_iter->get();
118 } 115 }
119 return NULL; 116 return NULL;
120 } 117 }
121 118
122 unsigned int GetAccessPermissionsForHandler(const Extension* extension, 119 unsigned int GetAccessPermissionsForHandler(const Extension* extension,
123 const std::string& action_id) { 120 const std::string& action_id,
121 TaskType task_type) {
122 if (task_type == TASK_WEBINTENT)
123 return kReadOnlyFilePermissions;
124
124 const FileBrowserHandler* action = 125 const FileBrowserHandler* action =
125 FindFileBrowserHandler(extension, action_id); 126 FindFileBrowserHandler(extension, action_id);
126 if (!action) 127 if (!action)
127 return 0; 128 return 0;
128 unsigned int result = 0; 129 unsigned int result = 0;
129 if (action->CanRead()) 130 if (action->CanRead())
130 result |= kReadOnlyFilePermissions; 131 result |= kReadOnlyFilePermissions;
131 if (action->CanWrite()) 132 if (action->CanWrite())
132 result |= kReadWriteFilePermissions; 133 result |= kReadWriteFilePermissions;
133 // TODO(tbarzic): We don't handle Create yet. 134 // TODO(tbarzic): We don't handle Create yet.
134 return result; 135 return result;
135 } 136 }
136 137
137
138 std::string EscapedUtf8ToLower(const std::string& str) { 138 std::string EscapedUtf8ToLower(const std::string& str) {
139 string16 utf16 = UTF8ToUTF16( 139 string16 utf16 = UTF8ToUTF16(
140 net::UnescapeURLComponent(str, net::UnescapeRule::NORMAL)); 140 net::UnescapeURLComponent(str, net::UnescapeRule::NORMAL));
141 return net::EscapeUrlEncodedData( 141 return net::EscapeUrlEncodedData(
142 UTF16ToUTF8(base::i18n::ToLower(utf16)), 142 UTF16ToUTF8(base::i18n::ToLower(utf16)),
143 false /* do not replace space with plus */); 143 false /* do not replace space with plus */);
144 } 144 }
145 145
146 bool GetFileBrowserHandlers(Profile* profile, 146 bool GetFileBrowserHandlers(Profile* profile,
147 const GURL& selected_file_url, 147 const GURL& selected_file_url,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 const LastUsedHandler& b) { 182 const LastUsedHandler& b) {
183 return a.timestamp > b.timestamp; 183 return a.timestamp > b.timestamp;
184 } 184 }
185 185
186 // TODO(zelidrag): Wire this with ICU to make this sort I18N happy. 186 // TODO(zelidrag): Wire this with ICU to make this sort I18N happy.
187 bool SortByTaskName(const LastUsedHandler& a, const LastUsedHandler& b) { 187 bool SortByTaskName(const LastUsedHandler& a, const LastUsedHandler& b) {
188 return base::strcasecmp(a.handler->title().c_str(), 188 return base::strcasecmp(a.handler->title().c_str(),
189 b.handler->title().c_str()) > 0; 189 b.handler->title().c_str()) > 0;
190 } 190 }
191 191
192 // Does this LastUsedHandlerList contain entries with only a common timestamp?
193 bool AllHaveSameTimestamp(LastUsedHandlerList* list) {
194 DCHECK(!list->empty());
195 int common_timestamp = list->begin()->timestamp;
196 for (LastUsedHandlerList::const_iterator iter = list->begin() + 1;
197 iter != list->end(); ++iter) {
198 if (common_timestamp != iter->timestamp)
199 return false;
200 }
201 return true;
202 }
203
192 void SortLastUsedHandlerList(LastUsedHandlerList *list) { 204 void SortLastUsedHandlerList(LastUsedHandlerList *list) {
193 // Sort by the last used descending. 205 // If we've got one element or fewer, the list is already sorted. If the
194 std::sort(list->begin(), list->end(), SortByLastUsedTimestampDesc); 206 // handlers have a common timestamp (e.g., if no handlers have ever been
195 if (list->size() > 1) { 207 // invoked), just sort by name. Otherwise, bring the last used handler to
196 // Sort the rest by name. 208 // the front and sort the rest by name.
209 if (list->size() <= 1) {
210 // do nothing
211 } else if (AllHaveSameTimestamp(list)) {
212 std::sort(list->begin(), list->end(), SortByTaskName);
213 } else {
214 std::sort(list->begin(), list->end(), SortByLastUsedTimestampDesc);
197 std::sort(list->begin() + 1, list->end(), SortByTaskName); 215 std::sort(list->begin() + 1, list->end(), SortByTaskName);
198 } 216 }
199 } 217 }
200 218
201 } // namespace 219 } // namespace
202 220
203 // Update file handler usage stats. 221 // Update file handler usage stats.
204 void UpdateFileHandlerUsageStats(Profile* profile, const std::string& task_id) { 222 void UpdateFileHandlerUsageStats(Profile* profile, const std::string& task_id) {
205 if (!profile || !profile->GetPrefs()) 223 if (!profile || !profile->GetPrefs())
206 return; 224 return;
207 DictionaryPrefUpdate prefs_usage_update(profile->GetPrefs(), 225 DictionaryPrefUpdate prefs_usage_update(profile->GetPrefs(),
208 prefs::kLastUsedFileBrowserHandlers); 226 prefs::kLastUsedFileBrowserHandlers);
209 prefs_usage_update->SetWithoutPathExpansion(task_id, 227 prefs_usage_update->SetWithoutPathExpansion(task_id,
210 new base::FundamentalValue( 228 new base::FundamentalValue(
211 static_cast<int>(base::Time::Now().ToInternalValue()/ 229 static_cast<int>(base::Time::Now().ToInternalValue()/
212 base::Time::kMicrosecondsPerSecond))); 230 base::Time::kMicrosecondsPerSecond)));
213 } 231 }
214 232
215 int GetReadWritePermissions() { 233 int GetReadWritePermissions() {
216 return kReadWriteFilePermissions; 234 return kReadWriteFilePermissions;
217 } 235 }
218 236
219 int GetReadOnlyPermissions() { 237 int GetReadOnlyPermissions() {
220 return kReadOnlyFilePermissions; 238 return kReadOnlyFilePermissions;
221 } 239 }
222 240
223 std::string MakeTaskID(const std::string& extension_id, 241 std::string MakeTaskID(const std::string& extension_id,
242 TaskType task_type,
224 const std::string& action_id) { 243 const std::string& action_id) {
225 return base::StringPrintf("%s|%s", extension_id.c_str(), action_id.c_str()); 244 DCHECK(task_type == TASK_FILE
245 || task_type == TASK_DRIVE
246 || task_type == TASK_WEBINTENT);
247 return base::StringPrintf("%s|%d|%s",
248 extension_id.c_str(),
249 task_type,
250 action_id.c_str());
226 } 251 }
227 252
228 std::string MakeDriveTaskID(const std::string& app_id,
229 const std::string& action_id) {
230 return MakeTaskID(FileTaskExecutor::kDriveTaskExtensionPrefix + app_id,
231 action_id);
232 }
233
234
235 // Breaks down task_id that is used between getFileTasks() and executeTask() on 253 // Breaks down task_id that is used between getFileTasks() and executeTask() on
236 // its building blocks. task_id field the following structure: 254 // its building blocks. task_id field the following structure:
237 // <extension-id>|<task-action-id> 255 // <extension-id>|<task-type>|<task-action-id>
238 // Currently, the only supported task-type is of 'context'. 256 // Currently, the only supported task-type is of 'context'.
239 bool CrackTaskID(const std::string& task_id, 257 bool CrackTaskID(const std::string& task_id,
240 std::string* extension_id, 258 std::string* extension_id,
259 TaskType* task_type,
241 std::string* action_id) { 260 std::string* action_id) {
242 std::vector<std::string> result; 261 std::vector<std::string> result;
243 int count = Tokenize(task_id, std::string("|"), &result); 262 int count = Tokenize(task_id, std::string("|"), &result);
244 if (count != 2) 263 if (count != 3)
245 return false; 264 return false;
246 *extension_id = result[0]; 265 *extension_id = result[0];
247 *action_id = result[1]; 266
267 *task_type = file_handler_util::TaskType(atoi(result[1].c_str()));
268 DCHECK(*task_type == TASK_FILE
269 || *task_type == TASK_DRIVE
270 || *task_type == TASK_WEBINTENT);
271
272 *action_id = result[2];
273
248 return true; 274 return true;
249 } 275 }
250 276
251 // Find a specific handler in the handler list. 277 // Find a specific handler in the handler list.
252 LastUsedHandlerList::iterator FindHandler( 278 LastUsedHandlerList::iterator FindHandler(
253 LastUsedHandlerList* list, 279 LastUsedHandlerList* list,
254 const std::string& extension_id, 280 const std::string& extension_id,
255 const std::string& id) { 281 const std::string& id) {
256 LastUsedHandlerList::iterator iter = list->begin(); 282 LastUsedHandlerList::iterator iter = list->begin();
257 while (iter != list->end() && 283 while (iter != list->end() &&
258 !(iter->handler->extension_id() == extension_id && 284 !(iter->handler->extension_id() == extension_id &&
259 iter->handler->id() == id)) { 285 iter->handler->id() == id)) {
260 iter++; 286 iter++;
261 } 287 }
262 return iter; 288 return iter;
263 } 289 }
264 290
265 // Given the list of selected files, returns array of context menu tasks 291 // Given the list of selected files, returns array of file action tasks
266 // that are shared 292 // that are shared between them.
267 bool FindCommonTasks(Profile* profile, 293 bool FindCommonTasks(Profile* profile,
268 const std::vector<GURL>& files_list, 294 const std::vector<GURL>& files_list,
269 LastUsedHandlerList* named_action_list) { 295 LastUsedHandlerList* named_action_list) {
270 named_action_list->clear(); 296 named_action_list->clear();
271 ActionSet common_tasks; 297 ActionSet common_tasks;
272 for (std::vector<GURL>::const_iterator it = files_list.begin(); 298 for (std::vector<GURL>::const_iterator it = files_list.begin();
273 it != files_list.end(); ++it) { 299 it != files_list.end(); ++it) {
274 ActionSet file_actions; 300 ActionSet file_actions;
275 if (!GetFileBrowserHandlers(profile, *it, &file_actions)) 301 if (!GetFileBrowserHandlers(profile, *it, &file_actions))
276 return false; 302 return false;
(...skipping 24 matching lines...) Expand all
301 for (ActionSet::const_iterator iter = common_tasks.begin(); 327 for (ActionSet::const_iterator iter = common_tasks.begin();
302 iter != common_tasks.end(); ++iter) { 328 iter != common_tasks.end(); ++iter) {
303 // Get timestamp of when this task was used last time. 329 // Get timestamp of when this task was used last time.
304 int last_used_timestamp = 0; 330 int last_used_timestamp = 0;
305 331
306 if ((*iter)->extension_id() == kFileBrowserDomain) { 332 if ((*iter)->extension_id() == kFileBrowserDomain) {
307 // Give a little bump to the action from File Browser extension 333 // Give a little bump to the action from File Browser extension
308 // to make sure it is the default on a fresh profile. 334 // to make sure it is the default on a fresh profile.
309 last_used_timestamp = 1; 335 last_used_timestamp = 1;
310 } 336 }
311 prefs_tasks->GetInteger(MakeTaskID((*iter)->extension_id(), (*iter)->id()), 337 prefs_tasks->GetInteger(MakeTaskID((*iter)->extension_id(),
338 TASK_FILE,
339 (*iter)->id()),
312 &last_used_timestamp); 340 &last_used_timestamp);
313 URLPatternSet matching_patterns = GetAllMatchingPatterns(*iter, files_list); 341 URLPatternSet matching_patterns = GetAllMatchingPatterns(*iter, files_list);
314 named_action_list->push_back(LastUsedHandler(last_used_timestamp, *iter, 342 named_action_list->push_back(LastUsedHandler(last_used_timestamp, *iter,
315 matching_patterns)); 343 matching_patterns));
316 } 344 }
317 345
318 LastUsedHandlerList::iterator watch_iter = FindHandler( 346 LastUsedHandlerList::iterator watch_iter = FindHandler(
319 named_action_list, kFileBrowserDomain, kFileBrowserWatchTaskId); 347 named_action_list, kFileBrowserDomain, kFileBrowserWatchTaskId);
320 LastUsedHandlerList::iterator gallery_iter = FindHandler( 348 LastUsedHandlerList::iterator gallery_iter = FindHandler(
321 named_action_list, kFileBrowserDomain, kFileBrowserGalleryTaskId); 349 named_action_list, kFileBrowserDomain, kFileBrowserGalleryTaskId);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 virtual bool ExecuteAndNotify(const std::vector<GURL>& file_urls, 386 virtual bool ExecuteAndNotify(const std::vector<GURL>& file_urls,
359 const FileTaskFinishedCallback& done) OVERRIDE; 387 const FileTaskFinishedCallback& done) OVERRIDE;
360 388
361 private: 389 private:
362 // FileTaskExecutor is the only class allowed to create one. 390 // FileTaskExecutor is the only class allowed to create one.
363 friend class FileTaskExecutor; 391 friend class FileTaskExecutor;
364 392
365 ExtensionTaskExecutor(Profile* profile, 393 ExtensionTaskExecutor(Profile* profile,
366 const GURL source_url, 394 const GURL source_url,
367 const std::string& extension_id, 395 const std::string& extension_id,
396 TaskType task_type,
368 const std::string& action_id); 397 const std::string& action_id);
369 virtual ~ExtensionTaskExecutor(); 398 virtual ~ExtensionTaskExecutor();
370 399
371 struct FileDefinition { 400 struct FileDefinition {
372 FileDefinition(); 401 FileDefinition();
373 ~FileDefinition(); 402 ~FileDefinition();
374 403
375 GURL target_file_url; 404 GURL target_file_url;
376 FilePath virtual_path; 405 FilePath virtual_path;
377 FilePath absolute_path; 406 FilePath absolute_path;
(...skipping 18 matching lines...) Expand all
396 const GURL& file_system_root, 425 const GURL& file_system_root,
397 const FileDefinitionList& file_list, 426 const FileDefinitionList& file_list,
398 int handler_pid_in, 427 int handler_pid_in,
399 extensions::ExtensionHost* host); 428 extensions::ExtensionHost* host);
400 429
401 // Populates |handler_host_permissions| with file path-permissions pairs that 430 // Populates |handler_host_permissions| with file path-permissions pairs that
402 // will be given to the handler extension host process. 431 // will be given to the handler extension host process.
403 void InitHandlerHostFileAccessPermissions( 432 void InitHandlerHostFileAccessPermissions(
404 const FileDefinitionList& file_list, 433 const FileDefinitionList& file_list,
405 const extensions::Extension* handler_extension, 434 const extensions::Extension* handler_extension,
406 const std::string& action_id,
407 const base::Closure& callback); 435 const base::Closure& callback);
408 436
409 // Invoked upon completion of InitHandlerHostFileAccessPermissions initiated 437 // Invoked upon completion of InitHandlerHostFileAccessPermissions initiated
410 // by ExecuteFileActionsOnUIThread. 438 // by ExecuteFileActionsOnUIThread.
411 void OnInitAccessForExecuteFileActionsOnUIThread( 439 void OnInitAccessForExecuteFileActionsOnUIThread(
412 const std::string& file_system_name, 440 const std::string& file_system_name,
413 const GURL& file_system_root, 441 const GURL& file_system_root,
414 const FileDefinitionList& file_list, 442 const FileDefinitionList& file_list,
415 int handler_pid); 443 int handler_pid);
416 444
417 // Registers file permissions from |handler_host_permissions_| with 445 // Registers file permissions from |handler_host_permissions_| with
418 // ChildProcessSecurityPolicy for process with id |handler_pid|. 446 // ChildProcessSecurityPolicy for process with id |handler_pid|.
419 void SetupHandlerHostFileAccessPermissions(int handler_pid); 447 void SetupHandlerHostFileAccessPermissions(int handler_pid);
420 448
421 // Helper function to get the extension pointer. 449 // Helper function to get the extension pointer.
422 const extensions::Extension* GetExtension(); 450 const extensions::Extension* GetExtension();
423 451
424 const GURL source_url_; 452 const GURL source_url_;
425 const std::string extension_id_; 453 const std::string extension_id_;
454 TaskType task_type_;
426 const std::string action_id_; 455 const std::string action_id_;
427 FileTaskFinishedCallback done_; 456 FileTaskFinishedCallback done_;
428 457
429 // (File path, permission for file path) pairs for the handler. 458 // (File path, permission for file path) pairs for the handler.
430 std::vector<std::pair<FilePath, int> > handler_host_permissions_; 459 std::vector<std::pair<FilePath, int> > handler_host_permissions_;
431 }; 460 };
432 461
433 // static 462 // static
434 FileTaskExecutor* FileTaskExecutor::Create(Profile* profile, 463 FileTaskExecutor* FileTaskExecutor::Create(Profile* profile,
435 const GURL source_url, 464 const GURL source_url,
436 const std::string& extension_id, 465 const std::string& extension_id,
466 TaskType task_type,
437 const std::string& action_id) { 467 const std::string& action_id) {
438 // Check out the extension ID and see if this is a drive task, 468 if (task_type == TASK_DRIVE) {
439 // and instantiate drive-specific executor if so.
440 if (StartsWithASCII(extension_id,
441 FileTaskExecutor::kDriveTaskExtensionPrefix,
442 false)) {
443 return new gdata::DriveTaskExecutor(profile, 469 return new gdata::DriveTaskExecutor(profile,
444 extension_id, // really app_id 470 extension_id, // really app_id
445 action_id); 471 action_id);
446 } else { 472 } else {
447 return new ExtensionTaskExecutor(profile, 473 return new ExtensionTaskExecutor(profile,
448 source_url, 474 source_url,
449 extension_id, 475 extension_id,
476 task_type,
450 action_id); 477 action_id);
451 } 478 }
452 } 479 }
453 480
454 FileTaskExecutor::FileTaskExecutor(Profile* profile) : profile_(profile) { 481 FileTaskExecutor::FileTaskExecutor(Profile* profile) : profile_(profile) {
455 } 482 }
456 483
457 FileTaskExecutor::~FileTaskExecutor() { 484 FileTaskExecutor::~FileTaskExecutor() {
458 } 485 }
459 486
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 int handler_pid_; 654 int handler_pid_;
628 std::string action_id_; 655 std::string action_id_;
629 std::vector<GURL> origin_file_urls_; 656 std::vector<GURL> origin_file_urls_;
630 DISALLOW_COPY_AND_ASSIGN(ExecuteTasksFileSystemCallbackDispatcher); 657 DISALLOW_COPY_AND_ASSIGN(ExecuteTasksFileSystemCallbackDispatcher);
631 }; 658 };
632 659
633 ExtensionTaskExecutor::ExtensionTaskExecutor( 660 ExtensionTaskExecutor::ExtensionTaskExecutor(
634 Profile* profile, 661 Profile* profile,
635 const GURL source_url, 662 const GURL source_url,
636 const std::string& extension_id, 663 const std::string& extension_id,
664 TaskType task_type,
637 const std::string& action_id) 665 const std::string& action_id)
638 : FileTaskExecutor(profile), 666 : FileTaskExecutor(profile),
639 source_url_(source_url), 667 source_url_(source_url),
640 extension_id_(extension_id), 668 extension_id_(extension_id),
669 task_type_(task_type),
641 action_id_(action_id) { 670 action_id_(action_id) {
642 } 671 }
643 672
644 ExtensionTaskExecutor::~ExtensionTaskExecutor() {} 673 ExtensionTaskExecutor::~ExtensionTaskExecutor() {}
645 674
646 bool ExtensionTaskExecutor::ExecuteAndNotify( 675 bool ExtensionTaskExecutor::ExecuteAndNotify(
647 const std::vector<GURL>& file_urls, 676 const std::vector<GURL>& file_urls,
648 const FileTaskFinishedCallback& done) { 677 const FileTaskFinishedCallback& done) {
649 ExtensionService* service = profile()->GetExtensionService(); 678 ExtensionService* service = profile()->GetExtensionService();
650 if (!service) 679 if (!service)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 753
725 const Extension* extension = GetExtension(); 754 const Extension* extension = GetExtension();
726 if (!extension) { 755 if (!extension) {
727 ExecuteDoneOnUIThread(false); 756 ExecuteDoneOnUIThread(false);
728 return; 757 return;
729 } 758 }
730 759
731 InitHandlerHostFileAccessPermissions( 760 InitHandlerHostFileAccessPermissions(
732 file_list, 761 file_list,
733 extension, 762 extension,
734 action_id_,
735 base::Bind( 763 base::Bind(
736 &ExtensionTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread, 764 &ExtensionTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread,
737 this, 765 this,
738 file_system_name, 766 file_system_name,
739 file_system_root, 767 file_system_root,
740 file_list, 768 file_list,
741 handler_pid)); 769 handler_pid));
742 } 770 }
743 771
744 void ExtensionTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread( 772 void ExtensionTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 int handler_pid_in, 809 int handler_pid_in,
782 extensions::ExtensionHost* host) { 810 extensions::ExtensionHost* host) {
783 int handler_pid = host ? host->render_process_host()->GetID() : 811 int handler_pid = host ? host->render_process_host()->GetID() :
784 handler_pid_in; 812 handler_pid_in;
785 813
786 if (handler_pid <= 0) { 814 if (handler_pid <= 0) {
787 ExecuteDoneOnUIThread(false); 815 ExecuteDoneOnUIThread(false);
788 return; 816 return;
789 } 817 }
790 818
819 // If we're a Web Intent action (to an extension), short-circuit and deliver
820 // the Web Intent via LaunchPlatformAppWithPath.
821 if (task_type_ == TASK_WEBINTENT) {
822 for (FileDefinitionList::const_iterator iter = file_list.begin();
823 iter != file_list.end(); ++iter) {
824 extensions::LaunchPlatformAppWithPath(
825 profile(), GetExtension(), iter->absolute_path);
826 }
827 ExecuteDoneOnUIThread(true);
828 return;
829 }
830 DCHECK(task_type_ == TASK_FILE);
831
791 extensions::EventRouter* event_router = profile()->GetExtensionEventRouter(); 832 extensions::EventRouter* event_router = profile()->GetExtensionEventRouter();
792 if (!event_router) { 833 if (!event_router) {
793 ExecuteDoneOnUIThread(false); 834 ExecuteDoneOnUIThread(false);
794 return; 835 return;
795 } 836 }
796 837
797 SetupHandlerHostFileAccessPermissions(handler_pid); 838 SetupHandlerHostFileAccessPermissions(handler_pid);
798 839
799 scoped_ptr<ListValue> event_args(new ListValue()); 840 scoped_ptr<ListValue> event_args(new ListValue());
800 event_args->Append(Value::CreateStringValue(action_id_)); 841 event_args->Append(Value::CreateStringValue(action_id_));
(...skipping 26 matching lines...) Expand all
827 868
828 event_router->DispatchEventToExtension( 869 event_router->DispatchEventToExtension(
829 extension_id_, std::string("fileBrowserHandler.onExecute"), 870 extension_id_, std::string("fileBrowserHandler.onExecute"),
830 event_args.Pass(), profile(), GURL()); 871 event_args.Pass(), profile(), GURL());
831 ExecuteDoneOnUIThread(true); 872 ExecuteDoneOnUIThread(true);
832 } 873 }
833 874
834 void ExtensionTaskExecutor::InitHandlerHostFileAccessPermissions( 875 void ExtensionTaskExecutor::InitHandlerHostFileAccessPermissions(
835 const FileDefinitionList& file_list, 876 const FileDefinitionList& file_list,
836 const Extension* handler_extension, 877 const Extension* handler_extension,
837 const std::string& action_id,
838 const base::Closure& callback) { 878 const base::Closure& callback) {
839 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 879 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
840 880
841 scoped_ptr<std::vector<FilePath> > gdata_paths(new std::vector<FilePath>); 881 scoped_ptr<std::vector<FilePath> > gdata_paths(new std::vector<FilePath>);
842 for (FileDefinitionList::const_iterator iter = file_list.begin(); 882 for (FileDefinitionList::const_iterator iter = file_list.begin();
843 iter != file_list.end(); 883 iter != file_list.end();
844 ++iter) { 884 ++iter) {
845 // Setup permission for file's absolute file. 885 // Setup permission for file's absolute file.
846 handler_host_permissions_.push_back(std::make_pair( 886 handler_host_permissions_.push_back(std::make_pair(iter->absolute_path,
847 iter->absolute_path, 887 GetAccessPermissionsForHandler(handler_extension,
848 GetAccessPermissionsForHandler(handler_extension, action_id))); 888 action_id_,
889 task_type_)));
849 890
850 if (gdata::util::IsUnderGDataMountPoint(iter->absolute_path)) 891 if (gdata::util::IsUnderGDataMountPoint(iter->absolute_path))
851 gdata_paths->push_back(iter->virtual_path); 892 gdata_paths->push_back(iter->virtual_path);
852 } 893 }
853 894
854 if (gdata_paths->empty()) { 895 if (gdata_paths->empty()) {
855 // Invoke callback if none of the files are on gdata mount point. 896 // Invoke callback if none of the files are on gdata mount point.
856 callback.Run(); 897 callback.Run();
857 return; 898 return;
858 } 899 }
(...skipping 13 matching lines...) Expand all
872 handler_pid, 913 handler_pid,
873 handler_host_permissions_[i].first, 914 handler_host_permissions_[i].first,
874 handler_host_permissions_[i].second); 915 handler_host_permissions_[i].second);
875 } 916 }
876 917
877 // We don't need this anymore. 918 // We don't need this anymore.
878 handler_host_permissions_.clear(); 919 handler_host_permissions_.clear();
879 } 920 }
880 921
881 } // namespace file_handler_util 922 } // namespace file_handler_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698