From e28eeb0c2e566587a2c78d4803a8c0ed4dd11621 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Fri, 5 Oct 2018 14:24:38 -0700 Subject: [PATCH] fix notification permission handler --- .../browser/platform_notification_service.cc | 11 +- .../browser/platform_notification_service.h | 2 +- patches/common/chromium/.patches.yaml | 7 + .../chromium/notification_provenance.patch | 130 ++++++++++++++++++ 4 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 patches/common/chromium/notification_provenance.patch diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index cb653e3ddcfb..ef62e2388283 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -10,6 +10,7 @@ #include "brightray/browser/notification_delegate.h" #include "brightray/browser/notification_presenter.h" #include "content/public/browser/notification_event_dispatcher.h" +#include "content/public/browser/render_process_host.h" #include "content/public/common/notification_resources.h" #include "content/public/common/platform_notification_data.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -72,11 +73,12 @@ class NotificationDelegateImpl final : public brightray::NotificationDelegate { PlatformNotificationService::PlatformNotificationService( BrowserClient* browser_client) - : browser_client_(browser_client), render_process_id_(-1) {} + : browser_client_(browser_client) {} PlatformNotificationService::~PlatformNotificationService() {} void PlatformNotificationService::DisplayNotification( + content::RenderProcessHost* render_process_host, content::BrowserContext* browser_context, const std::string& notification_id, const GURL& origin, @@ -90,9 +92,10 @@ void PlatformNotificationService::DisplayNotification( auto notification = presenter->CreateNotification(delegate, notification_id); if (notification) { browser_client_->WebNotificationAllowed( - render_process_id_, base::Bind(&OnWebNotificationAllowed, notification, - notification_resources.notification_icon, - notification_data)); + render_process_host->GetID(), + base::Bind(&OnWebNotificationAllowed, notification, + notification_resources.notification_icon, + notification_data)); } } diff --git a/brightray/browser/platform_notification_service.h b/brightray/browser/platform_notification_service.h index 6ad8d9cf6dcf..b8c7b793d031 100644 --- a/brightray/browser/platform_notification_service.h +++ b/brightray/browser/platform_notification_service.h @@ -24,6 +24,7 @@ class PlatformNotificationService protected: // content::PlatformNotificationService: void DisplayNotification( + content::RenderProcessHost* render_process_host, content::BrowserContext* browser_context, const std::string& notification_id, const GURL& origin, @@ -48,7 +49,6 @@ class PlatformNotificationService private: BrowserClient* browser_client_; - int render_process_id_; DISALLOW_COPY_AND_ASSIGN(PlatformNotificationService); }; diff --git a/patches/common/chromium/.patches.yaml b/patches/common/chromium/.patches.yaml index b5cd0a9a4f33..cc4f1e8fa8af 100644 --- a/patches/common/chromium/.patches.yaml +++ b/patches/common/chromium/.patches.yaml @@ -470,3 +470,10 @@ patches: Pass pre allocated isolate for initialization, node platform needs to register on an isolate so that it can be used later down in the initialization process of an isolate. +- + author: Jeremy Apthorp + file: notification_provenance.patch + description: | + Pass RenderProcessHost through to PlatformNotificationService. + + This is so Electron can identify which renderer a notification came from. diff --git a/patches/common/chromium/notification_provenance.patch b/patches/common/chromium/notification_provenance.patch new file mode 100644 index 000000000000..ffc104b1195a --- /dev/null +++ b/patches/common/chromium/notification_provenance.patch @@ -0,0 +1,130 @@ +From 5c9dd74385e37830bff8918b54868ac37042c513 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 cbcd2b5369fc..1b4066649d92 100644 +--- a/content/browser/notifications/blink_notification_service_impl.cc ++++ b/content/browser/notifications/blink_notification_service_impl.cc +@@ -40,9 +40,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), +@@ -99,7 +101,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 193f5d241c31..3cfcc6b86ae1 100644 +--- a/content/browser/notifications/blink_notification_service_impl.h ++++ b/content/browser/notifications/blink_notification_service_impl.h +@@ -33,6 +33,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; +@@ -94,6 +95,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/platform_notification_context_impl.cc b/content/browser/notifications/platform_notification_context_impl.cc +index 627e8dbd251d..48c290470e48 100644 +--- a/content/browser/notifications/platform_notification_context_impl.cc ++++ b/content/browser/notifications/platform_notification_context_impl.cc +@@ -122,12 +122,13 @@ void PlatformNotificationContextImpl::ShutdownOnIO() { + } + + 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 7ea92b626202..faa3a1d8069f 100644 +--- a/content/browser/notifications/platform_notification_context_impl.h ++++ b/content/browser/notifications/platform_notification_context_impl.h +@@ -21,6 +21,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; +@@ -65,7 +66,8 @@ class CONTENT_EXPORT PlatformNotificationContextImpl + + // Creates a BlinkNotificationServiceImpl that is owned by this context. Must + // be called on the UI thread. +- 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 896f1b27ded7..20a1f86a36fd 100644 +--- a/content/browser/renderer_interface_binders.cc ++++ b/content/browser/renderer_interface_binders.cc +@@ -168,7 +168,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::Create)); +diff --git a/content/public/browser/platform_notification_service.h b/content/public/browser/platform_notification_service.h +index 228fc30240c5..fd3e20c5335a 100644 +--- a/content/public/browser/platform_notification_service.h ++++ b/content/public/browser/platform_notification_service.h +@@ -21,6 +21,7 @@ class GURL; + namespace content { + + class BrowserContext; ++class RenderProcessHost; + struct NotificationResources; + struct PlatformNotificationData; + +@@ -38,6 +39,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, +-- +2.17.0 +