OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/renderer/notification_provider.h" | 5 #include "chrome/renderer/notification_provider.h" |
6 | 6 |
7 #include "base/task.h" | 7 #include "base/task.h" |
8 #include "chrome/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
10 #include "chrome/renderer/render_thread.h" | 10 #include "chrome/renderer/render_thread.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 IPC_MESSAGE_HANDLER(ViewMsg_PostDisplayToNotificationObject, OnDisplay); | 72 IPC_MESSAGE_HANDLER(ViewMsg_PostDisplayToNotificationObject, OnDisplay); |
73 IPC_MESSAGE_HANDLER(ViewMsg_PostErrorToNotificationObject, OnError); | 73 IPC_MESSAGE_HANDLER(ViewMsg_PostErrorToNotificationObject, OnError); |
74 IPC_MESSAGE_HANDLER(ViewMsg_PostCloseToNotificationObject, OnClose); | 74 IPC_MESSAGE_HANDLER(ViewMsg_PostCloseToNotificationObject, OnClose); |
75 IPC_MESSAGE_HANDLER(ViewMsg_PermissionRequestDone, | 75 IPC_MESSAGE_HANDLER(ViewMsg_PermissionRequestDone, |
76 OnPermissionRequestComplete); | 76 OnPermissionRequestComplete); |
77 IPC_MESSAGE_UNHANDLED(handled = false) | 77 IPC_MESSAGE_UNHANDLED(handled = false) |
78 IPC_END_MESSAGE_MAP() | 78 IPC_END_MESSAGE_MAP() |
79 return handled; | 79 return handled; |
80 } | 80 } |
81 | 81 |
| 82 void NotificationProvider::OnNavigate() { |
| 83 manager_.Clear(); |
| 84 } |
| 85 |
82 bool NotificationProvider::ShowHTML(const WebNotification& notification, | 86 bool NotificationProvider::ShowHTML(const WebNotification& notification, |
83 int id) { | 87 int id) { |
84 // Disallow HTML notifications from non-HTTP schemes. | 88 // Disallow HTML notifications from non-HTTP schemes. |
85 GURL url = notification.url(); | 89 GURL url = notification.url(); |
86 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme)) | 90 if (!url.SchemeIs(chrome::kHttpScheme) && !url.SchemeIs(chrome::kHttpsScheme)) |
87 return false; | 91 return false; |
88 | 92 |
89 DCHECK(notification.isHTML()); | 93 DCHECK(notification.isHTML()); |
90 return Send(new ViewHostMsg_ShowDesktopNotification(view_->routing_id(), | 94 return Send(new ViewHostMsg_ShowDesktopNotification(view_->routing_id(), |
91 GURL(view_->webview()->mainFrame()->url()).GetOrigin(), | 95 GURL(view_->webview()->mainFrame()->url()).GetOrigin(), |
(...skipping 25 matching lines...) Expand all Loading... |
117 // the page before the error occurred. | 121 // the page before the error occurred. |
118 if (found) | 122 if (found) |
119 notification.dispatchErrorEvent(message); | 123 notification.dispatchErrorEvent(message); |
120 } | 124 } |
121 | 125 |
122 void NotificationProvider::OnClose(int id, bool by_user) { | 126 void NotificationProvider::OnClose(int id, bool by_user) { |
123 WebNotification notification; | 127 WebNotification notification; |
124 bool found = manager_.GetNotification(id, ¬ification); | 128 bool found = manager_.GetNotification(id, ¬ification); |
125 // |found| may be false if the WebNotification went out of scope in | 129 // |found| may be false if the WebNotification went out of scope in |
126 // the page before the associated toast was closed by the user. | 130 // the page before the associated toast was closed by the user. |
127 if (found) | 131 if (found) { |
128 notification.dispatchCloseEvent(by_user); | 132 notification.dispatchCloseEvent(by_user); |
129 manager_.UnregisterNotification(id); | 133 manager_.UnregisterNotification(id); |
| 134 } |
130 } | 135 } |
131 | 136 |
132 void NotificationProvider::OnPermissionRequestComplete(int id) { | 137 void NotificationProvider::OnPermissionRequestComplete(int id) { |
133 WebNotificationPermissionCallback* callback = manager_.GetCallback(id); | 138 WebNotificationPermissionCallback* callback = manager_.GetCallback(id); |
134 DCHECK(callback); | 139 DCHECK(callback); |
135 callback->permissionRequestComplete(); | 140 callback->permissionRequestComplete(); |
136 manager_.OnPermissionRequestComplete(id); | 141 manager_.OnPermissionRequestComplete(id); |
137 } | 142 } |
138 | 143 |
139 bool NotificationProvider::Send(IPC::Message* message) { | 144 bool NotificationProvider::Send(IPC::Message* message) { |
140 return RenderThread::current()->Send(message); | 145 return RenderThread::current()->Send(message); |
141 } | 146 } |
OLD | NEW |