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

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

Issue 609393002: [Push] Use Manifest.gcm_sender_id instead of API sender_id if possible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@manifest_gcm_sender_id
Patch Set: review comments Created 6 years, 2 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
« no previous file with comments | « content/renderer/push_messaging_dispatcher.h ('k') | content/renderer/render_frame_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_dispatcher.h" 5 #include "content/renderer/push_messaging_dispatcher.h"
6 6
7 #include "base/strings/utf_string_conversions.h"
7 #include "content/child/service_worker/web_service_worker_provider_impl.h" 8 #include "content/child/service_worker/web_service_worker_provider_impl.h"
8 #include "content/common/push_messaging_messages.h" 9 #include "content/common/push_messaging_messages.h"
10 #include "content/renderer/manifest/manifest_manager.h"
11 #include "content/renderer/render_frame_impl.h"
9 #include "ipc/ipc_message.h" 12 #include "ipc/ipc_message.h"
10 #include "third_party/WebKit/public/platform/WebPushError.h" 13 #include "third_party/WebKit/public/platform/WebPushError.h"
11 #include "third_party/WebKit/public/platform/WebPushRegistration.h" 14 #include "third_party/WebKit/public/platform/WebPushRegistration.h"
12 #include "third_party/WebKit/public/platform/WebServiceWorkerProvider.h" 15 #include "third_party/WebKit/public/platform/WebServiceWorkerProvider.h"
13 #include "third_party/WebKit/public/platform/WebString.h" 16 #include "third_party/WebKit/public/platform/WebString.h"
14 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" 17 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
15 #include "url/gurl.h" 18 #include "url/gurl.h"
16 19
17 using blink::WebString; 20 using blink::WebString;
18 21
(...skipping 10 matching lines...) Expand all
29 IPC_BEGIN_MESSAGE_MAP(PushMessagingDispatcher, message) 32 IPC_BEGIN_MESSAGE_MAP(PushMessagingDispatcher, message)
30 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterSuccess, OnRegisterSuccess) 33 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterSuccess, OnRegisterSuccess)
31 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterError, OnRegisterError) 34 IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterError, OnRegisterError)
32 IPC_MESSAGE_UNHANDLED(handled = false) 35 IPC_MESSAGE_UNHANDLED(handled = false)
33 IPC_END_MESSAGE_MAP() 36 IPC_END_MESSAGE_MAP()
34 return handled; 37 return handled;
35 } 38 }
36 39
37 void PushMessagingDispatcher::registerPushMessaging( 40 void PushMessagingDispatcher::registerPushMessaging(
38 const WebString& sender_id, 41 const WebString& sender_id,
39 blink::WebPushRegistrationCallbacks* callbacks) {
40 DCHECK(callbacks);
41 scoped_ptr<blink::WebPushError> error(new blink::WebPushError(
42 blink::WebPushError::ErrorTypeAbort,
43 WebString::fromUTF8(PushMessagingStatusToString(
44 PUSH_MESSAGING_STATUS_REGISTRATION_FAILED_NO_SERVICE_WORKER))));
45 callbacks->onError(error.release());
46 delete callbacks;
47 }
48
49 void PushMessagingDispatcher::registerPushMessaging(
50 const WebString& sender_id,
51 blink::WebPushRegistrationCallbacks* callbacks, 42 blink::WebPushRegistrationCallbacks* callbacks,
52 blink::WebServiceWorkerProvider* service_worker_provider) { 43 blink::WebServiceWorkerProvider* service_worker_provider) {
44 RenderFrameImpl::FromRoutingID(routing_id())->manifest_manager()->GetManifest(
45 base::Bind(&PushMessagingDispatcher::DoRegister,
46 base::Unretained(this),
47 sender_id.utf8(),
48 callbacks,
49 service_worker_provider));
50 }
51
52 void PushMessagingDispatcher::DoRegister(
53 const std::string& sender_id,
54 blink::WebPushRegistrationCallbacks* callbacks,
55 blink::WebServiceWorkerProvider* service_worker_provider,
56 const Manifest& manifest) {
53 DCHECK(callbacks); 57 DCHECK(callbacks);
54 int callbacks_id = registration_callbacks_.Add(callbacks); 58 int callbacks_id = registration_callbacks_.Add(callbacks);
55 int service_worker_provider_id = static_cast<WebServiceWorkerProviderImpl*>( 59 int service_worker_provider_id = static_cast<WebServiceWorkerProviderImpl*>(
56 service_worker_provider)->provider_id(); 60 service_worker_provider)->provider_id();
57 Send(new PushMessagingHostMsg_Register( 61 Send(new PushMessagingHostMsg_Register(
58 routing_id(), 62 routing_id(),
59 callbacks_id, 63 callbacks_id,
60 sender_id.utf8(), 64 manifest.gcm_sender_id.is_null()
65 ? sender_id
66 : base::UTF16ToUTF8(manifest.gcm_sender_id.string()),
61 blink::WebUserGestureIndicator::isProcessingUserGesture(), 67 blink::WebUserGestureIndicator::isProcessingUserGesture(),
62 service_worker_provider_id)); 68 service_worker_provider_id));
63 } 69 }
64 70
65 void PushMessagingDispatcher::OnRegisterSuccess( 71 void PushMessagingDispatcher::OnRegisterSuccess(
66 int32 callbacks_id, 72 int32 callbacks_id,
67 const GURL& endpoint, 73 const GURL& endpoint,
68 const std::string& registration_id) { 74 const std::string& registration_id) {
69 blink::WebPushRegistrationCallbacks* callbacks = 75 blink::WebPushRegistrationCallbacks* callbacks =
70 registration_callbacks_.Lookup(callbacks_id); 76 registration_callbacks_.Lookup(callbacks_id);
(...skipping 14 matching lines...) Expand all
85 CHECK(callbacks); 91 CHECK(callbacks);
86 92
87 scoped_ptr<blink::WebPushError> error(new blink::WebPushError( 93 scoped_ptr<blink::WebPushError> error(new blink::WebPushError(
88 blink::WebPushError::ErrorTypeAbort, 94 blink::WebPushError::ErrorTypeAbort,
89 WebString::fromUTF8(PushMessagingStatusToString(status)))); 95 WebString::fromUTF8(PushMessagingStatusToString(status))));
90 callbacks->onError(error.release()); 96 callbacks->onError(error.release());
91 registration_callbacks_.Remove(callbacks_id); 97 registration_callbacks_.Remove(callbacks_id);
92 } 98 }
93 99
94 } // namespace content 100 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/push_messaging_dispatcher.h ('k') | content/renderer/render_frame_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698