summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/push_messaging/push_messaging_service_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/chrome/browser/push_messaging/push_messaging_service_impl.cc')
-rw-r--r--chromium/chrome/browser/push_messaging/push_messaging_service_impl.cc109
1 files changed, 109 insertions, 0 deletions
diff --git a/chromium/chrome/browser/push_messaging/push_messaging_service_impl.cc b/chromium/chrome/browser/push_messaging/push_messaging_service_impl.cc
index 6313d399760..6438b081d07 100644
--- a/chromium/chrome/browser/push_messaging/push_messaging_service_impl.cc
+++ b/chromium/chrome/browser/push_messaging/push_messaging_service_impl.cc
@@ -21,22 +21,32 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "build/build_config.h"
+#ifndef TOOLKIT_QT
#include "chrome/browser/browser_process.h"
+#endif
#include "chrome/browser/chrome_notification_types.h"
+#ifndef TOOLKIT_QT
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
+#endif
#include "chrome/browser/gcm/gcm_profile_service_factory.h"
#include "chrome/browser/gcm/instance_id/instance_id_profile_service_factory.h"
+#ifndef TOOLKIT_QT
#include "chrome/browser/permissions/abusive_origin_permission_revocation_request.h"
#include "chrome/browser/permissions/permission_manager_factory.h"
+#endif
#include "chrome/browser/profiles/profile.h"
+#ifndef TOOLKIT_QT
#include "chrome/browser/profiles/profile_keep_alive_types.h"
#include "chrome/browser/profiles/scoped_profile_keep_alive.h"
+#endif
#include "chrome/browser/push_messaging/push_messaging_app_identifier.h"
#include "chrome/browser/push_messaging/push_messaging_constants.h"
#include "chrome/browser/push_messaging/push_messaging_features.h"
#include "chrome/browser/push_messaging/push_messaging_service_factory.h"
#include "chrome/browser/push_messaging/push_messaging_utils.h"
+#ifndef TOOLKIT_QT
#include "chrome/browser/ui/chrome_pages.h"
+#endif
#include "chrome/common/buildflags.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
@@ -81,6 +91,14 @@ using instance_id::InstanceID;
namespace {
+#ifdef TOOLKIT_QT
+GURL CreateCustomEndpoint(Profile *profile, const std::string& subscription_id) {
+ const GURL endpoint(profile->GetPushMessagingEndpoint() + subscription_id);
+ DCHECK(endpoint.is_valid());
+ return endpoint;
+}
+#endif
+
// Scope passed to getToken to obtain GCM registration tokens.
// Must match Java GoogleCloudMessaging.INSTANCE_ID_SCOPE.
const char kGCMScope[] = "GCM";
@@ -262,7 +280,9 @@ PushMessagingServiceImpl::PushMessagingServiceImpl(Profile* profile)
pending_push_subscription_count_(0),
notification_manager_(profile) {
DCHECK(profile);
+#ifndef TOOLKIT_QT
HostContentSettingsMapFactory::GetForProfile(profile_)->AddObserver(this);
+#endif
registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
content::NotificationService::AllSources());
@@ -328,11 +348,13 @@ void PushMessagingServiceImpl::OnStoreReset() {
void PushMessagingServiceImpl::OnMessage(const std::string& app_id,
const gcm::IncomingMessage& message) {
+#ifndef TOOLKIT_QT
// We won't have time to process and act on the message.
// TODO(peter) This should be checked at the level of the GCMDriver, so that
// the message is not consumed. See https://crbug.com/612815
if (g_browser_process->IsShuttingDown() || shutdown_started_)
return;
+#endif // !TOOLKIT_QT
#if BUILDFLAG(ENABLE_BACKGROUND_MODE)
if (g_browser_process->background_mode_manager()) {
@@ -376,10 +398,14 @@ void PushMessagingServiceImpl::OnMessage(const std::string& app_id,
if (IsPermissionSet(app_identifier.origin())) {
messages_pending_permission_check_.emplace(app_id, message);
+#ifndef TOOLKIT_QT
// Start abusive origin verification only if no other verification is in
// progress.
if (!abusive_origin_revocation_request_)
CheckOriginForAbuseAndDispatchNextMessage();
+#else
+ DispatchNextMessage();
+#endif
} else {
// Drop message and unregister if origin has lost push permission.
DeliverMessageCallback(app_id, app_identifier.origin(),
@@ -389,6 +415,7 @@ void PushMessagingServiceImpl::OnMessage(const std::string& app_id,
}
}
+#ifndef TOOLKIT_QT
void PushMessagingServiceImpl::CheckOriginForAbuseAndDispatchNextMessage() {
if (messages_pending_permission_check_.empty())
return;
@@ -464,6 +491,43 @@ void PushMessagingServiceImpl::OnCheckedOriginForAbuse(
// Verify the next message in the queue.
CheckOriginForAbuseAndDispatchNextMessage();
}
+#else
+void PushMessagingServiceImpl::DispatchNextMessage()
+{
+ if (messages_pending_permission_check_.empty())
+ return;
+
+ PendingMessage message =
+ std::move(messages_pending_permission_check_.front());
+ messages_pending_permission_check_.pop();
+
+ PushMessagingAppIdentifier app_identifier =
+ PushMessagingAppIdentifier::FindByAppId(profile_, message.app_id);
+
+ if (app_identifier.is_null()) {
+ DispatchNextMessage();
+ return;
+ }
+
+ const GURL& origin = app_identifier.origin();
+ int64_t service_worker_registration_id =
+ app_identifier.service_worker_registration_id();
+
+ std::queue<PendingMessage>& delivery_queue =
+ message_delivery_queue_[{origin, service_worker_registration_id}];
+ delivery_queue.push(std::move(message));
+
+ // Start delivering push messages to this service worker if this was the
+ // first message. Otherwise just enqueue the message to be delivered once
+ // all previous messages have been handled.
+ if (delivery_queue.size() == 1) {
+ DeliverNextQueuedMessageForServiceWorkerRegistration(
+ origin, service_worker_registration_id);
+ }
+
+ DispatchNextMessage();
+}
+#endif // !TOOLKIT_QT
void PushMessagingServiceImpl::
DeliverNextQueuedMessageForServiceWorkerRegistration(
@@ -781,6 +845,7 @@ void PushMessagingServiceImpl::SubscribeFromDocument(
}
// Push does not allow permission requests from iframes.
+#ifndef TOOLKIT_QT
PermissionManagerFactory::GetForProfile(profile_)->RequestPermission(
ContentSettingsType::NOTIFICATIONS, render_frame_host, requesting_origin,
user_gesture,
@@ -788,6 +853,20 @@ void PushMessagingServiceImpl::SubscribeFromDocument(
weak_factory_.GetWeakPtr(), std::move(app_identifier),
std::move(options), std::move(callback), render_process_id,
render_frame_id));
+#else
+ if (!IsPermissionSet(requesting_origin)) {
+ profile_->GetPermissionControllerDelegate()->RequestPermission(
+ content::PermissionType::NOTIFICATIONS, render_frame_host, requesting_origin,
+ user_gesture,
+ base::BindOnce(&PushMessagingServiceImpl::DoSubscribe,
+ weak_factory_.GetWeakPtr(), std::move(app_identifier),
+ std::move(options), std::move(callback), render_process_id,
+ render_frame_id));
+ } else {
+ DoSubscribe(std::move(app_identifier), std::move(options), std::move(callback),
+ render_process_id, render_frame_id, blink::mojom::PermissionStatus::GRANTED);
+ }
+#endif
}
void PushMessagingServiceImpl::SubscribeFromWorker(
@@ -823,7 +902,11 @@ void PushMessagingServiceImpl::SubscribeFromWorker(
DoSubscribe(std::move(app_identifier), std::move(options),
std::move(register_callback),
/* render_process_id= */ -1, /* render_frame_id= */ -1,
+#ifndef TOOLKIT_QT
CONTENT_SETTING_ALLOW);
+#else
+ blink::mojom::PermissionStatus::GRANTED);
+#endif
}
blink::mojom::PermissionStatus PushMessagingServiceImpl::GetPermissionStatus(
@@ -832,6 +915,7 @@ blink::mojom::PermissionStatus PushMessagingServiceImpl::GetPermissionStatus(
if (!user_visible)
return blink::mojom::PermissionStatus::DENIED;
+#ifndef TOOLKIT_QT
// Because the Push API is tied to Service Workers, many usages of the API
// won't have an embedding origin at all. Only consider the requesting
// |origin| when checking whether permission to use the API has been granted.
@@ -840,6 +924,11 @@ blink::mojom::PermissionStatus PushMessagingServiceImpl::GetPermissionStatus(
->GetPermissionStatus(ContentSettingsType::NOTIFICATIONS, origin,
origin)
.content_setting);
+#else
+ return profile_->GetPermissionControllerDelegate()
+ ->GetPermissionStatus(content::PermissionType::NOTIFICATIONS,
+ origin, origin);
+#endif
}
bool PushMessagingServiceImpl::SupportNonVisibleMessages() {
@@ -852,8 +941,13 @@ void PushMessagingServiceImpl::DoSubscribe(
RegisterCallback register_callback,
int render_process_id,
int render_frame_id,
+#ifndef TOOLKIT_QT
ContentSetting content_setting) {
if (content_setting != CONTENT_SETTING_ALLOW) {
+#else
+ blink::mojom::PermissionStatus permission_status) {
+ if (permission_status != blink::mojom::PermissionStatus::GRANTED) {
+#endif
SubscribeEndWithError(
std::move(register_callback),
blink::mojom::PushRegistrationStatus::PERMISSION_DENIED);
@@ -947,7 +1041,11 @@ void PushMessagingServiceImpl::DidSubscribe(
switch (result) {
case InstanceID::SUCCESS: {
+#ifndef TOOLKIT_QT
const GURL endpoint = push_messaging::CreateEndpoint(subscription_id);
+#else
+ const GURL endpoint = CreateCustomEndpoint(profile_, subscription_id);
+#endif
// Make sure that this subscription has associated encryption keys prior
// to returning it to the developer - they'll need this information in
@@ -1022,7 +1120,12 @@ void PushMessagingServiceImpl::GetSubscriptionInfo(
return;
}
+#ifndef TOOLKIT_QT
const GURL endpoint = push_messaging::CreateEndpoint(subscription_id);
+#else
+ const GURL endpoint = CreateCustomEndpoint(profile_, subscription_id);
+#endif
+
const std::string& app_id = app_identifier.app_id();
absl::optional<base::Time> expiration_time = app_identifier.expiration_time();
@@ -1455,7 +1558,9 @@ void PushMessagingServiceImpl::SetContentSettingChangedCallbackForTesting(
void PushMessagingServiceImpl::Shutdown() {
GetGCMDriver()->RemoveAppHandler(kPushMessagingAppIdentifierPrefix);
+#ifndef TOOLKIT_QT
HostContentSettingsMapFactory::GetForProfile(profile_)->RemoveObserver(this);
+#endif
}
// content::NotificationObserver methods ---------------------------------------
@@ -1552,7 +1657,11 @@ void PushMessagingServiceImpl::UpdateSubscription(
// the expiration time of |app_identifier|
DoSubscribe(app_identifier, std::move(options), std::move(register_callback),
-1 /* render_process_id */, -1 /* render_frame_id */,
+#ifndef TOOLKIT_QT
CONTENT_SETTING_ALLOW);
+#else
+ blink::mojom::PermissionStatus::GRANTED);
+#endif
}
void PushMessagingServiceImpl::DidUpdateSubscription(