notification_provenance.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 21683b9fba4414d825a32a7c12cf55b4bcc488a9..367299bdfc6d716099ff4ceafe493af4fe880bad 100644
  9. --- a/chrome/browser/notifications/platform_notification_service_impl.cc
  10. +++ b/chrome/browser/notifications/platform_notification_service_impl.cc
  11. @@ -201,6 +201,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 4ffd662e1411c8ba707cfab6970d7533246633e1..9266120342a179bb642286e617feeafb8f57d798 100644
  20. --- a/chrome/browser/notifications/platform_notification_service_impl.h
  21. +++ b/chrome/browser/notifications/platform_notification_service_impl.h
  22. @@ -57,6 +57,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 688c95eeb2a1ea60b004eb643cb5afcff48c11bd..226d1e3f01f976d8b35e6b3fbd332683d1a0f84b 100644
  31. --- a/content/browser/notifications/blink_notification_service_impl.cc
  32. +++ b/content/browser/notifications/blink_notification_service_impl.cc
  33. @@ -87,12 +87,14 @@ BlinkNotificationServiceImpl::BlinkNotificationServiceImpl(
  34. BrowserContext* browser_context,
  35. scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
  36. RenderProcessHost* render_process_host,
  37. + RenderFrameHost* render_frame_host,
  38. const blink::StorageKey& storage_key,
  39. const GURL& document_url,
  40. const WeakDocumentPtr& weak_document_ptr,
  41. RenderProcessHost::NotificationServiceCreatorType creator_type,
  42. mojo::PendingReceiver<blink::mojom::NotificationService> receiver)
  43. : notification_context_(notification_context),
  44. + render_frame_host_(render_frame_host),
  45. browser_context_(browser_context),
  46. service_worker_context_(std::move(service_worker_context)),
  47. render_process_host_id_(render_process_host->GetID()),
  48. @@ -184,7 +186,7 @@ void BlinkNotificationServiceImpl::DisplayNonPersistentNotification(
  49. creator_type_);
  50. browser_context_->GetPlatformNotificationService()->DisplayNotification(
  51. - notification_id, storage_key_.origin().GetURL(), document_url_,
  52. + render_frame_host_, notification_id, storage_key_.origin().GetURL(), document_url_,
  53. platform_notification_data, notification_resources);
  54. }
  55. diff --git a/content/browser/notifications/blink_notification_service_impl.h b/content/browser/notifications/blink_notification_service_impl.h
  56. index e7cc73f375ada7ee8715d331c3d372e0f59a0cdf..c0a142bea4a9a30c10dbb30c72fedce9ab4d1e62 100644
  57. --- a/content/browser/notifications/blink_notification_service_impl.h
  58. +++ b/content/browser/notifications/blink_notification_service_impl.h
  59. @@ -44,6 +44,7 @@ class CONTENT_EXPORT BlinkNotificationServiceImpl
  60. BrowserContext* browser_context,
  61. scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
  62. RenderProcessHost* render_process_host,
  63. + RenderFrameHost* render_frame_host,
  64. const blink::StorageKey& storage_key,
  65. const GURL& document_url,
  66. const WeakDocumentPtr& weak_document_ptr,
  67. @@ -113,6 +114,7 @@ class CONTENT_EXPORT BlinkNotificationServiceImpl
  68. raw_ptr<PlatformNotificationContextImpl, DanglingUntriaged>
  69. notification_context_;
  70. + raw_ptr<RenderFrameHost> render_frame_host_;
  71. raw_ptr<BrowserContext> browser_context_;
  72. scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
  73. diff --git a/content/browser/notifications/blink_notification_service_impl_unittest.cc b/content/browser/notifications/blink_notification_service_impl_unittest.cc
  74. index 00965c253f28bd3947255b2ab77bf3a0bb71f14a..e04a7eef94990dfb0e2fca2e116352fe80965303 100644
  75. --- a/content/browser/notifications/blink_notification_service_impl_unittest.cc
  76. +++ b/content/browser/notifications/blink_notification_service_impl_unittest.cc
  77. @@ -136,7 +136,7 @@ class BlinkNotificationServiceImplTest : public ::testing::Test {
  78. notification_service_ = std::make_unique<BlinkNotificationServiceImpl>(
  79. notification_context_.get(), &browser_context_,
  80. embedded_worker_helper_->context_wrapper(), &render_process_host_,
  81. - storage_key_,
  82. + nullptr, storage_key_,
  83. /*document_url=*/GURL(),
  84. contents_.get()->GetPrimaryMainFrame()->GetWeakDocumentPtr(),
  85. RenderProcessHost::NotificationServiceCreatorType::kDocument,
  86. diff --git a/content/browser/notifications/platform_notification_context_impl.cc b/content/browser/notifications/platform_notification_context_impl.cc
  87. index 9814861ab18fa88bc781f83acb602129b6f3de1f..1c5a2efc2749697aa3d38247f491eabf240c1aa5 100644
  88. --- a/content/browser/notifications/platform_notification_context_impl.cc
  89. +++ b/content/browser/notifications/platform_notification_context_impl.cc
  90. @@ -268,6 +268,7 @@ void PlatformNotificationContextImpl::Shutdown() {
  91. void PlatformNotificationContextImpl::CreateService(
  92. RenderProcessHost* render_process_host,
  93. + RenderFrameHost* render_frame_host,
  94. const blink::StorageKey& storage_key,
  95. const GURL& document_url,
  96. const WeakDocumentPtr& weak_document_ptr,
  97. @@ -276,7 +277,7 @@ void PlatformNotificationContextImpl::CreateService(
  98. DCHECK_CURRENTLY_ON(BrowserThread::UI);
  99. services_.push_back(std::make_unique<BlinkNotificationServiceImpl>(
  100. this, browser_context_, service_worker_context_, render_process_host,
  101. - storage_key, document_url, weak_document_ptr, creator_type,
  102. + render_frame_host, storage_key, document_url, weak_document_ptr, creator_type,
  103. std::move(receiver)));
  104. }
  105. diff --git a/content/browser/notifications/platform_notification_context_impl.h b/content/browser/notifications/platform_notification_context_impl.h
  106. index d0e0d10739b5daf99435a67e18dc51df8e670e09..704f3d6c2fdd27a84d1c4e1b7bf680f62c86c2d0 100644
  107. --- a/content/browser/notifications/platform_notification_context_impl.h
  108. +++ b/content/browser/notifications/platform_notification_context_impl.h
  109. @@ -45,6 +45,7 @@ struct NotificationDatabaseData;
  110. class PlatformNotificationServiceProxy;
  111. class RenderProcessHost;
  112. class ServiceWorkerContextWrapper;
  113. +class RenderFrameHost;
  114. // Implementation of the Web Notification storage context. The public methods
  115. // defined in this interface must only be called on the UI thread.
  116. @@ -78,6 +79,7 @@ class CONTENT_EXPORT PlatformNotificationContextImpl
  117. // service is created by a dedicated worker, or is `nullptr` otherwise.
  118. void CreateService(
  119. RenderProcessHost* render_process_host,
  120. + RenderFrameHost* render_frame_host,
  121. const blink::StorageKey& storage_key,
  122. const GURL& document_url,
  123. const WeakDocumentPtr& weak_document_ptr,
  124. diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
  125. index 7f34ad97947dfb3dccc29edeb06365b007236183..1165a7e81de03921ab774006cfb06f928cb2632e 100644
  126. --- a/content/browser/renderer_host/render_process_host_impl.cc
  127. +++ b/content/browser/renderer_host/render_process_host_impl.cc
  128. @@ -2230,7 +2230,7 @@ void RenderProcessHostImpl::CreateNotificationService(
  129. case RenderProcessHost::NotificationServiceCreatorType::kSharedWorker:
  130. case RenderProcessHost::NotificationServiceCreatorType::kDedicatedWorker: {
  131. storage_partition_impl_->GetPlatformNotificationContext()->CreateService(
  132. - this, storage_key, /*document_url=*/GURL(), weak_document_ptr,
  133. + this, rfh, storage_key, /*document_url=*/GURL(), weak_document_ptr,
  134. creator_type, std::move(receiver));
  135. break;
  136. }
  137. @@ -2238,7 +2238,7 @@ void RenderProcessHostImpl::CreateNotificationService(
  138. CHECK(rfh);
  139. storage_partition_impl_->GetPlatformNotificationContext()->CreateService(
  140. - this, storage_key, rfh->GetLastCommittedURL(), weak_document_ptr,
  141. + this, rfh, storage_key, rfh->GetLastCommittedURL(), weak_document_ptr,
  142. creator_type, std::move(receiver));
  143. break;
  144. }
  145. diff --git a/content/public/browser/platform_notification_service.h b/content/public/browser/platform_notification_service.h
  146. index d9e36712dc3fbc6a9043e2c33660090ca2f7367b..7d910583eb22fc315eb0619febe518d5c24c0c4d 100644
  147. --- a/content/public/browser/platform_notification_service.h
  148. +++ b/content/public/browser/platform_notification_service.h
  149. @@ -26,6 +26,8 @@ struct PlatformNotificationData;
  150. namespace content {
  151. +class RenderFrameHost;
  152. +
  153. // The service using which notifications can be presented to the user. There
  154. // should be a unique instance of the PlatformNotificationService depending
  155. // on the browsing context being used.
  156. @@ -41,6 +43,7 @@ class CONTENT_EXPORT PlatformNotificationService {
  157. // This method must be called on the UI thread. |document_url| is empty when
  158. // the display notification originates from a worker.
  159. virtual void DisplayNotification(
  160. + RenderFrameHost* render_frame_host,
  161. const std::string& notification_id,
  162. const GURL& origin,
  163. const GURL& document_url,
  164. diff --git a/content/test/mock_platform_notification_service.cc b/content/test/mock_platform_notification_service.cc
  165. index c9a01dd2bd6e0de08c09b417c3dce5ef13adb304..ded3b477c9766a77cd8fe1c2646bcc1935ebb1ec 100644
  166. --- a/content/test/mock_platform_notification_service.cc
  167. +++ b/content/test/mock_platform_notification_service.cc
  168. @@ -29,6 +29,7 @@ MockPlatformNotificationService::MockPlatformNotificationService(
  169. MockPlatformNotificationService::~MockPlatformNotificationService() = default;
  170. void MockPlatformNotificationService::DisplayNotification(
  171. + RenderFrameHost* render_frame_host,
  172. const std::string& notification_id,
  173. const GURL& origin,
  174. const GURL& document_url,
  175. diff --git a/content/test/mock_platform_notification_service.h b/content/test/mock_platform_notification_service.h
  176. index 7cd457defa729855c8d7c9d873efab5389d025cd..2b8e644d54d93a9499adcc1bf5660d72a24e2f29 100644
  177. --- a/content/test/mock_platform_notification_service.h
  178. +++ b/content/test/mock_platform_notification_service.h
  179. @@ -52,6 +52,7 @@ class MockPlatformNotificationService : public PlatformNotificationService {
  180. // PlatformNotificationService implementation.
  181. void DisplayNotification(
  182. + RenderFrameHost* render_frame_host,
  183. const std::string& notification_id,
  184. const GURL& origin,
  185. const GURL& document_url,