Chromium Code Reviews| Index: chrome/browser/extensions/api/file_system/file_system_api.cc |
| 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 68c4cd7054f908f64c489239d3192304dd300e10..6c10faf01acd189f6a6843c1dde087faf40ffa10 100644 |
| --- a/chrome/browser/extensions/api/file_system/file_system_api.cc |
| +++ b/chrome/browser/extensions/api/file_system/file_system_api.cc |
| @@ -5,12 +5,14 @@ |
| #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
| #include <set> |
| +#include <vector> |
| #include "apps/saved_files_service.h" |
| #include "base/bind.h" |
| #include "base/files/file_path.h" |
| #include "base/files/file_util.h" |
| #include "base/logging.h" |
| +#include "base/memory/linked_ptr.h" |
| #include "base/path_service.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| @@ -350,6 +352,70 @@ void ConsentProvider::DialogResultToConsent(const ConsentCallback& callback, |
| break; |
| } |
| } |
| + |
| +ConsentProviderDelegate::ConsentProviderDelegate(Profile* profile, |
| + content::RenderViewHost* host) |
| + : profile_(profile), host_(host) { |
| + DCHECK(profile_); |
| + DCHECK(host_); |
| +} |
| + |
| +ConsentProviderDelegate::~ConsentProviderDelegate() { |
| +} |
| + |
| +// static |
| +void ConsentProviderDelegate::SetAutoDialogButtonForTest( |
| + ui::DialogButton button) { |
| + g_auto_dialog_button_for_test = button; |
| +} |
| + |
| +void ConsentProviderDelegate::ShowDialog( |
| + const extensions::Extension& extension, |
| + base::WeakPtr<file_manager::Volume> volume, |
| + bool writable, |
| + const file_system_api::ConsentProvider::ShowDialogCallback& callback) { |
| + content::WebContents* const foreground_contents = |
| + GetWebContentsForRenderViewHost(profile_, host_); |
| + // If there is no web contents handle, then the method is most probably |
| + // executed from a background page. Find an app window to host the dialog. |
| + content::WebContents* const web_contents = |
| + foreground_contents ? foreground_contents |
| + : GetWebContentsForAppId(profile_, extension.id()); |
| + if (!web_contents) { |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, base::Bind(callback, ui::DIALOG_BUTTON_NONE)); |
| + return; |
| + } |
| + |
| + // Short circuit the user consent dialog for tests. This is far from a pretty |
| + // code design. |
| + if (g_auto_dialog_button_for_test != ui::DIALOG_BUTTON_NONE) { |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, |
| + base::Bind(callback, g_auto_dialog_button_for_test /* result */)); |
| + return; |
| + } |
| + |
| + RequestFileSystemDialogView::ShowDialog(web_contents, extension, volume, |
| + writable, base::Bind(callback)); |
| +} |
| + |
| +bool ConsentProviderDelegate::IsAutoLaunched( |
| + const extensions::Extension& extension) { |
| + chromeos::KioskAppManager::App app_info; |
| + return chromeos::KioskAppManager::Get()->GetApp(extension.id(), &app_info) && |
| + app_info.was_auto_launched_with_zero_delay; |
| +} |
| + |
| +bool ConsentProviderDelegate::IsWhitelistedComponent( |
| + const extensions::Extension& extension) { |
| + for (const auto& whitelisted_id : kRequestFileSystemComponentWhitelist) { |
| + if (extension.id().compare(whitelisted_id) == 0) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| #endif |
| } // namespace file_system_api |
| @@ -1135,9 +1201,17 @@ ExtensionFunction::ResponseAction FileSystemRequestFileSystemFunction::Run() { |
| return RespondNow(Error(kNotSupportedOnCurrentPlatformError)); |
| } |
| +ExtensionFunction::ResponseAction FileSystemGetVolumeListFunction::Run() { |
| + NOTIMPLEMENTED(); |
| + return RespondNow(Error(kNotSupportedOnCurrentPlatformError)); |
| +} |
| #else |
| + |
| FileSystemRequestFileSystemFunction::FileSystemRequestFileSystemFunction() |
| - : chrome_details_(this), consent_provider_(this) { |
| + : chrome_details_(this), |
| + consent_provider_delegate_(chrome_details_.GetProfile(), |
| + render_view_host()), |
| + consent_provider_(&consent_provider_delegate_) { |
| } |
| FileSystemRequestFileSystemFunction::~FileSystemRequestFileSystemFunction() { |
| @@ -1194,61 +1268,6 @@ ExtensionFunction::ResponseAction FileSystemRequestFileSystemFunction::Run() { |
| return RespondLater(); |
| } |
| -// static |
| -void FileSystemRequestFileSystemFunction::SetAutoDialogButtonForTest( |
| - ui::DialogButton button) { |
| - g_auto_dialog_button_for_test = button; |
| -} |
| - |
| -void FileSystemRequestFileSystemFunction::ShowDialog( |
| - const extensions::Extension& extension, |
| - base::WeakPtr<file_manager::Volume> volume, |
| - bool writable, |
| - const file_system_api::ConsentProvider::ShowDialogCallback& callback) { |
| - content::WebContents* const foreground_contents = |
| - GetWebContentsForRenderViewHost(chrome_details_.GetProfile(), |
| - render_view_host()); |
| - // If there is no web contents handle, then the method is most probably |
| - // executed from a background page. Find an app window to host the dialog. |
| - content::WebContents* const web_contents = |
| - foreground_contents ? foreground_contents |
| - : GetWebContentsForAppId(chrome_details_.GetProfile(), |
| - extension_id()); |
| - if (!web_contents) { |
| - base::ThreadTaskRunnerHandle::Get()->PostTask( |
| - FROM_HERE, base::Bind(callback, ui::DIALOG_BUTTON_NONE)); |
| - return; |
| - } |
| - |
| - // Short circuit the user consent dialog for tests. This is far from a pretty |
| - // code design. |
| - if (g_auto_dialog_button_for_test != ui::DIALOG_BUTTON_NONE) { |
| - base::ThreadTaskRunnerHandle::Get()->PostTask( |
| - FROM_HERE, |
| - base::Bind(callback, g_auto_dialog_button_for_test /* result */)); |
| - return; |
| - } |
| - |
| - RequestFileSystemDialogView::ShowDialog(web_contents, extension, volume, |
| - writable, base::Bind(callback)); |
| -} |
| - |
| -bool FileSystemRequestFileSystemFunction::IsAutoLaunched( |
| - const extensions::Extension& extension) { |
| - chromeos::KioskAppManager::App app_info; |
| - return chromeos::KioskAppManager::Get()->GetApp(extension.id(), &app_info) && |
| - app_info.was_auto_launched_with_zero_delay; |
| -} |
| - |
| -bool FileSystemRequestFileSystemFunction::IsWhitelistedComponent( |
| - const extensions::Extension& extension) { |
| - for (const auto& whitelisted_id : kRequestFileSystemComponentWhitelist) { |
| - if (extension.id().compare(whitelisted_id) == 0) |
| - return true; |
| - } |
| - return false; |
| -} |
| - |
| void FileSystemRequestFileSystemFunction::OnConsentReceived( |
| base::WeakPtr<file_manager::Volume> volume, |
| bool writable, |
| @@ -1351,6 +1370,43 @@ void FileSystemRequestFileSystemFunction::OnConsentReceived( |
| SetResult(dict); |
| SendResponse(true); |
| } |
| + |
| +FileSystemGetVolumeListFunction::FileSystemGetVolumeListFunction() |
| + : chrome_details_(this), |
| + consent_provider_delegate_(chrome_details_.GetProfile(), |
| + render_view_host()), |
| + consent_provider_(&consent_provider_delegate_) { |
| +} |
| + |
| +FileSystemGetVolumeListFunction::~FileSystemGetVolumeListFunction() { |
| +} |
| + |
| +ExtensionFunction::ResponseAction FileSystemGetVolumeListFunction::Run() { |
| + // Only kiosk apps in kiosk sessions can use this API. |
| + // Additionally whitelisted component extensions and apps. |
|
benwells
2015/04/07 05:43:13
Nit: this last sentence isn't really a sentence (n
mtomasz
2015/04/07 07:35:35
Done.
|
| + if (!consent_provider_.IsGrantable(*extension())) |
| + return RespondNow(Error(kNotSupportedOnNonKioskSessionError)); |
| + |
| + using file_manager::VolumeManager; |
| + VolumeManager* const volume_manager = |
| + VolumeManager::Get(chrome_details_.GetProfile()); |
| + DCHECK(volume_manager); |
| + |
| + using extensions::api::file_system::Volume; |
| + const auto& volume_list = volume_manager->GetVolumeList(); |
| + std::vector<linked_ptr<Volume>> result_volume_list; |
| + // Convert volume_list to result_volume_list. |
| + for (const auto& volume : volume_list) { |
| + const linked_ptr<Volume> result_volume(new Volume); |
| + result_volume->volume_id = volume->volume_id(); |
| + result_volume->writable = !volume->is_read_only(); |
| + result_volume_list.push_back(result_volume); |
| + } |
| + |
| + return RespondNow( |
| + ArgumentList(extensions::api::file_system::GetVolumeList::Results::Create( |
| + result_volume_list).Pass())); |
| +} |
| #endif |
| } // namespace extensions |