#include "content/browser/push_messaging/push_messaging_manager.h"
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
#include "content/browser/bad_message.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/permissions/permission_controller_impl.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/service_worker/service_worker_context_core.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_host.h"
#include "content/public/browser/permission_controller.h"
#include "content/public/browser/permission_request_description.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/content_switches.h"
#include "third_party/blink/public/common/permissions/permission_utils.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/devtools/console_message.mojom.h"
#include "third_party/blink/public/mojom/push_messaging/push_messaging.mojom.h"
#include "third_party/blink/public/mojom/push_messaging/push_messaging_status.mojom.h"
#include "url/origin.h"
namespace content {
const char kPushSenderIdServiceWorkerKey[] = …;
const char kPushRegistrationIdServiceWorkerKey[] = …;
namespace {
const char kIncognitoPushUnsupportedMessage[] = …;
void RecordRegistrationStatus(blink::mojom::PushRegistrationStatus status) { … }
void RecordUnregistrationStatus(blink::mojom::PushUnregistrationStatus status) { … }
void RecordGetRegistrationStatus(
blink::mojom::PushGetRegistrationStatus status) { … }
const char* PushUnregistrationStatusToString(
blink::mojom::PushUnregistrationStatus status) { … }
std::string FixSenderInfo(const std::string& application_server_key,
const std::string& stored_sender_id) { … }
bool IsRequestFromDocument(int render_frame_id) { … }
}
struct PushMessagingManager::RegisterData { … };
PushMessagingManager::PushMessagingManager(
RenderProcessHost& render_process_host,
int render_frame_id,
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context)
: … { … }
PushMessagingManager::~PushMessagingManager() { … }
void PushMessagingManager::AddPushMessagingReceiver(
mojo::PendingReceiver<blink::mojom::PushMessaging> receiver) { … }
void PushMessagingManager::Subscribe(
int64_t service_worker_registration_id,
blink::mojom::PushSubscriptionOptionsPtr options,
bool user_gesture,
SubscribeCallback callback) { … }
void PushMessagingManager::DidCheckForExistingRegistration(
RegisterData data,
const std::vector<std::string>& subscription_id_and_sender_id,
blink::ServiceWorkerStatusCode service_worker_status) { … }
void PushMessagingManager::DidGetSenderIdFromStorage(
RegisterData data,
const std::vector<std::string>& stored_sender_id,
blink::ServiceWorkerStatusCode service_worker_status) { … }
void PushMessagingManager::Register(PushMessagingManager::RegisterData data) { … }
void PushMessagingManager::DidRequestPermissionInIncognito(
RegisterData data,
blink::mojom::PermissionStatus status) { … }
void PushMessagingManager::DidRegister(
RegisterData data,
const std::string& push_subscription_id,
const GURL& endpoint,
const std::optional<base::Time>& expiration_time,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth,
blink::mojom::PushRegistrationStatus status) { … }
void PushMessagingManager::PersistRegistration(
RegisterData data,
const std::string& push_subscription_id,
const GURL& endpoint,
const std::optional<base::Time>& expiration_time,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth,
blink::mojom::PushRegistrationStatus status) { … }
void PushMessagingManager::DidPersistRegistration(
RegisterData data,
const GURL& endpoint,
const std::optional<base::Time>& expiration_time,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth,
blink::mojom::PushRegistrationStatus push_registration_status,
blink::ServiceWorkerStatusCode service_worker_status) { … }
void PushMessagingManager::SendSubscriptionError(
RegisterData data,
blink::mojom::PushRegistrationStatus status) { … }
void PushMessagingManager::SendSubscriptionSuccess(
RegisterData data,
blink::mojom::PushRegistrationStatus status,
const GURL& endpoint,
const std::optional<base::Time>& expiration_time,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth) { … }
void PushMessagingManager::Unsubscribe(int64_t service_worker_registration_id,
UnsubscribeCallback callback) { … }
void PushMessagingManager::UnsubscribeHavingGottenSenderId(
UnsubscribeCallback callback,
int64_t service_worker_registration_id,
const url::Origin& requesting_origin,
const std::vector<std::string>& sender_ids,
blink::ServiceWorkerStatusCode service_worker_status) { … }
void PushMessagingManager::DidUnregister(
UnsubscribeCallback callback,
blink::mojom::PushUnregistrationStatus unregistration_status) { … }
void PushMessagingManager::GetSubscription(
int64_t service_worker_registration_id,
GetSubscriptionCallback callback) { … }
void PushMessagingManager::DidGetSubscription(
GetSubscriptionCallback callback,
int64_t service_worker_registration_id,
const std::vector<std::string>&
push_subscription_id_and_application_server_key,
blink::ServiceWorkerStatusCode service_worker_status) { … }
void PushMessagingManager::GetSubscriptionDidGetInfo(
GetSubscriptionCallback callback,
const url::Origin& origin,
int64_t service_worker_registration_id,
const std::string& application_server_key,
bool is_valid,
const GURL& endpoint,
const std::optional<base::Time>& expiration_time,
const std::vector<uint8_t>& p256dh,
const std::vector<uint8_t>& auth) { … }
void PushMessagingManager::GetSubscriptionDidUnsubscribe(
GetSubscriptionCallback callback,
blink::mojom::PushGetRegistrationStatus get_status,
blink::mojom::PushUnregistrationStatus unsubscribe_status) { … }
void PushMessagingManager::GetSubscriptionInfo(
const url::Origin& origin,
int64_t service_worker_registration_id,
const std::string& sender_id,
const std::string& push_subscription_id,
PushMessagingService::SubscriptionInfoCallback callback) { … }
PushMessagingService* PushMessagingManager::GetService() { … }
}