Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: chrome/browser/ui/views/status_icons/status_tray_state_changer_win.h

Issue 110693004: Moves the notification icon out of the status area overflow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_UI_VIEWS_STATUS_ICONS_STATUS_TRAY_STATE_CHANGER_WIN_H_
sky 2014/04/04 21:13:25 I'm assuming cpu reviewed all this code.
6 #define CHROME_BROWSER_UI_VIEWS_STATUS_ICONS_STATUS_TRAY_STATE_CHANGER_WIN_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string16.h"
10 #include "base/threading/non_thread_safe.h"
11 #include "base/win/iunknown_impl.h"
12 #include "base/win/scoped_comptr.h"
13
14 // The known values for NOTIFYITEM's dwPreference member.
15 enum NOTIFYITEM_PREFERENCE {
16 // In Windows UI: "Only show notifications."
17 PREFERENCE_SHOW_WHEN_ACTIVE = 0,
18 // In Windows UI: "Hide icon and notifications."
19 PREFERENCE_SHOW_NEVER = 1,
20 // In Windows UI: "Show icon and notifications."
21 PREFERENCE_SHOW_ALWAYS = 2
22 };
23
24 // NOTIFYITEM describes an entry in Explorer's registry of status icons.
25 // Explorer keeps entries around for a process even after it exits.
26 struct NOTIFYITEM {
27 PWSTR pszExeName; // The file name of the creating executable.
sky 2014/04/04 21:13:25 Even though I'm assuming cpu reviewed all this, ho
dewittj 2014/04/04 22:35:57 I guess I thought that in windows data structures
28 PWSTR pszTip; // The last hover-text value associated with this status item.
29 HICON hIcon; // The icon associated with this status item.
30 HWND hWnd; // The HWND associated with the status item.
31 DWORD dwPreference; // Determines the behavior of the icon with respect to
32 // the taskbar. Values taken from NOTIFYITEM_PREFERENCE.
33 UINT uID; // The ID specified by the application. (hWnd, uID) is unique.
34 GUID guidItem; // The GUID specified by the application, alternative to uID.
35 };
36
37 // INotificationCB is an interface that applications can implement in order to
38 // receive notifications about the state of the notification area manager.
39 class __declspec(uuid("D782CCBA-AFB0-43F1-94DB-FDA3779EACCB")) INotificationCB
40 : public IUnknown {
41 public:
42 virtual HRESULT STDMETHODCALLTYPE
43 Notify(ULONG event, NOTIFYITEM* notify_item) = 0;
44 };
45
46 // A class that is capable of reading and writing the state of the notification
47 // area in the Windows taskbar. It is used to promote a tray icon from the
48 // overflow area to the taskbar, and refuses to do anything if the user has
49 // explicitly marked an icon to be always hidden.
50 class StatusTrayStateChangerWin : public INotificationCB,
51 public base::win::IUnknownImpl,
52 public base::NonThreadSafe {
53 public:
54 StatusTrayStateChangerWin(UINT icon_id, HWND window);
55
56 // Call this method to move the icon matching |icon_id| and |window| to the
57 // taskbar from the overflow area. This will not make any changes if the
58 // icon has been set to |PREFERENCE_SHOW_NEVER|, in order to comply with
59 // the explicit wishes/configuration of the user.
60 void EnsureTrayIconVisible();
61
62 // IUnknown.
63 virtual ULONG STDMETHODCALLTYPE AddRef() OVERRIDE;
64 virtual ULONG STDMETHODCALLTYPE Release() OVERRIDE;
65 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, PVOID*) OVERRIDE;
66
67 // INotificationCB.
68 // Notify is called in response to RegisterCallback for each current
69 // entry in Explorer's list of notification area icons, and ever time
70 // one of them changes, until UnregisterCallback is called or |this|
71 // is destroyed.
72 virtual HRESULT STDMETHODCALLTYPE Notify(ULONG, NOTIFYITEM*);
73
74 protected:
75 virtual ~StatusTrayStateChangerWin();
76
77 private:
78 friend class StatusTrayStateChangerWinTest;
79
80 enum InterfaceVersion {
81 INTERFACE_VERSION_LEGACY = 0,
82 INTERFACE_VERSION_WIN8,
83 INTERFACE_VERSION_UNKNOWN
84 };
85
86 // Creates an instance of TrayNotify, and ensures that it supports either
87 // ITrayNotify or ITrayNotifyWin8. Returns true on success.
88 bool CreateTrayNotify();
89
90 // Returns the NOTIFYITEM that corresponds to this executable and the
91 // HWND/ID pair that were used to create the StatusTrayStateChangerWin.
92 // Internally it calls the appropriate RegisterCallback{Win8,Legacy}.
93 scoped_ptr<NOTIFYITEM> RegisterCallback();
94
95 // Calls RegisterCallback with the appropriate interface required by
96 // different versions of Windows. This will result in |notify_item_| being
97 // updated when a matching item is passed into
98 // StatusTrayStateChangerWin::Notify.
99 bool RegisterCallbackWin8();
100 bool RegisterCallbackLegacy();
101
102 // Sends an update to Explorer with the passed NOTIFYITEM.
103 void SendNotifyItemUpdate(scoped_ptr<NOTIFYITEM> notify_item);
104
105 // Storing IUnknown since we will need to use different interfaces
106 // for different versions of Windows.
107 base::win::ScopedComPtr<IUnknown> tray_notify_;
108 InterfaceVersion interface_version_;
109
110 // The ID assigned to the notification area icon that we want to manipulate.
111 const UINT icon_id_;
112 // The HWND associated with the notification area icon that we want to
113 // manipulate. This is an unretained pointer, do not dereference.
114 const HWND window_;
115 // Executable name of the current program. Along with |icon_id_| and
116 // |window_|, this uniquely identifies a notification area entry to Explorer.
117 base::string16 file_name_;
118
119 // Temporary storage for the matched NOTIFYITEM. This is necessary because
120 // Notify doesn't return anything. The call flow looks like this:
121 // TrayNotify->RegisterCallback()
122 // ... other COM stack frames ..
123 // StatusTrayStateChangerWin->Notify(NOTIFYITEM);
124 // so we can't just return the notifyitem we're looking for.
125 scoped_ptr<NOTIFYITEM> notify_item_;
126
127 DISALLOW_COPY_AND_ASSIGN(StatusTrayStateChangerWin);
128 };
129
130 #endif // CHROME_BROWSER_UI_VIEWS_STATUS_ICONS_STATUS_TRAY_STATE_CHANGER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698