Expose NotificationPresenter to public

This commit is contained in:
Cheng Zhao 2015-12-24 22:20:47 +08:00
parent 9897f3aab0
commit 6f81d1e29f
5 changed files with 57 additions and 58 deletions

View file

@ -4,15 +4,19 @@
#include "browser/browser_client.h"
#include "base/path_service.h"
#include "browser/browser_context.h"
#include "browser/browser_main_parts.h"
#include "browser/devtools_manager_delegate.h"
#include "browser/media/media_capture_devices_dispatcher.h"
#include "browser/platform_notification_service_impl.h"
#include "base/path_service.h"
#include "browser/notification_presenter.h"
#include "browser/platform_notification_service.h"
#include "content/public/common/url_constants.h"
#if defined(OS_WIN)
#include "base/win/windows_version.h"
#endif
namespace brightray {
namespace {
@ -38,6 +42,20 @@ BrowserContext* BrowserClient::browser_context() {
return browser_main_parts_->browser_context();
}
NotificationPresenter* BrowserClient::GetNotificationPresenter() {
#if defined(OS_WIN)
// Bail out if on Windows 7 or even lower, no operating will follow
if (base::win::GetVersion() < base::win::VERSION_WIN8)
return nullptr;
#endif
if (!notification_presenter_) {
// Create a new presenter if on OS X, Linux, or Windows 8+
notification_presenter_.reset(NotificationPresenter::Create());
}
return notification_presenter_.get();
}
BrowserMainParts* BrowserClient::OverrideCreateBrowserMainParts(
const content::MainFunctionParams&) {
return new BrowserMainParts;
@ -65,7 +83,9 @@ content::MediaObserver* BrowserClient::GetMediaObserver() {
}
content::PlatformNotificationService* BrowserClient::GetPlatformNotificationService() {
return PlatformNotificationServiceImpl::GetInstance();
if (!notification_service_)
notification_service_.reset(new PlatformNotificationService(this));
return notification_service_.get();
}
void BrowserClient::GetAdditionalAllowedSchemesForFileSystem(

View file

@ -13,6 +13,8 @@ namespace brightray {
class BrowserContext;
class BrowserMainParts;
class NetLog;
class NotificationPresenter;
class PlatformNotificationService;
class BrowserClient : public content::ContentBrowserClient {
public:
@ -24,6 +26,8 @@ class BrowserClient : public content::ContentBrowserClient {
BrowserContext* browser_context();
BrowserMainParts* browser_main_parts() { return browser_main_parts_; }
NotificationPresenter* GetNotificationPresenter();
protected:
// Subclasses should override this to provide their own BrowserMainParts
// implementation. The lifetime of the returned instance is managed by the
@ -51,6 +55,9 @@ class BrowserClient : public content::ContentBrowserClient {
NetLog net_log_;
private:
scoped_ptr<PlatformNotificationService> notification_service_;
scoped_ptr<NotificationPresenter> notification_presenter_;
DISALLOW_COPY_AND_ASSIGN(BrowserClient);
};

View file

@ -2,68 +2,48 @@
// 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/platform_notification_service.h"
#include "browser/browser_client.h"
#include "browser/notification_presenter.h"
#include "content/public/browser/desktop_notification_delegate.h"
#if defined(OS_WIN)
#include "base/win/windows_version.h"
#endif
namespace brightray {
// static
PlatformNotificationServiceImpl*
PlatformNotificationServiceImpl::GetInstance() {
return base::Singleton<PlatformNotificationServiceImpl>::get();
PlatformNotificationService::PlatformNotificationService(
BrowserClient* browser_client)
: browser_client_(browser_client) {
}
PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() {}
PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {}
PlatformNotificationService::~PlatformNotificationService() {}
NotificationPresenter* PlatformNotificationServiceImpl::notification_presenter() {
#if defined(OS_WIN)
// Bail out if on Windows 7 or even lower, no operating will follow
if (base::win::GetVersion() < base::win::VERSION_WIN8)
return nullptr;
#endif
if (!notification_presenter_) {
// Create a new presenter if on OS X, Linux, or Windows 8+
notification_presenter_.reset(NotificationPresenter::Create());
}
return notification_presenter_.get();
}
blink::WebNotificationPermission PlatformNotificationServiceImpl::CheckPermissionOnUIThread(
blink::WebNotificationPermission PlatformNotificationService::CheckPermissionOnUIThread(
content::BrowserContext* browser_context,
const GURL& origin,
int render_process_id) {
return blink::WebNotificationPermissionAllowed;
}
blink::WebNotificationPermission PlatformNotificationServiceImpl::CheckPermissionOnIOThread(
blink::WebNotificationPermission PlatformNotificationService::CheckPermissionOnIOThread(
content::ResourceContext* resource_context,
const GURL& origin,
int render_process_id) {
return blink::WebNotificationPermissionAllowed;
}
void PlatformNotificationServiceImpl::DisplayNotification(
void PlatformNotificationService::DisplayNotification(
content::BrowserContext* browser_context,
const GURL& origin,
const SkBitmap& icon,
const content::PlatformNotificationData& notification_data,
scoped_ptr<content::DesktopNotificationDelegate> delegate,
base::Closure* cancel_callback) {
auto presenter = notification_presenter();
auto presenter = browser_client_->GetNotificationPresenter();
if (presenter)
presenter->ShowNotification(notification_data, icon, delegate.Pass(), cancel_callback);
}
void PlatformNotificationServiceImpl::DisplayPersistentNotification(
void PlatformNotificationService::DisplayPersistentNotification(
content::BrowserContext* browser_context,
int64_t service_worker_registration_id,
const GURL& origin,
@ -71,12 +51,12 @@ void PlatformNotificationServiceImpl::DisplayPersistentNotification(
const content::PlatformNotificationData& notification_data) {
}
void PlatformNotificationServiceImpl::ClosePersistentNotification(
void PlatformNotificationService::ClosePersistentNotification(
content::BrowserContext* browser_context,
int64_t persistent_notification_id) {
}
bool PlatformNotificationServiceImpl::GetDisplayedPersistentNotifications(
bool PlatformNotificationService::GetDisplayedPersistentNotifications(
content::BrowserContext* browser_context,
std::set<std::string>* displayed_notifications) {
return false;

View file

@ -2,31 +2,22 @@
// 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_
#ifndef BROWSER_PLATFORM_NOTIFICATION_SERVICE_H_
#define BROWSER_PLATFORM_NOTIFICATION_SERVICE_H_
#include "base/memory/singleton.h"
#include "content/public/browser/platform_notification_service.h"
namespace brightray {
class NotificationPresenter;
class BrowserClient;
class PlatformNotificationServiceImpl
class PlatformNotificationService
: 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 base::DefaultSingletonTraits<PlatformNotificationServiceImpl>;
PlatformNotificationServiceImpl();
~PlatformNotificationServiceImpl() override;
explicit PlatformNotificationService(BrowserClient* browser_client);
~PlatformNotificationService() override;
protected:
// content::PlatformNotificationService:
blink::WebNotificationPermission CheckPermissionOnUIThread(
content::BrowserContext* browser_context,
@ -56,11 +47,12 @@ class PlatformNotificationServiceImpl
content::BrowserContext* browser_context,
std::set<std::string>* displayed_notifications) override;
scoped_ptr<NotificationPresenter> notification_presenter_;
private:
BrowserClient* browser_client_;
DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl);
DISALLOW_COPY_AND_ASSIGN(PlatformNotificationService);
};
} // namespace brightray
#endif // BROWSER_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_
#endif // BROWSER_PLATFORM_NOTIFICATION_SERVICE_H_

View file

@ -64,8 +64,8 @@
'browser/notification.h',
'browser/permission_manager.cc',
'browser/permission_manager.h',
'browser/platform_notification_service_impl.cc',
'browser/platform_notification_service_impl.h',
'browser/platform_notification_service.cc',
'browser/platform_notification_service.h',
'browser/linux/libnotify_loader.h',
'browser/linux/libnotify_loader.cc',
'browser/linux/notification_presenter_linux.h',