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

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: 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/command_line.h"
7 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
8 #include "content/child/service_worker/web_service_worker_registration_impl.h" 9 #include "content/child/service_worker/web_service_worker_registration_impl.h"
9 #include "content/common/push_messaging_messages.h" 10 #include "content/common/push_messaging_messages.h"
11 #include "content/public/common/content_switches.h"
10 #include "content/renderer/manifest/manifest_manager.h" 12 #include "content/renderer/manifest/manifest_manager.h"
11 #include "content/renderer/render_frame_impl.h" 13 #include "content/renderer/render_frame_impl.h"
12 #include "ipc/ipc_message.h" 14 #include "ipc/ipc_message.h"
13 #include "third_party/WebKit/public/platform/WebString.h" 15 #include "third_party/WebKit/public/platform/WebString.h"
14 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushError .h" 16 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushError .h"
15 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc ription.h" 17 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc ription.h"
16 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc riptionOptions.h" 18 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubsc riptionOptions.h"
17 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRegistration.h" 19 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRegistration.h"
18 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 20 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
19 #include "third_party/WebKit/public/web/WebLocalFrame.h" 21 #include "third_party/WebKit/public/web/WebLocalFrame.h"
(...skipping 17 matching lines...) Expand all
37 IPC_END_MESSAGE_MAP() 39 IPC_END_MESSAGE_MAP()
38 return handled; 40 return handled;
39 } 41 }
40 42
41 void PushMessagingDispatcher::subscribe( 43 void PushMessagingDispatcher::subscribe(
42 blink::WebServiceWorkerRegistration* service_worker_registration, 44 blink::WebServiceWorkerRegistration* service_worker_registration,
43 const blink::WebPushSubscriptionOptions& options, 45 const blink::WebPushSubscriptionOptions& options,
44 blink::WebPushSubscriptionCallbacks* callbacks) { 46 blink::WebPushSubscriptionCallbacks* callbacks) {
45 DCHECK(service_worker_registration); 47 DCHECK(service_worker_registration);
46 DCHECK(callbacks); 48 DCHECK(callbacks);
49 // TODO(harkness) If the command line flag for push subscriptions is enabled
50 // and the client provided a public key, don't load the manifest.
47 RenderFrameImpl::FromRoutingID(routing_id()) 51 RenderFrameImpl::FromRoutingID(routing_id())
48 ->manifest_manager() 52 ->manifest_manager()
49 ->GetManifest(base::Bind( 53 ->GetManifest(base::Bind(
50 &PushMessagingDispatcher::DoSubscribe, base::Unretained(this), 54 &PushMessagingDispatcher::DoSubscribe, base::Unretained(this),
51 service_worker_registration, options, callbacks)); 55 service_worker_registration, options, callbacks));
52 } 56 }
53 57
54 void PushMessagingDispatcher::DoSubscribe( 58 void PushMessagingDispatcher::DoSubscribe(
55 blink::WebServiceWorkerRegistration* service_worker_registration, 59 blink::WebServiceWorkerRegistration* service_worker_registration,
56 const blink::WebPushSubscriptionOptions& options, 60 const blink::WebPushSubscriptionOptions& options,
57 blink::WebPushSubscriptionCallbacks* callbacks, 61 blink::WebPushSubscriptionCallbacks* callbacks,
58 const Manifest& manifest) { 62 const Manifest& manifest) {
59 int request_id = subscription_callbacks_.Add(callbacks); 63 int request_id = subscription_callbacks_.Add(callbacks);
60 int64_t service_worker_registration_id = 64 int64_t service_worker_registration_id =
61 static_cast<WebServiceWorkerRegistrationImpl*>( 65 static_cast<WebServiceWorkerRegistrationImpl*>(
62 service_worker_registration) 66 service_worker_registration)
63 ->registration_id(); 67 ->registration_id();
64 68
65 if (manifest.IsEmpty()) { 69 ContentPushSubscriptionOptions content_options;
66 OnSubscribeFromDocumentError( 70 content_options.user_visible_only = options.userVisibleOnly;
67 request_id, PUSH_REGISTRATION_STATUS_MANIFEST_EMPTY_OR_MISSING);
68 return;
69 }
70 71
71 std::string sender_id = 72 // If SubscriptionRestrictions aren't enabled or a public key isn't provided
72 manifest.gcm_sender_id.is_null() 73 // by the client, fall back to the old sender_id specification.
73 ? std::string() 74 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
74 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()); 75 switches::kEnableExperimentalWebPlatformFeatures) ||
Peter Beverloo 2016/02/17 16:15:36 No need to check for the command line flag— we can
harkness 2016/02/18 10:45:15 Done.
75 if (sender_id.empty()) { 76 options.applicationServerKey.isEmpty()) {
76 OnSubscribeFromDocumentError(request_id, 77 if (manifest.IsEmpty()) {
77 PUSH_REGISTRATION_STATUS_NO_SENDER_ID); 78 OnSubscribeFromDocumentError(
78 return; 79 request_id, PUSH_REGISTRATION_STATUS_MANIFEST_EMPTY_OR_MISSING);
80 return;
81 }
82
83 content_options.using_public_key = false;
84 content_options.sender_info =
85 manifest.gcm_sender_id.is_null()
86 ? std::string()
87 : base::UTF16ToUTF8(manifest.gcm_sender_id.string());
88 if (content_options.sender_info.empty()) {
89 OnSubscribeFromDocumentError(request_id,
90 PUSH_REGISTRATION_STATUS_NO_SENDER_ID);
91 return;
92 }
93 } else {
94 content_options.using_public_key = true;
95 content_options.sender_info = options.applicationServerKey.utf8();
96
97 // TODO(harkness) Need to check that appServicePublicKey has a valid
98 // format and reject with InvalidAccessError if invalid.
79 } 99 }
80 100
81 Send(new PushMessagingHostMsg_SubscribeFromDocument( 101 Send(new PushMessagingHostMsg_SubscribeFromDocument(
82 routing_id(), request_id, 102 routing_id(), request_id, content_options,
83 manifest.gcm_sender_id.is_null() 103 service_worker_registration_id));
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