fix notification permission handler

This commit is contained in:
Jeremy Apthorp 2018-10-05 14:24:38 -07:00
parent f027e62b2a
commit e28eeb0c2e
4 changed files with 145 additions and 5 deletions

View file

@ -10,6 +10,7 @@
#include "brightray/browser/notification_delegate.h"
#include "brightray/browser/notification_presenter.h"
#include "content/public/browser/notification_event_dispatcher.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/notification_resources.h"
#include "content/public/common/platform_notification_data.h"
#include "third_party/skia/include/core/SkBitmap.h"
@ -72,11 +73,12 @@ class NotificationDelegateImpl final : public brightray::NotificationDelegate {
PlatformNotificationService::PlatformNotificationService(
BrowserClient* browser_client)
: browser_client_(browser_client), render_process_id_(-1) {}
: browser_client_(browser_client) {}
PlatformNotificationService::~PlatformNotificationService() {}
void PlatformNotificationService::DisplayNotification(
content::RenderProcessHost* render_process_host,
content::BrowserContext* browser_context,
const std::string& notification_id,
const GURL& origin,
@ -90,7 +92,8 @@ void PlatformNotificationService::DisplayNotification(
auto notification = presenter->CreateNotification(delegate, notification_id);
if (notification) {
browser_client_->WebNotificationAllowed(
render_process_id_, base::Bind(&OnWebNotificationAllowed, notification,
render_process_host->GetID(),
base::Bind(&OnWebNotificationAllowed, notification,
notification_resources.notification_icon,
notification_data));
}

View file

@ -24,6 +24,7 @@ class PlatformNotificationService
protected:
// content::PlatformNotificationService:
void DisplayNotification(
content::RenderProcessHost* render_process_host,
content::BrowserContext* browser_context,
const std::string& notification_id,
const GURL& origin,
@ -48,7 +49,6 @@ class PlatformNotificationService
private:
BrowserClient* browser_client_;
int render_process_id_;
DISALLOW_COPY_AND_ASSIGN(PlatformNotificationService);
};

View file

@ -470,3 +470,10 @@ patches:
Pass pre allocated isolate for initialization, node platform
needs to register on an isolate so that it can be used later
down in the initialization process of an isolate.
-
author: Jeremy Apthorp <jeremya@chromium.org>
file: notification_provenance.patch
description: |
Pass RenderProcessHost through to PlatformNotificationService.
This is so Electron can identify which renderer a notification came from.

View file

@ -0,0 +1,130 @@
From 5c9dd74385e37830bff8918b54868ac37042c513 Mon Sep 17 00:00:00 2001
From: Jeremy Apthorp <jeremya@chromium.org>
Date: Fri, 5 Oct 2018 14:22:06 -0700
Subject: pass RenderProcessHost through to PlatformNotificationService
this is so Electron can identify which renderer a notification came from
diff --git a/content/browser/notifications/blink_notification_service_impl.cc b/content/browser/notifications/blink_notification_service_impl.cc
index cbcd2b5369fc..1b4066649d92 100644
--- a/content/browser/notifications/blink_notification_service_impl.cc
+++ b/content/browser/notifications/blink_notification_service_impl.cc
@@ -40,9 +40,11 @@ BlinkNotificationServiceImpl::BlinkNotificationServiceImpl(
PlatformNotificationContextImpl* notification_context,
BrowserContext* browser_context,
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
+ RenderProcessHost* render_process_host,
const url::Origin& origin,
mojo::InterfaceRequest<blink::mojom::NotificationService> request)
: notification_context_(notification_context),
+ render_process_host_(render_process_host),
browser_context_(browser_context),
service_worker_context_(std::move(service_worker_context)),
origin_(origin),
@@ -99,7 +101,7 @@ void BlinkNotificationServiceImpl::DisplayNonPersistentNotification(
notification_id, std::move(event_listener_ptr));
GetNotificationService()->DisplayNotification(
- browser_context_, notification_id, origin_.GetURL(),
+ render_process_host_, browser_context_, notification_id, origin_.GetURL(),
platform_notification_data, notification_resources);
}
diff --git a/content/browser/notifications/blink_notification_service_impl.h b/content/browser/notifications/blink_notification_service_impl.h
index 193f5d241c31..3cfcc6b86ae1 100644
--- a/content/browser/notifications/blink_notification_service_impl.h
+++ b/content/browser/notifications/blink_notification_service_impl.h
@@ -33,6 +33,7 @@ class CONTENT_EXPORT BlinkNotificationServiceImpl
PlatformNotificationContextImpl* notification_context,
BrowserContext* browser_context,
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
+ RenderProcessHost* render_process_host,
const url::Origin& origin,
mojo::InterfaceRequest<blink::mojom::NotificationService> request);
~BlinkNotificationServiceImpl() override;
@@ -94,6 +95,7 @@ class CONTENT_EXPORT BlinkNotificationServiceImpl
// The notification context that owns this service instance.
PlatformNotificationContextImpl* notification_context_;
+ RenderProcessHost* render_process_host_;
BrowserContext* browser_context_;
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
diff --git a/content/browser/notifications/platform_notification_context_impl.cc b/content/browser/notifications/platform_notification_context_impl.cc
index 627e8dbd251d..48c290470e48 100644
--- a/content/browser/notifications/platform_notification_context_impl.cc
+++ b/content/browser/notifications/platform_notification_context_impl.cc
@@ -122,12 +122,13 @@ void PlatformNotificationContextImpl::ShutdownOnIO() {
}
void PlatformNotificationContextImpl::CreateService(
+ RenderProcessHost* render_process_host,
const url::Origin& origin,
blink::mojom::NotificationServiceRequest request) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
services_.push_back(std::make_unique<BlinkNotificationServiceImpl>(
- this, browser_context_, service_worker_context_, origin,
- std::move(request)));
+ this, browser_context_, service_worker_context_, render_process_host,
+ origin, std::move(request)));
}
void PlatformNotificationContextImpl::RemoveService(
diff --git a/content/browser/notifications/platform_notification_context_impl.h b/content/browser/notifications/platform_notification_context_impl.h
index 7ea92b626202..faa3a1d8069f 100644
--- a/content/browser/notifications/platform_notification_context_impl.h
+++ b/content/browser/notifications/platform_notification_context_impl.h
@@ -21,6 +21,7 @@
#include "content/common/content_export.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/platform_notification_context.h"
+#include "content/public/browser/render_process_host.h"
#include "third_party/blink/public/platform/modules/notifications/notification_service.mojom.h"
class GURL;
@@ -65,7 +66,8 @@ class CONTENT_EXPORT PlatformNotificationContextImpl
// Creates a BlinkNotificationServiceImpl that is owned by this context. Must
// be called on the UI thread.
- void CreateService(const url::Origin& origin,
+ void CreateService(RenderProcessHost* render_process_host,
+ const url::Origin& origin,
blink::mojom::NotificationServiceRequest request);
// Removes |service| from the list of owned services, for example because the
diff --git a/content/browser/renderer_interface_binders.cc b/content/browser/renderer_interface_binders.cc
index 896f1b27ded7..20a1f86a36fd 100644
--- a/content/browser/renderer_interface_binders.cc
+++ b/content/browser/renderer_interface_binders.cc
@@ -168,7 +168,7 @@ void RendererInterfaceBinders::InitializeParameterizedBinderRegistry() {
RenderProcessHost* host, const url::Origin& origin) {
static_cast<StoragePartitionImpl*>(host->GetStoragePartition())
->GetPlatformNotificationContext()
- ->CreateService(origin, std::move(request));
+ ->CreateService(host, origin, std::move(request));
}));
parameterized_binder_registry_.AddInterface(
base::BindRepeating(&BackgroundFetchServiceImpl::Create));
diff --git a/content/public/browser/platform_notification_service.h b/content/public/browser/platform_notification_service.h
index 228fc30240c5..fd3e20c5335a 100644
--- a/content/public/browser/platform_notification_service.h
+++ b/content/public/browser/platform_notification_service.h
@@ -21,6 +21,7 @@ class GURL;
namespace content {
class BrowserContext;
+class RenderProcessHost;
struct NotificationResources;
struct PlatformNotificationData;
@@ -38,6 +39,7 @@ class CONTENT_EXPORT PlatformNotificationService {
// Displays the notification described in |notification_data| to the user.
// This method must be called on the UI thread.
virtual void DisplayNotification(
+ RenderProcessHost* render_process_host,
BrowserContext* browser_context,
const std::string& notification_id,
const GURL& origin,
--
2.17.0