dom/plugins/base/nsPluginStreamListenerPeer.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsPluginStreamListenerPeer_h_
michael@0 7 #define nsPluginStreamListenerPeer_h_
michael@0 8
michael@0 9 #include "nscore.h"
michael@0 10 #include "nsIFile.h"
michael@0 11 #include "nsIStreamListener.h"
michael@0 12 #include "nsIProgressEventSink.h"
michael@0 13 #include "nsIHttpHeaderVisitor.h"
michael@0 14 #include "nsWeakReference.h"
michael@0 15 #include "nsNPAPIPluginStreamListener.h"
michael@0 16 #include "nsDataHashtable.h"
michael@0 17 #include "nsHashKeys.h"
michael@0 18 #include "nsNPAPIPluginInstance.h"
michael@0 19 #include "nsIInterfaceRequestor.h"
michael@0 20 #include "nsIChannelEventSink.h"
michael@0 21
michael@0 22 class nsIChannel;
michael@0 23
michael@0 24 /**
michael@0 25 * When a plugin requests opens multiple requests to the same URL and
michael@0 26 * the request must be satified by saving a file to disk, each stream
michael@0 27 * listener holds a reference to the backing file: the file is only removed
michael@0 28 * when all the listeners are done.
michael@0 29 */
michael@0 30 class CachedFileHolder
michael@0 31 {
michael@0 32 public:
michael@0 33 CachedFileHolder(nsIFile* cacheFile);
michael@0 34 ~CachedFileHolder();
michael@0 35
michael@0 36 void AddRef();
michael@0 37 void Release();
michael@0 38
michael@0 39 nsIFile* file() const { return mFile; }
michael@0 40
michael@0 41 private:
michael@0 42 nsAutoRefCnt mRefCnt;
michael@0 43 nsCOMPtr<nsIFile> mFile;
michael@0 44 };
michael@0 45
michael@0 46 class nsPluginStreamListenerPeer : public nsIStreamListener,
michael@0 47 public nsIProgressEventSink,
michael@0 48 public nsIHttpHeaderVisitor,
michael@0 49 public nsSupportsWeakReference,
michael@0 50 public nsIInterfaceRequestor,
michael@0 51 public nsIChannelEventSink
michael@0 52 {
michael@0 53 public:
michael@0 54 nsPluginStreamListenerPeer();
michael@0 55 virtual ~nsPluginStreamListenerPeer();
michael@0 56
michael@0 57 NS_DECL_ISUPPORTS
michael@0 58 NS_DECL_NSIPROGRESSEVENTSINK
michael@0 59 NS_DECL_NSIREQUESTOBSERVER
michael@0 60 NS_DECL_NSISTREAMLISTENER
michael@0 61 NS_DECL_NSIHTTPHEADERVISITOR
michael@0 62 NS_DECL_NSIINTERFACEREQUESTOR
michael@0 63 NS_DECL_NSICHANNELEVENTSINK
michael@0 64
michael@0 65 // Called by RequestRead
michael@0 66 void
michael@0 67 MakeByteRangeString(NPByteRange* aRangeList, nsACString &string, int32_t *numRequests);
michael@0 68
michael@0 69 bool UseExistingPluginCacheFile(nsPluginStreamListenerPeer* psi);
michael@0 70
michael@0 71 // Called by GetURL and PostURL (via NewStream) or by the host in the case of
michael@0 72 // the initial plugin stream.
michael@0 73 nsresult Initialize(nsIURI *aURL,
michael@0 74 nsNPAPIPluginInstance *aInstance,
michael@0 75 nsNPAPIPluginStreamListener *aListener);
michael@0 76
michael@0 77 nsresult OnFileAvailable(nsIFile* aFile);
michael@0 78
michael@0 79 nsresult ServeStreamAsFile(nsIRequest *request, nsISupports *ctxt);
michael@0 80
michael@0 81 nsNPAPIPluginInstance *GetPluginInstance() { return mPluginInstance; }
michael@0 82
michael@0 83 nsresult RequestRead(NPByteRange* rangeList);
michael@0 84 nsresult GetLength(uint32_t* result);
michael@0 85 nsresult GetURL(const char** result);
michael@0 86 nsresult GetLastModified(uint32_t* result);
michael@0 87 nsresult IsSeekable(bool* result);
michael@0 88 nsresult GetContentType(char** result);
michael@0 89 nsresult GetStreamOffset(int32_t* result);
michael@0 90 nsresult SetStreamOffset(int32_t value);
michael@0 91
michael@0 92 void TrackRequest(nsIRequest* request)
michael@0 93 {
michael@0 94 mRequests.AppendObject(request);
michael@0 95 }
michael@0 96
michael@0 97 void ReplaceRequest(nsIRequest* oldRequest, nsIRequest* newRequest)
michael@0 98 {
michael@0 99 int32_t i = mRequests.IndexOfObject(oldRequest);
michael@0 100 if (i == -1) {
michael@0 101 NS_ASSERTION(mRequests.Count() == 0,
michael@0 102 "Only our initial stream should be unknown!");
michael@0 103 mRequests.AppendObject(oldRequest);
michael@0 104 }
michael@0 105 else {
michael@0 106 mRequests.ReplaceObjectAt(newRequest, i);
michael@0 107 }
michael@0 108 }
michael@0 109
michael@0 110 void CancelRequests(nsresult status)
michael@0 111 {
michael@0 112 // Copy the array to avoid modification during the loop.
michael@0 113 nsCOMArray<nsIRequest> requestsCopy(mRequests);
michael@0 114 for (int32_t i = 0; i < requestsCopy.Count(); ++i)
michael@0 115 requestsCopy[i]->Cancel(status);
michael@0 116 }
michael@0 117
michael@0 118 void SuspendRequests() {
michael@0 119 nsCOMArray<nsIRequest> requestsCopy(mRequests);
michael@0 120 for (int32_t i = 0; i < requestsCopy.Count(); ++i)
michael@0 121 requestsCopy[i]->Suspend();
michael@0 122 }
michael@0 123
michael@0 124 void ResumeRequests() {
michael@0 125 nsCOMArray<nsIRequest> requestsCopy(mRequests);
michael@0 126 for (int32_t i = 0; i < requestsCopy.Count(); ++i)
michael@0 127 requestsCopy[i]->Resume();
michael@0 128 }
michael@0 129
michael@0 130 private:
michael@0 131 nsresult SetUpStreamListener(nsIRequest* request, nsIURI* aURL);
michael@0 132 nsresult SetupPluginCacheFile(nsIChannel* channel);
michael@0 133 nsresult GetInterfaceGlobal(const nsIID& aIID, void** result);
michael@0 134
michael@0 135 nsCOMPtr<nsIURI> mURL;
michael@0 136 nsCString mURLSpec; // Have to keep this member because GetURL hands out char*
michael@0 137 nsRefPtr<nsNPAPIPluginStreamListener> mPStreamListener;
michael@0 138
michael@0 139 // Set to true if we request failed (like with a HTTP response of 404)
michael@0 140 bool mRequestFailed;
michael@0 141
michael@0 142 /*
michael@0 143 * Set to true after nsNPAPIPluginStreamListener::OnStartBinding() has
michael@0 144 * been called. Checked in ::OnStopRequest so we can call the
michael@0 145 * plugin's OnStartBinding if, for some reason, it has not already
michael@0 146 * been called.
michael@0 147 */
michael@0 148 bool mStartBinding;
michael@0 149 bool mHaveFiredOnStartRequest;
michael@0 150 // these get passed to the plugin stream listener
michael@0 151 uint32_t mLength;
michael@0 152 int32_t mStreamType;
michael@0 153
michael@0 154 // local cached file, we save the content into local cache if browser cache is not available,
michael@0 155 // or plugin asks stream as file and it expects file extension until bug 90558 got fixed
michael@0 156 nsRefPtr<CachedFileHolder> mLocalCachedFileHolder;
michael@0 157 nsCOMPtr<nsIOutputStream> mFileCacheOutputStream;
michael@0 158 nsDataHashtable<nsUint32HashKey, uint32_t>* mDataForwardToRequest;
michael@0 159
michael@0 160 nsCString mContentType;
michael@0 161 bool mSeekable;
michael@0 162 uint32_t mModified;
michael@0 163 nsRefPtr<nsNPAPIPluginInstance> mPluginInstance;
michael@0 164 int32_t mStreamOffset;
michael@0 165 bool mStreamComplete;
michael@0 166
michael@0 167 public:
michael@0 168 bool mAbort;
michael@0 169 int32_t mPendingRequests;
michael@0 170 nsWeakPtr mWeakPtrChannelCallbacks;
michael@0 171 nsWeakPtr mWeakPtrChannelLoadGroup;
michael@0 172 nsCOMArray<nsIRequest> mRequests;
michael@0 173 };
michael@0 174
michael@0 175 #endif // nsPluginStreamListenerPeer_h_

mercurial