| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_manager/private_api_tasks.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_tasks.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chromeos/drive/drive_app_registry.h" | 7 #include "chrome/browser/chromeos/drive/drive_app_registry.h" |
| 8 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 8 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
| 9 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_handlers.
h" | 9 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_handlers.
h" |
| 10 #include "chrome/browser/chromeos/extensions/file_manager/file_tasks.h" | 10 #include "chrome/browser/chromeos/extensions/file_manager/file_tasks.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
| 23 #include "content/public/browser/storage_partition.h" | 23 #include "content/public/browser/storage_partition.h" |
| 24 #include "webkit/browser/fileapi/file_system_context.h" | 24 #include "webkit/browser/fileapi/file_system_context.h" |
| 25 #include "webkit/browser/fileapi/file_system_url.h" | 25 #include "webkit/browser/fileapi/file_system_url.h" |
| 26 | 26 |
| 27 using content::BrowserContext; | 27 using content::BrowserContext; |
| 28 using extensions::app_file_handler_util::FindFileHandlersForFiles; | 28 using extensions::app_file_handler_util::FindFileHandlersForFiles; |
| 29 using extensions::Extension; | 29 using extensions::Extension; |
| 30 using fileapi::FileSystemURL; | 30 using fileapi::FileSystemURL; |
| 31 | 31 |
| 32 namespace file_manager { | 32 namespace extensions { |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 // Error messages. | 35 // Error messages. |
| 36 const char kInvalidFileUrl[] = "Invalid file URL"; | 36 const char kInvalidFileUrl[] = "Invalid file URL"; |
| 37 | 37 |
| 38 // Default icon path for drive docs. | 38 // Default icon path for drive docs. |
| 39 const char kDefaultIcon[] = "images/filetype_generic.png"; | 39 const char kDefaultIcon[] = "images/filetype_generic.png"; |
| 40 | 40 |
| 41 // Logs the default task for debugging. | 41 // Logs the default task for debugging. |
| 42 void LogDefaultTask(const std::set<std::string>& mime_types, | 42 void LogDefaultTask(const std::set<std::string>& mime_types, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 121 |
| 122 // TODO(kaznacheev): Crack the task_id here, store it in the Executor | 122 // TODO(kaznacheev): Crack the task_id here, store it in the Executor |
| 123 // and avoid passing it around. | 123 // and avoid passing it around. |
| 124 | 124 |
| 125 // The second param is the list of files that need to be executed with this | 125 // The second param is the list of files that need to be executed with this |
| 126 // task. | 126 // task. |
| 127 ListValue* files_list = NULL; | 127 ListValue* files_list = NULL; |
| 128 if (!args_->GetList(1, &files_list)) | 128 if (!args_->GetList(1, &files_list)) |
| 129 return false; | 129 return false; |
| 130 | 130 |
| 131 file_tasks::TaskDescriptor task; | 131 file_manager::file_tasks::TaskDescriptor task; |
| 132 if (!file_tasks::ParseTaskID(task_id, &task)) { | 132 if (!file_manager::file_tasks::ParseTaskID(task_id, &task)) { |
| 133 LOG(WARNING) << "Invalid task " << task_id; | 133 LOG(WARNING) << "Invalid task " << task_id; |
| 134 return false; | 134 return false; |
| 135 } | 135 } |
| 136 | 136 |
| 137 if (!files_list->GetSize()) | 137 if (!files_list->GetSize()) |
| 138 return true; | 138 return true; |
| 139 | 139 |
| 140 scoped_refptr<fileapi::FileSystemContext> file_system_context = | 140 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 141 util::GetFileSystemContextForRenderViewHost( | 141 file_manager::util::GetFileSystemContextForRenderViewHost( |
| 142 profile(), render_view_host()); | 142 profile(), render_view_host()); |
| 143 | 143 |
| 144 std::vector<FileSystemURL> file_urls; | 144 std::vector<FileSystemURL> file_urls; |
| 145 for (size_t i = 0; i < files_list->GetSize(); i++) { | 145 for (size_t i = 0; i < files_list->GetSize(); i++) { |
| 146 std::string file_url_str; | 146 std::string file_url_str; |
| 147 if (!files_list->GetString(i, &file_url_str)) { | 147 if (!files_list->GetString(i, &file_url_str)) { |
| 148 error_ = kInvalidFileUrl; | 148 error_ = kInvalidFileUrl; |
| 149 return false; | 149 return false; |
| 150 } | 150 } |
| 151 FileSystemURL url = file_system_context->CrackURL(GURL(file_url_str)); | 151 FileSystemURL url = file_system_context->CrackURL(GURL(file_url_str)); |
| 152 if (!chromeos::FileSystemBackend::CanHandleURL(url)) { | 152 if (!chromeos::FileSystemBackend::CanHandleURL(url)) { |
| 153 error_ = kInvalidFileUrl; | 153 error_ = kInvalidFileUrl; |
| 154 return false; | 154 return false; |
| 155 } | 155 } |
| 156 file_urls.push_back(url); | 156 file_urls.push_back(url); |
| 157 } | 157 } |
| 158 | 158 |
| 159 int32 tab_id = util::GetTabId(dispatcher()); | 159 int32 tab_id = file_manager::util::GetTabId(dispatcher()); |
| 160 return file_tasks::ExecuteFileTask( | 160 return file_manager::file_tasks::ExecuteFileTask( |
| 161 profile(), | 161 profile(), |
| 162 source_url(), | 162 source_url(), |
| 163 extension_->id(), | 163 extension_->id(), |
| 164 tab_id, | 164 tab_id, |
| 165 task, | 165 task, |
| 166 file_urls, | 166 file_urls, |
| 167 base::Bind(&ExecuteTaskFunction::OnTaskExecuted, this)); | 167 base::Bind(&ExecuteTaskFunction::OnTaskExecuted, this)); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void ExecuteTaskFunction::OnTaskExecuted(bool success) { | 170 void ExecuteTaskFunction::OnTaskExecuted(bool success) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 if (file_path.empty()) | 204 if (file_path.empty()) |
| 205 continue; | 205 continue; |
| 206 | 206 |
| 207 ScopedVector<drive::DriveAppInfo> app_info_list; | 207 ScopedVector<drive::DriveAppInfo> app_info_list; |
| 208 registry->GetAppsForFile(file_path, mime_type, &app_info_list); | 208 registry->GetAppsForFile(file_path, mime_type, &app_info_list); |
| 209 | 209 |
| 210 if (is_first) { | 210 if (is_first) { |
| 211 // For the first file, we store all the info. | 211 // For the first file, we store all the info. |
| 212 for (size_t j = 0; j < app_info_list.size(); ++j) { | 212 for (size_t j = 0; j < app_info_list.size(); ++j) { |
| 213 const drive::DriveAppInfo& app_info = *app_info_list[j]; | 213 const drive::DriveAppInfo& app_info = *app_info_list[j]; |
| 214 GURL icon_url = util::FindPreferredIcon(app_info.app_icons, | 214 GURL icon_url = file_manager::util::FindPreferredIcon( |
| 215 util::kPreferredIconSize); | 215 app_info.app_icons, file_manager::util::kPreferredIconSize); |
| 216 task_info_map->insert(std::pair<std::string, TaskInfo>( | 216 task_info_map->insert(std::pair<std::string, TaskInfo>( |
| 217 file_tasks::MakeDriveAppTaskId(app_info.app_id), | 217 file_manager::file_tasks::MakeDriveAppTaskId(app_info.app_id), |
| 218 TaskInfo(app_info.app_name, icon_url))); | 218 TaskInfo(app_info.app_name, icon_url))); |
| 219 } | 219 } |
| 220 } else { | 220 } else { |
| 221 // For remaining files, take the intersection with the current result, | 221 // For remaining files, take the intersection with the current result, |
| 222 // based on the task id. | 222 // based on the task id. |
| 223 std::set<std::string> task_id_set; | 223 std::set<std::string> task_id_set; |
| 224 for (size_t j = 0; j < app_info_list.size(); ++j) { | 224 for (size_t j = 0; j < app_info_list.size(); ++j) { |
| 225 task_id_set.insert( | 225 task_id_set.insert(file_manager::file_tasks::MakeDriveAppTaskId( |
| 226 file_tasks::MakeDriveAppTaskId(app_info_list[j]->app_id)); | 226 app_info_list[j]->app_id)); |
| 227 } | 227 } |
| 228 for (TaskInfoMap::iterator iter = task_info_map->begin(); | 228 for (TaskInfoMap::iterator iter = task_info_map->begin(); |
| 229 iter != task_info_map->end(); ) { | 229 iter != task_info_map->end(); ) { |
| 230 if (task_id_set.find(iter->first) == task_id_set.end()) { | 230 if (task_id_set.find(iter->first) == task_id_set.end()) { |
| 231 task_info_map->erase(iter++); | 231 task_info_map->erase(iter++); |
| 232 } else { | 232 } else { |
| 233 ++iter; | 233 ++iter; |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 | 237 |
| 238 is_first = false; | 238 is_first = false; |
| 239 } | 239 } |
| 240 } | 240 } |
| 241 | 241 |
| 242 void GetFileTasksFunction::FindDefaultDriveTasks( | 242 void GetFileTasksFunction::FindDefaultDriveTasks( |
| 243 const PathAndMimeTypeSet& path_mime_set, | 243 const PathAndMimeTypeSet& path_mime_set, |
| 244 const TaskInfoMap& task_info_map, | 244 const TaskInfoMap& task_info_map, |
| 245 std::set<std::string>* default_tasks) { | 245 std::set<std::string>* default_tasks) { |
| 246 DCHECK(default_tasks); | 246 DCHECK(default_tasks); |
| 247 | 247 |
| 248 for (PathAndMimeTypeSet::const_iterator it = path_mime_set.begin(); | 248 for (PathAndMimeTypeSet::const_iterator it = path_mime_set.begin(); |
| 249 it != path_mime_set.end(); ++it) { | 249 it != path_mime_set.end(); ++it) { |
| 250 const base::FilePath& file_path = it->first; | 250 const base::FilePath& file_path = it->first; |
| 251 const std::string& mime_type = it->second; | 251 const std::string& mime_type = it->second; |
| 252 std::string task_id = file_tasks::GetDefaultTaskIdFromPrefs( | 252 std::string task_id = file_manager::file_tasks::GetDefaultTaskIdFromPrefs( |
| 253 profile_, mime_type, file_path.Extension()); | 253 profile_, mime_type, file_path.Extension()); |
| 254 if (task_info_map.find(task_id) != task_info_map.end()) | 254 if (task_info_map.find(task_id) != task_info_map.end()) |
| 255 default_tasks->insert(task_id); | 255 default_tasks->insert(task_id); |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 | 258 |
| 259 // static | 259 // static |
| 260 void GetFileTasksFunction::CreateDriveTasks( | 260 void GetFileTasksFunction::CreateDriveTasks( |
| 261 const TaskInfoMap& task_info_map, | 261 const TaskInfoMap& task_info_map, |
| 262 const std::set<std::string>& default_tasks, | 262 const std::set<std::string>& default_tasks, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 DCHECK(result_list); | 326 DCHECK(result_list); |
| 327 DCHECK(default_already_set); | 327 DCHECK(default_already_set); |
| 328 | 328 |
| 329 ExtensionService* service = profile_->GetExtensionService(); | 329 ExtensionService* service = profile_->GetExtensionService(); |
| 330 if (!service) | 330 if (!service) |
| 331 return; | 331 return; |
| 332 | 332 |
| 333 std::set<std::string> default_tasks; | 333 std::set<std::string> default_tasks; |
| 334 for (PathAndMimeTypeSet::iterator it = path_mime_set.begin(); | 334 for (PathAndMimeTypeSet::iterator it = path_mime_set.begin(); |
| 335 it != path_mime_set.end(); ++it) { | 335 it != path_mime_set.end(); ++it) { |
| 336 default_tasks.insert(file_tasks::GetDefaultTaskIdFromPrefs( | 336 default_tasks.insert(file_manager::file_tasks::GetDefaultTaskIdFromPrefs( |
| 337 profile_, it->second, it->first.Extension())); | 337 profile_, it->second, it->first.Extension())); |
| 338 } | 338 } |
| 339 | 339 |
| 340 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); | 340 for (ExtensionSet::const_iterator iter = service->extensions()->begin(); |
| 341 iter != service->extensions()->end(); | 341 iter != service->extensions()->end(); |
| 342 ++iter) { | 342 ++iter) { |
| 343 const Extension* extension = iter->get(); | 343 const Extension* extension = iter->get(); |
| 344 | 344 |
| 345 // We don't support using hosted apps to open files. | 345 // We don't support using hosted apps to open files. |
| 346 if (!extension->is_platform_app()) | 346 if (!extension->is_platform_app()) |
| 347 continue; | 347 continue; |
| 348 | 348 |
| 349 if (profile_->IsOffTheRecord() && | 349 if (profile_->IsOffTheRecord() && |
| 350 !service->IsIncognitoEnabled(extension->id())) | 350 !service->IsIncognitoEnabled(extension->id())) |
| 351 continue; | 351 continue; |
| 352 | 352 |
| 353 typedef std::vector<const extensions::FileHandlerInfo*> FileHandlerList; | 353 typedef std::vector<const extensions::FileHandlerInfo*> FileHandlerList; |
| 354 FileHandlerList file_handlers = | 354 FileHandlerList file_handlers = |
| 355 FindFileHandlersForFiles(*extension, path_mime_set); | 355 FindFileHandlersForFiles(*extension, path_mime_set); |
| 356 if (file_handlers.empty()) | 356 if (file_handlers.empty()) |
| 357 continue; | 357 continue; |
| 358 | 358 |
| 359 for (FileHandlerList::iterator i = file_handlers.begin(); | 359 for (FileHandlerList::iterator i = file_handlers.begin(); |
| 360 i != file_handlers.end(); ++i) { | 360 i != file_handlers.end(); ++i) { |
| 361 DictionaryValue* task = new DictionaryValue; | 361 DictionaryValue* task = new DictionaryValue; |
| 362 std::string task_id = file_tasks::MakeTaskID( | 362 std::string task_id = file_manager::file_tasks::MakeTaskID( |
| 363 extension->id(), file_tasks::TASK_TYPE_FILE_HANDLER, (*i)->id); | 363 extension->id(), |
| 364 file_manager::file_tasks::TASK_TYPE_FILE_HANDLER, |
| 365 (*i)->id); |
| 364 task->SetString("taskId", task_id); | 366 task->SetString("taskId", task_id); |
| 365 task->SetString("title", (*i)->title); | 367 task->SetString("title", (*i)->title); |
| 366 if (!(*default_already_set) && ContainsKey(default_tasks, task_id)) { | 368 if (!(*default_already_set) && ContainsKey(default_tasks, task_id)) { |
| 367 task->SetBoolean("isDefault", true); | 369 task->SetBoolean("isDefault", true); |
| 368 *default_already_set = true; | 370 *default_already_set = true; |
| 369 } else { | 371 } else { |
| 370 task->SetBoolean("isDefault", false); | 372 task->SetBoolean("isDefault", false); |
| 371 } | 373 } |
| 372 | 374 |
| 373 GURL best_icon = extensions::ExtensionIconSource::GetIconURL( | 375 GURL best_icon = extensions::ExtensionIconSource::GetIconURL( |
| 374 extension, | 376 extension, |
| 375 util::kPreferredIconSize, | 377 file_manager::util::kPreferredIconSize, |
| 376 ExtensionIconSet::MATCH_BIGGER, | 378 ExtensionIconSet::MATCH_BIGGER, |
| 377 false, // grayscale | 379 false, // grayscale |
| 378 NULL); // exists | 380 NULL); // exists |
| 379 if (!best_icon.is_empty()) | 381 if (!best_icon.is_empty()) |
| 380 task->SetString("iconUrl", best_icon.spec()); | 382 task->SetString("iconUrl", best_icon.spec()); |
| 381 else | 383 else |
| 382 task->SetString("iconUrl", kDefaultIcon); | 384 task->SetString("iconUrl", kDefaultIcon); |
| 383 | 385 |
| 384 task->SetBoolean("driveApp", false); | 386 task->SetBoolean("driveApp", false); |
| 385 result_list->Append(task); | 387 result_list->Append(task); |
| 386 } | 388 } |
| 387 } | 389 } |
| 388 } | 390 } |
| 389 | 391 |
| 390 void GetFileTasksFunction::FindFileBrowserHandlerTasks( | 392 void GetFileTasksFunction::FindFileBrowserHandlerTasks( |
| 391 const std::vector<GURL>& file_urls, | 393 const std::vector<GURL>& file_urls, |
| 392 const std::vector<base::FilePath>& file_paths, | 394 const std::vector<base::FilePath>& file_paths, |
| 393 ListValue* result_list, | 395 ListValue* result_list, |
| 394 bool* default_already_set) { | 396 bool* default_already_set) { |
| 395 DCHECK(!file_paths.empty()); | 397 DCHECK(!file_paths.empty()); |
| 396 DCHECK(!file_urls.empty()); | 398 DCHECK(!file_urls.empty()); |
| 397 DCHECK(result_list); | 399 DCHECK(result_list); |
| 398 DCHECK(default_already_set); | 400 DCHECK(default_already_set); |
| 399 | 401 |
| 400 file_browser_handlers::FileBrowserHandlerList common_tasks = | 402 file_manager::file_browser_handlers::FileBrowserHandlerList common_tasks = |
| 401 file_browser_handlers::FindCommonFileBrowserHandlers(profile_, file_urls); | 403 file_manager::file_browser_handlers::FindCommonFileBrowserHandlers( |
| 404 profile_, file_urls); |
| 402 if (common_tasks.empty()) | 405 if (common_tasks.empty()) |
| 403 return; | 406 return; |
| 404 file_browser_handlers::FileBrowserHandlerList default_tasks = | 407 file_manager::file_browser_handlers::FileBrowserHandlerList default_tasks = |
| 405 file_browser_handlers::FindDefaultFileBrowserHandlers( | 408 file_manager::file_browser_handlers::FindDefaultFileBrowserHandlers( |
| 406 profile_, file_paths, common_tasks); | 409 profile_, file_paths, common_tasks); |
| 407 | 410 |
| 408 ExtensionService* service = | 411 ExtensionService* service = |
| 409 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 412 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 410 for (file_browser_handlers::FileBrowserHandlerList::const_iterator iter = | 413 for (file_manager::file_browser_handlers::FileBrowserHandlerList:: |
| 411 common_tasks.begin(); | 414 const_iterator iter = common_tasks.begin(); |
| 412 iter != common_tasks.end(); | 415 iter != common_tasks.end(); |
| 413 ++iter) { | 416 ++iter) { |
| 414 const FileBrowserHandler* handler = *iter; | 417 const FileBrowserHandler* handler = *iter; |
| 415 const std::string extension_id = handler->extension_id(); | 418 const std::string extension_id = handler->extension_id(); |
| 416 const Extension* extension = service->GetExtensionById(extension_id, false); | 419 const Extension* extension = service->GetExtensionById(extension_id, false); |
| 417 CHECK(extension); | 420 CHECK(extension); |
| 418 DictionaryValue* task = new DictionaryValue; | 421 DictionaryValue* task = new DictionaryValue; |
| 419 task->SetString("taskId", file_tasks::MakeTaskID( | 422 task->SetString("taskId", file_manager::file_tasks::MakeTaskID( |
| 420 extension_id, | 423 extension_id, |
| 421 file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER, | 424 file_manager::file_tasks::TASK_TYPE_FILE_BROWSER_HANDLER, |
| 422 handler->id())); | 425 handler->id())); |
| 423 task->SetString("title", handler->title()); | 426 task->SetString("title", handler->title()); |
| 424 // TODO(zelidrag): Figure out how to expose icon URL that task defined in | 427 // TODO(zelidrag): Figure out how to expose icon URL that task defined in |
| 425 // manifest instead of the default extension icon. | 428 // manifest instead of the default extension icon. |
| 426 GURL icon = extensions::ExtensionIconSource::GetIconURL( | 429 GURL icon = extensions::ExtensionIconSource::GetIconURL( |
| 427 extension, | 430 extension, |
| 428 extension_misc::EXTENSION_ICON_BITTY, | 431 extension_misc::EXTENSION_ICON_BITTY, |
| 429 ExtensionIconSet::MATCH_BIGGER, | 432 ExtensionIconSet::MATCH_BIGGER, |
| 430 false, // grayscale | 433 false, // grayscale |
| 431 NULL); // exists | 434 NULL); // exists |
| (...skipping 27 matching lines...) Expand all Loading... |
| 459 ListValue* mime_types_list = NULL; | 462 ListValue* mime_types_list = NULL; |
| 460 if (!args_->GetList(1, &mime_types_list)) | 463 if (!args_->GetList(1, &mime_types_list)) |
| 461 return false; | 464 return false; |
| 462 | 465 |
| 463 // MIME types can either be empty, or there needs to be one for each file. | 466 // MIME types can either be empty, or there needs to be one for each file. |
| 464 if (mime_types_list->GetSize() != files_list->GetSize() && | 467 if (mime_types_list->GetSize() != files_list->GetSize() && |
| 465 mime_types_list->GetSize() != 0) | 468 mime_types_list->GetSize() != 0) |
| 466 return false; | 469 return false; |
| 467 | 470 |
| 468 scoped_refptr<fileapi::FileSystemContext> file_system_context = | 471 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 469 util::GetFileSystemContextForRenderViewHost( | 472 file_manager::util::GetFileSystemContextForRenderViewHost( |
| 470 profile(), render_view_host()); | 473 profile(), render_view_host()); |
| 471 | 474 |
| 472 // Collect all the URLs, convert them to GURLs, and crack all the urls into | 475 // Collect all the URLs, convert them to GURLs, and crack all the urls into |
| 473 // file paths. | 476 // file paths. |
| 474 PathAndMimeTypeSet path_mime_set; | 477 PathAndMimeTypeSet path_mime_set; |
| 475 std::vector<GURL> file_urls; | 478 std::vector<GURL> file_urls; |
| 476 std::vector<base::FilePath> file_paths; | 479 std::vector<base::FilePath> file_paths; |
| 477 bool has_google_document = false; | 480 bool has_google_document = false; |
| 478 for (size_t i = 0; i < files_list->GetSize(); ++i) { | 481 for (size_t i = 0; i < files_list->GetSize(); ++i) { |
| 479 std::string file_url_str; | 482 std::string file_url_str; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 490 file_system_context->CrackURL(file_url)); | 493 file_system_context->CrackURL(file_url)); |
| 491 if (!chromeos::FileSystemBackend::CanHandleURL(file_system_url)) | 494 if (!chromeos::FileSystemBackend::CanHandleURL(file_system_url)) |
| 492 continue; | 495 continue; |
| 493 const base::FilePath file_path = file_system_url.path(); | 496 const base::FilePath file_path = file_system_url.path(); |
| 494 | 497 |
| 495 file_urls.push_back(file_url); | 498 file_urls.push_back(file_url); |
| 496 file_paths.push_back(file_path); | 499 file_paths.push_back(file_path); |
| 497 | 500 |
| 498 // If MIME type is not provided, guess it from the file path. | 501 // If MIME type is not provided, guess it from the file path. |
| 499 if (mime_type.empty()) | 502 if (mime_type.empty()) |
| 500 mime_type = util::GetMimeTypeForPath(file_path); | 503 mime_type = file_manager::util::GetMimeTypeForPath(file_path); |
| 501 | 504 |
| 502 path_mime_set.insert(std::make_pair(file_path, mime_type)); | 505 path_mime_set.insert(std::make_pair(file_path, mime_type)); |
| 503 | 506 |
| 504 if (google_apis::ResourceEntry::ClassifyEntryKindByFileExtension( | 507 if (google_apis::ResourceEntry::ClassifyEntryKindByFileExtension( |
| 505 file_path) & | 508 file_path) & |
| 506 google_apis::ResourceEntry::KIND_OF_GOOGLE_DOCUMENT) { | 509 google_apis::ResourceEntry::KIND_OF_GOOGLE_DOCUMENT) { |
| 507 has_google_document = true; | 510 has_google_document = true; |
| 508 } | 511 } |
| 509 } | 512 } |
| 510 | 513 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 // First param is task id that was to the extension with setDefaultTask call. | 548 // First param is task id that was to the extension with setDefaultTask call. |
| 546 std::string task_id; | 549 std::string task_id; |
| 547 if (!args_->GetString(0, &task_id) || !task_id.size()) | 550 if (!args_->GetString(0, &task_id) || !task_id.size()) |
| 548 return false; | 551 return false; |
| 549 | 552 |
| 550 base::ListValue* file_url_list; | 553 base::ListValue* file_url_list; |
| 551 if (!args_->GetList(1, &file_url_list)) | 554 if (!args_->GetList(1, &file_url_list)) |
| 552 return false; | 555 return false; |
| 553 | 556 |
| 554 scoped_refptr<fileapi::FileSystemContext> file_system_context = | 557 scoped_refptr<fileapi::FileSystemContext> file_system_context = |
| 555 util::GetFileSystemContextForRenderViewHost( | 558 file_manager::util::GetFileSystemContextForRenderViewHost( |
| 556 profile(), render_view_host()); | 559 profile(), render_view_host()); |
| 557 | 560 |
| 558 std::set<std::string> suffixes = | 561 std::set<std::string> suffixes = |
| 559 GetUniqueSuffixes(file_url_list, file_system_context.get()); | 562 GetUniqueSuffixes(file_url_list, file_system_context.get()); |
| 560 | 563 |
| 561 // MIME types are an optional parameter. | 564 // MIME types are an optional parameter. |
| 562 base::ListValue* mime_type_list; | 565 base::ListValue* mime_type_list; |
| 563 std::set<std::string> mime_types; | 566 std::set<std::string> mime_types; |
| 564 if (args_->GetList(2, &mime_type_list) && !mime_type_list->empty()) { | 567 if (args_->GetList(2, &mime_type_list) && !mime_type_list->empty()) { |
| 565 if (mime_type_list->GetSize() != file_url_list->GetSize()) | 568 if (mime_type_list->GetSize() != file_url_list->GetSize()) |
| 566 return false; | 569 return false; |
| 567 mime_types = GetUniqueMimeTypes(mime_type_list); | 570 mime_types = GetUniqueMimeTypes(mime_type_list); |
| 568 } | 571 } |
| 569 | 572 |
| 570 if (VLOG_IS_ON(1)) | 573 if (VLOG_IS_ON(1)) |
| 571 LogDefaultTask(mime_types, suffixes, task_id); | 574 LogDefaultTask(mime_types, suffixes, task_id); |
| 572 | 575 |
| 573 // If there weren't any mime_types, and all the suffixes were blank, | 576 // If there weren't any mime_types, and all the suffixes were blank, |
| 574 // then we "succeed", but don't actually associate with anything. | 577 // then we "succeed", but don't actually associate with anything. |
| 575 // Otherwise, any time we set the default on a file with no extension | 578 // Otherwise, any time we set the default on a file with no extension |
| 576 // on the local drive, we'd fail. | 579 // on the local drive, we'd fail. |
| 577 // TODO(gspencer): Fix file manager so that it never tries to set default in | 580 // TODO(gspencer): Fix file manager so that it never tries to set default in |
| 578 // cases where extensionless local files are part of the selection. | 581 // cases where extensionless local files are part of the selection. |
| 579 if (suffixes.empty() && mime_types.empty()) { | 582 if (suffixes.empty() && mime_types.empty()) { |
| 580 SetResult(new base::FundamentalValue(true)); | 583 SetResult(new base::FundamentalValue(true)); |
| 581 return true; | 584 return true; |
| 582 } | 585 } |
| 583 | 586 |
| 584 file_tasks::UpdateDefaultTask(profile_, task_id, suffixes, mime_types); | 587 file_manager::file_tasks::UpdateDefaultTask( |
| 588 profile_, task_id, suffixes, mime_types); |
| 585 | 589 |
| 586 return true; | 590 return true; |
| 587 } | 591 } |
| 588 | 592 |
| 589 } // namespace file_manager | 593 } // namespace extensions |
| OLD | NEW |