Chromium Code Reviews| 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/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/extensions/file_manager_util.h" | 14 #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
| 15 #include "chrome/browser/chromeos/gdata/drive_file_system_util.h" | 15 #include "chrome/browser/chromeos/gdata/drive_file_system_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 typedef std::set<const FileBrowserHandler*> FileBrowserHandlerSet; | 54 typedef std::set<const FileBrowserHandler*> FileBrowserHandlerSet; |
| 58 | 55 |
| 59 const int kReadWriteFilePermissions = base::PLATFORM_FILE_OPEN | | 56 const int kReadWriteFilePermissions = base::PLATFORM_FILE_OPEN | |
| 60 base::PLATFORM_FILE_CREATE | | 57 base::PLATFORM_FILE_CREATE | |
| 61 base::PLATFORM_FILE_OPEN_ALWAYS | | 58 base::PLATFORM_FILE_OPEN_ALWAYS | |
| 62 base::PLATFORM_FILE_CREATE_ALWAYS | | 59 base::PLATFORM_FILE_CREATE_ALWAYS | |
| 63 base::PLATFORM_FILE_OPEN_TRUNCATED | | 60 base::PLATFORM_FILE_OPEN_TRUNCATED | |
| 64 base::PLATFORM_FILE_READ | | 61 base::PLATFORM_FILE_READ | |
| 65 base::PLATFORM_FILE_WRITE | | 62 base::PLATFORM_FILE_WRITE | |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 94 extension->file_browser_handlers()->begin(); | 91 extension->file_browser_handlers()->begin(); |
| 95 action_iter != extension->file_browser_handlers()->end(); | 92 action_iter != extension->file_browser_handlers()->end(); |
| 96 ++action_iter) { | 93 ++action_iter) { |
| 97 if (action_iter->get()->id() == action_id) | 94 if (action_iter->get()->id() == action_id) |
| 98 return action_iter->get(); | 95 return action_iter->get(); |
| 99 } | 96 } |
| 100 return NULL; | 97 return NULL; |
| 101 } | 98 } |
| 102 | 99 |
| 103 unsigned int GetAccessPermissionsForHandler(const Extension* extension, | 100 unsigned int GetAccessPermissionsForHandler(const Extension* extension, |
| 104 const std::string& action_id) { | 101 const std::string& action_id, |
| 102 TaskType task_type) { | |
| 103 if (task_type == TASK_WEBINTENT) | |
| 104 return kReadOnlyFilePermissions; | |
| 105 | |
| 105 const FileBrowserHandler* action = | 106 const FileBrowserHandler* action = |
| 106 FindFileBrowserHandler(extension, action_id); | 107 FindFileBrowserHandler(extension, action_id); |
| 107 if (!action) | 108 if (!action) |
| 108 return 0; | 109 return 0; |
| 109 unsigned int result = 0; | 110 unsigned int result = 0; |
| 110 if (action->CanRead()) | 111 if (action->CanRead()) |
| 111 result |= kReadOnlyFilePermissions; | 112 result |= kReadOnlyFilePermissions; |
| 112 if (action->CanWrite()) | 113 if (action->CanWrite()) |
| 113 result |= kReadWriteFilePermissions; | 114 result |= kReadWriteFilePermissions; |
| 114 // TODO(tbarzic): We don't handle Create yet. | 115 // TODO(tbarzic): We don't handle Create yet. |
| 115 return result; | 116 return result; |
| 116 } | 117 } |
| 117 | 118 |
| 118 | |
| 119 std::string EscapedUtf8ToLower(const std::string& str) { | 119 std::string EscapedUtf8ToLower(const std::string& str) { |
| 120 string16 utf16 = UTF8ToUTF16( | 120 string16 utf16 = UTF8ToUTF16( |
| 121 net::UnescapeURLComponent(str, net::UnescapeRule::NORMAL)); | 121 net::UnescapeURLComponent(str, net::UnescapeRule::NORMAL)); |
| 122 return net::EscapeUrlEncodedData( | 122 return net::EscapeUrlEncodedData( |
| 123 UTF16ToUTF8(base::i18n::ToLower(utf16)), | 123 UTF16ToUTF8(base::i18n::ToLower(utf16)), |
| 124 false /* do not replace space with plus */); | 124 false /* do not replace space with plus */); |
| 125 } | 125 } |
| 126 | 126 |
| 127 bool GetFileBrowserHandlers(Profile* profile, | 127 bool GetFileBrowserHandlers(Profile* profile, |
| 128 const GURL& selected_file_url, | 128 const GURL& selected_file_url, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 | 226 |
| 227 int GetReadWritePermissions() { | 227 int GetReadWritePermissions() { |
| 228 return kReadWriteFilePermissions; | 228 return kReadWriteFilePermissions; |
| 229 } | 229 } |
| 230 | 230 |
| 231 int GetReadOnlyPermissions() { | 231 int GetReadOnlyPermissions() { |
| 232 return kReadOnlyFilePermissions; | 232 return kReadOnlyFilePermissions; |
| 233 } | 233 } |
| 234 | 234 |
| 235 std::string MakeTaskID(const std::string& extension_id, | 235 std::string MakeTaskID(const std::string& extension_id, |
| 236 TaskType task_type, | |
| 236 const std::string& action_id) { | 237 const std::string& action_id) { |
| 237 return base::StringPrintf("%s|%s", extension_id.c_str(), action_id.c_str()); | 238 DCHECK(task_type == TASK_FILE |
| 238 } | 239 || task_type == TASK_DRIVE |
| 239 | 240 || task_type == TASK_WEBINTENT); |
| 240 std::string MakeDriveTaskID(const std::string& app_id, | 241 return base::StringPrintf("%s|%d|%s", |
|
tbarzic
2012/09/11 02:01:40
I'd rather make task_type string (or, if you keep
thorogood
2012/09/13 02:34:49
I agree with you. I've updated this CL with all th
thorogood
2012/09/19 07:07:17
just updating this as Done :)
| |
| 241 const std::string& action_id) { | 242 extension_id.c_str(), |
| 242 return MakeTaskID(FileTaskExecutor::kDriveTaskExtensionPrefix + app_id, | 243 task_type, |
| 243 action_id); | 244 action_id.c_str()); |
| 244 } | |
| 245 | |
| 246 bool CrackDriveTaskID(const std::string& task_id, | |
| 247 std::string* app_id, | |
| 248 std::string* action_id) { | |
| 249 std::string app_id_tmp; | |
| 250 std::string action_id_tmp; | |
| 251 if (!CrackTaskID(task_id, &app_id_tmp, &action_id_tmp)) | |
| 252 return false; | |
| 253 if (StartsWithASCII(app_id_tmp, | |
| 254 FileTaskExecutor::kDriveTaskExtensionPrefix, | |
| 255 false)) { | |
| 256 // Strip off the prefix from the extension ID so we convert it to an app id. | |
| 257 if (app_id) { | |
| 258 *app_id = app_id_tmp.substr( | |
| 259 FileTaskExecutor::kDriveTaskExtensionPrefixLength); | |
| 260 } | |
| 261 if (action_id) | |
| 262 *action_id = action_id_tmp; | |
| 263 return true; | |
| 264 } | |
| 265 return false; | |
| 266 } | 245 } |
| 267 | 246 |
| 268 // Breaks down task_id that is used between getFileTasks() and executeTask() on | 247 // Breaks down task_id that is used between getFileTasks() and executeTask() on |
| 269 // its building blocks. task_id field the following structure: | 248 // its building blocks. task_id field the following structure: |
| 270 // <extension-id>|<task-action-id> | 249 // <extension-id>|<task-type>|<task-action-id> |
| 271 bool CrackTaskID(const std::string& task_id, | 250 bool CrackTaskID(const std::string& task_id, |
| 272 std::string* extension_id, | 251 std::string* extension_id, |
| 252 TaskType* task_type, | |
| 273 std::string* action_id) { | 253 std::string* action_id) { |
| 274 std::vector<std::string> result; | 254 std::vector<std::string> result; |
| 275 int count = Tokenize(task_id, std::string("|"), &result); | 255 int count = Tokenize(task_id, std::string("|"), &result); |
| 276 if (count != 2) | 256 if (count != 3) |
|
tbarzic
2012/09/11 02:01:40
Since task ids are persisted in prefs, we should p
thorogood
2012/09/13 02:34:49
Sounds good. If we see two components I'll try to
| |
| 277 return false; | 257 return false; |
| 258 | |
| 278 if (extension_id) | 259 if (extension_id) |
| 279 *extension_id = result[0]; | 260 *extension_id = result[0]; |
| 261 | |
| 262 if (task_type) { | |
| 263 *task_type = file_handler_util::TaskType(atoi(result[1].c_str())); | |
| 264 DCHECK(*task_type == TASK_FILE | |
| 265 || *task_type == TASK_DRIVE | |
| 266 || *task_type == TASK_WEBINTENT); | |
| 267 } | |
| 268 | |
| 280 if (action_id) | 269 if (action_id) |
| 281 *action_id = result[1]; | 270 *action_id = result[2]; |
| 271 | |
| 282 return true; | 272 return true; |
| 283 } | 273 } |
| 284 | 274 |
| 285 // Find a specific handler in the handler list. | 275 // Find a specific handler in the handler list. |
| 286 FileBrowserHandlerSet::iterator FindHandler( | 276 FileBrowserHandlerSet::iterator FindHandler( |
| 287 FileBrowserHandlerSet* handler_set, | 277 FileBrowserHandlerSet* handler_set, |
| 288 const std::string& extension_id, | 278 const std::string& extension_id, |
| 289 const std::string& id) { | 279 const std::string& id) { |
| 290 FileBrowserHandlerSet::iterator iter = handler_set->begin(); | 280 FileBrowserHandlerSet::iterator iter = handler_set->begin(); |
| 291 while (iter != handler_set->end() && | 281 while (iter != handler_set->end() && |
| 292 !((*iter)->extension_id() == extension_id && | 282 !((*iter)->extension_id() == extension_id && |
| 293 (*iter)->id() == id)) { | 283 (*iter)->id() == id)) { |
| 294 iter++; | 284 iter++; |
| 295 } | 285 } |
| 296 return iter; | 286 return iter; |
| 297 } | 287 } |
| 298 | 288 |
| 289 // Given the list of selected files, returns array of file action tasks | |
| 290 // that are shared between them. | |
| 299 void FindDefaultTasks(Profile* profile, | 291 void FindDefaultTasks(Profile* profile, |
| 300 const std::vector<GURL>& files_list, | 292 const std::vector<GURL>& files_list, |
| 301 const FileBrowserHandlerSet& common_tasks, | 293 const FileBrowserHandlerSet& common_tasks, |
| 302 FileBrowserHandlerSet* default_tasks) { | 294 FileBrowserHandlerSet* default_tasks) { |
| 303 DCHECK(default_tasks); | 295 DCHECK(default_tasks); |
| 304 default_tasks->clear(); | 296 default_tasks->clear(); |
| 305 | 297 |
| 306 std::set<std::string> default_ids; | 298 std::set<std::string> default_ids; |
| 307 for (std::vector<GURL>::const_iterator it = files_list.begin(); | 299 for (std::vector<GURL>::const_iterator it = files_list.begin(); |
| 308 it != files_list.end(); ++it) { | 300 it != files_list.end(); ++it) { |
| 309 // Get the default task for this file based only on the extension (since | 301 // Get the default task for this file based only on the extension (since |
| 310 // we don't have MIME types here), and add it to the set of default tasks. | 302 // we don't have MIME types here), and add it to the set of default tasks. |
| 311 fileapi::FileSystemURL filesystem_url(*it); | 303 fileapi::FileSystemURL filesystem_url(*it); |
| 312 if (filesystem_url.is_valid() && | 304 if (filesystem_url.is_valid() && |
| 313 (filesystem_url.type() == fileapi::kFileSystemTypeDrive || | 305 (filesystem_url.type() == fileapi::kFileSystemTypeDrive || |
| 314 filesystem_url.type() == fileapi::kFileSystemTypeNativeMedia || | 306 filesystem_url.type() == fileapi::kFileSystemTypeNativeMedia || |
| 315 filesystem_url.type() == fileapi::kFileSystemTypeNativeLocal)) { | 307 filesystem_url.type() == fileapi::kFileSystemTypeNativeLocal)) { |
| 316 std::string task_id = file_handler_util::GetDefaultTaskIdFromPrefs( | 308 std::string task_id = file_handler_util::GetDefaultTaskIdFromPrefs( |
| 317 profile, "", filesystem_url.virtual_path().Extension()); | 309 profile, "", filesystem_url.virtual_path().Extension()); |
| 318 if (!task_id.empty()) | 310 if (!task_id.empty()) |
| 319 default_ids.insert(task_id); | 311 default_ids.insert(task_id); |
| 320 } | 312 } |
| 321 } | 313 } |
| 322 | 314 |
| 323 // Convert the default task IDs collected above to one of the handler pointers | 315 // Convert the default task IDs collected above to one of the handler pointers |
| 324 // from common_tasks. | 316 // from common_tasks. |
| 325 for (FileBrowserHandlerSet::const_iterator task_iter = common_tasks.begin(); | 317 for (FileBrowserHandlerSet::const_iterator task_iter = common_tasks.begin(); |
| 326 task_iter != common_tasks.end(); ++task_iter) { | 318 task_iter != common_tasks.end(); ++task_iter) { |
| 327 std::string task_id = MakeTaskID((*task_iter)->extension_id(), | 319 std::string task_id = MakeTaskID((*task_iter)->extension_id(), TASK_FILE, |
| 328 (*task_iter)->id()); | 320 (*task_iter)->id()); |
| 329 for (std::set<std::string>::iterator default_iter = default_ids.begin(); | 321 for (std::set<std::string>::iterator default_iter = default_ids.begin(); |
| 330 default_iter != default_ids.end(); ++default_iter) { | 322 default_iter != default_ids.end(); ++default_iter) { |
| 331 if (task_id == *default_iter) { | 323 if (task_id == *default_iter) { |
| 332 default_tasks->insert(*task_iter); | 324 default_tasks->insert(*task_iter); |
| 333 break; | 325 break; |
| 334 } | 326 } |
| 335 } | 327 } |
| 336 } | 328 } |
| 337 } | 329 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 virtual bool ExecuteAndNotify(const std::vector<GURL>& file_urls, | 411 virtual bool ExecuteAndNotify(const std::vector<GURL>& file_urls, |
| 420 const FileTaskFinishedCallback& done) OVERRIDE; | 412 const FileTaskFinishedCallback& done) OVERRIDE; |
| 421 | 413 |
| 422 private: | 414 private: |
| 423 // FileTaskExecutor is the only class allowed to create one. | 415 // FileTaskExecutor is the only class allowed to create one. |
| 424 friend class FileTaskExecutor; | 416 friend class FileTaskExecutor; |
| 425 | 417 |
| 426 ExtensionTaskExecutor(Profile* profile, | 418 ExtensionTaskExecutor(Profile* profile, |
| 427 const GURL source_url, | 419 const GURL source_url, |
| 428 const std::string& extension_id, | 420 const std::string& extension_id, |
| 421 TaskType task_type, | |
| 429 const std::string& action_id); | 422 const std::string& action_id); |
| 430 virtual ~ExtensionTaskExecutor(); | 423 virtual ~ExtensionTaskExecutor(); |
| 431 | 424 |
| 432 struct FileDefinition { | 425 struct FileDefinition { |
| 433 FileDefinition(); | 426 FileDefinition(); |
| 434 ~FileDefinition(); | 427 ~FileDefinition(); |
| 435 | 428 |
| 436 GURL target_file_url; | 429 GURL target_file_url; |
| 437 FilePath virtual_path; | 430 FilePath virtual_path; |
| 438 FilePath absolute_path; | 431 FilePath absolute_path; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 457 const GURL& file_system_root, | 450 const GURL& file_system_root, |
| 458 const FileDefinitionList& file_list, | 451 const FileDefinitionList& file_list, |
| 459 int handler_pid_in, | 452 int handler_pid_in, |
| 460 extensions::ExtensionHost* host); | 453 extensions::ExtensionHost* host); |
| 461 | 454 |
| 462 // Populates |handler_host_permissions| with file path-permissions pairs that | 455 // Populates |handler_host_permissions| with file path-permissions pairs that |
| 463 // will be given to the handler extension host process. | 456 // will be given to the handler extension host process. |
| 464 void InitHandlerHostFileAccessPermissions( | 457 void InitHandlerHostFileAccessPermissions( |
| 465 const FileDefinitionList& file_list, | 458 const FileDefinitionList& file_list, |
| 466 const extensions::Extension* handler_extension, | 459 const extensions::Extension* handler_extension, |
| 467 const std::string& action_id, | |
| 468 const base::Closure& callback); | 460 const base::Closure& callback); |
| 469 | 461 |
| 470 // Invoked upon completion of InitHandlerHostFileAccessPermissions initiated | 462 // Invoked upon completion of InitHandlerHostFileAccessPermissions initiated |
| 471 // by ExecuteFileActionsOnUIThread. | 463 // by ExecuteFileActionsOnUIThread. |
| 472 void OnInitAccessForExecuteFileActionsOnUIThread( | 464 void OnInitAccessForExecuteFileActionsOnUIThread( |
| 473 const std::string& file_system_name, | 465 const std::string& file_system_name, |
| 474 const GURL& file_system_root, | 466 const GURL& file_system_root, |
| 475 const FileDefinitionList& file_list, | 467 const FileDefinitionList& file_list, |
| 476 int handler_pid); | 468 int handler_pid); |
| 477 | 469 |
| 478 // Registers file permissions from |handler_host_permissions_| with | 470 // Registers file permissions from |handler_host_permissions_| with |
| 479 // ChildProcessSecurityPolicy for process with id |handler_pid|. | 471 // ChildProcessSecurityPolicy for process with id |handler_pid|. |
| 480 void SetupHandlerHostFileAccessPermissions(int handler_pid); | 472 void SetupHandlerHostFileAccessPermissions(int handler_pid); |
| 481 | 473 |
| 482 // Helper function to get the extension pointer. | 474 // Helper function to get the extension pointer. |
| 483 const extensions::Extension* GetExtension(); | 475 const extensions::Extension* GetExtension(); |
| 484 | 476 |
| 485 const GURL source_url_; | 477 const GURL source_url_; |
| 486 const std::string extension_id_; | 478 const std::string extension_id_; |
| 479 TaskType task_type_; | |
| 487 const std::string action_id_; | 480 const std::string action_id_; |
| 488 FileTaskFinishedCallback done_; | 481 FileTaskFinishedCallback done_; |
| 489 | 482 |
| 490 // (File path, permission for file path) pairs for the handler. | 483 // (File path, permission for file path) pairs for the handler. |
| 491 std::vector<std::pair<FilePath, int> > handler_host_permissions_; | 484 std::vector<std::pair<FilePath, int> > handler_host_permissions_; |
| 492 }; | 485 }; |
| 493 | 486 |
| 494 // static | 487 // static |
| 495 FileTaskExecutor* FileTaskExecutor::Create(Profile* profile, | 488 FileTaskExecutor* FileTaskExecutor::Create(Profile* profile, |
| 496 const GURL source_url, | 489 const GURL source_url, |
| 497 const std::string& extension_id, | 490 const std::string& extension_id, |
| 491 TaskType task_type, | |
| 498 const std::string& action_id) { | 492 const std::string& action_id) { |
| 499 // Check out the extension ID and see if this is a drive task, | 493 if (task_type == TASK_DRIVE) { |
| 500 // and instantiate drive-specific executor if so. | |
| 501 if (StartsWithASCII(extension_id, | |
| 502 FileTaskExecutor::kDriveTaskExtensionPrefix, | |
| 503 false)) { | |
| 504 return new gdata::DriveTaskExecutor(profile, | 494 return new gdata::DriveTaskExecutor(profile, |
| 505 extension_id, // really app_id | 495 extension_id, // really app_id |
| 506 action_id); | 496 action_id); |
| 507 } else { | 497 } else { |
| 508 return new ExtensionTaskExecutor(profile, | 498 return new ExtensionTaskExecutor(profile, |
| 509 source_url, | 499 source_url, |
| 510 extension_id, | 500 extension_id, |
| 501 task_type, | |
| 511 action_id); | 502 action_id); |
| 512 } | 503 } |
| 513 } | 504 } |
| 514 | 505 |
| 515 FileTaskExecutor::FileTaskExecutor(Profile* profile) : profile_(profile) { | 506 FileTaskExecutor::FileTaskExecutor(Profile* profile) : profile_(profile) { |
| 516 } | 507 } |
| 517 | 508 |
| 518 FileTaskExecutor::~FileTaskExecutor() { | 509 FileTaskExecutor::~FileTaskExecutor() { |
| 519 } | 510 } |
| 520 | 511 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 688 int handler_pid_; | 679 int handler_pid_; |
| 689 std::string action_id_; | 680 std::string action_id_; |
| 690 std::vector<GURL> origin_file_urls_; | 681 std::vector<GURL> origin_file_urls_; |
| 691 DISALLOW_COPY_AND_ASSIGN(ExecuteTasksFileSystemCallbackDispatcher); | 682 DISALLOW_COPY_AND_ASSIGN(ExecuteTasksFileSystemCallbackDispatcher); |
| 692 }; | 683 }; |
| 693 | 684 |
| 694 ExtensionTaskExecutor::ExtensionTaskExecutor( | 685 ExtensionTaskExecutor::ExtensionTaskExecutor( |
| 695 Profile* profile, | 686 Profile* profile, |
| 696 const GURL source_url, | 687 const GURL source_url, |
| 697 const std::string& extension_id, | 688 const std::string& extension_id, |
| 689 TaskType task_type, | |
| 698 const std::string& action_id) | 690 const std::string& action_id) |
| 699 : FileTaskExecutor(profile), | 691 : FileTaskExecutor(profile), |
| 700 source_url_(source_url), | 692 source_url_(source_url), |
| 701 extension_id_(extension_id), | 693 extension_id_(extension_id), |
| 694 task_type_(task_type), | |
| 702 action_id_(action_id) { | 695 action_id_(action_id) { |
| 703 } | 696 } |
| 704 | 697 |
| 705 ExtensionTaskExecutor::~ExtensionTaskExecutor() {} | 698 ExtensionTaskExecutor::~ExtensionTaskExecutor() {} |
| 706 | 699 |
| 707 bool ExtensionTaskExecutor::ExecuteAndNotify( | 700 bool ExtensionTaskExecutor::ExecuteAndNotify( |
| 708 const std::vector<GURL>& file_urls, | 701 const std::vector<GURL>& file_urls, |
| 709 const FileTaskFinishedCallback& done) { | 702 const FileTaskFinishedCallback& done) { |
| 710 ExtensionService* service = profile()->GetExtensionService(); | 703 ExtensionService* service = profile()->GetExtensionService(); |
| 711 if (!service) | 704 if (!service) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 785 | 778 |
| 786 const Extension* extension = GetExtension(); | 779 const Extension* extension = GetExtension(); |
| 787 if (!extension) { | 780 if (!extension) { |
| 788 ExecuteDoneOnUIThread(false); | 781 ExecuteDoneOnUIThread(false); |
| 789 return; | 782 return; |
| 790 } | 783 } |
| 791 | 784 |
| 792 InitHandlerHostFileAccessPermissions( | 785 InitHandlerHostFileAccessPermissions( |
| 793 file_list, | 786 file_list, |
| 794 extension, | 787 extension, |
| 795 action_id_, | |
| 796 base::Bind( | 788 base::Bind( |
| 797 &ExtensionTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread, | 789 &ExtensionTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread, |
| 798 this, | 790 this, |
| 799 file_system_name, | 791 file_system_name, |
| 800 file_system_root, | 792 file_system_root, |
| 801 file_list, | 793 file_list, |
| 802 handler_pid)); | 794 handler_pid)); |
| 803 } | 795 } |
| 804 | 796 |
| 805 void ExtensionTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread( | 797 void ExtensionTaskExecutor::OnInitAccessForExecuteFileActionsOnUIThread( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 842 int handler_pid_in, | 834 int handler_pid_in, |
| 843 extensions::ExtensionHost* host) { | 835 extensions::ExtensionHost* host) { |
| 844 int handler_pid = host ? host->render_process_host()->GetID() : | 836 int handler_pid = host ? host->render_process_host()->GetID() : |
| 845 handler_pid_in; | 837 handler_pid_in; |
| 846 | 838 |
| 847 if (handler_pid <= 0) { | 839 if (handler_pid <= 0) { |
| 848 ExecuteDoneOnUIThread(false); | 840 ExecuteDoneOnUIThread(false); |
| 849 return; | 841 return; |
| 850 } | 842 } |
| 851 | 843 |
| 844 // If we're a Web Intent action (to an extension), short-circuit and deliver | |
| 845 // the Web Intent via LaunchPlatformAppWithPath. | |
| 846 if (task_type_ == TASK_WEBINTENT) { | |
| 847 for (FileDefinitionList::const_iterator iter = file_list.begin(); | |
|
tbarzic
2012/09/11 02:01:40
why don't you create a separate executor for inten
thorogood
2012/09/13 02:34:49
Yup. You're totally right. This is much more conci
| |
| 848 iter != file_list.end(); ++iter) { | |
| 849 extensions::LaunchPlatformAppWithPath( | |
| 850 profile(), GetExtension(), iter->absolute_path); | |
| 851 } | |
| 852 ExecuteDoneOnUIThread(true); | |
| 853 return; | |
| 854 } | |
| 855 DCHECK_EQ(task_type_, TASK_FILE); | |
| 856 | |
| 852 extensions::EventRouter* event_router = profile()->GetExtensionEventRouter(); | 857 extensions::EventRouter* event_router = profile()->GetExtensionEventRouter(); |
| 853 if (!event_router) { | 858 if (!event_router) { |
| 854 ExecuteDoneOnUIThread(false); | 859 ExecuteDoneOnUIThread(false); |
| 855 return; | 860 return; |
| 856 } | 861 } |
| 857 | 862 |
| 858 SetupHandlerHostFileAccessPermissions(handler_pid); | 863 SetupHandlerHostFileAccessPermissions(handler_pid); |
| 859 | 864 |
| 860 scoped_ptr<ListValue> event_args(new ListValue()); | 865 scoped_ptr<ListValue> event_args(new ListValue()); |
| 861 event_args->Append(Value::CreateStringValue(action_id_)); | 866 event_args->Append(Value::CreateStringValue(action_id_)); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 888 | 893 |
| 889 event_router->DispatchEventToExtension( | 894 event_router->DispatchEventToExtension( |
| 890 extension_id_, std::string("fileBrowserHandler.onExecute"), | 895 extension_id_, std::string("fileBrowserHandler.onExecute"), |
| 891 event_args.Pass(), profile(), GURL()); | 896 event_args.Pass(), profile(), GURL()); |
| 892 ExecuteDoneOnUIThread(true); | 897 ExecuteDoneOnUIThread(true); |
| 893 } | 898 } |
| 894 | 899 |
| 895 void ExtensionTaskExecutor::InitHandlerHostFileAccessPermissions( | 900 void ExtensionTaskExecutor::InitHandlerHostFileAccessPermissions( |
| 896 const FileDefinitionList& file_list, | 901 const FileDefinitionList& file_list, |
| 897 const Extension* handler_extension, | 902 const Extension* handler_extension, |
| 898 const std::string& action_id, | |
| 899 const base::Closure& callback) { | 903 const base::Closure& callback) { |
| 900 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 904 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 901 | 905 |
| 902 scoped_ptr<std::vector<FilePath> > gdata_paths(new std::vector<FilePath>); | 906 scoped_ptr<std::vector<FilePath> > gdata_paths(new std::vector<FilePath>); |
| 903 for (FileDefinitionList::const_iterator iter = file_list.begin(); | 907 for (FileDefinitionList::const_iterator iter = file_list.begin(); |
| 904 iter != file_list.end(); | 908 iter != file_list.end(); |
| 905 ++iter) { | 909 ++iter) { |
| 906 // Setup permission for file's absolute file. | 910 // Setup permission for file's absolute file. |
| 907 handler_host_permissions_.push_back(std::make_pair( | 911 handler_host_permissions_.push_back(std::make_pair(iter->absolute_path, |
| 908 iter->absolute_path, | 912 GetAccessPermissionsForHandler(handler_extension, |
| 909 GetAccessPermissionsForHandler(handler_extension, action_id))); | 913 action_id_, |
| 914 task_type_))); | |
| 910 | 915 |
| 911 if (gdata::util::IsUnderGDataMountPoint(iter->absolute_path)) | 916 if (gdata::util::IsUnderGDataMountPoint(iter->absolute_path)) |
| 912 gdata_paths->push_back(iter->virtual_path); | 917 gdata_paths->push_back(iter->virtual_path); |
| 913 } | 918 } |
| 914 | 919 |
| 915 if (gdata_paths->empty()) { | 920 if (gdata_paths->empty()) { |
| 916 // Invoke callback if none of the files are on gdata mount point. | 921 // Invoke callback if none of the files are on gdata mount point. |
| 917 callback.Run(); | 922 callback.Run(); |
| 918 return; | 923 return; |
| 919 } | 924 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 933 handler_pid, | 938 handler_pid, |
| 934 handler_host_permissions_[i].first, | 939 handler_host_permissions_[i].first, |
| 935 handler_host_permissions_[i].second); | 940 handler_host_permissions_[i].second); |
| 936 } | 941 } |
| 937 | 942 |
| 938 // We don't need this anymore. | 943 // We don't need this anymore. |
| 939 handler_host_permissions_.clear(); | 944 handler_host_permissions_.clear(); |
| 940 } | 945 } |
| 941 | 946 |
| 942 } // namespace file_handler_util | 947 } // namespace file_handler_util |
| OLD | NEW |