Move notification-related code into a new NotificationPresenter class

This commit is contained in:
Adam Roben 2013-03-28 17:49:29 -04:00
parent 1328c85eef
commit 3c41af84a1
6 changed files with 58 additions and 5 deletions

View file

@ -18,7 +18,6 @@
'sources': [
'browser/browser_client.cc',
'browser/browser_client.h',
'browser/browser_client_mac.mm',
'browser/browser_context.cc',
'browser/browser_context.h',
'browser/browser_main_parts.cc',
@ -43,6 +42,9 @@
'browser/mac/bry_inspectable_web_contents_view_private.h',
'browser/network_delegate.cc',
'browser/network_delegate.h',
'browser/notification_presenter.cc',
'browser/notification_presenter.h',
'browser/notification_presenter_mac.mm',
'browser/url_request_context_getter.cc',
'browser/url_request_context_getter.h',
'common/application_name.h',

View file

@ -6,6 +6,7 @@
#include "browser_context.h"
#include "browser_main_parts.h"
#include "notification_presenter.h"
namespace brightray {
@ -19,6 +20,12 @@ BrowserContext* BrowserClient::browser_context() {
return browser_main_parts_->browser_context();
}
NotificationPresenter* BrowserClient::notification_presenter() {
if (!notification_presenter_)
notification_presenter_.reset(new NotificationPresenter);
return notification_presenter_.get();
}
BrowserMainParts* BrowserClient::OverrideCreateBrowserMainParts(const content::MainFunctionParams&) {
return new BrowserMainParts;
}
@ -33,4 +40,12 @@ net::URLRequestContextGetter* BrowserClient::CreateRequestContext(content::Brows
return static_cast<BrowserContext*>(browser_context)->CreateRequestContext(protocol_handlers);
}
void BrowserClient::ShowDesktopNotification(
const content::ShowDesktopNotificationHostMsgParams& params,
int render_process_id,
int render_view_id,
bool worker) {
notification_presenter()->ShowNotification(params, render_process_id, render_view_id);
}
}

View file

@ -11,6 +11,7 @@ namespace brightray {
class BrowserContext;
class BrowserMainParts;
class NotificationPresenter;
class BrowserClient : public content::ContentBrowserClient {
public:
@ -19,6 +20,7 @@ public:
BrowserContext* browser_context();
BrowserMainParts* browser_main_parts() { return browser_main_parts_; }
NotificationPresenter* notification_presenter();
protected:
// Subclasses should override this to provide their own BrowserMainParts implementation. The
@ -35,6 +37,7 @@ private:
bool worker) OVERRIDE;
BrowserMainParts* browser_main_parts_;
scoped_ptr<NotificationPresenter> notification_presenter_;
DISALLOW_COPY_AND_ASSIGN(BrowserClient);
};

View file

@ -0,0 +1,11 @@
#include "browser/notification_presenter.h"
namespace brightray {
NotificationPresenter::NotificationPresenter() {
}
NotificationPresenter::~NotificationPresenter() {
}
}

View file

@ -0,0 +1,23 @@
#ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_H_
#define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_H_
namespace content {
struct ShowDesktopNotificationHostMsgParams;
}
namespace brightray {
class NotificationPresenter {
public:
NotificationPresenter();
~NotificationPresenter();
void ShowNotification(
const content::ShowDesktopNotificationHostMsgParams&,
int render_process_id,
int render_view_id);
};
}
#endif

View file

@ -1,4 +1,4 @@
#import "browser/browser_client.h"
#import "browser/notification_presenter.h"
#import "base/strings/sys_string_conversions.h"
#import "content/public/browser/render_view_host.h"
@ -8,11 +8,10 @@
namespace brightray {
void BrowserClient::ShowDesktopNotification(
void NotificationPresenter::ShowNotification(
const content::ShowDesktopNotificationHostMsgParams& params,
int render_process_id,
int render_view_id,
bool worker) {
int render_view_id) {
auto notification = [[NSUserNotification alloc] init];
notification.title = base::SysUTF16ToNSString(params.title);
notification.informativeText = base::SysUTF16ToNSString(params.body);