Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/push_messaging/push_messaging_dispatcher.h" | 5 #include "content/renderer/push_messaging/push_messaging_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 8 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 9 #include "content/common/push_messaging_messages.h" | 9 #include "content/common/push_messaging_messages.h" |
| 10 #include "content/renderer/manifest/manifest_manager.h" | 10 #include "content/renderer/manifest/manifest_manager.h" |
| 11 #include "content/renderer/render_frame_impl.h" | 11 #include "content/renderer/render_frame_impl.h" |
| 12 #include "ipc/ipc_message.h" | 12 #include "ipc/ipc_message.h" |
| 13 #include "third_party/WebKit/public/platform/WebServiceWorkerRegistration.h" | 13 #include "third_party/WebKit/public/platform/WebServiceWorkerRegistration.h" |
| 14 #include "third_party/WebKit/public/platform/WebString.h" | 14 #include "third_party/WebKit/public/platform/WebString.h" |
| 15 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushError .h" | 15 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushError .h" |
| 16 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc ription.h" | 16 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc ription.h" |
| 17 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc riptionOptions.h" | 17 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc riptionOptions.h" |
| 18 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | |
| 19 #include "third_party/WebKit/public/web/WebLocalFrame.h" | |
| 18 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 19 | 21 |
| 20 using blink::WebString; | 22 using blink::WebString; |
| 21 | 23 |
| 22 namespace content { | 24 namespace content { |
| 23 | 25 |
| 26 const char kManifestDeprecationWarning[] = | |
|
johnme
2015/05/20 14:05:41
Move to anonymous namespace?
Peter Beverloo
2015/05/20 14:15:13
No, constants are internally linked by default so
| |
| 27 "The 'gcm_user_visible_only' manifest key is deprecated and will be " | |
| 28 "removed in Chrome 45, around August 2015. Use PushSubscriptionOptions " | |
|
johnme
2015/05/20 14:05:41
Nit: How about "Call pushManager.subscribe({userVi
Peter Beverloo
2015/05/20 14:15:14
Changed..
| |
| 29 "when subscribing for push instead."; | |
| 30 | |
| 24 PushMessagingDispatcher::PushMessagingDispatcher(RenderFrame* render_frame) | 31 PushMessagingDispatcher::PushMessagingDispatcher(RenderFrame* render_frame) |
| 25 : RenderFrameObserver(render_frame) { | 32 : RenderFrameObserver(render_frame) { |
| 26 } | 33 } |
| 27 | 34 |
| 28 PushMessagingDispatcher::~PushMessagingDispatcher() {} | 35 PushMessagingDispatcher::~PushMessagingDispatcher() {} |
| 29 | 36 |
| 30 bool PushMessagingDispatcher::OnMessageReceived(const IPC::Message& message) { | 37 bool PushMessagingDispatcher::OnMessageReceived(const IPC::Message& message) { |
| 31 bool handled = true; | 38 bool handled = true; |
| 32 IPC_BEGIN_MESSAGE_MAP(PushMessagingDispatcher, message) | 39 IPC_BEGIN_MESSAGE_MAP(PushMessagingDispatcher, message) |
| 33 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterFromDocumentSuccess, | 40 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterFromDocumentSuccess, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 std::string sender_id = | 74 std::string sender_id = |
| 68 manifest.gcm_sender_id.is_null() | 75 manifest.gcm_sender_id.is_null() |
| 69 ? std::string() | 76 ? std::string() |
| 70 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()); | 77 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()); |
| 71 if (sender_id.empty()) { | 78 if (sender_id.empty()) { |
| 72 OnRegisterFromDocumentError(request_id, | 79 OnRegisterFromDocumentError(request_id, |
| 73 PUSH_REGISTRATION_STATUS_NO_SENDER_ID); | 80 PUSH_REGISTRATION_STATUS_NO_SENDER_ID); |
| 74 return; | 81 return; |
| 75 } | 82 } |
| 76 | 83 |
| 77 // TODO(peter): Display a deprecation warning if gcm_user_visible_only is | 84 // Support for the "gcm_user_visible_only" Manifest key has been deprecated |
| 78 // set to true. See https://crbug.com/471534 | 85 // in favor of the userVisibleOnly subscription option, and will be removed |
| 86 // in a future Chrome release. Inform developers of this deprecation. | |
| 87 if (manifest.gcm_user_visible_only && !options.userVisibleOnly) { | |
| 88 blink::WebConsoleMessage message( | |
| 89 blink::WebConsoleMessage::LevelWarning, | |
| 90 blink::WebString::fromUTF8(kManifestDeprecationWarning)); | |
| 91 | |
| 92 render_frame()->GetWebFrame()->addMessageToConsole(message); | |
|
johnme
2015/05/20 14:05:41
Ideally we'd log no more than once per page load;
Peter Beverloo
2015/05/20 14:15:13
Acknowledged.
| |
| 93 } | |
| 94 | |
| 79 const bool user_visible = manifest.gcm_user_visible_only || | 95 const bool user_visible = manifest.gcm_user_visible_only || |
| 80 options.userVisibleOnly; | 96 options.userVisibleOnly; |
| 81 | 97 |
| 82 Send(new PushMessagingHostMsg_RegisterFromDocument( | 98 Send(new PushMessagingHostMsg_RegisterFromDocument( |
| 83 routing_id(), request_id, | 99 routing_id(), request_id, |
| 84 manifest.gcm_sender_id.is_null() | 100 manifest.gcm_sender_id.is_null() |
| 85 ? std::string() | 101 ? std::string() |
| 86 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()), | 102 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()), |
| 87 user_visible, service_worker_registration_id)); | 103 user_visible, service_worker_registration_id)); |
| 88 } | 104 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 113 | 129 |
| 114 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( | 130 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( |
| 115 blink::WebPushError::ErrorTypeAbort, | 131 blink::WebPushError::ErrorTypeAbort, |
| 116 WebString::fromUTF8(PushRegistrationStatusToString(status)))); | 132 WebString::fromUTF8(PushRegistrationStatusToString(status)))); |
| 117 callbacks->onError(error.release()); | 133 callbacks->onError(error.release()); |
| 118 | 134 |
| 119 subscription_callbacks_.Remove(request_id); | 135 subscription_callbacks_.Remove(request_id); |
| 120 } | 136 } |
| 121 | 137 |
| 122 } // namespace content | 138 } // namespace content |
| OLD | NEW |