Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: content/renderer/notification_provider.cc

Issue 554213003: Request the icon of a Web Notification in the renderer process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: include logging.h Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/notification_provider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/notification_provider.h" 5 #include "content/renderer/notification_provider.h"
6 6
7 #include <vector>
8
7 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
8 #include "content/common/desktop_notification_messages.h" 10 #include "content/common/desktop_notification_messages.h"
9 #include "content/common/frame_messages.h" 11 #include "content/common/frame_messages.h"
12 #include "content/renderer/notification_icon_loader.h"
10 #include "content/renderer/render_frame_impl.h" 13 #include "content/renderer/render_frame_impl.h"
11 #include "third_party/WebKit/public/platform/WebURL.h"
12 #include "third_party/WebKit/public/web/WebDocument.h" 14 #include "third_party/WebKit/public/web/WebDocument.h"
13 #include "third_party/WebKit/public/web/WebLocalFrame.h" 15 #include "third_party/WebKit/public/web/WebLocalFrame.h"
14 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
15 16
16 using blink::WebDocument; 17 using blink::WebDocument;
17 using blink::WebNotification; 18 using blink::WebNotification;
18 using blink::WebNotificationPresenter; 19 using blink::WebNotificationPresenter;
19 using blink::WebSecurityOrigin; 20 using blink::WebSecurityOrigin;
20 using blink::WebString; 21 using blink::WebString;
21 using blink::WebURL;
22 using blink::WebUserGestureIndicator;
23 22
24 namespace content { 23 namespace content {
25 24
26 NotificationProvider::NotificationProvider(RenderFrame* render_frame) 25 NotificationProvider::NotificationProvider(RenderFrame* render_frame)
27 : RenderFrameObserver(render_frame) { 26 : RenderFrameObserver(render_frame) {}
27
28 NotificationProvider::~NotificationProvider() {}
29
30 bool NotificationProvider::show(const WebNotification& notification) {
31 int notification_id = manager_.RegisterNotification(notification);
32 if (notification.iconURL().isEmpty()) {
33 DisplayNotification(notification_id, SkBitmap());
34 return true;
35 }
36
37 scoped_ptr<NotificationIconLoader> loader(
38 new NotificationIconLoader(
39 notification_id,
40 base::Bind(&NotificationProvider::DisplayNotification,
41 base::Unretained(this))));
42
43 loader->Start(notification.iconURL());
44
45 pending_notifications_.push_back(loader.release());
46 return true;
28 } 47 }
29 48
30 NotificationProvider::~NotificationProvider() { 49 void NotificationProvider::DisplayNotification(int notification_id,
31 } 50 const SkBitmap& icon) {
51 WebDocument document = render_frame()->GetWebFrame()->document();
52 WebNotification notification;
32 53
33 bool NotificationProvider::show(const WebNotification& notification) { 54 if (!manager_.GetNotification(notification_id, &notification)) {
34 WebDocument document = render_frame()->GetWebFrame()->document(); 55 NOTREACHED();
35 int notification_id = manager_.RegisterNotification(notification); 56 return;
57 }
58
59 RemovePendingNotification(notification_id);
36 60
37 ShowDesktopNotificationHostMsgParams params; 61 ShowDesktopNotificationHostMsgParams params;
38 params.origin = GURL(document.securityOrigin().toString()); 62 params.origin = GURL(document.securityOrigin().toString());
39 params.icon_url = notification.iconURL(); 63 params.icon = icon;
40 params.title = notification.title(); 64 params.title = notification.title();
41 params.body = notification.body(); 65 params.body = notification.body();
42 params.direction = notification.direction(); 66 params.direction = notification.direction();
43 params.replace_id = notification.replaceId(); 67 params.replace_id = notification.replaceId();
44 return Send(new DesktopNotificationHostMsg_Show( 68
45 routing_id(), notification_id, params)); 69 Send(new DesktopNotificationHostMsg_Show(routing_id(),
70 notification_id,
71 params));
72 }
73
74 bool NotificationProvider::RemovePendingNotification(int notification_id) {
75 PendingNotifications::iterator iter = pending_notifications_.begin();
76 for (; iter != pending_notifications_.end(); ++iter) {
77 if ((*iter)->notification_id() != notification_id)
78 continue;
79
80 pending_notifications_.erase(iter);
81 return true;
82 }
83
84 return false;
46 } 85 }
47 86
48 void NotificationProvider::cancel(const WebNotification& notification) { 87 void NotificationProvider::cancel(const WebNotification& notification) {
49 int id; 88 int id;
50 bool id_found = manager_.GetId(notification, id); 89 bool id_found = manager_.GetId(notification, id);
51 // Won't be found if the notification has already been closed by the user. 90 // Won't be found if the notification has already been closed by the user,
52 if (id_found) 91 // or if the notification's icon is still being requested.
92 if (id_found && !RemovePendingNotification(id))
53 Send(new DesktopNotificationHostMsg_Cancel(routing_id(), id)); 93 Send(new DesktopNotificationHostMsg_Cancel(routing_id(), id));
54 } 94 }
55 95
56 void NotificationProvider::objectDestroyed( 96 void NotificationProvider::objectDestroyed(
57 const WebNotification& notification) { 97 const WebNotification& notification) {
58 int id; 98 int id;
59 bool id_found = manager_.GetId(notification, id); 99 bool id_found = manager_.GetId(notification, id);
60 // Won't be found if the notification has already been closed by the user. 100 // Won't be found if the notification has already been closed by the user.
61 if (id_found) 101 if (id_found) {
102 RemovePendingNotification(id);
62 manager_.UnregisterNotification(id); 103 manager_.UnregisterNotification(id);
104 }
63 } 105 }
64 106
65 WebNotificationPresenter::Permission NotificationProvider::checkPermission( 107 WebNotificationPresenter::Permission NotificationProvider::checkPermission(
66 const WebSecurityOrigin& origin) { 108 const WebSecurityOrigin& origin) {
67 int permission = WebNotificationPresenter::PermissionNotAllowed; 109 int permission = WebNotificationPresenter::PermissionNotAllowed;
68 Send(new DesktopNotificationHostMsg_CheckPermission( 110 Send(new DesktopNotificationHostMsg_CheckPermission(
69 routing_id(), 111 routing_id(),
70 GURL(origin.toString()), 112 GURL(origin.toString()),
71 &permission)); 113 &permission));
72 return static_cast<WebNotificationPresenter::Permission>(permission); 114 return static_cast<WebNotificationPresenter::Permission>(permission);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // the page before the associated toast was clicked on. 166 // the page before the associated toast was clicked on.
125 if (found) 167 if (found)
126 notification.dispatchClickEvent(); 168 notification.dispatchClickEvent();
127 } 169 }
128 170
129 void NotificationProvider::OnNavigate() { 171 void NotificationProvider::OnNavigate() {
130 manager_.Clear(); 172 manager_.Clear();
131 } 173 }
132 174
133 } // namespace content 175 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/notification_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698