1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2  *
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef mozilla_image_encoders_icon_win_nsIconChannel_h
8 #define mozilla_image_encoders_icon_win_nsIconChannel_h
9 
10 #include "mozilla/Attributes.h"
11 
12 #include "nsCOMPtr.h"
13 #include "nsString.h"
14 #include "nsIChannel.h"
15 #include "nsILoadGroup.h"
16 #include "nsILoadInfo.h"
17 #include "nsIInterfaceRequestor.h"
18 #include "nsIInterfaceRequestorUtils.h"
19 #include "nsIURI.h"
20 #include "nsIInputStreamPump.h"
21 #include "nsIOutputStream.h"
22 #include "nsIStreamListener.h"
23 #include "nsIIconURI.h"
24 
25 #include <windows.h>
26 
27 class nsIFile;
28 
29 class nsIconChannel final : public nsIChannel, public nsIStreamListener {
30   ~nsIconChannel();
31 
32  public:
33   NS_DECL_THREADSAFE_ISUPPORTS
34   NS_DECL_NSIREQUEST
35   NS_DECL_NSICHANNEL
36   NS_DECL_NSIREQUESTOBSERVER
37   NS_DECL_NSISTREAMLISTENER
38 
39   nsIconChannel();
40 
41   nsresult Init(nsIURI* uri);
42 
43  protected:
44   class IconAsyncOpenTask;
45   class IconSyncOpenTask;
46 
47   void OnAsyncError(nsresult aStatus);
48   void FinishAsyncOpen(HICON aIcon, nsresult aStatus);
49   nsresult EnsurePipeCreated(uint32_t aIconSize, bool aNonBlocking);
50 
51   nsCOMPtr<nsIURI> mUrl;
52   nsCOMPtr<nsIURI> mOriginalURI;
53   nsCOMPtr<nsILoadGroup> mLoadGroup;
54   nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
55   nsCOMPtr<nsISupports> mOwner;
56   nsCOMPtr<nsILoadInfo> mLoadInfo;
57 
58   nsCOMPtr<nsIInputStreamPump> mPump;
59   nsCOMPtr<nsIInputStream> mInputStream;
60   nsCOMPtr<nsIOutputStream> mOutputStream;
61   nsCOMPtr<nsIStreamListener> mListener;
62   nsCOMPtr<nsIEventTarget> mListenerTarget;
63 
64   nsresult ExtractIconInfoFromUrl(nsIFile** aLocalFile,
65                                   uint32_t* aDesiredImageSize,
66                                   nsCString& aContentType,
67                                   nsCString& aFileExtension);
68   nsresult GetHIcon(bool aNonBlocking, HICON* hIcon);
69   nsresult GetHIconFromFile(bool aNonBlocking, HICON* hIcon);
70   nsresult GetHIconFromFile(nsIFile* aLocalFile, const nsAutoString& aPath,
71                             UINT aInfoFlags, HICON* hIcon);
72   [[nodiscard]] nsresult MakeInputStream(nsIInputStream** _retval,
73                                          bool aNonBlocking, HICON aIcon);
74 
75   // Functions specific to Vista and above
76  protected:
77   nsresult GetStockHIcon(nsIMozIconURI* aIconURI, HICON* hIcon);
78 
79  private:
80   bool mCanceled = false;
81 };
82 
83 #endif  // mozilla_image_encoders_icon_win_nsIconChannel_h
84