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 f49963aad901c4f1f32be4995613355f5a6d2e14..eb2e8b6fcc5b00c3a74c88d79db9d20653cdd2f2 100644 --- a/content/browser/notifications/blink_notification_service_impl.cc +++ b/content/browser/notifications/blink_notification_service_impl.cc @@ -50,9 +50,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), @@ -112,7 +114,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 9b927ba78d006b599b7dc6776e50a76d581c9e9e..ab16372bcc7a1a4c8ddc1c56edd46b6d78393ae1 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; @@ -97,6 +98,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 5bb02dcf4011d23de6b8b70050555555aa31d669..6cf025c744d988389452b31a2ba18bf6ed69357c 100644 --- a/content/browser/notifications/blink_notification_service_impl_unittest.cc +++ b/content/browser/notifications/blink_notification_service_impl_unittest.cc @@ -127,7 +127,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 d78bd8005178dea2dd3985527de4709e28b1ac3e..11d82930e851975997fcc69f623c4ec154f83dcc 100644 --- a/content/browser/notifications/platform_notification_context_impl.cc +++ b/content/browser/notifications/platform_notification_context_impl.cc @@ -108,12 +108,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 09fd40b0a55a9799dc8018ea69a85cb25724fa63..143335b6ba90b0d0aef8aa95687db1dbcc2bdf79 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; @@ -62,7 +63,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 8e4df0b15aebc30c517a8c99f20201d8148777e0..ad49782df16c92a6ed0f736a5980263de908c137 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,