#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
-#include "base/platform_file.h"
#include "chrome/browser/chromeos/file_manager/fileapi_util.h"
-#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/chrome_select_file_policy.h"
#include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
-#include "content/public/browser/storage_partition.h"
+#include "storage/browser/fileapi/file_system_backend.h"
+#include "storage/browser/fileapi/file_system_context.h"
+#include "storage/common/fileapi/file_system_info.h"
+#include "storage/common/fileapi/file_system_util.h"
#include "ui/shell_dialogs/select_file_dialog.h"
-#include "webkit/browser/fileapi/file_system_backend.h"
-#include "webkit/browser/fileapi/file_system_context.h"
-#include "webkit/common/fileapi/file_system_info.h"
-#include "webkit/common/fileapi/file_system_util.h"
-using content::BrowserContext;
using content::BrowserThread;
using extensions::api::file_browser_handler_internal::FileEntryInfo;
using file_manager::FileSelector;
using file_manager::FileSelectorFactory;
+using file_manager::util::EntryDefinition;
+using file_manager::util::FileDefinition;
namespace SelectFile =
extensions::api::file_browser_handler_internal::SelectFile;
class FileSelectorImpl : public FileSelector,
public ui::SelectFileDialog::Listener {
public:
- explicit FileSelectorImpl();
- virtual ~FileSelectorImpl() OVERRIDE;
+ FileSelectorImpl();
+ virtual ~FileSelectorImpl() override;
protected:
// file_manager::FileSelectr overrides.
const base::FilePath& suggested_name,
const std::vector<std::string>& allowed_extensions,
Browser* browser,
- FileBrowserHandlerInternalSelectFileFunction* function) OVERRIDE;
+ FileBrowserHandlerInternalSelectFileFunction* function) override;
// ui::SelectFileDialog::Listener overrides.
virtual void FileSelected(const base::FilePath& path,
int index,
- void* params) OVERRIDE;
+ void* params) override;
virtual void MultiFilesSelected(const std::vector<base::FilePath>& files,
- void* params) OVERRIDE;
- virtual void FileSelectionCanceled(void* params) OVERRIDE;
+ void* params) override;
+ virtual void FileSelectionCanceled(void* params) override;
private:
// Initiates and shows 'save as' dialog which will be used to prompt user to
allowed_file_info.support_drive = true;
dialog_->SelectFile(ui::SelectFileDialog::SELECT_SAVEAS_FILE,
- string16() /* dialog title*/,
+ base::string16() /* dialog title*/,
suggested_name,
&allowed_file_info,
0 /* file type index */,
// FileSelectorFactory implementation.
// Creates new FileSelectorImplementation for the function.
- virtual FileSelector* CreateFileSelector() const OVERRIDE {
+ virtual FileSelector* CreateFileSelector() const override {
return new FileSelectorImpl();
}
FileBrowserHandlerInternalSelectFileFunction::
~FileBrowserHandlerInternalSelectFileFunction() {}
-bool FileBrowserHandlerInternalSelectFileFunction::RunImpl() {
+bool FileBrowserHandlerInternalSelectFileFunction::RunAsync() {
scoped_ptr<SelectFile::Params> params(SelectFile::Params::Create(*args_));
base::FilePath suggested_name(params->selection_params.suggested_name);
allowed_extensions = *params->selection_params.allowed_file_extensions;
if (!user_gesture() && user_gesture_check_enabled_) {
- error_ = kNoUserGestureError;
+ SetError(kNoUserGestureError);
return false;
}
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!success) {
- Respond(false);
+ Respond(EntryDefinition(), false);
return;
}
- full_path_ = full_path;
-
- fileapi::FileSystemInfo info =
- fileapi::GetFileSystemInfoForChromeOS(source_url_.GetOrigin());
- file_system_name_ = info.name;
- file_system_root_ = info.root_url;
-
- GrantPermissions();
-
- Respond(true);
-}
-
-void FileBrowserHandlerInternalSelectFileFunction::GrantPermissions() {
- fileapi::ExternalFileSystemBackend* external_backend =
+ storage::ExternalFileSystemBackend* external_backend =
file_manager::util::GetFileSystemContextForRenderViewHost(
GetProfile(), render_view_host())->external_backend();
DCHECK(external_backend);
- external_backend->GetVirtualPath(full_path_, &virtual_path_);
- DCHECK(!virtual_path_.empty());
+ FileDefinition file_definition;
+ file_definition.is_directory = false;
+
+ external_backend->GetVirtualPath(full_path, &file_definition.virtual_path);
+ DCHECK(!file_definition.virtual_path.empty());
// Grant access to this particular file to target extension. This will
// ensure that the target extension can access only this FS entry and
// prevent from traversing FS hierarchy upward.
- external_backend->GrantFileAccessToExtension(extension_id(), virtual_path_);
+ external_backend->GrantFileAccessToExtension(extension_id(),
+ file_definition.virtual_path);
// Grant access to the selected file to target extensions render view process.
content::ChildProcessSecurityPolicy::GetInstance()->GrantCreateReadWriteFile(
- render_view_host()->GetProcess()->GetID(), full_path_);
+ render_view_host()->GetProcess()->GetID(), full_path);
+
+ file_manager::util::ConvertFileDefinitionToEntryDefinition(
+ GetProfile(),
+ extension_id(),
+ file_definition,
+ base::Bind(
+ &FileBrowserHandlerInternalSelectFileFunction::RespondEntryDefinition,
+ this));
+}
+
+void FileBrowserHandlerInternalSelectFileFunction::RespondEntryDefinition(
+ const EntryDefinition& entry_definition) {
+ Respond(entry_definition, true);
}
-void FileBrowserHandlerInternalSelectFileFunction::Respond(bool success) {
+void FileBrowserHandlerInternalSelectFileFunction::Respond(
+ const EntryDefinition& entry_definition,
+ bool success) {
scoped_ptr<SelectFile::Results::Result> result(
new SelectFile::Results::Result());
result->success = success;
// If the file was selected, add 'entry' object which will be later used to
// create a FileEntry instance for the selected file.
- if (success) {
+ if (success && entry_definition.error == base::File::FILE_OK) {
result->entry.reset(new FileEntryInfo());
- result->entry->file_system_name = file_system_name_;
- result->entry->file_system_root = file_system_root_.spec();
- result->entry->file_full_path = "/" + virtual_path_.AsUTF8Unsafe();
- result->entry->file_is_directory = false;
+ // TODO(mtomasz): Make the response fields consistent with other files.
+ result->entry->file_system_name = entry_definition.file_system_name;
+ result->entry->file_system_root = entry_definition.file_system_root_url;
+ result->entry->file_full_path =
+ "/" + entry_definition.full_path.AsUTF8Unsafe();
+ result->entry->file_is_directory = entry_definition.is_directory;
}
results_ = SelectFile::Results::Create(*result);