Bug 878401 - Move WorkerNavigator to WebIDL; r=khuey

This commit is contained in:
Ms2ger 2013-07-24 09:38:23 +02:00
Родитель 59ef6e7599
Коммит d179468520
8 изменённых файлов: 109 добавлений и 172 удалений

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

@ -1355,6 +1355,12 @@ DOMInterfaces = {
'workers': True
}],
'WorkerNavigator': {
'headerFile': 'mozilla/dom/workers/bindings/Navigator.h',
'castable': True,
'workers': True,
},
'XMLHttpRequest': [
{
'nativeType': 'nsXMLHttpRequest',

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

@ -369,6 +369,7 @@ webidl_files = \
WebSocket.webidl \
WheelEvent.webidl \
Window.webidl \
WorkerNavigator.webidl \
XMLDocument.webidl \
XMLHttpRequest.webidl \
XMLHttpRequestEventTarget.webidl \

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

@ -0,0 +1,14 @@
/* 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/. */
interface WorkerNavigator {
[Constant]
readonly attribute DOMString appName;
[Constant]
readonly attribute DOMString appVersion;
[Constant]
readonly attribute DOMString platform;
[Constant]
readonly attribute DOMString userAgent;
};

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

@ -11,6 +11,7 @@
#include "mozilla/dom/TextEncoderBinding.h"
#include "mozilla/dom/XMLHttpRequestBinding.h"
#include "mozilla/dom/XMLHttpRequestUploadBinding.h"
#include "mozilla/dom/WorkerNavigatorBinding.h"
BEGIN_WORKERS_NAMESPACE
@ -19,6 +20,7 @@ class TextDecoder;
class TextEncoder;
class XMLHttpRequest;
class XMLHttpRequestUpload;
class WorkerNavigator;
namespace {
@ -52,6 +54,7 @@ SPECIALIZE_PROTO_TRAITS(TextDecoder)
SPECIALIZE_PROTO_TRAITS(TextEncoder)
SPECIALIZE_PROTO_TRAITS(XMLHttpRequest)
SPECIALIZE_PROTO_TRAITS(XMLHttpRequestUpload)
SPECIALIZE_PROTO_TRAITS(WorkerNavigator)
#undef SPECIALIZE_PROTO_TRAITS

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

@ -5,174 +5,41 @@
#include "Navigator.h"
#include "jsapi.h"
#include "jsfriendapi.h"
#include "nsTraceRefcnt.h"
#include "DOMBindingInlines.h"
#include "RuntimeService.h"
#define PROPERTY_FLAGS \
(JSPROP_ENUMERATE | JSPROP_SHARED)
USING_WORKERS_NAMESPACE
namespace {
class Navigator
{
static JSClass sClass;
static const JSPropertySpec sProperties[];
enum SLOT {
SLOT_appName = 0,
SLOT_appVersion,
SLOT_platform,
SLOT_userAgent,
SLOT_COUNT
};
public:
static JSObject*
InitClass(JSContext* aCx, JSObject* aObj)
{
return JS_InitClass(aCx, aObj, NULL, &sClass, Construct, 0, sProperties,
NULL, NULL, NULL);
}
static JSObject*
Create(JSContext* aCx)
{
RuntimeService* rts = RuntimeService::GetService();
JS_ASSERT(rts);
const RuntimeService::NavigatorStrings& strings =
rts->GetNavigatorStrings();
JS::Rooted<JSString*> appName(aCx), version(aCx), platform(aCx), userAgent(aCx);
#define COPY_STRING(_jsstr, _str) \
if (strings. _str .IsEmpty()) { \
_jsstr = NULL; \
} \
else if (!(_jsstr = JS_NewUCStringCopyN(aCx, strings. _str .get(), \
strings. _str .Length()))) { \
return NULL; \
}
COPY_STRING(appName, mAppName);
COPY_STRING(version, mAppVersion);
COPY_STRING(platform, mPlatform);
COPY_STRING(userAgent, mUserAgent);
#undef COPY_STRING
JSObject* obj = JS_NewObject(aCx, &sClass, NULL, NULL);
if (!obj) {
return NULL;
}
jsval empty = JS_GetEmptyStringValue(aCx);
JS_SetReservedSlot(obj, SLOT_appName,
appName ? STRING_TO_JSVAL(appName) : empty);
JS_SetReservedSlot(obj, SLOT_appVersion,
version ? STRING_TO_JSVAL(version) : empty);
JS_SetReservedSlot(obj, SLOT_platform,
platform ? STRING_TO_JSVAL(platform) : empty);
JS_SetReservedSlot(obj, SLOT_userAgent,
userAgent ? STRING_TO_JSVAL(userAgent) : empty);
Navigator* priv = new Navigator();
JS_SetPrivate(obj, priv);
return obj;
}
private:
Navigator()
{
MOZ_COUNT_CTOR(mozilla::dom::workers::Navigator);
}
~Navigator()
{
MOZ_COUNT_DTOR(mozilla::dom::workers::Navigator);
}
static JSBool
Construct(JSContext* aCx, unsigned aArgc, jsval* aVp)
{
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL, JSMSG_WRONG_CONSTRUCTOR,
sClass.name);
return false;
}
static void
Finalize(JSFreeOp* aFop, JSObject* aObj)
{
JS_ASSERT(JS_GetClass(aObj) == &sClass);
delete static_cast<Navigator*>(JS_GetPrivate(aObj));
}
static JSBool
GetProperty(JSContext* aCx, JS::Handle<JSObject*> aObj, JS::Handle<jsid> aIdval,
JS::MutableHandle<JS::Value> aVp)
{
JSClass* classPtr = JS_GetClass(aObj);
if (classPtr != &sClass) {
JS_ReportErrorNumber(aCx, js_GetErrorMessage, NULL,
JSMSG_INCOMPATIBLE_PROTO, sClass.name, "GetProperty",
classPtr->name);
return false;
}
JS_ASSERT(JSID_IS_INT(aIdval));
JS_ASSERT(JSID_TO_INT(aIdval) >= 0 && JSID_TO_INT(aIdval) < SLOT_COUNT);
aVp.set(JS_GetReservedSlot(aObj, JSID_TO_INT(aIdval)));
return true;
}
};
JSClass Navigator::sClass = {
"WorkerNavigator",
JSCLASS_HAS_PRIVATE | JSCLASS_HAS_RESERVED_SLOTS(SLOT_COUNT),
JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, Finalize
};
const JSPropertySpec Navigator::sProperties[] = {
{ "appName", SLOT_appName, PROPERTY_FLAGS, JSOP_WRAPPER(GetProperty),
JSOP_WRAPPER(js_GetterOnlyPropertyStub) },
{ "appVersion", SLOT_appVersion, PROPERTY_FLAGS, JSOP_WRAPPER(GetProperty),
JSOP_WRAPPER(js_GetterOnlyPropertyStub) },
{ "platform", SLOT_platform, PROPERTY_FLAGS, JSOP_WRAPPER(GetProperty),
JSOP_WRAPPER(js_GetterOnlyPropertyStub) },
{ "userAgent", SLOT_userAgent, PROPERTY_FLAGS, JSOP_WRAPPER(GetProperty),
JSOP_WRAPPER(js_GetterOnlyPropertyStub) },
{ 0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER }
};
} // anonymous namespace
BEGIN_WORKERS_NAMESPACE
namespace navigator {
bool
InitClass(JSContext* aCx, JSObject* aGlobal)
/* static */ already_AddRefed<WorkerNavigator>
WorkerNavigator::Create(JSContext* aCx, JS::Handle<JSObject*> aGlobal)
{
return !!Navigator::InitClass(aCx, aGlobal);
RuntimeService* rts = RuntimeService::GetService();
MOZ_ASSERT(rts);
const RuntimeService::NavigatorStrings& strings =
rts->GetNavigatorStrings();
nsRefPtr<WorkerNavigator> navigator =
new WorkerNavigator(aCx, strings.mAppName, strings.mAppVersion,
strings.mPlatform, strings.mUserAgent);
if (!Wrap(aCx, aGlobal, navigator)) {
return nullptr;
}
return navigator.forget();
}
JSObject*
Create(JSContext* aCx)
void
WorkerNavigator::_trace(JSTracer* aTrc)
{
return Navigator::Create(aCx);
DOMBindingBase::_trace(aTrc);
}
} // namespace navigator
void
WorkerNavigator::_finalize(JSFreeOp* aFop)
{
DOMBindingBase::_finalize(aFop);
}
END_WORKERS_NAMESPACE

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

@ -7,21 +7,65 @@
#define mozilla_dom_workers_navigator_h__
#include "Workers.h"
#include "jspubtd.h"
#include "mozilla/dom/workers/bindings/DOMBindingBase.h"
#include "nsStringGlue.h"
BEGIN_WORKERS_NAMESPACE
namespace navigator {
class WorkerNavigator MOZ_FINAL : public DOMBindingBase
{
nsString mAppName;
nsString mAppVersion;
nsString mPlatform;
nsString mUserAgent;
bool
InitClass(JSContext* aCx, JSObject* aGlobal);
WorkerNavigator(JSContext* aCx,
const nsAString& aAppName,
const nsAString& aAppVersion,
const nsAString& aPlatform,
const nsAString& aUserAgent)
: DOMBindingBase(aCx)
, mAppName(aAppName)
, mAppVersion(aAppVersion)
, mPlatform(aPlatform)
, mUserAgent(aUserAgent)
{
MOZ_COUNT_CTOR(mozilla::dom::workers::WorkerNavigator);
}
JSObject*
Create(JSContext* aCx);
public:
static already_AddRefed<WorkerNavigator>
Create(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
} // namespace navigator
virtual void
_trace(JSTracer* aTrc) MOZ_OVERRIDE;
virtual void
_finalize(JSFreeOp* aFop) MOZ_OVERRIDE;
~WorkerNavigator()
{
MOZ_COUNT_DTOR(mozilla::dom::workers::WorkerNavigator);
}
void GetAppName(nsString& aAppName) const
{
aAppName = mAppName;
}
void GetAppVersion(nsString& aAppVersion) const
{
aAppVersion = mAppVersion;
}
void GetPlatform(nsString& aPlatform) const
{
aPlatform = mPlatform;
}
void GetUserAgent(nsString& aUserAgent) const
{
aUserAgent = mUserAgent;
}
};
END_WORKERS_NAMESPACE
#endif // mozilla_dom_workers_navigator_h__

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

@ -18,6 +18,7 @@
#include "mozilla/dom/XMLHttpRequestBinding.h"
#include "mozilla/dom/XMLHttpRequestUploadBinding.h"
#include "mozilla/dom/URLBinding.h"
#include "mozilla/dom/WorkerNavigatorBinding.h"
#include "mozilla/OSFileConstants.h"
#include "nsTraceRefcnt.h"
#include "xpcpublic.h"
@ -397,12 +398,12 @@ private:
}
if (JSVAL_IS_VOID(scope->mSlots[SLOT_navigator])) {
JSObject* navigator = navigator::Create(aCx);
nsRefPtr<WorkerNavigator> navigator = WorkerNavigator::Create(aCx, aObj);
if (!navigator) {
return false;
}
scope->mSlots[SLOT_navigator] = OBJECT_TO_JSVAL(navigator);
scope->mSlots[SLOT_navigator] = OBJECT_TO_JSVAL(navigator->GetJSObject());
}
aVp.set(scope->mSlots[SLOT_navigator]);
@ -1037,8 +1038,7 @@ CreateDedicatedWorkerGlobalScope(JSContext* aCx)
!file::InitClasses(aCx, global) ||
!exceptions::InitClasses(aCx, global) ||
!location::InitClass(aCx, global) ||
!imagedata::InitClass(aCx, global) ||
!navigator::InitClass(aCx, global)) {
!imagedata::InitClass(aCx, global)) {
return NULL;
}
@ -1048,7 +1048,8 @@ CreateDedicatedWorkerGlobalScope(JSContext* aCx)
!TextEncoderBinding_workers::GetConstructorObject(aCx, global) ||
!XMLHttpRequestBinding_workers::GetConstructorObject(aCx, global) ||
!XMLHttpRequestUploadBinding_workers::GetConstructorObject(aCx, global) ||
!URLBinding_workers::GetConstructorObject(aCx, global)) {
!URLBinding_workers::GetConstructorObject(aCx, global) ||
!WorkerNavigatorBinding_workers::GetConstructorObject(aCx, global)) {
return NULL;
}

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

@ -19,6 +19,7 @@ EXPORTS.mozilla.dom.workers.bindings += [
'EventListenerManager.h',
'EventTarget.h',
'FileReaderSync.h',
'Navigator.h',
'TextDecoder.h',
'TextEncoder.h',
'URL.h',