Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3092)

Unified Diff: chrome/browser/chromeos/extensions/file_handler_util.cc

Issue 11787028: New FileSystemURL cracking (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Couple of nits I noticed Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/extensions/file_handler_util.cc
diff --git a/chrome/browser/chromeos/extensions/file_handler_util.cc b/chrome/browser/chromeos/extensions/file_handler_util.cc
index dc5aa726cd1369365d4c5418ddbb440e7111d5d9..b6b56e4c97f31656e1a6116e5744107320fc8d2a 100644
--- a/chrome/browser/chromeos/extensions/file_handler_util.cc
+++ b/chrome/browser/chromeos/extensions/file_handler_util.cc
@@ -49,6 +49,7 @@ using content::ChildProcessSecurityPolicy;
using content::SiteInstance;
using content::WebContents;
using extensions::Extension;
+using fileapi::FileSystemURL;
namespace file_handler_util {
@@ -347,27 +348,19 @@ FileBrowserHandlerSet::iterator FindHandler(
// Given the list of selected files, returns array of file action tasks
// that are shared between them.
void FindDefaultTasks(Profile* profile,
- const std::vector<GURL>& files_list,
+ const std::vector<FilePath>& files_list,
const FileBrowserHandlerSet& common_tasks,
FileBrowserHandlerSet* default_tasks) {
DCHECK(default_tasks);
default_tasks->clear();
std::set<std::string> default_ids;
- for (std::vector<GURL>::const_iterator it = files_list.begin();
+ for (std::vector<FilePath>::const_iterator it = files_list.begin();
it != files_list.end(); ++it) {
- // Get the default task for this file based only on the extension (since
- // we don't have MIME types here), and add it to the set of default tasks.
- fileapi::FileSystemURL filesystem_url(*it);
- if (filesystem_url.is_valid() &&
- (filesystem_url.type() == fileapi::kFileSystemTypeDrive ||
- filesystem_url.type() == fileapi::kFileSystemTypeNativeMedia ||
- filesystem_url.type() == fileapi::kFileSystemTypeNativeLocal)) {
- std::string task_id = file_handler_util::GetDefaultTaskIdFromPrefs(
- profile, "", filesystem_url.virtual_path().Extension());
- if (!task_id.empty())
- default_ids.insert(task_id);
- }
+ std::string task_id = file_handler_util::GetDefaultTaskIdFromPrefs(
+ profile, "", it->Extension());
+ if (!task_id.empty())
+ default_ids.insert(task_id);
}
const FileBrowserHandler* builtin_task = NULL;
@@ -454,8 +447,10 @@ bool FindCommonTasks(Profile* profile,
return true;
}
-bool GetTaskForURL(
- Profile* profile, const GURL& url, const FileBrowserHandler** handler) {
+bool GetTaskForURLAndPath(Profile* profile,
+ const GURL& url,
+ const FilePath& file_path,
+ const FileBrowserHandler** handler) {
std::vector<GURL> file_urls;
file_urls.push_back(url);
@@ -467,7 +462,10 @@ bool GetTaskForURL(
if (common_tasks.empty())
return false;
- FindDefaultTasks(profile, file_urls, common_tasks, &default_tasks);
+ std::vector<FilePath> file_paths;
+ file_paths.push_back(file_path);
+
+ FindDefaultTasks(profile, file_paths, common_tasks, &default_tasks);
// If there's none, or more than one, then we don't have a canonical default.
if (!default_tasks.empty()) {
@@ -488,7 +486,7 @@ bool GetTaskForURL(
class ExtensionTaskExecutor : public FileTaskExecutor {
public:
// FileTaskExecutor overrides.
- virtual bool ExecuteAndNotify(const std::vector<GURL>& file_urls,
+ virtual bool ExecuteAndNotify(const std::vector<FileSystemURL>& file_urls,
const FileTaskFinishedCallback& done) OVERRIDE;
private:
@@ -507,7 +505,6 @@ class ExtensionTaskExecutor : public FileTaskExecutor {
FileDefinition();
~FileDefinition();
- GURL target_file_url;
FilePath virtual_path;
FilePath absolute_path;
bool is_directory;
@@ -520,7 +517,7 @@ class ExtensionTaskExecutor : public FileTaskExecutor {
const GURL& handler_base_url,
const scoped_refptr<const extensions::Extension>& handler,
int handler_pid,
- const std::vector<GURL>& file_urls);
+ const std::vector<FileSystemURL>& file_urls);
void ExecuteDoneOnUIThread(bool success);
void ExecuteFileActionsOnUIThread(const std::string& file_system_name,
@@ -548,7 +545,7 @@ class ExtensionTaskExecutor : public FileTaskExecutor {
class WebIntentTaskExecutor : public FileTaskExecutor {
public:
// FileTaskExecutor overrides.
- virtual bool ExecuteAndNotify(const std::vector<GURL>& file_urls,
+ virtual bool ExecuteAndNotify(const std::vector<FileSystemURL>& file_urls,
const FileTaskFinishedCallback& done) OVERRIDE;
private:
@@ -569,7 +566,7 @@ class WebIntentTaskExecutor : public FileTaskExecutor {
class AppTaskExecutor : public FileTaskExecutor {
public:
// FileTaskExecutor overrides.
- virtual bool ExecuteAndNotify(const std::vector<GURL>& file_urls,
+ virtual bool ExecuteAndNotify(const std::vector<FileSystemURL>& file_urls,
const FileTaskFinishedCallback& done) OVERRIDE;
private:
@@ -639,12 +636,12 @@ FileTaskExecutor::FileTaskExecutor(Profile* profile,
FileTaskExecutor::~FileTaskExecutor() {
}
-bool FileTaskExecutor::Execute(const std::vector<GURL>& file_urls) {
+bool FileTaskExecutor::Execute(const std::vector<FileSystemURL>& file_urls) {
return ExecuteAndNotify(file_urls, FileTaskFinishedCallback());
}
bool FileTaskExecutor::FileBrowserHasAccessPermissionForFiles(
- const std::vector<GURL>& files) {
+ const std::vector<FileSystemURL>& files) {
// Check if the file browser extension has permissions for the files in its
// file system context.
GURL site = extensions::ExtensionSystem::Get(profile())->extension_service()->
@@ -657,13 +654,12 @@ bool FileTaskExecutor::FileBrowserHasAccessPermissionForFiles(
return false;
for (size_t i = 0; i < files.size(); ++i) {
- fileapi::FileSystemURL url(files[i]);
// Make sure this url really being used by the right caller extension.
- if (source_url_.GetOrigin() != url.origin())
+ if (source_url_.GetOrigin() != files[i].origin())
return false;
- if (!chromeos::CrosMountPointProvider::CanHandleURL(url) ||
- !external_provider->IsAccessAllowed(url)) {
+ if (!chromeos::CrosMountPointProvider::CanHandleURL(files[i]) ||
+ !external_provider->IsAccessAllowed(files[i])) {
return false;
}
}
@@ -702,7 +698,7 @@ class ExtensionTaskExecutor::ExecuteTasksFileSystemCallbackDispatcher {
scoped_refptr<const Extension> handler_extension,
int handler_pid,
const std::string& action_id,
- const std::vector<GURL>& file_urls) {
+ const std::vector<FileSystemURL>& file_urls) {
return base::Bind(
&ExecuteTasksFileSystemCallbackDispatcher::DidOpenFileSystem,
base::Owned(new ExecuteTasksFileSystemCallbackDispatcher(
@@ -719,8 +715,8 @@ class ExtensionTaskExecutor::ExecuteTasksFileSystemCallbackDispatcher {
}
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
ExtensionTaskExecutor::FileDefinitionList file_list;
- for (std::vector<GURL>::iterator iter = origin_file_urls_.begin();
- iter != origin_file_urls_.end();
+ for (std::vector<FileSystemURL>::iterator iter = urls_.begin();
+ iter != urls_.end();
++iter) {
// Set up file permission access.
ExtensionTaskExecutor::FileDefinition file;
@@ -765,19 +761,19 @@ class ExtensionTaskExecutor::ExecuteTasksFileSystemCallbackDispatcher {
const scoped_refptr<const Extension>& handler_extension,
int handler_pid,
const std::string& action_id,
- const std::vector<GURL>& file_urls)
+ const std::vector<FileSystemURL>& file_urls)
: executor_(executor),
file_system_context_handler_(file_system_context_handler),
handler_extension_(handler_extension),
handler_pid_(handler_pid),
action_id_(action_id),
- origin_file_urls_(file_urls) {
+ urls_(file_urls) {
DCHECK(executor_);
}
// Checks legitimacy of file url and grants file RO access permissions from
// handler (target) extension and its renderer process.
- bool SetupFileAccessPermissions(const GURL& origin_file_url,
+ bool SetupFileAccessPermissions(const FileSystemURL& url,
FileDefinition* file) {
if (!handler_extension_.get())
return false;
@@ -785,8 +781,6 @@ class ExtensionTaskExecutor::ExecuteTasksFileSystemCallbackDispatcher {
if (handler_pid_ == 0)
return false;
- fileapi::FileSystemURL url(origin_file_url);
-
fileapi::ExternalFileSystemMountPointProvider* external_provider_handler =
file_system_context_handler_->external_provider();
@@ -816,11 +810,6 @@ class ExtensionTaskExecutor::ExecuteTasksFileSystemCallbackDispatcher {
handler_extension_->id(), virtual_path);
// Output values.
- GURL target_origin_url(Extension::GetBaseURLFromExtensionId(
- handler_extension_->id()));
- GURL base_url = fileapi::GetFileSystemRootURI(target_origin_url,
- fileapi::kFileSystemTypeExternal);
- file->target_file_url = GURL(base_url.spec() + virtual_path.value());
file->virtual_path = virtual_path;
file->is_directory = file_info.is_directory;
file->absolute_path = local_path;
@@ -832,7 +821,7 @@ class ExtensionTaskExecutor::ExecuteTasksFileSystemCallbackDispatcher {
scoped_refptr<const Extension> handler_extension_;
int handler_pid_;
std::string action_id_;
- std::vector<GURL> origin_file_urls_;
+ std::vector<FileSystemURL> urls_;
DISALLOW_COPY_AND_ASSIGN(ExecuteTasksFileSystemCallbackDispatcher);
};
@@ -851,7 +840,7 @@ ExtensionTaskExecutor::ExtensionTaskExecutor(
ExtensionTaskExecutor::~ExtensionTaskExecutor() {}
bool ExtensionTaskExecutor::ExecuteAndNotify(
- const std::vector<GURL>& file_urls,
+ const std::vector<FileSystemURL>& file_urls,
const FileTaskFinishedCallback& done) {
if (!FileBrowserHasAccessPermissionForFiles(file_urls))
return false;
@@ -895,7 +884,7 @@ void ExtensionTaskExecutor::RequestFileEntryOnFileThread(
const GURL& handler_base_url,
const scoped_refptr<const Extension>& handler,
int handler_pid,
- const std::vector<GURL>& file_urls) {
+ const std::vector<FileSystemURL>& file_urls) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
GURL origin_url = handler_base_url.GetOrigin();
file_system_context_handler->OpenFileSystem(
@@ -1036,15 +1025,14 @@ WebIntentTaskExecutor::WebIntentTaskExecutor(
WebIntentTaskExecutor::~WebIntentTaskExecutor() {}
bool WebIntentTaskExecutor::ExecuteAndNotify(
- const std::vector<GURL>& file_urls,
+ const std::vector<FileSystemURL>& file_urls,
const FileTaskFinishedCallback& done) {
if (!FileBrowserHasAccessPermissionForFiles(file_urls))
return false;
for (size_t i = 0; i != file_urls.size(); ++i) {
- fileapi::FileSystemURL url(file_urls[i]);
extensions::LaunchPlatformAppWithPath(profile(), GetExtension(),
- url.path());
+ file_urls[i].path());
}
if (!done.is_null())
@@ -1066,20 +1054,18 @@ AppTaskExecutor::AppTaskExecutor(
AppTaskExecutor::~AppTaskExecutor() {}
bool AppTaskExecutor::ExecuteAndNotify(
- const std::vector<GURL>& file_urls,
+ const std::vector<FileSystemURL>& file_urls,
const FileTaskFinishedCallback& done) {
if (!FileBrowserHasAccessPermissionForFiles(file_urls))
return false;
for (size_t i = 0; i != file_urls.size(); ++i) {
- fileapi::FileSystemURL url(file_urls[i]);
extensions::LaunchPlatformAppWithFileHandler(profile(), GetExtension(),
- action_id_, url.path());
+ action_id_, file_urls[i].path());
}
if (!done.is_null())
done.Run(true);
-
return true;
}

Powered by Google App Engine
This is Rietveld 408576698