Merge pull request #63 from brightray/chrome36

Upgrade to Chrome36
This commit is contained in:
Cheng Zhao 2014-07-29 14:36:23 +08:00
commit fd90f2c360
18 changed files with 213 additions and 273 deletions

View file

@ -259,6 +259,7 @@
'msvs_disabled_warnings': [
4100, # unreferenced formal parameter
4127, # conditional expression is constant
4189, # local variable is initialized but not referenced
4244, # 'initializing' : conversion from 'double' to 'size_t', possible loss of data
4245, # 'initializing' : conversion from 'int' to 'const net::QuicVersionTag', signed/unsigned mismatch
4251, # class 'std::xx' needs to have dll-interface.

View file

@ -9,6 +9,8 @@
#include "browser/media/media_capture_devices_dispatcher.h"
#include "browser/notification_presenter.h"
#include "base/base_paths.h"
#include "base/path_service.h"
#include "content/public/common/url_constants.h"
namespace brightray {
@ -66,24 +68,12 @@ net::URLRequestContextGetter* BrowserClient::CreateRequestContext(
void BrowserClient::ShowDesktopNotification(
const content::ShowDesktopNotificationHostMsgParams& params,
int render_process_id,
int render_view_id,
bool worker) {
content::RenderFrameHost* render_frame_host,
content::DesktopNotificationDelegate* delegate,
base::Closure* cancel_callback) {
auto presenter = notification_presenter();
if (!presenter)
return;
presenter->ShowNotification(params, render_process_id, render_view_id);
}
void BrowserClient::CancelDesktopNotification(
int render_process_id,
int render_view_id,
int notification_id) {
auto presenter = notification_presenter();
if (!presenter)
return;
presenter->CancelNotification(
render_process_id, render_view_id, notification_id);
if (presenter)
presenter->ShowNotification(params, delegate, cancel_callback);
}
content::MediaObserver* BrowserClient::GetMediaObserver() {
@ -96,4 +86,13 @@ void BrowserClient::GetAdditionalAllowedSchemesForFileSystem(
additional_schemes->push_back(content::kChromeUIScheme);
}
base::FilePath BrowserClient::GetDefaultDownloadDirectory() {
// ~/Downloads
base::FilePath path;
if (PathService::Get(base::DIR_HOME, &path))
path = path.Append(FILE_PATH_LITERAL("Downloads"));
return path;
}
} // namespace brightray

View file

@ -43,16 +43,13 @@ class BrowserClient : public content::ContentBrowserClient {
const content::MainFunctionParams&) OVERRIDE;
virtual void ShowDesktopNotification(
const content::ShowDesktopNotificationHostMsgParams&,
int render_process_id,
int render_view_id,
bool worker) OVERRIDE;
virtual void CancelDesktopNotification(
int render_process_id,
int render_view_id,
int notification_id) OVERRIDE;
content::RenderFrameHost* render_frame_host,
content::DesktopNotificationDelegate* delegate,
base::Closure* cancel_callback) OVERRIDE;
virtual content::MediaObserver* GetMediaObserver() OVERRIDE;
virtual void GetAdditionalAllowedSchemesForFileSystem(
std::vector<std::string>* additional_schemes) OVERRIDE;
virtual base::FilePath GetDefaultDownloadDirectory() OVERRIDE;
BrowserMainParts* browser_main_parts_;
scoped_ptr<NotificationPresenter> notification_presenter_;

View file

@ -204,4 +204,8 @@ quota::SpecialStoragePolicy* BrowserContext::GetSpecialStoragePolicy() {
return nullptr;
}
content::BrowserPluginGuestManagerDelegate* BrowserContext::GetGuestManagerDelegate() {
return nullptr;
}
} // namespace brightray

View file

@ -80,6 +80,8 @@ class BrowserContext : public content::BrowserContext {
GetDownloadManagerDelegate() OVERRIDE;
virtual content::GeolocationPermissionContext*
GetGeolocationPermissionContext() OVERRIDE;
virtual content::BrowserPluginGuestManagerDelegate*
GetGuestManagerDelegate() OVERRIDE;
virtual quota::SpecialStoragePolicy*
GetSpecialStoragePolicy() OVERRIDE;

View file

@ -9,7 +9,6 @@
#include "net/proxy/proxy_resolver_v8.h"
#if defined(USE_AURA)
#include "ui/aura/env.h"
#include "ui/gfx/screen.h"
#include "ui/views/widget/desktop_aura/desktop_screen.h"
#endif
@ -61,6 +60,8 @@ void BrowserMainParts::PreEarlyInitialization() {
#if defined(USE_AURA) && defined(USE_X11)
views::LinuxUI::SetInstance(BuildGtk2UI());
#endif
InitProxyResolverV8();
}
void BrowserMainParts::ToolkitInitialized() {
@ -97,19 +98,14 @@ void BrowserMainParts::PreMainMessageLoopRun() {
void BrowserMainParts::PostMainMessageLoopRun() {
browser_context_.reset();
#if defined(USE_AURA)
aura::Env::DeleteInstance();
#endif
}
int BrowserMainParts::PreCreateThreads() {
#if defined(USE_AURA)
aura::Env::CreateInstance();
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE,
views::CreateDesktopScreen());
#endif
InitProxyResolverV8();
return 0;
}
@ -118,11 +114,7 @@ BrowserContext* BrowserMainParts::CreateBrowserContext() {
}
void BrowserMainParts::InitProxyResolverV8() {
#if defined(OS_WIN)
net::ProxyResolverV8::CreateIsolate();
#else
net::ProxyResolverV8::RememberDefaultIsolate();
#endif
net::ProxyResolverV8::EnsureIsolateCreated();
}
} // namespace brightray

View file

@ -2,18 +2,11 @@
#include "browser/inspectable_web_contents_impl.h"
#include "content/public/browser/web_contents_view.h"
namespace brightray {
InspectableWebContents* InspectableWebContents::Create(
const content::WebContents::CreateParams& create_params) {
auto contents = content::WebContents::Create(create_params);
#if defined(OS_MACOSX)
// Work around http://crbug.com/279472.
contents->GetView()->SetAllowOverlappingViews(true);
#endif
return Create(contents);
}

View file

@ -21,7 +21,6 @@
#include "content/public/browser/devtools_client_host.h"
#include "content/public/browser/devtools_http_handler.h"
#include "content/public/browser/devtools_manager.h"
#include "content/public/browser/web_contents_view.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
@ -152,7 +151,7 @@ void InspectableWebContentsImpl::CloseDevTools() {
if (devtools_web_contents_) {
view_->CloseDevTools();
devtools_web_contents_.reset();
web_contents_->GetView()->Focus();
web_contents_->Focus();
}
}
@ -176,7 +175,7 @@ void InspectableWebContentsImpl::ActivateWindow() {
}
void InspectableWebContentsImpl::CloseWindow() {
devtools_web_contents()->GetMainFrame()->DispatchBeforeUnload(false);
devtools_web_contents()->DispatchBeforeUnload(false);
}
void InspectableWebContentsImpl::SetContentsResizingStrategy(
@ -289,7 +288,7 @@ void InspectableWebContentsImpl::DidFinishLoad(int64 frame_id,
view_->ShowDevTools();
}
void InspectableWebContentsImpl::WebContentsDestroyed(content::WebContents*) {
void InspectableWebContentsImpl::WebContentsDestroyed() {
content::DevToolsManager::GetInstance()->ClientHostClosing(
frontend_host_.get());
Observe(nullptr);

View file

@ -103,7 +103,7 @@ class InspectableWebContentsImpl :
const GURL& validated_url,
bool is_main_frame,
content::RenderViewHost*) OVERRIDE;
virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE;
virtual void WebContentsDestroyed() OVERRIDE;
// content::WebContentsDelegate

View file

@ -5,8 +5,6 @@
#include "browser/inspectable_web_contents.h"
#import "browser/mac/bry_inspectable_web_contents_view.h"
#include "content/public/browser/web_contents_view.h"
namespace brightray {
InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContentsImpl* inspectable_web_contents) {

View file

@ -3,13 +3,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-CHROMIUM file.
#include <libnotify/notify.h>
#include "browser/linux/notification_presenter_linux.h"
#include "base/strings/stringprintf.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/desktop_notification_delegate.h"
#include "content/public/common/show_desktop_notification_params.h"
#include "common/application_info.h"
@ -17,13 +16,7 @@ namespace brightray {
namespace {
const char *kRenderProcessIDKey = "RenderProcessID";
const char *kRenderViewIDKey = "RenderViewID";
const char *kNotificationIDKey = "NotificationID";
void log_and_clear_error(GError* error, const char* context) {
if (!error) return;
LOG(ERROR) << context
<< ": domain=" << error->domain
<< " code=" << error->code
@ -31,38 +24,15 @@ void log_and_clear_error(GError *error, const char *context) {
g_error_free(error);
}
int GetObjectInt(NotifyNotification *noti, const char *key) {
return GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), key));
}
void SetObjectInt(NotifyNotification *noti, const char *key, int value) {
g_object_set_data(G_OBJECT(noti), key, GINT_TO_POINTER(value));
}
void NotificationClosedCallback(NotifyNotification *noti, NotificationPresenterLinux *obj) {
int render_process_id = GetObjectInt(noti, kRenderProcessIDKey);
int render_view_id = GetObjectInt(noti, kRenderViewIDKey);
int notification_id = GetObjectInt(noti, kNotificationIDKey);
auto host = content::RenderViewHost::FromID(render_process_id, render_view_id);
if (host) host->DesktopNotificationPostClose(notification_id, false);
obj->RemoveNotification(noti);
}
void NotificationViewCallback(NotifyNotification *noti, const char *action,
NotificationPresenterLinux *obj) {
int render_process_id = GetObjectInt(noti, kRenderProcessIDKey);
int render_view_id = GetObjectInt(noti, kRenderViewIDKey);
int notification_id = GetObjectInt(noti, kNotificationIDKey);
auto host = content::RenderViewHost::FromID(render_process_id, render_view_id);
if (host) host->DesktopNotificationPostClick(notification_id);
obj->RemoveNotification(noti);
content::DesktopNotificationDelegate* GetDelegateFromNotification(
NotifyNotification* notification) {
return static_cast<content::DesktopNotificationDelegate*>(
g_object_get_data(G_OBJECT(notification), "delegate"));
}
} // namespace
// static
NotificationPresenter* NotificationPresenter::Create() {
if (!notify_is_initted()) {
notify_init(GetApplicationName().c_str());
@ -70,79 +40,71 @@ NotificationPresenter* NotificationPresenter::Create() {
return new NotificationPresenterLinux;
}
NotificationPresenterLinux::NotificationPresenterLinux() : notifications_(nullptr) { }
NotificationPresenterLinux::NotificationPresenterLinux()
: notifications_(nullptr) {
}
NotificationPresenterLinux::~NotificationPresenterLinux() {
// unref any outstanding notifications, and then free the list.
if (!notifications_) return;
for (GList *p = notifications_; p != nullptr; p = p->next) {
g_object_unref(G_OBJECT(p->data));
}
g_list_free(notifications_);
if (notifications_)
g_list_free_full(notifications_, g_object_unref);
}
void NotificationPresenterLinux::ShowNotification(
const content::ShowDesktopNotificationHostMsgParams& params,
int render_process_id,
int render_view_id) {
content::DesktopNotificationDelegate* delegate,
base::Closure* cancel_callback) {
std::string title = base::UTF16ToUTF8(params.title);
std::string body = base::UTF16ToUTF8(params.body);
NotifyNotification *noti = notify_notification_new(title.c_str(), body.c_str(), nullptr);
SetObjectInt(noti, kRenderProcessIDKey, render_process_id);
SetObjectInt(noti, kRenderViewIDKey, render_view_id);
SetObjectInt(noti, kNotificationIDKey, params.notification_id);
g_signal_connect(noti, "closed",
G_CALLBACK(NotificationClosedCallback), this);
notify_notification_add_action(noti, "default", "View",
(NotifyActionCallback)NotificationViewCallback, this, nullptr);
NotifyNotification* notification = notify_notification_new(title.c_str(), body.c_str(), nullptr);
notifications_ = g_list_append(notifications_, noti);
g_object_set_data(G_OBJECT(notification), "delegate", delegate);
g_signal_connect(notification, "closed", G_CALLBACK(OnNotificationClosedThunk), this);
notify_notification_add_action(notification, "default", "View", OnNotificationViewThunk, this,
nullptr);
GError* error = nullptr;
notify_notification_show(noti, &error);
notify_notification_show(notification, &error);
if (error) {
log_and_clear_error(error, "notify_notification_show");
auto host = content::RenderViewHost::FromID(render_process_id, render_view_id);
if (!host)
delegate->NotificationError();
return;
host->DesktopNotificationPostDisplay(params.notification_id);
}
void NotificationPresenterLinux::CancelNotification(
int render_process_id,
int render_view_id,
int notification_id) {
NotifyNotification *noti = nullptr;
for (GList *p = notifications_; p != nullptr; p = p->next) {
int rpid = GetObjectInt(noti, kRenderProcessIDKey);
int rvid = GetObjectInt(noti, kRenderViewIDKey);
int nid = GetObjectInt(noti, kNotificationIDKey);
if (render_process_id == rpid && render_view_id == rvid && notification_id == nid) {
noti = reinterpret_cast<NotifyNotification*>(p->data);
notifications_ = g_list_delete_link(notifications_, p);
break;
}
}
if (!noti)
return;
notifications_ = g_list_append(notifications_, notification);
delegate->NotificationDisplayed();
if (cancel_callback)
*cancel_callback = base::Bind(
&NotificationPresenterLinux::CancelNotification,
base::Unretained(this),
notification);
}
void NotificationPresenterLinux::CancelNotification(NotifyNotification* notification) {
GError* error = nullptr;
notify_notification_close(noti, &error);
notify_notification_close(notification, &error);
if (error)
log_and_clear_error(error, "notify_notification_close");
g_object_unref(noti);
auto host = content::RenderViewHost::FromID(render_process_id, render_view_id);
if (!host)
return;
host->DesktopNotificationPostClose(notification_id, false);
GetDelegateFromNotification(notification)->NotificationClosed(false);
DeleteNotification(notification);
}
void NotificationPresenterLinux::RemoveNotification(NotifyNotification *noti) {
notifications_ = g_list_remove(notifications_, noti);
g_object_unref(noti);
void NotificationPresenterLinux::DeleteNotification(NotifyNotification* notification) {
notifications_ = g_list_remove(notifications_, notification);
g_object_unref(notification);
}
void NotificationPresenterLinux::OnNotificationClosed(NotifyNotification* notification) {
GetDelegateFromNotification(notification)->NotificationClosed(false);
DeleteNotification(notification);
}
void NotificationPresenterLinux::OnNotificationView(
NotifyNotification* notification, char* action) {
GetDelegateFromNotification(notification)->NotificationClick();
DeleteNotification(notification);
}
} // namespace brightray

View file

@ -7,10 +7,12 @@
#define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_LINUX_H_
#include <libnotify/notify.h>
#include <map>
#include "base/compiler_specific.h"
#include "browser/notification_presenter.h"
#include "ui/base/glib/glib_signal.h"
namespace brightray {
@ -22,14 +24,18 @@ class NotificationPresenterLinux : public NotificationPresenter {
void RemoveNotification(NotifyNotification *notification);
private:
// NotificationPresenter:
virtual void ShowNotification(
const content::ShowDesktopNotificationHostMsgParams&,
int render_process_id,
int render_view_id) OVERRIDE;
virtual void CancelNotification(
int render_process_id,
int render_view_id,
int notification_id) OVERRIDE;
content::DesktopNotificationDelegate* delegate,
base::Closure* cancel_callback) OVERRIDE;
void CancelNotification(NotifyNotification* notification);
void DeleteNotification(NotifyNotification* notification);
CHROMEG_CALLBACK_0(NotificationPresenterLinux, void, OnNotificationClosed, NotifyNotification*);
CHROMEG_CALLBACK_1(NotificationPresenterLinux, void, OnNotificationView, NotifyNotification*,
char*);
// A list of all open NotifyNotification objects.
// We do lookups here both by NotifyNotification object (when the user

View file

@ -4,7 +4,6 @@
#include "browser/inspectable_web_contents_view_mac.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents_view.h"
#import "ui/base/cocoa/underlay_opengl_hosting_window.h"
#include "ui/gfx/mac/scoped_ns_disable_screen_updates.h"
@ -22,10 +21,15 @@ using namespace brightray;
devtools_docked_ = NO;
auto contents = inspectableWebContentsView_->inspectable_web_contents()->GetWebContents();
auto contentsView = contents->GetView()->GetNativeView();
contents->SetAllowOverlappingViews(true);
auto contentsView = contents->GetNativeView();
[contentsView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[self addSubview:contentsView];
// See https://code.google.com/p/chromium/issues/detail?id=348490.
[self setWantsLayer:YES];
return self;
}
@ -42,7 +46,7 @@ using namespace brightray;
return;
auto devToolsWebContents = inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents();
auto devToolsView = devToolsWebContents->GetView()->GetNativeView();
auto devToolsView = devToolsWebContents->GetNativeView();
devtools_visible_ = visible;
if (devtools_docked_) {
@ -53,7 +57,7 @@ using namespace brightray;
[self update];
} else {
gfx::ScopedNSDisableScreenUpdates disabler;
devToolsWebContents->GetView()->RemoveOverlayView();
devToolsWebContents->RemoveOverlayView();
[devToolsView removeFromSuperview];
[self adjustSubviews];
}
@ -79,7 +83,7 @@ using namespace brightray;
devtools_docked_ = docked;
if (!docked) {
auto devToolsWebContents = inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents();
auto devToolsView = devToolsWebContents->GetView()->GetNativeView();
auto devToolsView = devToolsWebContents->GetNativeView();
auto styleMask = NSTitledWindowMask | NSClosableWindowMask |
NSMiniaturizableWindowMask | NSResizableWindowMask |
@ -119,8 +123,8 @@ using namespace brightray;
auto devToolsWebContents = inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents();
gfx::ScopedNSDisableScreenUpdates disabler;
devToolsWebContents->GetView()->SetOverlayView(
contents->GetView(),
devToolsWebContents->SetOverlayView(
contents,
gfx::Point(strategy_.insets().left(), strategy_.insets().top()));
[self adjustSubviews];
}

View file

@ -1,7 +1,10 @@
#ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_H_
#define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_H_
#include "base/callback_forward.h"
namespace content {
class DesktopNotificationDelegate;
struct ShowDesktopNotificationHostMsgParams;
}
@ -15,12 +18,8 @@ class NotificationPresenter {
virtual void ShowNotification(
const content::ShowDesktopNotificationHostMsgParams&,
int render_process_id,
int render_view_id) = 0;
virtual void CancelNotification(
int render_process_id,
int render_view_id,
int notification_id) = 0;
content::DesktopNotificationDelegate* delegate,
base::Closure* cancel_callback) = 0;
};
} // namespace brightray

View file

@ -22,17 +22,27 @@ class NotificationPresenterMac : public NotificationPresenter {
virtual void ShowNotification(
const content::ShowDesktopNotificationHostMsgParams&,
int render_process_id,
int render_view_id) OVERRIDE;
virtual void CancelNotification(
int render_process_id,
int render_view_id,
int notification_id) OVERRIDE;
content::DesktopNotificationDelegate* delegate,
base::Closure* cancel_callback) OVERRIDE;
// Get the delegate accroding from the notification object.
content::DesktopNotificationDelegate* GetDelegateFromNotification(
NSUserNotification* notification);
// Remove the notification object accroding to its delegate.
void RemoveNotification(content::DesktopNotificationDelegate* delegate);
private:
typedef std::map<std::string, base::scoped_nsobject<NSUserNotification>>
NotificationMap;
NotificationMap notification_map_;
void CancelNotification(content::DesktopNotificationDelegate* delegate);
// The userInfo of NSUserNotification can not store pointers (because they are
// not in property list), so we have to track them in a C++ map.
// Also notice that the delegate acts as "ID" or "Key", because it is certain
// that each notification has a unique delegate.
typedef std::map<content::DesktopNotificationDelegate*, base::scoped_nsobject<NSUserNotification>>
NotificationsMap;
NotificationsMap notifications_map_;
base::scoped_nsobject<BRYUserNotificationCenterDelegate> delegate_;
};

View file

@ -5,146 +5,121 @@
#import "browser/notification_presenter_mac.h"
#import "base/strings/stringprintf.h"
#import "base/strings/sys_string_conversions.h"
#import "content/public/browser/render_view_host.h"
#import "content/public/common/show_desktop_notification_params.h"
#include "base/bind.h"
#include "base/stl_util.h"
#include "base/strings/sys_string_conversions.h"
#include "content/public/browser/desktop_notification_delegate.h"
#include "content/public/common/show_desktop_notification_params.h"
#import <Foundation/Foundation.h>
@interface BRYUserNotificationCenterDelegate : NSObject <NSUserNotificationCenterDelegate>
@interface BRYUserNotificationCenterDelegate : NSObject<NSUserNotificationCenterDelegate> {
@private
brightray::NotificationPresenterMac* presenter_;
}
- (instancetype)initWithNotificationPresenter:(brightray::NotificationPresenterMac*)presenter;
@end
namespace brightray {
namespace {
NSString * const kRenderProcessIDKey = @"RenderProcessID";
NSString * const kRenderViewIDKey = @"RenderViewID";
NSString * const kNotificationIDKey = @"NotificationID";
struct NotificationID {
NotificationID(
int render_process_id,
int render_view_id,
int notification_id)
: render_process_id(render_process_id),
render_view_id(render_view_id),
notification_id(notification_id) {
}
NotificationID(NSUserNotification* notification)
: render_process_id([[notification.userInfo objectForKey:kRenderProcessIDKey] intValue]),
render_view_id([[notification.userInfo objectForKey:kRenderViewIDKey] intValue]),
notification_id([[notification.userInfo objectForKey:kNotificationIDKey] intValue]) {
}
std::string GetID() {
return base::StringPrintf("%d:%d:%d", render_process_id, render_view_id, notification_id);
}
NSDictionary* GetUserInfo() {
return @{
kRenderProcessIDKey: @(render_process_id),
kRenderViewIDKey: @(render_view_id),
kNotificationIDKey: @(notification_id),
};
}
int render_process_id;
int render_view_id;
int notification_id;
};
base::scoped_nsobject<NSUserNotification> CreateUserNotification(
const content::ShowDesktopNotificationHostMsgParams& params,
int render_process_id,
int render_view_id) {
auto notification = [[NSUserNotification alloc] init];
notification.title = base::SysUTF16ToNSString(params.title);
notification.informativeText = base::SysUTF16ToNSString(params.body);
notification.userInfo = NotificationID(render_process_id, render_view_id, params.notification_id).GetUserInfo();
return base::scoped_nsobject<NSUserNotification>(notification);
}
}
} // namespace
NotificationPresenter* NotificationPresenter::Create() {
return new NotificationPresenterMac;
}
NotificationPresenterMac::NotificationPresenterMac()
: delegate_([[BRYUserNotificationCenterDelegate alloc] init]) {
: delegate_([[BRYUserNotificationCenterDelegate alloc] initWithNotificationPresenter:this]) {
NSUserNotificationCenter.defaultUserNotificationCenter.delegate = delegate_;
}
NotificationPresenterMac::~NotificationPresenterMac() {
NSUserNotificationCenter.defaultUserNotificationCenter.delegate = nil;
}
void NotificationPresenterMac::ShowNotification(
const content::ShowDesktopNotificationHostMsgParams& params,
int render_process_id,
int render_view_id) {
auto notification = CreateUserNotification(params, render_process_id, render_view_id);
notification_map_.insert(std::make_pair(NotificationID(notification).GetID(), notification));
content::DesktopNotificationDelegate* delegate,
base::Closure* cancel_callback) {
auto notification = [[NSUserNotification alloc] init];
notification.title = base::SysUTF16ToNSString(params.title);
notification.informativeText = base::SysUTF16ToNSString(params.body);
notifications_map_[delegate].reset(notification);
[NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification];
if (cancel_callback)
*cancel_callback = base::Bind(
&NotificationPresenterMac::CancelNotification,
base::Unretained(this),
delegate);
}
void NotificationPresenterMac::CancelNotification(
int render_process_id,
int render_view_id,
int notification_id) {
auto found = notification_map_.find(NotificationID(render_process_id, render_view_id, notification_id).GetID());
if (found == notification_map_.end())
content::DesktopNotificationDelegate* NotificationPresenterMac::GetDelegateFromNotification(
NSUserNotification* notification) {
for (NotificationsMap::const_iterator it = notifications_map_.begin();
it != notifications_map_.end(); ++it)
if ([it->second isEqual:notification])
return it->first;
return NULL;
}
void NotificationPresenterMac::RemoveNotification(content::DesktopNotificationDelegate* delegate) {
if (ContainsKey(notifications_map_, delegate))
notifications_map_.erase(delegate);
}
void NotificationPresenterMac::CancelNotification(content::DesktopNotificationDelegate* delegate) {
if (!ContainsKey(notifications_map_, delegate))
return;
auto notification = found->second;
notification_map_.erase(found);
// Notifications in -deliveredNotifications aren't the same objects we passed to
// -deliverNotification:, but they will respond YES to -isEqual:.
auto notification = notifications_map_[delegate];
auto center = NSUserNotificationCenter.defaultUserNotificationCenter;
for (NSUserNotification* deliveredNotification in center.deliveredNotifications) {
if (![notification isEqual:deliveredNotification])
continue;
for (NSUserNotification* deliveredNotification in center.deliveredNotifications)
if ([notification isEqual:deliveredNotification]) {
[center removeDeliveredNotification:deliveredNotification];
delegate->NotificationClosed(false);
break;
}
NotificationID ID(notification);
auto host = content::RenderViewHost::FromID(ID.render_process_id, ID.render_view_id);
if (!host)
return;
host->DesktopNotificationPostClose(ID.notification_id, false);
RemoveNotification(delegate);
}
}
} // namespace brightray
@implementation BRYUserNotificationCenterDelegate
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didDeliverNotification:(NSUserNotification *)notification {
brightray::NotificationID ID(notification);
- (instancetype)initWithNotificationPresenter:(brightray::NotificationPresenterMac*)presenter {
self = [super init];
if (!self)
return nil;
auto host = content::RenderViewHost::FromID(ID.render_process_id, ID.render_view_id);
if (!host)
return;
host->DesktopNotificationPostDisplay(ID.notification_id);
presenter_ = presenter;
return self;
}
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification {
brightray::NotificationID ID(notification);
auto host = content::RenderViewHost::FromID(ID.render_process_id, ID.render_view_id);
if (!host)
return;
host->DesktopNotificationPostClick(ID.notification_id);
- (void)userNotificationCenter:(NSUserNotificationCenter*)center
didDeliverNotification:(NSUserNotification*)notification {
auto delegate = presenter_->GetDelegateFromNotification(notification);
if (delegate)
delegate->NotificationDisplayed();
}
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification {
- (void)userNotificationCenter:(NSUserNotificationCenter*)center
didActivateNotification:(NSUserNotification *)notification {
auto delegate = presenter_->GetDelegateFromNotification(notification);
if (delegate) {
delegate->NotificationClick();
presenter_->RemoveNotification(delegate);
}
}
- (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center
shouldPresentNotification:(NSUserNotification*)notification {
// Display notifications even if the app is active.
return YES;
}

View file

@ -3,7 +3,6 @@
#include "browser/inspectable_web_contents_impl.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/web_contents_view.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"

@ -1 +1 @@
Subproject commit 4b4bcec11a02d1c7981562cf0b8a4670c338992b
Subproject commit a88222442d2a85345d9a208c23456956c208571d