notification_provenance.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Jeremy Apthorp <[email protected]>
  3. Date: Fri, 5 Oct 2018 14:22:06 -0700
  4. Subject: notification_provenance.patch
  5. Pass RenderFrameHost through to PlatformNotificationService
  6. so Electron can identify which renderer a notification came from.
  7. diff --git a/chrome/browser/notifications/platform_notification_service_impl.cc b/chrome/browser/notifications/platform_notification_service_impl.cc
  8. index 225609e52130d4113c8ae667f3ffa565bbde5b73..b33d27ce4fc6222146255cf4c0e7342751c75c9b 100644
  9. --- a/chrome/browser/notifications/platform_notification_service_impl.cc
  10. +++ b/chrome/browser/notifications/platform_notification_service_impl.cc
  11. @@ -196,6 +196,7 @@ bool PlatformNotificationServiceImpl::WasClosedProgrammatically(
  12. // TODO(awdf): Rename to DisplayNonPersistentNotification (Similar for Close)
  13. void PlatformNotificationServiceImpl::DisplayNotification(
  14. + content::RenderFrameHost* render_frame_host,
  15. const std::string& notification_id,
  16. const GURL& origin,
  17. const GURL& document_url,
  18. diff --git a/chrome/browser/notifications/platform_notification_service_impl.h b/chrome/browser/notifications/platform_notification_service_impl.h
  19. index b0e64049d411305d58802fd290bb0480e9b36fee..4afcf3b7a5b841409b0e1c4c2f32fd4878f12768 100644
  20. --- a/chrome/browser/notifications/platform_notification_service_impl.h
  21. +++ b/chrome/browser/notifications/platform_notification_service_impl.h
  22. @@ -56,6 +56,7 @@ class PlatformNotificationServiceImpl
  23. // content::PlatformNotificationService implementation.
  24. void DisplayNotification(
  25. + content::RenderFrameHost* render_frame_host,
  26. const std::string& notification_id,
  27. const GURL& origin,
  28. const GURL& document_url,
  29. diff --git a/content/browser/notifications/blink_notification_service_impl.cc b/content/browser/notifications/blink_notification_service_impl.cc
  30. index fd2c2d72ebc3cab0cc824bb091da32d4be635dd9..8bcd6a87c38413a5281d164e3c0fcfd23c3fa04b 100644
  31. --- a/content/browser/notifications/blink_notification_service_impl.cc
  32. +++ b/content/browser/notifications/blink_notification_service_impl.cc
  33. @@ -81,10 +81,12 @@ BlinkNotificationServiceImpl::BlinkNotificationServiceImpl(
  34. PlatformNotificationContextImpl* notification_context,
  35. BrowserContext* browser_context,
  36. scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
  37. + RenderFrameHost* render_frame_host,
  38. const url::Origin& origin,
  39. const GURL& document_url,
  40. mojo::PendingReceiver<blink::mojom::NotificationService> receiver)
  41. : notification_context_(notification_context),
  42. + render_frame_host_(render_frame_host),
  43. browser_context_(browser_context),
  44. service_worker_context_(std::move(service_worker_context)),
  45. origin_(origin),
  46. @@ -147,7 +149,7 @@ void BlinkNotificationServiceImpl::DisplayNonPersistentNotification(
  47. notification_id, std::move(event_listener_remote));
  48. browser_context_->GetPlatformNotificationService()->DisplayNotification(
  49. - notification_id, origin_.GetURL(), document_url_,
  50. + render_frame_host_, notification_id, origin_.GetURL(), document_url_,
  51. platform_notification_data, notification_resources);
  52. }
  53. diff --git a/content/browser/notifications/blink_notification_service_impl.h b/content/browser/notifications/blink_notification_service_impl.h
  54. index cb2b09912dbe426611e944316841ee2a9c2e373f..4d2603c29b2d89fa296b1aad40c2132a9c7498aa 100644
  55. --- a/content/browser/notifications/blink_notification_service_impl.h
  56. +++ b/content/browser/notifications/blink_notification_service_impl.h
  57. @@ -41,6 +41,7 @@ class CONTENT_EXPORT BlinkNotificationServiceImpl
  58. PlatformNotificationContextImpl* notification_context,
  59. BrowserContext* browser_context,
  60. scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
  61. + RenderFrameHost* render_frame_host,
  62. const url::Origin& origin,
  63. const GURL& document_url,
  64. mojo::PendingReceiver<blink::mojom::NotificationService> receiver);
  65. @@ -101,6 +102,7 @@ class CONTENT_EXPORT BlinkNotificationServiceImpl
  66. // The notification context that owns this service instance.
  67. raw_ptr<PlatformNotificationContextImpl> notification_context_;
  68. + raw_ptr<RenderFrameHost> render_frame_host_;
  69. raw_ptr<BrowserContext> browser_context_;
  70. scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
  71. diff --git a/content/browser/notifications/blink_notification_service_impl_unittest.cc b/content/browser/notifications/blink_notification_service_impl_unittest.cc
  72. index f0d5ea365cf09d2dc06de88fc03e4bf5ddfdf4a6..b68666813ab231a3d4233d3ed2f9655b18d8a280 100644
  73. --- a/content/browser/notifications/blink_notification_service_impl_unittest.cc
  74. +++ b/content/browser/notifications/blink_notification_service_impl_unittest.cc
  75. @@ -126,7 +126,7 @@ class BlinkNotificationServiceImplTest : public ::testing::Test {
  76. notification_service_ = std::make_unique<BlinkNotificationServiceImpl>(
  77. notification_context_.get(), &browser_context_,
  78. - embedded_worker_helper_->context_wrapper(),
  79. + embedded_worker_helper_->context_wrapper(), nullptr,
  80. url::Origin::Create(GURL(kTestOrigin)),
  81. /*document_url=*/GURL(),
  82. notification_service_remote_.BindNewPipeAndPassReceiver());
  83. diff --git a/content/browser/notifications/platform_notification_context_impl.cc b/content/browser/notifications/platform_notification_context_impl.cc
  84. index 5580c415a1e8a45327147861d7c71cebd1ecbd5a..d37711f83be7566ec5ad2078942aaca1948a77c5 100644
  85. --- a/content/browser/notifications/platform_notification_context_impl.cc
  86. +++ b/content/browser/notifications/platform_notification_context_impl.cc
  87. @@ -281,13 +281,14 @@ void PlatformNotificationContextImpl::Shutdown() {
  88. }
  89. void PlatformNotificationContextImpl::CreateService(
  90. + RenderFrameHost* render_frame_host,
  91. const url::Origin& origin,
  92. const GURL& document_url,
  93. mojo::PendingReceiver<blink::mojom::NotificationService> receiver) {
  94. DCHECK_CURRENTLY_ON(BrowserThread::UI);
  95. services_.push_back(std::make_unique<BlinkNotificationServiceImpl>(
  96. - this, browser_context_, service_worker_context_, origin, document_url,
  97. - std::move(receiver)));
  98. + this, browser_context_, service_worker_context_, render_frame_host,
  99. + origin, document_url, std::move(receiver)));
  100. }
  101. void PlatformNotificationContextImpl::RemoveService(
  102. diff --git a/content/browser/notifications/platform_notification_context_impl.h b/content/browser/notifications/platform_notification_context_impl.h
  103. index 951075749b24814606f494c5a89ee2adf527f512..7036323ff8ee38ae92790dfd2e216df61181bc55 100644
  104. --- a/content/browser/notifications/platform_notification_context_impl.h
  105. +++ b/content/browser/notifications/platform_notification_context_impl.h
  106. @@ -47,6 +47,7 @@ class BrowserContext;
  107. struct NotificationDatabaseData;
  108. class PlatformNotificationServiceProxy;
  109. class ServiceWorkerContextWrapper;
  110. +class RenderFrameHost;
  111. // Implementation of the Web Notification storage context. The public methods
  112. // defined in this interface must only be called on the UI thread.
  113. @@ -76,6 +77,7 @@ class CONTENT_EXPORT PlatformNotificationContextImpl
  114. // Creates a BlinkNotificationServiceImpl that is owned by this context.
  115. // |document_url| is empty when originating from a worker.
  116. void CreateService(
  117. + RenderFrameHost* render_frame_host,
  118. const url::Origin& origin,
  119. const GURL& document_url,
  120. mojo::PendingReceiver<blink::mojom::NotificationService> receiver);
  121. diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
  122. index cc5f7c8d616ec9a433da428f180483da60736a9d..fb25a7c19f20ca690963c5a15bd09224687b5f57 100644
  123. --- a/content/browser/renderer_host/render_process_host_impl.cc
  124. +++ b/content/browser/renderer_host/render_process_host_impl.cc
  125. @@ -2083,7 +2083,7 @@ void RenderProcessHostImpl::CreateNotificationService(
  126. document_url = rfh->GetLastCommittedURL();
  127. storage_partition_impl_->GetPlatformNotificationContext()->CreateService(
  128. - origin, document_url, std::move(receiver));
  129. + RenderFrameHost::FromID(GetID(), render_frame_id), origin, document_url, std::move(receiver));
  130. }
  131. void RenderProcessHostImpl::CreateWebSocketConnector(
  132. diff --git a/content/public/browser/platform_notification_service.h b/content/public/browser/platform_notification_service.h
  133. index 9646cbeb31141e3518f51482801431f3a6010360..b13b6ab07b4931b892749c84879d9a6adb3bcb58 100644
  134. --- a/content/public/browser/platform_notification_service.h
  135. +++ b/content/public/browser/platform_notification_service.h
  136. @@ -26,6 +26,8 @@ struct PlatformNotificationData;
  137. namespace content {
  138. +class RenderFrameHost;
  139. +
  140. // The service using which notifications can be presented to the user. There
  141. // should be a unique instance of the PlatformNotificationService depending
  142. // on the browsing context being used.
  143. @@ -41,6 +43,7 @@ class CONTENT_EXPORT PlatformNotificationService {
  144. // This method must be called on the UI thread. |document_url| is empty when
  145. // the display notification originates from a worker.
  146. virtual void DisplayNotification(
  147. + RenderFrameHost* render_frame_host,
  148. const std::string& notification_id,
  149. const GURL& origin,
  150. const GURL& document_url,
  151. diff --git a/content/test/mock_platform_notification_service.cc b/content/test/mock_platform_notification_service.cc
  152. index 7397963a36bec7016ae92fbc4bb741825e5fb8d1..d1818311fd657d3c099cdce41898daf4ab3ede8b 100644
  153. --- a/content/test/mock_platform_notification_service.cc
  154. +++ b/content/test/mock_platform_notification_service.cc
  155. @@ -29,6 +29,7 @@ MockPlatformNotificationService::MockPlatformNotificationService(
  156. MockPlatformNotificationService::~MockPlatformNotificationService() = default;
  157. void MockPlatformNotificationService::DisplayNotification(
  158. + RenderFrameHost* render_frame_host,
  159. const std::string& notification_id,
  160. const GURL& origin,
  161. const GURL& document_url,
  162. diff --git a/content/test/mock_platform_notification_service.h b/content/test/mock_platform_notification_service.h
  163. index 45ad11f0fc5f0abebbc05836221528e59da6c26b..7f914f69d597dbd149d554dc0282c27ed234c7ed 100644
  164. --- a/content/test/mock_platform_notification_service.h
  165. +++ b/content/test/mock_platform_notification_service.h
  166. @@ -52,6 +52,7 @@ class MockPlatformNotificationService : public PlatformNotificationService {
  167. // PlatformNotificationService implementation.
  168. void DisplayNotification(
  169. + RenderFrameHost* render_frame_host,
  170. const std::string& notification_id,
  171. const GURL& origin,
  172. const GURL& document_url,