summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authortbarzic@chromium.org <tbarzic@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-25 04:48:31 +0000
committertbarzic@chromium.org <tbarzic@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-25 04:48:31 +0000
commitd47048b6fc87d531ca57ff2361db8fcb1425d46a (patch)
tree022bc1c4ed05c59008a3b97a9250615320b52964 /chrome
parent5784e4490e8d63e65497597a1acdc2ce1b420c6f (diff)
downloadchromium_src-d47048b6fc87d531ca57ff2361db8fcb1425d46a.zip
chromium_src-d47048b6fc87d531ca57ff2361db8fcb1425d46a.tar.gz
chromium_src-d47048b6fc87d531ca57ff2361db8fcb1425d46a.tar.bz2
Add support for drive files to chrome.fileBrowserHandler.selectFile
first, we don't create file on disk when it is selected anymore (since we can't really know exact file path for drive files), we just setup permissions for the file. second, we have to give read permissions for drive cache paths as well in order to enable file reading. TEST=existing BUG=138089 Review URL: https://chromiumcodereview.appspot.com/10664002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148292 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chromeos/extensions/file_browser_handler_api.cc97
-rw-r--r--chrome/browser/chromeos/extensions/file_browser_handler_api.h26
-rw-r--r--chrome/common/extensions/api/file_browser_handler.json8
3 files changed, 80 insertions, 51 deletions
diff --git a/chrome/browser/chromeos/extensions/file_browser_handler_api.cc b/chrome/browser/chromeos/extensions/file_browser_handler_api.cc
index 99a73d9..5efeadd 100644
--- a/chrome/browser/chromeos/extensions/file_browser_handler_api.cc
+++ b/chrome/browser/chromeos/extensions/file_browser_handler_api.cc
@@ -7,11 +7,13 @@
#include "base/bind.h"
#include "base/file_path.h"
#include "base/file_util.h"
+#include "base/memory/scoped_ptr.h"
#include "base/message_loop_proxy.h"
#include "base/platform_file.h"
#include "base/values.h"
#include "chrome/browser/chromeos/extensions/file_handler_util.h"
#include "chrome/browser/chromeos/extensions/file_manager_util.h"
+#include "chrome/browser/chromeos/gdata/gdata_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
@@ -169,37 +171,19 @@ typedef base::Callback<void (bool success,
const GURL& file_system_root)>
FileSystemOpenCallback;
-void RelayOpenFileSystemCallbackToFileThread(
+void RunOpenFileSystemCallback(
const FileSystemOpenCallback& callback,
base::PlatformFileError error,
const std::string& file_system_name,
const GURL& file_system_root) {
bool success = (error == base::PLATFORM_FILE_OK);
- content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
- base::Bind(callback, success, file_system_name, file_system_root));
+ callback.Run(success, file_system_name, file_system_root);
}
} // namespace
FileHandlerSelectFileFunction::FileHandlerSelectFileFunction() {}
-void FileHandlerSelectFileFunction::OnFilePathSelected(
- bool success,
- const FilePath& full_path) {
- if (!success) {
- Respond(false, std::string(), GURL(), FilePath());
- return;
- }
-
- full_path_ = full_path;
-
- BrowserContext::GetFileSystemContext(profile_)->OpenFileSystem(
- source_url_.GetOrigin(), fileapi::kFileSystemTypeExternal, false,
- base::Bind(&RelayOpenFileSystemCallbackToFileThread,
- base::Bind(&FileHandlerSelectFileFunction::CreateFileOnFileThread,
- this)));
-};
-
// static
void FileHandlerSelectFileFunction::set_file_selector_for_test(
FileSelector* file_selector) {
@@ -231,30 +215,40 @@ bool FileHandlerSelectFileFunction::RunImpl() {
return true;
}
-void FileHandlerSelectFileFunction::CreateFileOnFileThread(
+void FileHandlerSelectFileFunction::OnFilePathSelected(
bool success,
- const std::string& file_system_name,
- const GURL& file_system_root) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
+ const FilePath& full_path) {
+ if (!success) {
+ Respond(false, std::string(), GURL(), FilePath());
+ return;
+ }
- content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
- base::Bind(&FileHandlerSelectFileFunction::OnFileCreated, this,
- success, file_system_name, file_system_root));
-}
+ full_path_ = full_path;
-void FileHandlerSelectFileFunction::OnFileCreated(
+ BrowserContext::GetFileSystemContext(profile_)->OpenFileSystem(
+ source_url_.GetOrigin(), fileapi::kFileSystemTypeExternal, false,
+ base::Bind(&RunOpenFileSystemCallback,
+ base::Bind(&FileHandlerSelectFileFunction::OnFileSystemOpened,
+ this)));
+};
+
+void FileHandlerSelectFileFunction::OnFileSystemOpened(
bool success,
const std::string& file_system_name,
const GURL& file_system_root) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
- FilePath virtual_path;
- if (success)
- virtual_path = GrantPermissions();
- Respond(success, file_system_name, file_system_root, virtual_path);
+ if (success) {
+ GrantPermissions(base::Bind(
+ &FileHandlerSelectFileFunction::Respond, this,
+ success, file_system_name, file_system_root));
+ return;
+ }
+ Respond(success, file_system_name, file_system_root, FilePath());
}
-FilePath FileHandlerSelectFileFunction::GrantPermissions() {
+void FileHandlerSelectFileFunction::GrantPermissions(
+ const GrantPermissionsCallback& callback) {
fileapi::ExternalFileSystemMountPointProvider* external_provider =
BrowserContext::GetFileSystemContext(profile_)->external_provider();
DCHECK(external_provider);
@@ -267,12 +261,39 @@ FilePath FileHandlerSelectFileFunction::GrantPermissions() {
// ensure that the target extension can access only this FS entry and
// prevent from traversing FS hierarchy upward.
external_provider->GrantFileAccessToExtension(extension_id(), virtual_path);
- content::ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile(
- render_view_host()->GetProcess()->GetID(),
+
+ // Give read write permissions for the file.
+ permissions_to_grant_.push_back(std::make_pair(
full_path_,
- file_handler_util::GetReadWritePermissions());
+ file_handler_util::GetReadWritePermissions()));
+
+ if (!gdata::util::IsUnderGDataMountPoint(full_path_)) {
+ OnGotPermissionsToGrant(callback, virtual_path);
+ return;
+ }
- return virtual_path;
+ // For drive files, we also have to grant permissions for cache paths.
+ scoped_ptr<std::vector<FilePath> > gdata_paths(new std::vector<FilePath>());
+ gdata_paths->push_back(virtual_path);
+
+ gdata::util::InsertGDataCachePathsPermissions(
+ profile(),
+ gdata_paths.Pass(),
+ &permissions_to_grant_,
+ base::Bind(&FileHandlerSelectFileFunction::OnGotPermissionsToGrant,
+ this, callback, virtual_path));
+}
+
+void FileHandlerSelectFileFunction::OnGotPermissionsToGrant(
+ const GrantPermissionsCallback& callback,
+ const FilePath& virtual_path) {
+ for (size_t i = 0; i < permissions_to_grant_.size(); i++) {
+ content::ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile(
+ render_view_host()->GetProcess()->GetID(),
+ permissions_to_grant_[i].first,
+ permissions_to_grant_[i].second);
+ }
+ callback.Run(virtual_path);
}
void FileHandlerSelectFileFunction::Respond(
diff --git a/chrome/browser/chromeos/extensions/file_browser_handler_api.h b/chrome/browser/chromeos/extensions/file_browser_handler_api.h
index 74ca9bc..2229b36 100644
--- a/chrome/browser/chromeos/extensions/file_browser_handler_api.h
+++ b/chrome/browser/chromeos/extensions/file_browser_handler_api.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_HANDLER_API_H_
#include <string>
+#include <vector>
#include "base/file_path.h"
#include "chrome/browser/extensions/extension_function.h"
@@ -51,20 +52,23 @@ class FileHandlerSelectFileFunction : public AsyncExtensionFunction {
virtual bool RunImpl() OVERRIDE;
private:
- // Calls |DoCreateFile| on file thread and invokes the callback.
- void CreateFileOnFileThread(bool success,
- const std::string& file_system_name,
- const GURL& file_system_root);
+ typedef base::Callback<void(const FilePath& virtual_path)>
+ GrantPermissionsCallback;
// Called on UI thread after the file gets created.
- void OnFileCreated(bool success,
- const std::string& file_system_name,
- const GURL& file_system_root);
+ void OnFileSystemOpened(bool success,
+ const std::string& file_system_name,
+ const GURL& file_system_root);
// Grants file access permissions for the created file to the extension with
// cros mount point provider and child process security policy.
- // Returns virtual path for which has been given permission.
- FilePath GrantPermissions();
+ void GrantPermissions(const GrantPermissionsCallback& callback);
+
+ // Callback called when we collect all paths and permissions that should be
+ // given to the caller render process in order for it to normally access file.
+ void OnGotPermissionsToGrant(
+ const GrantPermissionsCallback& callback,
+ const FilePath& virtual_path);
// Sends response to the extension.
void Respond(bool success,
@@ -79,6 +83,10 @@ class FileHandlerSelectFileFunction : public AsyncExtensionFunction {
// Full file system path of the selected file.
FilePath full_path_;
+ // List of permissions and paths that have to be granted for the selected
+ // files.
+ std::vector<std::pair<FilePath, int> > permissions_to_grant_;
+
// |file_selector_for_test_| and |disable_geture_check_for_test_| are used
// primary in testing to override file selector to be used in the function
// implementation and disable user gesture check.
diff --git a/chrome/common/extensions/api/file_browser_handler.json b/chrome/common/extensions/api/file_browser_handler.json
index 65209fd..a50c2f5 100644
--- a/chrome/common/extensions/api/file_browser_handler.json
+++ b/chrome/common/extensions/api/file_browser_handler.json
@@ -50,16 +50,16 @@
{
"name": "selectFile",
"type": "function",
- "description": "Prompts user to select file path under which a new file will be created. When the user selects file, the file gets created or, if it already existed, truncated. The function has to be called with a user gesture.",
+ "description": "Prompts user to select file path under which file should be saved. When the file is selected, file access permission required to use the file (read, write and create) are granted to the caller. The file will not actually get created during the functin call, so function caller must ensure its existance before using it. The function has to be invoked with a user gesture.",
"parameters": [
{
"name": "selectionParams",
"type": "object",
- "description": "Parameters that will be used to create a new file.",
+ "description": "Parameters that will be used while selecting the file.",
"properties": {
"suggestedName": {
"type": "string",
- "description": "Suggested name for the new file."
+ "description": "Suggested name for the file."
}
}
},
@@ -75,7 +75,7 @@
"properties": {
"success": {
"type": "boolean",
- "description": "Has the file been selected."
+ "description": "Whether the file has been selected."
},
"entry": {
"type": "object",