| OLD | NEW |
| 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 "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "content/common/desktop_notification_messages.h" | 8 #include "content/common/desktop_notification_messages.h" |
| 9 #include "content/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
| 10 #include "content/renderer/render_view_impl.h" | 10 #include "content/renderer/render_view_impl.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 | 29 |
| 30 NotificationProvider::NotificationProvider(RenderViewImpl* render_view) | 30 NotificationProvider::NotificationProvider(RenderViewImpl* render_view) |
| 31 : RenderViewObserver(render_view) { | 31 : RenderViewObserver(render_view) { |
| 32 } | 32 } |
| 33 | 33 |
| 34 NotificationProvider::~NotificationProvider() { | 34 NotificationProvider::~NotificationProvider() { |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool NotificationProvider::show(const WebNotification& notification) { | 37 bool NotificationProvider::show(const WebNotification& notification) { |
| 38 WebDocument document = render_view()->GetWebView()->mainFrame()->document(); |
| 38 int notification_id = manager_.RegisterNotification(notification); | 39 int notification_id = manager_.RegisterNotification(notification); |
| 39 if (notification.isHTML()) | 40 |
| 40 return ShowHTML(notification, notification_id); | 41 ShowDesktopNotificationHostMsgParams params; |
| 41 else | 42 params.origin = GURL(document.securityOrigin().toString()); |
| 42 return ShowText(notification, notification_id); | 43 params.icon_url = notification.iconURL(); |
| 44 params.title = notification.title(); |
| 45 params.body = notification.body(); |
| 46 params.direction = notification.direction(); |
| 47 params.notification_id = notification_id; |
| 48 params.replace_id = notification.replaceId(); |
| 49 return Send(new DesktopNotificationHostMsg_Show(routing_id(), params)); |
| 43 } | 50 } |
| 44 | 51 |
| 45 void NotificationProvider::cancel(const WebNotification& notification) { | 52 void NotificationProvider::cancel(const WebNotification& notification) { |
| 46 int id; | 53 int id; |
| 47 bool id_found = manager_.GetId(notification, id); | 54 bool id_found = manager_.GetId(notification, id); |
| 48 // Won't be found if the notification has already been closed by the user. | 55 // Won't be found if the notification has already been closed by the user. |
| 49 if (id_found) | 56 if (id_found) |
| 50 Send(new DesktopNotificationHostMsg_Cancel(routing_id(), id)); | 57 Send(new DesktopNotificationHostMsg_Cancel(routing_id(), id)); |
| 51 } | 58 } |
| 52 | 59 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 OnPermissionRequestComplete); | 100 OnPermissionRequestComplete); |
| 94 IPC_MESSAGE_UNHANDLED(handled = false) | 101 IPC_MESSAGE_UNHANDLED(handled = false) |
| 95 IPC_END_MESSAGE_MAP() | 102 IPC_END_MESSAGE_MAP() |
| 96 | 103 |
| 97 if (message.type() == ViewMsg_Navigate::ID) | 104 if (message.type() == ViewMsg_Navigate::ID) |
| 98 OnNavigate(); // Don't want to swallow the message. | 105 OnNavigate(); // Don't want to swallow the message. |
| 99 | 106 |
| 100 return handled; | 107 return handled; |
| 101 } | 108 } |
| 102 | 109 |
| 103 bool NotificationProvider::ShowHTML(const WebNotification& notification, | |
| 104 int id) { | |
| 105 DCHECK(notification.isHTML()); | |
| 106 ShowDesktopNotificationHostMsgParams params; | |
| 107 WebDocument document = render_view()->GetWebView()->mainFrame()->document(); | |
| 108 params.origin = GURL(document.securityOrigin().toString()); | |
| 109 params.is_html = true; | |
| 110 params.contents_url = notification.url(); | |
| 111 params.notification_id = id; | |
| 112 params.replace_id = notification.replaceId(); | |
| 113 return Send(new DesktopNotificationHostMsg_Show(routing_id(), params)); | |
| 114 } | |
| 115 | |
| 116 bool NotificationProvider::ShowText(const WebNotification& notification, | |
| 117 int id) { | |
| 118 DCHECK(!notification.isHTML()); | |
| 119 ShowDesktopNotificationHostMsgParams params; | |
| 120 params.is_html = false; | |
| 121 WebDocument document = render_view()->GetWebView()->mainFrame()->document(); | |
| 122 params.origin = GURL(document.securityOrigin().toString()); | |
| 123 params.icon_url = notification.iconURL(); | |
| 124 params.title = notification.title(); | |
| 125 params.body = notification.body(); | |
| 126 params.direction = notification.direction(); | |
| 127 params.notification_id = id; | |
| 128 params.replace_id = notification.replaceId(); | |
| 129 return Send(new DesktopNotificationHostMsg_Show(routing_id(), params)); | |
| 130 } | |
| 131 | |
| 132 void NotificationProvider::OnDisplay(int id) { | 110 void NotificationProvider::OnDisplay(int id) { |
| 133 WebNotification notification; | 111 WebNotification notification; |
| 134 bool found = manager_.GetNotification(id, ¬ification); | 112 bool found = manager_.GetNotification(id, ¬ification); |
| 135 // |found| may be false if the WebNotification went out of scope in | 113 // |found| may be false if the WebNotification went out of scope in |
| 136 // the page before it was actually displayed to the user. | 114 // the page before it was actually displayed to the user. |
| 137 if (found) | 115 if (found) |
| 138 notification.dispatchDisplayEvent(); | 116 notification.dispatchDisplayEvent(); |
| 139 } | 117 } |
| 140 | 118 |
| 141 void NotificationProvider::OnError(int id, const WebString& message) { | 119 void NotificationProvider::OnError(int id, const WebString& message) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 172 DCHECK(callback); | 150 DCHECK(callback); |
| 173 callback->permissionRequestComplete(); | 151 callback->permissionRequestComplete(); |
| 174 manager_.OnPermissionRequestComplete(id); | 152 manager_.OnPermissionRequestComplete(id); |
| 175 } | 153 } |
| 176 | 154 |
| 177 void NotificationProvider::OnNavigate() { | 155 void NotificationProvider::OnNavigate() { |
| 178 manager_.Clear(); | 156 manager_.Clear(); |
| 179 } | 157 } |
| 180 | 158 |
| 181 } // namespace content | 159 } // namespace content |
| OLD | NEW |