<commit_before>// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright (c) 2013 <NAME> <<EMAIL>>. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-CHROMIUM file.

#import "browser/notification_presenter_mac.h"

#include "base/bind.h"
#include "base/stl_util.h"
#include "base/mac/mac_util.h"
#include "base/strings/sys_string_conversions.h"
#include "content/public/common/platform_notification_data.h"
#include "content/public/browser/desktop_notification_delegate.h"
#include "skia/ext/skia_utils_mac.h"

#import <Foundation/Foundation.h>

@interface BRYUserNotificationCenterDelegate : NSObject<NSUserNotificationCenterDelegate> {
 @private
  brightray::NotificationPresenterMac* presenter_;
}
- (instancetype)initWithNotificationPresenter:(brightray::NotificationPresenterMac*)presenter;
@end

namespace brightray {

namespace {

}  // namespace

NotificationPresenter* NotificationPresenter::Create() {
  return new NotificationPresenterMac;
}

NotificationPresenterMac::NotificationPresenterMac()
    : delegate_([[BRYUserNotificationCenterDelegate alloc] initWithNotificationPresenter:this]) {
  NSUserNotificationCenter.defaultUserNotificationCenter.delegate = delegate_;
}

NotificationPresenterMac::~NotificationPresenterMac() {
  NSUserNotificationCenter.defaultUserNotificationCenter.delegate = nil;
}

void NotificationPresenterMac::ShowNotification(
    const content::PlatformNotificationData& data,
    const SkBitmap& icon,
    scoped_ptr<content::DesktopNotificationDelegate> delegate,
    base::Closure* cancel_callback) {
  auto notification = [[NSUserNotification alloc] init];
  notification.title = base::SysUTF16ToNSString(data.title);
  notification.informativeText = base::SysUTF16ToNSString(data.body);
  notification.contentImage = gfx::SkBitmapToNSImageWithColorSpace(icon, base::mac::GetGenericRGBColorSpace());

  notifications_map_[delegate.get()].reset(notification);
  [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification];<commit_msg>Ensure we don't try to set contentImage on 10.7/10.8. That would be rude!<commit_after>// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright (c) 2013 <NAME> <<EMAIL>>. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-CHROMIUM file.

#import "browser/notification_presenter_mac.h"

#include "base/bind.h"
#include "base/stl_util.h"
#include "base/mac/mac_util.h"
#include "base/mac/sdk_forward_declarations.h"
#include "base/strings/sys_string_conversions.h"
#include "content/public/common/platform_notification_data.h"
#include "content/public/browser/desktop_notification_delegate.h"
#include "skia/ext/skia_utils_mac.h"

#import <Foundation/Foundation.h>

@interface BRYUserNotificationCenterDelegate : NSObject<NSUserNotificationCenterDelegate> {
 @private
  brightray::NotificationPresenterMac* presenter_;
}
- (instancetype)initWithNotificationPresenter:(brightray::NotificationPresenterMac*)presenter;
@end

namespace brightray {

namespace {

}  // namespace

NotificationPresenter* NotificationPresenter::Create() {
  return new NotificationPresenterMac;
}

NotificationPresenterMac::NotificationPresenterMac()
    : delegate_([[BRYUserNotificationCenterDelegate alloc] initWithNotificationPresenter:this]) {
  NSUserNotificationCenter.defaultUserNotificationCenter.delegate = delegate_;
}

NotificationPresenterMac::~NotificationPresenterMac() {
  NSUserNotificationCenter.defaultUserNotificationCenter.delegate = nil;
}

void NotificationPresenterMac::ShowNotification(
    const content::PlatformNotificationData& data,
    const SkBitmap& icon,
    scoped_ptr<content::DesktopNotificationDelegate> delegate,
    base::Closure* cancel_callback) {
  auto notification = [[NSUserNotification alloc] init];
  notification.title = base::SysUTF16ToNSString(data.title);
  notification.informativeText = base::SysUTF16ToNSString(data.body);

  if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_9)
    notification.contentImage = gfx::SkBitmapToNSImageWithColorSpace(icon, base::mac::GetGenericRGBColorSpace());

  notifications_map_[delegate.get()].reset(notification);
  [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification];
{'fraction_non_alphanumeric': 0.10162508583199817, 'fraction_numerical': 0.007553215838864729, 'mean_word_length': 7.518518518518518, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '970450', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1208, 'n_words': 232}