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/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/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "grit/generated_resources.h" | 42 #include "grit/generated_resources.h" |
43 #include "grit/platform_locale_settings.h" | 43 #include "grit/platform_locale_settings.h" |
44 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
45 #include "webkit/fileapi/file_system_context.h" | 45 #include "webkit/fileapi/file_system_context.h" |
46 #include "webkit/fileapi/file_system_file_util.h" | 46 #include "webkit/fileapi/file_system_file_util.h" |
47 #include "webkit/fileapi/file_system_mount_point_provider.h" | 47 #include "webkit/fileapi/file_system_mount_point_provider.h" |
48 #include "webkit/fileapi/file_system_operation_context.h" | 48 #include "webkit/fileapi/file_system_operation_context.h" |
49 #include "webkit/fileapi/file_system_types.h" | 49 #include "webkit/fileapi/file_system_types.h" |
50 #include "webkit/fileapi/file_system_util.h" | 50 #include "webkit/fileapi/file_system_util.h" |
51 | 51 |
| 52 #ifdef OS_CHROMEOS |
| 53 #include "chrome/browser/chromeos/disks/disk_mount_manager.h" |
| 54 #endif |
| 55 |
| 56 using chromeos::disks::DiskMountManager; |
52 using content::BrowserThread; | 57 using content::BrowserThread; |
53 using content::WebContents; | 58 using content::WebContents; |
54 | 59 |
55 namespace { | 60 namespace { |
56 | 61 |
57 // Error messages. | 62 // Error messages. |
58 const char kFileError[] = "File error %d"; | 63 const char kFileError[] = "File error %d"; |
59 const char kInvalidFileUrl[] = "Invalid file URL"; | 64 const char kInvalidFileUrl[] = "Invalid file URL"; |
60 const char kVolumeDevicePathNotFound[] = "Device path not found"; | 65 const char kVolumeDevicePathNotFound[] = "Device path not found"; |
61 | 66 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 DictionaryPrefUpdate prefs_usage_update(profile->GetPrefs(), | 263 DictionaryPrefUpdate prefs_usage_update(profile->GetPrefs(), |
259 prefs::kLastUsedFileBrowserHandlers); | 264 prefs::kLastUsedFileBrowserHandlers); |
260 prefs_usage_update->SetWithoutPathExpansion(task_id, | 265 prefs_usage_update->SetWithoutPathExpansion(task_id, |
261 new base::FundamentalValue( | 266 new base::FundamentalValue( |
262 static_cast<int>(base::Time::Now().ToInternalValue()/ | 267 static_cast<int>(base::Time::Now().ToInternalValue()/ |
263 base::Time::kMicrosecondsPerSecond))); | 268 base::Time::kMicrosecondsPerSecond))); |
264 } | 269 } |
265 | 270 |
266 #ifdef OS_CHROMEOS | 271 #ifdef OS_CHROMEOS |
267 base::DictionaryValue* MountPointToValue(Profile* profile, | 272 base::DictionaryValue* MountPointToValue(Profile* profile, |
268 const chromeos::disks::DiskMountManager::MountPointInfo& mount_point_info) { | 273 const DiskMountManager::MountPointInfo& mount_point_info) { |
269 | 274 |
270 base::DictionaryValue *mount_info = new base::DictionaryValue(); | 275 base::DictionaryValue *mount_info = new base::DictionaryValue(); |
271 | 276 |
272 mount_info->SetString("mountType", | 277 mount_info->SetString("mountType", |
273 chromeos::disks::DiskMountManager::MountTypeToString( | 278 DiskMountManager::MountTypeToString( |
274 mount_point_info.mount_type)); | 279 mount_point_info.mount_type)); |
275 | 280 |
276 if (mount_point_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { | 281 if (mount_point_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { |
277 GURL source_url; | 282 GURL source_url; |
278 if (file_manager_util::ConvertFileToFileSystemUrl(profile, | 283 if (file_manager_util::ConvertFileToFileSystemUrl(profile, |
279 FilePath(mount_point_info.source_path), | 284 FilePath(mount_point_info.source_path), |
280 file_manager_util::GetFileBrowserExtensionUrl().GetOrigin(), | 285 file_manager_util::GetFileBrowserExtensionUrl().GetOrigin(), |
281 &source_url)) { | 286 &source_url)) { |
282 mount_info->SetString("sourceUrl", source_url.spec()); | 287 mount_info->SetString("sourceUrl", source_url.spec()); |
283 } | 288 } |
284 } else { | 289 } else { |
285 mount_info->SetString("sourceUrl", mount_point_info.source_path); | 290 mount_info->SetString("sourceUrl", mount_point_info.source_path); |
286 } | 291 } |
287 | 292 |
288 FilePath relative_mount_path; | 293 FilePath relative_mount_path; |
289 // Convert mount point path to relative path with the external file system | 294 // Convert mount point path to relative path with the external file system |
290 // exposed within File API. | 295 // exposed within File API. |
291 if (file_manager_util::ConvertFileToRelativeFileSystemPath(profile, | 296 if (file_manager_util::ConvertFileToRelativeFileSystemPath(profile, |
292 FilePath(mount_point_info.mount_path), | 297 FilePath(mount_point_info.mount_path), |
293 &relative_mount_path)) { | 298 &relative_mount_path)) { |
294 mount_info->SetString("mountPath", relative_mount_path.value()); | 299 mount_info->SetString("mountPath", relative_mount_path.value()); |
295 } | 300 } |
296 | 301 |
297 mount_info->SetString("mountCondition", | 302 mount_info->SetString("mountCondition", |
298 chromeos::disks::DiskMountManager::MountConditionToString( | 303 DiskMountManager::MountConditionToString( |
299 mount_point_info.mount_condition)); | 304 mount_point_info.mount_condition)); |
300 | 305 |
301 return mount_info; | 306 return mount_info; |
302 } | 307 } |
303 #endif | 308 #endif |
304 | 309 |
305 } // namespace | 310 } // namespace |
306 | 311 |
307 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher | 312 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher |
308 : public fileapi::FileSystemCallbackDispatcher { | 313 : public fileapi::FileSystemCallbackDispatcher { |
309 public: | 314 public: |
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1236 | 1241 |
1237 if (!files.size()) { | 1242 if (!files.size()) { |
1238 SendResponse(false); | 1243 SendResponse(false); |
1239 return; | 1244 return; |
1240 } | 1245 } |
1241 | 1246 |
1242 #ifdef OS_CHROMEOS | 1247 #ifdef OS_CHROMEOS |
1243 FilePath::StringType source_file = files[0].value(); | 1248 FilePath::StringType source_file = files[0].value(); |
1244 | 1249 |
1245 chromeos::disks::DiskMountManager* disk_mount_manager = | 1250 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); |
1246 chromeos::disks::DiskMountManager::GetInstance(); | |
1247 | 1251 |
1248 chromeos::MountType mount_type = | 1252 chromeos::MountType mount_type = |
1249 disk_mount_manager->MountTypeFromString(mount_type_str); | 1253 disk_mount_manager->MountTypeFromString(mount_type_str); |
1250 if (mount_type == chromeos::MOUNT_TYPE_INVALID) { | 1254 if (mount_type == chromeos::MOUNT_TYPE_INVALID) { |
1251 error_ = "Invalid mount type"; | 1255 error_ = "Invalid mount type"; |
1252 SendResponse(false); | 1256 SendResponse(false); |
1253 return; | 1257 return; |
1254 } | 1258 } |
1255 | 1259 |
1256 disk_mount_manager->MountPath(source_file.data(), mount_type); | 1260 disk_mount_manager->MountPath(source_file.data(), mount_type); |
(...skipping 28 matching lines...) Expand all Loading... |
1285 | 1289 |
1286 void RemoveMountFunction::GetLocalPathsResponseOnUIThread( | 1290 void RemoveMountFunction::GetLocalPathsResponseOnUIThread( |
1287 const FilePathList& files) { | 1291 const FilePathList& files) { |
1288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1289 | 1293 |
1290 if (files.size() != 1) { | 1294 if (files.size() != 1) { |
1291 SendResponse(false); | 1295 SendResponse(false); |
1292 return; | 1296 return; |
1293 } | 1297 } |
1294 #ifdef OS_CHROMEOS | 1298 #ifdef OS_CHROMEOS |
1295 chromeos::disks::DiskMountManager::GetInstance()->UnmountPath( | 1299 DiskMountManager::GetInstance()->UnmountPath(files[0].value()); |
1296 files[0].value()); | |
1297 #endif | 1300 #endif |
1298 | 1301 |
1299 SendResponse(true); | 1302 SendResponse(true); |
1300 } | 1303 } |
1301 | 1304 |
1302 GetMountPointsFunction::GetMountPointsFunction() { | 1305 GetMountPointsFunction::GetMountPointsFunction() { |
1303 } | 1306 } |
1304 | 1307 |
1305 GetMountPointsFunction::~GetMountPointsFunction() { | 1308 GetMountPointsFunction::~GetMountPointsFunction() { |
1306 } | 1309 } |
1307 | 1310 |
1308 bool GetMountPointsFunction::RunImpl() { | 1311 bool GetMountPointsFunction::RunImpl() { |
1309 if (args_->GetSize()) | 1312 if (args_->GetSize()) |
1310 return false; | 1313 return false; |
1311 | 1314 |
1312 base::ListValue *mounts = new base::ListValue(); | 1315 base::ListValue *mounts = new base::ListValue(); |
1313 result_.reset(mounts); | 1316 result_.reset(mounts); |
1314 | 1317 |
1315 #ifdef OS_CHROMEOS | 1318 #ifdef OS_CHROMEOS |
1316 chromeos::disks::DiskMountManager* disk_mount_manager = | 1319 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); |
1317 chromeos::disks::DiskMountManager::GetInstance(); | 1320 DiskMountManager::MountPointMap mount_points = |
1318 chromeos::disks::DiskMountManager::MountPointMap mount_points = | |
1319 disk_mount_manager->mount_points(); | 1321 disk_mount_manager->mount_points(); |
1320 | 1322 |
1321 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it = | 1323 for (DiskMountManager::MountPointMap::const_iterator it = |
1322 mount_points.begin(); | 1324 mount_points.begin(); |
1323 it != mount_points.end(); | 1325 it != mount_points.end(); |
1324 ++it) { | 1326 ++it) { |
1325 mounts->Append(MountPointToValue(profile_, it->second)); | 1327 mounts->Append(MountPointToValue(profile_, it->second)); |
1326 } | 1328 } |
1327 #endif | 1329 #endif |
1328 | 1330 |
1329 SendResponse(true); | 1331 SendResponse(true); |
1330 return true; | 1332 return true; |
1331 } | 1333 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 files[0].value())); | 1373 files[0].value())); |
1372 } | 1374 } |
1373 | 1375 |
1374 void GetSizeStatsFunction::CallGetSizeStatsOnFileThread( | 1376 void GetSizeStatsFunction::CallGetSizeStatsOnFileThread( |
1375 const std::string& mount_path) { | 1377 const std::string& mount_path) { |
1376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 1378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
1377 | 1379 |
1378 size_t total_size_kb = 0; | 1380 size_t total_size_kb = 0; |
1379 size_t remaining_size_kb = 0; | 1381 size_t remaining_size_kb = 0; |
1380 #ifdef OS_CHROMEOS | 1382 #ifdef OS_CHROMEOS |
1381 chromeos::disks::DiskMountManager::GetInstance()-> | 1383 DiskMountManager::GetInstance()-> |
1382 GetSizeStatsOnFileThread(mount_path, &total_size_kb, &remaining_size_kb); | 1384 GetSizeStatsOnFileThread(mount_path, &total_size_kb, &remaining_size_kb); |
1383 #endif | 1385 #endif |
1384 | 1386 |
1385 BrowserThread::PostTask( | 1387 BrowserThread::PostTask( |
1386 BrowserThread::UI, FROM_HERE, | 1388 BrowserThread::UI, FROM_HERE, |
1387 base::Bind( | 1389 base::Bind( |
1388 &GetSizeStatsFunction::GetSizeStatsCallbackOnUIThread, | 1390 &GetSizeStatsFunction::GetSizeStatsCallbackOnUIThread, |
1389 this, | 1391 this, |
1390 mount_path, total_size_kb, remaining_size_kb)); | 1392 mount_path, total_size_kb, remaining_size_kb)); |
1391 } | 1393 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 void FormatDeviceFunction::GetLocalPathsResponseOnUIThread( | 1436 void FormatDeviceFunction::GetLocalPathsResponseOnUIThread( |
1435 const FilePathList& files) { | 1437 const FilePathList& files) { |
1436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1437 | 1439 |
1438 if (files.size() != 1) { | 1440 if (files.size() != 1) { |
1439 SendResponse(false); | 1441 SendResponse(false); |
1440 return; | 1442 return; |
1441 } | 1443 } |
1442 | 1444 |
1443 #ifdef OS_CHROMEOS | 1445 #ifdef OS_CHROMEOS |
1444 chromeos::disks::DiskMountManager::GetInstance()->FormatMountedDevice( | 1446 DiskMountManager::GetInstance()->FormatMountedDevice(files[0].value()); |
1445 files[0].value()); | |
1446 #endif | 1447 #endif |
1447 | 1448 |
1448 SendResponse(true); | 1449 SendResponse(true); |
1449 } | 1450 } |
1450 | 1451 |
1451 GetVolumeMetadataFunction::GetVolumeMetadataFunction() { | 1452 GetVolumeMetadataFunction::GetVolumeMetadataFunction() { |
1452 } | 1453 } |
1453 | 1454 |
1454 GetVolumeMetadataFunction::~GetVolumeMetadataFunction() { | 1455 GetVolumeMetadataFunction::~GetVolumeMetadataFunction() { |
1455 } | 1456 } |
1456 | 1457 |
1457 bool GetVolumeMetadataFunction::RunImpl() { | 1458 bool GetVolumeMetadataFunction::RunImpl() { |
1458 if (args_->GetSize() != 1) { | 1459 if (args_->GetSize() != 1) { |
1459 error_ = "Invalid argument count"; | 1460 error_ = "Invalid argument count"; |
1460 return false; | 1461 return false; |
1461 } | 1462 } |
1462 | 1463 |
1463 std::string volume_device_path; | 1464 std::string volume_device_path; |
1464 if (!args_->GetString(0, &volume_device_path)) { | 1465 if (!args_->GetString(0, &volume_device_path)) { |
1465 NOTREACHED(); | 1466 NOTREACHED(); |
1466 } | 1467 } |
1467 | 1468 |
1468 #ifdef OS_CHROMEOS | 1469 #ifdef OS_CHROMEOS |
1469 chromeos::disks::DiskMountManager* disk_mount_manager = | 1470 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); |
1470 chromeos::disks::DiskMountManager::GetInstance(); | 1471 DiskMountManager::DiskMap::const_iterator volume_it = |
1471 chromeos::disks::DiskMountManager::DiskMap::const_iterator volume_it = | |
1472 disk_mount_manager->disks().find(volume_device_path); | 1472 disk_mount_manager->disks().find(volume_device_path); |
1473 | 1473 |
1474 if (volume_it != disk_mount_manager->disks().end() && | 1474 if (volume_it != disk_mount_manager->disks().end() && |
1475 !volume_it->second->is_hidden()) { | 1475 !volume_it->second->is_hidden()) { |
1476 chromeos::disks::DiskMountManager::Disk* volume = volume_it->second; | 1476 DiskMountManager::Disk* volume = volume_it->second; |
1477 DictionaryValue* volume_info = new DictionaryValue(); | 1477 DictionaryValue* volume_info = new DictionaryValue(); |
1478 result_.reset(volume_info); | 1478 result_.reset(volume_info); |
1479 // Localising mount path. | 1479 // Localising mount path. |
1480 std::string mount_path; | 1480 std::string mount_path; |
1481 if (!volume->mount_path().empty()) { | 1481 if (!volume->mount_path().empty()) { |
1482 FilePath relative_mount_path; | 1482 FilePath relative_mount_path; |
1483 file_manager_util::ConvertFileToRelativeFileSystemPath(profile_, | 1483 file_manager_util::ConvertFileToRelativeFileSystemPath(profile_, |
1484 FilePath(volume->mount_path()), &relative_mount_path); | 1484 FilePath(volume->mount_path()), &relative_mount_path); |
1485 mount_path = relative_mount_path.value(); | 1485 mount_path = relative_mount_path.value(); |
1486 } | 1486 } |
1487 volume_info->SetString("devicePath", volume->device_path()); | 1487 volume_info->SetString("devicePath", volume->device_path()); |
1488 volume_info->SetString("mountPath", mount_path); | 1488 volume_info->SetString("mountPath", mount_path); |
1489 volume_info->SetString("systemPath", volume->system_path()); | 1489 volume_info->SetString("systemPath", volume->system_path()); |
1490 volume_info->SetString("filePath", volume->file_path()); | 1490 volume_info->SetString("filePath", volume->file_path()); |
1491 volume_info->SetString("deviceLabel", volume->device_label()); | 1491 volume_info->SetString("deviceLabel", volume->device_label()); |
1492 volume_info->SetString("driveLabel", volume->drive_label()); | 1492 volume_info->SetString("driveLabel", volume->drive_label()); |
1493 volume_info->SetString("deviceType", | 1493 volume_info->SetString("deviceType", |
1494 DeviceTypeToString(volume->device_type())); | 1494 DiskMountManager::DeviceTypeToString(volume->device_type())); |
1495 volume_info->SetInteger("totalSize", volume->total_size_in_bytes()); | 1495 volume_info->SetInteger("totalSize", volume->total_size_in_bytes()); |
1496 volume_info->SetBoolean("isParent", volume->is_parent()); | 1496 volume_info->SetBoolean("isParent", volume->is_parent()); |
1497 volume_info->SetBoolean("isReadOnly", volume->is_read_only()); | 1497 volume_info->SetBoolean("isReadOnly", volume->is_read_only()); |
1498 volume_info->SetBoolean("hasMedia", volume->has_media()); | 1498 volume_info->SetBoolean("hasMedia", volume->has_media()); |
1499 volume_info->SetBoolean("isOnBootDevice", volume->on_boot_device()); | 1499 volume_info->SetBoolean("isOnBootDevice", volume->on_boot_device()); |
1500 | 1500 |
1501 return true; | 1501 return true; |
1502 } | 1502 } |
1503 #endif | 1503 #endif |
1504 error_ = kVolumeDevicePathNotFound; | 1504 error_ = kVolumeDevicePathNotFound; |
1505 return false; | 1505 return false; |
1506 } | 1506 } |
1507 | 1507 |
1508 #ifdef OS_CHROMEOS | |
1509 std::string GetVolumeMetadataFunction::DeviceTypeToString( | |
1510 chromeos::DeviceType type) { | |
1511 switch (type) { | |
1512 case chromeos::FLASH: | |
1513 return kVolumeTypeFlash; | |
1514 case chromeos::OPTICAL: | |
1515 return kVolumeTypeOptical; | |
1516 case chromeos::HDD: | |
1517 return kVolumeTypeHardDrive; | |
1518 default: | |
1519 break; | |
1520 } | |
1521 return kVolumeTypeUnknown; | |
1522 } | |
1523 #endif | |
1524 | |
1525 bool FileDialogStringsFunction::RunImpl() { | 1508 bool FileDialogStringsFunction::RunImpl() { |
1526 result_.reset(new DictionaryValue()); | 1509 result_.reset(new DictionaryValue()); |
1527 DictionaryValue* dict = reinterpret_cast<DictionaryValue*>(result_.get()); | 1510 DictionaryValue* dict = reinterpret_cast<DictionaryValue*>(result_.get()); |
1528 | 1511 |
1529 #define SET_STRING(ns, id) \ | 1512 #define SET_STRING(ns, id) \ |
1530 dict->SetString(#id, l10n_util::GetStringUTF16(ns##_##id)) | 1513 dict->SetString(#id, l10n_util::GetStringUTF16(ns##_##id)) |
1531 | 1514 |
1532 SET_STRING(IDS, WEB_FONT_FAMILY); | 1515 SET_STRING(IDS, WEB_FONT_FAMILY); |
1533 SET_STRING(IDS, WEB_FONT_SIZE); | 1516 SET_STRING(IDS, WEB_FONT_SIZE); |
1534 | 1517 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1687 SET_STRING(IDS_FILE_BROWSER, ENQUEUE); | 1670 SET_STRING(IDS_FILE_BROWSER, ENQUEUE); |
1688 #undef SET_STRING | 1671 #undef SET_STRING |
1689 | 1672 |
1690 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); | 1673 ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); |
1691 | 1674 |
1692 dict->SetString("PLAY_MEDIA", | 1675 dict->SetString("PLAY_MEDIA", |
1693 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); | 1676 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); |
1694 | 1677 |
1695 return true; | 1678 return true; |
1696 } | 1679 } |
OLD | NEW |