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