Code cleanup with Chromium's coding style

This commit is contained in:
Cheng Zhao 2015-11-10 18:27:18 +08:00
parent 37a89ee0d9
commit 1b9c9e40e3
5 changed files with 358 additions and 358 deletions

View file

@ -164,8 +164,11 @@
'msvs_settings': {
'VCLinkerTool': {
'AdditionalDependencies': [
# Windows Runtime.
'crypt32.lib',
'runtimeobject.lib',
'windowsapp.lib'
'shlwapi.lib',
'windowsapp.lib',
],
},
},
@ -203,8 +206,6 @@
'msvs_settings': {
'VCLinkerTool': {
'AdditionalDependencies': [
'Shlwapi.lib',
'Crypt32.lib',
'advapi32.lib',
'dbghelp.lib',
'delayimp.lib',

View file

@ -5,13 +5,12 @@
#include "browser/win/notification_presenter_win.h"
#include "base/win/windows_version.h"
#include "common/application_info.h"
#include "content/public/browser/desktop_notification_delegate.h"
#include "content/public/common/platform_notification_data.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "common/application_info.h"
#pragma comment(lib, "runtimeobject.lib")
#pragma comment(lib, "Crypt32.lib")
using namespace WinToasts;
using namespace Microsoft::WRL;
@ -38,7 +37,6 @@ void NotificationPresenterWin::ShowNotification(
const SkBitmap& icon,
scoped_ptr<content::DesktopNotificationDelegate> delegate_ptr,
base::Closure* cancel_callback) {
std::wstring title = data.title;
std::wstring body = data.body;
std::string iconPath = data.icon.spec();

View file

@ -13,9 +13,8 @@
// windowsNotification.onclick = function () { console.log("Notification clicked") };
// windowsNotification.onclose = function () { console.log("Notification dismissed") };
#ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_WIN_H_
#define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_WIN_H_
#ifndef BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_
#define BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_
#include "base/compiler_specific.h"
#include "browser/notification_presenter.h"
@ -48,4 +47,4 @@ class NotificationPresenterWin : public NotificationPresenter {
} // namespace
#endif // BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_WIN_H_
#endif // BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_

View file

@ -3,25 +3,28 @@
// Thanks to both of those folks mentioned above who first thought up a bunch of this code
// and released it as MIT to the world.
#include "windows_toast_notification.h"
#include "browser/win/windows_toast_notification.h"
#include "content/public/browser/desktop_notification_delegate.h"
using namespace WinToasts;
using namespace Microsoft::WRL;
using namespace ABI::Windows::UI::Notifications;
using namespace ABI::Windows::Data::Xml::Dom;
#define BREAK_IF_BAD(hr) if(!SUCCEEDED(hr)) break;
namespace WinToasts {
// Initialize Windows Runtime
static HRESULT init = Windows::Foundation::Initialize(RO_INIT_MULTITHREADED);
namespace {
WindowsToastNotification::WindowsToastNotification(const char* appName, content::DesktopNotificationDelegate* delegate)
{
HSTRING toastNotifMgrStr = NULL;
HSTRING appId = NULL;
// Initialize Windows Runtime
HRESULT init = Windows::Foundation::Initialize(RO_INIT_MULTITHREADED);
} // namespace
WindowsToastNotification::WindowsToastNotification(
const char* appName, content::DesktopNotificationDelegate* delegate) {
HSTRING toastNotifMgrStr = nullptr;
HSTRING appId = nullptr;
HRESULT hr = CreateHString(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager, &toastNotifMgrStr);
@ -33,28 +36,27 @@ WindowsToastNotification::WindowsToastNotification(const char* appName, content:
m_toastManager->CreateToastNotifierWithId(appId, &m_toastNotifier);
if (toastNotifMgrStr != NULL) {
if (toastNotifMgrStr) {
WindowsDeleteString(toastNotifMgrStr);
}
if (appId != NULL) {
if (appId) {
WindowsDeleteString(appId);
}
n_delegate = delegate;
}
WindowsToastNotification::~WindowsToastNotification()
{
WindowsToastNotification::~WindowsToastNotification() {
if (n_delegate) {
delete n_delegate;
}
}
void WindowsToastNotification::ShowNotification(const WCHAR* title, const WCHAR* msg, std::string iconPath, ComPtr<IToastNotification>& toast)
{
void WindowsToastNotification::ShowNotification(
const WCHAR* title, const WCHAR* msg, std::string iconPath, ComPtr<IToastNotification>& toast) {
HRESULT hr;
HSTRING toastNotifStr = NULL;
HSTRING toastNotifStr = nullptr;
do {
ComPtr<IXmlDocument> toastXml;
@ -80,23 +82,21 @@ void WindowsToastNotification::ShowNotification(const WCHAR* title, const WCHAR*
n_delegate->NotificationDisplayed();
} while (FALSE);
if (toastNotifStr != NULL) {
if (toastNotifStr) {
WindowsDeleteString(toastNotifStr);
}
}
void WindowsToastNotification::DismissNotification(ComPtr<IToastNotification> toast)
{
void WindowsToastNotification::DismissNotification(
ComPtr<IToastNotification> toast) {
m_toastNotifier->Hide(toast.Get());
}
void WindowsToastNotification::NotificationClicked()
{
void WindowsToastNotification::NotificationClicked() {
delete this;
}
void WindowsToastNotification::NotificationDismissed()
{
void WindowsToastNotification::NotificationDismissed() {
delete this;
}
@ -106,7 +106,6 @@ HRESULT WindowsToastNotification::GetToastXml(
const WCHAR* msg,
std::string iconPath,
IXmlDocument** toastXml) {
HRESULT hr;
ToastTemplateType templateType;
if (title == NULL || msg == NULL) {
@ -139,8 +138,8 @@ HRESULT WindowsToastNotification::GetToastXml(
return hr;
}
HRESULT WindowsToastNotification::SetXmlText(IXmlDocument* doc, const WCHAR* text)
{
HRESULT WindowsToastNotification::SetXmlText(
IXmlDocument* doc, const WCHAR* text) {
HSTRING tag = NULL;
ComPtr<IXmlNodeList> nodeList;
@ -162,8 +161,8 @@ HRESULT WindowsToastNotification::SetXmlText(IXmlDocument* doc, const WCHAR* tex
return hr;
}
HRESULT WindowsToastNotification::SetXmlText(IXmlDocument* doc, const WCHAR* title, const WCHAR* body)
{
HRESULT WindowsToastNotification::SetXmlText(
IXmlDocument* doc, const WCHAR* title, const WCHAR* body) {
HSTRING tag = NULL;
ComPtr<IXmlNodeList> nodeList;
HRESULT hr = GetTextNodeList(&tag, doc, &nodeList, 2);
@ -190,8 +189,8 @@ HRESULT WindowsToastNotification::SetXmlText(IXmlDocument* doc, const WCHAR* tit
return hr;
}
HRESULT WindowsToastNotification::SetXmlImage(IXmlDocument* doc, std::string iconPath)
{
HRESULT WindowsToastNotification::SetXmlImage(
IXmlDocument* doc, std::string iconPath) {
HSTRING tag = NULL;
HSTRING src = NULL;
HSTRING imgPath = NULL;
@ -249,8 +248,11 @@ HRESULT WindowsToastNotification::SetXmlImage(IXmlDocument* doc, std::string ico
return hr;
}
HRESULT WindowsToastNotification::GetTextNodeList(HSTRING* tag, IXmlDocument* doc, IXmlNodeList** nodeList, UINT32 reqLength)
{
HRESULT WindowsToastNotification::GetTextNodeList(
HSTRING* tag,
IXmlDocument* doc,
IXmlNodeList** nodeList,
UINT32 reqLength) {
HRESULT hr = CreateHString(L"text", tag);
do {
BREAK_IF_BAD(hr);
@ -275,8 +277,8 @@ HRESULT WindowsToastNotification::GetTextNodeList(HSTRING* tag, IXmlDocument* do
return hr;
}
HRESULT WindowsToastNotification::AppendTextToXml(IXmlDocument* doc, IXmlNode* node, const WCHAR* text)
{
HRESULT WindowsToastNotification::AppendTextToXml(
IXmlDocument* doc, IXmlNode* node, const WCHAR* text) {
HSTRING str = NULL;
HRESULT hr = CreateHString(text, &str);
do {
@ -301,8 +303,7 @@ HRESULT WindowsToastNotification::AppendTextToXml(IXmlDocument* doc, IXmlNode* n
return hr;
}
HRESULT WindowsToastNotification::SetupCallbacks(IToastNotification* toast)
{
HRESULT WindowsToastNotification::SetupCallbacks(IToastNotification* toast) {
EventRegistrationToken activatedToken, dismissedToken;
m_eventHandler = Make<ToastEventHandler>(this, n_delegate);
HRESULT hr = toast->add_Activated(m_eventHandler.Get(), &activatedToken);
@ -314,8 +315,8 @@ HRESULT WindowsToastNotification::SetupCallbacks(IToastNotification* toast)
return hr;
}
HRESULT WindowsToastNotification::CreateHString(const WCHAR* source, HSTRING* dest)
{
HRESULT WindowsToastNotification::CreateHString(
const WCHAR* source, HSTRING* dest) {
if (source == NULL || dest == NULL) {
return E_INVALIDARG;
}
@ -327,19 +328,18 @@ HRESULT WindowsToastNotification::CreateHString(const WCHAR* source, HSTRING* de
/*
/ Toast Event Handler
*/
ToastEventHandler::ToastEventHandler(WindowsToastNotification* notification, content::DesktopNotificationDelegate* delegate)
{
ToastEventHandler::ToastEventHandler(
WindowsToastNotification* notification,
content::DesktopNotificationDelegate* delegate) {
m_notification = notification;
n_delegate = delegate;
}
ToastEventHandler::~ToastEventHandler()
{
// Empty
ToastEventHandler::~ToastEventHandler() {
}
IFACEMETHODIMP ToastEventHandler::Invoke(IToastNotification* sender, IInspectable* args)
{
IFACEMETHODIMP ToastEventHandler::Invoke(
IToastNotification* sender, IInspectable* args) {
// Notification "activated" (clicked)
n_delegate->NotificationClick();
@ -350,14 +350,13 @@ IFACEMETHODIMP ToastEventHandler::Invoke(IToastNotification* sender, IInspectabl
return S_OK;
}
IFACEMETHODIMP ToastEventHandler::Invoke(IToastNotification* sender, IToastDismissedEventArgs* e)
{
IFACEMETHODIMP ToastEventHandler::Invoke(
IToastNotification* sender, IToastDismissedEventArgs* e) {
// Notification dismissed
n_delegate->NotificationClosed();
if (m_notification != NULL) {
m_notification->NotificationDismissed();
}
return S_OK;

View file

@ -3,33 +3,35 @@
// Thanks to both of those folks mentioned above who first thought up a bunch of this code
// and released it as MIT to the world.
#ifndef __WINDOWS_TOAST_NOTIFICATION_H__
#define __WINDOWS_TOAST_NOTIFICATION_H__
#include "content/public/browser/desktop_notification_delegate.h"
#include "content/public/common/platform_notification_data.h"
#include "base/bind.h"
#ifndef BRIGHTRAY_BROWSER_WIN_WINDOWS_TOAST_NOTIFICATION_H_
#define BRIGHTRAY_BROWSER_WIN_WINDOWS_TOAST_NOTIFICATION_H_
#include <windows.h>
#include <windows.ui.notifications.h>
#include <wrl/implements.h>
#include "base/bind.h"
#include "content/public/browser/desktop_notification_delegate.h"
#include "content/public/common/platform_notification_data.h"
using namespace Microsoft::WRL;
using namespace ABI::Windows::UI::Notifications;
using namespace ABI::Windows::Foundation;
namespace WinToasts {
typedef ITypedEventHandler<ToastNotification*, IInspectable*> DesktopToastActivatedEventHandler;
typedef ITypedEventHandler<ToastNotification*, ToastDismissedEventArgs*> DesktopToastDismissedEventHandler;
using DesktopToastActivatedEventHandler =
ITypedEventHandler<ToastNotification*, IInspectable*>;
using DesktopToastDismissedEventHandler =
ITypedEventHandler<ToastNotification*, ToastDismissedEventArgs*>;
class ToastEventHandler;
class WindowsToastNotification
{
class WindowsToastNotification {
public:
WindowsToastNotification(const char* appName, content::DesktopNotificationDelegate* delegate);
~WindowsToastNotification();
void ShowNotification(const WCHAR* title, const WCHAR* msg, std::string iconPath, ComPtr<IToastNotification>& toast);
void DismissNotification(ComPtr<IToastNotification> toast);
void NotificationClicked();
@ -53,12 +55,13 @@ namespace WinToasts {
};
class ToastEventHandler :
public RuntimeClass<RuntimeClassFlags<ClassicCom>, DesktopToastActivatedEventHandler, DesktopToastDismissedEventHandler>
{
class ToastEventHandler : public RuntimeClass<RuntimeClassFlags<ClassicCom>,
DesktopToastActivatedEventHandler,
DesktopToastDismissedEventHandler> {
public:
ToastEventHandler(WindowsToastNotification* notification, content::DesktopNotificationDelegate* delegate);
~ToastEventHandler();
IFACEMETHODIMP Invoke(IToastNotification* sender, IInspectable* args);
IFACEMETHODIMP Invoke(IToastNotification* sender, IToastDismissedEventArgs* e);
@ -69,4 +72,4 @@ namespace WinToasts {
} // namespace
#endif //__WINDOWS_TOAST_NOTIFICATION_H__
#endif // BRIGHTRAY_BROWSER_WIN_WINDOWS_TOAST_NOTIFICATION_H_