Bug 1360799 - Expose the requestIdleCallback API to chrome code unconditionally; r=bzbarsky

We need to use this API in the front-end code, and in the off-chance
that we end up turning it off for the Web for whatever reason, or if
someone has turned off the pref, we should make sure our UI code does
not break.
This commit is contained in:
Ehsan Akhgari 2017-04-29 01:54:50 -04:00
Родитель d462b93aeb
Коммит 66f333029f
6 изменённых файлов: 26 добавлений и 3 удалений

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

@ -298,6 +298,7 @@ bool nsContentUtils::sAnimationsAPICoreEnabled = false;
bool nsContentUtils::sAnimationsAPIElementAnimateEnabled = false;
bool nsContentUtils::sGetBoxQuadsEnabled = false;
bool nsContentUtils::sSkipCursorMoveForSameValueSet = false;
bool nsContentUtils::sRequestIdleCallbackEnabled = false;
int32_t nsContentUtils::sPrivacyMaxInnerWidth = 1000;
int32_t nsContentUtils::sPrivacyMaxInnerHeight = 1000;
@ -650,6 +651,9 @@ nsContentUtils::Init()
"dom.input.skip_cursor_move_for_same_value_set",
true);
Preferences::AddBoolVarCache(&sRequestIdleCallbackEnabled,
"dom.requestIdleCallback.enabled", false);
Element::InitCCCallbacks();
nsCOMPtr<nsIUUIDGenerator> uuidGenerator =

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

@ -2182,6 +2182,14 @@ public:
return sGetBoxQuadsEnabled;
}
/**
* Returns true if the requestIdleCallback API should be enabled.
*/
static bool RequestIdleCallbackEnabled()
{
return sRequestIdleCallbackEnabled;
}
/**
* Return true if this doc is controlled by a ServiceWorker.
*/
@ -3020,6 +3028,7 @@ private:
static bool sAnimationsAPIElementAnimateEnabled;
static bool sGetBoxQuadsEnabled;
static bool sSkipCursorMoveForSameValueSet;
static bool sRequestIdleCallbackEnabled;
static uint32_t sCookiesLifetimePolicy;
static uint32_t sCookiesBehavior;

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

@ -5169,6 +5169,14 @@ nsGlobalWindow::IsShowModalDialogEnabled(JSContext*, JSObject*)
return !sIsDisabled && !XRE_IsContentProcess();
}
/* static */ bool
nsGlobalWindow::IsRequestIdleCallbackEnabled(JSContext* aCx, JSObject* aObj)
{
// The requestIdleCallback should always be enabled for system code.
return nsContentUtils::RequestIdleCallbackEnabled() ||
nsContentUtils::IsSystemCaller(aCx);
}
nsIDOMOfflineResourceList*
nsGlobalWindow::GetApplicationCache(ErrorResult& aError)
{

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

@ -475,6 +475,8 @@ public:
static bool IsShowModalDialogEnabled(JSContext* /* unused */ = nullptr,
JSObject* /* unused */ = nullptr);
static bool IsRequestIdleCallbackEnabled(JSContext* /* unused */, JSObject* aObj);
bool DoResolve(JSContext* aCx, JS::Handle<JSObject*> aObj,
JS::Handle<jsid> aId,
JS::MutableHandle<JS::PropertyDescriptor> aDesc);

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

@ -7,7 +7,7 @@
* https://w3c.github.io/requestidlecallback/
*/
[Pref="dom.requestIdleCallback.enabled"]
[Func="nsGlobalWindow::IsRequestIdleCallbackEnabled"]
interface IdleDeadline {
DOMHighResTimeStamp timeRemaining();
readonly attribute boolean didTimeout;

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

@ -487,10 +487,10 @@ Window implements ChromeWindow;
Window implements WindowOrWorkerGlobalScope;
partial interface Window {
[Throws, Pref="dom.requestIdleCallback.enabled"]
[Throws, Func="nsGlobalWindow::IsRequestIdleCallbackEnabled"]
unsigned long requestIdleCallback(IdleRequestCallback callback,
optional IdleRequestOptions options);
[Pref="dom.requestIdleCallback.enabled"]
[Func="nsGlobalWindow::IsRequestIdleCallbackEnabled"]
void cancelIdleCallback(unsigned long handle);
};