OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_file_browser_private_api.h" | 5 #include "chrome/browser/extensions/extension_file_browser_private_api.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 #include "webkit/fileapi/file_system_util.h" | 49 #include "webkit/fileapi/file_system_util.h" |
50 #include "ui/base/l10n/l10n_util.h" | 50 #include "ui/base/l10n/l10n_util.h" |
51 | 51 |
52 #ifdef OS_CHROMEOS | 52 #ifdef OS_CHROMEOS |
53 #include "chrome/browser/chromeos/cros/cros_library.h" | 53 #include "chrome/browser/chromeos/cros/cros_library.h" |
54 #endif | 54 #endif |
55 | 55 |
56 // Error messages. | 56 // Error messages. |
57 const char kFileError[] = "File error %d"; | 57 const char kFileError[] = "File error %d"; |
58 const char kInvalidFileUrl[] = "Invalid file URL"; | 58 const char kInvalidFileUrl[] = "Invalid file URL"; |
| 59 #ifdef OS_CHROMEOS |
59 const char kVolumeDevicePathNotFound[] = "Device path not found"; | 60 const char kVolumeDevicePathNotFound[] = "Device path not found"; |
| 61 #endif |
60 | 62 |
61 #ifdef OS_CHROMEOS | 63 #ifdef OS_CHROMEOS |
62 // Volume type strings. | 64 // Volume type strings. |
63 const std::string kVolumeTypeFlash = "flash"; | 65 const std::string kVolumeTypeFlash = "flash"; |
64 const std::string kVolumeTypeOptical = "optical"; | 66 const std::string kVolumeTypeOptical = "optical"; |
65 const std::string kVolumeTypeHardDrive = "hdd"; | 67 const std::string kVolumeTypeHardDrive = "hdd"; |
66 const std::string kVolumeTypeUnknown = "undefined"; | 68 const std::string kVolumeTypeUnknown = "undefined"; |
67 #endif | 69 #endif |
68 | 70 |
69 // Internal task ids. | 71 // Internal task ids. |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 BrowserThread::PostTask( | 536 BrowserThread::PostTask( |
535 BrowserThread::UI, FROM_HERE, | 537 BrowserThread::UI, FROM_HERE, |
536 NewRunnableMethod(this, | 538 NewRunnableMethod(this, |
537 &FileWatchBrowserFunctionBase::RespondOnUIThread, | 539 &FileWatchBrowserFunctionBase::RespondOnUIThread, |
538 true)); | 540 true)); |
539 } | 541 } |
540 | 542 |
541 bool AddFileWatchBrowserFunction::PerformFileWatchOperation( | 543 bool AddFileWatchBrowserFunction::PerformFileWatchOperation( |
542 const FilePath& local_path, const FilePath& virtual_path, | 544 const FilePath& local_path, const FilePath& virtual_path, |
543 const std::string& extension_id) { | 545 const std::string& extension_id) { |
544 #if defined(OS_CHROMEOS) | |
545 return profile_->GetExtensionService()->file_browser_event_router()-> | 546 return profile_->GetExtensionService()->file_browser_event_router()-> |
546 AddFileWatch(local_path, virtual_path, extension_id); | 547 AddFileWatch(local_path, virtual_path, extension_id); |
547 #else | |
548 return true; | |
549 #endif // OS_CHROMEOS | |
550 } | 548 } |
551 | 549 |
552 bool RemoveFileWatchBrowserFunction::PerformFileWatchOperation( | 550 bool RemoveFileWatchBrowserFunction::PerformFileWatchOperation( |
553 const FilePath& local_path, const FilePath& unused, | 551 const FilePath& local_path, const FilePath& unused, |
554 const std::string& extension_id) { | 552 const std::string& extension_id) { |
555 #if defined(OS_CHROMEOS) | |
556 profile_->GetExtensionService()->file_browser_event_router()-> | 553 profile_->GetExtensionService()->file_browser_event_router()-> |
557 RemoveFileWatch(local_path, extension_id); | 554 RemoveFileWatch(local_path, extension_id); |
558 #endif | |
559 return true; | 555 return true; |
560 } | 556 } |
561 | 557 |
562 bool GetFileTasksFileBrowserFunction::RunImpl() { | 558 bool GetFileTasksFileBrowserFunction::RunImpl() { |
563 ListValue* files_list = NULL; | 559 ListValue* files_list = NULL; |
564 if (!args_->GetList(0, &files_list)) | 560 if (!args_->GetList(0, &files_list)) |
565 return false; | 561 return false; |
566 | 562 |
567 std::vector<GURL> file_urls; | 563 std::vector<GURL> file_urls; |
568 for (size_t i = 0; i < files_list->GetSize(); ++i) { | 564 for (size_t i = 0; i < files_list->GetSize(); ++i) { |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 } | 1170 } |
1175 | 1171 |
1176 std::string mount_type_str; | 1172 std::string mount_type_str; |
1177 if (!args_->GetString(1, &mount_type_str)) { | 1173 if (!args_->GetString(1, &mount_type_str)) { |
1178 return false; | 1174 return false; |
1179 } | 1175 } |
1180 | 1176 |
1181 UrlList file_paths; | 1177 UrlList file_paths; |
1182 file_paths.push_back(GURL(file_url)); | 1178 file_paths.push_back(GURL(file_url)); |
1183 | 1179 |
1184 #if defined(OS_CHROMEOS) | |
1185 chromeos::MountPathOptions options; | 1180 chromeos::MountPathOptions options; |
1186 if (args_->GetSize() == 3) { | 1181 if (args_->GetSize() == 3) { |
1187 DictionaryValue *dict; | 1182 DictionaryValue *dict; |
1188 if (!args_->GetDictionary(2, &dict)) { | 1183 if (!args_->GetDictionary(2, &dict)) { |
1189 NOTREACHED(); | 1184 NOTREACHED(); |
1190 } | 1185 } |
1191 | 1186 |
1192 for (base::DictionaryValue::key_iterator it = dict->begin_keys(); | 1187 for (base::DictionaryValue::key_iterator it = dict->begin_keys(); |
1193 it != dict->end_keys(); | 1188 it != dict->end_keys(); |
1194 ++it) { | 1189 ++it) { |
1195 std::string value; | 1190 std::string value; |
1196 if (!dict->GetString(*it, &value)) { | 1191 if (!dict->GetString(*it, &value)) { |
1197 NOTREACHED(); | 1192 NOTREACHED(); |
1198 } | 1193 } |
1199 | 1194 |
1200 options.push_back(chromeos::MountPathOptions::value_type((*it).c_str(), | 1195 options.push_back(chromeos::MountPathOptions::value_type((*it).c_str(), |
1201 value.c_str())); | 1196 value.c_str())); |
1202 } | 1197 } |
1203 } | 1198 } |
1204 | 1199 |
1205 MountParamaters* params = new MountParamaters(mount_type_str, options); | 1200 MountParamaters* params = new MountParamaters(mount_type_str, options); |
1206 BrowserThread::PostTask( | 1201 BrowserThread::PostTask( |
1207 BrowserThread::FILE, FROM_HERE, | 1202 BrowserThread::FILE, FROM_HERE, |
1208 NewRunnableMethod(this, | 1203 NewRunnableMethod(this, |
1209 &AddMountFunction::GetLocalPathsOnFileThread, | 1204 &AddMountFunction::GetLocalPathsOnFileThread, |
1210 file_paths, reinterpret_cast<void*>(params))); | 1205 file_paths, reinterpret_cast<void*>(params))); |
1211 #endif // OS_CHROMEOS | |
1212 | 1206 |
1213 return true; | 1207 return true; |
1214 } | 1208 } |
1215 | 1209 |
1216 void AddMountFunction::GetLocalPathsResponseOnUIThread( | 1210 void AddMountFunction::GetLocalPathsResponseOnUIThread( |
1217 const FilePathList& files, void* context) { | 1211 const FilePathList& files, void* context) { |
1218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1219 DCHECK(context); | 1213 DCHECK(context); |
| 1214 scoped_ptr<MountParamaters> params( |
| 1215 reinterpret_cast<MountParamaters*>(context)); |
1220 | 1216 |
1221 if (!files.size()) { | 1217 if (!files.size()) { |
1222 SendResponse(false); | 1218 SendResponse(false); |
1223 return; | 1219 return; |
1224 } | 1220 } |
1225 | 1221 |
1226 #ifdef OS_CHROMEOS | |
1227 scoped_ptr<MountParamaters> params( | |
1228 reinterpret_cast<MountParamaters*>(context)); | |
1229 const std::string& mount_type_str = params->mount_type; | 1222 const std::string& mount_type_str = params->mount_type; |
1230 const chromeos::MountPathOptions& options = params->mount_options; | 1223 const chromeos::MountPathOptions& options = params->mount_options; |
1231 FilePath::StringType source_file = files[0].value(); | 1224 FilePath::StringType source_file = files[0].value(); |
1232 | 1225 |
| 1226 #ifdef OS_CHROMEOS |
1233 chromeos::MountLibrary *mount_lib = | 1227 chromeos::MountLibrary *mount_lib = |
1234 chromeos::CrosLibrary::Get()->GetMountLibrary(); | 1228 chromeos::CrosLibrary::Get()->GetMountLibrary(); |
1235 | 1229 |
1236 chromeos::MountType mount_type = | 1230 chromeos::MountType mount_type = |
1237 mount_lib->MountTypeFromString(mount_type_str); | 1231 mount_lib->MountTypeFromString(mount_type_str); |
1238 if (mount_type == chromeos::MOUNT_TYPE_INVALID) { | 1232 if (mount_type == chromeos::MOUNT_TYPE_INVALID) { |
1239 error_ = "Invalid mount type"; | 1233 error_ = "Invalid mount type"; |
1240 SendResponse(false); | 1234 SendResponse(false); |
1241 return; | 1235 return; |
1242 } | 1236 } |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1575 SET_STRING(IDS_FILE_BROWSER, ID3_USER_DEFINED_URL_LINK_FRAME); // WXXX | 1569 SET_STRING(IDS_FILE_BROWSER, ID3_USER_DEFINED_URL_LINK_FRAME); // WXXX |
1576 | 1570 |
1577 SET_STRING(IDS_FILEBROWSER, ENQUEUE); | 1571 SET_STRING(IDS_FILEBROWSER, ENQUEUE); |
1578 #undef SET_STRING | 1572 #undef SET_STRING |
1579 | 1573 |
1580 // TODO(serya): Create a new string in .grd file for this one in M13. | 1574 // TODO(serya): Create a new string in .grd file for this one in M13. |
1581 dict->SetString("PREVIEW_IMAGE", | 1575 dict->SetString("PREVIEW_IMAGE", |
1582 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_VIEW_CERT_BUTTON)); | 1576 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_VIEW_CERT_BUTTON)); |
1583 dict->SetString("PLAY_MEDIA", | 1577 dict->SetString("PLAY_MEDIA", |
1584 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); | 1578 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); |
1585 #if defined(OS_CHROMEOS) | |
1586 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableArchives)) | 1579 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableArchives)) |
1587 dict->SetString("ENABLE_ARCHIVES", "true"); | 1580 dict->SetString("ENABLE_ARCHIVES", "true"); |
1588 #endif | |
1589 | 1581 |
1590 return true; | 1582 return true; |
1591 } | 1583 } |
OLD | NEW |