| Index: content/renderer/notification_provider.cc
|
| diff --git a/content/renderer/notification_provider.cc b/content/renderer/notification_provider.cc
|
| index c4d869c2b1caea82e31f46e5997d5e64675c4808..3c2a3c6e4e7c6106faf51a8aaa828a5b9e23b260 100644
|
| --- a/content/renderer/notification_provider.cc
|
| +++ b/content/renderer/notification_provider.cc
|
| @@ -4,52 +4,92 @@
|
|
|
| #include "content/renderer/notification_provider.h"
|
|
|
| +#include <vector>
|
| +
|
| #include "base/strings/string_util.h"
|
| #include "content/common/desktop_notification_messages.h"
|
| #include "content/common/frame_messages.h"
|
| +#include "content/renderer/notification_icon_loader.h"
|
| #include "content/renderer/render_frame_impl.h"
|
| -#include "third_party/WebKit/public/platform/WebURL.h"
|
| #include "third_party/WebKit/public/web/WebDocument.h"
|
| #include "third_party/WebKit/public/web/WebLocalFrame.h"
|
| -#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
|
|
|
| using blink::WebDocument;
|
| using blink::WebNotification;
|
| using blink::WebNotificationPresenter;
|
| using blink::WebSecurityOrigin;
|
| using blink::WebString;
|
| -using blink::WebURL;
|
| -using blink::WebUserGestureIndicator;
|
|
|
| namespace content {
|
|
|
| NotificationProvider::NotificationProvider(RenderFrame* render_frame)
|
| - : RenderFrameObserver(render_frame) {
|
| -}
|
| + : RenderFrameObserver(render_frame) {}
|
|
|
| -NotificationProvider::~NotificationProvider() {
|
| -}
|
| +NotificationProvider::~NotificationProvider() {}
|
|
|
| bool NotificationProvider::show(const WebNotification& notification) {
|
| - WebDocument document = render_frame()->GetWebFrame()->document();
|
| int notification_id = manager_.RegisterNotification(notification);
|
| + if (notification.iconURL().isEmpty()) {
|
| + DisplayNotification(notification_id, SkBitmap());
|
| + return true;
|
| + }
|
| +
|
| + scoped_ptr<NotificationIconLoader> loader(
|
| + new NotificationIconLoader(
|
| + notification_id,
|
| + base::Bind(&NotificationProvider::DisplayNotification,
|
| + base::Unretained(this))));
|
| +
|
| + loader->Start(notification.iconURL());
|
| +
|
| + pending_notifications_.push_back(loader.release());
|
| + return true;
|
| +}
|
| +
|
| +void NotificationProvider::DisplayNotification(int notification_id,
|
| + const SkBitmap& icon) {
|
| + WebDocument document = render_frame()->GetWebFrame()->document();
|
| + WebNotification notification;
|
| +
|
| + if (!manager_.GetNotification(notification_id, ¬ification)) {
|
| + NOTREACHED();
|
| + return;
|
| + }
|
| +
|
| + RemovePendingNotification(notification_id);
|
|
|
| ShowDesktopNotificationHostMsgParams params;
|
| params.origin = GURL(document.securityOrigin().toString());
|
| - params.icon_url = notification.iconURL();
|
| + params.icon = icon;
|
| params.title = notification.title();
|
| params.body = notification.body();
|
| params.direction = notification.direction();
|
| params.replace_id = notification.replaceId();
|
| - return Send(new DesktopNotificationHostMsg_Show(
|
| - routing_id(), notification_id, params));
|
| +
|
| + Send(new DesktopNotificationHostMsg_Show(routing_id(),
|
| + notification_id,
|
| + params));
|
| +}
|
| +
|
| +bool NotificationProvider::RemovePendingNotification(int notification_id) {
|
| + PendingNotifications::iterator iter = pending_notifications_.begin();
|
| + for (; iter != pending_notifications_.end(); ++iter) {
|
| + if ((*iter)->notification_id() != notification_id)
|
| + continue;
|
| +
|
| + pending_notifications_.erase(iter);
|
| + return true;
|
| + }
|
| +
|
| + return false;
|
| }
|
|
|
| void NotificationProvider::cancel(const WebNotification& notification) {
|
| int id;
|
| bool id_found = manager_.GetId(notification, id);
|
| - // Won't be found if the notification has already been closed by the user.
|
| - if (id_found)
|
| + // Won't be found if the notification has already been closed by the user,
|
| + // or if the notification's icon is still being requested.
|
| + if (id_found && !RemovePendingNotification(id))
|
| Send(new DesktopNotificationHostMsg_Cancel(routing_id(), id));
|
| }
|
|
|
| @@ -58,8 +98,10 @@ void NotificationProvider::objectDestroyed(
|
| int id;
|
| bool id_found = manager_.GetId(notification, id);
|
| // Won't be found if the notification has already been closed by the user.
|
| - if (id_found)
|
| + if (id_found) {
|
| + RemovePendingNotification(id);
|
| manager_.UnregisterNotification(id);
|
| + }
|
| }
|
|
|
| WebNotificationPresenter::Permission NotificationProvider::checkPermission(
|
|
|