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 2a4592f1565b99db37e91e090b5478fd1ad6e1a7..8a4144153789f4174763e3b23d47080521b0c20e 100644 --- a/content/browser/notifications/blink_notification_service_impl.cc +++ b/content/browser/notifications/blink_notification_service_impl.cc @@ -48,9 +48,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), @@ -110,7 +112,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 1ae12ca955024b85296449eb33f18af7f7bea37d..6d1df92efe1aec0a51cdb90a7731b187a3433154 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; @@ -104,6 +105,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 9985cfee820e4bb536813e39ebdca9b45574d6cf..e0636fde3c97bb4fce19b6042344cb432d96427c 100644 --- a/content/browser/notifications/blink_notification_service_impl_unittest.cc +++ b/content/browser/notifications/blink_notification_service_impl_unittest.cc @@ -126,7 +126,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 9b31e66db71ad167d593dd037bcecf4151b1452e..d01fe86c8f1ad8c9610b4b66f7b2b14bd819e359 100644 --- a/content/browser/notifications/platform_notification_context_impl.cc +++ b/content/browser/notifications/platform_notification_context_impl.cc @@ -127,12 +127,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( - 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 653f487b0b0e01de7cdda8483f081550a9077e98..da9e5f53d07eaaf11525efd996be9420f0189a88 100644 --- a/content/browser/notifications/platform_notification_context_impl.h +++ b/content/browser/notifications/platform_notification_context_impl.h @@ -22,6 +22,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 5a6e7ed16110e5d34d5e4f6e37f59ff84094a994..63af4bd1d17aca55229960422082643f2926d705 100644 --- a/content/browser/renderer_interface_binders.cc +++ b/content/browser/renderer_interface_binders.cc @@ -176,7 +176,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 80ffd8d426c2380d57172a951a8cd15a0393bf88..0cf9ee3a44647f44bcd89351931c162370ebfe29 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 0246db2c6d249843867d26d7ae6eb77f781e30a8..bc232b2684652e0febef9f3fe2f5e5e97719f06b 100644 --- a/content/test/mock_platform_notification_service.cc +++ b/content/test/mock_platform_notification_service.cc @@ -22,6 +22,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 1d38db3e3d141b32b237c0f4ebe6abc80751225c..4f6dcf2c72493b1c29751ec5f7b16bf96946f4a5 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,