2016-08-22 15:52:45 +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: */
|
|
|
|
/* 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 "IdleRequest.h"
|
|
|
|
|
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "mozilla/dom/IdleDeadline.h"
|
|
|
|
#include "mozilla/dom/PerformanceTiming.h"
|
2016-12-03 01:22:48 +03:00
|
|
|
#include "mozilla/dom/TimeoutManager.h"
|
2016-08-22 15:52:45 +03:00
|
|
|
#include "mozilla/dom/WindowBinding.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsGlobalWindow.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2016-11-08 15:54:40 +03:00
|
|
|
IdleRequest::IdleRequest(IdleRequestCallback* aCallback, uint32_t aHandle)
|
|
|
|
: mCallback(aCallback)
|
2016-08-22 15:52:45 +03:00
|
|
|
, mHandle(aHandle)
|
|
|
|
, mTimeoutHandle(Nothing())
|
|
|
|
{
|
2016-11-08 15:54:40 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mCallback);
|
2016-08-22 15:52:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
IdleRequest::~IdleRequest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-11-28 22:23:46 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IdleRequest)
|
2016-08-22 15:52:45 +03:00
|
|
|
|
2017-11-28 22:23:46 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IdleRequest)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCallback)
|
|
|
|
if (tmp->isInList()) {
|
|
|
|
tmp->remove();
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2016-08-22 15:52:45 +03:00
|
|
|
|
2017-11-28 22:23:46 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IdleRequest)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCallback)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(IdleRequest, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(IdleRequest, Release)
|
2016-08-22 15:52:45 +03:00
|
|
|
|
|
|
|
void
|
2016-11-08 15:54:40 +03:00
|
|
|
IdleRequest::SetTimeoutHandle(int32_t aHandle)
|
2016-08-22 15:52:45 +03:00
|
|
|
{
|
2016-11-08 15:54:40 +03:00
|
|
|
mTimeoutHandle = Some(aHandle);
|
2016-08-22 15:52:45 +03:00
|
|
|
}
|
|
|
|
|
2017-01-31 18:25:49 +03:00
|
|
|
uint32_t
|
|
|
|
IdleRequest::GetTimeoutHandle() const
|
|
|
|
{
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mTimeoutHandle.isSome());
|
|
|
|
return mTimeoutHandle.value();
|
|
|
|
}
|
|
|
|
|
2016-08-22 15:52:45 +03:00
|
|
|
nsresult
|
2016-11-08 15:54:40 +03:00
|
|
|
IdleRequest::IdleRun(nsPIDOMWindowInner* aWindow,
|
|
|
|
DOMHighResTimeStamp aDeadline,
|
|
|
|
bool aDidTimeout)
|
2016-08-22 15:52:45 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2016-11-08 15:54:40 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mCallback);
|
2016-08-22 15:52:45 +03:00
|
|
|
|
|
|
|
ErrorResult error;
|
|
|
|
RefPtr<IdleDeadline> deadline =
|
2016-11-08 15:54:40 +03:00
|
|
|
new IdleDeadline(aWindow, aDidTimeout, aDeadline);
|
2016-08-22 15:52:45 +03:00
|
|
|
mCallback->Call(*deadline, error, "requestIdleCallback handler");
|
2017-01-29 21:29:27 +03:00
|
|
|
|
2016-11-08 15:54:40 +03:00
|
|
|
mCallback = nullptr;
|
|
|
|
error.SuppressException();
|
2016-08-22 15:52:45 +03:00
|
|
|
return error.StealNSResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|