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

Unified Diff: chrome/browser/push_messaging/push_messaging_service_impl.cc

Issue 1701313002: Partial implementation of subscription restrictions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added testing and integrated previous comments. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/push_messaging/push_messaging_service_impl.cc
diff --git a/chrome/browser/push_messaging/push_messaging_service_impl.cc b/chrome/browser/push_messaging/push_messaging_service_impl.cc
index b8725fc67189a4ed51fd419acbae9a2008eb4523..fdf792b78cfccc102f7d3a201730c93a8d1a344e 100644
--- a/chrome/browser/push_messaging/push_messaging_service_impl.cc
+++ b/chrome/browser/push_messaging/push_messaging_service_impl.cc
@@ -43,6 +43,7 @@
#include "content/public/common/child_process_host.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/push_messaging_status.h"
+#include "content/public/common/push_subscription_options.h"
#include "ui/base/l10n/l10n_util.h"
#if defined(ENABLE_BACKGROUND)
@@ -343,10 +344,9 @@ GURL PushMessagingServiceImpl::GetPushEndpoint() {
void PushMessagingServiceImpl::SubscribeFromDocument(
const GURL& requesting_origin,
int64_t service_worker_registration_id,
- const std::string& sender_id,
int renderer_id,
int render_frame_id,
- bool user_visible,
+ const content::PushSubscriptionOptions& options,
const content::PushMessagingService::RegisterCallback& callback) {
PushMessagingAppIdentifier app_identifier =
PushMessagingAppIdentifier::Generate(requesting_origin,
@@ -366,7 +366,7 @@ void PushMessagingServiceImpl::SubscribeFromDocument(
if (!web_contents)
return;
- if (!user_visible) {
+ if (!options.user_visible_only) {
web_contents->GetMainFrame()->AddMessageToConsole(
content::CONSOLE_MESSAGE_LEVEL_ERROR, kSilentPushUnsupportedMessage);
@@ -375,20 +375,21 @@ void PushMessagingServiceImpl::SubscribeFromDocument(
return;
}
+ // TODO(harkness) Check the validity of the options.sender_info field.
+
// Push does not allow permission requests from iframes.
profile_->GetPermissionManager()->RequestPermission(
content::PermissionType::PUSH_MESSAGING, web_contents->GetMainFrame(),
requesting_origin, true /* user_gesture */,
base::Bind(&PushMessagingServiceImpl::DidRequestPermission,
- weak_factory_.GetWeakPtr(), app_identifier, sender_id,
+ weak_factory_.GetWeakPtr(), app_identifier, options,
callback));
}
void PushMessagingServiceImpl::SubscribeFromWorker(
const GURL& requesting_origin,
int64_t service_worker_registration_id,
- const std::string& sender_id,
- bool user_visible,
+ const content::PushSubscriptionOptions& options,
const content::PushMessagingService::RegisterCallback& register_callback) {
PushMessagingAppIdentifier app_identifier =
PushMessagingAppIdentifier::Generate(requesting_origin,
@@ -404,7 +405,7 @@ void PushMessagingServiceImpl::SubscribeFromWorker(
GURL embedding_origin = requesting_origin;
blink::WebPushPermissionStatus permission_status =
PushMessagingServiceImpl::GetPermissionStatus(
- requesting_origin, embedding_origin, user_visible);
+ requesting_origin, embedding_origin, options.user_visible_only);
if (permission_status != blink::WebPushPermissionStatusGranted) {
SubscribeEndWithError(register_callback,
content::PUSH_REGISTRATION_STATUS_PERMISSION_DENIED);
@@ -412,7 +413,7 @@ void PushMessagingServiceImpl::SubscribeFromWorker(
}
IncreasePushSubscriptionCount(1, true /* is_pending */);
- std::vector<std::string> sender_ids(1, sender_id);
+ std::vector<std::string> sender_ids(1, options.sender_info);
GetGCMDriver()->Register(app_identifier.app_id(), sender_ids,
base::Bind(&PushMessagingServiceImpl::DidSubscribe,
weak_factory_.GetWeakPtr(),
@@ -522,7 +523,7 @@ void PushMessagingServiceImpl::DidSubscribeWithEncryptionInfo(
void PushMessagingServiceImpl::DidRequestPermission(
const PushMessagingAppIdentifier& app_identifier,
- const std::string& sender_id,
+ const content::PushSubscriptionOptions& options,
const content::PushMessagingService::RegisterCallback& register_callback,
content::PermissionStatus permission_status) {
if (permission_status != content::PermissionStatus::GRANTED) {
@@ -532,7 +533,7 @@ void PushMessagingServiceImpl::DidRequestPermission(
}
IncreasePushSubscriptionCount(1, true /* is_pending */);
- std::vector<std::string> sender_ids(1, sender_id);
+ std::vector<std::string> sender_ids(1, options.sender_info);
GetGCMDriver()->Register(app_identifier.app_id(), sender_ids,
base::Bind(&PushMessagingServiceImpl::DidSubscribe,
weak_factory_.GetWeakPtr(),

Powered by Google App Engine
This is Rietveld 408576698