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"
12 #include "nsIContentPolicy.h"
13 #include "nsISupports.h"
17 class imgRequestProxy
;
20 namespace mozilla::widget
{
23 * IconLoader is a utility for loading icons from either the disk or over
24 * the network, and then using them in native OS widgetry like the macOS
25 * global menu bar or the Windows notification area.
28 class IconLoader
: public imgINotificationObserver
{
31 * IconLoader itself is cross-platform, but each platform needs to supply
32 * it with a Helper that does the platform-specific conversion work. The
33 * Helper needs to implement the OnComplete method in order to handle the
34 * imgIContainer of the loaded icon.
36 class Helper
: public nsISupports
{
38 // Helper needs to implement nsISupports in order for its subclasses to
39 // participate in cycle collection
40 virtual nsresult
OnComplete(imgIContainer
* aContainer
,
41 const nsIntRect
& aRect
) = 0;
44 virtual ~Helper() = default;
47 IconLoader(Helper
* aHelper
, nsINode
* aContent
,
48 const nsIntRect
& aImageRegionRect
);
51 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
52 NS_DECL_IMGINOTIFICATIONOBSERVER
53 NS_DECL_CYCLE_COLLECTION_CLASS(IconLoader
)
55 // LoadIcon will start a load request for the icon.
56 // The request may not complete until after LoadIcon returns.
57 // If aIsInternalIcon is true, the document and principal will not be
59 nsresult
LoadIcon(nsIURI
* aIconURI
, bool aIsInternalIcon
= false);
61 void ReleaseJSObjects() { mContent
= nullptr; }
66 virtual ~IconLoader();
69 nsresult
OnFrameComplete(imgIRequest
* aRequest
);
71 nsCOMPtr
<nsINode
> mContent
;
72 nsContentPolicyType mContentType
;
73 RefPtr
<imgRequestProxy
> mIconRequest
;
74 nsIntRect mImageRegionRect
;
76 RefPtr
<Helper
> mHelper
;
79 } // namespace mozilla::widget
80 #endif // mozilla_widget_IconLoader_h_