Implement PlatformNotificationService
This commit is contained in:
parent
99e2dbd6e8
commit
a5026907e4
8 changed files with 140 additions and 36 deletions
|
@ -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',
|
||||
|
|
|
@ -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<content::DesktopNotificationDelegate> 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<std::string>* additional_schemes) {
|
||||
additional_schemes->push_back(content::kChromeDevToolsScheme);
|
||||
|
|
|
@ -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<content::DesktopNotificationDelegate> delegate,
|
||||
base::Closure* cancel_callback) override;
|
||||
content::MediaObserver* GetMediaObserver() override;
|
||||
content::PlatformNotificationService* GetPlatformNotificationService() override;
|
||||
void GetAdditionalAllowedSchemesForFileSystem(
|
||||
std::vector<std::string>* additional_schemes) override;
|
||||
base::FilePath GetDefaultDownloadDirectory() override;
|
||||
content::DevToolsManagerDelegate* GetDevToolsManagerDelegate() override;
|
||||
|
||||
BrowserMainParts* browser_main_parts_;
|
||||
scoped_ptr<NotificationPresenter> notification_presenter_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(BrowserClient);
|
||||
};
|
||||
|
|
|
@ -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<content::DesktopNotificationDelegate> delegate,
|
||||
base::Closure* cancel_callback) = 0;
|
||||
};
|
||||
|
|
|
@ -21,7 +21,7 @@ class NotificationPresenterMac : public NotificationPresenter {
|
|||
~NotificationPresenterMac();
|
||||
|
||||
virtual void ShowNotification(
|
||||
const content::ShowDesktopNotificationHostMsgParams&,
|
||||
const content::PlatformNotificationData&,
|
||||
scoped_ptr<content::DesktopNotificationDelegate> delegate,
|
||||
base::Closure* cancel_callback) override;
|
||||
|
||||
|
|
|
@ -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 <Foundation/Foundation.h>
|
||||
|
||||
|
@ -40,12 +40,12 @@ NotificationPresenterMac::~NotificationPresenterMac() {
|
|||
}
|
||||
|
||||
void NotificationPresenterMac::ShowNotification(
|
||||
const content::ShowDesktopNotificationHostMsgParams& params,
|
||||
const content::PlatformNotificationData& data,
|
||||
scoped_ptr<content::DesktopNotificationDelegate> 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];
|
||||
|
|
64
brightray/browser/platform_notification_service_impl.cc
Normal file
64
brightray/browser/platform_notification_service_impl.cc
Normal file
|
@ -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<PlatformNotificationServiceImpl>::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<content::DesktopNotificationDelegate> 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
|
61
brightray/browser/platform_notification_service_impl.h
Normal file
61
brightray/browser/platform_notification_service_impl.h
Normal file
|
@ -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();
|
||||
~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<content::DesktopNotificationDelegate> 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<NotificationPresenter> notification_presenter_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl);
|
||||
};
|
||||
|
||||
} // namespace brightray
|
||||
|
||||
#endif // BROWSER_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_
|
Loading…
Reference in a new issue