Bug 1631735 Part 1: Make nsCocoaWindow animated transitions asynchronous and atomic...
[gecko.git] / widget / IconLoader.h
blobf665df6fc57538dc3bb00c6c832997b0670ed6fe
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 mozilla_widget_IconLoader_h_
7 #define mozilla_widget_IconLoader_h_
9 #include "imgINotificationObserver.h"
10 #include "mozilla/RefPtr.h"
11 #include "nsCOMPtr.h"
12 #include "nsISupports.h"
14 class nsIURI;
15 class nsINode;
16 class imgRequestProxy;
17 class imgIContainer;
19 namespace mozilla::widget {
21 /**
22 * IconLoader is a utility for loading icons from either the disk or over
23 * the network, and then using them in native OS widgetry like the macOS
24 * global menu bar or the Windows notification area.
27 class IconLoader : public imgINotificationObserver {
28 public:
29 // This is the interface that our listeners need to implement so that they can
30 // be notified when the icon is loaded.
31 class Listener {
32 public:
33 virtual nsresult OnComplete(imgIContainer* aContainer) = 0;
36 // Create the loader.
37 // aListener will be notified when the load is complete.
38 // The loader does not keep an owning reference to the listener. Call Destroy
39 // before the listener goes away.
40 explicit IconLoader(Listener* aListener);
42 public:
43 NS_DECL_ISUPPORTS
44 NS_DECL_IMGINOTIFICATIONOBSERVER
46 // LoadIcon will start a load request for the icon.
47 // The request may not complete until after LoadIcon returns.
48 // If aIsInternalIcon is true, the document and principal will not be
49 // used when loading.
50 nsresult LoadIcon(nsIURI* aIconURI, nsINode* aNode,
51 bool aIsInternalIcon = false);
53 void Destroy();
55 protected:
56 virtual ~IconLoader();
58 private:
59 RefPtr<imgRequestProxy> mIconRequest;
61 // The listener, which is notified when loading completes.
62 // Can be null, after a call to Destroy.
63 // This is a non-owning reference and needs to be cleared with a call to
64 // Destroy before the listener goes away.
65 Listener* mListener;
68 } // namespace mozilla::widget
69 #endif // mozilla_widget_IconLoader_h_