1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef __JumpListItem_h__
7 #define __JumpListItem_h__
8 
9 #include <windows.h>
10 #include <shobjidl.h>
11 #undef LogSeverity  // SetupAPI.h #defines this as DWORD
12 
13 #include "mozilla/RefPtr.h"
14 #include "nsIJumpListItem.h"  // defines nsIJumpListItem
15 #include "nsIMIMEInfo.h"      // defines nsILocalHandlerApp
16 #include "nsTArray.h"
17 #include "nsIMutableArray.h"
18 #include "nsCOMPtr.h"
19 #include "nsIURI.h"
20 #include "nsICryptoHash.h"
21 #include "nsString.h"
22 #include "nsCycleCollectionParticipant.h"
23 
24 class nsIThread;
25 
26 namespace mozilla {
27 namespace widget {
28 
29 class JumpListItemBase : public nsIJumpListItem {
30  public:
JumpListItemBase()31   JumpListItemBase() : mItemType(nsIJumpListItem::JUMPLIST_ITEM_EMPTY) {}
32 
JumpListItemBase(int32_t type)33   explicit JumpListItemBase(int32_t type) : mItemType(type) {}
34 
35   NS_DECL_NSIJUMPLISTITEM
36 
37   static const char kJumpListCacheDir[];
38 
39  protected:
~JumpListItemBase()40   virtual ~JumpListItemBase() {}
41 
Type()42   short Type() { return mItemType; }
43   short mItemType;
44 };
45 
46 class JumpListItem : public JumpListItemBase {
~JumpListItem()47   ~JumpListItem() {}
48 
49  public:
50   using JumpListItemBase::JumpListItemBase;
51 
52   NS_DECL_ISUPPORTS
53 };
54 
55 class JumpListSeparator : public JumpListItemBase, public nsIJumpListSeparator {
~JumpListSeparator()56   ~JumpListSeparator() {}
57 
58  public:
JumpListSeparator()59   JumpListSeparator()
60       : JumpListItemBase(nsIJumpListItem::JUMPLIST_ITEM_SEPARATOR) {}
61 
62   NS_DECL_ISUPPORTS
63   NS_FORWARD_NSIJUMPLISTITEM(JumpListItemBase::)
64 
65   static nsresult GetSeparator(RefPtr<IShellLinkW> &aShellLink);
66 };
67 
68 class JumpListLink : public JumpListItemBase, public nsIJumpListLink {
~JumpListLink()69   ~JumpListLink() {}
70 
71  public:
JumpListLink()72   JumpListLink() : JumpListItemBase(nsIJumpListItem::JUMPLIST_ITEM_LINK) {}
73 
74   NS_DECL_ISUPPORTS
GetType(int16_t * aType)75   NS_IMETHOD GetType(int16_t *aType) override {
76     return JumpListItemBase::GetType(aType);
77   }
78   NS_IMETHOD Equals(nsIJumpListItem *item, bool *_retval) override;
79   NS_DECL_NSIJUMPLISTLINK
80 
81   static nsresult GetShellItem(nsCOMPtr<nsIJumpListItem> &item,
82                                RefPtr<IShellItem2> &aShellItem);
83   static nsresult GetJumpListLink(IShellItem *pItem,
84                                   nsCOMPtr<nsIJumpListLink> &aLink);
85 
86  protected:
87   nsString mUriTitle;
88   nsCOMPtr<nsIURI> mURI;
89   nsCOMPtr<nsICryptoHash> mCryptoHash;
90 };
91 
92 class JumpListShortcut : public JumpListItemBase, public nsIJumpListShortcut {
~JumpListShortcut()93   ~JumpListShortcut() {}
94 
95  public:
JumpListShortcut()96   JumpListShortcut()
97       : JumpListItemBase(nsIJumpListItem::JUMPLIST_ITEM_SHORTCUT) {}
98 
99   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(JumpListShortcut,JumpListItemBase)100   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(JumpListShortcut, JumpListItemBase)
101   NS_IMETHOD GetType(int16_t *aType) override {
102     return JumpListItemBase::GetType(aType);
103   }
104   NS_IMETHOD Equals(nsIJumpListItem *item, bool *_retval) override;
105   NS_DECL_NSIJUMPLISTSHORTCUT
106 
107   static nsresult GetShellLink(nsCOMPtr<nsIJumpListItem> &item,
108                                RefPtr<IShellLinkW> &aShellLink,
109                                nsCOMPtr<nsIThread> &aIOThread);
110   static nsresult GetJumpListShortcut(IShellLinkW *pLink,
111                                       nsCOMPtr<nsIJumpListShortcut> &aShortcut);
112   static nsresult GetOutputIconPath(nsCOMPtr<nsIURI> aFaviconPageURI,
113                                     nsCOMPtr<nsIFile> &aICOFile);
114 
115  protected:
116   int32_t mIconIndex;
117   nsCOMPtr<nsIURI> mFaviconPageURI;
118   nsCOMPtr<nsILocalHandlerApp> mHandlerApp;
119 
120   bool ExecutableExists(nsCOMPtr<nsILocalHandlerApp> &handlerApp);
121   static nsresult ObtainCachedIconFile(nsCOMPtr<nsIURI> aFaviconPageURI,
122                                        nsString &aICOFilePath,
123                                        nsCOMPtr<nsIThread> &aIOThread);
124   static nsresult CacheIconFileFromFaviconURIAsync(
125       nsCOMPtr<nsIURI> aFaviconPageURI, nsCOMPtr<nsIFile> aICOFile,
126       nsCOMPtr<nsIThread> &aIOThread);
127 };
128 
129 }  // namespace widget
130 }  // namespace mozilla
131 
132 #endif /* __JumpListItem_h__ */
133