Skip to content

Commit e00b767

Browse files
committed
Merge branch 'm41' of https://github.com/nwjs/nw.js into m41
2 parents 025cf6b + be36dfe commit e00b767

18 files changed

+173
-152
lines changed

nw.gypi

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -380,16 +380,16 @@
380380
'src/renderer/shell_render_process_observer.h',
381381
'src/nw_shell.cc',
382382
'src/nw_shell.h',
383-
# 'src/nw_notification_manager.h',
384-
# 'src/nw_notification_manager.cc',
385-
# 'src/nw_notification_manager_win.h',
386-
# 'src/nw_notification_manager_win.cc',
387-
# 'src/nw_notification_manager_toast_win.h',
388-
# 'src/nw_notification_manager_toast_win.cc',
389-
# 'src/nw_notification_manager_mac.h',
390-
# 'src/nw_notification_manager_mac.mm',
391-
# 'src/nw_notification_manager_linux.h',
392-
# 'src/nw_notification_manager_linux.cc',
383+
'src/nw_notification_manager.h',
384+
'src/nw_notification_manager.cc',
385+
'src/nw_notification_manager_win.h',
386+
'src/nw_notification_manager_win.cc',
387+
'src/nw_notification_manager_toast_win.h',
388+
'src/nw_notification_manager_toast_win.cc',
389+
'src/nw_notification_manager_mac.h',
390+
'src/nw_notification_manager_mac.mm',
391+
'src/nw_notification_manager_linux.h',
392+
'src/nw_notification_manager_linux.cc',
393393
'src/shell_browser_context.cc',
394394
'src/shell_browser_context.h',
395395
'src/shell_browser_main.cc',

