Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1146)

Side by Side Diff: content/renderer/push_messaging/push_messaging_dispatcher.cc

Issue 1701313002: Partial implementation of subscription restrictions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added testing and integrated previous comments. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 26 matching lines...) Expand all
37 IPC_END_MESSAGE_MAP() 37 IPC_END_MESSAGE_MAP()
38 return handled; 38 return handled;
39 } 39 }
40 40
41 void PushMessagingDispatcher::subscribe( 41 void PushMessagingDispatcher::subscribe(
42 blink::WebServiceWorkerRegistration* service_worker_registration, 42 blink::WebServiceWorkerRegistration* service_worker_registration,
43 const blink::WebPushSubscriptionOptions& options, 43 const blink::WebPushSubscriptionOptions& options,
44 blink::WebPushSubscriptionCallbacks* callbacks) { 44 blink::WebPushSubscriptionCallbacks* callbacks) {
45 DCHECK(service_worker_registration); 45 DCHECK(service_worker_registration);
46 DCHECK(callbacks); 46 DCHECK(callbacks);
47 RenderFrameImpl::FromRoutingID(routing_id()) 47 // If a developer provided an application server key in |options|, skip
48 ->manifest_manager() 48 // fetching the manifest.
49 ->GetManifest(base::Bind( 49 if (options.applicationServerKey.isEmpty()) {
50 &PushMessagingDispatcher::DoSubscribe, base::Unretained(this), 50 RenderFrameImpl::FromRoutingID(routing_id())
51 service_worker_registration, options, callbacks)); 51 ->manifest_manager()
52 ->GetManifest(base::Bind(
53 &PushMessagingDispatcher::DidGetManifest, base::Unretained(this),
54 service_worker_registration, options, callbacks));
55 } else {
Peter Beverloo 2016/02/23 14:28:29 nit: Chrome prefers early returns, so you could re
harkness 2016/02/26 11:44:26 Actually, in this case, I feel like the different
Peter Beverloo 2016/02/26 16:02:32 No :-)
56 PushSubscriptionOptions content_options;
57 content_options.user_visible_only = options.userVisibleOnly;
58 content_options.sender_info = options.applicationServerKey.utf8();
59 DoSubscribe(service_worker_registration, content_options, callbacks);
60 }
61 }
62
63 void PushMessagingDispatcher::DidGetManifest(
64 blink::WebServiceWorkerRegistration* service_worker_registration,
65 const blink::WebPushSubscriptionOptions& options,
66 blink::WebPushSubscriptionCallbacks* callbacks,
67 const Manifest& manifest) {
68 int request_id = subscription_callbacks_.Add(callbacks);
69 // Get the sender_info from the manifest since it wasn't provided by
70 // the caller.
71 if (manifest.IsEmpty()) {
72 OnSubscribeFromDocumentError(
73 request_id, PUSH_REGISTRATION_STATUS_MANIFEST_EMPTY_OR_MISSING);
74 return;
75 }
76
77 PushSubscriptionOptions content_options;
78 content_options.user_visible_only = options.userVisibleOnly;
79 content_options.sender_info =
Peter Beverloo 2016/02/23 14:28:29 nit: Since this has got a default value of empty a
harkness 2016/02/26 11:44:26 Done.
80 manifest.gcm_sender_id.is_null()
81 ? std::string()
82 : base::UTF16ToUTF8(manifest.gcm_sender_id.string());
83
84 DoSubscribe(service_worker_registration, content_options, callbacks);
52 } 85 }
53 86
54 void PushMessagingDispatcher::DoSubscribe( 87 void PushMessagingDispatcher::DoSubscribe(
55 blink::WebServiceWorkerRegistration* service_worker_registration, 88 blink::WebServiceWorkerRegistration* service_worker_registration,
56 const blink::WebPushSubscriptionOptions& options, 89 const PushSubscriptionOptions& options,
57 blink::WebPushSubscriptionCallbacks* callbacks, 90 blink::WebPushSubscriptionCallbacks* callbacks) {
58 const Manifest& manifest) {
59 int request_id = subscription_callbacks_.Add(callbacks); 91 int request_id = subscription_callbacks_.Add(callbacks);
60 int64_t service_worker_registration_id = 92 int64_t service_worker_registration_id =
61 static_cast<WebServiceWorkerRegistrationImpl*>( 93 static_cast<WebServiceWorkerRegistrationImpl*>(
62 service_worker_registration) 94 service_worker_registration)
63 ->registration_id(); 95 ->registration_id();
64 96
65 if (manifest.IsEmpty()) { 97 if (options.sender_info.empty()) {
66 OnSubscribeFromDocumentError(
67 request_id, PUSH_REGISTRATION_STATUS_MANIFEST_EMPTY_OR_MISSING);
68 return;
69 }
70
71 std::string sender_id =
72 manifest.gcm_sender_id.is_null()
73 ? std::string()
74 : base::UTF16ToUTF8(manifest.gcm_sender_id.string());
75 if (sender_id.empty()) {
76 OnSubscribeFromDocumentError(request_id, 98 OnSubscribeFromDocumentError(request_id,
77 PUSH_REGISTRATION_STATUS_NO_SENDER_ID); 99 PUSH_REGISTRATION_STATUS_NO_SENDER_ID);
78 return; 100 return;
79 } 101 }
80
81 Send(new PushMessagingHostMsg_SubscribeFromDocument( 102 Send(new PushMessagingHostMsg_SubscribeFromDocument(
82 routing_id(), request_id, 103 routing_id(), request_id, options, service_worker_registration_id));
83 manifest.gcm_sender_id.is_null()
84 ? std::string()
85 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()),
86 options.userVisibleOnly, service_worker_registration_id));
87 } 104 }
88 105
89 void PushMessagingDispatcher::OnSubscribeFromDocumentSuccess( 106 void PushMessagingDispatcher::OnSubscribeFromDocumentSuccess(
90 int32_t request_id, 107 int32_t request_id,
91 const GURL& endpoint, 108 const GURL& endpoint,
92 const std::vector<uint8_t>& p256dh, 109 const std::vector<uint8_t>& p256dh,
93 const std::vector<uint8_t>& auth) { 110 const std::vector<uint8_t>& auth) {
94 blink::WebPushSubscriptionCallbacks* callbacks = 111 blink::WebPushSubscriptionCallbacks* callbacks =
95 subscription_callbacks_.Lookup(request_id); 112 subscription_callbacks_.Lookup(request_id);
96 DCHECK(callbacks); 113 DCHECK(callbacks);
(...skipping 17 matching lines...) Expand all
114 : blink::WebPushError::ErrorTypeAbort; 131 : blink::WebPushError::ErrorTypeAbort;
115 132
116 callbacks->onError(blink::WebPushError( 133 callbacks->onError(blink::WebPushError(
117 error_type, 134 error_type,
118 blink::WebString::fromUTF8(PushRegistrationStatusToString(status)))); 135 blink::WebString::fromUTF8(PushRegistrationStatusToString(status))));
119 136
120 subscription_callbacks_.Remove(request_id); 137 subscription_callbacks_.Remove(request_id);
121 } 138 }
122 139
123 } // namespace content 140 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698