Bug 1278716 - Remove wakelocks from geo. r=jdm

MozReview-Commit-ID: 2Uu1W34r3g8

--HG--
extra : rebase_source : 3fe68bb861ce60da3b6b42819c90df02c58a8e70
This commit is contained in:
Michelangelo De Simone 2016-10-04 15:12:16 -07:00
Родитель fcec1aca37
Коммит 01caec7221
2 изменённых файлов: 8 добавлений и 112 удалений

Просмотреть файл

@ -18,20 +18,15 @@
#include "nsContentUtils.h"
#include "nsContentPermissionHelper.h"
#include "nsIDocument.h"
#include "nsIDOMEvent.h"
#include "nsIObserverService.h"
#include "nsPIDOMWindow.h"
#include "nsThreadUtils.h"
#include "mozilla/HalWakeLock.h"
#include "mozilla/Hal.h"
#include "mozilla/Services.h"
#include "mozilla/Unused.h"
#include "mozilla/Preferences.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/dom/Event.h"
#include "mozilla/WeakPtr.h"
#include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/dom/WakeLock.h"
class nsIPrincipal;
@ -63,7 +58,6 @@ class nsIPrincipal;
using mozilla::Unused; // <snicker>
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::hal;
class nsGeolocationRequest final
: public nsIContentPermissionRequest
@ -487,10 +481,6 @@ nsGeolocationRequest::Allow(JS::HandleValue aChoices)
return NS_OK;
}
if (mLocator->ContainsRequest(this)) {
return NS_OK;
}
if (mIsWatchPositionRequest || !canUseCache) {
// let the locator know we're pending
// we will now be owned by the locator
@ -833,9 +823,9 @@ nsGeolocationService::StartDevice(nsIPrincipal *aPrincipal)
return NS_ERROR_NOT_AVAILABLE;
}
// we do not want to keep the geolocation devices online
// indefinitely. Close them down after a reasonable period of
// inactivivity
// We do not want to keep the geolocation devices online
// indefinitely.
// Close them down after a reasonable period of inactivivity.
SetDisconnectTimer();
if (XRE_IsContentProcess()) {
@ -871,15 +861,6 @@ nsGeolocationService::StartDevice(nsIPrincipal *aPrincipal)
return NS_OK;
}
void
nsGeolocationService::StopDisconnectTimer()
{
if (mDisconnectTimer) {
mDisconnectTimer->Cancel();
mDisconnectTimer = nullptr;
}
}
void
nsGeolocationService::SetDisconnectTimer()
{
@ -927,7 +908,10 @@ nsGeolocationService::UpdateAccuracy(bool aForceHigh)
void
nsGeolocationService::StopDevice()
{
StopDisconnectTimer();
if (mDisconnectTimer) {
mDisconnectTimer->Cancel();
mDisconnectTimer = nullptr;
}
if (XRE_IsContentProcess()) {
ContentChild* cpc = ContentChild::GetSingleton();
@ -1037,14 +1021,6 @@ Geolocation::Init(nsPIDOMWindowInner* aContentDom)
mPrincipal = doc->NodePrincipal();
if (Preferences::GetBool("dom.wakelock.enabled") &&
XRE_IsContentProcess()) {
doc->AddSystemEventListener(NS_LITERAL_STRING("visibilitychange"),
/* listener */ this,
/* use capture */ true,
/* wants untrusted */ false);
}
nsCOMPtr<nsIURI> uri;
nsresult rv = mPrincipal->GetURI(getter_AddRefs(uri));
NS_ENSURE_SUCCESS(rv, rv);
@ -1078,66 +1054,6 @@ Geolocation::Init(nsPIDOMWindowInner* aContentDom)
return NS_OK;
}
bool
Geolocation::ContainsRequest(nsGeolocationRequest* aRequest)
{
if (aRequest->IsWatch() && mWatchingCallbacks.Contains(aRequest)) {
return true;
}
if (mPendingCallbacks.Contains(aRequest)) {
return true;
}
return false;
}
NS_IMETHODIMP
Geolocation::HandleEvent(nsIDOMEvent* aEvent)
{
nsAutoString type;
aEvent->GetType(type);
if (!type.EqualsLiteral("visibilitychange")) {
return NS_OK;
}
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aEvent->InternalDOMEvent()->GetTarget());
MOZ_ASSERT(doc);
if (doc->Hidden()) {
WakeLockInformation info;
GetWakeLockInfo(NS_LITERAL_STRING("gps"), &info);
MOZ_ASSERT(XRE_IsContentProcess());
ContentChild* cpc = ContentChild::GetSingleton();
if (!info.lockingProcesses().Contains(cpc->GetID())) {
cpc->SendRemoveGeolocationListener();
mService->StopDisconnectTimer();
}
return NS_OK;
}
mService->SetDisconnectTimer();
// We will unconditionally allow all the requests in the callbacks
// because if a request is put into either of these two callbacks,
// it means that it has been allowed before.
// That's why when we resume them, we unconditionally allow them again.
for (uint32_t i = 0, length = mWatchingCallbacks.Length(); i < length; ++i) {
mWatchingCallbacks[i]->Allow(JS::UndefinedHandleValue);
}
for (uint32_t i = 0, length = mPendingCallbacks.Length(); i < length; ++i) {
mPendingCallbacks[i]->Allow(JS::UndefinedHandleValue);
}
return NS_OK;
}
void
Geolocation::Shutdown()
{
@ -1145,18 +1061,6 @@ Geolocation::Shutdown()
mPendingCallbacks.Clear();
mWatchingCallbacks.Clear();
if (Preferences::GetBool("dom.wakelock.enabled") &&
XRE_IsContentProcess()) {
if (nsCOMPtr<nsPIDOMWindowInner> window = do_QueryReferent(mOwner)) {
nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
if (doc) {
doc->RemoveSystemEventListener(NS_LITERAL_STRING("visibilitychange"),
this,
/* aUseCapture = */ true);
}
}
}
if (mService) {
mService->RemoveLocator(this);
mService->UpdateAccuracy();

Просмотреть файл

@ -21,7 +21,6 @@
#include "nsCycleCollectionParticipant.h"
#include "nsGeoPosition.h"
#include "nsIDOMEventListener.h"
#include "nsIDOMGeoGeolocation.h"
#include "nsIDOMGeoPosition.h"
#include "nsIDOMGeoPositionError.h"
@ -87,7 +86,6 @@ public:
// create, or reinitalize the callback timer
void SetDisconnectTimer();
void StopDisconnectTimer();
// Update the accuracy and notify the provider if changed
void UpdateAccuracy(bool aForceHigh = false);
@ -125,8 +123,7 @@ namespace dom {
*/
class Geolocation final : public nsIDOMGeoGeolocation,
public nsIGeolocationUpdate,
public nsWrapperCache,
public nsIDOMEventListener
public nsWrapperCache
{
public:
@ -136,8 +133,6 @@ public:
NS_DECL_NSIGEOLOCATIONUPDATE
NS_DECL_NSIDOMGEOGEOLOCATION
NS_DECL_NSIDOMEVENTLISTENER
Geolocation();
nsresult Init(nsPIDOMWindowInner* aContentDom = nullptr);
@ -154,9 +149,6 @@ public:
// Register an allowed request
void NotifyAllowedRequest(nsGeolocationRequest* aRequest);
// Check if callbacks arrays already contain this request
bool ContainsRequest(nsGeolocationRequest* aRequest);
// Remove request from all callbacks arrays
void RemoveRequest(nsGeolocationRequest* request);