Bug 1045561 Use a WebIDL Func attribute to conditionally enable Fetch Headers. r=ehsan r=bz

This commit is contained in:
Ben Kelly 2014-07-29 17:24:22 -04:00
parent e0060d9e3f
commit 03e77dbb2f
5 changed files with 37 additions and 7 deletions

View File

@ -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,

View File

@ -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,

View File

@ -12,6 +12,10 @@ UNIFIED_SOURCES += [
'Headers.cpp',
]
LOCAL_INCLUDES += [
'../workers',
]
FAIL_ON_WARNINGS = True
MSVC_ENABLE_PGO = True
FINAL_LIBRARY = 'xul'

View File

@ -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);

View File

@ -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;
}