From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Fri, 5 Oct 2018 14:22:06 -0700 Subject: notification_provenance.patch Pass RenderFrameHost through to PlatformNotificationService so Electron can identify which renderer a notification came from. diff --git a/chrome/browser/notifications/platform_notification_service_impl.cc b/chrome/browser/notifications/platform_notification_service_impl.cc index 362fedd0a0b654db546a73ff84c7e0676097e824..f1f6e2a36a6764ef12827fdab16818061b007959 100644 --- a/chrome/browser/notifications/platform_notification_service_impl.cc +++ b/chrome/browser/notifications/platform_notification_service_impl.cc @@ -195,6 +195,7 @@ bool PlatformNotificationServiceImpl::WasClosedProgrammatically( // TODO(awdf): Rename to DisplayNonPersistentNotification (Similar for Close) void PlatformNotificationServiceImpl::DisplayNotification( + content::RenderFrameHost* render_frame_host, const std::string& notification_id, const GURL& origin, const GURL& document_url, diff --git a/chrome/browser/notifications/platform_notification_service_impl.h b/chrome/browser/notifications/platform_notification_service_impl.h index b0e64049d411305d58802fd290bb0480e9b36fee..4afcf3b7a5b841409b0e1c4c2f32fd4878f12768 100644 --- a/chrome/browser/notifications/platform_notification_service_impl.h +++ b/chrome/browser/notifications/platform_notification_service_impl.h @@ -56,6 +56,7 @@ class PlatformNotificationServiceImpl // content::PlatformNotificationService implementation. void DisplayNotification( + content::RenderFrameHost* render_frame_host, const std::string& notification_id, const GURL& origin, const GURL& document_url, diff --git a/content/browser/notifications/blink_notification_service_impl.cc b/content/browser/notifications/blink_notification_service_impl.cc index a3df152caabcadaba454f73f58763a89fdea4247..ba76f2f294a2eab8581b5ef8d879cb464f14cb1f 100644 --- a/content/browser/notifications/blink_notification_service_impl.cc +++ b/content/browser/notifications/blink_notification_service_impl.cc @@ -82,10 +82,12 @@ BlinkNotificationServiceImpl::BlinkNotificationServiceImpl( BrowserContext* browser_context, scoped_refptr service_worker_context, RenderProcessHost* render_process_host, + RenderFrameHost* render_frame_host, const url::Origin& origin, const GURL& document_url, mojo::PendingReceiver receiver) : notification_context_(notification_context), + render_frame_host_(render_frame_host), browser_context_(browser_context), service_worker_context_(std::move(service_worker_context)), render_process_host_id_(render_process_host->GetID()), @@ -149,7 +151,7 @@ void BlinkNotificationServiceImpl::DisplayNonPersistentNotification( notification_id, std::move(event_listener_remote)); browser_context_->GetPlatformNotificationService()->DisplayNotification( - notification_id, origin_.GetURL(), document_url_, + render_frame_host_, notification_id, origin_.GetURL(), document_url_, 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 dc8de24c86f1769680ce7830844d35dfef7eb7e7..fcd99361fa8c895d6bd89bacb9fb94e76969e7b2 100644 --- a/content/browser/notifications/blink_notification_service_impl.h +++ b/content/browser/notifications/blink_notification_service_impl.h @@ -42,6 +42,7 @@ class CONTENT_EXPORT BlinkNotificationServiceImpl BrowserContext* browser_context, scoped_refptr service_worker_context, RenderProcessHost* render_process_host, + RenderFrameHost* render_frame_host, const url::Origin& origin, const GURL& document_url, mojo::PendingReceiver receiver); @@ -102,6 +103,7 @@ class CONTENT_EXPORT BlinkNotificationServiceImpl // The notification context that owns this service instance. raw_ptr notification_context_; + raw_ptr render_frame_host_; raw_ptr 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 fe015fa7d7813115a2c6a23a00cb509c4c16cd93..88e04351204c786d0fc72a99ccc421f76fc26ef9 100644 --- a/content/browser/notifications/blink_notification_service_impl_unittest.cc +++ b/content/browser/notifications/blink_notification_service_impl_unittest.cc @@ -129,7 +129,7 @@ class BlinkNotificationServiceImplTest : public ::testing::Test { notification_service_ = std::make_unique( notification_context_.get(), &browser_context_, embedded_worker_helper_->context_wrapper(), &render_process_host_, - url::Origin::Create(GURL(kTestOrigin)), + nullptr, url::Origin::Create(GURL(kTestOrigin)), /*document_url=*/GURL(), notification_service_remote_.BindNewPipeAndPassReceiver()); diff --git a/content/browser/notifications/platform_notification_context_impl.cc b/content/browser/notifications/platform_notification_context_impl.cc index fc24d16beb5a0ae61bf3123d0594287031d69ddf..6a6edfa8f919ffca815cc0f50fcde0b09067d494 100644 --- a/content/browser/notifications/platform_notification_context_impl.cc +++ b/content/browser/notifications/platform_notification_context_impl.cc @@ -282,13 +282,14 @@ void PlatformNotificationContextImpl::Shutdown() { void PlatformNotificationContextImpl::CreateService( RenderProcessHost* render_process_host, + RenderFrameHost* render_frame_host, const url::Origin& origin, const GURL& document_url, mojo::PendingReceiver receiver) { DCHECK_CURRENTLY_ON(BrowserThread::UI); services_.push_back(std::make_unique( this, browser_context_, service_worker_context_, render_process_host, - origin, document_url, std::move(receiver))); + render_frame_host, origin, document_url, std::move(receiver))); } void PlatformNotificationContextImpl::RemoveService( diff --git a/content/browser/notifications/platform_notification_context_impl.h b/content/browser/notifications/platform_notification_context_impl.h index 69f000e5cd25c6d89c88238873f638923bafdf0e..4f0068a92a0e99e2b34f105954689c7b5c19f436 100644 --- a/content/browser/notifications/platform_notification_context_impl.h +++ b/content/browser/notifications/platform_notification_context_impl.h @@ -48,6 +48,7 @@ struct NotificationDatabaseData; class PlatformNotificationServiceProxy; class RenderProcessHost; class ServiceWorkerContextWrapper; +class RenderFrameHost; // Implementation of the Web Notification storage context. The public methods // defined in this interface must only be called on the UI thread. @@ -78,6 +79,7 @@ class CONTENT_EXPORT PlatformNotificationContextImpl // |document_url| is empty when originating from a worker. void CreateService( RenderProcessHost* render_process_host, + RenderFrameHost* render_frame_host, const url::Origin& origin, const GURL& document_url, mojo::PendingReceiver receiver); diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 36830abdfa49fed9b8294ca33065816faa672e18..36b4e75828436df4274b522bdf75e88e1112aab6 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -2085,7 +2085,8 @@ void RenderProcessHostImpl::CreateNotificationService( document_url = rfh->GetLastCommittedURL(); storage_partition_impl_->GetPlatformNotificationContext()->CreateService( - this, origin, document_url, std::move(receiver)); + this, RenderFrameHost::FromID(GetID(), render_frame_id), + origin, document_url, std::move(receiver)); } void RenderProcessHostImpl::CreateWebSocketConnector( diff --git a/content/public/browser/platform_notification_service.h b/content/public/browser/platform_notification_service.h index 9646cbeb31141e3518f51482801431f3a6010360..b13b6ab07b4931b892749c84879d9a6adb3bcb58 100644 --- a/content/public/browser/platform_notification_service.h +++ b/content/public/browser/platform_notification_service.h @@ -26,6 +26,8 @@ struct PlatformNotificationData; namespace content { +class RenderFrameHost; + // The service using which notifications can be presented to the user. There // should be a unique instance of the PlatformNotificationService depending // on the browsing context being used. @@ -41,6 +43,7 @@ class CONTENT_EXPORT PlatformNotificationService { // This method must be called on the UI thread. |document_url| is empty when // the display notification originates from a worker. virtual void DisplayNotification( + RenderFrameHost* render_frame_host, const std::string& notification_id, const GURL& origin, const GURL& document_url, diff --git a/content/test/mock_platform_notification_service.cc b/content/test/mock_platform_notification_service.cc index 7397963a36bec7016ae92fbc4bb741825e5fb8d1..d1818311fd657d3c099cdce41898daf4ab3ede8b 100644 --- a/content/test/mock_platform_notification_service.cc +++ b/content/test/mock_platform_notification_service.cc @@ -29,6 +29,7 @@ MockPlatformNotificationService::MockPlatformNotificationService( MockPlatformNotificationService::~MockPlatformNotificationService() = default; void MockPlatformNotificationService::DisplayNotification( + RenderFrameHost* render_frame_host, const std::string& notification_id, const GURL& origin, const GURL& document_url, diff --git a/content/test/mock_platform_notification_service.h b/content/test/mock_platform_notification_service.h index 45ad11f0fc5f0abebbc05836221528e59da6c26b..7f914f69d597dbd149d554dc0282c27ed234c7ed 100644 --- a/content/test/mock_platform_notification_service.h +++ b/content/test/mock_platform_notification_service.h @@ -52,6 +52,7 @@ class MockPlatformNotificationService : public PlatformNotificationService { // PlatformNotificationService implementation. void DisplayNotification( + RenderFrameHost* render_frame_host, const std::string& notification_id, const GURL& origin, const GURL& document_url,