diff options
-rw-r--r-- | apps/DEPS | 2 | ||||
-rw-r--r-- | apps/launcher.cc | 40 | ||||
-rw-r--r-- | chrome/browser/chromeos/file_manager/filesystem_api_util.cc | 109 | ||||
-rw-r--r-- | chrome/browser/chromeos/file_manager/filesystem_api_util.h | 53 | ||||
-rw-r--r-- | chrome/browser/extensions/api/file_handlers/app_file_handler_util.cc | 50 | ||||
-rw-r--r-- | chrome/browser/extensions/api/file_system/file_system_api.cc | 27 | ||||
-rw-r--r-- | chrome/browser/extensions/api/file_system/file_system_api.h | 11 | ||||
-rw-r--r-- | chrome/chrome_browser_chromeos.gypi | 2 |
8 files changed, 212 insertions, 82 deletions
@@ -17,7 +17,7 @@ include_rules = [ # Temporary allowed includes. # TODO(benwells): remove these (http://crbug.com/159366) "+chrome/browser/chrome_notification_types.h", - "+chrome/browser/chromeos/drive", + "+chrome/browser/chromeos/file_manager/filesystem_api_util.h", "+chrome/browser/chromeos/login/users/user_manager.h", "+chrome/browser/lifetime/application_lifetime.h", "+chrome/browser/profiles", diff --git a/apps/launcher.cc b/apps/launcher.cc index 52c1328..acaec41 100644 --- a/apps/launcher.cc +++ b/apps/launcher.cc @@ -38,9 +38,7 @@ #include "url/gurl.h" #if defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/drive/file_errors.h" -#include "chrome/browser/chromeos/drive/file_system_interface.h" -#include "chrome/browser/chromeos/drive/file_system_util.h" +#include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" #include "chrome/browser/chromeos/login/users/user_manager.h" #endif @@ -162,8 +160,11 @@ class PlatformAppPathLauncher void OnFileValid() { #if defined(OS_CHROMEOS) - if (drive::util::IsUnderDriveMountPoint(file_path_)) { - PlatformAppPathLauncher::GetMimeTypeAndLaunchForDriveFile(); + if (file_manager::util::IsUnderNonNativeLocalPath(profile_, file_path_)) { + file_manager::util::GetNonNativeLocalPathMimeType( + profile_, + file_path_, + base::Bind(&PlatformAppPathLauncher::OnGotMimeType, this)); return; } #endif @@ -212,37 +213,14 @@ class PlatformAppPathLauncher } #if defined(OS_CHROMEOS) - void GetMimeTypeAndLaunchForDriveFile() { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - - drive::FileSystemInterface* file_system = - drive::util::GetFileSystemByProfile(profile_); - if (!file_system) { + void OnGotMimeType(bool success, const std::string& mime_type) { + if (!success) { LaunchWithNoLaunchData(); return; } - - file_system->GetFile( - drive::util::ExtractDrivePath(file_path_), - base::Bind(&PlatformAppPathLauncher::OnGotDriveFile, this)); - } - - void OnGotDriveFile(drive::FileError error, - const base::FilePath& file_path, - scoped_ptr<drive::ResourceEntry> entry) { - DCHECK_CURRENTLY_ON(BrowserThread::UI); - - if (error != drive::FILE_ERROR_OK || - !entry || entry->file_specific_info().is_hosted_document()) { - LaunchWithNoLaunchData(); - return; - } - - const std::string& mime_type = - entry->file_specific_info().content_mime_type(); LaunchWithMimeType(mime_type.empty() ? kFallbackMimeType : mime_type); } -#endif // defined(OS_CHROMEOS) +#endif void LaunchWithNoLaunchData() { // This method is required as an entry point on the UI thread. diff --git a/chrome/browser/chromeos/file_manager/filesystem_api_util.cc b/chrome/browser/chromeos/file_manager/filesystem_api_util.cc new file mode 100644 index 0000000..43e07b7 --- /dev/null +++ b/chrome/browser/chromeos/file_manager/filesystem_api_util.cc @@ -0,0 +1,109 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" + +#include "base/callback.h" +#include "base/files/file_path.h" +#include "base/memory/scoped_ptr.h" +#include "chrome/browser/chromeos/drive/file_errors.h" +#include "chrome/browser/chromeos/drive/file_system_interface.h" +#include "chrome/browser/chromeos/drive/file_system_util.h" +#include "content/public/browser/browser_thread.h" + +namespace file_manager { +namespace util { + +namespace { + +void GetMimeTypeAfterGetResourceEntry( + const base::Callback<void(bool, const std::string&)>& callback, + drive::FileError error, + scoped_ptr<drive::ResourceEntry> entry) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + + if (error != drive::FILE_ERROR_OK || !entry->has_file_specific_info()) { + callback.Run(false, std::string()); + return; + } + callback.Run(true, entry->file_specific_info().content_mime_type()); +} + +void CheckDirectoryAfterDriveCheck(const base::Callback<void(bool)>& callback, + drive::FileError error) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + + return callback.Run(error == drive::FILE_ERROR_OK); +} + +void CheckWritableAfterDriveCheck(const base::Callback<void(bool)>& callback, + drive::FileError error, + const base::FilePath& local_path) { + // This is called on the IO-allowed blocking pool. Call back to UI. + content::BrowserThread::PostTask( + content::BrowserThread::UI, + FROM_HERE, + base::Bind(callback, error == drive::FILE_ERROR_OK)); +} + +} // namespace + +bool IsUnderNonNativeLocalPath(Profile* profile, + const base::FilePath& path) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + + // TODO(kinaba): support other types of volumes besides Drive. + return drive::util::IsUnderDriveMountPoint(path); +} + +void GetNonNativeLocalPathMimeType( + Profile* profile, + const base::FilePath& path, + const base::Callback<void(bool, const std::string&)>& callback) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + + // TODO(kinaba): support other types of volumes besides Drive. + drive::FileSystemInterface* file_system = + drive::util::GetFileSystemByProfile(profile); + if (!file_system) { + content::BrowserThread::PostTask( + content::BrowserThread::UI, + FROM_HERE, + base::Bind(callback, false, std::string())); + return; + } + + file_system->GetResourceEntry( + drive::util::ExtractDrivePath(path), + base::Bind(&GetMimeTypeAfterGetResourceEntry, callback)); +} + +void IsNonNativeLocalPathDirectory( + Profile* profile, + const base::FilePath& path, + const base::Callback<void(bool)>& callback) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + + // TODO(kinaba): support other types of volumes besides Drive. + drive::util::CheckDirectoryExists( + profile, + path, + base::Bind(&CheckDirectoryAfterDriveCheck, callback)); +} + +void PrepareNonNativeLocalPathWritableFile( + Profile* profile, + const base::FilePath& path, + const base::Callback<void(bool)>& callback) { + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); + + // TODO(kinaba): support other types of volumes besides Drive. + drive::util::PrepareWritableFileAndRun( + profile, + path, + base::Bind(&CheckWritableAfterDriveCheck, callback)); +} + +} // namespace util +} // namespace file_manager diff --git a/chrome/browser/chromeos/file_manager/filesystem_api_util.h b/chrome/browser/chromeos/file_manager/filesystem_api_util.h new file mode 100644 index 0000000..3ce7a6b --- /dev/null +++ b/chrome/browser/chromeos/file_manager/filesystem_api_util.h @@ -0,0 +1,53 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// The file contains utility functions to implement chrome.fileSystem API for +// file paths that do not directly map to host machine's file system path, such +// as Google Drive or virtual volumes provided by fileSystemProvider extensions. + +#ifndef CHROME_BROWSER_CHROMEOS_FILE_MANAGER_FILESYSTEM_API_UTIL_H_ +#define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_FILESYSTEM_API_UTIL_H_ + +#include <string> + +#include "base/callback_forward.h" + +class Profile; + +namespace base { +class FilePath; +} // namespace base + +namespace file_manager { +namespace util { + +// Checks whether the given |path| points to a non-local filesystem that +// requires special handling. +bool IsUnderNonNativeLocalPath(Profile* profile, const base::FilePath& path); + +// Returns the mime type of the file pointed by |path|, and asynchronously sends +// the result to |callback|. +void GetNonNativeLocalPathMimeType( + Profile* profile, + const base::FilePath& path, + const base::Callback<void(bool, const std::string&)>& callback); + +// Checks whether the |path| points to a directory, and asynchronously sends +// the result to |callback|. +void IsNonNativeLocalPathDirectory( + Profile* profile, + const base::FilePath& path, + const base::Callback<void(bool)>& callback); + +// Prepares a writable file at |path|, i.e., creates a file there if it didn't +// exist, and asynchronously sends to |callback| whether it succeeded. +void PrepareNonNativeLocalPathWritableFile( + Profile* profile, + const base::FilePath& path, + const base::Callback<void(bool)>& callback); + +} // namespace util +} // namespace file_manager + +#endif // CHROME_BROWSER_CHROMEOS_FILE_MANAGER_FILESYSTEM_API_UTIL_H_ 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 04d54af..9c92117 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 @@ -18,7 +18,7 @@ #include "webkit/common/fileapi/file_system_types.h" #if defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/drive/file_system_util.h" +#include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" #endif using apps::file_handler_util::GrantedFileEntry; @@ -116,11 +116,7 @@ class WritableFileChecker void CheckLocalWritableFiles(); #if defined(OS_CHROMEOS) - void CheckRemoteWritableFile(const base::FilePath& remote_path, - drive::FileError error, - const base::FilePath& local_path); - void RemoteCheckDone(const base::FilePath& remote_path, - drive::FileError error); + void NonNativeLocalPathCheckDone(const base::FilePath& path, bool success); #endif const std::vector<base::FilePath> paths_; @@ -147,23 +143,23 @@ WritableFileChecker::WritableFileChecker( void WritableFileChecker::Check() { #if defined(OS_CHROMEOS) - if (drive::util::IsUnderDriveMountPoint(paths_[0])) { + if (file_manager::util::IsUnderNonNativeLocalPath(profile_, paths_[0])) { outstanding_tasks_ = paths_.size(); for (std::vector<base::FilePath>::const_iterator it = paths_.begin(); it != paths_.end(); ++it) { - DCHECK(drive::util::IsUnderDriveMountPoint(*it)); if (is_directory_) { - drive::util::CheckDirectoryExists( + file_manager::util::IsNonNativeLocalPathDirectory( profile_, *it, - base::Bind(&WritableFileChecker::RemoteCheckDone, this, *it)); + base::Bind(&WritableFileChecker::NonNativeLocalPathCheckDone, + this, *it)); } else { - drive::util::PrepareWritableFileAndRun( + file_manager::util::PrepareNonNativeLocalPathWritableFile( profile_, *it, - base::Bind(&WritableFileChecker::CheckRemoteWritableFile, this, - *it)); + base::Bind(&WritableFileChecker::NonNativeLocalPathCheckDone, + this, *it)); } } return; @@ -216,27 +212,13 @@ void WritableFileChecker::CheckLocalWritableFiles() { } #if defined(OS_CHROMEOS) -void WritableFileChecker::CheckRemoteWritableFile( - const base::FilePath& remote_path, - drive::FileError error, - const base::FilePath& /* local_path */) { - RemoteCheckDone(remote_path, error); -} - -void WritableFileChecker::RemoteCheckDone( - const base::FilePath& remote_path, - drive::FileError error) { - if (error == drive::FILE_ERROR_OK) { - content::BrowserThread::PostTask( - content::BrowserThread::UI, - FROM_HERE, - base::Bind(&WritableFileChecker::TaskDone, this)); - } else { - content::BrowserThread::PostTask( - content::BrowserThread::UI, - FROM_HERE, - base::Bind(&WritableFileChecker::Error, this, remote_path)); - } +void WritableFileChecker::NonNativeLocalPathCheckDone( + const base::FilePath& path, + bool success) { + if (success) + TaskDone(); + else + Error(path); } #endif 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 3313cd0..9200d89 100644 --- a/chrome/browser/extensions/api/file_system/file_system_api.cc +++ b/chrome/browser/extensions/api/file_system/file_system_api.cc @@ -51,7 +51,7 @@ #endif #if defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/drive/file_system_util.h" +#include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" #endif using apps::SavedFileEntry; @@ -681,12 +681,23 @@ void FileSystemChooseEntryFunction::FilesSelected( } content::WebContents* web_contents = app_window->web_contents(); + DCHECK_EQ(paths.size(), 1u); +#if defined(OS_CHROMEOS) + base::FilePath check_path = + file_manager::util::IsUnderNonNativeLocalPath(GetProfile(), paths[0]) + ? paths[0] + : base::MakeAbsoluteFilePath(paths[0]); +#else + base::FilePath check_path = base::MakeAbsoluteFilePath(paths[0]); +#endif + content::BrowserThread::PostTask( content::BrowserThread::FILE, FROM_HERE, base::Bind( &FileSystemChooseEntryFunction::ConfirmDirectoryAccessOnFileThread, this, + check_path, paths, web_contents)); return; @@ -701,17 +712,10 @@ void FileSystemChooseEntryFunction::FileSelectionCanceled() { } void FileSystemChooseEntryFunction::ConfirmDirectoryAccessOnFileThread( + const base::FilePath& check_path, const std::vector<base::FilePath>& paths, content::WebContents* web_contents) { - DCHECK_EQ(paths.size(), 1u); -#if defined(OS_CHROMEOS) - const base::FilePath path = - drive::util::IsUnderDriveMountPoint(paths[0]) ? paths[0] : - base::MakeAbsoluteFilePath(paths[0]); -#else - const base::FilePath path = base::MakeAbsoluteFilePath(paths[0]); -#endif - if (path.empty()) { + if (check_path.empty()) { content::BrowserThread::PostTask( content::BrowserThread::UI, FROM_HERE, @@ -723,7 +727,8 @@ void FileSystemChooseEntryFunction::ConfirmDirectoryAccessOnFileThread( for (size_t i = 0; i < arraysize(kGraylistedPaths); i++) { base::FilePath graylisted_path; if (PathService::Get(kGraylistedPaths[i], &graylisted_path) && - (path == graylisted_path || path.IsParent(graylisted_path))) { + (check_path == graylisted_path || + check_path.IsParent(graylisted_path))) { if (g_skip_directory_confirmation_for_test) { if (g_allow_directory_access_for_test) { break; 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 7aee4e5..df4e662 100644 --- a/chrome/browser/extensions/api/file_system/file_system_api.h +++ b/chrome/browser/extensions/api/file_system/file_system_api.h @@ -157,12 +157,13 @@ class FileSystemChooseEntryFunction : public FileSystemEntryFunction { void FilesSelected(const std::vector<base::FilePath>& path); void FileSelectionCanceled(); - // Check if the chosen directory is or is an ancestor of a sensitive - // directory. If so, show a dialog to confirm that the user wants to open the - // directory. Calls OnDirectoryAccessConfirmed if the directory isn't - // sensitive or the user chooses to open it. Otherwise, calls - // FileSelectionCanceled. + // Check if |check_path|, the canonicalized form of the chosen directory + // |paths|, is or is an ancestor of a sensitive directory. If so, show a + // dialog to confirm that the user wants to open the directory. + // Calls OnDirectoryAccessConfirmed if the directory isn't sensitive or the + // user chooses to open it. Otherwise, calls FileSelectionCanceled. void ConfirmDirectoryAccessOnFileThread( + const base::FilePath& check_path, const std::vector<base::FilePath>& paths, content::WebContents* web_contents); void OnDirectoryAccessConfirmed(const std::vector<base::FilePath>& paths); diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi index 4f6ae7c..fa130b1 100644 --- a/chrome/chrome_browser_chromeos.gypi +++ b/chrome/chrome_browser_chromeos.gypi @@ -353,6 +353,8 @@ 'browser/chromeos/file_manager/file_watcher.h', 'browser/chromeos/file_manager/fileapi_util.cc', 'browser/chromeos/file_manager/fileapi_util.h', + 'browser/chromeos/file_manager/filesystem_api_util.cc', + 'browser/chromeos/file_manager/filesystem_api_util.h', 'browser/chromeos/file_manager/mime_util.cc', 'browser/chromeos/file_manager/mime_util.h', 'browser/chromeos/file_manager/mounted_disk_monitor.cc', |