mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 22:53:28 +00:00
54259209d7
- Bug 891551 - Part 7: Fix some intermittent failures in multi_tcp_socket_unittest. r=ekr (b0fb5f6167)
- Bug 891551 - Part 11: fix a couple of issues from part 5. r=bwc (1f3586e037)
- Bug 1131779: 403 on permission request no longer invalidates the whole TURN relay. r=bwc (d0c594e2c7)
- Bug 797262 - IPV6 support for webrtc. r=drno (91894f480c)
- Bug 1187775 - Plumb RTCConfiguration.iceTransportPolicy down to NrIceCtx. r=smaug, r=bwc (1edc8f89c7)
- Bug 1191258 - check for IFF_RUNNING to detect online interfaces. r=mcmanus (3882c4d36e)
- Bug 1191253 - start the link monitor, ignore link-local notifications. r=mcmanus (f26b864061)
- Bug 1203658 - mark Linux's nsNotifyAddrListener::mChildThreadShutdown member as Atomic; r=bagder (6459a89dc0)
- re-enable warnings (e132d2f5db)
- Bug 1205266 - log network-change events on Mac. r=mcmanus (4c50d25945)
- Bug 1163419 - Make nsQtNetworkLinkService destructor private. r=dougt (c6993deef9)
- Bug 1178091: Implement RTCDataChannel BufferedAmountLowThreshold and bufferedamountlow event r=smaug,drno (0536f587b4)
- Bug 1194817: disable PMTUD in DataChannels/SCTP, set initial MTU per spec r=tuexen (60db372861)
- Bug 1198730: fix simple bug in PMTUD disable that clears all other flags r=tuexen (aeac9858cf)
- Bug 1148231: fix wrong error message on DataChannel failed resend of packet r=khuey (c1d9d11e17)
- Bug 1152334 - StartWebsocketData null deref mSocketIn, r=bagder (e55850770e)
- Bug 1149872 - Add the missing format specifiers. r=jduell (ffef5c91c2)
- Bug 1182515 - WebSocketChannel leaked when WebSocketChannel::AsyncOpen fails, r=mcmanus (0b52e2eb82)
- Bug 1140765 - Build some network code in unified mode; r=mcmanus (a6b9c325bb)
- Bug 1147749 - View source should go through service worker interception, r=bz, r=jduell (8c5a3cab90)
- Bug 1137151: Marked destructors of ref-counted RTSP classes as protected, r=sworkman (a6873944ee)
- Bug 1117486 - [FFOS2.0][Woodduck] System crash by replaying the same RTSP clip several times. r=bechen (1401ee0f11)
- Bug 1133461 - [RTSP] Remove the extra PLAY request for seek operation. r=bechen (c603b06ac6)
- Bug 1138983 - RTSP not enabled in Lollipop. r=vchang (a42d0bcd30)
- Bug 1144513 - [gonk-lmr1] Adapt RTSPSource.cpp. r=ettseng (8e011ab7bf)
- Bug 1151760 - Separate timeout timer with end of stream. r=ettseng (60bb18556c)
- Bug 1208756 - Hoist shared CheckMayLoad logic into BasePrincipal. r=bz (0108fa0c7c)
- Bug 1208756 - Introduce URI_FETCHABLE_BY_ANYONE and use it for moz-extension. r=bz (04de31fcbd)
- Bug 1188421 - Properly null memory reporter's compressor reference. r=hurley (9275695d87)
- bug 1204614 - test for h2 per stream flow control r=hurley (a56d4aacff)
- Bug 1197847 - Disallow folded headers in h2. r=mcmanus (ec5febf843)
- Bug 1136361 - update node-http2 on ci. rs=mcmanus (a7e2de9e02)
- Bug 1197847 - make debugging h2 and spdy test servers easier. r=mcmanus (7dcc251b63)
- Missing bits of 1132357 (431f194ed7)
- Bug 1207519 - Prevent HashTable shrink from ignoring allocation failures that may have been reported r=Waldo (d9270ce946)
- Bug 920479 - Properly convert all arguments to the Function constructor to strings before parsing out an arguments list for the function to be created. r=arai (2ba9fb0af0)
- Bug 1206520: Create an option to throw on asm.js validation failures; r=luke (6a19a37db7)
- Bug 1210295 - Simplify TOK_DEFAULT case in Parser::exportDeclaration. r=Waldo (850e383381)
- code style (5356d4a123)
- Bug 589199 - Mark non-global lexical scopes are non-extensible. (r=efaust) (d0430a0f5e)
- Bug 589199 - Cleanup: remove unused DEPTH_SLOT from BlockObject. (r=efaust) (97206b2b00)
- Bug 1211100 - Add Vector::infallibleEmplaceBack and use it in JSScript::initScriptCounts() r=nbp (09705ff8db)
- Bug 1199203 - Add support for per-thread OOM testing. r=jonco (2a9919d659)
- Bug 1171226 - Fix mozilla::devtools::UniqueStringHashPolicy::match for strings with the same prefix; r=jimb (1843cec175)
- Bug 1206290 - Part 0: Move js/UbiNodeTraverse.h to js/UbiNodeBreadthFirst.h; r=sfink (c22e008995)
- Bug 1199843 - Part 1: Prefer T::traceChildren over tag dispatched TraceChildren; r=jonco (d935bb1c1c)
- Bug 1199843 - Part 2: Use js::TraceChildren everywhere we don't need external linkage; r=jonco (de8cd29a01)
- Bug 1199843 - Part 3: Strongly type JS::TraceChildren; r=jonco r=mccr8 (2cdd931159)
- Bug 1178961 - Restore the std::string fix from bug 1167230 r=BenWa (4251402fce)
- Bug 1206288 - Remove JS::ubi::SimpleEdge and make JS::ubi::Edge a concrete class; r=shu (d995efed2d)
- Bug 1182653 - Use JSRuntime* instead of JSContext* in ubi::Node infrastructure; r=sfink (e11e0bd0ba)
- Bug 1207236 - ARM64: Build errors with --enable-simulator=arm64. r=h4writer (cc76d43493)
- Bug 1207793 - Fix unified bustage from the TaggedPointer split; r=jolesen (e05b300406)
- Bug 1204866 - IonMonkey: Crash when failing to apand to parse finished list, r=bhackett (efab1b4a1f)
- Bug 1209911 - Use a Variant type to represent HelperThread data r=jandem (ea21131f21)
- Bug 1209911 - Make AutoEnterOOMUnsafeRegion ignore threads that are not simulating OOM r=terrence (769f06a4dc)
- Bug 1203814 - "Adding a testing function causes intermittent orange in oomInFormatStackDump.js on Win32 debug SM(p)." r=jcoppeard (da95054606)
- Bug 1209911 - Add oomThreadTypes() test function to report the number of thread types we can simulate OOM on r=terrence (1d56ca0b74)
- Bug 1209911 - Limit the number of helper threads of a particular type when simulating OOM r=jandem (ceafa83794)
- Bug 1209911 - Remove option to simulate OOM on all threads r=terrence (b43fcf3959)
- Bug 1201057 - Update shell args for OOM tests now we don't have to worry about unhandlable OOMs r=terrence (843c1fc6e3)
- Bug 1208994 - ToAtom<NoGC> should not throw an exception on failure r=terrence (ad57246c1e)
- Bug 1210760 - Don't simulate OOM in ExceptionHandlerBailout() r=terrence (89bab8d51b)
- Bug 1209911 - Enable threads for existing OOM tests r=terrence (a6f94e1f2f)
- Bug 1169974 - Tolerate inconsistent-missing-override warnings for MOCK_METHOD2 macro from gtests. r=fitzgen. (96d613239d)
- Bug 1206290 - Part 1: Implement a JS::ubi::PostOrder depth first traversal; r=sfink (d4de3aa8bc)
- Bug 1196461 - De-duplicate strings in heap snapshot core dumps; r=shu,jimb (24080971ae)
- missing bit of 1101561 (d4b61c9688)
- Bug 1199215 - Implement JS::ubi::Node::size for JS::Symbol referents;S::ubi::Node::size for JS::Symbol referents; r=sfink (929fceb199)
- Bug 1200345: Add comment to js/public/UbiNode.h warning about operating on graphs constructed by hostile code. DONTBUILD r=fitzgen (b83c2d0aad)
- Bug 1199216 - Implement JS::ubi::Node::size for JSScript referents; r=sfink (5a134ffa8e)
- Bug 1205744 - Removed redundant method IsContextRunningJS. r=h4writer (a7e90bbead)
- Bug 1203920 - Get rid of JS_SetStructuredCloneCallbacks, r=sfink (197118cf95)
- Bug 1204554 part 1 - Remove unused JSContext from LcovWriteScript. r=bhackett (12fa4dcc99)
- Bug 1209263 - Allow embedders to tell SpiderMonkey how to structured clone principals; r=bz (c4e929e50f)
- Bug 1191098 - Replace AutoHashableValueRooter with Rooted<HashableValue>; r=jonco (99e23cf3a4)
- Bug 1190628 - Replace AutoScriptVector with normal Rooted usage; r=jimb (926d499edd)
- Bug 1188445 - Allow PersistentRooted to store StaticTraceable; r=sfink (eac1824298)
- Bug 1195957 - Implement a Swap for Heap<T> that does not put temporaries on the stack, r=terrence (26935b5efd)
- Bug 1203695 - GenerateLcovInfo: Check if JSScripts have associated bytecode before spewing their content. r=bhackett (71854b606a)
- Bug 1204554 part 2 - Split LCov functions to make the aggregation of results incremental. r=terrence,bhackett (3a6bd8719e)
- Bug 1204554 part 3.0 - Collect lcov output on the JSCompartment, and on the JSRuntime. r=terrence,bhackett (35544460b1)
- Bug 1204554 part 3.1 - Prevent lazy parsing if we have to spew lcov result. r=bhackett (b36775e171)
- Bug 1204554 part 3.2 - Collect the source files before any script, as they are swept first. r=terrence (4d841a641e)
- Bug 1204554 part 3.3 - Only collect inner JSScript if they have the same source. r=terrence (b38f45764e)
- Bug 1204554 part 3.4 - Ensure that scriptCountsMaps data are still alive until the destruction of compartments. r=terrence,bhackett (50d4217d20)
- Bug 1200642 - Fix OOM handling issues r=terrence (d8ba8b1714)
- Bug 1206247 - Do not collect coverage information if the source has n filename. r=bhackett (0602188d8e)
- pointer style (09cd14aec3)
- Bug 1207232: Let lockOwner be Atomic; r=terrence (e4aa1e635d)
- Bug 1192304 - Common up the checks when entering GC API; r=jonco (935c618bc4)
- Bug 1192306 - Use a function to check if IsShutdownGC rather than open-coding it; r=jonco (c14a96ba2d)
- Bug 1202865 - Split out Zone selection from stats collection and malloc bytes reset; r=jonco (89d5e9def1)
- Bug 1193428 - Rename the incremental parameter to be more meaningful; r=jonco (5d5f38b39d)
- Bug 1209704 - Part 1: Rename BarrieredBase to WriteBarrieredBase; r=jonco (4559ae15aa)
- Bug 1209704 - Part 2: Share storage and mixins between Read and Write barriers; r=jonco (eddc9ff80c)
- Bug 1177515 - Skip tracing object elements if type information shows they don't contain any GC pointers r=terrence (94e2c1ee71)
- Bug 1209704 - Part 3: Share tracing accessors between all barrier classes; r=jonco (1e30d0f16d)
- Bug 1209704 - Part 4: Add a post-barrier to ReadBarriered; r=jonco (22bb316d70)
- Bug 1211022 - Add a type specialization for weak C++ GC thing references; r=sfink (d3d5e88ba8)
- Bug 1204169 - Push SPS pseudo frame entries when GCing; r=terrence (61501f7597)
- Bug 1211031 - Use WeakRef to manage the LazyScript to JSScript back-reference; r=jandem (7c48b04d35)
- Bug 1204167 - Create the js::AutoSPSEntry RAII class for defining psuedo frame entries; r=djvj (519342668f)
- Bug 1204584 - Ensure that entries created by AutoSPSEntry propogate their category information; r=djvj (bd5d96e8b6)
- Bug 1011786 - Diagnostic patch to detect cyclic ropes, r=terrence (c2ece1d49d)
- fix comment (619a5bff31)
518 lines
13 KiB
C++
518 lines
13 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "nsDOMDataChannel.h"
|
|
|
|
#include "base/basictypes.h"
|
|
#include "mozilla/Logging.h"
|
|
|
|
extern PRLogModuleInfo* GetDataChannelLog();
|
|
#undef LOG
|
|
#define LOG(args) MOZ_LOG(GetDataChannelLog(), mozilla::LogLevel::Debug, args)
|
|
|
|
|
|
#include "nsDOMDataChannelDeclarations.h"
|
|
#include "nsDOMDataChannel.h"
|
|
#include "nsIDOMDataChannel.h"
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
|
#include "mozilla/dom/File.h"
|
|
#include "mozilla/dom/MessageEvent.h"
|
|
#include "mozilla/dom/ScriptSettings.h"
|
|
|
|
#include "nsError.h"
|
|
#include "nsAutoPtr.h"
|
|
#include "nsContentUtils.h"
|
|
#include "nsCycleCollectionParticipant.h"
|
|
#include "nsIScriptObjectPrincipal.h"
|
|
|
|
#include "DataChannel.h"
|
|
|
|
// Since we've moved the windows.h include down here, we have to explicitly
|
|
// undef GetBinaryType, otherwise we'll get really odd conflicts
|
|
#ifdef GetBinaryType
|
|
#undef GetBinaryType
|
|
#endif
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::dom;
|
|
|
|
nsDOMDataChannel::~nsDOMDataChannel()
|
|
{
|
|
// Don't call us anymore! Likely isn't an issue (or maybe just less of
|
|
// one) once we block GC until all the (appropriate) onXxxx handlers
|
|
// are dropped. (See WebRTC spec)
|
|
LOG(("Close()ing %p", mDataChannel.get()));
|
|
mDataChannel->SetListener(nullptr, nullptr);
|
|
mDataChannel->Close();
|
|
}
|
|
|
|
/* virtual */ JSObject*
|
|
nsDOMDataChannel::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
|
{
|
|
return DataChannelBinding::Wrap(aCx, this, aGivenProto);
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMDataChannel)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMDataChannel,
|
|
DOMEventTargetHelper)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMDataChannel,
|
|
DOMEventTargetHelper)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsDOMDataChannel, DOMEventTargetHelper)
|
|
NS_IMPL_RELEASE_INHERITED(nsDOMDataChannel, DOMEventTargetHelper)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMDataChannel)
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDataChannel)
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
|
|
|
nsDOMDataChannel::nsDOMDataChannel(already_AddRefed<mozilla::DataChannel>& aDataChannel,
|
|
nsPIDOMWindow* aWindow)
|
|
: DOMEventTargetHelper(aWindow && aWindow->IsOuterWindow() ?
|
|
aWindow->GetCurrentInnerWindow() : aWindow)
|
|
, mDataChannel(aDataChannel)
|
|
, mBinaryType(DC_BINARY_TYPE_BLOB)
|
|
{
|
|
}
|
|
|
|
nsresult
|
|
nsDOMDataChannel::Init(nsPIDOMWindow* aDOMWindow)
|
|
{
|
|
nsresult rv;
|
|
nsAutoString urlParam;
|
|
|
|
MOZ_ASSERT(mDataChannel);
|
|
mDataChannel->SetListener(this, nullptr);
|
|
|
|
// Now grovel through the objects to get a usable origin for onMessage
|
|
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(aDOMWindow);
|
|
NS_ENSURE_STATE(sgo);
|
|
nsCOMPtr<nsIScriptContext> scriptContext = sgo->GetContext();
|
|
NS_ENSURE_STATE(scriptContext);
|
|
|
|
nsCOMPtr<nsIScriptObjectPrincipal> scriptPrincipal(do_QueryInterface(aDOMWindow));
|
|
NS_ENSURE_STATE(scriptPrincipal);
|
|
nsCOMPtr<nsIPrincipal> principal = scriptPrincipal->GetPrincipal();
|
|
NS_ENSURE_STATE(principal);
|
|
|
|
// Attempt to kill "ghost" DataChannel (if one can happen): but usually too early for check to fail
|
|
rv = CheckInnerWindowCorrectness();
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
rv = nsContentUtils::GetUTFOrigin(principal,mOrigin);
|
|
LOG(("%s: origin = %s\n",__FUNCTION__,NS_LossyConvertUTF16toASCII(mOrigin).get()));
|
|
return rv;
|
|
}
|
|
|
|
NS_IMPL_EVENT_HANDLER(nsDOMDataChannel, open)
|
|
NS_IMPL_EVENT_HANDLER(nsDOMDataChannel, error)
|
|
NS_IMPL_EVENT_HANDLER(nsDOMDataChannel, close)
|
|
NS_IMPL_EVENT_HANDLER(nsDOMDataChannel, message)
|
|
|
|
NS_IMETHODIMP
|
|
nsDOMDataChannel::GetLabel(nsAString& aLabel)
|
|
{
|
|
mDataChannel->GetLabel(aLabel);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsDOMDataChannel::GetProtocol(nsAString& aProtocol)
|
|
{
|
|
mDataChannel->GetProtocol(aProtocol);
|
|
return NS_OK;
|
|
}
|
|
|
|
uint16_t
|
|
nsDOMDataChannel::Id() const
|
|
{
|
|
return mDataChannel->GetStream();
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsDOMDataChannel::GetId(uint16_t *aId)
|
|
{
|
|
*aId = Id();
|
|
return NS_OK;
|
|
}
|
|
|
|
uint16_t
|
|
nsDOMDataChannel::Stream() const
|
|
{
|
|
return mDataChannel->GetStream();
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsDOMDataChannel::GetStream(uint16_t *aStream)
|
|
{
|
|
*aStream = Stream();
|
|
return NS_OK;
|
|
}
|
|
|
|
// XXX should be GetType()? Open question for the spec
|
|
bool
|
|
nsDOMDataChannel::Reliable() const
|
|
{
|
|
return mDataChannel->GetType() == mozilla::DataChannelConnection::RELIABLE;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsDOMDataChannel::GetReliable(bool* aReliable)
|
|
{
|
|
*aReliable = Reliable();
|
|
return NS_OK;
|
|
}
|
|
|
|
bool
|
|
nsDOMDataChannel::Ordered() const
|
|
{
|
|
return mDataChannel->GetOrdered();
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsDOMDataChannel::GetOrdered(bool* aOrdered)
|
|
{
|
|
*aOrdered = Ordered();
|
|
return NS_OK;
|
|
}
|
|
|
|
RTCDataChannelState
|
|
nsDOMDataChannel::ReadyState() const
|
|
{
|
|
return static_cast<RTCDataChannelState>(mDataChannel->GetReadyState());
|
|
}
|
|
|
|
|
|
NS_IMETHODIMP
|
|
nsDOMDataChannel::GetReadyState(nsAString& aReadyState)
|
|
{
|
|
uint16_t readyState = mDataChannel->GetReadyState();
|
|
// From the WebRTC spec
|
|
const char * stateName[] = {
|
|
"connecting",
|
|
"open",
|
|
"closing",
|
|
"closed"
|
|
};
|
|
MOZ_ASSERT(/*readyState >= mozilla::DataChannel::CONNECTING && */ // Always true due to datatypes
|
|
readyState <= mozilla::DataChannel::CLOSED);
|
|
aReadyState.AssignASCII(stateName[readyState]);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
uint32_t
|
|
nsDOMDataChannel::BufferedAmount() const
|
|
{
|
|
return mDataChannel->GetBufferedAmount();
|
|
}
|
|
|
|
uint32_t
|
|
nsDOMDataChannel::BufferedAmountLowThreshold() const
|
|
{
|
|
return mDataChannel->GetBufferedAmountLowThreshold();
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsDOMDataChannel::GetBufferedAmount(uint32_t* aBufferedAmount)
|
|
{
|
|
*aBufferedAmount = BufferedAmount();
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
nsDOMDataChannel::SetBufferedAmountLowThreshold(uint32_t aThreshold)
|
|
{
|
|
mDataChannel->SetBufferedAmountLowThreshold(aThreshold);
|
|
}
|
|
|
|
NS_IMETHODIMP nsDOMDataChannel::GetBinaryType(nsAString & aBinaryType)
|
|
{
|
|
switch (mBinaryType) {
|
|
case DC_BINARY_TYPE_ARRAYBUFFER:
|
|
aBinaryType.AssignLiteral("arraybuffer");
|
|
break;
|
|
case DC_BINARY_TYPE_BLOB:
|
|
aBinaryType.AssignLiteral("blob");
|
|
break;
|
|
default:
|
|
NS_ERROR("Should not happen");
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsDOMDataChannel::SetBinaryType(const nsAString& aBinaryType)
|
|
{
|
|
if (aBinaryType.EqualsLiteral("arraybuffer")) {
|
|
mBinaryType = DC_BINARY_TYPE_ARRAYBUFFER;
|
|
} else if (aBinaryType.EqualsLiteral("blob")) {
|
|
mBinaryType = DC_BINARY_TYPE_BLOB;
|
|
} else {
|
|
return NS_ERROR_INVALID_ARG;
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsDOMDataChannel::Close()
|
|
{
|
|
mDataChannel->Close();
|
|
return NS_OK;
|
|
}
|
|
|
|
// All of the following is copy/pasted from WebSocket.cpp.
|
|
void
|
|
nsDOMDataChannel::Send(const nsAString& aData, ErrorResult& aRv)
|
|
{
|
|
NS_ConvertUTF16toUTF8 msgString(aData);
|
|
Send(nullptr, msgString, msgString.Length(), false, aRv);
|
|
}
|
|
|
|
void
|
|
nsDOMDataChannel::Send(Blob& aData, ErrorResult& aRv)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread(), "Not running on main thread");
|
|
|
|
nsCOMPtr<nsIInputStream> msgStream;
|
|
aData.GetInternalStream(getter_AddRefs(msgStream), aRv);
|
|
if (NS_WARN_IF(aRv.Failed())){
|
|
return;
|
|
}
|
|
|
|
uint64_t msgLength = aData.GetSize(aRv);
|
|
if (NS_WARN_IF(aRv.Failed())){
|
|
return;
|
|
}
|
|
|
|
if (msgLength > UINT32_MAX) {
|
|
aRv.Throw(NS_ERROR_FILE_TOO_BIG);
|
|
return;
|
|
}
|
|
|
|
Send(msgStream, EmptyCString(), msgLength, true, aRv);
|
|
}
|
|
|
|
void
|
|
nsDOMDataChannel::Send(const ArrayBuffer& aData, ErrorResult& aRv)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread(), "Not running on main thread");
|
|
|
|
aData.ComputeLengthAndData();
|
|
|
|
static_assert(sizeof(*aData.Data()) == 1, "byte-sized data required");
|
|
|
|
uint32_t len = aData.Length();
|
|
char* data = reinterpret_cast<char*>(aData.Data());
|
|
|
|
nsDependentCSubstring msgString(data, len);
|
|
Send(nullptr, msgString, len, true, aRv);
|
|
}
|
|
|
|
void
|
|
nsDOMDataChannel::Send(const ArrayBufferView& aData, ErrorResult& aRv)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread(), "Not running on main thread");
|
|
|
|
aData.ComputeLengthAndData();
|
|
|
|
static_assert(sizeof(*aData.Data()) == 1, "byte-sized data required");
|
|
|
|
uint32_t len = aData.Length();
|
|
char* data = reinterpret_cast<char*>(aData.Data());
|
|
|
|
nsDependentCSubstring msgString(data, len);
|
|
Send(nullptr, msgString, len, true, aRv);
|
|
}
|
|
|
|
void
|
|
nsDOMDataChannel::Send(nsIInputStream* aMsgStream,
|
|
const nsACString& aMsgString,
|
|
uint32_t aMsgLength,
|
|
bool aIsBinary,
|
|
ErrorResult& aRv)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
uint16_t state = mDataChannel->GetReadyState();
|
|
|
|
// In reality, the DataChannel protocol allows this, but we want it to
|
|
// look like WebSockets
|
|
if (state == mozilla::DataChannel::CONNECTING) {
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
return;
|
|
}
|
|
|
|
if (state == mozilla::DataChannel::CLOSING ||
|
|
state == mozilla::DataChannel::CLOSED) {
|
|
return;
|
|
}
|
|
|
|
MOZ_ASSERT(state == mozilla::DataChannel::OPEN,
|
|
"Unknown state in nsDOMDataChannel::Send");
|
|
|
|
int32_t sent;
|
|
if (aMsgStream) {
|
|
sent = mDataChannel->SendBinaryStream(aMsgStream, aMsgLength);
|
|
} else {
|
|
if (aIsBinary) {
|
|
sent = mDataChannel->SendBinaryMsg(aMsgString);
|
|
} else {
|
|
sent = mDataChannel->SendMsg(aMsgString);
|
|
}
|
|
}
|
|
if (sent < 0) {
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
}
|
|
}
|
|
|
|
nsresult
|
|
nsDOMDataChannel::DoOnMessageAvailable(const nsACString& aData,
|
|
bool aBinary)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
LOG(("DoOnMessageAvailable%s\n",aBinary ? ((mBinaryType == DC_BINARY_TYPE_BLOB) ? " (blob)" : " (binary)") : ""));
|
|
|
|
nsresult rv = CheckInnerWindowCorrectness();
|
|
if (NS_FAILED(rv)) {
|
|
return NS_OK;
|
|
}
|
|
|
|
AutoJSAPI jsapi;
|
|
if (NS_WARN_IF(!jsapi.Init(GetOwner()))) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
JSContext* cx = jsapi.cx();
|
|
|
|
JS::Rooted<JS::Value> jsData(cx);
|
|
|
|
if (aBinary) {
|
|
if (mBinaryType == DC_BINARY_TYPE_BLOB) {
|
|
rv = nsContentUtils::CreateBlobBuffer(cx, GetOwner(), aData, &jsData);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
} else if (mBinaryType == DC_BINARY_TYPE_ARRAYBUFFER) {
|
|
JS::Rooted<JSObject*> arrayBuf(cx);
|
|
rv = nsContentUtils::CreateArrayBuffer(cx, aData, arrayBuf.address());
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
jsData.setObject(*arrayBuf);
|
|
} else {
|
|
NS_RUNTIMEABORT("Unknown binary type!");
|
|
return NS_ERROR_UNEXPECTED;
|
|
}
|
|
} else {
|
|
NS_ConvertUTF8toUTF16 utf16data(aData);
|
|
JSString* jsString = JS_NewUCStringCopyN(cx, utf16data.get(), utf16data.Length());
|
|
NS_ENSURE_TRUE(jsString, NS_ERROR_FAILURE);
|
|
|
|
jsData.setString(jsString);
|
|
}
|
|
|
|
nsRefPtr<MessageEvent> event = NS_NewDOMMessageEvent(this, nullptr, nullptr);
|
|
|
|
rv = event->InitMessageEvent(NS_LITERAL_STRING("message"), false, false,
|
|
jsData, mOrigin, EmptyString(), nullptr);
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
event->SetTrusted(true);
|
|
|
|
LOG(("%p(%p): %s - Dispatching\n",this,(void*)mDataChannel,__FUNCTION__));
|
|
rv = DispatchDOMEvent(nullptr, static_cast<Event*>(event), nullptr, nullptr);
|
|
if (NS_FAILED(rv)) {
|
|
NS_WARNING("Failed to dispatch the message event!!!");
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
nsresult
|
|
nsDOMDataChannel::OnMessageAvailable(nsISupports* aContext,
|
|
const nsACString& aMessage)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
return DoOnMessageAvailable(aMessage, false);
|
|
}
|
|
|
|
nsresult
|
|
nsDOMDataChannel::OnBinaryMessageAvailable(nsISupports* aContext,
|
|
const nsACString& aMessage)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
return DoOnMessageAvailable(aMessage, true);
|
|
}
|
|
|
|
nsresult
|
|
nsDOMDataChannel::OnSimpleEvent(nsISupports* aContext, const nsAString& aName)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
nsresult rv = CheckInnerWindowCorrectness();
|
|
if (NS_FAILED(rv)) {
|
|
return NS_OK;
|
|
}
|
|
|
|
nsRefPtr<Event> event = NS_NewDOMEvent(this, nullptr, nullptr);
|
|
|
|
rv = event->InitEvent(aName, false, false);
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
event->SetTrusted(true);
|
|
|
|
return DispatchDOMEvent(nullptr, event, nullptr, nullptr);
|
|
}
|
|
|
|
nsresult
|
|
nsDOMDataChannel::OnChannelConnected(nsISupports* aContext)
|
|
{
|
|
LOG(("%p(%p): %s - Dispatching\n",this,(void*)mDataChannel,__FUNCTION__));
|
|
|
|
return OnSimpleEvent(aContext, NS_LITERAL_STRING("open"));
|
|
}
|
|
|
|
nsresult
|
|
nsDOMDataChannel::OnChannelClosed(nsISupports* aContext)
|
|
{
|
|
LOG(("%p(%p): %s - Dispatching\n",this,(void*)mDataChannel,__FUNCTION__));
|
|
|
|
return OnSimpleEvent(aContext, NS_LITERAL_STRING("close"));
|
|
}
|
|
|
|
nsresult
|
|
nsDOMDataChannel::OnBufferLow(nsISupports* aContext)
|
|
{
|
|
LOG(("%p(%p): %s - Dispatching\n",this,(void*)mDataChannel,__FUNCTION__));
|
|
|
|
return OnSimpleEvent(aContext, NS_LITERAL_STRING("bufferedamountlow"));
|
|
}
|
|
|
|
void
|
|
nsDOMDataChannel::AppReady()
|
|
{
|
|
mDataChannel->AppReady();
|
|
}
|
|
|
|
/* static */
|
|
nsresult
|
|
NS_NewDOMDataChannel(already_AddRefed<mozilla::DataChannel>&& aDataChannel,
|
|
nsPIDOMWindow* aWindow,
|
|
nsIDOMDataChannel** aDomDataChannel)
|
|
{
|
|
nsRefPtr<nsDOMDataChannel> domdc =
|
|
new nsDOMDataChannel(aDataChannel, aWindow);
|
|
|
|
nsresult rv = domdc->Init(aWindow);
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
return CallQueryInterface(domdc, aDomDataChannel);
|
|
}
|
|
|
|
/* static */
|
|
void
|
|
NS_DataChannelAppReady(nsIDOMDataChannel* aDomDataChannel)
|
|
{
|
|
((nsDOMDataChannel *)aDomDataChannel)->AppReady();
|
|
}
|