mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 677166 - Part 6 - Add NetworkInformation handling into hal. r=jlebar
This commit is contained in:
parent
a280e39ab5
commit
439fd5f9cf
55
dom/network/src/Constants.h
Normal file
55
dom/network/src/Constants.h
Normal file
@ -0,0 +1,55 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 mozilla_dom_network_Constants_h__
|
||||
#define mozilla_dom_network_Constants_h__
|
||||
|
||||
/**
|
||||
* A set of constants to be used by network backends.
|
||||
*/
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace network {
|
||||
|
||||
static const double kDefaultBandwidth = -1.0;
|
||||
static const bool kDefaultCanBeMetered = false;
|
||||
|
||||
} // namespace network
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_network_Constants_h__
|
@ -51,6 +51,8 @@ EXPORTS_NAMESPACES = mozilla/dom/network
|
||||
|
||||
EXPORTS_mozilla/dom/network = \
|
||||
Utils.h \
|
||||
Types.h \
|
||||
Constants.h \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
|
53
dom/network/src/Types.h
Normal file
53
dom/network/src/Types.h
Normal file
@ -0,0 +1,53 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of 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 mozilla_dom_network_Types_h
|
||||
#define mozilla_dom_network_Types_h
|
||||
|
||||
namespace mozilla {
|
||||
namespace hal {
|
||||
class NetworkInformation;
|
||||
} // namespace hal
|
||||
|
||||
template <class T>
|
||||
class Observer;
|
||||
|
||||
typedef Observer<hal::NetworkInformation> NetworkObserver;
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_network_Types_h
|
46
hal/Hal.cpp
46
hal/Hal.cpp
@ -273,6 +273,24 @@ protected:
|
||||
|
||||
static BatteryObserversManager sBatteryObservers;
|
||||
|
||||
class NetworkObserversManager : public ObserversManager<NetworkInformation>
|
||||
{
|
||||
protected:
|
||||
void EnableNotifications() {
|
||||
PROXY_IF_SANDBOXED(EnableNetworkNotifications());
|
||||
}
|
||||
|
||||
void DisableNotifications() {
|
||||
PROXY_IF_SANDBOXED(DisableNetworkNotifications());
|
||||
}
|
||||
|
||||
void GetCurrentInformationInternal(NetworkInformation* aInfo) {
|
||||
PROXY_IF_SANDBOXED(GetCurrentNetworkInformation(aInfo));
|
||||
}
|
||||
};
|
||||
|
||||
static NetworkObserversManager sNetworkObservers;
|
||||
|
||||
void
|
||||
RegisterBatteryObserver(BatteryObserver* aObserver)
|
||||
{
|
||||
@ -326,5 +344,33 @@ void SetScreenBrightness(double brightness)
|
||||
PROXY_IF_SANDBOXED(SetScreenBrightness(clamped(brightness, 0.0, 1.0)));
|
||||
}
|
||||
|
||||
void
|
||||
RegisterNetworkObserver(NetworkObserver* aObserver)
|
||||
{
|
||||
AssertMainThread();
|
||||
sNetworkObservers.AddObserver(aObserver);
|
||||
}
|
||||
|
||||
void
|
||||
UnregisterNetworkObserver(NetworkObserver* aObserver)
|
||||
{
|
||||
AssertMainThread();
|
||||
sNetworkObservers.RemoveObserver(aObserver);
|
||||
}
|
||||
|
||||
void
|
||||
GetCurrentNetworkInformation(NetworkInformation* aInfo)
|
||||
{
|
||||
AssertMainThread();
|
||||
*aInfo = sNetworkObservers.GetCurrentInformation();
|
||||
}
|
||||
|
||||
void
|
||||
NotifyNetworkChange(const NetworkInformation& aInfo)
|
||||
{
|
||||
sNetworkObservers.CacheInformation(aInfo);
|
||||
sNetworkObservers.BroadcastCachedInformation();
|
||||
}
|
||||
|
||||
} // namespace hal
|
||||
} // namespace mozilla
|
||||
|
24
hal/Hal.h
24
hal/Hal.h
@ -46,6 +46,7 @@
|
||||
#include "nsTArray.h"
|
||||
#include "prlog.h"
|
||||
#include "mozilla/dom/battery/Types.h"
|
||||
#include "mozilla/dom/network/Types.h"
|
||||
|
||||
/*
|
||||
* Hal.h contains the public Hal API.
|
||||
@ -168,6 +169,29 @@ double GetScreenBrightness();
|
||||
*/
|
||||
void SetScreenBrightness(double brightness);
|
||||
|
||||
/**
|
||||
* Inform the network backend there is a new network observer.
|
||||
* @param aNetworkObserver The observer that should be added.
|
||||
*/
|
||||
void RegisterNetworkObserver(NetworkObserver* aNetworkObserver);
|
||||
|
||||
/**
|
||||
* Inform the network backend a network observer unregistered.
|
||||
* @param aNetworkObserver The observer that should be removed.
|
||||
*/
|
||||
void UnregisterNetworkObserver(NetworkObserver* aNetworkObserver);
|
||||
|
||||
/**
|
||||
* Returns the current network information.
|
||||
*/
|
||||
void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo);
|
||||
|
||||
/**
|
||||
* Notify of a change in the network state.
|
||||
* @param aNetworkInfo The new network information.
|
||||
*/
|
||||
void NotifyNetworkChange(const hal::NetworkInformation& aNetworkInfo);
|
||||
|
||||
} // namespace MOZ_HAL_NAMESPACE
|
||||
} // namespace mozilla
|
||||
|
||||
|
@ -67,6 +67,16 @@ void EnableBatteryNotifications();
|
||||
*/
|
||||
void DisableBatteryNotifications();
|
||||
|
||||
/**
|
||||
* Enables network notifications from the backend.
|
||||
*/
|
||||
void EnableNetworkNotifications();
|
||||
|
||||
/**
|
||||
* Disables network notifications from the backend.
|
||||
*/
|
||||
void DisableNetworkNotifications();
|
||||
|
||||
} // namespace MOZ_HAL_NAMESPACE
|
||||
} // namespace mozilla
|
||||
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "HalImpl.h"
|
||||
#include "WindowIdentifier.h"
|
||||
#include "AndroidBridge.h"
|
||||
#include "mozilla/dom/network/Constants.h"
|
||||
|
||||
using mozilla::hal::WindowIdentifier;
|
||||
|
||||
@ -139,6 +140,21 @@ void
|
||||
SetScreenBrightness(double brightness)
|
||||
{}
|
||||
|
||||
void
|
||||
EnableNetworkNotifications()
|
||||
{}
|
||||
|
||||
void
|
||||
DisableNetworkNotifications()
|
||||
{}
|
||||
|
||||
void
|
||||
GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo)
|
||||
{
|
||||
aNetworkInfo->bandwidth() = dom::network::kDefaultBandwidth;
|
||||
aNetworkInfo->canBeMetered() = dom::network::kDefaultCanBeMetered;
|
||||
}
|
||||
|
||||
} // hal_impl
|
||||
} // mozilla
|
||||
|
||||
|
@ -39,6 +39,7 @@
|
||||
|
||||
#include "Hal.h"
|
||||
#include "mozilla/dom/battery/Constants.h"
|
||||
#include "mozilla/dom/network/Constants.h"
|
||||
|
||||
using mozilla::hal::WindowIdentifier;
|
||||
|
||||
@ -89,5 +90,20 @@ void
|
||||
SetScreenBrightness(double brightness)
|
||||
{}
|
||||
|
||||
void
|
||||
EnableNetworkNotifications()
|
||||
{}
|
||||
|
||||
void
|
||||
DisableNetworkNotifications()
|
||||
{}
|
||||
|
||||
void
|
||||
GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo)
|
||||
{
|
||||
aNetworkInfo->bandwidth() = dom::network::kDefaultBandwidth;
|
||||
aNetworkInfo->canBeMetered() = dom::network::kDefaultCanBeMetered;
|
||||
}
|
||||
|
||||
} // hal_impl
|
||||
} // namespace mozilla
|
||||
|
@ -36,6 +36,7 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "Hal.h"
|
||||
#include "mozilla/dom/network/Constants.h"
|
||||
|
||||
#ifndef MOZ_ENABLE_DBUS
|
||||
#include <mozilla/dom/battery/Constants.h>
|
||||
@ -90,6 +91,21 @@ void
|
||||
SetScreenBrightness(double brightness)
|
||||
{}
|
||||
|
||||
void
|
||||
EnableNetworkNotifications()
|
||||
{}
|
||||
|
||||
void
|
||||
DisableNetworkNotifications()
|
||||
{}
|
||||
|
||||
void
|
||||
GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo)
|
||||
{
|
||||
aNetworkInfo->bandwidth() = dom::network::kDefaultBandwidth;
|
||||
aNetworkInfo->canBeMetered() = dom::network::kDefaultCanBeMetered;
|
||||
}
|
||||
|
||||
} // hal_impl
|
||||
} // mozilla
|
||||
|
||||
|
@ -50,6 +50,13 @@ namespace hal {
|
||||
};
|
||||
}
|
||||
|
||||
namespace hal {
|
||||
struct NetworkInformation {
|
||||
double bandwidth;
|
||||
bool canBeMetered;
|
||||
};
|
||||
}
|
||||
|
||||
namespace hal_sandbox {
|
||||
|
||||
sync protocol PHal {
|
||||
@ -57,6 +64,7 @@ sync protocol PHal {
|
||||
|
||||
child:
|
||||
NotifyBatteryChange(BatteryInformation aBatteryInfo);
|
||||
NotifyNetworkChange(NetworkInformation aNetworkInfo);
|
||||
|
||||
parent:
|
||||
Vibrate(uint32[] pattern, uint64[] id, PBrowser browser);
|
||||
@ -67,6 +75,11 @@ parent:
|
||||
sync GetCurrentBatteryInformation()
|
||||
returns (BatteryInformation aBatteryInfo);
|
||||
|
||||
EnableNetworkNotifications();
|
||||
DisableNetworkNotifications();
|
||||
sync GetCurrentNetworkInformation()
|
||||
returns (NetworkInformation aNetworkInfo);
|
||||
|
||||
sync GetScreenEnabled() returns (bool enabled);
|
||||
SetScreenEnabled(bool enabled);
|
||||
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "mozilla/dom/TabParent.h"
|
||||
#include "mozilla/dom/TabChild.h"
|
||||
#include "mozilla/dom/battery/Types.h"
|
||||
#include "mozilla/dom/network/Types.h"
|
||||
#include "mozilla/Observer.h"
|
||||
#include "mozilla/unused.h"
|
||||
#include "WindowIdentifier.h"
|
||||
@ -105,6 +106,24 @@ GetCurrentBatteryInformation(BatteryInformation* aBatteryInfo)
|
||||
Hal()->SendGetCurrentBatteryInformation(aBatteryInfo);
|
||||
}
|
||||
|
||||
void
|
||||
EnableNetworkNotifications()
|
||||
{
|
||||
Hal()->SendEnableNetworkNotifications();
|
||||
}
|
||||
|
||||
void
|
||||
DisableNetworkNotifications()
|
||||
{
|
||||
Hal()->SendDisableNetworkNotifications();
|
||||
}
|
||||
|
||||
void
|
||||
GetCurrentNetworkInformation(NetworkInformation* aNetworkInfo)
|
||||
{
|
||||
Hal()->SendGetCurrentNetworkInformation(aNetworkInfo);
|
||||
}
|
||||
|
||||
bool
|
||||
GetScreenEnabled()
|
||||
{
|
||||
@ -134,7 +153,9 @@ SetScreenBrightness(double brightness)
|
||||
}
|
||||
|
||||
class HalParent : public PHalParent
|
||||
, public BatteryObserver {
|
||||
, public BatteryObserver
|
||||
, public NetworkObserver
|
||||
{
|
||||
public:
|
||||
NS_OVERRIDE virtual bool
|
||||
RecvVibrate(const InfallibleTArray<unsigned int>& pattern,
|
||||
@ -197,6 +218,28 @@ public:
|
||||
unused << SendNotifyBatteryChange(aBatteryInfo);
|
||||
}
|
||||
|
||||
NS_OVERRIDE virtual bool
|
||||
RecvEnableNetworkNotifications() {
|
||||
hal::RegisterNetworkObserver(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_OVERRIDE virtual bool
|
||||
RecvDisableNetworkNotifications() {
|
||||
hal::UnregisterNetworkObserver(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_OVERRIDE virtual bool
|
||||
RecvGetCurrentNetworkInformation(NetworkInformation* aNetworkInfo) {
|
||||
hal::GetCurrentNetworkInformation(aNetworkInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Notify(const NetworkInformation& aNetworkInfo) {
|
||||
unused << SendNotifyNetworkChange(aNetworkInfo);
|
||||
}
|
||||
|
||||
NS_OVERRIDE virtual bool
|
||||
RecvGetScreenEnabled(bool *enabled)
|
||||
{
|
||||
@ -233,6 +276,12 @@ public:
|
||||
hal::NotifyBatteryChange(aBatteryInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_OVERRIDE virtual bool
|
||||
RecvNotifyNetworkChange(const NetworkInformation& aNetworkInfo) {
|
||||
hal::NotifyNetworkChange(aNetworkInfo);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
PHalChild* CreateHalChild() {
|
||||
|
@ -36,6 +36,7 @@
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "Hal.h"
|
||||
#include "mozilla/dom/network/Constants.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace hal_impl {
|
||||
@ -68,5 +69,20 @@ void
|
||||
SetScreenBrightness(double brightness)
|
||||
{}
|
||||
|
||||
void
|
||||
EnableNetworkNotifications()
|
||||
{}
|
||||
|
||||
void
|
||||
DisableNetworkNotifications()
|
||||
{}
|
||||
|
||||
void
|
||||
GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo)
|
||||
{
|
||||
aNetworkInfo->bandwidth() = dom::network::kDefaultBandwidth;
|
||||
aNetworkInfo->canBeMetered() = dom::network::kDefaultCanBeMetered;
|
||||
}
|
||||
|
||||
} // hal_impl
|
||||
} // mozilla
|
||||
|
Loading…
Reference in New Issue
Block a user