src/browser/app_controller_mac.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ @implementation AppController
3434
- (BOOL)application:(NSApplication*)sender
3535
openFile:(NSString*)filename {
3636
if (content::Shell::windows().size() == 0) {
37-
CommandLine::ForCurrentProcess()->AppendArg([filename UTF8String]);
38-
CommandLine::ForCurrentProcess()->FixOrigArgv4Finder([filename UTF8String]);
37+
base::CommandLine::ForCurrentProcess()->AppendArg([filename UTF8String]);
38+
base::CommandLine::ForCurrentProcess()->FixOrigArgv4Finder([filename UTF8String]);
3939
return TRUE;
4040
}
4141

src/browser/autofill_popup_view_bridge.mm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "chrome/browser/ui/autofill/autofill_popup_controller.h"
1111
#include "chrome/browser/ui/autofill/autofill_popup_view_delegate.h"
1212
#import "chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.h"
13-
#include "ui/gfx/rect.h"
1413

1514
namespace autofill {
1615

src/browser/autofill_popup_view_cocoa.mm

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
#include "chrome/browser/ui/autofill/popup_constants.h"
1111
#include "chrome/browser/ui/cocoa/autofill/autofill_popup_view_bridge.h"
1212
#include "components/autofill/core/browser/popup_item_ids.h"
13+
#include "components/autofill/core/browser/suggestion.h"
1314
#include "ui/base/cocoa/window_size_constants.h"
1415
#include "ui/base/resource/resource_bundle.h"
1516
#include "ui/gfx/font_list.h"
1617
#include "ui/gfx/image/image.h"
17-
#include "ui/gfx/point.h"
18-
#include "ui/gfx/rect.h"
1918

2019
using autofill::AutofillPopupView;
2120

@@ -97,31 +96,31 @@ - (void)drawRect:(NSRect)dirtyRect {
9796

9897
[self drawBackgroundAndBorder];
9998

100-
for (size_t i = 0; i < controller_->names().size(); ++i) {
99+
for (size_t i = 0; i < controller_->GetLineCount(); ++i) {
101100
// Skip rows outside of the dirty rect.
102101
NSRect rowBounds =
103102
NSRectFromCGRect(controller_->GetRowBounds(i).ToCGRect());
104103
if (!NSIntersectsRect(rowBounds, dirtyRect))
105104
continue;
106105

107-
if (controller_->identifiers()[i] == autofill::POPUP_ITEM_ID_SEPARATOR) {
106+
if (controller_->GetSuggestionAt(i).frontend_id == autofill::POPUP_ITEM_ID_SEPARATOR) {
108107
[self drawSeparatorWithBounds:rowBounds];
109108
continue;
110109
}
111110

112111
// Additional offset applied to the text in the vertical direction.
113112
CGFloat textYOffset = 0;
114113
BOOL imageFirst = NO;
115-
if (controller_->identifiers()[i] ==
114+
if (controller_->GetSuggestionAt(i).frontend_id ==
116115
autofill::POPUP_ITEM_ID_MAC_ACCESS_CONTACTS) {
117116
// Due to the weighting of the asset used for this autofill entry, the
118117
// text needs to be bumped up by 1 pt to make it look vertically aligned.
119118
textYOffset = -1;
120119
imageFirst = YES;
121120
}
122121

123-
NSString* name = SysUTF16ToNSString(controller_->names()[i]);
124-
NSString* subtext = SysUTF16ToNSString(controller_->subtexts()[i]);
122+
NSString* name = SysUTF16ToNSString(controller_->GetElidedValueAt(i));
123+
NSString* subtext = SysUTF16ToNSString(controller_->GetElidedLabelAt(i));
125124
BOOL isSelected = static_cast<int>(i) == controller_->selected_line();
126125
[self drawSuggestionWithName:name
127126
subtext:subtext
@@ -203,7 +202,7 @@ - (CGFloat)drawName:(NSString*)name
203202
controller_->IsWarning(index) ? [self warningColor] : [self nameColor];
204203
NSDictionary* nameAttributes =
205204
[NSDictionary dictionaryWithObjectsAndKeys:
206-
controller_->GetNameFontListForRow(index).GetPrimaryFont().
205+
controller_->GetValueFontListForRow(index).GetPrimaryFont().
207206
GetNativeFont(),
208207
NSFontAttributeName, nameColor, NSForegroundColorAttributeName,
209208
nil];
@@ -247,7 +246,7 @@ - (CGFloat)drawSubtext:(NSString*)subtext
247246
textYOffset:(CGFloat)textYOffset {
248247
NSDictionary* subtextAttributes =
249248
[NSDictionary dictionaryWithObjectsAndKeys:
250-
controller_->subtext_font_list().GetPrimaryFont().GetNativeFont(),
249+
controller_->GetLabelFontList().GetPrimaryFont().GetNativeFont(),
251250
NSFontAttributeName,
252251
[self subtextColor],
253252
NSForegroundColorAttributeName,
@@ -263,10 +262,10 @@ - (CGFloat)drawSubtext:(NSString*)subtext
263262
}
264263

265264
- (NSImage*)iconAtIndex:(size_t)index {
266-
if (controller_->icons()[index].empty())
265+
if (controller_->GetSuggestionAt(index).icon.empty())
267266
return nil;
268267

269-
int iconId = controller_->GetIconResourceID(controller_->icons()[index]);
268+
int iconId = controller_->GetIconResourceID(controller_->GetSuggestionAt(index).icon);
270269
DCHECK_NE(-1, iconId);
271270

272271
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();

src/browser/native_window.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ class CapturePageHelper;
6666

6767
#if defined(OS_WIN) || defined(OS_LINUX)
6868
class NativeWindow : public web_modal::WebContentsModalDialogHost {
69+
public:
70+
~NativeWindow() override;
6971
#else
7072
class NativeWindow {
73+
public:
74+
virtual ~NativeWindow();
7175
#endif
72-
public:
73-
~NativeWindow() override;
7476

7577
static NativeWindow* Create(const base::WeakPtr<content::Shell>& shell,
7678
base::DictionaryValue* manifest);

src/browser/native_window_mac.mm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,6 @@ - (void)drawRect:(NSRect)dirtyRect {
495495
void NativeWindowCocoa::Show() {
496496
NSApplication *myApp = [NSApplication sharedApplication];
497497
[myApp activateIgnoringOtherApps:NO];
498-
content::RenderWidgetHostView* rwhv =
499-
shell_->web_contents()->GetRenderWidgetHostView();
500498

501499
if (first_show_ && initial_focus_) {
502500
[window() makeKeyAndOrderFront:nil];

src/nw_notification_manager.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
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/desktop_notification_delegate.h"
2122
#include "content/public/browser/render_process_host.h"
2223
#include "content/common/platform_notification_messages.h"
2324

@@ -97,4 +98,45 @@ bool NotificationManager::DesktopNotificationPostError(int render_process_id, in
9798
#endif
9899
return true;
99100
}
101+
102+
blink::WebNotificationPermission NotificationManager::CheckPermission(ResourceContext* resource_context,
103+
const GURL& origin,
104+
int render_process_id) {
105+
return blink::WebNotificationPermissionAllowed;
106+
}
107+
108+
void CancelDesktopNotification(int notification_id) {
109+
nw::NotificationManager *notificationManager = nw::NotificationManager::getSingleton();
110+
if (notificationManager == NULL) {
111+
NOTIMPLEMENTED();
112+
return;
113+
}
114+
notificationManager->CancelDesktopNotification(notification_id);
115+
}
116+
117+
void NotificationManager::DisplayNotification(BrowserContext* browser_context,
118+
const GURL& origin,
119+
const SkBitmap& icon,
120+
const PlatformNotificationData& notification_data,
121+
scoped_ptr<DesktopNotificationDelegate> delegate,
122+
int render_process_id,
123+
base::Closure* cancel_callback) {
124+
if (AddDesktopNotification(notification_data, render_process_id, delegate->notification_id(), icon))
125+
*cancel_callback = base::Bind(&nw::CancelDesktopNotification, delegate->notification_id());
126+
}
127+
128+
void NotificationManager::DisplayPersistentNotification(BrowserContext* browser_context,
129+
int64 service_worker_registration_id,
130+
const GURL& origin,
131+
const SkBitmap& icon,
132+
const PlatformNotificationData& notification_data,
133+
int render_process_id) {
134+
NOTIMPLEMENTED();
135+
}
136+
137+
void NotificationManager::ClosePersistentNotification(BrowserContext* browser_context,
138+
const std::string& persistent_notification_id) {
139+
NOTIMPLEMENTED();
140+
}
141+
100142
} // namespace nw

src/nw_notification_manager.h

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,58 @@
2121
#define CONTENT_NW_NOTIFICATION_MANAGER_H_
2222

2323
#include "base/basictypes.h"
24-
#include "content/public/common/platform_notification_data.h"
24+
#include "content/public/browser/platform_notification_service.h"
2525

2626
namespace nw {
2727

28-
class NotificationManager{
28+
using namespace content;
29+
30+
class NotificationManager : public content::PlatformNotificationService{
2931
private:
3032
static NotificationManager *singleton_;
3133

3234
protected:
3335
explicit NotificationManager();
3436

3537
public:
36-
virtual ~NotificationManager();
38+
~NotificationManager() override;
3739
static NotificationManager* getSingleton();
38-
virtual bool AddDesktopNotification(const content::ShowDesktopNotificationHostMsgParams& params,
40+
41+
virtual bool AddDesktopNotification(const content::PlatformNotificationData& params,
3942
const int render_process_id,
4043
const int notification_id,
41-
const bool worker) = 0;
44+
const SkBitmap& icon) = 0;
4245

43-
virtual bool CancelDesktopNotification(int render_process_id, int notification_id) = 0;
46+
virtual bool CancelDesktopNotification(int notification_id) = 0;
4447

4548
bool DesktopNotificationPostClick(int render_process_id, int notification_id);
4649
bool DesktopNotificationPostClose(int render_process_id, int notification_id, bool by_user);
4750
bool DesktopNotificationPostDisplay(int render_process_id, int notification_id);
4851
bool DesktopNotificationPostError(int render_process_id, int notification_id, const base::string16& message);
52+
53+
// PlatformNotificationService functions
54+
blink::WebNotificationPermission CheckPermission(ResourceContext* resource_context,
55+
const GURL& origin,
56+
int render_process_id) override;
57+
58+
void DisplayNotification(BrowserContext* browser_context,
59+
const GURL& origin,
60+
const SkBitmap& icon,
61+
const PlatformNotificationData& notification_data,
62+
scoped_ptr<DesktopNotificationDelegate> delegate,
63+
int render_process_id,
64+
base::Closure* cancel_callback) override;
65+
66+
void DisplayPersistentNotification(BrowserContext* browser_context,
67+
int64 service_worker_registration_id,
68+
const GURL& origin,
69+
const SkBitmap& icon,
70+
const PlatformNotificationData& notification_data,
71+
int render_process_id) override;
72+
73+
void ClosePersistentNotification(BrowserContext* browser_context,
74+
const std::string& persistent_notification_id) override;
75+
4976

5077
};
5178

src/nw_notification_manager_linux.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "content/public/browser/web_contents.h"
2424
#include "content/public/browser/render_frame_host.h"
2525
#include "content/public/browser/render_view_host.h"
26+
#include "content/public/common/platform_notification_data.h"
2627
#include "content/nw/src/browser/native_window.h"
2728
#include "content/nw/src/nw_package.h"
2829
#include "content/nw/src/nw_shell.h"
@@ -69,14 +70,14 @@ void NotificationManagerLinux::onClose(NotifyNotification *notif)
6970
g_object_unref(G_OBJECT(notif));
7071
};
7172

72-
bool NotificationManagerLinux::AddDesktopNotification(const content::ShowDesktopNotificationHostMsgParams& params,
73+
bool NotificationManagerLinux::AddDesktopNotification(const content::PlatformNotificationData& params,
7374
const int render_process_id,
7475
const int notification_id,
75-
const bool worker) {
76+
const SkBitmap& icon) {
7677
content::Shell* shell = content::Shell::windows()[0];
7778
SkBitmap bitmap;
78-
if(params.icon.getSize()) {
79-
bitmap = params.icon;
79+
if(icon.getSize()) {
80+
bitmap = icon;
8081
} else {
8182
bitmap = shell->window()->app_icon().AsBitmap();
8283
}
@@ -126,7 +127,7 @@ bool NotificationManagerLinux::AddDesktopNotification(const content::ShowDesktop
126127
return error==NULL;
127128
}
128129

129-
bool NotificationManagerLinux::CancelDesktopNotification(int render_process_id, int notification_id) {
130+
bool NotificationManagerLinux::CancelDesktopNotification(int notification_id) {
130131
NotificationMap::const_iterator i = getNotification(notification_id);
131132
if (i!=mNotificationIDmap.end()) {
132133
return notify_notification_close(i->second.mNotification, NULL);

src/nw_notification_manager_linux.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class NotificationManagerLinux : public NotificationManager {
2929
struct NotificationData {
3030
NotifyNotification* mNotification;
3131
int mRenderProcessId;
32-
int mRenderViewId;
3332
};
3433

3534
typedef std::map<int, NotificationData> NotificationMap;
@@ -42,12 +41,12 @@ class NotificationManagerLinux : public NotificationManager {
4241

4342
public:
4443
explicit NotificationManagerLinux();
45-
virtual ~NotificationManagerLinux();
46-
virtual bool AddDesktopNotification(const content::ShowDesktopNotificationHostMsgParams& params,
44+
~NotificationManagerLinux() override;
45+
bool AddDesktopNotification(const content::PlatformNotificationData& params,
4746
const int render_process_id,
4847
const int notification_id,
49-
const bool worker) override;
50-
virtual bool CancelDesktopNotification(int render_process_id, int notification_id) override;
48+
const SkBitmap& icon) override;
49+
bool CancelDesktopNotification(int notification_id) override;
5150
};
5251

5352
} // namespace nw

src/nw_notification_manager_mac.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@
2525
namespace nw {
2626

2727
class NotificationManagerMac : public NotificationManager {
28-
2928
public:
3029
explicit NotificationManagerMac();
3130
virtual ~NotificationManagerMac(){}
3231

33-
virtual bool AddDesktopNotification(const content::ShowDesktopNotificationHostMsgParams& params,
34-
const int render_process_id, const int notification_id, const bool worker) override;
32+
virtual bool AddDesktopNotification(const content::PlatformNotificationData& params,
33+
const int render_process_id, const int notification_id, const SkBitmap& icon) override;
3534

36-
virtual bool CancelDesktopNotification(int render_process_id, int notification_id) override;
35+
virtual bool CancelDesktopNotification(int notification_id) override;
3736

3837
};
3938

src/nw_notification_manager_mac.mm

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "content/public/browser/web_contents.h"
2525
#include "content/public/browser/render_frame_host.h"
2626
#include "content/public/browser/render_view_host.h"
27+
#include "content/public/common/platform_notification_data.h"
2728
#include "content/nw/src/browser/native_window.h"
2829
#include "content/nw/src/nw_package.h"
2930
#include "content/nw/src/nw_shell.h"
@@ -80,21 +81,19 @@ -(void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNoti
8081
namespace nw {
8182
NotificationManagerMac::NotificationManagerMac() {
8283
}
83-
84-
bool NotificationManagerMac::AddDesktopNotification(const content::ShowDesktopNotificationHostMsgParams& params,
85-
const int render_process_id, const int notification_id, const bool worker) {
86-
84+
85+
bool NotificationManagerMac::AddDesktopNotification(const content::PlatformNotificationData &params,
86+
const int render_process_id, const int notification_id, const SkBitmap& icon) {
87+
8788
NSUserNotification *notification = [[NSUserNotification alloc] init];
8889
[notification setTitle : base::SysUTF16ToNSString(params.title)];
8990
[notification setInformativeText : base::SysUTF16ToNSString(params.body)];
9091
notification.hasActionButton = YES;
91-
92-
if (params.icon.getSize() > 0 && base::mac::IsOSMavericksOrLater()) {
93-
// try to get the notification icon image given by image download callback
94-
gfx::Image icon = gfx::Image::CreateFrom1xBitmap(params.icon);
95-
92+
93+
if (base::mac::IsOSMavericksOrLater() && icon.getSize()) {
94+
gfx::Image image = gfx::Image::CreateFrom1xBitmap(icon);
9695
// this function only runs on Mavericks or later
97-
[notification setContentImage : icon.ToNSImage()];
96+
[notification setContentImage : image.ToNSImage()];
9897
}
9998

10099
notification.userInfo = @{ @"render_process_id" :[NSNumber numberWithInt : render_process_id],
@@ -111,7 +110,7 @@ -(void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNoti
111110
return true;
112111
}
113112

114-
bool NotificationManagerMac::CancelDesktopNotification(int render_process_id, int notification_id){
113+
bool NotificationManagerMac::CancelDesktopNotification(int notification_id){
115114
for (NSUserNotification *notification in[[NSUserNotificationCenter defaultUserNotificationCenter] deliveredNotifications]) {
116115
NSNumber *current_notification_id = [notification.userInfo objectForKey : @"notification_id"];
117116
if (current_notification_id.intValue == notification_id){

0 commit comments

Comments
 (0)