From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp 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 f251139f5976d4ff52ac4d0f89a2c627c1809c8a..457890dcb49ca59c61326c633d74eabcf999ff08 100644 --- a/content/browser/notifications/blink_notification_service_impl.cc +++ b/content/browser/notifications/blink_notification_service_impl.cc @@ -71,9 +71,11 @@ BlinkNotificationServiceImpl::BlinkNotificationServiceImpl( PlatformNotificationContextImpl* notification_context, BrowserContext* browser_context, scoped_refptr service_worker_context, + RenderProcessHost* render_process_host, const url::Origin& origin, mojo::InterfaceRequest 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), @@ -133,7 +135,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 088637b68b1fb40fb8a32bb72781b425077e668a..ec2cce6b644e6cc8fd899a761fb55d9a01b65f98 100644 --- a/content/browser/notifications/blink_notification_service_impl.h +++ b/content/browser/notifications/blink_notification_service_impl.h @@ -36,6 +36,7 @@ class CONTENT_EXPORT BlinkNotificationServiceImpl PlatformNotificationContextImpl* notification_context, BrowserContext* browser_context, scoped_refptr service_worker_context, + RenderProcessHost* render_process_host, const url::Origin& origin, mojo::InterfaceRequest request); ~BlinkNotificationServiceImpl() override; @@ -99,6 +100,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 service_worker_context_; diff --git a/content/browser/notifications/blink_notification_service_impl_unittest.cc b/content/browser/notifications/blink_notification_service_impl_unittest.cc index a2fb2bbd8761b0c0078fbde0999f4f8f434c4a35..e68613c4a4c6b05694514071c7dc2e0c4419d141 100644 --- a/content/browser/notifications/blink_notification_service_impl_unittest.cc +++ b/content/browser/notifications/blink_notification_service_impl_unittest.cc @@ -130,7 +130,7 @@ class BlinkNotificationServiceImplTest : public ::testing::Test { notification_service_ = std::make_unique( notification_context_.get(), &browser_context_, - embedded_worker_helper_->context_wrapper(), + embedded_worker_helper_->context_wrapper(), nullptr, url::Origin::Create(GURL(kTestOrigin)), mojo::MakeRequest(¬ification_service_ptr_)); diff --git a/content/browser/notifications/platform_notification_context_impl.cc b/content/browser/notifications/platform_notification_context_impl.cc index 9d43b4e8cbd0238fdcde03e31537a68c4edb9471..ba5a87e8fca4680e7acd173111d5882a8f0667f9 100644 --- a/content/browser/notifications/platform_notification_context_impl.cc +++ b/content/browser/notifications/platform_notification_context_impl.cc @@ -178,12 +178,13 @@ void PlatformNotificationContextImpl::Shutdown() { } 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( - 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 c7c9bc8fb304697bb1802d04e26038c65b8facdc..e73d2b0a276d4a0a7d1a484d11d5ac43d963cc77 100644 --- a/content/browser/notifications/platform_notification_context_impl.h +++ b/content/browser/notifications/platform_notification_context_impl.h @@ -25,6 +25,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; @@ -66,7 +67,8 @@ class CONTENT_EXPORT PlatformNotificationContextImpl void Shutdown(); // Creates a BlinkNotificationServiceImpl that is owned by this context. - 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 b317a37b4fa12be4e737a91948110fd16308c221..b3968f52c478ce051370e543b2fb904360d7892c 100644 --- a/content/browser/renderer_interface_binders.cc +++ b/content/browser/renderer_interface_binders.cc @@ -189,7 +189,7 @@ void RendererInterfaceBinders::InitializeParameterizedBinderRegistry() { RenderProcessHost* host, const url::Origin& origin) { static_cast(host->GetStoragePartition()) ->GetPlatformNotificationContext() - ->CreateService(origin, std::move(request)); + ->CreateService(host, origin, std::move(request)); })); parameterized_binder_registry_.AddInterface( base::BindRepeating(&BackgroundFetchServiceImpl::CreateForWorker)); diff --git a/content/public/browser/platform_notification_service.h b/content/public/browser/platform_notification_service.h index c7209a74a84ae4a284170ba882ee537cb732d467..4960a11bc922fd79c00bf418e1468f09f0457407 100644 --- a/content/public/browser/platform_notification_service.h +++ b/content/public/browser/platform_notification_service.h @@ -27,6 +27,7 @@ struct PlatformNotificationData; namespace content { class BrowserContext; +class RenderProcessHost; // The service using which notifications can be presented to the user. There // should be a unique instance of the PlatformNotificationService depending @@ -42,6 +43,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, diff --git a/content/test/mock_platform_notification_service.cc b/content/test/mock_platform_notification_service.cc index 7d16ee63cd349c107a0a0c35446cef557be1aed1..ac9860af1234d2c451525bbd924b79fb32f99015 100644 --- a/content/test/mock_platform_notification_service.cc +++ b/content/test/mock_platform_notification_service.cc @@ -26,6 +26,7 @@ MockPlatformNotificationService::MockPlatformNotificationService() = default; MockPlatformNotificationService::~MockPlatformNotificationService() = default; void MockPlatformNotificationService::DisplayNotification( + RenderProcessHost* render_process_host, BrowserContext* browser_context, const std::string& notification_id, const GURL& origin, diff --git a/content/test/mock_platform_notification_service.h b/content/test/mock_platform_notification_service.h index 89aad27b34da99fc90e2d0352994eb3baa64fae4..0c8b8dbdacc83006c53fd85894d95c8fa01166d8 100644 --- a/content/test/mock_platform_notification_service.h +++ b/content/test/mock_platform_notification_service.h @@ -45,6 +45,7 @@ class MockPlatformNotificationService : public PlatformNotificationService { // PlatformNotificationService implementation. void DisplayNotification( + RenderProcessHost* render_process_host, BrowserContext* browser_context, const std::string& notification_id, const GURL& origin,