2015-05-03 19:32:37 +00: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 11:12:37 +00: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 12:23:44 +00:00
|
|
|
|
2012-01-16 17:14:56 +00:00
|
|
|
#include <limits>
|
|
|
|
#include "mozilla/Hal.h"
|
2014-01-16 10:53:48 +00:00
|
|
|
#include "mozilla/dom/network/Connection.h"
|
2012-01-16 12:23:44 +00:00
|
|
|
#include "nsIDOMClassInfo.h"
|
2012-01-16 12:25:13 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-01-16 17:14:56 +00:00
|
|
|
#include "Constants.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 03:54:55 +00:00
|
|
|
#define CHANGE_EVENT_NAME NS_LITERAL_STRING("typechange")
|
2012-01-16 12:23:44 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace network {
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_QUERY_INTERFACE_INHERITED(Connection, DOMEventTargetHelper,
|
|
|
|
nsINetworkProperties)
|
2012-01-16 17:14:56 +00:00
|
|
|
|
2013-02-28 17:52:15 +00:00
|
|
|
// Don't use |Connection| alone, since that confuses nsTraceRefcnt since
|
|
|
|
// we're not the only class with that name.
|
2014-04-01 06:13:50 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(dom::network::Connection, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(dom::network::Connection, DOMEventTargetHelper)
|
2012-01-16 17:14:56 +00:00
|
|
|
|
2014-10-07 09:44:48 +00:00
|
|
|
Connection::Connection(nsPIDOMWindow* aWindow)
|
|
|
|
: DOMEventTargetHelper(aWindow)
|
|
|
|
, mType(static_cast<ConnectionType>(kDefaultType))
|
2013-07-11 15:39:36 +00:00
|
|
|
, mIsWifi(kDefaultIsWifi)
|
|
|
|
, mDHCPGateway(kDefaultDHCPGateway)
|
2012-01-16 17:14:56 +00:00
|
|
|
{
|
|
|
|
hal::RegisterNetworkObserver(this);
|
|
|
|
|
|
|
|
hal::NetworkInformation networkInfo;
|
|
|
|
hal::GetCurrentNetworkInformation(&networkInfo);
|
|
|
|
|
|
|
|
UpdateFromNetworkInfo(networkInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Connection::Shutdown()
|
|
|
|
{
|
|
|
|
hal::UnregisterNetworkObserver(this);
|
|
|
|
}
|
|
|
|
|
2013-07-11 15:39:36 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Connection::GetIsWifi(bool *aIsWifi)
|
|
|
|
{
|
|
|
|
*aIsWifi = mIsWifi;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Connection::GetDhcpGateway(uint32_t *aGW)
|
|
|
|
{
|
|
|
|
*aGW = mDHCPGateway;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-16 17:14:56 +00:00
|
|
|
void
|
|
|
|
Connection::UpdateFromNetworkInfo(const hal::NetworkInformation& aNetworkInfo)
|
|
|
|
{
|
2014-03-05 03:54:55 +00:00
|
|
|
mType = static_cast<ConnectionType>(aNetworkInfo.type());
|
2013-07-11 15:39:36 +00:00
|
|
|
mIsWifi = aNetworkInfo.isWifi();
|
|
|
|
mDHCPGateway = aNetworkInfo.dhcpGateway();
|
2012-01-16 17:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Connection::Notify(const hal::NetworkInformation& aNetworkInfo)
|
|
|
|
{
|
2014-03-05 03:54:55 +00:00
|
|
|
ConnectionType previousType = mType;
|
2012-01-16 17:14:56 +00:00
|
|
|
|
|
|
|
UpdateFromNetworkInfo(aNetworkInfo);
|
|
|
|
|
2014-03-05 03:54:55 +00:00
|
|
|
if (previousType == mType) {
|
2012-01-16 17:14:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-27 20:11:31 +00:00
|
|
|
DispatchTrustedEvent(CHANGE_EVENT_NAME);
|
2012-01-16 17:14:56 +00:00
|
|
|
}
|
|
|
|
|
2014-01-16 10:53:48 +00:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
Connection::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2014-01-16 10:53:48 +00:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
return NetworkInformationBinding::Wrap(aCx, this, aGivenProto);
|
2014-01-16 10:53:48 +00:00
|
|
|
}
|
|
|
|
|
2012-01-16 12:23:44 +00:00
|
|
|
} // namespace network
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|