зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1045561 Use a WebIDL Func attribute to conditionally enable Fetch Headers. r=ehsan r=bz
This commit is contained in:
Родитель
411bb10871
Коммит
a91096978e
|
@ -8,6 +8,8 @@
|
|||
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/UnionTypes.h"
|
||||
#include "mozilla/dom/WorkerPrivate.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
|
||||
#include "nsCharSeparatedTokenizer.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
@ -28,6 +30,32 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Headers)
|
|||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
// static
|
||||
bool
|
||||
Headers::PrefEnabled(JSContext* aCx, JSObject* aObj)
|
||||
{
|
||||
using mozilla::dom::workers::WorkerPrivate;
|
||||
using mozilla::dom::workers::GetWorkerPrivateFromContext;
|
||||
|
||||
if (NS_IsMainThread()) {
|
||||
static bool sPrefCacheInit = false;
|
||||
static bool sPrefEnabled = false;
|
||||
if (sPrefCacheInit) {
|
||||
return sPrefEnabled;
|
||||
}
|
||||
Preferences::AddBoolVarCache(&sPrefEnabled, "dom.fetch.enabled");
|
||||
sPrefCacheInit = true;
|
||||
return sPrefEnabled;
|
||||
}
|
||||
|
||||
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
|
||||
if (!workerPrivate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return workerPrivate->DOMFetchEnabled();
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<Headers>
|
||||
Headers::Constructor(const GlobalObject& aGlobal,
|
||||
|
|
|
@ -54,6 +54,8 @@ public:
|
|||
SetIsDOMBinding();
|
||||
}
|
||||
|
||||
static bool PrefEnabled(JSContext* cx, JSObject* obj);
|
||||
|
||||
static already_AddRefed<Headers>
|
||||
Constructor(const GlobalObject& aGlobal,
|
||||
const Optional<HeadersOrByteStringSequenceSequenceOrByteStringMozMap>& aInit,
|
||||
|
|
|
@ -12,6 +12,10 @@ UNIFIED_SOURCES += [
|
|||
'Headers.cpp',
|
||||
]
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
'../workers',
|
||||
]
|
||||
|
||||
FAIL_ON_WARNINGS = True
|
||||
MSVC_ENABLE_PGO = True
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
|
|
@ -20,7 +20,7 @@ enum HeadersGuardEnum {
|
|||
|
||||
[Constructor(optional HeadersInit init),
|
||||
// FIXME: Exposed=Window,Worker,
|
||||
Pref="dom.fetch.enabled"]
|
||||
Func="mozilla::dom::Headers::PrefEnabled"]
|
||||
interface Headers {
|
||||
[Throws] void append(ByteString name, ByteString value);
|
||||
[Throws] void delete(ByteString name);
|
||||
|
|
|
@ -64,6 +64,8 @@ WorkerPrivate::RegisterBindings(JSContext* aCx, JS::Handle<JSObject*> aGlobal)
|
|||
!DOMExceptionBinding::GetConstructorObject(aCx, aGlobal) ||
|
||||
!EventBinding::GetConstructorObject(aCx, aGlobal) ||
|
||||
!FileReaderSyncBinding_workers::GetConstructorObject(aCx, aGlobal) ||
|
||||
(HeadersBinding::ConstructorEnabled(aCx, aGlobal) &&
|
||||
!HeadersBinding::GetConstructorObject(aCx, aGlobal)) ||
|
||||
!ImageDataBinding::GetConstructorObject(aCx, aGlobal) ||
|
||||
!MessageEventBinding::GetConstructorObject(aCx, aGlobal) ||
|
||||
!MessagePortBinding::GetConstructorObject(aCx, aGlobal) ||
|
||||
|
@ -80,12 +82,6 @@ WorkerPrivate::RegisterBindings(JSContext* aCx, JS::Handle<JSObject*> aGlobal)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (DOMFetchEnabled()) {
|
||||
if (!HeadersBinding::GetConstructorObject(aCx, aGlobal)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!JS_DefineProfilingFunctions(aCx, aGlobal)) {
|
||||
return false;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче