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 a3bc7c2ff135fe6fe228bd60886f08a7c94b7ebb..9fb3a65e68cd7d3a3d60b479b4497482100835b6 100644 --- a/chrome/browser/notifications/platform_notification_service_impl.cc +++ b/chrome/browser/notifications/platform_notification_service_impl.cc @@ -197,6 +197,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 dfbfbf4e5d92eb8c7c2ba38f31264ac41713a485..78cc81931321656c308e5611e30e0813b8e6b88a 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 d4540308246d1166aee7319229390b9b8afce219..a0e67d2bdb8680229bfba072173acfcc3162b96c 100644 --- a/content/browser/notifications/blink_notification_service_impl.cc +++ b/content/browser/notifications/blink_notification_service_impl.cc @@ -87,12 +87,14 @@ BlinkNotificationServiceImpl::BlinkNotificationServiceImpl( BrowserContext* browser_context, scoped_refptr service_worker_context, RenderProcessHost* render_process_host, + RenderFrameHost* render_frame_host, const blink::StorageKey& storage_key, const GURL& document_url, const WeakDocumentPtr& weak_document_ptr, RenderProcessHost::NotificationServiceCreatorType creator_type, 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()), @@ -184,7 +186,7 @@ void BlinkNotificationServiceImpl::DisplayNonPersistentNotification( creator_type_); browser_context_->GetPlatformNotificationService()->DisplayNotification( - notification_id, storage_key_.origin().GetURL(), document_url_, + render_frame_host_, notification_id, storage_key_.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 1c1a95953c6c216b378c2ab0bfbef6eeb19cc184..2f0ce853dbb28163aa30914b5bc31be7066d60a2 100644 --- a/content/browser/notifications/blink_notification_service_impl.h +++ b/content/browser/notifications/blink_notification_service_impl.h @@ -44,6 +44,7 @@ class CONTENT_EXPORT BlinkNotificationServiceImpl BrowserContext* browser_context, scoped_refptr service_worker_context, RenderProcessHost* render_process_host, + RenderFrameHost* render_frame_host, const blink::StorageKey& storage_key, const GURL& document_url, const WeakDocumentPtr& weak_document_ptr, @@ -112,6 +113,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 b07eaabb5f2914b160edbfd38091c1b9b24e9564..aba444e8e8f4973056ebe5a88ed1b7939d2d7def 100644 --- a/content/browser/notifications/blink_notification_service_impl_unittest.cc +++ b/content/browser/notifications/blink_notification_service_impl_unittest.cc @@ -136,7 +136,7 @@ class BlinkNotificationServiceImplTest : public ::testing::Test { notification_service_ = std::make_unique( notification_context_.get(), &browser_context_, embedded_worker_helper_->context_wrapper(), &render_process_host_, - storage_key_, + nullptr, storage_key_, /*document_url=*/GURL(), contents_.get()->GetPrimaryMainFrame()->GetWeakDocumentPtr(), RenderProcessHost::NotificationServiceCreatorType::kDocument, diff --git a/content/browser/notifications/platform_notification_context_impl.cc b/content/browser/notifications/platform_notification_context_impl.cc index 76e711cf9e1aee95ca7d10d268e02b41447ed986..5e46ea38736ec5ba820485212abd6c99bec0ef40 100644 --- a/content/browser/notifications/platform_notification_context_impl.cc +++ b/content/browser/notifications/platform_notification_context_impl.cc @@ -282,6 +282,7 @@ void PlatformNotificationContextImpl::Shutdown() { void PlatformNotificationContextImpl::CreateService( RenderProcessHost* render_process_host, + RenderFrameHost* render_frame_host, const blink::StorageKey& storage_key, const GURL& document_url, const WeakDocumentPtr& weak_document_ptr, @@ -290,7 +291,7 @@ void PlatformNotificationContextImpl::CreateService( DCHECK_CURRENTLY_ON(BrowserThread::UI); services_.push_back(std::make_unique( this, browser_context_, service_worker_context_, render_process_host, - storage_key, document_url, weak_document_ptr, creator_type, + render_frame_host, storage_key, document_url, weak_document_ptr, creator_type, std::move(receiver))); } diff --git a/content/browser/notifications/platform_notification_context_impl.h b/content/browser/notifications/platform_notification_context_impl.h index 600d248a3060f754c676b9b96007329d2db7253e..5e075572ef71397a8bbdb54e8ed8131892476aab 100644 --- a/content/browser/notifications/platform_notification_context_impl.h +++ b/content/browser/notifications/platform_notification_context_impl.h @@ -45,6 +45,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 // service is created by a dedicated worker, or is `nullptr` otherwise. void CreateService( RenderProcessHost* render_process_host, + RenderFrameHost* render_frame_host, const blink::StorageKey& storage_key, const GURL& document_url, const WeakDocumentPtr& weak_document_ptr, diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index ebe9c1eafcffa70e436d4f23d6859a70e6a7ab7e..44d5616a627d34576cd70eac6dee664a1da25341 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -2122,7 +2122,7 @@ void RenderProcessHostImpl::CreateNotificationService( case RenderProcessHost::NotificationServiceCreatorType::kSharedWorker: case RenderProcessHost::NotificationServiceCreatorType::kDedicatedWorker: { storage_partition_impl_->GetPlatformNotificationContext()->CreateService( - this, storage_key, /*document_url=*/GURL(), weak_document_ptr, + this, rfh, storage_key, /*document_url=*/GURL(), weak_document_ptr, creator_type, std::move(receiver)); break; } @@ -2130,7 +2130,7 @@ void RenderProcessHostImpl::CreateNotificationService( CHECK(rfh); storage_partition_impl_->GetPlatformNotificationContext()->CreateService( - this, storage_key, rfh->GetLastCommittedURL(), weak_document_ptr, + this, rfh, storage_key, rfh->GetLastCommittedURL(), weak_document_ptr, creator_type, std::move(receiver)); break; } diff --git a/content/public/browser/platform_notification_service.h b/content/public/browser/platform_notification_service.h index 2cb0d1fc03df42c4681d2594d9c600b414a423b4..7959141a4707d55b88ed2c986f4b41874c123c9f 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 b78a368e201d7f1624fcf8371c5c7c2be5e536e0..c10dd93fecd308f832132183da5c136658177f9f 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 91f77590918d92c2d35bd5a94e42817015905d4d..ff61450499ba2e1c8caafbc0548bb239e632b887 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,