1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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/. */
7 #ifndef nsMimeTypeArray_h___
8 #define nsMimeTypeArray_h___
12 #include "nsWrapperCache.h"
13 #include "nsPIDOMWindow.h"
14 #include "mozilla/dom/BindingDeclarations.h"
17 class nsPluginElement
;
19 class nsMimeTypeArray final
: public nsISupports
, public nsWrapperCache
{
21 explicit nsMimeTypeArray(nsPIDOMWindowInner
* aWindow
);
23 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
24 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsMimeTypeArray
)
26 nsPIDOMWindowInner
* GetParentObject() const;
27 virtual JSObject
* WrapObject(JSContext
* aCx
,
28 JS::Handle
<JSObject
*> aGivenProto
) override
;
32 // MimeTypeArray WebIDL methods
33 nsMimeType
* Item(uint32_t index
, mozilla::dom::CallerType aCallerType
);
34 nsMimeType
* NamedItem(const nsAString
& name
,
35 mozilla::dom::CallerType aCallerType
);
36 nsMimeType
* IndexedGetter(uint32_t index
, bool& found
,
37 mozilla::dom::CallerType aCallerType
);
38 nsMimeType
* NamedGetter(const nsAString
& name
, bool& found
,
39 mozilla::dom::CallerType aCallerType
);
40 uint32_t Length(mozilla::dom::CallerType aCallerType
);
41 void GetSupportedNames(nsTArray
<nsString
>& retval
,
42 mozilla::dom::CallerType aCallerType
);
45 virtual ~nsMimeTypeArray();
47 void EnsurePluginMimeTypes();
50 nsCOMPtr
<nsPIDOMWindowInner
> mWindow
;
52 // mMimeTypes contains MIME types handled by plugins or by an OS
53 // PreferredApplicationHandler.
54 nsTArray
<RefPtr
<nsMimeType
> > mMimeTypes
;
55 nsTArray
<RefPtr
<nsMimeType
> > mCTPMimeTypes
;
58 class nsMimeType final
: public nsWrapperCache
{
60 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsMimeType
)
61 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(nsMimeType
)
63 nsMimeType(nsPIDOMWindowInner
* aWindow
, nsPluginElement
* aPluginElement
,
64 const nsAString
& aType
, const nsAString
& aDescription
,
65 const nsAString
& aExtension
);
66 nsPIDOMWindowInner
* GetParentObject() const;
67 virtual JSObject
* WrapObject(JSContext
* aCx
,
68 JS::Handle
<JSObject
*> aGivenProto
) override
;
70 const nsString
& Type() const { return mType
; }
72 // MimeType WebIDL methods
73 void GetDescription(nsString
& retval
) const;
74 nsPluginElement
* GetEnabledPlugin() const;
75 void GetSuffixes(nsString
& retval
) const;
76 void GetType(nsString
& retval
) const;
79 virtual ~nsMimeType();
81 nsCOMPtr
<nsPIDOMWindowInner
> mWindow
;
83 // Strong reference to the active plugin. Note that this creates an explicit
84 // reference cycle through the plugin element's mimetype array. We rely on the
85 // cycle collector to break this cycle.
86 RefPtr
<nsPluginElement
> mPluginElement
;
88 nsString mDescription
;
92 #endif /* nsMimeTypeArray_h___ */