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/. */
6 #ifndef __JumpListBuilder_h__
7 #define __JumpListBuilder_h__
9 #include "nsIJumpListBuilder.h"
11 #include "nsIObserver.h"
12 #include "nsProxyRelease.h"
13 #include "mozilla/LazyIdleThread.h"
18 struct WindowsJumpListShortcutDescription
;
24 * This is an abstract class for a backend to write to the Windows Jump List.
26 * It has a 1-to-1 method mapping with ICustomDestinationList. The abtract
27 * class allows us to implement a "fake" backend for automated testing.
29 class JumpListBackend
{
30 NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
32 virtual bool IsAvailable() = 0;
34 virtual HRESULT
SetAppID(LPCWSTR pszAppID
) = 0;
35 virtual HRESULT
BeginList(UINT
* pcMinSlots
, REFIID riid
, void** ppv
) = 0;
36 virtual HRESULT
AddUserTasks(IObjectArray
* poa
) = 0;
37 virtual HRESULT
AppendCategory(LPCWSTR pszCategory
, IObjectArray
* poa
) = 0;
38 virtual HRESULT
CommitList() = 0;
39 virtual HRESULT
AbortList() = 0;
40 virtual HRESULT
DeleteList(LPCWSTR pszAppID
) = 0;
41 virtual HRESULT
AppendKnownCategory(KNOWNDESTCATEGORY category
) = 0;
44 virtual ~JumpListBackend() {}
48 * JumpListBuilder is a component that can be used to manage the Windows
49 * Jump List off of the main thread.
51 class JumpListBuilder
: public nsIJumpListBuilder
, public nsIObserver
{
52 virtual ~JumpListBuilder();
55 NS_DECL_THREADSAFE_ISUPPORTS
56 NS_DECL_NSIJUMPLISTBUILDER
59 explicit JumpListBuilder(const nsAString
& aAppUserModelId
,
60 RefPtr
<JumpListBackend
> aTestingBackend
= nullptr);
63 // These all run on the lazy helper thread.
64 void DoSetupBackend();
65 void DoSetupTestingBackend(RefPtr
<JumpListBackend
> aTestingBackend
);
66 void DoShutdownBackend();
67 void DoSetAppIDIfAvailable(nsString aAppUserModelID
);
68 void DoIsAvailable(const nsMainThreadPtrHandle
<dom::Promise
>& aPromiseHolder
);
69 void DoCheckForRemovals(
70 const nsMainThreadPtrHandle
<dom::Promise
>& aPromiseHolder
);
71 void DoPopulateJumpList(
72 const nsTArray
<dom::WindowsJumpListShortcutDescription
>&&
74 const nsAString
& aCustomTitle
,
75 const nsTArray
<dom::WindowsJumpListShortcutDescription
>&&
77 const nsMainThreadPtrHandle
<dom::Promise
>& aPromiseHolder
);
79 const nsMainThreadPtrHandle
<dom::Promise
>& aPromiseHolder
);
80 void RemoveIconCacheAndGetJumplistShortcutURIs(IObjectArray
* aObjArray
,
81 nsTArray
<nsString
>& aURISpecs
);
82 void DeleteIconFromDisk(const nsAString
& aPath
);
83 nsresult
GetShellLinkFromDescription(
84 const dom::WindowsJumpListShortcutDescription
& aDesc
,
85 RefPtr
<IShellLinkW
>& aShellLink
);
87 // This is written to once during construction on the main thread before the
88 // lazy helper thread is created. After that, the lazy helper thread might
90 nsString mAppUserModelId
;
92 // This is only accessed by the lazy helper thread.
93 RefPtr
<JumpListBackend
> mJumpListBackend
;
95 // This is only accessed by the main thread.
96 RefPtr
<LazyIdleThread
> mIOThread
;
100 } // namespace mozilla
102 #endif /* __JumpListBuilder_h__ */