mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-10-02 00:57:20 +00:00
#463: initial plumbing for requestIdleCallback
This commit is contained in:
parent
37e85c8c9f
commit
ca84d557fc
70
dom/base/IdleDeadline.cpp
Normal file
70
dom/base/IdleDeadline.cpp
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||||
|
/* 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 <algorithm>
|
||||||
|
|
||||||
|
#include "mozilla/dom/IdleDeadline.h"
|
||||||
|
#include "mozilla/dom/IdleDeadlineBinding.h"
|
||||||
|
#include "nsPerformance.h"
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
#include "nsCycleCollectionParticipant.h"
|
||||||
|
#include "nsDOMNavigationTiming.h"
|
||||||
|
#include "nsPIDOMWindow.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
namespace dom {
|
||||||
|
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(IdleDeadline, mWindow)
|
||||||
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(IdleDeadline)
|
||||||
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(IdleDeadline)
|
||||||
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IdleDeadline)
|
||||||
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||||
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||||
|
NS_INTERFACE_MAP_END
|
||||||
|
|
||||||
|
IdleDeadline::IdleDeadline(nsPIDOMWindow* aWindow, bool aDidTimeout,
|
||||||
|
DOMHighResTimeStamp aDeadline)
|
||||||
|
: mWindow(aWindow)
|
||||||
|
, mDidTimeout(aDidTimeout)
|
||||||
|
, mDeadline(aDeadline)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
IdleDeadline::~IdleDeadline()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
JSObject*
|
||||||
|
IdleDeadline::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||||
|
{
|
||||||
|
return IdleDeadlineBinding::Wrap(aCx, this, aGivenProto);
|
||||||
|
}
|
||||||
|
|
||||||
|
DOMHighResTimeStamp
|
||||||
|
IdleDeadline::TimeRemaining()
|
||||||
|
{
|
||||||
|
if (mDidTimeout) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefPtr<nsPerformance> performance = mWindow->GetPerformance();
|
||||||
|
if (!performance) {
|
||||||
|
// If there is no performance object the window is partially torn
|
||||||
|
// down, so we can safely say that there is no time remaining.
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::max(mDeadline - performance->Now(), 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
IdleDeadline::DidTimeout() const
|
||||||
|
{
|
||||||
|
return mDidTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace dom
|
||||||
|
} // namespace mozilla
|
55
dom/base/IdleDeadline.h
Normal file
55
dom/base/IdleDeadline.h
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
#ifndef mozilla_dom_IdleDeadline_h
|
||||||
|
#define mozilla_dom_IdleDeadline_h
|
||||||
|
|
||||||
|
#include "js/TypeDecls.h"
|
||||||
|
#include "mozilla/Attributes.h"
|
||||||
|
#include "mozilla/ErrorResult.h"
|
||||||
|
#include "mozilla/Maybe.h"
|
||||||
|
#include "mozilla/dom/BindingDeclarations.h"
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
#include "nsCycleCollectionParticipant.h"
|
||||||
|
#include "nsDOMNavigationTiming.h"
|
||||||
|
#include "nsWrapperCache.h"
|
||||||
|
|
||||||
|
class nsPIDOMWindow;
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
namespace dom {
|
||||||
|
|
||||||
|
class IdleDeadline final
|
||||||
|
: public nsISupports
|
||||||
|
, public nsWrapperCache
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IdleDeadline(nsPIDOMWindow* aWindow, bool aDidTimeout,
|
||||||
|
DOMHighResTimeStamp aDeadline);
|
||||||
|
|
||||||
|
nsPIDOMWindow* GetParentObject() const { return mWindow; }
|
||||||
|
|
||||||
|
virtual JSObject* WrapObject(JSContext* aCx,
|
||||||
|
JS::Handle<JSObject*> aGivenProto) override;
|
||||||
|
|
||||||
|
DOMHighResTimeStamp TimeRemaining();
|
||||||
|
bool DidTimeout() const;
|
||||||
|
|
||||||
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||||
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IdleDeadline)
|
||||||
|
|
||||||
|
private:
|
||||||
|
~IdleDeadline();
|
||||||
|
|
||||||
|
nsCOMPtr<nsPIDOMWindow> mWindow;
|
||||||
|
const bool mDidTimeout;
|
||||||
|
const DOMHighResTimeStamp mDeadline;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace dom
|
||||||
|
} // namespace mozilla
|
||||||
|
|
||||||
|
#endif // mozilla_dom_IdleDeadline_h
|
@ -182,6 +182,7 @@ EXPORTS.mozilla.dom += [
|
|||||||
'FileReader.h',
|
'FileReader.h',
|
||||||
'FragmentOrElement.h',
|
'FragmentOrElement.h',
|
||||||
'FromParser.h',
|
'FromParser.h',
|
||||||
|
'IdleDeadline.h',
|
||||||
'ImageEncoder.h',
|
'ImageEncoder.h',
|
||||||
'ImportManager.h',
|
'ImportManager.h',
|
||||||
'Link.h',
|
'Link.h',
|
||||||
@ -247,6 +248,7 @@ UNIFIED_SOURCES += [
|
|||||||
'FileList.cpp',
|
'FileList.cpp',
|
||||||
'FileReader.cpp',
|
'FileReader.cpp',
|
||||||
'FragmentOrElement.cpp',
|
'FragmentOrElement.cpp',
|
||||||
|
'IdleDeadline.cpp',
|
||||||
'ImageEncoder.cpp',
|
'ImageEncoder.cpp',
|
||||||
'ImportManager.cpp',
|
'ImportManager.cpp',
|
||||||
'Link.cpp',
|
'Link.cpp',
|
||||||
|
@ -1143,6 +1143,7 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow)
|
|||||||
mTimeoutsSuspendDepth(0),
|
mTimeoutsSuspendDepth(0),
|
||||||
mFocusMethod(0),
|
mFocusMethod(0),
|
||||||
mSerial(0),
|
mSerial(0),
|
||||||
|
mIdleRequestCallbackCounter(1),
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
mSetOpenerWindowCalled(false),
|
mSetOpenerWindowCalled(false),
|
||||||
#endif
|
#endif
|
||||||
@ -13858,3 +13859,35 @@ nsGlobalWindow::CreateImageBitmap(const ImageBitmapSource& aImage,
|
|||||||
{
|
{
|
||||||
return ImageBitmap::Create(this, aImage, Some(gfx::IntRect(aSx, aSy, aSw, aSh)), aRv);
|
return ImageBitmap::Create(this, aImage, Some(gfx::IntRect(aSx, aSy, aSw, aSh)), aRv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Support for requestIdleCallback() from TenFourFox issue 463 */
|
||||||
|
|
||||||
|
uint32_t
|
||||||
|
nsGlobalWindow::RequestIdleCallback(JSContext* aCx,
|
||||||
|
IdleRequestCallback& aCallback,
|
||||||
|
const IdleRequestOptions& aOptions,
|
||||||
|
ErrorResult& aError)
|
||||||
|
{
|
||||||
|
MOZ_RELEASE_ASSERT(IsInnerWindow());
|
||||||
|
AssertIsOnMainThread();
|
||||||
|
|
||||||
|
// uint32_t handle = ++mIdleRequestCallbackCounter;
|
||||||
|
|
||||||
|
fprintf(stderr, "::RequestIdleCallback() is not yet implemented\n");
|
||||||
|
#if DEBUG
|
||||||
|
MOZ_ASSERT(0);
|
||||||
|
#endif
|
||||||
|
return 0; // handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsGlobalWindow::CancelIdleCallback(uint32_t aHandle)
|
||||||
|
{
|
||||||
|
MOZ_RELEASE_ASSERT(IsInnerWindow());
|
||||||
|
|
||||||
|
fprintf(stderr, "::CancelIdleCallback() is not yet implemented\n");
|
||||||
|
#if DEBUG
|
||||||
|
MOZ_ASSERT(0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -118,6 +118,7 @@ class RequestOrUSVString;
|
|||||||
class Selection;
|
class Selection;
|
||||||
class SpeechSynthesis;
|
class SpeechSynthesis;
|
||||||
class WakeLock;
|
class WakeLock;
|
||||||
|
class IdleRequestCallback;
|
||||||
#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
|
#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
|
||||||
class WindowOrientationObserver;
|
class WindowOrientationObserver;
|
||||||
#endif
|
#endif
|
||||||
@ -1042,6 +1043,13 @@ public:
|
|||||||
int32_t RequestAnimationFrame(mozilla::dom::FrameRequestCallback& aCallback,
|
int32_t RequestAnimationFrame(mozilla::dom::FrameRequestCallback& aCallback,
|
||||||
mozilla::ErrorResult& aError);
|
mozilla::ErrorResult& aError);
|
||||||
void CancelAnimationFrame(int32_t aHandle, mozilla::ErrorResult& aError);
|
void CancelAnimationFrame(int32_t aHandle, mozilla::ErrorResult& aError);
|
||||||
|
|
||||||
|
uint32_t RequestIdleCallback(JSContext* aCx,
|
||||||
|
mozilla::dom::IdleRequestCallback& aCallback,
|
||||||
|
const mozilla::dom::IdleRequestOptions& aOptions,
|
||||||
|
mozilla::ErrorResult& aError);
|
||||||
|
void CancelIdleCallback(uint32_t aHandle);
|
||||||
|
|
||||||
#ifdef MOZ_WEBSPEECH
|
#ifdef MOZ_WEBSPEECH
|
||||||
mozilla::dom::SpeechSynthesis*
|
mozilla::dom::SpeechSynthesis*
|
||||||
GetSpeechSynthesis(mozilla::ErrorResult& aError);
|
GetSpeechSynthesis(mozilla::ErrorResult& aError);
|
||||||
@ -1791,6 +1799,9 @@ protected:
|
|||||||
|
|
||||||
uint32_t mSerial;
|
uint32_t mSerial;
|
||||||
|
|
||||||
|
// requestIdleCallback() support
|
||||||
|
uint32_t mIdleRequestCallbackCounter;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
bool mSetOpenerWindowCalled;
|
bool mSetOpenerWindowCalled;
|
||||||
nsCOMPtr<nsIURI> mLastOpenedURI;
|
nsCOMPtr<nsIURI> mLastOpenedURI;
|
||||||
|
@ -1610,6 +1610,9 @@ DOMInterfaces = {
|
|||||||
'binaryNames': {
|
'binaryNames': {
|
||||||
'postMessage': 'postMessageMoz',
|
'postMessage': 'postMessageMoz',
|
||||||
},
|
},
|
||||||
|
'implicitJSContext': [
|
||||||
|
'requestIdleCallback'
|
||||||
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
'WindowProxy': {
|
'WindowProxy': {
|
||||||
|
15
dom/webidl/IdleDeadline.webidl
Normal file
15
dom/webidl/IdleDeadline.webidl
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* 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/.
|
||||||
|
*
|
||||||
|
* The origin of this IDL file is:
|
||||||
|
* https://w3c.github.io/requestidlecallback/
|
||||||
|
*/
|
||||||
|
|
||||||
|
[Pref="dom.requestIdleCallback.enabled"]
|
||||||
|
interface IdleDeadline {
|
||||||
|
DOMHighResTimeStamp timeRemaining();
|
||||||
|
readonly attribute boolean didTimeout;
|
||||||
|
};
|
||||||
|
|
@ -494,3 +494,17 @@ interface ChromeWindow {
|
|||||||
Window implements ChromeWindow;
|
Window implements ChromeWindow;
|
||||||
Window implements GlobalFetch;
|
Window implements GlobalFetch;
|
||||||
Window implements ImageBitmapFactories;
|
Window implements ImageBitmapFactories;
|
||||||
|
|
||||||
|
partial interface Window {
|
||||||
|
[Throws, Pref="dom.requestIdleCallback.enabled"]
|
||||||
|
unsigned long requestIdleCallback(IdleRequestCallback callback,
|
||||||
|
optional IdleRequestOptions options);
|
||||||
|
[Pref="dom.requestIdleCallback.enabled"]
|
||||||
|
void cancelIdleCallback(unsigned long handle);
|
||||||
|
};
|
||||||
|
|
||||||
|
dictionary IdleRequestOptions {
|
||||||
|
unsigned long timeout;
|
||||||
|
};
|
||||||
|
|
||||||
|
callback IdleRequestCallback = void (IdleDeadline deadline);
|
||||||
|
@ -264,6 +264,7 @@ WEBIDL_FILES = [
|
|||||||
'IDBRequest.webidl',
|
'IDBRequest.webidl',
|
||||||
'IDBTransaction.webidl',
|
'IDBTransaction.webidl',
|
||||||
'IDBVersionChangeEvent.webidl',
|
'IDBVersionChangeEvent.webidl',
|
||||||
|
'IdleDeadline.webidl',
|
||||||
'ImageBitmap.webidl',
|
'ImageBitmap.webidl',
|
||||||
'ImageCapture.webidl',
|
'ImageCapture.webidl',
|
||||||
'ImageData.webidl',
|
'ImageData.webidl',
|
||||||
|
@ -1042,6 +1042,9 @@ pref("dom.disable_window_open_feature.status", true);
|
|||||||
|
|
||||||
pref("dom.allow_scripts_to_close_windows", false);
|
pref("dom.allow_scripts_to_close_windows", false);
|
||||||
|
|
||||||
|
// TenFourFox issue 463
|
||||||
|
pref("dom.requestIdleCallback.enabled", false);
|
||||||
|
|
||||||
pref("dom.require_user_interaction_for_beforeunload", true);
|
pref("dom.require_user_interaction_for_beforeunload", true);
|
||||||
|
|
||||||
pref("dom.disable_open_during_load", false);
|
pref("dom.disable_open_during_load", false);
|
||||||
|
Loading…
Reference in New Issue
Block a user