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 a35ff68f3f89ba507e337364c9acf248c85a4368..ba75f0d56363dee93df38b0147ba5fc638a8e832 100644 |
--- a/chrome/browser/extensions/api/file_system/file_system_api.cc |
+++ b/chrome/browser/extensions/api/file_system/file_system_api.cc |
@@ -67,6 +67,7 @@ |
#include "chrome/browser/chromeos/file_manager/app_id.h" |
#include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" |
#include "chrome/browser/extensions/api/file_system/request_file_system_dialog_view.h" |
+#include "chrome/browser/extensions/api/file_system/request_file_system_notification.h" |
#include "chrome/browser/ui/simple_message_box.h" |
#include "components/user_manager/user_manager.h" |
#include "extensions/common/constants.h" |
@@ -280,9 +281,10 @@ std::vector<base::FilePath> GetGrayListedDirectories() { |
} |
#if defined(OS_CHROMEOS) |
-ConsentProvider::ConsentProvider( |
- const UserConsentRequestCallback& user_consent_request_callback) |
- : user_consent_request_callback_(user_consent_request_callback), |
+ConsentProvider::ConsentProvider(const AskUserCallback& ask_user_callback, |
+ const NotifyUserCallback& notify_user_callback) |
+ : ask_user_callback_(ask_user_callback), |
+ notify_user_callback_(notify_user_callback), |
is_auto_launched_callback_(base::Bind(&ConsentProvider::IsAutoLaunched, |
base::Unretained(this))) { |
for (const auto& whitelisted_id : kRequestFileSystemComponentWhitelist) |
@@ -311,19 +313,27 @@ void ConsentProvider::RequestConsent( |
} |
const bool is_auto_launched = is_auto_launched_callback_.Run(extension); |
- const bool requires_consent = |
- !is_auto_launched && extension.location() != Manifest::COMPONENT; |
- if (!requires_consent) { |
- // Grant the permission without showing the dialog. |
+ if (extension.location() == Manifest::COMPONENT) { |
+ // Grant the permission without showing the dialog or notification. |
base::ThreadTaskRunnerHandle::Get()->PostTask( |
FROM_HERE, base::Bind(callback, CONSENT_GRANTED)); |
- } else { |
- DCHECK(!user_consent_request_callback_.is_null()); |
+ return; |
+ } else if (is_auto_launched) { |
+ // Grant the permission without showing the dialog, but with a notification. |
+ DCHECK(!notify_user_callback_.is_null()); |
+ base::ThreadTaskRunnerHandle::Get()->PostTask( |
+ FROM_HERE, base::Bind(notify_user_callback_, volume_info, writable)); |
base::ThreadTaskRunnerHandle::Get()->PostTask( |
- FROM_HERE, base::Bind(user_consent_request_callback_, volume_info, |
- writable, callback)); |
+ FROM_HERE, base::Bind(callback, CONSENT_GRANTED)); |
+ return; |
} |
+ |
+ // By default ask for user consent. |
+ DCHECK(!ask_user_callback_.is_null()); |
+ base::ThreadTaskRunnerHandle::Get()->PostTask( |
+ FROM_HERE, |
+ base::Bind(ask_user_callback_, volume_info, writable, callback)); |
} |
bool ConsentProvider::IsGrantable(const Extension& extension) { |
@@ -1132,8 +1142,9 @@ bool FileSystemGetObservedEntriesFunction::RunSync() { |
FileSystemRequestFileSystemFunction::FileSystemRequestFileSystemFunction() |
: chrome_details_(this) { |
#if defined(OS_CHROMEOS) |
- consent_provider_.reset(new ConsentProvider(base::Bind( |
- &FileSystemRequestFileSystemFunction::OnUserConsentRequested, this))); |
+ consent_provider_.reset(new ConsentProvider( |
+ base::Bind(&FileSystemRequestFileSystemFunction::OnAskUser, this), |
+ base::Bind(&FileSystemRequestFileSystemFunction::OnNotifyUser, this))); |
#endif |
} |
@@ -1210,7 +1221,7 @@ void FileSystemRequestFileSystemFunction::SetAutoDialogButtonForTesting( |
FileSystemRequestFileSystemFunction::auto_dialog_button_for_testing_ = button; |
} |
-void FileSystemRequestFileSystemFunction::OnUserConsentRequested( |
+void FileSystemRequestFileSystemFunction::OnAskUser( |
const file_manager::VolumeInfo& volume_info, |
bool writable, |
const ConsentProvider::ConsentCallback& callback) { |
@@ -1248,6 +1259,13 @@ void FileSystemRequestFileSystemFunction::OnUserConsentRequested( |
callback)); |
} |
+void FileSystemRequestFileSystemFunction::OnNotifyUser( |
+ const file_manager::VolumeInfo& volume_info, |
+ bool writable) { |
+ RequestFileSystemNotification::ShowAutoGrantedNotification( |
+ chrome_details_.GetProfile(), *extension(), volume_info, writable); |
+} |
+ |
void FileSystemRequestFileSystemFunction::OnUserConsentDialogClosed( |
const ConsentProvider::ConsentCallback& callback, |
ui::DialogButton result) { |