1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=2 sw=2 et tw=79: */
3 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is mozilla.org code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Netscape Communications Corporation.
20 : * Portions created by the Initial Developer are Copyright (C) 1998
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef nsMimeTypeArray_h___
40 : #define nsMimeTypeArray_h___
41 :
42 : #include "nsIDOMMimeTypeArray.h"
43 : #include "nsIDOMMimeType.h"
44 : #include "nsString.h"
45 : #include "nsCOMPtr.h"
46 : #include "nsCOMArray.h"
47 :
48 : class nsIDOMNavigator;
49 :
50 : // NB: Due to weak references, nsNavigator has intimate knowledge of our
51 : // members.
52 : class nsMimeTypeArray : public nsIDOMMimeTypeArray
53 : {
54 : public:
55 : nsMimeTypeArray(nsIDOMNavigator* navigator);
56 : virtual ~nsMimeTypeArray();
57 :
58 : NS_DECL_ISUPPORTS
59 : NS_DECL_NSIDOMMIMETYPEARRAY
60 :
61 : void Refresh();
62 :
63 : nsIDOMMimeType* GetItemAt(PRUint32 aIndex, nsresult* aResult);
64 : nsIDOMMimeType* GetNamedItem(const nsAString& aName, nsresult* aResult);
65 :
66 0 : static nsMimeTypeArray* FromSupports(nsISupports* aSupports)
67 : {
68 : #ifdef DEBUG
69 : {
70 0 : nsCOMPtr<nsIDOMMimeTypeArray> array_qi = do_QueryInterface(aSupports);
71 :
72 : // If this assertion fires the QI implementation for the object in
73 : // question doesn't use the nsIDOMMimeTypeArray pointer as the nsISupports
74 : // pointer. That must be fixed, or we'll crash...
75 0 : NS_ASSERTION(array_qi == static_cast<nsIDOMMimeTypeArray*>(aSupports),
76 : "Uh, fix QI!");
77 : }
78 : #endif
79 :
80 0 : return static_cast<nsMimeTypeArray*>(aSupports);
81 : }
82 :
83 : void Invalidate()
84 : {
85 : // NB: This will cause GetMimeTypes to fail from now on.
86 : mNavigator = nsnull;
87 : Clear();
88 : }
89 :
90 : private:
91 : nsresult GetMimeTypes();
92 : void Clear();
93 :
94 : protected:
95 : nsIDOMNavigator* mNavigator;
96 : // Number of mimetypes handled by plugins.
97 : PRUint32 mPluginMimeTypeCount;
98 : // mMimeTypeArray contains all mimetypes handled by plugins
99 : // (mPluginMimeTypeCount) and any mimetypes that we handle internally and
100 : // have been looked up before. The number of items in mMimeTypeArray should
101 : // thus always be equal to or higher than mPluginMimeTypeCount.
102 : nsCOMArray<nsIDOMMimeType> mMimeTypeArray;
103 : bool mInited;
104 : };
105 :
106 : class nsMimeType : public nsIDOMMimeType
107 : {
108 : public:
109 : nsMimeType(nsIDOMPlugin* aPlugin, nsIDOMMimeType* aMimeType);
110 : virtual ~nsMimeType();
111 :
112 : NS_DECL_ISUPPORTS
113 : NS_DECL_NSIDOMMIMETYPE
114 :
115 0 : void DetachPlugin() { mPlugin = nsnull; }
116 :
117 : protected:
118 : nsIDOMPlugin* mPlugin;
119 : nsCOMPtr<nsIDOMMimeType> mMimeType;
120 : };
121 :
122 : class nsHelperMimeType : public nsIDOMMimeType
123 : {
124 : public:
125 0 : nsHelperMimeType(const nsAString& aType)
126 0 : : mType(aType)
127 : {
128 0 : }
129 :
130 0 : virtual ~nsHelperMimeType()
131 0 : {
132 0 : }
133 :
134 : NS_DECL_ISUPPORTS
135 : NS_DECL_NSIDOMMIMETYPE
136 :
137 : private:
138 : nsString mType;
139 : };
140 :
141 : #endif /* nsMimeTypeArray_h___ */
|