| Index: content/browser/push_messaging/push_messaging_message_filter.cc
|
| diff --git a/content/browser/push_messaging/push_messaging_message_filter.cc b/content/browser/push_messaging/push_messaging_message_filter.cc
|
| index c328a8a0a3d0075104dd928e0b7a37dd734be39e..652d7e2901f3dddb9169ca3b81b17bedf50b188e 100644
|
| --- a/content/browser/push_messaging/push_messaging_message_filter.cc
|
| +++ b/content/browser/push_messaging/push_messaging_message_filter.cc
|
| @@ -72,6 +72,8 @@ bool PushMessagingMessageFilter::OnMessageReceived(
|
| OnRegisterFromWorker)
|
| IPC_MESSAGE_HANDLER(PushMessagingHostMsg_GetPermissionStatus,
|
| OnGetPermissionStatus)
|
| + IPC_MESSAGE_HANDLER(PushMessagingHostMsg_Unregister,
|
| + OnUnregister)
|
| IPC_MESSAGE_UNHANDLED(handled = false)
|
| IPC_END_MESSAGE_MAP()
|
| return handled;
|
| @@ -351,6 +353,65 @@ void PushMessagingMessageFilter::SendRegisterSuccessOnUI(
|
| SendRegisterSuccess(data, status, push_endpoint, push_registration_id);
|
| }
|
|
|
| +void PushMessagingMessageFilter::OnUnregister(
|
| + int request_id, int64 service_worker_registration_id) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + ServiceWorkerRegistration* service_worker_registration =
|
| + service_worker_context_->context()->GetLiveRegistration(
|
| + service_worker_registration_id);
|
| + DCHECK(service_worker_registration);
|
| + if (!service_worker_registration)
|
| + return;
|
| +
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&PushMessagingMessageFilter::UnregisterOnUI,
|
| + this,
|
| + request_id,
|
| + service_worker_registration_id,
|
| + service_worker_registration->pattern().GetOrigin()));
|
| +}
|
| +
|
| +void PushMessagingMessageFilter::UnregisterOnUI(
|
| + int request_id,
|
| + int64 service_worker_registration_id,
|
| + const GURL& requesting_origin) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + if (!service()) {
|
| + DidUnregister(request_id, PUSH_UNREGISTRATION_STATUS_UNKNOWN_ERROR);
|
| + return;
|
| + }
|
| +
|
| + service()->Unregister(requesting_origin, service_worker_registration_id,
|
| + base::Bind(&PushMessagingMessageFilter::DidUnregister,
|
| + weak_factory_ui_to_ui_.GetWeakPtr(), request_id));
|
| +}
|
| +
|
| +void PushMessagingMessageFilter::DidUnregister(
|
| + int request_id,
|
| + PushUnregistrationStatus unregistration_status) {
|
| + switch (unregistration_status) {
|
| + case PUSH_UNREGISTRATION_STATUS_SUCCESS_UNREGISTER:
|
| + Send(new PushMessagingMsg_UnregisterSuccess(request_id, true));
|
| + return;
|
| + case PUSH_UNREGISTRATION_STATUS_SUCCESS_WAS_NOT_REGISTERED:
|
| + Send(new PushMessagingMsg_UnregisterSuccess(request_id, false));
|
| + return;
|
| + case PUSH_UNREGISTRATION_STATUS_NETWORK_ERROR:
|
| + Send(new PushMessagingMsg_UnregisterError(
|
| + request_id,
|
| + blink::WebPushError::ErrorTypeNetwork,
|
| + "Failed to connect to the push server."));
|
| + return;
|
| + case PUSH_UNREGISTRATION_STATUS_UNKNOWN_ERROR:
|
| + Send(new PushMessagingMsg_UnregisterError(
|
| + request_id,
|
| + blink::WebPushError::ErrorTypeUnknown,
|
| + "Unexpected error while trying to unregister from the push server."));
|
| + return;
|
| + }
|
| +}
|
| +
|
| void PushMessagingMessageFilter::OnGetRegistration(
|
| int request_id,
|
| int64 service_worker_registration_id) {
|
|
|