summaryrefslogtreecommitdiffstats
path: root/chrome/browser/notifications/desktop_notification_service_win.cc
blob: cc41eb4f98836b41c47c32ec44a7dc8106037e56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/notifications/desktop_notification_service.h"

#include "base/logging.h"
#include "base/win/metro.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_object_proxy.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "win8/util/win8_util.h"

bool DesktopNotificationService::CancelDesktopNotification(
    int process_id, int route_id, int notification_id) {
  scoped_refptr<NotificationObjectProxy> proxy(
      new NotificationObjectProxy(process_id, route_id, notification_id,
                                  false));
  if (win8::IsSingleWindowMetroMode()) {
    base::win::MetroCancelNotification cancel_metro_notification =
        reinterpret_cast<base::win::MetroCancelNotification>(GetProcAddress(
            base::win::GetMetroModule(), "CancelNotification"));
    DCHECK(cancel_metro_notification);
    if (cancel_metro_notification(proxy->id().c_str()))
      return true;
  }
  return GetUIManager()->CancelById(proxy->id());
}

void DesktopNotificationService::ShowNotification(
    const Notification& notification) {
  if (win8::IsSingleWindowMetroMode()) {
    base::win::MetroNotification display_metro_notification =
        reinterpret_cast<base::win::MetroNotification>(GetProcAddress(
            base::win::GetMetroModule(), "DisplayNotification"));
    DCHECK(display_metro_notification);
    if (!notification.is_html()) {
      display_metro_notification(notification.origin_url().spec().c_str(),
                                 notification.content_url().spec().c_str(),
                                 notification.title().c_str(),
                                 notification.message().c_str(),
                                 notification.display_source().c_str(),
                                 notification.notification_id().c_str(),
                                 NULL, NULL);
      return;
    } else {
      NOTREACHED() << "We don't support HTML notifications in Windows 8 metro";
    }
  }
  GetUIManager()->Add(notification, profile_);
}