Skip to content

Commit 2fa4e27

Browse files
committed
Merge pull request nwjs#2546 from jtg-gg/notification-rebase
Notification rebase
2 parents 3ebeecc + 3d23537 commit 2fa4e27

15 files changed

+667
-74
lines changed

nw.gypi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@
324324
'src/nw_notification_manager.cc',
325325
'src/nw_notification_manager_win.h',
326326
'src/nw_notification_manager_win.cc',
327+
'src/nw_notification_manager_toast_win.h',
328+
'src/nw_notification_manager_toast_win.cc',
327329
'src/nw_notification_manager_mac.h',
328330
'src/nw_notification_manager_mac.mm',
329331
'src/nw_notification_manager_linux.h',

src/api/app/app.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
#include "base/logging.h"
2525
#include "base/message_loop/message_loop.h"
2626
#include "base/values.h"
27+
28+
#if defined(OS_WIN)
29+
#include "base/strings/utf_string_conversions.h"
30+
#include "base/files/file_path.h"
31+
#include "base/win/shortcut.h"
32+
#include "base/path_service.h"
33+
#include "content/nw/src/common/shell_switches.h"
34+
#endif
35+
2736
#include "content/nw/src/api/api_messages.h"
2837
#include "content/nw/src/api/dispatcher_host.h"
2938
#include "content/nw/src/api/shortcut/global_shortcut_listener.h"
@@ -120,6 +129,26 @@ void App::Call(Shell* shell,
120129
} else if (method == "ClearCache") {
121130
ClearCache(GetRenderProcessHost());
122131
return;
132+
} else if (method == "CreateShortcut") {
133+
#if defined(OS_WIN)
134+
base::string16 path;
135+
arguments.GetString(0, &path);
136+
137+
base::win::ShortcutProperties props;
138+
base::string16 appID;
139+
if (content::Shell::GetPackage()->root()->GetString("app-id", &appID) == false)
140+
content::Shell::GetPackage()->root()->GetString(switches::kmName, &appID);
141+
const std::wstring appName = base::UTF8ToWide(content::Shell::GetPackage()->GetName());
142+
props.set_app_id(appID);
143+
144+
base::FilePath processPath;
145+
PathService::Get(base::FILE_EXE, &processPath);
146+
props.set_target(processPath);
147+
result->AppendBoolean(base::win::CreateOrUpdateShortcutLink(base::FilePath(path), props, base::win::SHORTCUT_CREATE_ALWAYS));
148+
#else
149+
result->AppendBoolean(false);
150+
#endif
151+
return;
123152
} else if (method == "GetPackage") {
124153
result->AppendString(shell->GetPackage()->package_string());
125154
return;

src/api/app/app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ App.prototype.setCrashDumpDir = function(dir) {
5353
return nw.callStaticMethodSync('App', 'SetCrashDumpDir', [ dir ]);
5454
}
5555

56+
App.prototype.createShortcut = function(dir) {
57+
return nw.callStaticMethodSync('App', 'CreateShortcut', [ dir ]);
58+
}
59+
5660
App.prototype.clearCache = function() {
5761
nw.callStaticMethodSync('App', 'ClearCache', [ ]);
5862
}

src/nw_notification_manager.cc

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1919

2020
#include "ui/gfx/image/image.h"
21-
#include "content/public/browser/render_view_host.h"
21+
#include "content/public/browser/render_frame_host.h"
22+
#include "content/common/desktop_notification_messages.h"
23+
2224

2325
#include "content/nw/src/nw_notification_manager.h"
2426
#if defined(OS_MACOSX)
2527
#include "content/nw/src/nw_notification_manager_mac.h"
2628
#elif defined(OS_WIN)
2729
#include "content/nw/src/nw_notification_manager_win.h"
30+
#include "content/nw/src/nw_notification_manager_toast_win.h"
2831
#elif defined(OS_LINUX)
2932
#include "content/nw/src/nw_notification_manager_linux.h"
3033
#endif
@@ -45,7 +48,10 @@ NotificationManager* NotificationManager::getSingleton() {
4548
#if defined(OS_MACOSX)
4649
singleton_ = new NotificationManagerMac();
4750
#elif defined(OS_WIN)
48-
singleton_ = new NotificationManagerWin();
51+
if (NotificationManagerToastWin::IsSupported())
52+
singleton_ = new NotificationManagerToastWin();
53+
else
54+
singleton_ = new NotificationManagerWin();
4955
#elif defined(OS_LINUX)
5056
singleton_ = new NotificationManagerLinux();
5157
#endif
@@ -57,53 +63,53 @@ NotificationManager* NotificationManager::getSingleton() {
5763
void NotificationManager::ImageDownloadCallback(int id, int http_status, const GURL& image_url, const std::vector<SkBitmap>& bitmaps, const std::vector<gfx::Size>& size) {
5864
NotificationManager *singleton = getSingleton();
5965
DesktopNotificationParams params = singleton->desktop_notification_params_[id];
60-
singleton->AddDesktopNotification(params.params_, params.render_process_id_, params.render_view_id_, id, params.worker_, &bitmaps);
66+
singleton->AddDesktopNotification(params.params_, params.render_process_id_, params.render_frame_id_, params.notification_id_, params.worker_, &bitmaps);
6167
singleton->desktop_notification_params_.erase(id);
6268
}
6369

6470
bool NotificationManager::AddDesktopNotification(const content::ShowDesktopNotificationHostMsgParams& params,
6571
const int render_process_id,
66-
const int render_view_id,
72+
const int render_frame_id,
6773
const int notification_id,
6874
const bool worker,
6975
const std::vector<SkBitmap>* bitmaps) {
7076
NOTIMPLEMENTED();
7177
return false;
7278
}
7379

74-
bool NotificationManager::DesktopNotificationPostClick(int render_process_id, int render_view_id, int notification_id) {
75-
content::RenderViewHost* host = content::RenderViewHost::FromID(render_process_id, render_view_id);
76-
if (host == NULL)
80+
bool NotificationManager::DesktopNotificationPostClick(int render_process_id, int render_frame_id, int notification_id) {
81+
content::RenderFrameHost* rfh = content::RenderFrameHost::FromID(render_process_id, render_frame_id);
82+
if (!rfh)
7783
return false;
78-
79-
// host->DesktopNotificationPostClick(notification_id);
84+
85+
rfh->Send(new DesktopNotificationMsg_PostClick(rfh->GetRoutingID(), notification_id));
8086
return true;
8187
}
8288

83-
bool NotificationManager::DesktopNotificationPostClose(int render_process_id, int render_view_id, int notification_id, bool by_user) {
84-
content::RenderViewHost* host = content::RenderViewHost::FromID(render_process_id, render_view_id);
85-
if (host == NULL)
89+
bool NotificationManager::DesktopNotificationPostClose(int render_process_id, int render_frame_id, int notification_id, bool by_user) {
90+
content::RenderFrameHost* rfh = content::RenderFrameHost::FromID(render_process_id, render_frame_id);
91+
if (!rfh)
8692
return false;
8793

88-
// host->DesktopNotificationPostClose(notification_id, by_user);
94+
rfh->Send(new DesktopNotificationMsg_PostClose(rfh->GetRoutingID(), notification_id, by_user));
8995
return true;
9096
}
9197

92-
bool NotificationManager::DesktopNotificationPostDisplay(int render_process_id, int render_view_id, int notification_id) {
93-
content::RenderViewHost* host = content::RenderViewHost::FromID(render_process_id, render_view_id);
94-
if (host == NULL)
98+
bool NotificationManager::DesktopNotificationPostDisplay(int render_process_id, int render_frame_id, int notification_id) {
99+
content::RenderFrameHost* rfh = content::RenderFrameHost::FromID(render_process_id, render_frame_id);
100+
if (!rfh)
95101
return false;
96102

97-
// host->DesktopNotificationPostDisplay(notification_id);
103+
rfh->Send(new DesktopNotificationMsg_PostDisplay(rfh->GetRoutingID(), notification_id));
98104
return true;
99105
}
100106

101-
bool NotificationManager::DesktopNotificationPostError(int render_process_id, int render_view_id, int notification_id, const base::string16& message) {
102-
content::RenderViewHost* host = content::RenderViewHost::FromID(render_process_id, render_view_id);
103-
if (host == NULL)
107+
bool NotificationManager::DesktopNotificationPostError(int render_process_id, int render_frame_id, int notification_id, const base::string16& message) {
108+
content::RenderFrameHost* rfh = content::RenderFrameHost::FromID(render_process_id, render_frame_id);
109+
if (!rfh)
104110
return false;
105111

106-
// host->DesktopNotificationPostError(notification_id, message);
112+
rfh->Send(new DesktopNotificationMsg_PostError(rfh->GetRoutingID(), notification_id));
107113
return true;
108114
}
109115
} // namespace nw

src/nw_notification_manager.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class NotificationManager{
3737
struct DesktopNotificationParams {
3838
content::ShowDesktopNotificationHostMsgParams params_;
3939
int render_process_id_;
40-
int render_view_id_;
40+
int render_frame_id_;
41+
int notification_id_;
4142
bool worker_;
4243
};
4344

@@ -46,7 +47,7 @@ class NotificationManager{
4647

4748
// internal function for AddDesktopNotification
4849
virtual bool AddDesktopNotification(const content::ShowDesktopNotificationHostMsgParams& params,
49-
const int render_process_id, const int render_view_id,
50+
const int render_process_id, const int render_frame_id,
5051
const int notification_id, const bool worker,
5152
const std::vector<SkBitmap>* bitmaps);
5253

@@ -56,15 +57,15 @@ class NotificationManager{
5657
virtual bool AddDesktopNotification(
5758
const content::ShowDesktopNotificationHostMsgParams& params,
5859
const int render_process_id,
59-
const int render_view_id,
60+
const int render_frame_id,
6061
const int notification_id,
6162
const bool worker) = 0;
62-
virtual bool CancelDesktopNotification(int render_process_id, int render_view_id, int notification_id) = 0;
63+
virtual bool CancelDesktopNotification(int render_process_id, int render_frame_id, int notification_id) = 0;
6364

64-
bool DesktopNotificationPostClick(int render_process_id, int render_view_id, int notification_id);
65-
bool DesktopNotificationPostClose(int render_process_id, int render_view_id, int notification_id, bool by_user);
66-
bool DesktopNotificationPostDisplay(int render_process_id, int render_view_id, int notification_id);
67-
bool DesktopNotificationPostError(int render_process_id, int render_view_id, int notification_id, const base::string16& message);
65+
bool DesktopNotificationPostClick(int render_process_id, int render_frame_id, int notification_id);
66+
bool DesktopNotificationPostClose(int render_process_id, int render_frame_id, int notification_id, bool by_user);
67+
bool DesktopNotificationPostDisplay(int render_process_id, int render_frame_id, int notification_id);
68+
bool DesktopNotificationPostError(int render_process_id, int render_frame_id, int notification_id, const base::string16& message);
6869

6970
};
7071

src/nw_notification_manager_linux.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ void NotificationManagerLinux::onClose(NotifyNotification *notif)
7272

7373
bool NotificationManagerLinux::AddDesktopNotification(const content::ShowDesktopNotificationHostMsgParams& params,
7474
const int render_process_id,
75-
const int render_view_id,
75+
const int render_frame_id,
7676
const int notification_id,
7777
const bool worker,
7878
const std::vector<SkBitmap>* bitmaps) {
7979

80-
content::RenderViewHost* host = content::RenderFrameHost::FromID(render_process_id, render_view_id)->GetRenderViewHost();
80+
content::RenderViewHost* host = content::RenderFrameHost::FromID(render_process_id, render_frame_id)->GetRenderViewHost();
8181
if (host == NULL)
8282
return false;
8383

@@ -88,7 +88,7 @@ bool NotificationManagerLinux::AddDesktopNotification(const content::ShowDesktop
8888
DesktopNotificationParams desktop_notification_params;
8989
desktop_notification_params.params_ = params;
9090
desktop_notification_params.render_process_id_ = render_process_id;
91-
desktop_notification_params.render_view_id_ = render_view_id;
91+
desktop_notification_params.render_frame_id_ = render_frame_id;
9292

9393
// download the icon image first
9494
content::WebContents::ImageDownloadCallback imageDownloadCallback = base::Bind(&NotificationManager::ImageDownloadCallback);
@@ -118,7 +118,7 @@ bool NotificationManagerLinux::AddDesktopNotification(const content::ShowDesktop
118118
NotificationData data;
119119
data.mNotification = notif;
120120
data.mRenderProcessId = render_process_id;
121-
data.mRenderViewId = render_view_id;
121+
data.mRenderViewId = render_frame_id;
122122
mNotificationIDmap[notification_id] = data;
123123
}
124124
else {
@@ -133,7 +133,7 @@ bool NotificationManagerLinux::AddDesktopNotification(const content::ShowDesktop
133133
g_object_ref(G_OBJECT(notif));
134134
onClose(notif);
135135
data.mRenderProcessId = render_process_id;
136-
data.mRenderViewId = render_view_id;
136+
data.mRenderViewId = render_frame_id;
137137
mNotificationIDmap[notification_id] = data;
138138
}
139139
}
@@ -146,16 +146,16 @@ bool NotificationManagerLinux::AddDesktopNotification(const content::ShowDesktop
146146

147147
GError* error = NULL;
148148
if (notify_notification_show (notif, &error)) {
149-
DesktopNotificationPostDisplay(render_process_id, render_view_id, notification_id);
149+
DesktopNotificationPostDisplay(render_process_id, render_frame_id, notification_id);
150150
}
151151
else {
152152
base::string16 errorMsg = base::UTF8ToUTF16(error->message);
153-
DesktopNotificationPostError(render_process_id, render_view_id, notification_id, errorMsg);
153+
DesktopNotificationPostError(render_process_id, render_frame_id, notification_id, errorMsg);
154154
}
155155
return error==NULL;
156156
}
157157

158-
bool NotificationManagerLinux::CancelDesktopNotification(int render_process_id, int render_view_id, int notification_id) {
158+
bool NotificationManagerLinux::CancelDesktopNotification(int render_process_id, int render_frame_id, int notification_id) {
159159
NotificationMap::const_iterator i = getNotification(notification_id);
160160
if (i!=mNotificationIDmap.end()) {
161161
return notify_notification_close(i->second.mNotification, NULL);
@@ -165,10 +165,10 @@ bool NotificationManagerLinux::CancelDesktopNotification(int render_process_id,
165165

166166
bool NotificationManagerLinux::AddDesktopNotification(const content::ShowDesktopNotificationHostMsgParams& params,
167167
const int render_process_id,
168-
const int render_view_id,
168+
const int render_frame_id,
169169
const int notification_id,
170170
const bool worker) {
171-
return AddDesktopNotification(params, render_process_id, render_view_id, notification_id, worker, NULL);
171+
return AddDesktopNotification(params, render_process_id, render_frame_id, notification_id, worker, NULL);
172172
}
173173

174174
} // namespace nw

src/nw_notification_manager_linux.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class NotificationManagerLinux : public NotificationManager {
4343
// internal function for AddDesktopNotification
4444
virtual bool AddDesktopNotification(const content::ShowDesktopNotificationHostMsgParams& params,
4545
const int render_process_id,
46-
const int render_view_id,
46+
const int render_frame_id,
4747
const int notification_id,
4848
const bool worker,
4949
const std::vector<SkBitmap>* bitmaps) OVERRIDE;
@@ -53,10 +53,10 @@ class NotificationManagerLinux : public NotificationManager {
5353
virtual ~NotificationManagerLinux();
5454
virtual bool AddDesktopNotification(const content::ShowDesktopNotificationHostMsgParams& params,
5555
const int render_process_id,
56-
const int render_view_id,
56+
const int render_frame_id,
5757
const int notification_id,
5858
const bool worker) OVERRIDE;
59-
virtual bool CancelDesktopNotification(int render_process_id, int render_view_id, int notification_id) OVERRIDE;
59+
virtual bool CancelDesktopNotification(int render_process_id, int render_frame_id, int notification_id) OVERRIDE;
6060
};
6161

6262
} // namespace nw

src/nw_notification_manager_mac.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ class NotificationManagerMac : public NotificationManager {
2828

2929
// internal function for AddDesktopNotification
3030
virtual bool AddDesktopNotification(const content::ShowDesktopNotificationHostMsgParams& params,
31-
const int render_process_id, const int render_view_id,
31+
const int render_process_id, const int render_frame_id,
3232
const int notification_id,
3333
const bool worker, const std::vector<SkBitmap>* bitmaps) OVERRIDE;
3434

3535
public:
3636
explicit NotificationManagerMac();
3737
virtual ~NotificationManagerMac(){}
3838
virtual bool AddDesktopNotification(const content::ShowDesktopNotificationHostMsgParams& params,
39-
const int render_process_id, const int render_view_id,
39+
const int render_process_id, const int render_frame_id,
4040
const int notification_id,
4141
const bool worker) OVERRIDE;
42-
virtual bool CancelDesktopNotification(int render_process_id, int render_view_id, int notification_id) OVERRIDE;
42+
virtual bool CancelDesktopNotification(int render_process_id, int render_frame_id, int notification_id) OVERRIDE;
4343

4444
};
4545

0 commit comments

Comments
 (0)