This repository has been archived by the owner on Apr 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a notification about auto-granted access to file systems.
For auto-launched kiosk apps permissions are granted automatically, without a user consent. In such case a notification will be shown though. TEST=unit_tests: *FileSystemApiConsentProviderTest* BUG=440674 Review URL: https://codereview.chromium.org/1032313002 Cr-Commit-Position: refs/heads/master@{#324169}
- Loading branch information
1 parent
aa89c5b
commit 232bdea
Showing
6 changed files
with
240 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
chrome/browser/extensions/api/file_system/request_file_system_notification.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// Copyright 2015 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/extensions/api/file_system/request_file_system_notification.h" | ||
|
||
#include "base/memory/ref_counted.h" | ||
#include "base/strings/string16.h" | ||
#include "base/strings/utf_string_conversions.h" | ||
#include "chrome/browser/browser_process.h" | ||
#include "chrome/browser/chromeos/file_manager/volume_manager.h" | ||
#include "chrome/browser/extensions/app_icon_loader_impl.h" | ||
#include "chrome/grit/generated_resources.h" | ||
#include "extensions/common/extension.h" | ||
#include "ui/base/l10n/l10n_util.h" | ||
#include "ui/message_center/message_center.h" | ||
#include "ui/message_center/notification.h" | ||
#include "ui/message_center/notification_delegate.h" | ||
#include "ui/message_center/notification_types.h" | ||
#include "ui/message_center/notifier_settings.h" | ||
|
||
using file_manager::Volume; | ||
using message_center::Notification; | ||
|
||
namespace { | ||
|
||
// Extension icon size for the notification. | ||
const int kIconSize = 48; | ||
|
||
scoped_ptr<Notification> CreateAutoGrantedNotification( | ||
const extensions::Extension& extension, | ||
const base::WeakPtr<Volume>& volume, | ||
bool writable, | ||
message_center::NotificationDelegate* delegate) { | ||
DCHECK(delegate); | ||
|
||
// If the volume is gone, then do not show the notification. | ||
if (!volume.get()) | ||
return scoped_ptr<Notification>(nullptr); | ||
|
||
const std::string notification_id = | ||
extension.id() + "-" + volume->volume_id(); | ||
message_center::RichNotificationData data; | ||
data.clickable = false; | ||
|
||
// TODO(mtomasz): Share this code with RequestFileSystemDialogView. | ||
const base::string16 display_name = | ||
base::UTF8ToUTF16(!volume->volume_label().empty() ? volume->volume_label() | ||
: volume->volume_id()); | ||
const base::string16 message = l10n_util::GetStringFUTF16( | ||
writable | ||
? IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_NOTIFICATION_WRITABLE_MESSAGE | ||
: IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_NOTIFICATION_MESSAGE, | ||
display_name); | ||
|
||
scoped_ptr<Notification> notification(new Notification( | ||
message_center::NOTIFICATION_TYPE_SIMPLE, notification_id, | ||
base::UTF8ToUTF16(extension.name()), message, | ||
gfx::Image(), // Updated asynchronously later. | ||
base::string16(), // display_source | ||
message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, | ||
notification_id), | ||
data, delegate)); | ||
|
||
return notification.Pass(); | ||
} | ||
|
||
} // namespace | ||
|
||
// static | ||
void RequestFileSystemNotification::ShowAutoGrantedNotification( | ||
Profile* profile, | ||
const extensions::Extension& extension, | ||
const base::WeakPtr<Volume>& volume, | ||
bool writable) { | ||
DCHECK(profile); | ||
scoped_refptr<RequestFileSystemNotification> | ||
request_file_system_notification = make_scoped_refptr( | ||
new RequestFileSystemNotification(profile, extension)); | ||
scoped_ptr<message_center::Notification> notification( | ||
CreateAutoGrantedNotification( | ||
extension, volume, writable, | ||
request_file_system_notification.get() /* delegate */)); | ||
if (notification.get()) | ||
request_file_system_notification->Show(notification.Pass()); | ||
} | ||
|
||
void RequestFileSystemNotification::SetAppImage(const std::string& id, | ||
const gfx::ImageSkia& image) { | ||
extension_icon_.reset(new gfx::Image(image)); | ||
|
||
// If there is a pending notification, then show it now. | ||
if (pending_notification_.get()) { | ||
pending_notification_->set_icon(*extension_icon_.get()); | ||
g_browser_process->message_center()->AddNotification( | ||
pending_notification_.Pass()); | ||
} | ||
} | ||
|
||
RequestFileSystemNotification::RequestFileSystemNotification( | ||
Profile* profile, | ||
const extensions::Extension& extension) | ||
: icon_loader_( | ||
new extensions::AppIconLoaderImpl(profile, kIconSize, this)) { | ||
icon_loader_->FetchImage(extension.id()); | ||
} | ||
|
||
RequestFileSystemNotification::~RequestFileSystemNotification() { | ||
} | ||
|
||
void RequestFileSystemNotification::Show( | ||
scoped_ptr<Notification> notification) { | ||
pending_notification_.reset(notification.release()); | ||
// If the extension icon is not known yet, then defer showing the notification | ||
// until it is (from SetAppImage). | ||
if (!extension_icon_.get()) | ||
return; | ||
|
||
pending_notification_->set_icon(*extension_icon_.get()); | ||
g_browser_process->message_center()->AddNotification( | ||
pending_notification_.Pass()); | ||
} |
65 changes: 65 additions & 0 deletions
65
chrome/browser/extensions/api/file_system/request_file_system_notification.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2015 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. | ||
|
||
#ifndef CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_REQUEST_FILE_SYSTEM_NOTIFICATION_H_ | ||
#define CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_REQUEST_FILE_SYSTEM_NOTIFICATION_H_ | ||
|
||
#include <string> | ||
|
||
#include "base/callback.h" | ||
#include "base/memory/scoped_ptr.h" | ||
#include "base/memory/weak_ptr.h" | ||
#include "chrome/browser/extensions/app_icon_loader.h" | ||
#include "ui/message_center/notification_delegate.h" | ||
|
||
class Profile; | ||
|
||
namespace extensions { | ||
class Extension; | ||
} // namespace extensions | ||
|
||
namespace file_manager { | ||
class Volume; | ||
} // namespace file_manager | ||
|
||
namespace gfx { | ||
class Image; | ||
class ImageSkia; | ||
} // namespace gfx | ||
|
||
namespace message_center { | ||
class Notification; | ||
} // namespace message_center | ||
|
||
// Shows notifications for the chrome.fileSystem.requestFileSystem() API. | ||
class RequestFileSystemNotification | ||
: public message_center::NotificationDelegate, | ||
public extensions::AppIconLoader::Delegate { | ||
public: | ||
// Shows a notification about automatically granted access to a file system. | ||
static void ShowAutoGrantedNotification( | ||
Profile* profile, | ||
const extensions::Extension& extension, | ||
const base::WeakPtr<file_manager::Volume>& volume, | ||
bool writable); | ||
|
||
private: | ||
RequestFileSystemNotification(Profile* profile, | ||
const extensions::Extension& extension); | ||
~RequestFileSystemNotification() override; | ||
|
||
// Shows the notification. Can be called only once. | ||
void Show(scoped_ptr<message_center::Notification> notification); | ||
|
||
// extensions::AppIconLoader::Delegate overrides: | ||
void SetAppImage(const std::string& id, const gfx::ImageSkia& image) override; | ||
|
||
scoped_ptr<extensions::AppIconLoader> icon_loader_; | ||
scoped_ptr<gfx::Image> extension_icon_; | ||
scoped_ptr<message_center::Notification> pending_notification_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(RequestFileSystemNotification); | ||
}; | ||
|
||
#endif // CHROME_BROWSER_EXTENSIONS_API_FILE_SYSTEM_REQUEST_FILE_SYSTEM_NOTIFICATION_H_ |
Oops, something went wrong.