Commit 07c26f62 authored by Steve Becker's avatar Steve Becker Committed by Commit Bot

Push messaging: Move endpoint URL creation into PushMessagingServiceImpl

content::PushMessagingService is a "push service-agnostic interface that
the Push API uses for talking to push messaging services like GCM."
This change updates the PushMessagingService interface to improve
compatibility with other push services by removing GetEndpoint().
The change also updates the PushMessagingService callbacks for
subscribe() and getSubscription() to include the endpoint URL.  The
new callbacks provide the endpoint URL without using GetEndpoint().

Before this change, PushMessagingService::GetEndpoint() returned the
absolute URL of the push service.  content::PushMessagingManager created
a subscription's endpoint URL by appending the subscription ID to the
return value from PushMessagingService::GetEndpoint().

This scheme does not work for all push services.  For example,
Microsoft's push service may use a different domain for each
subscription.  Additionally, Microsoft's push service endpoints do not
include the subscription ID.

This change moves endpoint URL construction from
endpoint URL construction from the content layer to the chrome layer
enables Chromium embedders to replace GCM with another push service
without updating the content layer.

content: :PushMessagingManager to PushMessagingServiceImpl.  Moving
Change-Id: Ifb5ee1dc8455d1dcbc34c52c29bc40de7e97476a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1704989Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Commit-Queue: Steve Becker <stevebe@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#678443}
parent 2e8255b2
......@@ -122,6 +122,7 @@ void LegacyRegisterCallback(const base::Closure& done_callback,
void DidRegister(base::Closure done_callback,
const std::string& registration_id,
const GURL& endpoint,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth,
blink::mojom::PushRegistrationStatus status) {
......@@ -488,8 +489,7 @@ void PushMessagingBrowserTest::EndpointToToken(const std::string& endpoint,
std::string* out_token) {
size_t last_slash = endpoint.rfind('/');
ASSERT_EQ(push_service()->GetEndpoint(standard_protocol).spec(),
endpoint.substr(0, last_slash + 1));
ASSERT_EQ(kPushMessagingGcmEndpoint, endpoint.substr(0, last_slash + 1));
ASSERT_LT(last_slash + 1, endpoint.length()); // Token must not be empty.
......
......@@ -498,12 +498,6 @@ void PushMessagingServiceImpl::OnMessageDecryptionFailed(
/* was_encrypted= */ true, error_message, "" /* payload */);
}
// GetEndpoint method ----------------------------------------------------------
GURL PushMessagingServiceImpl::GetEndpoint(bool standard_protocol) {
return GURL(kPushMessagingGcmEndpoint);
}
// Subscribe and GetPermissionStatus methods -----------------------------------
void PushMessagingServiceImpl::SubscribeFromDocument(
......@@ -647,16 +641,18 @@ void PushMessagingServiceImpl::DoSubscribe(
void PushMessagingServiceImpl::SubscribeEnd(
RegisterCallback callback,
const std::string& subscription_id,
const GURL& endpoint,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth,
blink::mojom::PushRegistrationStatus status) {
std::move(callback).Run(subscription_id, p256dh, auth, status);
std::move(callback).Run(subscription_id, endpoint, p256dh, auth, status);
}
void PushMessagingServiceImpl::SubscribeEndWithError(
RegisterCallback callback,
blink::mojom::PushRegistrationStatus status) {
SubscribeEnd(std::move(callback), std::string() /* subscription_id */,
GURL::EmptyGURL() /* endpoint */,
std::vector<uint8_t>() /* p256dh */,
std::vector<uint8_t>() /* auth */, status);
}
......@@ -673,7 +669,9 @@ void PushMessagingServiceImpl::DidSubscribe(
blink::mojom::PushRegistrationStatus::SERVICE_ERROR;
switch (result) {
case InstanceID::SUCCESS:
case InstanceID::SUCCESS: {
const GURL endpoint = CreateEndpoint(subscription_id);
// Make sure that this subscription has associated encryption keys prior
// to returning it to the developer - they'll need this information in
// order to send payloads to the user.
......@@ -682,8 +680,9 @@ void PushMessagingServiceImpl::DidSubscribe(
base::BindOnce(
&PushMessagingServiceImpl::DidSubscribeWithEncryptionInfo,
weak_factory_.GetWeakPtr(), app_identifier, std::move(callback),
subscription_id));
subscription_id, endpoint));
return;
}
case InstanceID::INVALID_PARAMETER:
case InstanceID::DISABLED:
case InstanceID::ASYNC_OPERATION_PENDING:
......@@ -705,6 +704,7 @@ void PushMessagingServiceImpl::DidSubscribeWithEncryptionInfo(
const PushMessagingAppIdentifier& app_identifier,
RegisterCallback callback,
const std::string& subscription_id,
const GURL& endpoint,
std::string p256dh,
std::string auth_secret) {
if (p256dh.empty()) {
......@@ -718,7 +718,7 @@ void PushMessagingServiceImpl::DidSubscribeWithEncryptionInfo(
IncreasePushSubscriptionCount(1, false /* is_pending */);
SubscribeEnd(std::move(callback), subscription_id,
SubscribeEnd(std::move(callback), subscription_id, endpoint,
std::vector<uint8_t>(p256dh.begin(), p256dh.end()),
std::vector<uint8_t>(auth_secret.begin(), auth_secret.end()),
blink::mojom::PushRegistrationStatus::SUCCESS_FROM_PUSH_SERVICE);
......@@ -737,15 +737,17 @@ void PushMessagingServiceImpl::GetSubscriptionInfo(
profile_, origin, service_worker_registration_id);
if (app_identifier.is_null()) {
callback.Run(false /* is_valid */, std::vector<uint8_t>() /* p256dh */,
callback.Run(false /* is_valid */, GURL::EmptyGURL() /*endpoint*/,
std::vector<uint8_t>() /* p256dh */,
std::vector<uint8_t>() /* auth */);
return;
}
const GURL endpoint = CreateEndpoint(subscription_id);
const std::string& app_id = app_identifier.app_id();
base::Callback<void(bool)> validate_cb =
base::Bind(&PushMessagingServiceImpl::DidValidateSubscription,
weak_factory_.GetWeakPtr(), app_id, sender_id, callback);
base::Callback<void(bool)> validate_cb = base::Bind(
&PushMessagingServiceImpl::DidValidateSubscription,
weak_factory_.GetWeakPtr(), app_id, sender_id, endpoint, callback);
if (PushMessagingAppIdentifier::UseInstanceID(app_id)) {
GetInstanceIDDriver()->GetInstanceID(app_id)->ValidateToken(
......@@ -760,10 +762,12 @@ void PushMessagingServiceImpl::GetSubscriptionInfo(
void PushMessagingServiceImpl::DidValidateSubscription(
const std::string& app_id,
const std::string& sender_id,
const GURL& endpoint,
const SubscriptionInfoCallback& callback,
bool is_valid) {
if (!is_valid) {
callback.Run(false /* is_valid */, std::vector<uint8_t>() /* p256dh */,
callback.Run(false /* is_valid */, GURL::EmptyGURL() /* endpoint */,
std::vector<uint8_t>() /* p256dh */,
std::vector<uint8_t>() /* auth */);
return;
}
......@@ -771,16 +775,18 @@ void PushMessagingServiceImpl::DidValidateSubscription(
GetEncryptionInfoForAppId(
app_id, sender_id,
base::BindOnce(&PushMessagingServiceImpl::DidGetEncryptionInfo,
weak_factory_.GetWeakPtr(), callback));
weak_factory_.GetWeakPtr(), endpoint, callback));
}
void PushMessagingServiceImpl::DidGetEncryptionInfo(
const GURL& endpoint,
const SubscriptionInfoCallback& callback,
std::string p256dh,
std::string auth_secret) const {
// I/O errors might prevent the GCM Driver from retrieving a key-pair.
bool is_valid = !p256dh.empty();
callback.Run(is_valid, std::vector<uint8_t>(p256dh.begin(), p256dh.end()),
callback.Run(is_valid, endpoint,
std::vector<uint8_t>(p256dh.begin(), p256dh.end()),
std::vector<uint8_t>(auth_secret.begin(), auth_secret.end()));
}
......@@ -1131,6 +1137,13 @@ void PushMessagingServiceImpl::GetEncryptionInfoForAppId(
}
}
GURL PushMessagingServiceImpl::CreateEndpoint(
const std::string& subscription_id) const {
const GURL endpoint(kPushMessagingGcmEndpoint + subscription_id);
DCHECK(endpoint.is_valid());
return endpoint;
}
gcm::GCMDriver* PushMessagingServiceImpl::GetGCMDriver() const {
gcm::GCMProfileService* gcm_profile_service =
gcm::GCMProfileServiceFactory::GetForProfile(profile_);
......
......@@ -90,7 +90,6 @@ class PushMessagingServiceImpl : public content::PushMessagingService,
bool CanHandle(const std::string& app_id) const override;
// content::PushMessagingService implementation:
GURL GetEndpoint(bool standard_protocol) override;
void SubscribeFromDocument(const GURL& requesting_origin,
int64_t service_worker_registration_id,
int renderer_id,
......@@ -173,6 +172,7 @@ class PushMessagingServiceImpl : public content::PushMessagingService,
void SubscribeEnd(RegisterCallback callback,
const std::string& subscription_id,
const GURL& endpoint,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth,
blink::mojom::PushRegistrationStatus status);
......@@ -190,6 +190,7 @@ class PushMessagingServiceImpl : public content::PushMessagingService,
const PushMessagingAppIdentifier& app_identifier,
RegisterCallback callback,
const std::string& subscription_id,
const GURL& endpoint,
std::string p256dh,
std::string auth_secret);
......@@ -197,10 +198,12 @@ class PushMessagingServiceImpl : public content::PushMessagingService,
void DidValidateSubscription(const std::string& app_id,
const std::string& sender_id,
const GURL& endpoint,
const SubscriptionInfoCallback& callback,
bool is_valid);
void DidGetEncryptionInfo(const SubscriptionInfoCallback& callback,
void DidGetEncryptionInfo(const GURL& endpoint,
const SubscriptionInfoCallback& callback,
std::string p256dh,
std::string auth_secret) const;
......@@ -254,6 +257,10 @@ class PushMessagingServiceImpl : public content::PushMessagingService,
const std::string& sender_id,
gcm::GCMEncryptionProvider::EncryptionInfoCallback callback);
// Returns the URL used to send push messages to the subscription identified
// by |subscription_id|.
GURL CreateEndpoint(const std::string& subscription_id) const;
gcm::GCMDriver* GetGCMDriver() const;
instance_id::InstanceIDDriver* GetInstanceIDDriver() const;
......
......@@ -104,10 +104,12 @@ class PushMessagingServiceTest : public ::testing::Test {
// Callback to use when the subscription may have been subscribed.
void DidRegister(std::string* subscription_id_out,
GURL* endpoint_out,
std::vector<uint8_t>* p256dh_out,
std::vector<uint8_t>* auth_out,
base::Closure done_callback,
const std::string& registration_id,
const GURL& endpoint,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth,
blink::mojom::PushRegistrationStatus status) {
......@@ -115,6 +117,7 @@ class PushMessagingServiceTest : public ::testing::Test {
status);
*subscription_id_out = registration_id;
*endpoint_out = endpoint;
*p256dh_out = p256dh;
*auth_out = auth;
......@@ -161,6 +164,7 @@ TEST_F(PushMessagingServiceTest, PayloadEncryptionTest) {
push_service->GetPermissionStatus(origin, true));
std::string subscription_id;
GURL endpoint;
std::vector<uint8_t> p256dh, auth;
base::RunLoop run_loop;
......@@ -175,13 +179,16 @@ TEST_F(PushMessagingServiceTest, PayloadEncryptionTest) {
push_service->SubscribeFromWorker(
origin, kTestServiceWorkerId, std::move(options),
base::Bind(&PushMessagingServiceTest::DidRegister, base::Unretained(this),
&subscription_id, &p256dh, &auth, run_loop.QuitClosure()));
&subscription_id, &endpoint, &p256dh, &auth,
run_loop.QuitClosure()));
EXPECT_EQ(0u, subscription_id.size()); // this must be asynchronous
run_loop.Run();
ASSERT_GT(subscription_id.size(), 0u);
ASSERT_TRUE(endpoint.is_valid());
ASSERT_GT(endpoint.spec().size(), 0u);
ASSERT_GT(p256dh.size(), 0u);
ASSERT_GT(auth.size(), 0u);
......
......@@ -104,14 +104,6 @@ const char* PushUnregistrationStatusToString(
return "";
}
// Returns whether |application_server_key| contains a valid application server
// key, that is, a NIST P-256 public key in uncompressed format.
bool IsApplicationServerKey(
const std::vector<uint8_t>& application_server_key) {
return application_server_key.size() == 65 &&
application_server_key[0] == 0x04;
}
// Returns application_server_key if non-empty, otherwise checks if
// stored_sender_id may be used as a fallback and if so, returns
// stored_sender_id instead.
......@@ -177,9 +169,9 @@ class PushMessagingManager::Core {
void GetSubscriptionDidGetInfoOnUI(GetSubscriptionCallback callback,
const GURL& origin,
int64_t service_worker_registration_id,
const GURL& endpoint,
const std::string& application_server_key,
bool is_valid,
const GURL& endpoint,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth);
......@@ -222,6 +214,7 @@ class PushMessagingManager::Core {
void DidRegister(RegisterData data,
const std::string& push_subscription_id,
const GURL& endpoint,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth,
blink::mojom::PushRegistrationStatus status);
......@@ -281,12 +274,6 @@ PushMessagingManager::PushMessagingManager(
PushMessagingService* service = ui_core_->service();
service_available_ = !!service;
if (service_available_) {
default_endpoint_ = service->GetEndpoint(false /* standard_protocol */);
web_push_protocol_endpoint_ =
service->GetEndpoint(true /* standard_protocol */);
}
}
PushMessagingManager::~PushMessagingManager() {}
......@@ -523,6 +510,7 @@ void PushMessagingManager::Core::DidRequestPermissionInIncognito(
void PushMessagingManager::Core::DidRegister(
RegisterData data,
const std::string& push_subscription_id,
const GURL& endpoint,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth,
blink::mojom::PushRegistrationStatus status) {
......@@ -541,7 +529,7 @@ void PushMessagingManager::Core::DidRegister(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&PushMessagingManager::PersistRegistrationOnIO,
io_parent_, std::move(data), push_subscription_id,
p256dh, auth,
endpoint, p256dh, auth,
subscription_changed
? blink::mojom::PushRegistrationStatus::
SUCCESS_NEW_SUBSCRIPTION_FROM_PUSH_SERVICE
......@@ -558,6 +546,7 @@ void PushMessagingManager::Core::DidRegister(
void PushMessagingManager::PersistRegistrationOnIO(
RegisterData data,
const std::string& push_subscription_id,
const GURL& endpoint,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth,
blink::mojom::PushRegistrationStatus status) {
......@@ -573,21 +562,21 @@ void PushMessagingManager::PersistRegistrationOnIO(
{{kPushRegistrationIdServiceWorkerKey, push_subscription_id},
{kPushSenderIdServiceWorkerKey, application_server_key}},
base::BindOnce(&PushMessagingManager::DidPersistRegistrationOnIO,
weak_factory_.GetWeakPtr(), std::move(data),
push_subscription_id, p256dh, auth, status));
weak_factory_.GetWeakPtr(), std::move(data), endpoint,
p256dh, auth, status));
}
void PushMessagingManager::DidPersistRegistrationOnIO(
RegisterData data,
const std::string& push_subscription_id,
const GURL& endpoint,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth,
blink::mojom::PushRegistrationStatus push_registration_status,
blink::ServiceWorkerStatusCode service_worker_status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (service_worker_status == blink::ServiceWorkerStatusCode::kOk) {
SendSubscriptionSuccess(std::move(data), push_registration_status,
push_subscription_id, p256dh, auth);
SendSubscriptionSuccess(std::move(data), push_registration_status, endpoint,
p256dh, auth);
} else {
// TODO(johnme): Unregister, so PushMessagingServiceImpl can decrease count.
SendSubscriptionError(std::move(data),
......@@ -606,7 +595,7 @@ void PushMessagingManager::SendSubscriptionError(
void PushMessagingManager::SendSubscriptionSuccess(
RegisterData data,
blink::mojom::PushRegistrationStatus status,
const std::string& push_subscription_id,
const GURL& endpoint,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
......@@ -620,10 +609,6 @@ void PushMessagingManager::SendSubscriptionSuccess(
return;
}
const GURL endpoint = CreateEndpoint(
IsApplicationServerKey(data.options->application_server_key),
push_subscription_id);
std::move(data.callback)
.Run(status, blink::mojom::PushSubscription::New(
endpoint, std::move(data.options), p256dh, auth));
......@@ -803,12 +788,6 @@ void PushMessagingManager::DidGetSubscription(
const GURL origin = registration->scope().GetOrigin();
const bool uses_standard_protocol =
IsApplicationServerKey(std::vector<uint8_t>(
application_server_key.begin(), application_server_key.end()));
const GURL endpoint =
CreateEndpoint(uses_standard_protocol, push_subscription_id);
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(&Core::GetSubscriptionInfoOnUI,
......@@ -818,7 +797,7 @@ void PushMessagingManager::DidGetSubscription(
base::Bind(&Core::GetSubscriptionDidGetInfoOnUI,
ui_core_weak_ptr_, base::Passed(&callback),
origin, service_worker_registration_id,
endpoint, application_server_key)));
application_server_key)));
return;
}
......@@ -863,9 +842,9 @@ void PushMessagingManager::Core::GetSubscriptionDidGetInfoOnUI(
GetSubscriptionCallback callback,
const GURL& origin,
int64_t service_worker_registration_id,
const GURL& endpoint,
const std::string& application_server_key,
bool is_valid,
const GURL& endpoint,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
......@@ -947,9 +926,9 @@ void PushMessagingManager::Core::GetSubscriptionInfoOnUI(
DCHECK_CURRENTLY_ON(BrowserThread::UI);
PushMessagingService* push_service = service();
if (!push_service) {
std::move(callback).Run(false /* is_valid */,
std::vector<uint8_t>() /* p256dh */,
std::vector<uint8_t>() /* auth */);
std::move(callback).Run(
false /* is_valid */, GURL::EmptyGURL() /* endpoint */,
std::vector<uint8_t>() /* p256dh */, std::vector<uint8_t>() /* auth */);
return;
}
......@@ -958,15 +937,6 @@ void PushMessagingManager::Core::GetSubscriptionInfoOnUI(
std::move(callback));
}
GURL PushMessagingManager::CreateEndpoint(
bool standard_protocol,
const std::string& subscription_id) const {
const GURL& base =
standard_protocol ? web_push_protocol_endpoint_ : default_endpoint_;
return GURL(base.spec() + subscription_id);
}
PushMessagingService* PushMessagingManager::Core::service() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
RenderProcessHost* process_host =
......
......@@ -85,13 +85,14 @@ class PushMessagingManager : public blink::mojom::PushMessaging {
// Called via PostTask from UI thread.
void PersistRegistrationOnIO(RegisterData data,
const std::string& push_subscription_id,
const GURL& endpoint,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth,
blink::mojom::PushRegistrationStatus status);
void DidPersistRegistrationOnIO(
RegisterData data,
const std::string& push_subscription_id,
const GURL& endpoint,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth,
blink::mojom::PushRegistrationStatus push_registration_status,
......@@ -103,7 +104,7 @@ class PushMessagingManager : public blink::mojom::PushMessaging {
// Called both from IO thread, and via PostTask from UI thread.
void SendSubscriptionSuccess(RegisterData data,
blink::mojom::PushRegistrationStatus status,
const std::string& push_subscription_id,
const GURL& endpoint,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth);
......@@ -127,11 +128,6 @@ class PushMessagingManager : public blink::mojom::PushMessaging {
// Helper methods on either thread -------------------------------------------
// Creates an endpoint for |subscription_id| with either the default protocol,
// or the standardized Web Push Protocol, depending on |standard_protocol|.
GURL CreateEndpoint(bool standard_protocol,
const std::string& subscription_id) const;
// Inner core of this message filter which lives on the UI thread.
std::unique_ptr<Core, BrowserThread::DeleteOnUIThread> ui_core_;
......@@ -147,9 +143,6 @@ class PushMessagingManager : public blink::mojom::PushMessaging {
// Will be ChildProcessHost::kInvalidUniqueID in requests from Service Worker.
int render_frame_id_;
GURL default_endpoint_;
GURL web_push_protocol_endpoint_;
mojo::ReceiverSet<blink::mojom::PushMessaging> receivers_;
base::WeakPtrFactory<PushMessagingManager> weak_factory_{this};
......
......@@ -33,6 +33,7 @@ class CONTENT_EXPORT PushMessagingService {
public:
using RegisterCallback =
base::OnceCallback<void(const std::string& registration_id,
const GURL& endpoint,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth,
blink::mojom::PushRegistrationStatus status)>;
......@@ -40,6 +41,7 @@ class CONTENT_EXPORT PushMessagingService {
base::OnceCallback<void(blink::mojom::PushUnregistrationStatus)>;
using SubscriptionInfoCallback =
base::Callback<void(bool is_valid,
const GURL& endpoint,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth)>;
using StringCallback = base::Callback<void(const std::string& data,
......@@ -48,11 +50,6 @@ class CONTENT_EXPORT PushMessagingService {
virtual ~PushMessagingService() {}
// Returns the absolute URL to the endpoint of the push service where messages
// should be posted to. Should return an endpoint compatible with the Web Push
// Protocol when |standard_protocol| is true.
virtual GURL GetEndpoint(bool standard_protocol) = 0;
// Subscribes the given |options->sender_info| with the push messaging service
// in a document context. The frame is known and a permission UI may be
// displayed to the user. It's safe to call this method multiple times for
......
......@@ -47,11 +47,6 @@ WebTestPushMessagingService::WebTestPushMessagingService()
WebTestPushMessagingService::~WebTestPushMessagingService() {}
GURL WebTestPushMessagingService::GetEndpoint(bool standard_protocol) {
return GURL(standard_protocol ? "https://example.com/StandardizedEndpoint/"
: "https://example.com/LayoutTestEndpoint/");
}
void WebTestPushMessagingService::SubscribeFromDocument(
const GURL& requesting_origin,
int64_t service_worker_registration_id,
......@@ -86,14 +81,17 @@ void WebTestPushMessagingService::SubscribeFromWorker(
std::vector<uint8_t> auth(kAuthentication,
kAuthentication + base::size(kAuthentication));
const std::string subscription_id = "layoutTestRegistrationId";
const GURL endpoint = CreateEndpoint(subscription_id);
subscribed_service_worker_registration_ = service_worker_registration_id;
std::move(callback).Run(
"layoutTestRegistrationId", p256dh, auth,
subscription_id, endpoint, p256dh, auth,
blink::mojom::PushRegistrationStatus::SUCCESS_FROM_PUSH_SERVICE);
} else {
std::move(callback).Run(
"registration_id", std::vector<uint8_t>() /* p256dh */,
std::vector<uint8_t>() /* auth */,
"registration_id", GURL::EmptyGURL() /* endpoint */,
std::vector<uint8_t>() /* p256dh */, std::vector<uint8_t>() /* auth */,
blink::mojom::PushRegistrationStatus::PERMISSION_DENIED);
}
}
......@@ -109,7 +107,8 @@ void WebTestPushMessagingService::GetSubscriptionInfo(
std::vector<uint8_t> auth(kAuthentication,
kAuthentication + base::size(kAuthentication));
callback.Run(true /* is_valid */, p256dh, auth);
const GURL endpoint = CreateEndpoint(subscription_id);
callback.Run(true /* is_valid */, endpoint, p256dh, auth);
}
bool WebTestPushMessagingService::SupportNonVisibleMessages() {
......@@ -154,4 +153,9 @@ void WebTestPushMessagingService::DidDeleteServiceWorkerDatabase() {
blink::mojom::kInvalidServiceWorkerRegistrationId;
}
GURL WebTestPushMessagingService::CreateEndpoint(
const std::string& subscription_id) const {
return GURL("https://example.com/StandardizedEndpoint/" + subscription_id);
}
} // namespace content
......@@ -22,7 +22,6 @@ class WebTestPushMessagingService : public PushMessagingService {
~WebTestPushMessagingService() override;
// PushMessagingService implementation:
GURL GetEndpoint(bool standard_protocol) override;
void SubscribeFromDocument(const GURL& requesting_origin,
int64_t service_worker_registration_id,
int renderer_id,
......@@ -51,6 +50,8 @@ class WebTestPushMessagingService : public PushMessagingService {
void DidDeleteServiceWorkerDatabase() override;
private:
GURL CreateEndpoint(const std::string& subscription_id) const;
int64_t subscribed_service_worker_registration_;
DISALLOW_COPY_AND_ASSIGN(WebTestPushMessagingService);
......
......@@ -31,7 +31,7 @@
return registerAndSubscribePushWithString(test, '0123456789')
.then(function(pushSubscription) {
assert_true(
pushSubscription.endpoint.includes('LayoutTestEndpoint'));
pushSubscription.endpoint.includes('StandardizedEndpoint'));
});
}, 'Subscribing with a valid numeric sender ID should succeed');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment