forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Push API: send and receive IPC messages for registration.
BUG=350378 Review URL: https://codereview.chromium.org/219653002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262419 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
mvanouwerkerk@chromium.org
committed
Apr 8, 2014
1 parent
fbe8f04
commit e1c1741
Showing
13 changed files
with
283 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "content/browser/push_messaging_message_filter.h" | ||
|
||
#include <string> | ||
|
||
#include "content/common/push_messaging_messages.h" | ||
#include "content/public/browser/browser_thread.h" | ||
|
||
namespace content { | ||
|
||
PushMessagingMessageFilter::PushMessagingMessageFilter() | ||
: BrowserMessageFilter(PushMessagingMsgStart) {} | ||
|
||
PushMessagingMessageFilter::~PushMessagingMessageFilter() {} | ||
|
||
bool PushMessagingMessageFilter::OnMessageReceived(const IPC::Message& message, | ||
bool* message_was_ok) { | ||
bool handled = true; | ||
IPC_BEGIN_MESSAGE_MAP_EX(PushMessagingMessageFilter, message, *message_was_ok) | ||
IPC_MESSAGE_HANDLER(PushMessagingHostMsg_Register, OnRegister) | ||
IPC_MESSAGE_UNHANDLED(handled = false) | ||
IPC_END_MESSAGE_MAP() | ||
return handled; | ||
} | ||
|
||
void PushMessagingMessageFilter::OnRegister(int routing_id, | ||
int callbacks_id, | ||
const std::string& sender_id) { | ||
// TODO(mvanouwerkerk): Really implement, the below simply returns an error. | ||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | ||
GURL endpoint = GURL("https://android.googleapis.com/gcm/send"); | ||
BrowserThread::PostTask(BrowserThread::UI, | ||
FROM_HERE, | ||
base::Bind(&PushMessagingMessageFilter::DidRegister, | ||
this, | ||
routing_id, | ||
callbacks_id, | ||
endpoint, | ||
"", | ||
true)); | ||
|
||
} | ||
|
||
void PushMessagingMessageFilter::DidRegister(int routing_id, | ||
int callbacks_id, | ||
const GURL& endpoint, | ||
const std::string& registration_id, | ||
bool error) { | ||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | ||
if (!error) { | ||
Send(new PushMessagingMsg_RegisterSuccess(routing_id, | ||
callbacks_id, | ||
endpoint, | ||
registration_id)); | ||
} else { | ||
Send(new PushMessagingMsg_RegisterError(routing_id, callbacks_id)); | ||
} | ||
} | ||
|
||
} // namespace content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CONTENT_BROWSER_PUSH_MESSAGING_MESSAGE_FILTER_H_ | ||
#define CONTENT_BROWSER_PUSH_MESSAGING_MESSAGE_FILTER_H_ | ||
|
||
#include <string> | ||
|
||
#include "content/public/browser/browser_message_filter.h" | ||
#include "url/gurl.h" | ||
|
||
namespace content { | ||
|
||
class PushMessagingMessageFilter : public BrowserMessageFilter { | ||
public: | ||
PushMessagingMessageFilter(); | ||
|
||
private: | ||
virtual ~PushMessagingMessageFilter(); | ||
|
||
// BrowserMessageFilter implementation. | ||
virtual bool OnMessageReceived(const IPC::Message& message, | ||
bool* message_was_ok) OVERRIDE; | ||
|
||
void OnRegister(int routing_id, | ||
int callbacks_id, | ||
const std::string& sender_id); | ||
|
||
void DidRegister(int routing_id, | ||
int callbacks_id, | ||
const GURL& endpoint, | ||
const std::string& registration_id, | ||
bool error); | ||
|
||
DISALLOW_COPY_AND_ASSIGN(PushMessagingMessageFilter); | ||
}; | ||
|
||
} // namespace content | ||
|
||
#endif // CONTENT_BROWSER_PUSH_MESSAGING_MESSAGE_FILTER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// IPC messages for push messaging. | ||
// Multiply-included message file, hence no include guard. | ||
|
||
#include "ipc/ipc_message_macros.h" | ||
#include "url/gurl.h" | ||
|
||
#define IPC_MESSAGE_START PushMessagingMsgStart | ||
|
||
// Messages sent from the browser to the renderer. | ||
|
||
IPC_MESSAGE_ROUTED3(PushMessagingMsg_RegisterSuccess, | ||
int32 /* callbacks_id */, | ||
GURL /* endpoint */, | ||
std::string /* registration_id */) | ||
|
||
IPC_MESSAGE_ROUTED1(PushMessagingMsg_RegisterError, | ||
int32 /* callbacks_id */) | ||
|
||
// Messages sent from the renderer to the browser. | ||
|
||
IPC_MESSAGE_CONTROL3(PushMessagingHostMsg_Register, | ||
int32 /* routing_id */, | ||
int32 /* callbacks_id */, | ||
std::string /* sender_id */) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "content/renderer/push_messaging_dispatcher.h" | ||
|
||
#include "content/common/push_messaging_messages.h" | ||
#include "content/renderer/render_view_impl.h" | ||
#include "ipc/ipc_message.h" | ||
#include "third_party/WebKit/public/platform/WebPushError.h" | ||
#include "third_party/WebKit/public/platform/WebPushRegistration.h" | ||
#include "third_party/WebKit/public/platform/WebString.h" | ||
#include "url/gurl.h" | ||
|
||
using blink::WebString; | ||
|
||
namespace content { | ||
|
||
PushMessagingDispatcher::PushMessagingDispatcher(RenderViewImpl* render_view) | ||
: RenderViewObserver(render_view) {} | ||
|
||
PushMessagingDispatcher::~PushMessagingDispatcher() {} | ||
|
||
bool PushMessagingDispatcher::OnMessageReceived(const IPC::Message& message) { | ||
bool handled = true; | ||
IPC_BEGIN_MESSAGE_MAP(PushMessagingDispatcher, message) | ||
IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterSuccess, OnRegisterSuccess) | ||
IPC_MESSAGE_HANDLER(PushMessagingMsg_RegisterError, OnRegisterError) | ||
IPC_MESSAGE_UNHANDLED(handled = false) | ||
IPC_END_MESSAGE_MAP() | ||
return handled; | ||
} | ||
|
||
void PushMessagingDispatcher::registerPushMessaging( | ||
const WebString& sender_id, | ||
blink::WebPushRegistrationCallbacks* callbacks) { | ||
DCHECK(callbacks); | ||
int callbacks_id = registration_callbacks_.Add(callbacks); | ||
Send(new PushMessagingHostMsg_Register( | ||
routing_id(), callbacks_id, sender_id.utf8())); | ||
} | ||
|
||
void PushMessagingDispatcher::OnRegisterSuccess( | ||
int32 callbacks_id, | ||
const GURL& endpoint, | ||
const std::string& registration_id) { | ||
blink::WebPushRegistrationCallbacks* callbacks = | ||
registration_callbacks_.Lookup(callbacks_id); | ||
CHECK(callbacks); | ||
|
||
scoped_ptr<blink::WebPushRegistration> registration( | ||
new blink::WebPushRegistration( | ||
WebString::fromUTF8(endpoint.spec()), | ||
WebString::fromUTF8(registration_id))); | ||
callbacks->onSuccess(registration.release()); | ||
registration_callbacks_.Remove(callbacks_id); | ||
} | ||
|
||
void PushMessagingDispatcher::OnRegisterError(int32 callbacks_id) { | ||
const std::string kAbortErrorReason = "Registration failed."; | ||
blink::WebPushRegistrationCallbacks* callbacks = | ||
registration_callbacks_.Lookup(callbacks_id); | ||
CHECK(callbacks); | ||
|
||
scoped_ptr<blink::WebPushError> error( | ||
new blink::WebPushError( | ||
blink::WebPushError::ErrorTypeAbort, | ||
WebString::fromUTF8(kAbortErrorReason))); | ||
callbacks->onError(error.release()); | ||
registration_callbacks_.Remove(callbacks_id); | ||
} | ||
|
||
} // namespace content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CONTENT_RENDERER_PUSH_MESSAGING_DISPATCHER_H_ | ||
#define CONTENT_RENDERER_PUSH_MESSAGING_DISPATCHER_H_ | ||
|
||
#include <string> | ||
|
||
#include "base/id_map.h" | ||
#include "content/public/renderer/render_view_observer.h" | ||
#include "third_party/WebKit/public/platform/WebPushClient.h" | ||
|
||
class GURL; | ||
|
||
namespace IPC { | ||
class Message; | ||
} // namespace IPC | ||
|
||
namespace blink { | ||
class WebString; | ||
} // namespace blink | ||
|
||
namespace content { | ||
class RenderViewImpl; | ||
|
||
class PushMessagingDispatcher : public RenderViewObserver, | ||
public blink::WebPushClient { | ||
public: | ||
explicit PushMessagingDispatcher(RenderViewImpl* render_view); | ||
virtual ~PushMessagingDispatcher(); | ||
|
||
private: | ||
// RenderView::Observer implementation. | ||
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | ||
|
||
// WebPushClient implementation. | ||
virtual void registerPushMessaging( | ||
const blink::WebString& sender_id, | ||
blink::WebPushRegistrationCallbacks* callbacks) OVERRIDE; | ||
|
||
void OnRegisterSuccess(int32 callbacks_id, | ||
const GURL& endpoint, | ||
const std::string& registration_id); | ||
|
||
void OnRegisterError(int32 callbacks_id); | ||
|
||
IDMap<blink::WebPushRegistrationCallbacks, IDMapOwnPointer> | ||
registration_callbacks_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(PushMessagingDispatcher); | ||
}; | ||
|
||
} // namespace content | ||
|
||
#endif // CONTENT_RENDERER_PUSH_MESSAGING_DISPATCHER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters