mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-09 04:25:38 +00:00
Backed out changeset d975d5a0f6ce (bug 1081686) for b2g/android mochitest-1 bustage
This commit is contained in:
parent
850f8b2792
commit
176b525aff
@ -83,9 +83,13 @@ public:
|
||||
, mDisconnected(false)
|
||||
, mCloseEventWasClean(false)
|
||||
, mCloseEventCode(nsIWebSocketChannel::CLOSE_ABNORMAL)
|
||||
, mOutgoingBufferedAmount(0)
|
||||
, mBinaryType(dom::BinaryType::Blob)
|
||||
, mScriptLine(0)
|
||||
, mInnerWindowID(0)
|
||||
, mMutex("WebSocketImpl::mMutex")
|
||||
, mWorkerPrivate(nullptr)
|
||||
, mReadyState(WebSocket::CONNECTING)
|
||||
{
|
||||
if (!NS_IsMainThread()) {
|
||||
mWorkerPrivate = GetCurrentThreadWorkerPrivate();
|
||||
@ -100,6 +104,51 @@ public:
|
||||
|
||||
bool IsTargetThread() const;
|
||||
|
||||
uint16_t ReadyState()
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
return mReadyState;
|
||||
}
|
||||
|
||||
void SetReadyState(uint16_t aReadyState)
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
mReadyState = aReadyState;
|
||||
}
|
||||
|
||||
uint32_t BufferedAmount() const
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
return mOutgoingBufferedAmount;
|
||||
}
|
||||
|
||||
dom::BinaryType BinaryType() const
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
return mBinaryType;
|
||||
}
|
||||
|
||||
void SetBinaryType(dom::BinaryType aData)
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
mBinaryType = aData;
|
||||
}
|
||||
|
||||
void GetUrl(nsAString& aURL) const
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
|
||||
if (mEffectiveURL.IsEmpty()) {
|
||||
aURL = mOriginalURL;
|
||||
} else {
|
||||
aURL = mEffectiveURL;
|
||||
}
|
||||
}
|
||||
|
||||
void Close(const Optional<uint16_t>& aCode,
|
||||
const Optional<nsAString>& aReason,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void Init(JSContext* aCx,
|
||||
nsIPrincipal* aPrincipal,
|
||||
const nsAString& aURL,
|
||||
@ -111,6 +160,12 @@ public:
|
||||
|
||||
void AsyncOpen(ErrorResult& aRv);
|
||||
|
||||
void Send(nsIInputStream* aMsgStream,
|
||||
const nsACString& aMsgString,
|
||||
uint32_t aMsgLength,
|
||||
bool aIsBinary,
|
||||
ErrorResult& aRv);
|
||||
|
||||
nsresult ParseURL(const nsAString& aURL);
|
||||
nsresult InitializeConnection();
|
||||
|
||||
@ -157,6 +212,9 @@ public:
|
||||
|
||||
nsCOMPtr<nsIWebSocketChannel> mChannel;
|
||||
|
||||
// related to the WebSocket constructor steps
|
||||
nsString mOriginalURL;
|
||||
nsString mEffectiveURL; // after redirects
|
||||
bool mSecure; // if true it is using SSL and the wss scheme,
|
||||
// otherwise it is using the ws scheme with no SSL
|
||||
|
||||
@ -176,10 +234,16 @@ public:
|
||||
|
||||
nsCString mURI;
|
||||
nsCString mRequestedProtocolList;
|
||||
nsCString mEstablishedProtocol;
|
||||
nsCString mEstablishedExtensions;
|
||||
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
nsWeakPtr mOriginDocument;
|
||||
|
||||
uint32_t mOutgoingBufferedAmount;
|
||||
|
||||
dom::BinaryType mBinaryType;
|
||||
|
||||
// Web Socket owner information:
|
||||
// - the script file name, UTF8 encoded.
|
||||
// - source code line number where the Web Socket object was constructed.
|
||||
@ -190,6 +254,10 @@ public:
|
||||
uint32_t mScriptLine;
|
||||
uint64_t mInnerWindowID;
|
||||
|
||||
// This mutex protects mReadyState that is the only variable that is used in
|
||||
// different threads.
|
||||
mozilla::Mutex mMutex;
|
||||
|
||||
WorkerPrivate* mWorkerPrivate;
|
||||
nsAutoPtr<WorkerFeature> mWorkerFeature;
|
||||
|
||||
@ -201,6 +269,9 @@ private:
|
||||
Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
// This value should not be used directly but use ReadyState() instead.
|
||||
uint16_t mReadyState;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(WebSocketImpl,
|
||||
@ -379,7 +450,7 @@ WebSocketImpl::CloseConnection(uint16_t aReasonCode,
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
|
||||
uint16_t readyState = mWebSocket->ReadyState();
|
||||
uint16_t readyState = ReadyState();
|
||||
if (readyState == WebSocket::CLOSING ||
|
||||
readyState == WebSocket::CLOSED) {
|
||||
return NS_OK;
|
||||
@ -387,7 +458,7 @@ WebSocketImpl::CloseConnection(uint16_t aReasonCode,
|
||||
|
||||
// The common case...
|
||||
if (mChannel) {
|
||||
mWebSocket->SetReadyState(WebSocket::CLOSING);
|
||||
SetReadyState(WebSocket::CLOSING);
|
||||
|
||||
// The channel has to be closed on the main-thread.
|
||||
|
||||
@ -410,7 +481,7 @@ WebSocketImpl::CloseConnection(uint16_t aReasonCode,
|
||||
mCloseEventCode = aReasonCode;
|
||||
CopyUTF8toUTF16(aReasonString, mCloseEventReason);
|
||||
|
||||
mWebSocket->SetReadyState(WebSocket::CLOSING);
|
||||
SetReadyState(WebSocket::CLOSING);
|
||||
|
||||
// Can be called from Cancel() or Init() codepaths, so need to dispatch
|
||||
// onerror/onclose asynchronously
|
||||
@ -432,7 +503,7 @@ WebSocketImpl::ConsoleError()
|
||||
NS_ConvertUTF8toUTF16 specUTF16(mURI);
|
||||
const char16_t* formatStrings[] = { specUTF16.get() };
|
||||
|
||||
if (mWebSocket->ReadyState() < WebSocket::OPEN) {
|
||||
if (ReadyState() < WebSocket::OPEN) {
|
||||
PrintErrorOnConsole("chrome://global/locale/appstrings.properties",
|
||||
MOZ_UTF16("connectionFailure"),
|
||||
formatStrings, ArrayLength(formatStrings));
|
||||
@ -550,7 +621,7 @@ WebSocketImpl::DoOnMessageAvailable(const nsACString& aMsg, bool isBinary)
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
|
||||
int16_t readyState = mWebSocket->ReadyState();
|
||||
int16_t readyState = ReadyState();
|
||||
if (readyState == WebSocket::CLOSED) {
|
||||
NS_ERROR("Received message after CLOSED");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
@ -593,7 +664,7 @@ WebSocketImpl::OnStart(nsISupports* aContext)
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
|
||||
int16_t readyState = mWebSocket->ReadyState();
|
||||
int16_t readyState = ReadyState();
|
||||
|
||||
// This is the only function that sets OPEN, and should be called only once
|
||||
MOZ_ASSERT(readyState != WebSocket::OPEN,
|
||||
@ -612,13 +683,13 @@ WebSocketImpl::OnStart(nsISupports* aContext)
|
||||
}
|
||||
|
||||
if (!mRequestedProtocolList.IsEmpty()) {
|
||||
mChannel->GetProtocol(mWebSocket->mEstablishedProtocol);
|
||||
mChannel->GetProtocol(mEstablishedProtocol);
|
||||
}
|
||||
|
||||
mChannel->GetExtensions(mWebSocket->mEstablishedExtensions);
|
||||
mChannel->GetExtensions(mEstablishedExtensions);
|
||||
UpdateURI();
|
||||
|
||||
mWebSocket->SetReadyState(WebSocket::OPEN);
|
||||
SetReadyState(WebSocket::OPEN);
|
||||
|
||||
// Call 'onopen'
|
||||
rv = mWebSocket->CreateAndDispatchSimpleEvent(NS_LITERAL_STRING("open"));
|
||||
@ -639,7 +710,7 @@ WebSocketImpl::OnStop(nsISupports* aContext, nsresult aStatusCode)
|
||||
// We can be CONNECTING here if connection failed.
|
||||
// We can be OPEN if we have encountered a fatal protocol error
|
||||
// We can be CLOSING if close() was called and/or server initiated close.
|
||||
MOZ_ASSERT(mWebSocket->ReadyState() != WebSocket::CLOSED,
|
||||
MOZ_ASSERT(ReadyState() != WebSocket::CLOSED,
|
||||
"Shouldn't already be CLOSED when OnStop called");
|
||||
|
||||
// called by network stack, not JS, so can dispatch JS events synchronously
|
||||
@ -684,11 +755,11 @@ WebSocketImpl::OnAcknowledge(nsISupports *aContext, uint32_t aSize)
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
|
||||
if (aSize > mWebSocket->mOutgoingBufferedAmount) {
|
||||
if (aSize > mOutgoingBufferedAmount) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
mWebSocket->mOutgoingBufferedAmount -= aSize;
|
||||
mOutgoingBufferedAmount -= aSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -698,7 +769,7 @@ WebSocketImpl::OnServerClose(nsISupports *aContext, uint16_t aCode,
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
|
||||
int16_t readyState = mWebSocket->ReadyState();
|
||||
int16_t readyState = ReadyState();
|
||||
|
||||
MOZ_ASSERT(readyState != WebSocket::CONNECTING,
|
||||
"Received server close before connected?");
|
||||
@ -736,7 +807,7 @@ WebSocketImpl::GetInterface(const nsIID& aIID, void** aResult)
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
|
||||
if (!mWebSocket || mWebSocket->ReadyState() == WebSocket::CLOSED) {
|
||||
if (ReadyState() == WebSocket::CLOSED) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -770,10 +841,6 @@ WebSocket::WebSocket(nsPIDOMWindow* aOwnerWindow)
|
||||
, mWorkerPrivate(nullptr)
|
||||
, mKeepingAlive(false)
|
||||
, mCheckMustKeepAlive(true)
|
||||
, mOutgoingBufferedAmount(0)
|
||||
, mBinaryType(dom::BinaryType::Blob)
|
||||
, mMutex("WebSocketImpl::mMutex")
|
||||
, mReadyState(CONNECTING)
|
||||
{
|
||||
mImpl = new WebSocketImpl(this);
|
||||
mWorkerPrivate = mImpl->mWorkerPrivate;
|
||||
@ -1423,7 +1490,7 @@ void
|
||||
WebSocketImpl::DispatchConnectionCloseEvents()
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
mWebSocket->SetReadyState(WebSocket::CLOSED);
|
||||
SetReadyState(WebSocket::CLOSED);
|
||||
|
||||
// Call 'onerror' if needed
|
||||
if (mFailed) {
|
||||
@ -1449,7 +1516,7 @@ nsresult
|
||||
WebSocket::CreateAndDispatchSimpleEvent(const nsAString& aName)
|
||||
{
|
||||
MOZ_ASSERT(mImpl);
|
||||
AssertIsOnTargetThread();
|
||||
mImpl->AssertIsOnTargetThread();
|
||||
|
||||
nsresult rv = CheckInnerWindowCorrectness();
|
||||
if (NS_FAILED(rv)) {
|
||||
@ -1474,7 +1541,7 @@ WebSocket::CreateAndDispatchMessageEvent(const nsACString& aData,
|
||||
bool aIsBinary)
|
||||
{
|
||||
MOZ_ASSERT(mImpl);
|
||||
AssertIsOnTargetThread();
|
||||
mImpl->AssertIsOnTargetThread();
|
||||
|
||||
AutoJSAPI jsapi;
|
||||
|
||||
@ -1498,7 +1565,7 @@ WebSocket::CreateAndDispatchMessageEvent(JSContext* aCx,
|
||||
bool aIsBinary)
|
||||
{
|
||||
MOZ_ASSERT(mImpl);
|
||||
AssertIsOnTargetThread();
|
||||
mImpl->AssertIsOnTargetThread();
|
||||
|
||||
nsresult rv = CheckInnerWindowCorrectness();
|
||||
if (NS_FAILED(rv)) {
|
||||
@ -1508,11 +1575,11 @@ WebSocket::CreateAndDispatchMessageEvent(JSContext* aCx,
|
||||
// Create appropriate JS object for message
|
||||
JS::Rooted<JS::Value> jsData(aCx);
|
||||
if (aIsBinary) {
|
||||
if (mBinaryType == dom::BinaryType::Blob) {
|
||||
if (mImpl->mBinaryType == dom::BinaryType::Blob) {
|
||||
nsresult rv = nsContentUtils::CreateBlobBuffer(aCx, GetOwner(), aData,
|
||||
&jsData);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
} else if (mBinaryType == dom::BinaryType::Arraybuffer) {
|
||||
} else if (mImpl->mBinaryType == dom::BinaryType::Arraybuffer) {
|
||||
JS::Rooted<JSObject*> arrayBuf(aCx);
|
||||
nsresult rv = nsContentUtils::CreateArrayBuffer(aCx, aData,
|
||||
arrayBuf.address());
|
||||
@ -1558,7 +1625,7 @@ WebSocket::CreateAndDispatchCloseEvent(bool aWasClean,
|
||||
const nsAString &aReason)
|
||||
{
|
||||
MOZ_ASSERT(mImpl);
|
||||
AssertIsOnTargetThread();
|
||||
mImpl->AssertIsOnTargetThread();
|
||||
|
||||
nsresult rv = CheckInnerWindowCorrectness();
|
||||
if (NS_FAILED(rv)) {
|
||||
@ -1700,7 +1767,7 @@ WebSocketImpl::ParseURL(const nsAString& aURL)
|
||||
}
|
||||
}
|
||||
|
||||
mWebSocket->mOriginalURL = aURL;
|
||||
mOriginalURL = aURL;
|
||||
|
||||
rv = parsedURL->GetSpec(mURI);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
@ -1728,9 +1795,9 @@ WebSocket::UpdateMustKeepAlive()
|
||||
bool shouldKeepAlive = false;
|
||||
|
||||
if (mListenerManager) {
|
||||
switch (ReadyState())
|
||||
switch (mImpl->ReadyState())
|
||||
{
|
||||
case CONNECTING:
|
||||
case WebSocket::CONNECTING:
|
||||
{
|
||||
if (mListenerManager->HasListenersFor(nsGkAtoms::onopen) ||
|
||||
mListenerManager->HasListenersFor(nsGkAtoms::onmessage) ||
|
||||
@ -1741,19 +1808,19 @@ WebSocket::UpdateMustKeepAlive()
|
||||
}
|
||||
break;
|
||||
|
||||
case OPEN:
|
||||
case CLOSING:
|
||||
case WebSocket::OPEN:
|
||||
case WebSocket::CLOSING:
|
||||
{
|
||||
if (mListenerManager->HasListenersFor(nsGkAtoms::onmessage) ||
|
||||
mListenerManager->HasListenersFor(nsGkAtoms::onerror) ||
|
||||
mListenerManager->HasListenersFor(nsGkAtoms::onclose) ||
|
||||
mOutgoingBufferedAmount != 0) {
|
||||
mImpl->mOutgoingBufferedAmount != 0) {
|
||||
shouldKeepAlive = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CLOSED:
|
||||
case WebSocket::CLOSED:
|
||||
{
|
||||
shouldKeepAlive = false;
|
||||
}
|
||||
@ -1873,7 +1940,7 @@ WebSocketImpl::UpdateURI()
|
||||
channel = static_cast<BaseWebSocketChannel*>(mChannel.get());
|
||||
MOZ_ASSERT(channel);
|
||||
|
||||
channel->GetEffectiveURL(mWebSocket->mEffectiveURL);
|
||||
channel->GetEffectiveURL(mEffectiveURL);
|
||||
mSecure = channel->IsEncrypted();
|
||||
|
||||
return NS_OK;
|
||||
@ -1899,70 +1966,62 @@ WebSocket::EventListenerRemoved(nsIAtom* aType)
|
||||
|
||||
// webIDL: readonly attribute unsigned short readyState;
|
||||
uint16_t
|
||||
WebSocket::ReadyState()
|
||||
WebSocket::ReadyState() const
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
return mReadyState;
|
||||
}
|
||||
|
||||
void
|
||||
WebSocket::SetReadyState(uint16_t aReadyState)
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
mReadyState = aReadyState;
|
||||
MOZ_ASSERT(mImpl);
|
||||
return mImpl->ReadyState();
|
||||
}
|
||||
|
||||
// webIDL: readonly attribute unsigned long bufferedAmount;
|
||||
uint32_t
|
||||
WebSocket::BufferedAmount() const
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
return mOutgoingBufferedAmount;
|
||||
MOZ_ASSERT(mImpl);
|
||||
return mImpl->BufferedAmount();
|
||||
}
|
||||
|
||||
// webIDL: attribute BinaryType binaryType;
|
||||
dom::BinaryType
|
||||
WebSocket::BinaryType() const
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
return mBinaryType;
|
||||
MOZ_ASSERT(mImpl);
|
||||
return mImpl->BinaryType();
|
||||
}
|
||||
|
||||
// webIDL: attribute BinaryType binaryType;
|
||||
void
|
||||
WebSocket::SetBinaryType(dom::BinaryType aData)
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
mBinaryType = aData;
|
||||
MOZ_ASSERT(mImpl);
|
||||
mImpl->SetBinaryType(aData);
|
||||
}
|
||||
|
||||
// webIDL: readonly attribute DOMString url
|
||||
void
|
||||
WebSocket::GetUrl(nsAString& aURL)
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
|
||||
if (mEffectiveURL.IsEmpty()) {
|
||||
aURL = mOriginalURL;
|
||||
} else {
|
||||
aURL = mEffectiveURL;
|
||||
}
|
||||
MOZ_ASSERT(mImpl);
|
||||
mImpl->GetUrl(aURL);
|
||||
}
|
||||
|
||||
// webIDL: readonly attribute DOMString extensions;
|
||||
void
|
||||
WebSocket::GetExtensions(nsAString& aExtensions)
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
CopyUTF8toUTF16(mEstablishedExtensions, aExtensions);
|
||||
MOZ_ASSERT(mImpl);
|
||||
mImpl->AssertIsOnTargetThread();
|
||||
|
||||
CopyUTF8toUTF16(mImpl->mEstablishedExtensions, aExtensions);
|
||||
}
|
||||
|
||||
// webIDL: readonly attribute DOMString protocol;
|
||||
void
|
||||
WebSocket::GetProtocol(nsAString& aProtocol)
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
CopyUTF8toUTF16(mEstablishedProtocol, aProtocol);
|
||||
MOZ_ASSERT(mImpl);
|
||||
mImpl->AssertIsOnTargetThread();
|
||||
|
||||
CopyUTF8toUTF16(mImpl->mEstablishedProtocol, aProtocol);
|
||||
}
|
||||
|
||||
// webIDL: void send(DOMString data);
|
||||
@ -1970,17 +2029,16 @@ void
|
||||
WebSocket::Send(const nsAString& aData,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
MOZ_ASSERT(mImpl);
|
||||
mImpl->AssertIsOnTargetThread();
|
||||
|
||||
NS_ConvertUTF16toUTF8 msgString(aData);
|
||||
Send(nullptr, msgString, msgString.Length(), false, aRv);
|
||||
mImpl->Send(nullptr, msgString, msgString.Length(), false, aRv);
|
||||
}
|
||||
|
||||
void
|
||||
WebSocket::Send(File& aData, ErrorResult& aRv)
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
|
||||
nsCOMPtr<nsIInputStream> msgStream;
|
||||
nsresult rv = aData.GetInternalStream(getter_AddRefs(msgStream));
|
||||
if (NS_FAILED(rv)) {
|
||||
@ -2000,14 +2058,15 @@ WebSocket::Send(File& aData, ErrorResult& aRv)
|
||||
return;
|
||||
}
|
||||
|
||||
Send(msgStream, EmptyCString(), msgLength, true, aRv);
|
||||
mImpl->Send(msgStream, EmptyCString(), msgLength, true, aRv);
|
||||
}
|
||||
|
||||
void
|
||||
WebSocket::Send(const ArrayBuffer& aData,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
MOZ_ASSERT(mImpl);
|
||||
mImpl->AssertIsOnTargetThread();
|
||||
|
||||
aData.ComputeLengthAndData();
|
||||
|
||||
@ -2017,14 +2076,15 @@ WebSocket::Send(const ArrayBuffer& aData,
|
||||
char* data = reinterpret_cast<char*>(aData.Data());
|
||||
|
||||
nsDependentCSubstring msgString(data, len);
|
||||
Send(nullptr, msgString, len, true, aRv);
|
||||
mImpl->Send(nullptr, msgString, len, true, aRv);
|
||||
}
|
||||
|
||||
void
|
||||
WebSocket::Send(const ArrayBufferView& aData,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
MOZ_ASSERT(mImpl);
|
||||
mImpl->AssertIsOnTargetThread();
|
||||
|
||||
aData.ComputeLengthAndData();
|
||||
|
||||
@ -2034,20 +2094,20 @@ WebSocket::Send(const ArrayBufferView& aData,
|
||||
char* data = reinterpret_cast<char*>(aData.Data());
|
||||
|
||||
nsDependentCSubstring msgString(data, len);
|
||||
Send(nullptr, msgString, len, true, aRv);
|
||||
mImpl->Send(nullptr, msgString, len, true, aRv);
|
||||
}
|
||||
|
||||
void
|
||||
WebSocket::Send(nsIInputStream* aMsgStream,
|
||||
const nsACString& aMsgString,
|
||||
uint32_t aMsgLength,
|
||||
bool aIsBinary,
|
||||
ErrorResult& aRv)
|
||||
WebSocketImpl::Send(nsIInputStream* aMsgStream,
|
||||
const nsACString& aMsgString,
|
||||
uint32_t aMsgLength,
|
||||
bool aIsBinary,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
|
||||
int64_t readyState = ReadyState();
|
||||
if (readyState == CONNECTING) {
|
||||
if (readyState == WebSocket::CONNECTING) {
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return;
|
||||
}
|
||||
@ -2055,23 +2115,22 @@ WebSocket::Send(nsIInputStream* aMsgStream,
|
||||
// Always increment outgoing buffer len, even if closed
|
||||
mOutgoingBufferedAmount += aMsgLength;
|
||||
|
||||
if (readyState == CLOSING ||
|
||||
readyState == CLOSED) {
|
||||
if (readyState == WebSocket::CLOSING ||
|
||||
readyState == WebSocket::CLOSED) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We must have mImpl when connected.
|
||||
MOZ_ASSERT(mImpl);
|
||||
MOZ_ASSERT(readyState == OPEN, "Unknown state in WebSocket::Send");
|
||||
MOZ_ASSERT(readyState == WebSocket::OPEN,
|
||||
"Unknown state in WebSocket::Send");
|
||||
|
||||
nsresult rv;
|
||||
if (aMsgStream) {
|
||||
rv = mImpl->mChannel->SendBinaryStream(aMsgStream, aMsgLength);
|
||||
rv = mChannel->SendBinaryStream(aMsgStream, aMsgLength);
|
||||
} else {
|
||||
if (aIsBinary) {
|
||||
rv = mImpl->mChannel->SendBinaryMsg(aMsgString);
|
||||
rv = mChannel->SendBinaryMsg(aMsgString);
|
||||
} else {
|
||||
rv = mImpl->mChannel->SendMsg(aMsgString);
|
||||
rv = mChannel->SendMsg(aMsgString);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2080,7 +2139,7 @@ WebSocket::Send(nsIInputStream* aMsgStream,
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateMustKeepAlive();
|
||||
mWebSocket->UpdateMustKeepAlive();
|
||||
}
|
||||
|
||||
// webIDL: void close(optional unsigned short code, optional DOMString reason):
|
||||
@ -2088,6 +2147,15 @@ void
|
||||
WebSocket::Close(const Optional<uint16_t>& aCode,
|
||||
const Optional<nsAString>& aReason,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(mImpl);
|
||||
mImpl->Close(aCode, aReason, aRv);
|
||||
}
|
||||
|
||||
void
|
||||
WebSocketImpl::Close(const Optional<uint16_t>& aCode,
|
||||
const Optional<nsAString>& aReason,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
|
||||
@ -2113,21 +2181,18 @@ WebSocket::Close(const Optional<uint16_t>& aCode,
|
||||
}
|
||||
|
||||
int64_t readyState = ReadyState();
|
||||
if (readyState == CLOSING ||
|
||||
readyState == CLOSED) {
|
||||
if (readyState == WebSocket::CLOSING ||
|
||||
readyState == WebSocket::CLOSED) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the webSocket is not closed we MUST have a mImpl.
|
||||
MOZ_ASSERT(mImpl);
|
||||
|
||||
if (readyState == CONNECTING) {
|
||||
mImpl->FailConnection(closeCode, closeReason);
|
||||
if (readyState == WebSocket::CONNECTING) {
|
||||
FailConnection(closeCode, closeReason);
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(readyState == OPEN);
|
||||
mImpl->CloseConnection(closeCode, closeReason);
|
||||
MOZ_ASSERT(readyState == WebSocket::OPEN);
|
||||
CloseConnection(closeCode, closeReason);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -2141,7 +2206,7 @@ WebSocketImpl::Observe(nsISupports* aSubject,
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
|
||||
int64_t readyState = mWebSocket->ReadyState();
|
||||
int64_t readyState = ReadyState();
|
||||
if ((readyState == WebSocket::CLOSING) ||
|
||||
(readyState == WebSocket::CLOSED)) {
|
||||
return NS_OK;
|
||||
@ -2170,7 +2235,7 @@ WebSocketImpl::GetName(nsACString& aName)
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
|
||||
CopyUTF16toUTF8(mWebSocket->mOriginalURL, aName);
|
||||
CopyUTF16toUTF8(mOriginalURL, aName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -2179,7 +2244,7 @@ WebSocketImpl::IsPending(bool* aValue)
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
|
||||
int64_t readyState = mWebSocket->ReadyState();
|
||||
int64_t readyState = ReadyState();
|
||||
*aValue = (readyState != WebSocket::CLOSED);
|
||||
return NS_OK;
|
||||
}
|
||||
@ -2258,7 +2323,7 @@ WebSocketImpl::CancelInternal()
|
||||
{
|
||||
AssertIsOnTargetThread();
|
||||
|
||||
int64_t readyState = mWebSocket->ReadyState();
|
||||
int64_t readyState = ReadyState();
|
||||
if (readyState == WebSocket::CLOSING || readyState == WebSocket::CLOSED) {
|
||||
return NS_OK;
|
||||
}
|
||||
@ -2419,11 +2484,5 @@ WebSocketImpl::IsTargetThread() const
|
||||
return NS_IsMainThread() == !mWorkerPrivate;
|
||||
}
|
||||
|
||||
void
|
||||
WebSocket::AssertIsOnTargetThread() const
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread() == !mWorkerPrivate);
|
||||
}
|
||||
|
||||
} // dom namespace
|
||||
} // mozilla namespace
|
||||
|
@ -23,8 +23,6 @@
|
||||
#define DEFAULT_WS_SCHEME_PORT 80
|
||||
#define DEFAULT_WSS_SCHEME_PORT 443
|
||||
|
||||
class nsIInputStream;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
@ -90,7 +88,7 @@ public: // WebIDL interface:
|
||||
void GetUrl(nsAString& aResult);
|
||||
|
||||
// webIDL: readonly attribute unsigned short readyState;
|
||||
uint16_t ReadyState();
|
||||
uint16_t ReadyState() const;
|
||||
|
||||
// webIDL: readonly attribute unsigned long bufferedAmount;
|
||||
uint32_t BufferedAmount() const;
|
||||
@ -136,8 +134,6 @@ private: // constructor && distructor
|
||||
explicit WebSocket(nsPIDOMWindow* aOwnerWindow);
|
||||
virtual ~WebSocket();
|
||||
|
||||
void SetReadyState(uint16_t aReadyState);
|
||||
|
||||
// These methods actually do the dispatch for various events.
|
||||
nsresult CreateAndDispatchSimpleEvent(const nsAString& aName);
|
||||
nsresult CreateAndDispatchMessageEvent(const nsACString& aData,
|
||||
@ -161,39 +157,16 @@ private:
|
||||
WebSocket(const WebSocket& x) MOZ_DELETE; // prevent bad usage
|
||||
WebSocket& operator=(const WebSocket& x) MOZ_DELETE;
|
||||
|
||||
void Send(nsIInputStream* aMsgStream,
|
||||
const nsACString& aMsgString,
|
||||
uint32_t aMsgLength,
|
||||
bool aIsBinary,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void AssertIsOnTargetThread() const;
|
||||
|
||||
// Raw pointer because this WebSocketImpl is created, managed and destroyed by
|
||||
// WebSocket.
|
||||
WebSocketImpl* mImpl;
|
||||
|
||||
// This is used just to check in which thread this object is used when mImpl
|
||||
// is null.
|
||||
workers::WorkerPrivate* mWorkerPrivate;
|
||||
|
||||
bool mKeepingAlive;
|
||||
bool mCheckMustKeepAlive;
|
||||
|
||||
uint32_t mOutgoingBufferedAmount;
|
||||
|
||||
// related to the WebSocket constructor steps
|
||||
nsString mOriginalURL;
|
||||
nsString mEffectiveURL; // after redirects
|
||||
nsCString mEstablishedExtensions;
|
||||
nsCString mEstablishedProtocol;
|
||||
|
||||
dom::BinaryType mBinaryType;
|
||||
|
||||
// This mutex protects mReadyState that is the only variable that is used in
|
||||
// different threads.
|
||||
mozilla::Mutex mMutex;
|
||||
|
||||
// This value should not be used directly but use ReadyState() instead.
|
||||
uint16_t mReadyState;
|
||||
};
|
||||
|
||||
} //namespace dom
|
||||
|
@ -659,4 +659,3 @@ support-files = file_bug1011748_redirect.sjs file_bug1011748_OK.sjs
|
||||
[test_element.matches.html]
|
||||
[test_user_select.html]
|
||||
skip-if = buildapp == 'mulet' || buildapp == 'b2g'
|
||||
[test_bug1081686.html]
|
||||
|
@ -1,70 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
-->
|
||||
<head>
|
||||
<title>bug 1081686</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body onload="testWebSocket()">
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
var ws;
|
||||
|
||||
function forcegc()
|
||||
{
|
||||
SpecialPowers.forceGC();
|
||||
SpecialPowers.gc();
|
||||
setTimeout(function()
|
||||
{
|
||||
SpecialPowers.gc();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function testWebSocket () {
|
||||
ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket_hello");
|
||||
ws.onopen = function(e) {
|
||||
ws.send("data");
|
||||
}
|
||||
ws.onclose = function(e) {
|
||||
forcegc();
|
||||
setTimeout(function() {
|
||||
is(ws.readyState, 3, 'WebSocket is closed');
|
||||
is(ws.bufferedAmount, 0, 'WebSocket.bufferedAmount should be empty.');
|
||||
is(ws.binaryType, 'blob', 'WebSocket.binaryType is blob');
|
||||
ws.binaryType = 'arraybuffer';
|
||||
is(ws.binaryType, 'arraybuffer', 'WebSocket.binaryType is arraybuffer');
|
||||
is(ws.url, 'ws://mochi.test:8888/tests/content/base/test/file_websocket_hello', 'WebSocket.url is correct');
|
||||
ws.close();
|
||||
ws.send('foobar');
|
||||
SimpleTest.finish();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
ws.onerror = function(e) {
|
||||
ok(false, "onerror called!");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
ws.onmessage = function(e) {
|
||||
is(e.data, "Hello world!", "Wrong data");
|
||||
ws.close();
|
||||
}
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
<div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user