2008-09-30 16:56:57 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is worker threads.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2008
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Ben Turner <bent.mozilla@gmail.com> (Original Author)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef __NSDOMWORKERXHRPROXIEDFUNCTIONS_H__
|
|
|
|
#define __NSDOMWORKERXHRPROXIEDFUNCTIONS_H__
|
|
|
|
|
|
|
|
#define MAKE_PROXIED_FUNCTION0(_name) \
|
2008-10-14 11:16:37 -07:00
|
|
|
class _name : public SyncEventCapturingRunnable \
|
2008-09-30 16:56:57 -07:00
|
|
|
{ \
|
|
|
|
public: \
|
2008-10-14 11:16:37 -07:00
|
|
|
_name (nsDOMWorkerXHRProxy* aXHR, SyncEventQueue* aQueue) \
|
|
|
|
: SyncEventCapturingRunnable(aXHR, aQueue) { } \
|
2008-09-30 16:56:57 -07:00
|
|
|
\
|
2008-10-14 11:16:37 -07:00
|
|
|
virtual nsresult RunInternal() \
|
2008-09-30 16:56:57 -07:00
|
|
|
{ \
|
|
|
|
nsCOMPtr<nsIXMLHttpRequest> xhr = mXHR->GetXMLHttpRequest(); \
|
|
|
|
if (xhr) { \
|
|
|
|
return xhr-> _name (); \
|
|
|
|
} \
|
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAKE_PROXIED_FUNCTION1(_name, _arg1) \
|
2008-10-14 11:16:37 -07:00
|
|
|
class _name : public SyncEventCapturingRunnable \
|
2008-09-30 16:56:57 -07:00
|
|
|
{ \
|
|
|
|
public: \
|
2008-10-14 11:16:37 -07:00
|
|
|
_name (nsDOMWorkerXHRProxy* aXHR, SyncEventQueue* aQueue, _arg1 aArg1) \
|
|
|
|
: SyncEventCapturingRunnable(aXHR, aQueue), mArg1(aArg1) { } \
|
2008-09-30 16:56:57 -07:00
|
|
|
\
|
2008-10-14 11:16:37 -07:00
|
|
|
virtual nsresult RunInternal() \
|
2008-09-30 16:56:57 -07:00
|
|
|
{ \
|
|
|
|
nsCOMPtr<nsIXMLHttpRequest> xhr = mXHR->GetXMLHttpRequest(); \
|
|
|
|
if (xhr) { \
|
|
|
|
return xhr-> _name (mArg1); \
|
|
|
|
} \
|
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
private: \
|
|
|
|
_arg1 mArg1; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAKE_PROXIED_FUNCTION2(_name, _arg1, _arg2) \
|
2008-10-14 11:16:37 -07:00
|
|
|
class _name : public SyncEventCapturingRunnable \
|
2008-09-30 16:56:57 -07:00
|
|
|
{ \
|
|
|
|
public: \
|
2008-10-14 11:16:37 -07:00
|
|
|
_name (nsDOMWorkerXHRProxy* aXHR, SyncEventQueue* aQueue, _arg1 aArg1, \
|
|
|
|
_arg2 aArg2) \
|
|
|
|
: SyncEventCapturingRunnable(aXHR, aQueue), mArg1(aArg1), mArg2(aArg2) { } \
|
2008-09-30 16:56:57 -07:00
|
|
|
\
|
2008-10-14 11:16:37 -07:00
|
|
|
virtual nsresult RunInternal() \
|
2008-09-30 16:56:57 -07:00
|
|
|
{ \
|
|
|
|
nsCOMPtr<nsIXMLHttpRequest> xhr = mXHR->GetXMLHttpRequest(); \
|
|
|
|
if (xhr) { \
|
|
|
|
return xhr-> _name (mArg1, mArg2); \
|
|
|
|
} \
|
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
private: \
|
|
|
|
_arg1 mArg1; \
|
|
|
|
_arg2 mArg2; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAKE_PROXIED_FUNCTION3(_name, _arg1, _arg2, _arg3) \
|
2008-10-14 11:16:37 -07:00
|
|
|
class _name : public SyncEventCapturingRunnable \
|
2008-09-30 16:56:57 -07:00
|
|
|
{ \
|
|
|
|
public: \
|
2008-10-14 11:16:37 -07:00
|
|
|
_name (nsDOMWorkerXHRProxy* aXHR, SyncEventQueue* aQueue, _arg1 aArg1, \
|
|
|
|
_arg2 aArg2, _arg3 aArg3) \
|
|
|
|
: SyncEventCapturingRunnable(aXHR, aQueue), mArg1(aArg1), mArg2(aArg2), \
|
|
|
|
mArg3(aArg3) { } \
|
2008-09-30 16:56:57 -07:00
|
|
|
\
|
2008-10-14 11:16:37 -07:00
|
|
|
virtual nsresult RunInternal() \
|
2008-09-30 16:56:57 -07:00
|
|
|
{ \
|
|
|
|
nsCOMPtr<nsIXMLHttpRequest> xhr = mXHR->GetXMLHttpRequest(); \
|
|
|
|
if (xhr) { \
|
|
|
|
return xhr-> _name (mArg1, mArg2, mArg3); \
|
|
|
|
} \
|
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
private: \
|
|
|
|
_arg1 mArg1; \
|
|
|
|
_arg2 mArg2; \
|
|
|
|
_arg3 mArg3; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAKE_PROXIED_FUNCTION4(_name, _arg1, _arg2, _arg3, _arg4) \
|
2008-10-14 11:16:37 -07:00
|
|
|
class _name : public SyncEventCapturingRunnable \
|
2008-09-30 16:56:57 -07:00
|
|
|
{ \
|
|
|
|
public: \
|
2008-10-14 11:16:37 -07:00
|
|
|
_name (nsDOMWorkerXHRProxy* aXHR, SyncEventQueue* aQueue, _arg1 aArg1, \
|
|
|
|
_arg2 aArg2, _arg3 aArg3, _arg4 aArg4) \
|
|
|
|
: SyncEventCapturingRunnable(aXHR, aQueue), mArg1(aArg1), mArg2(aArg2), \
|
|
|
|
mArg3(aArg3), mArg4(aArg4) { } \
|
2008-09-30 16:56:57 -07:00
|
|
|
\
|
2008-10-14 11:16:37 -07:00
|
|
|
virtual nsresult RunInternal() \
|
2008-09-30 16:56:57 -07:00
|
|
|
{ \
|
|
|
|
nsCOMPtr<nsIXMLHttpRequest> xhr = mXHR->GetXMLHttpRequest(); \
|
|
|
|
if (xhr) { \
|
|
|
|
return xhr-> _name (mArg1, mArg2, mArg3, mArg4); \
|
|
|
|
} \
|
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
private: \
|
|
|
|
_arg1 mArg1; \
|
|
|
|
_arg2 mArg2; \
|
|
|
|
_arg3 mArg3; \
|
|
|
|
_arg4 mArg4; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAKE_PROXIED_FUNCTION5(_name, _arg1, _arg2, _arg3, _arg4, _arg5) \
|
2008-10-14 11:16:37 -07:00
|
|
|
class _name : public SyncEventCapturingRunnable \
|
2008-09-30 16:56:57 -07:00
|
|
|
{ \
|
|
|
|
public: \
|
2008-10-14 11:16:37 -07:00
|
|
|
_name (nsDOMWorkerXHRProxy* aXHR, SyncEventQueue* aQueue, _arg1 aArg1, \
|
|
|
|
_arg2 aArg2, _arg3 aArg3, _arg4 aArg4, _arg5 aArg5) \
|
|
|
|
: SyncEventCapturingRunnable(aXHR, aQueue), mArg1(aArg1), mArg2(aArg2), \
|
|
|
|
mArg3(aArg3), mArg4(aArg4), mArg5(aArg5) { } \
|
2008-09-30 16:56:57 -07:00
|
|
|
\
|
2008-10-14 11:16:37 -07:00
|
|
|
virtual nsresult RunInternal() \
|
2008-09-30 16:56:57 -07:00
|
|
|
{ \
|
|
|
|
nsCOMPtr<nsIXMLHttpRequest> xhr = mXHR->GetXMLHttpRequest(); \
|
|
|
|
if (xhr) { \
|
|
|
|
return xhr-> _name (mArg1, mArg2, mArg3, mArg4, mArg5); \
|
|
|
|
} \
|
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
private: \
|
|
|
|
_arg1 mArg1; \
|
|
|
|
_arg2 mArg2; \
|
|
|
|
_arg3 mArg3; \
|
|
|
|
_arg4 mArg4; \
|
|
|
|
_arg5 mArg5; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define RUN_PROXIED_FUNCTION(_name, _args) \
|
|
|
|
PR_BEGIN_MACRO \
|
2008-10-14 11:16:37 -07:00
|
|
|
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!"); \
|
|
|
|
\
|
2008-09-30 16:56:57 -07:00
|
|
|
if (mCanceled) { \
|
|
|
|
return NS_ERROR_ABORT; \
|
|
|
|
} \
|
2008-10-14 11:16:37 -07:00
|
|
|
SyncEventQueue queue; \
|
2008-09-30 16:56:57 -07:00
|
|
|
\
|
|
|
|
nsCOMPtr<nsIRunnable> method = new :: _name _args; \
|
|
|
|
NS_ENSURE_TRUE(method, NS_ERROR_OUT_OF_MEMORY); \
|
|
|
|
\
|
|
|
|
nsRefPtr<nsResultReturningRunnable> runnable = \
|
|
|
|
new nsResultReturningRunnable(mMainThread, method, mWorkerXHR->mWorker); \
|
|
|
|
NS_ENSURE_TRUE(runnable, NS_ERROR_OUT_OF_MEMORY); \
|
|
|
|
\
|
|
|
|
nsresult _rv = runnable->Dispatch(); \
|
2008-10-14 11:16:37 -07:00
|
|
|
\
|
|
|
|
PRUint32 queueLength = queue.Length(); \
|
|
|
|
for (PRUint32 index = 0; index < queueLength; index++) { \
|
|
|
|
queue[index]->Run(); \
|
|
|
|
} \
|
|
|
|
\
|
2008-09-30 16:56:57 -07:00
|
|
|
if (NS_FAILED(_rv)) { \
|
|
|
|
return _rv; \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
|
|
|
namespace nsDOMWorkerProxiedXHRFunctions
|
|
|
|
{
|
2008-10-14 11:16:37 -07:00
|
|
|
typedef nsDOMWorkerXHRProxy::SyncEventQueue SyncEventQueue;
|
|
|
|
|
|
|
|
class SyncEventCapturingRunnable : public nsRunnable
|
2008-09-30 16:56:57 -07:00
|
|
|
{
|
|
|
|
public:
|
2008-10-14 11:16:37 -07:00
|
|
|
SyncEventCapturingRunnable(nsDOMWorkerXHRProxy* aXHR,
|
|
|
|
SyncEventQueue* aQueue)
|
|
|
|
: mXHR(aXHR), mQueue(aQueue) {
|
2008-09-30 16:56:57 -07:00
|
|
|
NS_ASSERTION(aXHR, "Null pointer!");
|
2008-10-14 11:16:37 -07:00
|
|
|
NS_ASSERTION(aQueue, "Null pointer!");
|
2008-09-30 16:56:57 -07:00
|
|
|
}
|
|
|
|
|
2008-10-14 11:16:37 -07:00
|
|
|
virtual nsresult RunInternal() = 0;
|
|
|
|
|
2008-09-30 16:56:57 -07:00
|
|
|
NS_IMETHOD Run() {
|
2008-10-14 11:16:37 -07:00
|
|
|
SyncEventQueue* oldQueue = mXHR->SetSyncEventQueue(mQueue);
|
|
|
|
|
|
|
|
nsresult rv = RunInternal();
|
|
|
|
|
|
|
|
mXHR->SetSyncEventQueue(oldQueue);
|
|
|
|
|
|
|
|
return rv;
|
2008-09-30 16:56:57 -07:00
|
|
|
}
|
2008-10-14 11:16:37 -07:00
|
|
|
|
|
|
|
protected:
|
2008-09-30 16:56:57 -07:00
|
|
|
nsRefPtr<nsDOMWorkerXHRProxy> mXHR;
|
2008-10-14 11:16:37 -07:00
|
|
|
SyncEventQueue* mQueue;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Abort : public SyncEventCapturingRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Abort (nsDOMWorkerXHRProxy* aXHR, SyncEventQueue* aQueue)
|
|
|
|
: SyncEventCapturingRunnable(aXHR, aQueue) { }
|
|
|
|
|
|
|
|
virtual nsresult RunInternal() {
|
|
|
|
return mXHR->Abort();
|
|
|
|
}
|
2008-09-30 16:56:57 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
MAKE_PROXIED_FUNCTION1(GetAllResponseHeaders, char**);
|
|
|
|
|
|
|
|
MAKE_PROXIED_FUNCTION2(GetResponseHeader, const nsACString&, nsACString&);
|
|
|
|
|
|
|
|
MAKE_PROXIED_FUNCTION5(OpenRequest, const nsACString&, const nsACString&,
|
|
|
|
PRBool, const nsAString&, const nsAString&);
|
|
|
|
|
|
|
|
MAKE_PROXIED_FUNCTION1(Send, nsIVariant*);
|
|
|
|
|
|
|
|
MAKE_PROXIED_FUNCTION1(SendAsBinary, const nsAString&);
|
|
|
|
|
|
|
|
MAKE_PROXIED_FUNCTION2(SetRequestHeader, const nsACString&,
|
|
|
|
const nsACString&);
|
|
|
|
|
|
|
|
MAKE_PROXIED_FUNCTION1(OverrideMimeType, const nsACString&);
|
|
|
|
|
|
|
|
MAKE_PROXIED_FUNCTION1(SetMultipart, PRBool);
|
2008-10-14 11:16:37 -07:00
|
|
|
|
|
|
|
MAKE_PROXIED_FUNCTION1(GetMultipart, PRBool*);
|
2008-09-30 17:08:53 -07:00
|
|
|
}
|
2008-09-30 16:56:57 -07:00
|
|
|
|
|
|
|
#endif /* __NSDOMWORKERXHRPROXIEDFUNCTIONS_H__ */
|