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': { 'msvs_settings': {
'VCLinkerTool': { 'VCLinkerTool': {
'AdditionalDependencies': [ 'AdditionalDependencies': [
# Windows Runtime.
'crypt32.lib',
'runtimeobject.lib', 'runtimeobject.lib',
'windowsapp.lib' 'shlwapi.lib',
'windowsapp.lib',
], ],
}, },
}, },
@ -203,8 +206,6 @@
'msvs_settings': { 'msvs_settings': {
'VCLinkerTool': { 'VCLinkerTool': {
'AdditionalDependencies': [ 'AdditionalDependencies': [
'Shlwapi.lib',
'Crypt32.lib',
'advapi32.lib', 'advapi32.lib',
'dbghelp.lib', 'dbghelp.lib',
'delayimp.lib', 'delayimp.lib',

View file

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

View file

@ -13,9 +13,8 @@
// windowsNotification.onclick = function () { console.log("Notification clicked") }; // windowsNotification.onclick = function () { console.log("Notification clicked") };
// windowsNotification.onclose = function () { console.log("Notification dismissed") }; // windowsNotification.onclose = function () { console.log("Notification dismissed") };
#ifndef BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_
#ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_WIN_H_ #define BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_
#define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_WIN_H_
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "browser/notification_presenter.h" #include "browser/notification_presenter.h"
@ -48,4 +47,4 @@ class NotificationPresenterWin : public NotificationPresenter {
} // namespace } // 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 // 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. // 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" #include "content/public/browser/desktop_notification_delegate.h"
using namespace WinToasts; using namespace WinToasts;
using namespace Microsoft::WRL;
using namespace ABI::Windows::UI::Notifications;
using namespace ABI::Windows::Data::Xml::Dom; using namespace ABI::Windows::Data::Xml::Dom;
#define BREAK_IF_BAD(hr) if(!SUCCEEDED(hr)) break; #define BREAK_IF_BAD(hr) if(!SUCCEEDED(hr)) break;
namespace WinToasts { namespace WinToasts {
// Initialize Windows Runtime namespace {
static HRESULT init = Windows::Foundation::Initialize(RO_INIT_MULTITHREADED);
WindowsToastNotification::WindowsToastNotification(const char* appName, content::DesktopNotificationDelegate* delegate) // Initialize Windows Runtime
{ HRESULT init = Windows::Foundation::Initialize(RO_INIT_MULTITHREADED);
HSTRING toastNotifMgrStr = NULL;
HSTRING appId = NULL; } // namespace
WindowsToastNotification::WindowsToastNotification(
const char* appName, content::DesktopNotificationDelegate* delegate) {
HSTRING toastNotifMgrStr = nullptr;
HSTRING appId = nullptr;
HRESULT hr = CreateHString(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager, &toastNotifMgrStr); 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); m_toastManager->CreateToastNotifierWithId(appId, &m_toastNotifier);
if (toastNotifMgrStr != NULL) { if (toastNotifMgrStr) {
WindowsDeleteString(toastNotifMgrStr); WindowsDeleteString(toastNotifMgrStr);
} }
if (appId != NULL) { if (appId) {
WindowsDeleteString(appId); WindowsDeleteString(appId);
} }
n_delegate = delegate; n_delegate = delegate;
} }
WindowsToastNotification::~WindowsToastNotification() WindowsToastNotification::~WindowsToastNotification() {
{
if (n_delegate) { if (n_delegate) {
delete 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; HRESULT hr;
HSTRING toastNotifStr = NULL; HSTRING toastNotifStr = nullptr;
do { do {
ComPtr<IXmlDocument> toastXml; ComPtr<IXmlDocument> toastXml;
@ -80,23 +82,21 @@ void WindowsToastNotification::ShowNotification(const WCHAR* title, const WCHAR*
n_delegate->NotificationDisplayed(); n_delegate->NotificationDisplayed();
} while (FALSE); } while (FALSE);
if (toastNotifStr != NULL) { if (toastNotifStr) {
WindowsDeleteString(toastNotifStr); WindowsDeleteString(toastNotifStr);
} }
} }
void WindowsToastNotification::DismissNotification(ComPtr<IToastNotification> toast) void WindowsToastNotification::DismissNotification(
{ ComPtr<IToastNotification> toast) {
m_toastNotifier->Hide(toast.Get()); m_toastNotifier->Hide(toast.Get());
} }
void WindowsToastNotification::NotificationClicked() void WindowsToastNotification::NotificationClicked() {
{
delete this; delete this;
} }
void WindowsToastNotification::NotificationDismissed() void WindowsToastNotification::NotificationDismissed() {
{
delete this; delete this;
} }
@ -106,7 +106,6 @@ HRESULT WindowsToastNotification::GetToastXml(
const WCHAR* msg, const WCHAR* msg,
std::string iconPath, std::string iconPath,
IXmlDocument** toastXml) { IXmlDocument** toastXml) {
HRESULT hr; HRESULT hr;
ToastTemplateType templateType; ToastTemplateType templateType;
if (title == NULL || msg == NULL) { if (title == NULL || msg == NULL) {
@ -139,8 +138,8 @@ HRESULT WindowsToastNotification::GetToastXml(
return hr; return hr;
} }
HRESULT WindowsToastNotification::SetXmlText(IXmlDocument* doc, const WCHAR* text) HRESULT WindowsToastNotification::SetXmlText(
{ IXmlDocument* doc, const WCHAR* text) {
HSTRING tag = NULL; HSTRING tag = NULL;
ComPtr<IXmlNodeList> nodeList; ComPtr<IXmlNodeList> nodeList;
@ -162,8 +161,8 @@ HRESULT WindowsToastNotification::SetXmlText(IXmlDocument* doc, const WCHAR* tex
return hr; 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; HSTRING tag = NULL;
ComPtr<IXmlNodeList> nodeList; ComPtr<IXmlNodeList> nodeList;
HRESULT hr = GetTextNodeList(&tag, doc, &nodeList, 2); HRESULT hr = GetTextNodeList(&tag, doc, &nodeList, 2);
@ -190,8 +189,8 @@ HRESULT WindowsToastNotification::SetXmlText(IXmlDocument* doc, const WCHAR* tit
return hr; return hr;
} }
HRESULT WindowsToastNotification::SetXmlImage(IXmlDocument* doc, std::string iconPath) HRESULT WindowsToastNotification::SetXmlImage(
{ IXmlDocument* doc, std::string iconPath) {
HSTRING tag = NULL; HSTRING tag = NULL;
HSTRING src = NULL; HSTRING src = NULL;
HSTRING imgPath = NULL; HSTRING imgPath = NULL;
@ -249,10 +248,13 @@ HRESULT WindowsToastNotification::SetXmlImage(IXmlDocument* doc, std::string ico
return hr; 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); HRESULT hr = CreateHString(L"text", tag);
do{ do {
BREAK_IF_BAD(hr); BREAK_IF_BAD(hr);
hr = doc->GetElementsByTagName(*tag, nodeList); hr = doc->GetElementsByTagName(*tag, nodeList);
@ -275,8 +277,8 @@ HRESULT WindowsToastNotification::GetTextNodeList(HSTRING* tag, IXmlDocument* do
return hr; 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; HSTRING str = NULL;
HRESULT hr = CreateHString(text, &str); HRESULT hr = CreateHString(text, &str);
do { do {
@ -301,8 +303,7 @@ HRESULT WindowsToastNotification::AppendTextToXml(IXmlDocument* doc, IXmlNode* n
return hr; return hr;
} }
HRESULT WindowsToastNotification::SetupCallbacks(IToastNotification* toast) HRESULT WindowsToastNotification::SetupCallbacks(IToastNotification* toast) {
{
EventRegistrationToken activatedToken, dismissedToken; EventRegistrationToken activatedToken, dismissedToken;
m_eventHandler = Make<ToastEventHandler>(this, n_delegate); m_eventHandler = Make<ToastEventHandler>(this, n_delegate);
HRESULT hr = toast->add_Activated(m_eventHandler.Get(), &activatedToken); HRESULT hr = toast->add_Activated(m_eventHandler.Get(), &activatedToken);
@ -314,8 +315,8 @@ HRESULT WindowsToastNotification::SetupCallbacks(IToastNotification* toast)
return hr; return hr;
} }
HRESULT WindowsToastNotification::CreateHString(const WCHAR* source, HSTRING* dest) HRESULT WindowsToastNotification::CreateHString(
{ const WCHAR* source, HSTRING* dest) {
if (source == NULL || dest == NULL) { if (source == NULL || dest == NULL) {
return E_INVALIDARG; return E_INVALIDARG;
} }
@ -327,19 +328,18 @@ HRESULT WindowsToastNotification::CreateHString(const WCHAR* source, HSTRING* de
/* /*
/ Toast Event Handler / Toast Event Handler
*/ */
ToastEventHandler::ToastEventHandler(WindowsToastNotification* notification, content::DesktopNotificationDelegate* delegate) ToastEventHandler::ToastEventHandler(
{ WindowsToastNotification* notification,
content::DesktopNotificationDelegate* delegate) {
m_notification = notification; m_notification = notification;
n_delegate = delegate; n_delegate = delegate;
} }
ToastEventHandler::~ToastEventHandler() ToastEventHandler::~ToastEventHandler() {
{
// Empty
} }
IFACEMETHODIMP ToastEventHandler::Invoke(IToastNotification* sender, IInspectable* args) IFACEMETHODIMP ToastEventHandler::Invoke(
{ IToastNotification* sender, IInspectable* args) {
// Notification "activated" (clicked) // Notification "activated" (clicked)
n_delegate->NotificationClick(); n_delegate->NotificationClick();
@ -350,14 +350,13 @@ IFACEMETHODIMP ToastEventHandler::Invoke(IToastNotification* sender, IInspectabl
return S_OK; return S_OK;
} }
IFACEMETHODIMP ToastEventHandler::Invoke(IToastNotification* sender, IToastDismissedEventArgs* e) IFACEMETHODIMP ToastEventHandler::Invoke(
{ IToastNotification* sender, IToastDismissedEventArgs* e) {
// Notification dismissed // Notification dismissed
n_delegate->NotificationClosed(); n_delegate->NotificationClosed();
if (m_notification != NULL) { if (m_notification != NULL) {
m_notification->NotificationDismissed(); m_notification->NotificationDismissed();
} }
return S_OK; 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 // 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. // and released it as MIT to the world.
#ifndef __WINDOWS_TOAST_NOTIFICATION_H__ #ifndef BRIGHTRAY_BROWSER_WIN_WINDOWS_TOAST_NOTIFICATION_H_
#define __WINDOWS_TOAST_NOTIFICATION_H__ #define BRIGHTRAY_BROWSER_WIN_WINDOWS_TOAST_NOTIFICATION_H_
#include "content/public/browser/desktop_notification_delegate.h"
#include "content/public/common/platform_notification_data.h"
#include "base/bind.h"
#include <windows.h> #include <windows.h>
#include <windows.ui.notifications.h> #include <windows.ui.notifications.h>
#include <wrl/implements.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 Microsoft::WRL;
using namespace ABI::Windows::UI::Notifications; using namespace ABI::Windows::UI::Notifications;
using namespace ABI::Windows::Foundation; using namespace ABI::Windows::Foundation;
namespace WinToasts { namespace WinToasts {
typedef ITypedEventHandler<ToastNotification*, IInspectable*> DesktopToastActivatedEventHandler; using DesktopToastActivatedEventHandler =
typedef ITypedEventHandler<ToastNotification*, ToastDismissedEventArgs*> DesktopToastDismissedEventHandler; ITypedEventHandler<ToastNotification*, IInspectable*>;
using DesktopToastDismissedEventHandler =
ITypedEventHandler<ToastNotification*, ToastDismissedEventArgs*>;
class ToastEventHandler; class ToastEventHandler;
class WindowsToastNotification class WindowsToastNotification {
{
public: public:
WindowsToastNotification(const char* appName, content::DesktopNotificationDelegate* delegate); WindowsToastNotification(const char* appName, content::DesktopNotificationDelegate* delegate);
~WindowsToastNotification(); ~WindowsToastNotification();
void ShowNotification(const WCHAR* title, const WCHAR* msg, std::string iconPath, ComPtr<IToastNotification>& toast); void ShowNotification(const WCHAR* title, const WCHAR* msg, std::string iconPath, ComPtr<IToastNotification>& toast);
void DismissNotification(ComPtr<IToastNotification> toast); void DismissNotification(ComPtr<IToastNotification> toast);
void NotificationClicked(); void NotificationClicked();
@ -50,23 +52,24 @@ namespace WinToasts {
HRESULT AppendTextToXml(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNode* node, const WCHAR* text); HRESULT AppendTextToXml(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNode* node, const WCHAR* text);
HRESULT SetupCallbacks(IToastNotification* toast); HRESULT SetupCallbacks(IToastNotification* toast);
HRESULT CreateHString(const WCHAR* source, HSTRING* dest); HRESULT CreateHString(const WCHAR* source, HSTRING* dest);
}; };
class ToastEventHandler : class ToastEventHandler : public RuntimeClass<RuntimeClassFlags<ClassicCom>,
public RuntimeClass<RuntimeClassFlags<ClassicCom>, DesktopToastActivatedEventHandler, DesktopToastDismissedEventHandler> DesktopToastActivatedEventHandler,
{ DesktopToastDismissedEventHandler> {
public: public:
ToastEventHandler(WindowsToastNotification* notification, content::DesktopNotificationDelegate* delegate); ToastEventHandler(WindowsToastNotification* notification, content::DesktopNotificationDelegate* delegate);
~ToastEventHandler(); ~ToastEventHandler();
IFACEMETHODIMP Invoke(IToastNotification* sender, IInspectable* args); IFACEMETHODIMP Invoke(IToastNotification* sender, IInspectable* args);
IFACEMETHODIMP Invoke(IToastNotification* sender, IToastDismissedEventArgs* e); IFACEMETHODIMP Invoke(IToastNotification* sender, IToastDismissedEventArgs* e);
private: private:
WindowsToastNotification* m_notification; WindowsToastNotification* m_notification;
content::DesktopNotificationDelegate* n_delegate; content::DesktopNotificationDelegate* n_delegate;
}; };
} // namespace } // namespace
#endif //__WINDOWS_TOAST_NOTIFICATION_H__ #endif // BRIGHTRAY_BROWSER_WIN_WINDOWS_TOAST_NOTIFICATION_H_