2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2012-01-16 16:23:44 +04:00
|
|
|
|
2016-12-16 10:50:23 +03:00
|
|
|
#include "Connection.h"
|
|
|
|
#include "ConnectionMainThread.h"
|
|
|
|
#include "ConnectionWorker.h"
|
2012-01-16 21:14:56 +04:00
|
|
|
#include "Constants.h"
|
2017-01-16 20:34:49 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2018-01-31 10:25:30 +03:00
|
|
|
#include "mozilla/dom/WorkerPrivate.h"
|
2012-01-16 21:14:56 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* We have to use macros here because our leak analysis tool things we are
|
|
|
|
* leaking strings when we have |static const nsString|. Sad :(
|
|
|
|
*/
|
2014-03-05 07:54:55 +04:00
|
|
|
#define CHANGE_EVENT_NAME NS_LITERAL_STRING("typechange")
|
2012-01-16 16:23:44 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2016-12-16 10:50:23 +03:00
|
|
|
|
2012-01-16 16:23:44 +04:00
|
|
|
namespace network {
|
|
|
|
|
2013-02-28 21:52:15 +04:00
|
|
|
// Don't use |Connection| alone, since that confuses nsTraceRefcnt since
|
|
|
|
// we're not the only class with that name.
|
2018-11-23 18:53:01 +03:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(dom::network::Connection, DOMEventTargetHelper)
|
2012-01-16 21:14:56 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
Connection::Connection(nsPIDOMWindowInner* aWindow)
|
2014-10-07 13:44:48 +04:00
|
|
|
: DOMEventTargetHelper(aWindow),
|
|
|
|
mType(static_cast<ConnectionType>(kDefaultType)),
|
2013-07-11 19:39:36 +04:00
|
|
|
mIsWifi(kDefaultIsWifi),
|
|
|
|
mDHCPGateway(kDefaultDHCPGateway),
|
2016-12-16 10:50:23 +03:00
|
|
|
mBeenShutDown(false) {
|
2017-01-16 20:34:49 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::NETWORK_CONNECTION_COUNT, 1);
|
2016-12-16 10:50:23 +03:00
|
|
|
}
|
2016-12-15 19:06:22 +03:00
|
|
|
|
2016-12-16 10:50:23 +03:00
|
|
|
Connection::~Connection() {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(Connection);
|
|
|
|
MOZ_ASSERT(mBeenShutDown);
|
2012-01-16 21:14:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Connection::Shutdown() {
|
2016-12-16 10:50:23 +03:00
|
|
|
NS_ASSERT_OWNINGTHREAD(Connection);
|
|
|
|
|
|
|
|
if (mBeenShutDown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mBeenShutDown = true;
|
|
|
|
ShutdownInternal();
|
2012-01-16 21:14:56 +04:00
|
|
|
}
|
|
|
|
|
2016-12-16 10:50:23 +03:00
|
|
|
JSObject* Connection::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return NetworkInformation_Binding::Wrap(aCx, this, aGivenProto);
|
2012-01-16 21:14:56 +04:00
|
|
|
}
|
|
|
|
|
2017-07-03 00:11:46 +03:00
|
|
|
void Connection::Update(ConnectionType aType, bool aIsWifi,
|
|
|
|
uint32_t aDHCPGateway, bool aNotify) {
|
2016-12-16 10:50:23 +03:00
|
|
|
NS_ASSERT_OWNINGTHREAD(Connection);
|
|
|
|
|
2014-03-05 07:54:55 +04:00
|
|
|
ConnectionType previousType = mType;
|
2012-01-16 21:14:56 +04:00
|
|
|
|
2016-12-16 10:50:23 +03:00
|
|
|
mType = aType;
|
|
|
|
mIsWifi = aIsWifi;
|
|
|
|
mDHCPGateway = aDHCPGateway;
|
2012-01-16 21:14:56 +04:00
|
|
|
|
2017-06-13 06:10:30 +03:00
|
|
|
if (aNotify && previousType != aType &&
|
|
|
|
!nsContentUtils::ShouldResistFingerprinting()) {
|
2016-12-16 10:50:23 +03:00
|
|
|
DispatchTrustedEvent(CHANGE_EVENT_NAME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
Connection* Connection::CreateForWindow(nsPIDOMWindowInner* aWindow) {
|
2016-12-16 10:50:23 +03:00
|
|
|
MOZ_ASSERT(aWindow);
|
|
|
|
return new ConnectionMainThread(aWindow);
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<Connection> Connection::CreateForWorker(
|
2018-01-31 10:24:08 +03:00
|
|
|
WorkerPrivate* aWorkerPrivate, ErrorResult& aRv) {
|
2016-12-16 10:50:23 +03:00
|
|
|
MOZ_ASSERT(aWorkerPrivate);
|
|
|
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
return ConnectionWorker::Create(aWorkerPrivate, aRv);
|
2014-01-16 14:53:48 +04:00
|
|
|
}
|
|
|
|
|
2012-01-16 16:23:44 +04:00
|
|
|
} // namespace network
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|