set notification close callback before requesting user permission

This commit is contained in:
deepak1556 2016-10-25 19:02:06 +05:30
parent 4fdca64030
commit ee4442f964
4 changed files with 33 additions and 35 deletions

View file

@ -82,8 +82,10 @@ LibnotifyNotification::LibnotifyNotification(NotificationDelegate* delegate,
} }
LibnotifyNotification::~LibnotifyNotification() { LibnotifyNotification::~LibnotifyNotification() {
g_signal_handlers_disconnect_by_data(notification_, this); if (notification_) {
g_object_unref(notification_); g_signal_handlers_disconnect_by_data(notification_, this);
g_object_unref(notification_);
}
} }
void LibnotifyNotification::Show(const base::string16& title, void LibnotifyNotification::Show(const base::string16& title,

View file

@ -24,8 +24,9 @@ CocoaNotification::CocoaNotification(NotificationDelegate* delegate,
} }
CocoaNotification::~CocoaNotification() { CocoaNotification::~CocoaNotification() {
[NSUserNotificationCenter.defaultUserNotificationCenter if (notification_)
removeDeliveredNotification:notification_]; [NSUserNotificationCenter.defaultUserNotificationCenter
removeDeliveredNotification:notification_];
} }
void CocoaNotification::Show(const base::string16& title, void CocoaNotification::Show(const base::string16& title,

View file

@ -34,6 +34,9 @@ class Notification {
void NotificationDismissed(); void NotificationDismissed();
void NotificationFailed(); void NotificationFailed();
// delete this.
void Destroy();
base::WeakPtr<Notification> GetWeakPtr() { base::WeakPtr<Notification> GetWeakPtr() {
return weak_factory_.GetWeakPtr(); return weak_factory_.GetWeakPtr();
} }
@ -46,9 +49,6 @@ class Notification {
NotificationPresenter* presenter); NotificationPresenter* presenter);
virtual ~Notification(); virtual ~Notification();
// delete this.
void Destroy();
private: private:
friend class NotificationPresenter; friend class NotificationPresenter;

View file

@ -21,28 +21,17 @@ void RemoveNotification(base::WeakPtr<Notification> notification) {
notification->Dismiss(); notification->Dismiss();
} }
void OnWebNotificationAllowed( void OnWebNotificationAllowed(base::WeakPtr<Notification> notification,
brightray::BrowserClient* browser_client, const SkBitmap& icon,
const SkBitmap& icon, const content::PlatformNotificationData& data,
const content::PlatformNotificationData& data, bool audio_muted,
std::unique_ptr<content::DesktopNotificationDelegate> delegate, bool allowed) {
base::Closure* cancel_callback, if (!allowed) {
bool audio_muted, notification->Destroy();
bool allowed) {
if (!allowed)
return; return;
auto presenter = browser_client->GetNotificationPresenter();
if (!presenter)
return;
std::unique_ptr<NotificationDelegateAdapter> adapter(
new NotificationDelegateAdapter(std::move(delegate)));
auto notification = presenter->CreateNotification(adapter.get());
if (notification) {
ignore_result(adapter.release()); // it will release itself automatically.
notification->Show(data.title, data.body, data.tag, data.icon, icon,
audio_muted ? true : data.silent);
*cancel_callback = base::Bind(&RemoveNotification, notification);
} }
notification->Show(data.title, data.body, data.tag, data.icon, icon,
audio_muted ? true : data.silent);
} }
} // namespace } // namespace
@ -77,14 +66,20 @@ void PlatformNotificationService::DisplayNotification(
const content::NotificationResources& notification_resources, const content::NotificationResources& notification_resources,
std::unique_ptr<content::DesktopNotificationDelegate> delegate, std::unique_ptr<content::DesktopNotificationDelegate> delegate,
base::Closure* cancel_callback) { base::Closure* cancel_callback) {
browser_client_->WebNotificationAllowed( auto presenter = browser_client_->GetNotificationPresenter();
render_process_id_, if (!presenter)
base::Bind(&OnWebNotificationAllowed, return;
browser_client_, std::unique_ptr<NotificationDelegateAdapter> adapter(
notification_resources.notification_icon, new NotificationDelegateAdapter(std::move(delegate)));
notification_data, auto notification = presenter->CreateNotification(adapter.get());
base::Passed(&delegate), if (notification) {
cancel_callback)); ignore_result(adapter.release()); // it will release itself automatically.
*cancel_callback = base::Bind(&RemoveNotification, notification);
browser_client_->WebNotificationAllowed(
render_process_id_, base::Bind(&OnWebNotificationAllowed, notification,
notification_resources.notification_icon,
notification_data));
}
} }
void PlatformNotificationService::DisplayPersistentNotification( void PlatformNotificationService::DisplayPersistentNotification(