OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/message_center/web_notification_tray.h" | 5 #include "chrome/browser/ui/views/message_center/web_notification_tray.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <objbase.h> |
8 | 9 |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/threading/worker_pool.h" |
| 12 #include "base/win/scoped_com_initializer.h" |
9 #include "base/win/windows_version.h" | 13 #include "base/win/windows_version.h" |
10 #include "chrome/browser/app_icon_win.h" | 14 #include "chrome/browser/app_icon_win.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
12 #include "chrome/browser/status_icons/status_icon.h" | 16 #include "chrome/browser/status_icons/status_icon.h" |
13 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/host_desktop.h" | 18 #include "chrome/browser/ui/host_desktop.h" |
15 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 19 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
16 #include "chrome/browser/ui/singleton_tabs.h" | 20 #include "chrome/browser/ui/singleton_tabs.h" |
| 21 #include "chrome/browser/ui/views/message_center/tray_watcher_win.h" |
| 22 #include "chrome/browser/ui/views/status_icons/status_icon_win.h" |
17 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
18 #include "grit/chromium_strings.h" | 24 #include "grit/chromium_strings.h" |
19 #include "third_party/skia/include/core/SkBitmap.h" | 25 #include "third_party/skia/include/core/SkBitmap.h" |
20 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
22 #include "ui/gfx/image/image_skia.h" | 28 #include "ui/gfx/image/image_skia.h" |
23 | 29 |
| 30 namespace { |
| 31 |
| 32 // This method is called on a worker pool thread. |
| 33 void PromoteMatchingTrayIcon(UINT icon_id, HWND window) { |
| 34 // It appears that IUnknowns are coincidentally compatible with |
| 35 // scoped_refptr. Normally I wouldn't depend on that but it seems that |
| 36 // base::win::IUnknownImpl itself depends on that coincidence so it's |
| 37 // already being assumed elsewhere. |
| 38 scoped_refptr<message_center::TrayWatcherWin> tray_watcher( |
| 39 new message_center::TrayWatcherWin(icon_id, window)); |
| 40 tray_watcher->EnsureTrayIconVisible(); |
| 41 } |
| 42 |
| 43 } // namespace |
| 44 |
24 namespace message_center { | 45 namespace message_center { |
25 void WebNotificationTray::OnBalloonClicked() { | 46 void WebNotificationTray::OnBalloonClicked() { |
26 chrome::ScopedTabbedBrowserDisplayer displayer( | 47 chrome::ScopedTabbedBrowserDisplayer displayer( |
27 ProfileManager::GetLastUsedProfileAllowedByPolicy(), | 48 ProfileManager::GetLastUsedProfileAllowedByPolicy(), |
28 chrome::GetActiveDesktop()); | 49 chrome::GetActiveDesktop()); |
29 chrome::ShowSingletonTab(displayer.browser(), | 50 chrome::ShowSingletonTab(displayer.browser(), |
30 GURL(chrome::kNotificationsHelpURL)); | 51 GURL(chrome::kNotificationsHelpURL)); |
31 } | 52 } |
32 | 53 |
33 void WebNotificationTray::DisplayFirstRunBalloon() { | 54 void WebNotificationTray::DisplayFirstRunBalloon() { |
(...skipping 15 matching lines...) Expand all Loading... |
49 icon_size = GetSystemMetrics(SM_CXSMICON); | 70 icon_size = GetSystemMetrics(SM_CXSMICON); |
50 | 71 |
51 scoped_ptr<SkBitmap> sized_app_icon_bitmap = GetAppIconForSize(icon_size); | 72 scoped_ptr<SkBitmap> sized_app_icon_bitmap = GetAppIconForSize(icon_size); |
52 gfx::ImageSkia sized_app_icon_skia = | 73 gfx::ImageSkia sized_app_icon_skia = |
53 gfx::ImageSkia::CreateFrom1xBitmap(*sized_app_icon_bitmap); | 74 gfx::ImageSkia::CreateFrom1xBitmap(*sized_app_icon_bitmap); |
54 status_icon_->DisplayBalloon( | 75 status_icon_->DisplayBalloon( |
55 sized_app_icon_skia, | 76 sized_app_icon_skia, |
56 l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_BALLOON_TITLE), | 77 l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_BALLOON_TITLE), |
57 l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_BALLOON_TEXT)); | 78 l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_BALLOON_TEXT)); |
58 } | 79 } |
| 80 |
| 81 void WebNotificationTray::EnforceStatusIconVisible() { |
| 82 DCHECK(status_icon_); |
| 83 StatusIconWin* status_icon_win = status_icon_->AsStatusIconWin(); |
| 84 // If we are in single-window metro mode, can't really do anything |
| 85 // here. |
| 86 if (status_icon_win == NULL) |
| 87 return; |
| 88 |
| 89 worker_thread_.reset(new base::Thread("COMWorkerThread")); |
| 90 worker_thread_->init_com_with_mta(false); |
| 91 worker_thread_->Start(); |
| 92 worker_thread_->message_loop_proxy()->PostTaskAndReply( |
| 93 FROM_HERE, |
| 94 base::Bind(PromoteMatchingTrayIcon, |
| 95 status_icon_win->icon_id(), |
| 96 status_icon_win->hwnd()), |
| 97 base::Bind(&WebNotificationTray::JoinWorkerThread, AsWeakPtr())); |
| 98 } |
| 99 |
| 100 void WebNotificationTray::JoinWorkerThread() { |
| 101 if (worker_thread_) { |
| 102 worker_thread_->Stop(); |
| 103 worker_thread_.reset(); |
| 104 } |
| 105 } |
| 106 |
59 } // namespace message_center | 107 } // namespace message_center |
OLD | NEW |