| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "content/common/desktop_notification_messages.h" | 10 #include "content/common/desktop_notification_messages.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 routing_id(), | 111 routing_id(), |
| 112 GURL(origin.toString()), | 112 GURL(origin.toString()), |
| 113 &permission)); | 113 &permission)); |
| 114 return static_cast<WebNotificationPresenter::Permission>(permission); | 114 return static_cast<WebNotificationPresenter::Permission>(permission); |
| 115 } | 115 } |
| 116 | 116 |
| 117 bool NotificationProvider::OnMessageReceived(const IPC::Message& message) { | 117 bool NotificationProvider::OnMessageReceived(const IPC::Message& message) { |
| 118 bool handled = true; | 118 bool handled = true; |
| 119 IPC_BEGIN_MESSAGE_MAP(NotificationProvider, message) | 119 IPC_BEGIN_MESSAGE_MAP(NotificationProvider, message) |
| 120 IPC_MESSAGE_HANDLER(DesktopNotificationMsg_PostDisplay, OnDisplay); | 120 IPC_MESSAGE_HANDLER(DesktopNotificationMsg_PostDisplay, OnDisplay); |
| 121 IPC_MESSAGE_HANDLER(DesktopNotificationMsg_PostError, OnError); | |
| 122 IPC_MESSAGE_HANDLER(DesktopNotificationMsg_PostClose, OnClose); | 121 IPC_MESSAGE_HANDLER(DesktopNotificationMsg_PostClose, OnClose); |
| 123 IPC_MESSAGE_HANDLER(DesktopNotificationMsg_PostClick, OnClick); | 122 IPC_MESSAGE_HANDLER(DesktopNotificationMsg_PostClick, OnClick); |
| 124 IPC_MESSAGE_UNHANDLED(handled = false) | 123 IPC_MESSAGE_UNHANDLED(handled = false) |
| 125 IPC_END_MESSAGE_MAP() | 124 IPC_END_MESSAGE_MAP() |
| 126 | 125 |
| 127 if (message.type() == FrameMsg_Navigate::ID) | 126 if (message.type() == FrameMsg_Navigate::ID) |
| 128 OnNavigate(); // Don't want to swallow the message. | 127 OnNavigate(); // Don't want to swallow the message. |
| 129 | 128 |
| 130 return handled; | 129 return handled; |
| 131 } | 130 } |
| 132 | 131 |
| 133 void NotificationProvider::OnDisplay(int id) { | 132 void NotificationProvider::OnDisplay(int id) { |
| 134 WebNotification notification; | 133 WebNotification notification; |
| 135 bool found = manager_.GetNotification(id, ¬ification); | 134 bool found = manager_.GetNotification(id, ¬ification); |
| 136 // |found| may be false if the WebNotification went out of scope in | 135 // |found| may be false if the WebNotification went out of scope in |
| 137 // the page before it was actually displayed to the user. | 136 // the page before it was actually displayed to the user. |
| 138 if (found) | 137 if (found) |
| 139 notification.dispatchDisplayEvent(); | 138 notification.dispatchDisplayEvent(); |
| 140 } | 139 } |
| 141 | 140 |
| 142 void NotificationProvider::OnError(int id) { | |
| 143 WebNotification notification; | |
| 144 bool found = manager_.GetNotification(id, ¬ification); | |
| 145 // |found| may be false if the WebNotification went out of scope in | |
| 146 // the page before the error occurred. | |
| 147 if (found) | |
| 148 notification.dispatchErrorEvent(WebString()); | |
| 149 } | |
| 150 | |
| 151 void NotificationProvider::OnClose(int id, bool by_user) { | 141 void NotificationProvider::OnClose(int id, bool by_user) { |
| 152 WebNotification notification; | 142 WebNotification notification; |
| 153 bool found = manager_.GetNotification(id, ¬ification); | 143 bool found = manager_.GetNotification(id, ¬ification); |
| 154 // |found| may be false if the WebNotification went out of scope in | 144 // |found| may be false if the WebNotification went out of scope in |
| 155 // the page before the associated toast was closed by the user. | 145 // the page before the associated toast was closed by the user. |
| 156 if (found) { | 146 if (found) { |
| 157 notification.dispatchCloseEvent(by_user); | 147 notification.dispatchCloseEvent(by_user); |
| 158 manager_.UnregisterNotification(id); | 148 manager_.UnregisterNotification(id); |
| 159 } | 149 } |
| 160 } | 150 } |
| 161 | 151 |
| 162 void NotificationProvider::OnClick(int id) { | 152 void NotificationProvider::OnClick(int id) { |
| 163 WebNotification notification; | 153 WebNotification notification; |
| 164 bool found = manager_.GetNotification(id, ¬ification); | 154 bool found = manager_.GetNotification(id, ¬ification); |
| 165 // |found| may be false if the WebNotification went out of scope in | 155 // |found| may be false if the WebNotification went out of scope in |
| 166 // the page before the associated toast was clicked on. | 156 // the page before the associated toast was clicked on. |
| 167 if (found) | 157 if (found) |
| 168 notification.dispatchClickEvent(); | 158 notification.dispatchClickEvent(); |
| 169 } | 159 } |
| 170 | 160 |
| 171 void NotificationProvider::OnNavigate() { | 161 void NotificationProvider::OnNavigate() { |
| 172 manager_.Clear(); | 162 manager_.Clear(); |
| 173 } | 163 } |
| 174 | 164 |
| 175 } // namespace content | 165 } // namespace content |
| OLD | NEW |