1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Sean Echevarria <sean@beatnik.com>
24 : * HÃ¥kan Waara <hwaara@chello.se>
25 : * Josh Aas <josh@mozilla.com>
26 : *
27 : * Alternatively, the contents of this file may be used under the terms of
28 : * either the GNU General Public License Version 2 or later (the "GPL"), or
29 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 : * in which case the provisions of the GPL or the LGPL are applicable instead
31 : * of those above. If you wish to allow use of your version of this file only
32 : * under the terms of either the GPL or the LGPL, and not to allow others to
33 : * use your version of this file under the terms of the MPL, indicate your
34 : * decision by deleting the provisions above and replace them with the notice
35 : * and other provisions required by the GPL or the LGPL. If you do not delete
36 : * the provisions above, a recipient may use your version of this file under
37 : * the terms of any one of the MPL, the GPL or the LGPL.
38 : *
39 : * ***** END LICENSE BLOCK ***** */
40 :
41 : #ifndef nsPluginStreamListenerPeer_h_
42 : #define nsPluginStreamListenerPeer_h_
43 :
44 : #include "nscore.h"
45 : #include "nsIFile.h"
46 : #include "nsIStreamListener.h"
47 : #include "nsIProgressEventSink.h"
48 : #include "nsIHttpHeaderVisitor.h"
49 : #include "nsWeakReference.h"
50 : #include "nsNPAPIPluginStreamListener.h"
51 : #include "nsHashtable.h"
52 : #include "nsNPAPIPluginInstance.h"
53 : #include "nsIInterfaceRequestor.h"
54 : #include "nsIChannelEventSink.h"
55 : #include "nsObjectLoadingContent.h"
56 :
57 : class nsIChannel;
58 :
59 : /**
60 : * When a plugin requests opens multiple requests to the same URL and
61 : * the request must be satified by saving a file to disk, each stream
62 : * listener holds a reference to the backing file: the file is only removed
63 : * when all the listeners are done.
64 : */
65 : class CachedFileHolder
66 : {
67 : public:
68 : CachedFileHolder(nsIFile* cacheFile);
69 : ~CachedFileHolder();
70 :
71 : void AddRef();
72 : void Release();
73 :
74 0 : nsIFile* file() const { return mFile; }
75 :
76 : private:
77 : nsAutoRefCnt mRefCnt;
78 : nsCOMPtr<nsIFile> mFile;
79 : };
80 :
81 : class nsPluginStreamListenerPeer : public nsIStreamListener,
82 : public nsIProgressEventSink,
83 : public nsIHttpHeaderVisitor,
84 : public nsSupportsWeakReference,
85 : public nsINPAPIPluginStreamInfo,
86 : public nsIInterfaceRequestor,
87 : public nsIChannelEventSink
88 : {
89 : public:
90 : nsPluginStreamListenerPeer();
91 : virtual ~nsPluginStreamListenerPeer();
92 :
93 : NS_DECL_ISUPPORTS
94 : NS_DECL_NSIPROGRESSEVENTSINK
95 : NS_DECL_NSIREQUESTOBSERVER
96 : NS_DECL_NSISTREAMLISTENER
97 : NS_DECL_NSIHTTPHEADERVISITOR
98 : NS_DECL_NSIINTERFACEREQUESTOR
99 : NS_DECL_NSICHANNELEVENTSINK
100 :
101 : // nsINPAPIPluginStreamInfo interface
102 : NS_DECL_NSIPLUGINSTREAMINFO
103 :
104 : // Called by RequestRead
105 : void
106 : MakeByteRangeString(NPByteRange* aRangeList, nsACString &string, PRInt32 *numRequests);
107 :
108 : bool UseExistingPluginCacheFile(nsPluginStreamListenerPeer* psi);
109 :
110 : // Called by GetURL and PostURL (via NewStream)
111 : nsresult Initialize(nsIURI *aURL,
112 : nsNPAPIPluginInstance *aInstance,
113 : nsIPluginStreamListener *aListener);
114 :
115 : nsresult InitializeEmbedded(nsIURI *aURL,
116 : nsNPAPIPluginInstance* aInstance,
117 : nsObjectLoadingContent *aContent);
118 :
119 : nsresult InitializeFullPage(nsIURI* aURL, nsNPAPIPluginInstance *aInstance);
120 :
121 : nsresult OnFileAvailable(nsIFile* aFile);
122 :
123 : nsresult ServeStreamAsFile(nsIRequest *request, nsISupports *ctxt);
124 :
125 0 : nsNPAPIPluginInstance *GetPluginInstance() { return mPluginInstance; }
126 :
127 : private:
128 : nsresult SetUpStreamListener(nsIRequest* request, nsIURI* aURL);
129 : nsresult SetupPluginCacheFile(nsIChannel* channel);
130 : nsresult GetInterfaceGlobal(const nsIID& aIID, void** result);
131 :
132 : nsCOMPtr<nsIURI> mURL;
133 : nsCString mURLSpec; // Have to keep this member because GetURL hands out char*
134 : nsCOMPtr<nsIObjectLoadingContent> mContent;
135 : nsRefPtr<nsNPAPIPluginStreamListener> mPStreamListener;
136 :
137 : // Set to true if we request failed (like with a HTTP response of 404)
138 : bool mRequestFailed;
139 :
140 : /*
141 : * Set to true after nsIPluginStreamListener::OnStartBinding() has
142 : * been called. Checked in ::OnStopRequest so we can call the
143 : * plugin's OnStartBinding if, for some reason, it has not already
144 : * been called.
145 : */
146 : bool mStartBinding;
147 : bool mHaveFiredOnStartRequest;
148 : // these get passed to the plugin stream listener
149 : PRUint32 mLength;
150 : PRInt32 mStreamType;
151 :
152 : // local cached file, we save the content into local cache if browser cache is not available,
153 : // or plugin asks stream as file and it expects file extension until bug 90558 got fixed
154 : nsRefPtr<CachedFileHolder> mLocalCachedFileHolder;
155 : nsCOMPtr<nsIOutputStream> mFileCacheOutputStream;
156 : nsHashtable *mDataForwardToRequest;
157 :
158 : nsCString mContentType;
159 : bool mSeekable;
160 : PRUint32 mModified;
161 : nsRefPtr<nsNPAPIPluginInstance> mPluginInstance;
162 : PRInt32 mStreamOffset;
163 : bool mStreamComplete;
164 :
165 : public:
166 : bool mAbort;
167 : PRInt32 mPendingRequests;
168 : nsWeakPtr mWeakPtrChannelCallbacks;
169 : nsWeakPtr mWeakPtrChannelLoadGroup;
170 : };
171 :
172 : #endif // nsPluginStreamListenerPeer_h_
|