diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 736d169ec6cd..17057574e68b 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -71,6 +71,8 @@ 'browser/notification_presenter.h', 'browser/notification_presenter_mac.h', 'browser/notification_presenter_mac.mm', + 'browser/platform_notification_service_impl.cc', + 'browser/platform_notification_service_impl.h', 'browser/linux/notification_presenter_linux.h', 'browser/linux/notification_presenter_linux.cc', 'browser/remote_debugging_server.cc', diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index b391cffaf8d3..b884cdcdbf1c 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -8,7 +8,7 @@ #include "browser/browser_main_parts.h" #include "browser/devtools_manager_delegate.h" #include "browser/media/media_capture_devices_dispatcher.h" -#include "browser/notification_presenter.h" +#include "browser/platform_notification_service_impl.h" #include "base/base_paths.h" #include "base/path_service.h" @@ -39,14 +39,6 @@ BrowserContext* BrowserClient::browser_context() { return browser_main_parts_->browser_context(); } -NotificationPresenter* BrowserClient::notification_presenter() { -#if defined(OS_MACOSX) || defined(OS_LINUX) - if (!notification_presenter_) - notification_presenter_.reset(NotificationPresenter::Create()); -#endif - return notification_presenter_.get(); -} - BrowserMainParts* BrowserClient::OverrideCreateBrowserMainParts( const content::MainFunctionParams&) { return new BrowserMainParts; @@ -67,21 +59,14 @@ net::URLRequestContextGetter* BrowserClient::CreateRequestContext( return context->CreateRequestContext(protocol_handlers, protocol_interceptors.Pass()); } -void BrowserClient::ShowDesktopNotification( - const content::ShowDesktopNotificationHostMsgParams& params, - content::BrowserContext* browser_context, - int render_process_id, - scoped_ptr delegate, - base::Closure* cancel_callback) { - auto presenter = notification_presenter(); - if (presenter) - presenter->ShowNotification(params, delegate.Pass(), cancel_callback); -} - content::MediaObserver* BrowserClient::GetMediaObserver() { return MediaCaptureDevicesDispatcher::GetInstance(); } +content::PlatformNotificationService* BrowserClient::GetPlatformNotificationService() { + return PlatformNotificationServiceImpl::GetInstance(); +} + void BrowserClient::GetAdditionalAllowedSchemesForFileSystem( std::vector* additional_schemes) { additional_schemes->push_back(content::kChromeDevToolsScheme); diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index e3e256249dea..fad326e10bc7 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -11,7 +11,6 @@ namespace brightray { class BrowserContext; class BrowserMainParts; -class NotificationPresenter; class BrowserClient : public content::ContentBrowserClient { public: @@ -22,7 +21,6 @@ class BrowserClient : public content::ContentBrowserClient { BrowserContext* browser_context(); BrowserMainParts* browser_main_parts() { return browser_main_parts_; } - NotificationPresenter* notification_presenter(); protected: // Subclasses should override this to provide their own BrowserMainParts @@ -41,20 +39,14 @@ class BrowserClient : public content::ContentBrowserClient { private: content::BrowserMainParts* CreateBrowserMainParts( const content::MainFunctionParams&) override; - void ShowDesktopNotification( - const content::ShowDesktopNotificationHostMsgParams& params, - content::BrowserContext* browser_context, - int render_process_id, - scoped_ptr delegate, - base::Closure* cancel_callback) override; content::MediaObserver* GetMediaObserver() override; + content::PlatformNotificationService* GetPlatformNotificationService() override; void GetAdditionalAllowedSchemesForFileSystem( std::vector* additional_schemes) override; base::FilePath GetDefaultDownloadDirectory() override; content::DevToolsManagerDelegate* GetDevToolsManagerDelegate() override; BrowserMainParts* browser_main_parts_; - scoped_ptr notification_presenter_; DISALLOW_COPY_AND_ASSIGN(BrowserClient); }; diff --git a/brightray/browser/notification_presenter.h b/brightray/browser/notification_presenter.h index 6c7def322ae1..ad17cdb3c531 100644 --- a/brightray/browser/notification_presenter.h +++ b/brightray/browser/notification_presenter.h @@ -6,7 +6,7 @@ namespace content { class DesktopNotificationDelegate; -struct ShowDesktopNotificationHostMsgParams; +struct PlatformNotificationData; } namespace brightray { @@ -18,7 +18,7 @@ class NotificationPresenter { static NotificationPresenter* Create(); virtual void ShowNotification( - const content::ShowDesktopNotificationHostMsgParams&, + const content::PlatformNotificationData&, scoped_ptr delegate, base::Closure* cancel_callback) = 0; }; diff --git a/brightray/browser/notification_presenter_mac.h b/brightray/browser/notification_presenter_mac.h index 508ad315f018..0ba7fe7c35e2 100644 --- a/brightray/browser/notification_presenter_mac.h +++ b/brightray/browser/notification_presenter_mac.h @@ -21,7 +21,7 @@ class NotificationPresenterMac : public NotificationPresenter { ~NotificationPresenterMac(); virtual void ShowNotification( - const content::ShowDesktopNotificationHostMsgParams&, + const content::PlatformNotificationData&, scoped_ptr delegate, base::Closure* cancel_callback) override; diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index 78e3cc2fd455..f0a08d759742 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -8,8 +8,8 @@ #include "base/bind.h" #include "base/stl_util.h" #include "base/strings/sys_string_conversions.h" +#include "content/public/common/platform_notification_data.h" #include "content/public/browser/desktop_notification_delegate.h" -#include "content/public/common/show_desktop_notification_params.h" #import @@ -40,12 +40,12 @@ NotificationPresenterMac::~NotificationPresenterMac() { } void NotificationPresenterMac::ShowNotification( - const content::ShowDesktopNotificationHostMsgParams& params, + const content::PlatformNotificationData& data, scoped_ptr delegate, base::Closure* cancel_callback) { auto notification = [[NSUserNotification alloc] init]; - notification.title = base::SysUTF16ToNSString(params.title); - notification.informativeText = base::SysUTF16ToNSString(params.body); + notification.title = base::SysUTF16ToNSString(data.title); + notification.informativeText = base::SysUTF16ToNSString(data.body); notifications_map_[delegate.get()].reset(notification); [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification]; diff --git a/brightray/browser/platform_notification_service_impl.cc b/brightray/browser/platform_notification_service_impl.cc new file mode 100644 index 000000000000..f47d3851198d --- /dev/null +++ b/brightray/browser/platform_notification_service_impl.cc @@ -0,0 +1,64 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/platform_notification_service_impl.h" + +#include "browser/notification_presenter.h" + +#include "content/public/browser/desktop_notification_delegate.h" + +namespace brightray { + +// static +PlatformNotificationServiceImpl* +PlatformNotificationServiceImpl::GetInstance() { + return Singleton::get(); +} + +PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() {} +PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} + +NotificationPresenter* PlatformNotificationServiceImpl::notification_presenter() { +#if defined(OS_MACOSX) || defined(OS_LINUX) + if (!notification_presenter_) + notification_presenter_.reset(NotificationPresenter::Create()); +#endif + return notification_presenter_.get(); +} + +blink::WebNotificationPermission PlatformNotificationServiceImpl::CheckPermission( + content::ResourceContext* resource_context, + const GURL& origin, + int render_process_id) { + return blink::WebNotificationPermissionAllowed; +} + +void PlatformNotificationServiceImpl::DisplayNotification( + content::BrowserContext* browser_context, + const GURL& origin, + const SkBitmap& icon, + const content::PlatformNotificationData& notification_data, + scoped_ptr delegate, + int render_process_id, + base::Closure* cancel_callback) { + auto presenter = notification_presenter(); + if (presenter) + presenter->ShowNotification(notification_data, delegate.Pass(), cancel_callback); +} + +void PlatformNotificationServiceImpl::DisplayPersistentNotification( + content::BrowserContext* browser_context, + int64 service_worker_registration_id, + const GURL& origin, + const SkBitmap& icon, + const content::PlatformNotificationData& notification_data, + int render_process_id) { +} + +void PlatformNotificationServiceImpl::ClosePersistentNotification( + content::BrowserContext* browser_context, + const std::string& persistent_notification_id) { +} + +} // namespace brightray diff --git a/brightray/browser/platform_notification_service_impl.h b/brightray/browser/platform_notification_service_impl.h new file mode 100644 index 000000000000..1a542bcc89b1 --- /dev/null +++ b/brightray/browser/platform_notification_service_impl.h @@ -0,0 +1,61 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BROWSER_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ +#define BROWSER_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ + +#include "base/memory/singleton.h" +#include "content/public/browser/platform_notification_service.h" + +namespace brightray { + +class NotificationPresenter; + +class PlatformNotificationServiceImpl + : public content::PlatformNotificationService { + public: + // Returns the active instance of the service in the browser process. Safe to + // be called from any thread. + static PlatformNotificationServiceImpl* GetInstance(); + + NotificationPresenter* notification_presenter(); + + private: + friend struct DefaultSingletonTraits; + + PlatformNotificationServiceImpl(); + ~PlatformNotificationServiceImpl() override; + + // content::PlatformNotificationService: + virtual blink::WebNotificationPermission CheckPermission( + content::ResourceContext* resource_context, + const GURL& origin, + int render_process_id) override; + virtual void DisplayNotification( + content::BrowserContext* browser_context, + const GURL& origin, + const SkBitmap& icon, + const content::PlatformNotificationData& notification_data, + scoped_ptr delegate, + int render_process_id, + base::Closure* cancel_callback) override; + virtual void DisplayPersistentNotification( + content::BrowserContext* browser_context, + int64 service_worker_registration_id, + const GURL& origin, + const SkBitmap& icon, + const content::PlatformNotificationData& notification_data, + int render_process_id) override; + virtual void ClosePersistentNotification( + content::BrowserContext* browser_context, + const std::string& persistent_notification_id) override; + + scoped_ptr notification_presenter_; + + DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); +}; + +} // namespace brightray + +#endif // BROWSER_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_