summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpeter <peter@chromium.org>2015-04-01 09:41:04 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-01 16:41:56 +0000
commit3e2d63d0413e2f0507f76cbe82cb1a03af451da8 (patch)
treee6c1045dfa3e78d62bd57dd5d9af1de1861654a1
parentc638a07bf65457b24956785146d3429045a47fe2 (diff)
downloadchromium_src-3e2d63d0413e2f0507f76cbe82cb1a03af451da8.zip
chromium_src-3e2d63d0413e2f0507f76cbe82cb1a03af451da8.tar.gz
chromium_src-3e2d63d0413e2f0507f76cbe82cb1a03af451da8.tar.bz2
Hook up PushSubscriptionOptions on the Chromium side.
This patch teaches Chromium how to deal with the PushSubscriptionOptions structure in addition to the existing gcm_user_visible_only key. Blink does not call the new methods yet. Additionally, rename a whole bunch of things to subscribe where they touch the Blink API. This allows us to do another three-sided patch later on. The rename is far from complete on the Chromium side. This CL is part of a series of four: [1] https://codereview.chromium.org/1047533002/ [2] This patch. [3] https://codereview.chromium.org/1044663002/ [4] https://codereview.chromium.org/1044673002/ BUG=471534, 446883 Review URL: https://codereview.chromium.org/1043723003 Cr-Commit-Position: refs/heads/master@{#323256}
-rw-r--r--chrome/browser/push_messaging/push_messaging_service_impl.cc20
-rw-r--r--chrome/browser/push_messaging/push_messaging_service_impl.h6
-rw-r--r--content/browser/push_messaging/push_messaging_message_filter.cc62
-rw-r--r--content/browser/push_messaging/push_messaging_message_filter.h22
-rw-r--r--content/child/push_messaging/push_provider.cc103
-rw-r--r--content/child/push_messaging/push_provider.h54
-rw-r--r--content/common/push_messaging_messages.h52
-rw-r--r--content/public/browser/push_messaging_service.h9
-rw-r--r--content/renderer/push_messaging/push_messaging_dispatcher.cc58
-rw-r--r--content/renderer/push_messaging/push_messaging_dispatcher.h23
-rw-r--r--content/shell/browser/layout_test/layout_test_push_messaging_service.cc10
-rw-r--r--content/shell/browser/layout_test/layout_test_push_messaging_service.h6
12 files changed, 272 insertions, 153 deletions
diff --git a/chrome/browser/push_messaging/push_messaging_service_impl.cc b/chrome/browser/push_messaging/push_messaging_service_impl.cc
index 251e85a..6de1b0e 100644
--- a/chrome/browser/push_messaging/push_messaging_service_impl.cc
+++ b/chrome/browser/push_messaging/push_messaging_service_impl.cc
@@ -455,7 +455,7 @@ void PushMessagingServiceImpl::RegisterFromDocument(
const std::string& sender_id,
int renderer_id,
int render_frame_id,
- bool user_visible_only,
+ bool user_visible,
const content::PushMessagingService::RegisterCallback& callback) {
PushMessagingApplicationId application_id =
PushMessagingApplicationId::Generate(requesting_origin,
@@ -490,15 +490,15 @@ void PushMessagingServiceImpl::RegisterFromDocument(
PushMessagingPermissionContext* permission_context =
PushMessagingPermissionContextFactory::GetForProfile(profile_);
- if (permission_context == NULL || !user_visible_only) {
+ if (permission_context == NULL || !user_visible) {
RegisterEnd(callback,
std::string(),
content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED);
return;
}
- // TODO(miguelg): Consider the value of |user_visible_only| when making
- // the permission request.
+ // TODO(miguelg): Consider the value of |user_visible| when making the
+ // permission request.
// TODO(mlamouri): Move requesting Push permission over to using Mojo, and
// re-introduce the ability of |user_gesture| when bubbles require this.
// https://crbug.com/423770.
@@ -513,6 +513,7 @@ void PushMessagingServiceImpl::RegisterFromWorker(
const GURL& requesting_origin,
int64 service_worker_registration_id,
const std::string& sender_id,
+ bool user_visible,
const content::PushMessagingService::RegisterCallback& register_callback) {
PushMessagingApplicationId application_id =
PushMessagingApplicationId::Generate(requesting_origin,
@@ -526,10 +527,14 @@ void PushMessagingServiceImpl::RegisterFromWorker(
return;
}
+ // TODO(peter): Consider |user_visible| when getting the permission status
+ // for registering from a worker.
+
GURL embedding_origin = requesting_origin;
blink::WebPushPermissionStatus permission_status =
PushMessagingServiceImpl::GetPermissionStatus(requesting_origin,
- embedding_origin);
+ embedding_origin,
+ user_visible);
if (permission_status != blink::WebPushPermissionStatusGranted) {
RegisterEnd(register_callback, std::string(),
content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED);
@@ -547,7 +552,10 @@ void PushMessagingServiceImpl::RegisterFromWorker(
blink::WebPushPermissionStatus PushMessagingServiceImpl::GetPermissionStatus(
const GURL& requesting_origin,
- const GURL& embedding_origin) {
+ const GURL& embedding_origin,
+ bool user_visible) {
+ // TODO(peter): Consider |user_visible| when checking Push permission.
+
PushMessagingPermissionContext* permission_context =
PushMessagingPermissionContextFactory::GetForProfile(profile_);
return ToPushPermission(permission_context->GetPermissionStatus(
diff --git a/chrome/browser/push_messaging/push_messaging_service_impl.h b/chrome/browser/push_messaging/push_messaging_service_impl.h
index a08d16f..01de398 100644
--- a/chrome/browser/push_messaging/push_messaging_service_impl.h
+++ b/chrome/browser/push_messaging/push_messaging_service_impl.h
@@ -63,12 +63,13 @@ class PushMessagingServiceImpl : public content::PushMessagingService,
const std::string& sender_id,
int renderer_id,
int render_frame_id,
- bool user_visible_only,
+ bool user_visible,
const content::PushMessagingService::RegisterCallback& callback) override;
void RegisterFromWorker(
const GURL& requesting_origin,
int64 service_worker_registration_id,
const std::string& sender_id,
+ bool user_visible,
const content::PushMessagingService::RegisterCallback& callback) override;
void Unregister(
const GURL& requesting_origin,
@@ -77,7 +78,8 @@ class PushMessagingServiceImpl : public content::PushMessagingService,
const content::PushMessagingService::UnregisterCallback&) override;
blink::WebPushPermissionStatus GetPermissionStatus(
const GURL& requesting_origin,
- const GURL& embedding_origin) override;
+ const GURL& embedding_origin,
+ bool user_visible) override;
// content_settings::Observer implementation.
void OnContentSettingChanged(const ContentSettingsPattern& primary_pattern,
diff --git a/content/browser/push_messaging/push_messaging_message_filter.cc b/content/browser/push_messaging/push_messaging_message_filter.cc
index 4a83a7c..3e319b6 100644
--- a/content/browser/push_messaging/push_messaging_message_filter.cc
+++ b/content/browser/push_messaging/push_messaging_message_filter.cc
@@ -62,10 +62,10 @@ struct PushMessagingMessageFilter::RegisterData {
bool FromDocument() const;
int request_id;
GURL requesting_origin;
- int64 service_worker_registration_id;
- // The following two members should only be read if FromDocument() is true.
+ int64_t service_worker_registration_id;
+ bool user_visible;
+ // The following member should only be read if FromDocument() is true.
int render_frame_id;
- bool user_visible_only;
};
@@ -84,14 +84,16 @@ class PushMessagingMessageFilter::Core {
// Called via PostTask from IO thread.
void UnregisterFromService(int request_id,
- int64 service_worker_registration_id,
+ int64_t service_worker_registration_id,
const GURL& requesting_origin,
const std::string& sender_id);
// Public GetPermission methods on UI thread ---------------------------------
// Called via PostTask from IO thread.
- void GetPermissionStatusOnUI(const GURL& requesting_origin, int request_id);
+ void GetPermissionStatusOnUI(const GURL& requesting_origin,
+ bool user_visible,
+ int request_id);
// Public helper methods on UI thread ----------------------------------------
@@ -116,7 +118,7 @@ class PushMessagingMessageFilter::Core {
// Private Unregister methods on UI thread -----------------------------------
void DidUnregisterFromService(int request_id,
- int64 service_worker_registration_id,
+ int64_t service_worker_registration_id,
PushUnregistrationStatus unregistration_status);
// Private helper methods on UI thread ---------------------------------------
@@ -139,8 +141,8 @@ class PushMessagingMessageFilter::Core {
PushMessagingMessageFilter::RegisterData::RegisterData()
: request_id(0),
service_worker_registration_id(0),
- render_frame_id(ChildProcessHost::kInvalidUniqueID),
- user_visible_only(false) {
+ user_visible(false),
+ render_frame_id(ChildProcessHost::kInvalidUniqueID) {
}
bool PushMessagingMessageFilter::RegisterData::FromDocument() const {
@@ -211,16 +213,16 @@ void PushMessagingMessageFilter::OnRegisterFromDocument(
int render_frame_id,
int request_id,
const std::string& sender_id,
- bool user_visible_only,
- int64 service_worker_registration_id) {
+ bool user_visible,
+ int64_t service_worker_registration_id) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// TODO(mvanouwerkerk): Validate arguments?
- // TODO(peter): Persist |user_visible_only| in Service Worker storage.
+ // TODO(peter): Persist |user_visible| in Service Worker storage.
RegisterData data;
data.request_id = request_id;
data.service_worker_registration_id = service_worker_registration_id;
data.render_frame_id = render_frame_id;
- data.user_visible_only = user_visible_only;
+ data.user_visible = user_visible;
ServiceWorkerRegistration* service_worker_registration =
service_worker_context_->context()->GetLiveRegistration(
@@ -244,11 +246,13 @@ void PushMessagingMessageFilter::OnRegisterFromDocument(
void PushMessagingMessageFilter::OnRegisterFromWorker(
int request_id,
- int64 service_worker_registration_id) {
+ int64_t service_worker_registration_id,
+ bool user_visible) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
RegisterData data;
data.request_id = request_id;
data.service_worker_registration_id = service_worker_registration_id;
+ data.user_visible = user_visible;
ServiceWorkerRegistration* service_worker_registration =
service_worker_context_->context()->GetLiveRegistration(
@@ -346,7 +350,7 @@ void PushMessagingMessageFilter::Core::RegisterOnUI(
} else {
// Prevent websites from detecting incognito mode, by emulating what would
// have happened if we had a PushMessagingService available.
- if (!data.FromDocument() || !data.user_visible_only) {
+ if (!data.FromDocument() || !data.user_visible) {
// Throw a permission denied error under the same circumstances.
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
@@ -365,12 +369,13 @@ void PushMessagingMessageFilter::Core::RegisterOnUI(
if (data.FromDocument()) {
push_service->RegisterFromDocument(
data.requesting_origin, data.service_worker_registration_id, sender_id,
- render_process_id_, data.render_frame_id, data.user_visible_only,
+ render_process_id_, data.render_frame_id, data.user_visible,
base::Bind(&Core::DidRegister, weak_factory_ui_to_ui_.GetWeakPtr(),
data));
} else {
push_service->RegisterFromWorker(
data.requesting_origin, data.service_worker_registration_id, sender_id,
+ data.user_visible,
base::Bind(&Core::DidRegister, weak_factory_ui_to_ui_.GetWeakPtr(),
data));
}
@@ -466,7 +471,7 @@ void PushMessagingMessageFilter::SendRegisterSuccess(
// -----------------------------------------------------------------------------
void PushMessagingMessageFilter::OnUnregister(
- int request_id, int64 service_worker_registration_id) {
+ int request_id, int64_t service_worker_registration_id) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
ServiceWorkerRegistration* service_worker_registration =
service_worker_context_->context()->GetLiveRegistration(
@@ -488,7 +493,7 @@ void PushMessagingMessageFilter::OnUnregister(
void PushMessagingMessageFilter::UnregisterHavingGottenPushRegistrationId(
int request_id,
- int64 service_worker_registration_id,
+ int64_t service_worker_registration_id,
const GURL& requesting_origin,
const std::string& push_registration_id, // Unused, we just want the status
ServiceWorkerStatusCode service_worker_status) {
@@ -516,7 +521,7 @@ void PushMessagingMessageFilter::UnregisterHavingGottenPushRegistrationId(
void PushMessagingMessageFilter::UnregisterHavingGottenSenderId(
int request_id,
- int64 service_worker_registration_id,
+ int64_t service_worker_registration_id,
const GURL& requesting_origin,
const std::string& sender_id,
ServiceWorkerStatusCode service_worker_status) {
@@ -563,7 +568,7 @@ void PushMessagingMessageFilter::UnregisterHavingGottenSenderId(
void PushMessagingMessageFilter::Core::UnregisterFromService(
int request_id,
- int64 service_worker_registration_id,
+ int64_t service_worker_registration_id,
const GURL& requesting_origin,
const std::string& sender_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
@@ -589,7 +594,7 @@ void PushMessagingMessageFilter::Core::UnregisterFromService(
void PushMessagingMessageFilter::Core::DidUnregisterFromService(
int request_id,
- int64 service_worker_registration_id,
+ int64_t service_worker_registration_id,
PushUnregistrationStatus unregistration_status) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
@@ -615,7 +620,7 @@ void PushMessagingMessageFilter::Core::DidUnregisterFromService(
void PushMessagingMessageFilter::ClearRegistrationData(
int request_id,
- int64 service_worker_registration_id,
+ int64_t service_worker_registration_id,
PushUnregistrationStatus unregistration_status) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
@@ -677,7 +682,7 @@ void PushMessagingMessageFilter::DidUnregister(
void PushMessagingMessageFilter::OnGetRegistration(
int request_id,
- int64 service_worker_registration_id) {
+ int64_t service_worker_registration_id) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// TODO(johnme): Validate arguments?
service_worker_context_->context()->storage()->GetUserData(
@@ -743,7 +748,8 @@ void PushMessagingMessageFilter::DidGetRegistration(
void PushMessagingMessageFilter::OnGetPermissionStatus(
int request_id,
- int64 service_worker_registration_id) {
+ int64_t service_worker_registration_id,
+ bool user_visible) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
ServiceWorkerRegistration* service_worker_registration =
service_worker_context_->context()->GetLiveRegistration(
@@ -758,19 +764,19 @@ void PushMessagingMessageFilter::OnGetPermissionStatus(
base::Bind(&Core::GetPermissionStatusOnUI,
base::Unretained(ui_core_.get()),
service_worker_registration->pattern().GetOrigin(),
- request_id));
+ user_visible, request_id));
}
void PushMessagingMessageFilter::Core::GetPermissionStatusOnUI(
- const GURL& requesting_origin,
- int request_id) {
+ const GURL& requesting_origin, bool user_visible, int request_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
blink::WebPushPermissionStatus permission_status;
PushMessagingService* push_service = service();
if (push_service) {
GURL embedding_origin = requesting_origin;
- permission_status =
- push_service->GetPermissionStatus(requesting_origin, embedding_origin);
+ permission_status = push_service->GetPermissionStatus(requesting_origin,
+ embedding_origin,
+ user_visible);
} else if (is_incognito()) {
// Return default, so the website can't detect incognito mode.
permission_status = blink::WebPushPermissionStatusDefault;
diff --git a/content/browser/push_messaging/push_messaging_message_filter.h b/content/browser/push_messaging/push_messaging_message_filter.h
index 3e12f4b..afd8d67 100644
--- a/content/browser/push_messaging/push_messaging_message_filter.h
+++ b/content/browser/push_messaging/push_messaging_message_filter.h
@@ -5,6 +5,7 @@
#ifndef CONTENT_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_MESSAGE_FILTER_H_
#define CONTENT_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_MESSAGE_FILTER_H_
+#include <stdint.h>
#include <string>
#include "base/memory/ref_counted.h"
@@ -49,11 +50,12 @@ class PushMessagingMessageFilter : public BrowserMessageFilter {
void OnRegisterFromDocument(int render_frame_id,
int request_id,
const std::string& sender_id,
- bool user_visible_only,
- int64 service_worker_registration_id);
+ bool user_visible,
+ int64_t service_worker_registration_id);
void OnRegisterFromWorker(int request_id,
- int64 service_worker_registration_id);
+ int64_t service_worker_registration_id,
+ bool user_visible);
void DidPersistSenderId(const RegisterData& data,
const std::string& sender_id,
@@ -94,25 +96,25 @@ class PushMessagingMessageFilter : public BrowserMessageFilter {
// Unregister methods on IO thread -------------------------------------------
- void OnUnregister(int request_id, int64 service_worker_registration_id);
+ void OnUnregister(int request_id, int64_t service_worker_registration_id);
void UnregisterHavingGottenPushRegistrationId(
int request_id,
- int64 service_worker_registration_id,
+ int64_t service_worker_registration_id,
const GURL& requesting_origin,
const std::string& push_registration_id,
ServiceWorkerStatusCode service_worker_status);
void UnregisterHavingGottenSenderId(
int request_id,
- int64 service_worker_registration_id,
+ int64_t service_worker_registration_id,
const GURL& requesting_origin,
const std::string& sender_id,
ServiceWorkerStatusCode service_worker_status);
// Called via PostTask from UI thread.
void ClearRegistrationData(int request_id,
- int64 service_worker_registration_id,
+ int64_t service_worker_registration_id,
PushUnregistrationStatus unregistration_status);
void DidClearRegistrationData(int request_id,
@@ -125,7 +127,8 @@ class PushMessagingMessageFilter : public BrowserMessageFilter {
// GetRegistration methods on IO thread --------------------------------------
- void OnGetRegistration(int request_id, int64 service_worker_registration_id);
+ void OnGetRegistration(int request_id,
+ int64_t service_worker_registration_id);
void DidGetRegistration(int request_id,
const std::string& push_registration_id,
@@ -134,7 +137,8 @@ class PushMessagingMessageFilter : public BrowserMessageFilter {
// GetPermission methods on IO thread ----------------------------------------
void OnGetPermissionStatus(int request_id,
- int64 service_worker_registration_id);
+ int64_t service_worker_registration_id,
+ bool user_visible);
// Helper methods on IO thread -----------------------------------------------
diff --git a/content/child/push_messaging/push_provider.cc b/content/child/push_messaging/push_provider.cc
index 48ff9b5..23033b5 100644
--- a/content/child/push_messaging/push_provider.cc
+++ b/content/child/push_messaging/push_provider.cc
@@ -14,7 +14,8 @@
#include "content/child/worker_task_runner.h"
#include "content/common/push_messaging_messages.h"
#include "third_party/WebKit/public/platform/WebString.h"
-#include "third_party/WebKit/public/platform/modules/push_messaging/WebPushRegistration.h"
+#include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubscription.h"
+#include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubscriptionOptions.h"
namespace content {
namespace {
@@ -64,27 +65,36 @@ void PushProvider::OnWorkerRunLoopStopped() {
delete this;
}
-void PushProvider::registerPushMessaging(
+void PushProvider::subscribe(
blink::WebServiceWorkerRegistration* service_worker_registration,
- blink::WebPushRegistrationCallbacks* callbacks) {
+ const blink::WebPushSubscriptionOptions& options,
+ blink::WebPushSubscriptionCallbacks* callbacks) {
DCHECK(service_worker_registration);
DCHECK(callbacks);
int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId());
- registration_callbacks_.AddWithID(callbacks, request_id);
+ subscription_callbacks_.AddWithID(callbacks, request_id);
int64 service_worker_registration_id =
GetServiceWorkerRegistrationId(service_worker_registration);
thread_safe_sender_->Send(new PushMessagingHostMsg_RegisterFromWorker(
- request_id, service_worker_registration_id));
+ request_id, service_worker_registration_id, options.userVisible));
}
-void PushProvider::unregister(
+void PushProvider::registerPushMessaging(
blink::WebServiceWorkerRegistration* service_worker_registration,
- blink::WebPushUnregisterCallbacks* callbacks) {
+ blink::WebPushSubscriptionCallbacks* callbacks) {
+ subscribe(service_worker_registration,
+ blink::WebPushSubscriptionOptions(),
+ callbacks);
+}
+
+void PushProvider::unsubscribe(
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ blink::WebPushUnsubscribeCallbacks* callbacks) {
DCHECK(service_worker_registration);
DCHECK(callbacks);
int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId());
- unregister_callbacks_.AddWithID(callbacks, request_id);
+ unsubscribe_callbacks_.AddWithID(callbacks, request_id);
int64 service_worker_registration_id =
GetServiceWorkerRegistrationId(service_worker_registration);
@@ -92,21 +102,34 @@ void PushProvider::unregister(
request_id, service_worker_registration_id));
}
-void PushProvider::getRegistration(
+void PushProvider::unregister(
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ blink::WebPushUnsubscribeCallbacks* callbacks) {
+ unsubscribe(service_worker_registration, callbacks);
+}
+
+void PushProvider::getSubscription(
blink::WebServiceWorkerRegistration* service_worker_registration,
- blink::WebPushRegistrationCallbacks* callbacks) {
+ blink::WebPushSubscriptionCallbacks* callbacks) {
DCHECK(service_worker_registration);
DCHECK(callbacks);
int request_id = push_dispatcher_->GenerateRequestId(CurrentWorkerId());
- registration_callbacks_.AddWithID(callbacks, request_id);
+ subscription_callbacks_.AddWithID(callbacks, request_id);
int64 service_worker_registration_id =
GetServiceWorkerRegistrationId(service_worker_registration);
thread_safe_sender_->Send(new PushMessagingHostMsg_GetRegistration(
request_id, service_worker_registration_id));
}
+void PushProvider::getRegistration(
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ blink::WebPushSubscriptionCallbacks* callbacks) {
+ getSubscription(service_worker_registration, callbacks);
+}
+
void PushProvider::getPermissionStatus(
blink::WebServiceWorkerRegistration* service_worker_registration,
+ const blink::WebPushSubscriptionOptions& options,
blink::WebPushPermissionStatusCallbacks* callbacks) {
DCHECK(service_worker_registration);
DCHECK(callbacks);
@@ -115,7 +138,15 @@ void PushProvider::getPermissionStatus(
int64 service_worker_registration_id =
GetServiceWorkerRegistrationId(service_worker_registration);
thread_safe_sender_->Send(new PushMessagingHostMsg_GetPermissionStatus(
- request_id, service_worker_registration_id));
+ request_id, service_worker_registration_id, options.userVisible));
+}
+
+void PushProvider::getPermissionStatus(
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ blink::WebPushPermissionStatusCallbacks* callbacks) {
+ getPermissionStatus(service_worker_registration,
+ blink::WebPushSubscriptionOptions(),
+ callbacks);
}
bool PushProvider::OnMessageReceived(const IPC::Message& message) {
@@ -147,24 +178,24 @@ void PushProvider::OnRegisterFromWorkerSuccess(
int request_id,
const GURL& endpoint,
const std::string& registration_id) {
- blink::WebPushRegistrationCallbacks* callbacks =
- registration_callbacks_.Lookup(request_id);
+ blink::WebPushSubscriptionCallbacks* callbacks =
+ subscription_callbacks_.Lookup(request_id);
if (!callbacks)
return;
- scoped_ptr<blink::WebPushRegistration> registration(
- new blink::WebPushRegistration(
+ scoped_ptr<blink::WebPushSubscription> subscription(
+ new blink::WebPushSubscription(
blink::WebString::fromUTF8(endpoint.spec()),
blink::WebString::fromUTF8(registration_id)));
- callbacks->onSuccess(registration.release());
+ callbacks->onSuccess(subscription.release());
- registration_callbacks_.Remove(request_id);
+ subscription_callbacks_.Remove(request_id);
}
void PushProvider::OnRegisterFromWorkerError(int request_id,
PushRegistrationStatus status) {
- blink::WebPushRegistrationCallbacks* callbacks =
- registration_callbacks_.Lookup(request_id);
+ blink::WebPushSubscriptionCallbacks* callbacks =
+ subscription_callbacks_.Lookup(request_id);
if (!callbacks)
return;
@@ -173,26 +204,26 @@ void PushProvider::OnRegisterFromWorkerError(int request_id,
blink::WebString::fromUTF8(PushRegistrationStatusToString(status))));
callbacks->onError(error.release());
- registration_callbacks_.Remove(request_id);
+ subscription_callbacks_.Remove(request_id);
}
void PushProvider::OnUnregisterSuccess(int request_id, bool did_unregister) {
- blink::WebPushUnregisterCallbacks* callbacks =
- unregister_callbacks_.Lookup(request_id);
+ blink::WebPushUnsubscribeCallbacks* callbacks =
+ unsubscribe_callbacks_.Lookup(request_id);
if (!callbacks)
return;
callbacks->onSuccess(&did_unregister);
- unregister_callbacks_.Remove(request_id);
+ unsubscribe_callbacks_.Remove(request_id);
}
void PushProvider::OnUnregisterError(
int request_id,
blink::WebPushError::ErrorType error_type,
const std::string& error_message) {
- blink::WebPushUnregisterCallbacks* callbacks =
- unregister_callbacks_.Lookup(request_id);
+ blink::WebPushUnsubscribeCallbacks* callbacks =
+ unsubscribe_callbacks_.Lookup(request_id);
if (!callbacks)
return;
@@ -200,39 +231,39 @@ void PushProvider::OnUnregisterError(
error_type, blink::WebString::fromUTF8(error_message)));
callbacks->onError(error.release());
- unregister_callbacks_.Remove(request_id);
+ unsubscribe_callbacks_.Remove(request_id);
}
void PushProvider::OnGetRegistrationSuccess(
int request_id,
const GURL& endpoint,
const std::string& registration_id) {
- blink::WebPushRegistrationCallbacks* callbacks =
- registration_callbacks_.Lookup(request_id);
+ blink::WebPushSubscriptionCallbacks* callbacks =
+ subscription_callbacks_.Lookup(request_id);
if (!callbacks)
return;
- scoped_ptr<blink::WebPushRegistration> registration(
- new blink::WebPushRegistration(
+ scoped_ptr<blink::WebPushSubscription> subscription(
+ new blink::WebPushSubscription(
blink::WebString::fromUTF8(endpoint.spec()),
blink::WebString::fromUTF8(registration_id)));
- callbacks->onSuccess(registration.release());
+ callbacks->onSuccess(subscription.release());
- registration_callbacks_.Remove(request_id);
+ subscription_callbacks_.Remove(request_id);
}
void PushProvider::OnGetRegistrationError(
int request_id,
PushGetRegistrationStatus status) {
- blink::WebPushRegistrationCallbacks* callbacks =
- registration_callbacks_.Lookup(request_id);
+ blink::WebPushSubscriptionCallbacks* callbacks =
+ subscription_callbacks_.Lookup(request_id);
if (!callbacks)
return;
// We are only expecting an error if we can't find a registration.
callbacks->onSuccess(nullptr);
- registration_callbacks_.Remove(request_id);
+ subscription_callbacks_.Remove(request_id);
}
void PushProvider::OnGetPermissionStatusSuccess(
diff --git a/content/child/push_messaging/push_provider.h b/content/child/push_messaging/push_provider.h
index 29049f7..39cb2e0 100644
--- a/content/child/push_messaging/push_provider.h
+++ b/content/child/push_messaging/push_provider.h
@@ -17,6 +17,10 @@
class GURL;
+namespace blink {
+struct WebPushSubscriptionOptions;
+}
+
namespace content {
class ThreadSafeSender;
@@ -36,14 +40,36 @@ class PushProvider : public blink::WebPushProvider,
void OnWorkerRunLoopStopped() override;
// blink::WebPushProvider implementation.
- virtual void registerPushMessaging(blink::WebServiceWorkerRegistration*,
- blink::WebPushRegistrationCallbacks*);
- virtual void unregister(blink::WebServiceWorkerRegistration*,
- blink::WebPushUnregisterCallbacks*);
- virtual void getRegistration(blink::WebServiceWorkerRegistration*,
- blink::WebPushRegistrationCallbacks*);
- virtual void getPermissionStatus(blink::WebServiceWorkerRegistration*,
- blink::WebPushPermissionStatusCallbacks*);
+ virtual void subscribe(
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ const blink::WebPushSubscriptionOptions& options,
+ blink::WebPushSubscriptionCallbacks* callbacks);
+ // TODO(peter): Remove this method when Blink switched over to the above.
+ virtual void registerPushMessaging(
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ blink::WebPushSubscriptionCallbacks* callbacks);
+ virtual void unsubscribe(
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ blink::WebPushUnsubscribeCallbacks* callbacks);
+ // TODO(peter): Remove this method when Blink switched over to the above.
+ virtual void unregister(
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ blink::WebPushUnsubscribeCallbacks* callbacks);
+ virtual void getSubscription(
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ blink::WebPushSubscriptionCallbacks* callbacks);
+ // TODO(peter): Remove this method when Blink switched over to the above.
+ virtual void getRegistration(
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ blink::WebPushSubscriptionCallbacks* callbacks);
+ virtual void getPermissionStatus(
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ const blink::WebPushSubscriptionOptions& options,
+ blink::WebPushPermissionStatusCallbacks* callbacks);
+ // TODO(peter): Remove this method when Blink switched over to the above.
+ virtual void getPermissionStatus(
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ blink::WebPushPermissionStatusCallbacks* callbacks);
// Called by the PushDispatcher.
bool OnMessageReceived(const IPC::Message& message);
@@ -72,20 +98,20 @@ class PushProvider : public blink::WebPushProvider,
scoped_refptr<ThreadSafeSender> thread_safe_sender_;
scoped_refptr<PushDispatcher> push_dispatcher_;
- // Stores the registration callbacks with their request ids. This class owns
+ // Stores the subscription callbacks with their request ids. This class owns
// the callbacks.
- IDMap<blink::WebPushRegistrationCallbacks, IDMapOwnPointer>
- registration_callbacks_;
+ IDMap<blink::WebPushSubscriptionCallbacks, IDMapOwnPointer>
+ subscription_callbacks_;
// Stores the permission status callbacks with their request ids. This class
// owns the callbacks.
IDMap<blink::WebPushPermissionStatusCallbacks, IDMapOwnPointer>
permission_status_callbacks_;
- // Stores the unregistration callbacks with their request ids. This class owns
+ // Stores the unsubscription callbacks with their request ids. This class owns
// the callbacks.
- IDMap<blink::WebPushUnregisterCallbacks, IDMapOwnPointer>
- unregister_callbacks_;
+ IDMap<blink::WebPushUnsubscribeCallbacks, IDMapOwnPointer>
+ unsubscribe_callbacks_;
DISALLOW_COPY_AND_ASSIGN(PushProvider);
};
diff --git a/content/common/push_messaging_messages.h b/content/common/push_messaging_messages.h
index 2acf204..73c11fe 100644
--- a/content/common/push_messaging_messages.h
+++ b/content/common/push_messaging_messages.h
@@ -5,6 +5,8 @@
// IPC messages for push messaging.
// Multiply-included message file, hence no include guard.
+#include <stdint.h>
+
#include "content/public/common/push_messaging_status.h"
#include "ipc/ipc_message_macros.h"
#include "third_party/WebKit/public/platform/modules/push_messaging/WebPushError.h"
@@ -30,69 +32,71 @@ IPC_ENUM_TRAITS_MAX_VALUE(
// Messages sent from the browser to the child process.
IPC_MESSAGE_ROUTED3(PushMessagingMsg_RegisterFromDocumentSuccess,
- int32 /* request_id */,
+ int32_t /* request_id */,
GURL /* push_endpoint */,
std::string /* push_registration_id */)
IPC_MESSAGE_CONTROL3(PushMessagingMsg_RegisterFromWorkerSuccess,
- int32 /* request_id */,
+ int32_t /* request_id */,
GURL /* push_endpoint */,
std::string /* push_registration_id */)
IPC_MESSAGE_ROUTED2(PushMessagingMsg_RegisterFromDocumentError,
- int32 /* request_id */,
+ int32_t /* request_id */,
content::PushRegistrationStatus /* status */)
IPC_MESSAGE_CONTROL2(PushMessagingMsg_RegisterFromWorkerError,
- int32 /* request_id */,
+ int32_t /* request_id */,
content::PushRegistrationStatus /* status */)
IPC_MESSAGE_CONTROL2(PushMessagingMsg_UnregisterSuccess,
- int32 /* request_id */,
+ int32_t /* request_id */,
bool /* did_unregister */)
IPC_MESSAGE_CONTROL3(PushMessagingMsg_UnregisterError,
- int32 /* request_id */,
+ int32_t /* request_id */,
blink::WebPushError::ErrorType /* error_type */,
std::string /* error_message */)
IPC_MESSAGE_CONTROL3(PushMessagingMsg_GetRegistrationSuccess,
- int32 /* request_id */,
+ int32_t /* request_id */,
GURL /* push_endpoint */,
std::string /* push_registration_id */)
IPC_MESSAGE_CONTROL2(PushMessagingMsg_GetRegistrationError,
- int32 /* request_id */,
+ int32_t /* request_id */,
content::PushGetRegistrationStatus /* status */)
IPC_MESSAGE_CONTROL2(PushMessagingMsg_GetPermissionStatusSuccess,
- int32 /* request_id */,
+ int32_t /* request_id */,
blink::WebPushPermissionStatus /* status */)
IPC_MESSAGE_CONTROL1(PushMessagingMsg_GetPermissionStatusError,
- int32 /* request_id */)
+ int32_t /* request_id */)
// Messages sent from the child process to the browser.
IPC_MESSAGE_CONTROL5(PushMessagingHostMsg_RegisterFromDocument,
- int32 /* render_frame_id */,
- int32 /* request_id */,
+ int32_t /* render_frame_id */,
+ int32_t /* request_id */,
std::string /* sender_id */,
- bool /* user_visible_only */,
- int64 /* service_worker_registration_id */)
+ bool /* user_visible */,
+ int64_t /* service_worker_registration_id */)
-IPC_MESSAGE_CONTROL2(PushMessagingHostMsg_RegisterFromWorker,
- int32 /* request_id */,
- int64 /* service_worker_registration_id */)
+IPC_MESSAGE_CONTROL3(PushMessagingHostMsg_RegisterFromWorker,
+ int32_t /* request_id */,
+ int64_t /* service_worker_registration_id */,
+ bool /* user_visible */)
IPC_MESSAGE_CONTROL2(PushMessagingHostMsg_Unregister,
- int32 /* request_id */,
- int64 /* service_worker_registration_id */)
+ int32_t /* request_id */,
+ int64_t /* service_worker_registration_id */)
IPC_MESSAGE_CONTROL2(PushMessagingHostMsg_GetRegistration,
- int32 /* request_id */,
- int64 /* service_worker_registration_id */)
+ int32_t /* request_id */,
+ int64_t /* service_worker_registration_id */)
-IPC_MESSAGE_CONTROL2(PushMessagingHostMsg_GetPermissionStatus,
- int32 /* request_id */,
- int64 /* service_worker_registration_id */)
+IPC_MESSAGE_CONTROL3(PushMessagingHostMsg_GetPermissionStatus,
+ int32_t /* request_id */,
+ int64_t /* service_worker_registration_id */,
+ bool /* user_visible */)
diff --git a/content/public/browser/push_messaging_service.h b/content/public/browser/push_messaging_service.h
index 8464e5c..c1a6f1c 100644
--- a/content/public/browser/push_messaging_service.h
+++ b/content/public/browser/push_messaging_service.h
@@ -48,7 +48,7 @@ class CONTENT_EXPORT PushMessagingService {
const std::string& sender_id,
int renderer_id,
int render_frame_id,
- bool user_visible_only,
+ bool user_visible,
const RegisterCallback& callback) = 0;
// Register the given |sender_id| with the push messaging service. The frame
@@ -57,6 +57,7 @@ class CONTENT_EXPORT PushMessagingService {
virtual void RegisterFromWorker(const GURL& requesting_origin,
int64 service_worker_registration_id,
const std::string& sender_id,
+ bool user_visible,
const RegisterCallback& callback) = 0;
// Unregister the given |sender_id| from the push messaging service. The
@@ -69,10 +70,12 @@ class CONTENT_EXPORT PushMessagingService {
// Checks the permission status for the requesting origin. Permission is only
// ever granted when the requesting origin matches the top level embedding
- // origin.
+ // origin. The |user_visible| boolean indicates whether the permission status
+ // only has to cover push messages resulting in visible effects to the user.
virtual blink::WebPushPermissionStatus GetPermissionStatus(
const GURL& requesting_origin,
- const GURL& embedding_origin) = 0;
+ const GURL& embedding_origin,
+ bool user_visible) = 0;
protected:
// Provide a storage mechanism to read/write an opaque
diff --git a/content/renderer/push_messaging/push_messaging_dispatcher.cc b/content/renderer/push_messaging/push_messaging_dispatcher.cc
index 6ad41f6..db8ef19 100644
--- a/content/renderer/push_messaging/push_messaging_dispatcher.cc
+++ b/content/renderer/push_messaging/push_messaging_dispatcher.cc
@@ -13,7 +13,8 @@
#include "third_party/WebKit/public/platform/WebServiceWorkerRegistration.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/modules/push_messaging/WebPushError.h"
-#include "third_party/WebKit/public/platform/modules/push_messaging/WebPushRegistration.h"
+#include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubscription.h"
+#include "third_party/WebKit/public/platform/modules/push_messaging/WebPushSubscriptionOptions.h"
#include "url/gurl.h"
using blink::WebString;
@@ -38,24 +39,36 @@ bool PushMessagingDispatcher::OnMessageReceived(const IPC::Message& message) {
return handled;
}
-void PushMessagingDispatcher::registerPushMessaging(
+void PushMessagingDispatcher::subscribe(
blink::WebServiceWorkerRegistration* service_worker_registration,
- blink::WebPushRegistrationCallbacks* callbacks) {
+ const blink::WebPushSubscriptionOptions& options,
+ blink::WebPushSubscriptionCallbacks* callbacks) {
DCHECK(service_worker_registration);
DCHECK(callbacks);
RenderFrameImpl::FromRoutingID(routing_id())
->manifest_manager()
->GetManifest(base::Bind(&PushMessagingDispatcher::DoRegister,
base::Unretained(this),
- service_worker_registration, callbacks));
+ service_worker_registration,
+ options,
+ callbacks));
+}
+
+void PushMessagingDispatcher::registerPushMessaging(
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ blink::WebPushSubscriptionCallbacks* callbacks) {
+ subscribe(service_worker_registration,
+ blink::WebPushSubscriptionOptions(),
+ callbacks);
}
void PushMessagingDispatcher::DoRegister(
blink::WebServiceWorkerRegistration* service_worker_registration,
- blink::WebPushRegistrationCallbacks* callbacks,
+ const blink::WebPushSubscriptionOptions& options,
+ blink::WebPushSubscriptionCallbacks* callbacks,
const Manifest& manifest) {
- int request_id = registration_callbacks_.Add(callbacks);
- int64 service_worker_registration_id =
+ int request_id = subscription_callbacks_.Add(callbacks);
+ int64_t service_worker_registration_id =
static_cast<WebServiceWorkerRegistrationImpl*>(
service_worker_registration)->registration_id();
@@ -69,42 +82,49 @@ void PushMessagingDispatcher::DoRegister(
return;
}
+ // TODO(peter): Display a deprecation warning if gcm_user_visible_only is
+ // set to true. See https://crbug.com/471534
+ const bool user_visible = manifest.gcm_user_visible_only ||
+ options.userVisible;
+
Send(new PushMessagingHostMsg_RegisterFromDocument(
routing_id(), request_id,
manifest.gcm_sender_id.is_null()
? std::string()
: base::UTF16ToUTF8(manifest.gcm_sender_id.string()),
- manifest.gcm_user_visible_only, service_worker_registration_id));
+ user_visible, service_worker_registration_id));
}
void PushMessagingDispatcher::OnRegisterFromDocumentSuccess(
- int32 request_id,
+ int32_t request_id,
const GURL& endpoint,
const std::string& registration_id) {
- blink::WebPushRegistrationCallbacks* callbacks =
- registration_callbacks_.Lookup(request_id);
+ blink::WebPushSubscriptionCallbacks* callbacks =
+ subscription_callbacks_.Lookup(request_id);
DCHECK(callbacks);
- scoped_ptr<blink::WebPushRegistration> registration(
- new blink::WebPushRegistration(
+ scoped_ptr<blink::WebPushSubscription> subscription(
+ new blink::WebPushSubscription(
WebString::fromUTF8(endpoint.spec()),
WebString::fromUTF8(registration_id)));
- callbacks->onSuccess(registration.release());
- registration_callbacks_.Remove(request_id);
+ callbacks->onSuccess(subscription.release());
+
+ subscription_callbacks_.Remove(request_id);
}
void PushMessagingDispatcher::OnRegisterFromDocumentError(
- int32 request_id,
+ int32_t request_id,
PushRegistrationStatus status) {
- blink::WebPushRegistrationCallbacks* callbacks =
- registration_callbacks_.Lookup(request_id);
+ blink::WebPushSubscriptionCallbacks* callbacks =
+ subscription_callbacks_.Lookup(request_id);
DCHECK(callbacks);
scoped_ptr<blink::WebPushError> error(new blink::WebPushError(
blink::WebPushError::ErrorTypeAbort,
WebString::fromUTF8(PushRegistrationStatusToString(status))));
callbacks->onError(error.release());
- registration_callbacks_.Remove(request_id);
+
+ subscription_callbacks_.Remove(request_id);
}
} // namespace content
diff --git a/content/renderer/push_messaging/push_messaging_dispatcher.h b/content/renderer/push_messaging/push_messaging_dispatcher.h
index 06fc371..da548db 100644
--- a/content/renderer/push_messaging/push_messaging_dispatcher.h
+++ b/content/renderer/push_messaging/push_messaging_dispatcher.h
@@ -5,6 +5,7 @@
#ifndef CONTENT_RENDERER_PUSH_MESSAGING_PUSH_MESSAGING_DISPATCHER_H_
#define CONTENT_RENDERER_PUSH_MESSAGING_PUSH_MESSAGING_DISPATCHER_H_
+#include <stdint.h>
#include <string>
#include "base/id_map.h"
@@ -15,6 +16,10 @@
class GURL;
+namespace blink {
+struct WebPushSubscriptionOptions;
+}
+
namespace IPC {
class Message;
} // namespace IPC
@@ -34,24 +39,30 @@ class PushMessagingDispatcher : public RenderFrameObserver,
bool OnMessageReceived(const IPC::Message& message) override;
// WebPushClient implementation.
+ virtual void subscribe(
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ const blink::WebPushSubscriptionOptions& options,
+ blink::WebPushSubscriptionCallbacks* callbacks);
+ // TODO(peter): Remove this method when Blink switched over to the above.
virtual void registerPushMessaging(
blink::WebServiceWorkerRegistration* service_worker_registration,
- blink::WebPushRegistrationCallbacks* callbacks); // override
+ blink::WebPushSubscriptionCallbacks* callbacks); // override
void DoRegister(
blink::WebServiceWorkerRegistration* service_worker_registration,
- blink::WebPushRegistrationCallbacks* callbacks,
+ const blink::WebPushSubscriptionOptions& options,
+ blink::WebPushSubscriptionCallbacks* callbacks,
const Manifest& manifest);
- void OnRegisterFromDocumentSuccess(int32 request_id,
+ void OnRegisterFromDocumentSuccess(int32_t request_id,
const GURL& endpoint,
const std::string& registration_id);
- void OnRegisterFromDocumentError(int32 request_id,
+ void OnRegisterFromDocumentError(int32_t request_id,
PushRegistrationStatus status);
- IDMap<blink::WebPushRegistrationCallbacks, IDMapOwnPointer>
- registration_callbacks_;
+ IDMap<blink::WebPushSubscriptionCallbacks, IDMapOwnPointer>
+ subscription_callbacks_;
DISALLOW_COPY_AND_ASSIGN(PushMessagingDispatcher);
};
diff --git a/content/shell/browser/layout_test/layout_test_push_messaging_service.cc b/content/shell/browser/layout_test/layout_test_push_messaging_service.cc
index 58890f5..85c0932 100644
--- a/content/shell/browser/layout_test/layout_test_push_messaging_service.cc
+++ b/content/shell/browser/layout_test/layout_test_push_messaging_service.cc
@@ -35,18 +35,19 @@ void LayoutTestPushMessagingService::RegisterFromDocument(
const std::string& sender_id,
int renderer_id,
int render_frame_id,
- bool user_gesture,
+ bool user_visible,
const PushMessagingService::RegisterCallback& callback) {
RegisterFromWorker(requesting_origin, service_worker_registration_id,
- sender_id, callback);
+ sender_id, user_visible, callback);
}
void LayoutTestPushMessagingService::RegisterFromWorker(
const GURL& requesting_origin,
int64 service_worker_registration_id,
const std::string& sender_id,
+ bool user_visible,
const PushMessagingService::RegisterCallback& callback) {
- if (GetPermissionStatus(requesting_origin, requesting_origin) ==
+ if (GetPermissionStatus(requesting_origin, requesting_origin, user_visible) ==
blink::WebPushPermissionStatusGranted) {
callback.Run("layoutTestRegistrationId",
PUSH_REGISTRATION_STATUS_SUCCESS_FROM_PUSH_SERVICE);
@@ -58,7 +59,8 @@ void LayoutTestPushMessagingService::RegisterFromWorker(
blink::WebPushPermissionStatus
LayoutTestPushMessagingService::GetPermissionStatus(
const GURL& requesting_origin,
- const GURL& embedding_origin) {
+ const GURL& embedding_origin,
+ bool user_visible) {
const auto& it = permission_map_.find(requesting_origin);
if (it == permission_map_.end())
return blink::WebPushPermissionStatusDefault;
diff --git a/content/shell/browser/layout_test/layout_test_push_messaging_service.h b/content/shell/browser/layout_test/layout_test_push_messaging_service.h
index 773c0b2..2fac0b0 100644
--- a/content/shell/browser/layout_test/layout_test_push_messaging_service.h
+++ b/content/shell/browser/layout_test/layout_test_push_messaging_service.h
@@ -30,16 +30,18 @@ class LayoutTestPushMessagingService : public PushMessagingService {
const std::string& sender_id,
int renderer_id,
int render_frame_id,
- bool user_gesture,
+ bool user_visible,
const PushMessagingService::RegisterCallback& callback) override;
void RegisterFromWorker(
const GURL& requesting_origin,
int64 service_worker_registration_id,
const std::string& sender_id,
+ bool user_visible,
const PushMessagingService::RegisterCallback& callback) override;
blink::WebPushPermissionStatus GetPermissionStatus(
const GURL& requesting_origin,
- const GURL& embedding_origin) override;
+ const GURL& embedding_origin,
+ bool user_visible) override;
void Unregister(const GURL& requesting_origin,
int64 service_worker_registration_id,
const std::string& sender_id,