diff options
author | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-25 14:15:53 +0000 |
---|---|---|
committer | kinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-25 14:15:53 +0000 |
commit | 5025efdb5e77d06403c7feb67caa76db00d8c18a (patch) | |
tree | eb70b6bf0253f590967aff3eff29b6e9b39a59b1 | |
parent | 4ae4272a09df5dcff1cd46135b6955c2ced39686 (diff) | |
download | chromium_src-5025efdb5e77d06403c7feb67caa76db00d8c18a.zip chromium_src-5025efdb5e77d06403c7feb67caa76db00d8c18a.tar.gz chromium_src-5025efdb5e77d06403c7feb67caa76db00d8c18a.tar.bz2 |
Change chrome.filesystem to handle the Chrome OS Drive file entries directly.
This CL shows the Drive folder in the open file dialog,
and allows the app to select the real entry of the remote file,
rather than its local cache.
BUG=156277
TEST=Run the sample text editor chrome app, and open a Drive file via
the open-file dialog on Chrome OS. Should see "/special/drive/..." path.
Review URL: https://chromiumcodereview.appspot.com/13023002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@190394 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 52 insertions, 4 deletions
diff --git a/apps/app_restore_service_browsertest.cc b/apps/app_restore_service_browsertest.cc index f17cc64..d0dac93b 100644 --- a/apps/app_restore_service_browsertest.cc +++ b/apps/app_restore_service_browsertest.cc @@ -70,6 +70,8 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, FileAccessIsSavedToPrefs) { FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( &temp_file); + FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest( + "temp", temp_directory.path()); ExtensionTestMessageListener file_written_listener("fileWritten", false); ExtensionTestMessageListener access_ok_listener( @@ -111,6 +113,8 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, FileAccessIsRestored) { FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( &temp_file); + FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest( + "temp", temp_directory.path()); ExtensionTestMessageListener file_written_listener("fileWritten", false); ExtensionTestMessageListener access_ok_listener( diff --git a/chrome/browser/extensions/api/file_handlers/app_file_handler_util.cc b/chrome/browser/extensions/api/file_handlers/app_file_handler_util.cc index d4ff715..27579a2 100644 --- a/chrome/browser/extensions/api/file_handlers/app_file_handler_util.cc +++ b/chrome/browser/extensions/api/file_handlers/app_file_handler_util.cc @@ -100,7 +100,8 @@ GrantedFileEntry CreateFileEntry( DCHECK(isolated_context); result.filesystem_id = isolated_context->RegisterFileSystemForPath( - fileapi::kFileSystemTypeNativeLocal, path, &result.registered_name); + fileapi::kFileSystemTypeNativeForPlatformApp, path, + &result.registered_name); content::ChildProcessSecurityPolicy* policy = content::ChildProcessSecurityPolicy::GetInstance(); diff --git a/chrome/browser/extensions/api/file_system/file_system_api.cc b/chrome/browser/extensions/api/file_system/file_system_api.cc index 0fc50c1..18d84e2 100644 --- a/chrome/browser/extensions/api/file_system/file_system_api.cc +++ b/chrome/browser/extensions/api/file_system/file_system_api.cc @@ -28,6 +28,8 @@ #include "net/base/mime_util.h" #include "ui/base/l10n/l10n_util.h" #include "ui/shell_dialogs/select_file_dialog.h" +#include "ui/shell_dialogs/selected_file_info.h" +#include "webkit/fileapi/external_mount_points.h" #include "webkit/fileapi/file_system_types.h" #include "webkit/fileapi/file_system_util.h" #include "webkit/fileapi/isolated_context.h" @@ -389,10 +391,13 @@ class FileSystemChooseEntryFunction::FilePicker if (g_skip_picker_for_test) { if (g_path_to_be_picked_for_test) { + ui::SelectedFileInfo selected_path(*g_path_to_be_picked_for_test, + base::FilePath()); content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, base::Bind( - &FileSystemChooseEntryFunction::FilePicker::FileSelected, - base::Unretained(this), *g_path_to_be_picked_for_test, 1, + &FileSystemChooseEntryFunction::FilePicker:: + FileSelectedWithExtraInfo, + base::Unretained(this), selected_path, 1, static_cast<void*>(NULL))); } else { content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, @@ -418,7 +423,22 @@ class FileSystemChooseEntryFunction::FilePicker virtual void FileSelected(const base::FilePath& path, int index, void* params) OVERRIDE { - function_->FileSelected(path, entry_type_); + // The version taking ui::SelectedFileInfo should be used. + NOTREACHED(); + } + + virtual void FileSelectedWithExtraInfo(const ui::SelectedFileInfo& file, + int index, + void* params) OVERRIDE { + // Normally, file.local_path is used because it is a native path to the + // local read-only cached file in the case of remote file system like + // Chrome OS's Google Drive integration. Here, however, |file.file_path| is + // necessary because we need to create a FileEntry denoting the remote file, + // not its cache. On other platforms than Chrome OS, they are the same. + // + // TODO(kinaba): remove this, once after the file picker implements proper + // switch of the path treatment depending on the |support_drive| flag. + function_->FileSelected(file.file_path, entry_type_); delete this; } @@ -478,6 +498,16 @@ void FileSystemChooseEntryFunction::StopSkippingPickerForTest() { g_skip_picker_for_test = false; } +// static +void FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest( + const std::string& name, const base::FilePath& path) { + // For testing on Chrome OS, where to deal with remote and local paths + // smoothly, all accessed paths need to be registered in the list of + // external mount points. + fileapi::ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( + name, fileapi::kFileSystemTypeNativeLocal, path); +} + void FileSystemChooseEntryFunction::FileSelected(const base::FilePath& path, EntryType entry_type) { if (entry_type == WRITABLE) { @@ -593,6 +623,9 @@ bool FileSystemChooseEntryFunction::RunImpl() { return false; } + if (entry_type != WRITABLE) + file_type_info.support_drive = true; + return ShowPicker(suggested_name, file_type_info, picker_type, entry_type); } diff --git a/chrome/browser/extensions/api/file_system/file_system_api.h b/chrome/browser/extensions/api/file_system/file_system_api.h index 6e72a0f..e8013b7 100644 --- a/chrome/browser/extensions/api/file_system/file_system_api.h +++ b/chrome/browser/extensions/api/file_system/file_system_api.h @@ -73,6 +73,11 @@ class FileSystemChooseEntryFunction : public FileSystemEntryFunction { static void SkipPickerAndAlwaysSelectPathForTest(base::FilePath* path); static void SkipPickerAndAlwaysCancelForTest(); static void StopSkippingPickerForTest(); + // Call this with the directory for test file paths. On Chrome OS, accessed + // path needs to be explicitly registered for smooth integration with Google + // Drive support. + static void RegisterTempExternalFileSystemForTest(const std::string& name, + const base::FilePath& path); DECLARE_EXTENSION_FUNCTION("fileSystem.chooseEntry", FILESYSTEM_CHOOSEENTRY) diff --git a/chrome/browser/extensions/api/file_system/file_system_apitest.cc b/chrome/browser/extensions/api/file_system/file_system_apitest.cc index 9b8371e..988d8d3 100644 --- a/chrome/browser/extensions/api/file_system/file_system_apitest.cc +++ b/chrome/browser/extensions/api/file_system/file_system_apitest.cc @@ -16,6 +16,8 @@ class FileSystemApiTest : public extensions::PlatformAppBrowserTest { extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); test_root_folder_ = test_data_dir_.AppendASCII("api_test") .AppendASCII("file_system"); + FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest( + "test_root", test_root_folder_); } virtual void TearDown() OVERRIDE { @@ -30,6 +32,9 @@ class FileSystemApiTest : public extensions::PlatformAppBrowserTest { ADD_FAILURE() << "CreateUniqueTempDir failed"; return base::FilePath(); } + FileSystemChooseEntryFunction::RegisterTempExternalFileSystemForTest( + "test_temp", temp_dir_.path()); + base::FilePath destination = temp_dir_.path().AppendASCII(destination_name); if (copy_gold) { base::FilePath source = test_root_folder_.AppendASCII("gold.txt"); |