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