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 "nsCOMPtr.h"
18 #include "nsIURI.h"
19 #include "nsICryptoHash.h"
20 #include "nsString.h"
21 #include "nsCycleCollectionParticipant.h"
22 
23 class nsIThread;
24 
25 namespace mozilla {
26 namespace widget {
27 
28 class JumpListItemBase : public nsIJumpListItem {
29  public:
JumpListItemBase()30   JumpListItemBase() : mItemType(nsIJumpListItem::JUMPLIST_ITEM_EMPTY) {}
31 
JumpListItemBase(int32_t type)32   explicit JumpListItemBase(int32_t type) : mItemType(type) {}
33 
34   NS_DECL_NSIJUMPLISTITEM
35 
36   static const char kJumpListCacheDir[];
37 
38  protected:
~JumpListItemBase()39   virtual ~JumpListItemBase() {}
40 
Type()41   short Type() { return mItemType; }
42   short mItemType;
43 };
44 
45 class JumpListItem : public JumpListItemBase {
~JumpListItem()46   ~JumpListItem() {}
47 
48  public:
49   using JumpListItemBase::JumpListItemBase;
50 
51   NS_DECL_ISUPPORTS
52 };
53 
54 class JumpListSeparator : public JumpListItemBase, public nsIJumpListSeparator {
~JumpListSeparator()55   ~JumpListSeparator() {}
56 
57  public:
JumpListSeparator()58   JumpListSeparator()
59       : JumpListItemBase(nsIJumpListItem::JUMPLIST_ITEM_SEPARATOR) {}
60 
61   NS_DECL_ISUPPORTS
62   NS_FORWARD_NSIJUMPLISTITEM(JumpListItemBase::)
63 
64   static nsresult GetSeparator(RefPtr<IShellLinkW>& aShellLink);
65 };
66 
67 class JumpListLink : public JumpListItemBase, public nsIJumpListLink {
~JumpListLink()68   ~JumpListLink() {}
69 
70  public:
JumpListLink()71   JumpListLink() : JumpListItemBase(nsIJumpListItem::JUMPLIST_ITEM_LINK) {}
72 
73   NS_DECL_ISUPPORTS
GetType(int16_t * aType)74   NS_IMETHOD GetType(int16_t* aType) override {
75     return JumpListItemBase::GetType(aType);
76   }
77   NS_IMETHOD Equals(nsIJumpListItem* item, bool* _retval) override;
78   NS_DECL_NSIJUMPLISTLINK
79 
80   static nsresult GetShellItem(nsCOMPtr<nsIJumpListItem>& item,
81                                RefPtr<IShellItem2>& aShellItem);
82   static nsresult GetJumpListLink(IShellItem* pItem,
83                                   nsCOMPtr<nsIJumpListLink>& aLink);
84 
85  protected:
86   nsString mUriTitle;
87   nsCOMPtr<nsIURI> mURI;
88   nsCOMPtr<nsICryptoHash> mCryptoHash;
89 };
90 
91 class JumpListShortcut : public JumpListItemBase, public nsIJumpListShortcut {
~JumpListShortcut()92   ~JumpListShortcut() {}
93 
94  public:
JumpListShortcut()95   JumpListShortcut()
96       : JumpListItemBase(nsIJumpListItem::JUMPLIST_ITEM_SHORTCUT) {}
97 
98   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(JumpListShortcut,JumpListItemBase)99   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(JumpListShortcut, JumpListItemBase)
100   NS_IMETHOD GetType(int16_t* aType) override {
101     return JumpListItemBase::GetType(aType);
102   }
103   NS_IMETHOD Equals(nsIJumpListItem* item, bool* _retval) override;
104   NS_DECL_NSIJUMPLISTSHORTCUT
105 
106   static nsresult GetShellLink(nsCOMPtr<nsIJumpListItem>& item,
107                                RefPtr<IShellLinkW>& aShellLink,
108                                nsCOMPtr<nsIThread>& aIOThread);
109   static nsresult GetJumpListShortcut(IShellLinkW* pLink,
110                                       nsCOMPtr<nsIJumpListShortcut>& aShortcut);
111   static nsresult GetOutputIconPath(nsCOMPtr<nsIURI> aFaviconPageURI,
112                                     nsCOMPtr<nsIFile>& aICOFile);
113 
114  protected:
115   int32_t mIconIndex;
116   nsCOMPtr<nsIURI> mFaviconPageURI;
117   nsCOMPtr<nsILocalHandlerApp> mHandlerApp;
118 
119   bool ExecutableExists(nsCOMPtr<nsILocalHandlerApp>& handlerApp);
120   static nsresult ObtainCachedIconFile(nsCOMPtr<nsIURI> aFaviconPageURI,
121                                        nsString& aICOFilePath,
122                                        nsCOMPtr<nsIThread>& aIOThread);
123   static nsresult CacheIconFileFromFaviconURIAsync(
124       nsCOMPtr<nsIURI> aFaviconPageURI, nsCOMPtr<nsIFile> aICOFile,
125       nsCOMPtr<nsIThread>& aIOThread);
126 };
127 
128 }  // namespace widget
129 }  // namespace mozilla
130 
131 #endif /* __JumpListItem_h__ */
132