зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset adceb7fb0fce (bug 660233) due to test failures.
This commit is contained in:
Родитель
b8575602ef
Коммит
73e5bc9071
|
@ -527,7 +527,9 @@ static const char kDOMStringBundleURL[] =
|
||||||
#define NODE_SCRIPTABLE_FLAGS \
|
#define NODE_SCRIPTABLE_FLAGS \
|
||||||
((DOM_DEFAULT_SCRIPTABLE_FLAGS | \
|
((DOM_DEFAULT_SCRIPTABLE_FLAGS | \
|
||||||
nsIXPCScriptable::USE_STUB_EQUALITY_HOOK | \
|
nsIXPCScriptable::USE_STUB_EQUALITY_HOOK | \
|
||||||
nsIXPCScriptable::WANT_ADDPROPERTY) & \
|
nsIXPCScriptable::WANT_GETPROPERTY | \
|
||||||
|
nsIXPCScriptable::WANT_ADDPROPERTY | \
|
||||||
|
nsIXPCScriptable::WANT_SETPROPERTY) & \
|
||||||
~nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY)
|
~nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY)
|
||||||
|
|
||||||
// We need to let JavaScript QI elements to interfaces that are not in
|
// We need to let JavaScript QI elements to interfaces that are not in
|
||||||
|
@ -551,6 +553,8 @@ static const char kDOMStringBundleURL[] =
|
||||||
#define DOCUMENT_SCRIPTABLE_FLAGS \
|
#define DOCUMENT_SCRIPTABLE_FLAGS \
|
||||||
(NODE_SCRIPTABLE_FLAGS | \
|
(NODE_SCRIPTABLE_FLAGS | \
|
||||||
nsIXPCScriptable::WANT_POSTCREATE | \
|
nsIXPCScriptable::WANT_POSTCREATE | \
|
||||||
|
nsIXPCScriptable::WANT_ADDPROPERTY | \
|
||||||
|
nsIXPCScriptable::WANT_GETPROPERTY | \
|
||||||
nsIXPCScriptable::WANT_ENUMERATE)
|
nsIXPCScriptable::WANT_ENUMERATE)
|
||||||
|
|
||||||
#define ARRAY_SCRIPTABLE_FLAGS \
|
#define ARRAY_SCRIPTABLE_FLAGS \
|
||||||
|
@ -758,8 +762,7 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
||||||
|
|
||||||
// Misc HTML classes
|
// Misc HTML classes
|
||||||
NS_DEFINE_CLASSINFO_DATA(HTMLDocument, nsHTMLDocumentSH,
|
NS_DEFINE_CLASSINFO_DATA(HTMLDocument, nsHTMLDocumentSH,
|
||||||
DOCUMENT_SCRIPTABLE_FLAGS |
|
DOCUMENT_SCRIPTABLE_FLAGS)
|
||||||
nsIXPCScriptable::WANT_GETPROPERTY)
|
|
||||||
NS_DEFINE_CLASSINFO_DATA(HTMLOptionsCollection,
|
NS_DEFINE_CLASSINFO_DATA(HTMLOptionsCollection,
|
||||||
nsHTMLOptionsCollectionSH,
|
nsHTMLOptionsCollectionSH,
|
||||||
ARRAY_SCRIPTABLE_FLAGS |
|
ARRAY_SCRIPTABLE_FLAGS |
|
||||||
|
@ -863,7 +866,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
||||||
ELEMENT_SCRIPTABLE_FLAGS)
|
ELEMENT_SCRIPTABLE_FLAGS)
|
||||||
NS_DEFINE_CLASSINFO_DATA(HTMLSelectElement, nsHTMLSelectElementSH,
|
NS_DEFINE_CLASSINFO_DATA(HTMLSelectElement, nsHTMLSelectElementSH,
|
||||||
ELEMENT_SCRIPTABLE_FLAGS |
|
ELEMENT_SCRIPTABLE_FLAGS |
|
||||||
nsIXPCScriptable::WANT_SETPROPERTY |
|
|
||||||
nsIXPCScriptable::WANT_GETPROPERTY)
|
nsIXPCScriptable::WANT_GETPROPERTY)
|
||||||
NS_DEFINE_CLASSINFO_DATA(HTMLSpanElement, nsElementSH,
|
NS_DEFINE_CLASSINFO_DATA(HTMLSpanElement, nsElementSH,
|
||||||
ELEMENT_SCRIPTABLE_FLAGS)
|
ELEMENT_SCRIPTABLE_FLAGS)
|
||||||
|
@ -1609,6 +1611,9 @@ jsid nsDOMClassInfo::sOpener_id = JSID_VOID;
|
||||||
jsid nsDOMClassInfo::sAll_id = JSID_VOID;
|
jsid nsDOMClassInfo::sAll_id = JSID_VOID;
|
||||||
jsid nsDOMClassInfo::sTags_id = JSID_VOID;
|
jsid nsDOMClassInfo::sTags_id = JSID_VOID;
|
||||||
jsid nsDOMClassInfo::sAddEventListener_id= JSID_VOID;
|
jsid nsDOMClassInfo::sAddEventListener_id= JSID_VOID;
|
||||||
|
jsid nsDOMClassInfo::sBaseURIObject_id = JSID_VOID;
|
||||||
|
jsid nsDOMClassInfo::sNodePrincipal_id = JSID_VOID;
|
||||||
|
jsid nsDOMClassInfo::sDocumentURIObject_id=JSID_VOID;
|
||||||
jsid nsDOMClassInfo::sJava_id = JSID_VOID;
|
jsid nsDOMClassInfo::sJava_id = JSID_VOID;
|
||||||
jsid nsDOMClassInfo::sPackages_id = JSID_VOID;
|
jsid nsDOMClassInfo::sPackages_id = JSID_VOID;
|
||||||
jsid nsDOMClassInfo::sWrappedJSObject_id = JSID_VOID;
|
jsid nsDOMClassInfo::sWrappedJSObject_id = JSID_VOID;
|
||||||
|
@ -1869,6 +1874,9 @@ nsDOMClassInfo::DefineStaticJSVals(JSContext *cx)
|
||||||
SET_JSID_TO_STRING(sAll_id, cx, "all");
|
SET_JSID_TO_STRING(sAll_id, cx, "all");
|
||||||
SET_JSID_TO_STRING(sTags_id, cx, "tags");
|
SET_JSID_TO_STRING(sTags_id, cx, "tags");
|
||||||
SET_JSID_TO_STRING(sAddEventListener_id,cx, "addEventListener");
|
SET_JSID_TO_STRING(sAddEventListener_id,cx, "addEventListener");
|
||||||
|
SET_JSID_TO_STRING(sBaseURIObject_id, cx, "baseURIObject");
|
||||||
|
SET_JSID_TO_STRING(sNodePrincipal_id, cx, "nodePrincipal");
|
||||||
|
SET_JSID_TO_STRING(sDocumentURIObject_id,cx,"documentURIObject");
|
||||||
SET_JSID_TO_STRING(sJava_id, cx, "java");
|
SET_JSID_TO_STRING(sJava_id, cx, "java");
|
||||||
SET_JSID_TO_STRING(sPackages_id, cx, "Packages");
|
SET_JSID_TO_STRING(sPackages_id, cx, "Packages");
|
||||||
SET_JSID_TO_STRING(sWrappedJSObject_id, cx, "wrappedJSObject");
|
SET_JSID_TO_STRING(sWrappedJSObject_id, cx, "wrappedJSObject");
|
||||||
|
@ -4860,6 +4868,9 @@ nsDOMClassInfo::ShutDown()
|
||||||
sAll_id = JSID_VOID;
|
sAll_id = JSID_VOID;
|
||||||
sTags_id = JSID_VOID;
|
sTags_id = JSID_VOID;
|
||||||
sAddEventListener_id= JSID_VOID;
|
sAddEventListener_id= JSID_VOID;
|
||||||
|
sBaseURIObject_id = JSID_VOID;
|
||||||
|
sNodePrincipal_id = JSID_VOID;
|
||||||
|
sDocumentURIObject_id=JSID_VOID;
|
||||||
sJava_id = JSID_VOID;
|
sJava_id = JSID_VOID;
|
||||||
sPackages_id = JSID_VOID;
|
sPackages_id = JSID_VOID;
|
||||||
sWrappedJSObject_id = JSID_VOID;
|
sWrappedJSObject_id = JSID_VOID;
|
||||||
|
@ -7119,6 +7130,26 @@ nsNodeSH::IsCapabilityEnabled(const char* aCapability)
|
||||||
enabled;
|
enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
nsNodeSH::DefineVoidProp(JSContext* cx, JSObject* obj, jsid id,
|
||||||
|
JSObject** objp)
|
||||||
|
{
|
||||||
|
NS_ASSERTION(JSID_IS_STRING(id), "id must be a string");
|
||||||
|
|
||||||
|
// We want this to be as invisible to content script as possible. So
|
||||||
|
// don't enumerate this, and set is as JSPROP_SHARED so it won't get
|
||||||
|
// cached on the object.
|
||||||
|
JSBool ok = ::JS_DefinePropertyById(cx, obj, id, JSVAL_VOID,
|
||||||
|
nsnull, nsnull, JSPROP_SHARED);
|
||||||
|
|
||||||
|
if (!ok) {
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*objp = obj;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj,
|
nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj,
|
||||||
JSObject **parentObj)
|
JSObject **parentObj)
|
||||||
|
@ -7266,6 +7297,11 @@ nsNodeSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||||
JSObject *obj, jsid id, PRUint32 flags,
|
JSObject *obj, jsid id, PRUint32 flags,
|
||||||
JSObject **objp, PRBool *_retval)
|
JSObject **objp, PRBool *_retval)
|
||||||
{
|
{
|
||||||
|
if ((id == sBaseURIObject_id || id == sNodePrincipal_id) &&
|
||||||
|
IsPrivilegedScript()) {
|
||||||
|
return DefineVoidProp(cx, obj, id, objp);
|
||||||
|
}
|
||||||
|
|
||||||
if (id == sOnload_id || id == sOnerror_id) {
|
if (id == sOnload_id || id == sOnerror_id) {
|
||||||
// Make sure that this node can't go away while waiting for a
|
// Make sure that this node can't go away while waiting for a
|
||||||
// network load that could fire an event handler.
|
// network load that could fire an event handler.
|
||||||
|
@ -7280,6 +7316,63 @@ nsNodeSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||||
_retval);
|
_retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsNodeSH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||||
|
JSObject *obj, jsid id, jsval *vp, PRBool *_retval)
|
||||||
|
{
|
||||||
|
if (id == sBaseURIObject_id && IsPrivilegedScript()) {
|
||||||
|
// I wish GetBaseURI lived on nsINode
|
||||||
|
nsCOMPtr<nsIURI> uri;
|
||||||
|
nsCOMPtr<nsIContent> content = do_QueryWrappedNative(wrapper, obj);
|
||||||
|
if (content) {
|
||||||
|
uri = content->GetBaseURI();
|
||||||
|
NS_ENSURE_TRUE(uri, NS_ERROR_OUT_OF_MEMORY);
|
||||||
|
} else {
|
||||||
|
nsCOMPtr<nsIDocument> doc = do_QueryWrappedNative(wrapper, obj);
|
||||||
|
NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
|
||||||
|
|
||||||
|
uri = doc->GetBaseURI();
|
||||||
|
NS_ENSURE_TRUE(uri, NS_ERROR_NOT_AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||||
|
nsresult rv = WrapNative(cx, JS_GetGlobalForScopeChain(cx), uri,
|
||||||
|
&NS_GET_IID(nsIURI), PR_TRUE, vp,
|
||||||
|
getter_AddRefs(holder));
|
||||||
|
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id == sNodePrincipal_id && IsPrivilegedScript()) {
|
||||||
|
nsCOMPtr<nsINode> node = do_QueryWrappedNative(wrapper, obj);
|
||||||
|
NS_ENSURE_TRUE(node, NS_ERROR_UNEXPECTED);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||||
|
nsresult rv = WrapNative(cx, JS_GetGlobalForScopeChain(cx),
|
||||||
|
node->NodePrincipal(), &NS_GET_IID(nsIPrincipal),
|
||||||
|
PR_TRUE, vp, getter_AddRefs(holder));
|
||||||
|
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: none of our ancestors want GetProperty
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsNodeSH::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||||
|
JSObject *obj, jsid id, jsval *vp, PRBool *_retval)
|
||||||
|
{
|
||||||
|
if ((id == sBaseURIObject_id || id == sNodePrincipal_id) &&
|
||||||
|
IsPrivilegedScript()) {
|
||||||
|
// We don't want privileged script that can read this property to set it,
|
||||||
|
// but _do_ want to allow everyone else to set a value they can then read.
|
||||||
|
//
|
||||||
|
// XXXbz Is there a better error we could use here?
|
||||||
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsNodeSH::GetFlags(PRUint32 *aFlags)
|
nsNodeSH::GetFlags(PRUint32 *aFlags)
|
||||||
{
|
{
|
||||||
|
@ -8172,6 +8265,8 @@ nsDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||||
getter_AddRefs(holder));
|
getter_AddRefs(holder));
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
JSAutoRequest ar(cx);
|
||||||
|
|
||||||
JSBool ok = ::JS_DefinePropertyById(cx, obj, id, v, nsnull,
|
JSBool ok = ::JS_DefinePropertyById(cx, obj, id, v, nsnull,
|
||||||
LocationSetter<nsIDOMDocument>,
|
LocationSetter<nsIDOMDocument>,
|
||||||
JSPROP_PERMANENT | JSPROP_ENUMERATE);
|
JSPROP_PERMANENT | JSPROP_ENUMERATE);
|
||||||
|
@ -8185,9 +8280,50 @@ nsDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (id == sDocumentURIObject_id && IsPrivilegedScript()) {
|
||||||
|
return DefineVoidProp(cx, obj, id, objp);
|
||||||
|
}
|
||||||
|
|
||||||
return nsNodeSH::NewResolve(wrapper, cx, obj, id, flags, objp, _retval);
|
return nsNodeSH::NewResolve(wrapper, cx, obj, id, flags, objp, _retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsDocumentSH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||||
|
JSObject *obj, jsid id, jsval *vp, PRBool *_retval)
|
||||||
|
{
|
||||||
|
if (id == sDocumentURIObject_id && IsPrivilegedScript()) {
|
||||||
|
nsCOMPtr<nsIDocument> doc = do_QueryWrappedNative(wrapper);
|
||||||
|
NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
|
||||||
|
|
||||||
|
nsIURI* uri = doc->GetDocumentURI();
|
||||||
|
NS_ENSURE_TRUE(uri, NS_ERROR_NOT_AVAILABLE);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||||
|
nsresult rv = WrapNative(cx, JS_GetGlobalForScopeChain(cx), uri,
|
||||||
|
&NS_GET_IID(nsIURI), PR_TRUE, vp,
|
||||||
|
getter_AddRefs(holder));
|
||||||
|
|
||||||
|
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nsNodeSH::GetProperty(wrapper, cx, obj, id, vp, _retval);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsDocumentSH::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||||
|
JSObject *obj, jsid id, jsval *vp, PRBool *_retval)
|
||||||
|
{
|
||||||
|
if (id == sDocumentURIObject_id && IsPrivilegedScript()) {
|
||||||
|
// We don't want privileged script that can read this property to set it,
|
||||||
|
// but _do_ want to allow everyone else to set a value they can then read.
|
||||||
|
//
|
||||||
|
// XXXbz Is there a better error we could use here?
|
||||||
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nsNodeSH::SetProperty(wrapper, cx, obj, id, vp, _retval);
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsDocumentSH::GetFlags(PRUint32* aFlags)
|
nsDocumentSH::GetFlags(PRUint32* aFlags)
|
||||||
{
|
{
|
||||||
|
@ -8853,7 +8989,7 @@ nsHTMLDocumentSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return nsDocumentSH::GetProperty(wrapper, cx, obj, id, vp, _retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTMLFormElement helper
|
// HTMLFormElement helper
|
||||||
|
@ -8952,7 +9088,7 @@ nsHTMLFormElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return nsElementSH::GetProperty(wrapper, cx, obj, id, vp, _retval);;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -9086,7 +9222,7 @@ nsHTMLSelectElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return nsElementSH::GetProperty(wrapper, cx, obj, id, vp, _retval);;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
@ -9137,7 +9273,7 @@ nsHTMLSelectElementSH::SetProperty(nsIXPConnectWrappedNative *wrapper,
|
||||||
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
|
return NS_FAILED(rv) ? rv : NS_SUCCESS_I_DID_SOMETHING;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return nsElementSH::SetProperty(wrapper, cx, obj, id, vp, _retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -9410,7 +9546,7 @@ nsHTMLPluginObjElementSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
|
||||||
return *_retval ? NS_SUCCESS_I_DID_SOMETHING : NS_ERROR_FAILURE;
|
return *_retval ? NS_SUCCESS_I_DID_SOMETHING : NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return nsElementSH::GetProperty(wrapper, cx, obj, id, vp, _retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -9439,7 +9575,7 @@ nsHTMLPluginObjElementSH::SetProperty(nsIXPConnectWrappedNative *wrapper,
|
||||||
return *_retval ? NS_SUCCESS_I_DID_SOMETHING : NS_ERROR_FAILURE;
|
return *_retval ? NS_SUCCESS_I_DID_SOMETHING : NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return nsElementSH::SetProperty(wrapper, cx, obj, id, vp, _retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
|
|
@ -282,6 +282,9 @@ public:
|
||||||
static jsid sAll_id;
|
static jsid sAll_id;
|
||||||
static jsid sTags_id;
|
static jsid sTags_id;
|
||||||
static jsid sAddEventListener_id;
|
static jsid sAddEventListener_id;
|
||||||
|
static jsid sBaseURIObject_id;
|
||||||
|
static jsid sNodePrincipal_id;
|
||||||
|
static jsid sDocumentURIObject_id;
|
||||||
static jsid sJava_id;
|
static jsid sJava_id;
|
||||||
static jsid sPackages_id;
|
static jsid sPackages_id;
|
||||||
static jsid sWrappedJSObject_id;
|
static jsid sWrappedJSObject_id;
|
||||||
|
@ -508,6 +511,13 @@ protected:
|
||||||
return IsCapabilityEnabled("UniversalXPConnect");
|
return IsCapabilityEnabled("UniversalXPConnect");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper to define a void property with JSPROP_SHARED; this can do all the
|
||||||
|
// work so it's safe to just return whatever it returns. |obj| is the object
|
||||||
|
// we're defining on, |id| is the name of the prop. This must be a string
|
||||||
|
// jsval. |objp| is the out param if we define successfully.
|
||||||
|
nsresult DefineVoidProp(JSContext* cx, JSObject* obj, jsid id,
|
||||||
|
JSObject** objp);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
|
NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
|
||||||
JSObject *globalObj, JSObject **parentObj);
|
JSObject *globalObj, JSObject **parentObj);
|
||||||
|
@ -516,6 +526,10 @@ public:
|
||||||
NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||||
JSObject *obj, jsid id, PRUint32 flags,
|
JSObject *obj, jsid id, PRUint32 flags,
|
||||||
JSObject **objp, PRBool *_retval);
|
JSObject **objp, PRBool *_retval);
|
||||||
|
NS_IMETHOD GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||||
|
JSObject *obj, jsid id, jsval *vp, PRBool *_retval);
|
||||||
|
NS_IMETHOD SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||||
|
JSObject *obj, jsid id, jsval *vp, PRBool *_retval);
|
||||||
NS_IMETHOD GetFlags(PRUint32 *aFlags);
|
NS_IMETHOD GetFlags(PRUint32 *aFlags);
|
||||||
|
|
||||||
virtual void PreserveWrapper(nsISupports *aNative);
|
virtual void PreserveWrapper(nsISupports *aNative);
|
||||||
|
@ -816,6 +830,10 @@ public:
|
||||||
NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||||
JSObject *obj, jsid id, PRUint32 flags,
|
JSObject *obj, jsid id, PRUint32 flags,
|
||||||
JSObject **objp, PRBool *_retval);
|
JSObject **objp, PRBool *_retval);
|
||||||
|
NS_IMETHOD GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||||
|
JSObject *obj, jsid id, jsval *vp, PRBool *_retval);
|
||||||
|
NS_IMETHOD SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||||
|
JSObject *obj, jsid id, jsval *vp, PRBool *_retval);
|
||||||
NS_IMETHOD GetFlags(PRUint32* aFlags);
|
NS_IMETHOD GetFlags(PRUint32* aFlags);
|
||||||
NS_IMETHOD PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
NS_IMETHOD PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
||||||
JSObject *obj);
|
JSObject *obj);
|
||||||
|
|
|
@ -80,10 +80,7 @@ const char* XPCJSRuntime::mStrings[] = {
|
||||||
"__proto__", // IDX_PROTO
|
"__proto__", // IDX_PROTO
|
||||||
"__iterator__", // IDX_ITERATOR
|
"__iterator__", // IDX_ITERATOR
|
||||||
"__exposedProps__", // IDX_EXPOSEDPROPS
|
"__exposedProps__", // IDX_EXPOSEDPROPS
|
||||||
"__scriptOnly__", // IDX_SCRIPTONLY
|
"__scriptOnly__" // IDX_SCRIPTONLY
|
||||||
"baseURIObject", // IDX_BASEURIOBJECT
|
|
||||||
"nodePrincipal", // IDX_NODEPRINCIPAL
|
|
||||||
"documentURIObject" // IDX_DOCUMENTURIOBJECT
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
|
|
|
@ -725,9 +725,6 @@ public:
|
||||||
IDX_ITERATOR ,
|
IDX_ITERATOR ,
|
||||||
IDX_EXPOSEDPROPS ,
|
IDX_EXPOSEDPROPS ,
|
||||||
IDX_SCRIPTONLY ,
|
IDX_SCRIPTONLY ,
|
||||||
IDX_BASEURIOBJECT ,
|
|
||||||
IDX_NODEPRINCIPAL ,
|
|
||||||
IDX_DOCUMENTURIOBJECT ,
|
|
||||||
IDX_TOTAL_COUNT // just a count of the above
|
IDX_TOTAL_COUNT // just a count of the above
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -46,9 +46,6 @@
|
||||||
#include "jscntxt.h"
|
#include "jscntxt.h"
|
||||||
#include "jsiter.h"
|
#include "jsiter.h"
|
||||||
|
|
||||||
#include "nsINode.h"
|
|
||||||
#include "nsIDocument.h"
|
|
||||||
|
|
||||||
#include "XPCWrapper.h"
|
#include "XPCWrapper.h"
|
||||||
#include "xpcprivate.h"
|
#include "xpcprivate.h"
|
||||||
|
|
||||||
|
@ -335,118 +332,11 @@ ResolveNativeProperty(JSContext *cx, JSObject *wrapper, JSObject *holder, jsid i
|
||||||
static JSBool
|
static JSBool
|
||||||
wrappedJSObject_getter(JSContext *cx, JSObject *wrapper, jsid id, jsval *vp)
|
wrappedJSObject_getter(JSContext *cx, JSObject *wrapper, jsid id, jsval *vp)
|
||||||
{
|
{
|
||||||
if (!wrapper->isWrapper() || !WrapperFactory::IsXrayWrapper(wrapper)) {
|
|
||||||
JS_ReportError(cx, "Unexpected object");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
*vp = OBJECT_TO_JSVAL(wrapper);
|
*vp = OBJECT_TO_JSVAL(wrapper);
|
||||||
|
|
||||||
return WrapperFactory::WaiveXrayAndWrap(cx, vp);
|
return WrapperFactory::WaiveXrayAndWrap(cx, vp);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
static bool
|
|
||||||
Is(JSObject *wrapper)
|
|
||||||
{
|
|
||||||
JSObject *holder = GetHolder(wrapper);
|
|
||||||
XPCWrappedNative *wn = GetWrappedNativeFromHolder(holder);
|
|
||||||
nsCOMPtr<T> native = do_QueryWrappedNative(wn);
|
|
||||||
return !!native;
|
|
||||||
}
|
|
||||||
|
|
||||||
static JSBool
|
|
||||||
WrapURI(JSContext *cx, nsIURI *uri, jsval *vp)
|
|
||||||
{
|
|
||||||
JSObject *scope = JS_GetGlobalForScopeChain(cx);
|
|
||||||
nsresult rv =
|
|
||||||
nsXPConnect::FastGetXPConnect()->WrapNativeToJSVal(cx, scope, uri, nsnull,
|
|
||||||
&NS_GET_IID(nsIURI), PR_TRUE,
|
|
||||||
vp, nsnull);
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
XPCThrower::Throw(rv, cx);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static JSBool
|
|
||||||
documentURIObject_getter(JSContext *cx, JSObject *wrapper, jsid id, jsval *vp)
|
|
||||||
{
|
|
||||||
if (!wrapper->isWrapper() || !WrapperFactory::IsXrayWrapper(wrapper)) {
|
|
||||||
JS_ReportError(cx, "Unexpected object");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSObject *holder = GetHolder(wrapper);
|
|
||||||
XPCWrappedNative *wn = GetWrappedNativeFromHolder(holder);
|
|
||||||
nsCOMPtr<nsIDocument> native = do_QueryWrappedNative(wn);
|
|
||||||
if (!native) {
|
|
||||||
JS_ReportError(cx, "Unexpected object");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> uri = native->GetDocumentURI();
|
|
||||||
if (!uri) {
|
|
||||||
JS_ReportOutOfMemory(cx);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return WrapURI(cx, uri, vp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static JSBool
|
|
||||||
baseURIObject_getter(JSContext *cx, JSObject *wrapper, jsid id, jsval *vp)
|
|
||||||
{
|
|
||||||
if (!wrapper->isWrapper() || !WrapperFactory::IsXrayWrapper(wrapper)) {
|
|
||||||
JS_ReportError(cx, "Unexpected object");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSObject *holder = GetHolder(wrapper);
|
|
||||||
XPCWrappedNative *wn = GetWrappedNativeFromHolder(holder);
|
|
||||||
nsCOMPtr<nsINode> native = do_QueryWrappedNative(wn);
|
|
||||||
if (!native) {
|
|
||||||
JS_ReportError(cx, "Unexpected object");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
nsCOMPtr<nsIURI> uri = native->GetBaseURI();
|
|
||||||
if (!uri) {
|
|
||||||
JS_ReportOutOfMemory(cx);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return WrapURI(cx, uri, vp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static JSBool
|
|
||||||
nodePrincipal_getter(JSContext *cx, JSObject *wrapper, jsid id, jsval *vp)
|
|
||||||
{
|
|
||||||
if (!wrapper->isWrapper() || !WrapperFactory::IsXrayWrapper(wrapper)) {
|
|
||||||
JS_ReportError(cx, "Unexpected object");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSObject *holder = GetHolder(wrapper);
|
|
||||||
XPCWrappedNative *wn = GetWrappedNativeFromHolder(holder);
|
|
||||||
nsCOMPtr<nsINode> node = do_QueryWrappedNative(wn);
|
|
||||||
if (!node) {
|
|
||||||
JS_ReportError(cx, "Unexpected object");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSObject *scope = JS_GetGlobalForScopeChain(cx);
|
|
||||||
nsresult rv =
|
|
||||||
nsXPConnect::FastGetXPConnect()->WrapNativeToJSVal(cx, scope, node->NodePrincipal(), nsnull,
|
|
||||||
&NS_GET_IID(nsIPrincipal), PR_TRUE,
|
|
||||||
vp, nsnull);
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
XPCThrower::Throw(rv, cx);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static JSBool
|
static JSBool
|
||||||
XrayToString(JSContext *cx, uintN argc, jsval *vp)
|
XrayToString(JSContext *cx, uintN argc, jsval *vp)
|
||||||
{
|
{
|
||||||
|
@ -511,22 +401,7 @@ class AutoLeaveHelper
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
IsPrivilegedScript()
|
Transparent(JSContext *cx, JSObject *wrapper)
|
||||||
{
|
|
||||||
// Redirect access straight to the wrapper if UniversalXPConnect is enabled.
|
|
||||||
nsIScriptSecurityManager *ssm = XPCWrapper::GetSecurityManager();
|
|
||||||
if (ssm) {
|
|
||||||
PRBool privileged;
|
|
||||||
if (NS_SUCCEEDED(ssm->IsCapabilityEnabled("UniversalXPConnect", &privileged)) && privileged)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace XrayUtils {
|
|
||||||
|
|
||||||
bool
|
|
||||||
IsTransparent(JSContext *cx, JSObject *wrapper)
|
|
||||||
{
|
{
|
||||||
if (WrapperFactory::HasWaiveXrayFlag(wrapper))
|
if (WrapperFactory::HasWaiveXrayFlag(wrapper))
|
||||||
return true;
|
return true;
|
||||||
|
@ -535,12 +410,24 @@ IsTransparent(JSContext *cx, JSObject *wrapper)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Redirect access straight to the wrapper if UniversalXPConnect is enabled.
|
// Redirect access straight to the wrapper if UniversalXPConnect is enabled.
|
||||||
if (IsPrivilegedScript())
|
nsIScriptSecurityManager *ssm = XPCWrapper::GetSecurityManager();
|
||||||
|
if (ssm) {
|
||||||
|
PRBool privileged;
|
||||||
|
if (NS_SUCCEEDED(ssm->IsCapabilityEnabled("UniversalXPConnect", &privileged)) && privileged)
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return AccessCheck::documentDomainMakesSameOrigin(cx, wrapper->unwrap());
|
return AccessCheck::documentDomainMakesSameOrigin(cx, wrapper->unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace XrayUtils {
|
||||||
|
|
||||||
|
bool
|
||||||
|
IsTransparent(JSContext *cx, JSObject *wrapper)
|
||||||
|
{
|
||||||
|
return Transparent(cx, wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Base>
|
template <typename Base>
|
||||||
|
@ -552,20 +439,8 @@ XrayWrapper<Base>::resolveOwnProperty(JSContext *cx, JSObject *wrapper, jsid id,
|
||||||
|
|
||||||
// Partially transparent wrappers (which used to be known as XOWs) don't
|
// Partially transparent wrappers (which used to be known as XOWs) don't
|
||||||
// have a .wrappedJSObject property.
|
// have a .wrappedJSObject property.
|
||||||
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
|
|
||||||
if (!WrapperFactory::IsPartiallyTransparent(wrapper) &&
|
if (!WrapperFactory::IsPartiallyTransparent(wrapper) &&
|
||||||
(id == rt->GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT) ||
|
id == nsXPConnect::GetRuntimeInstance()->GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT)) {
|
||||||
// Check for baseURIObject and nodePrincipal no nodes and
|
|
||||||
// documentURIObject on documents, but only from privileged scripts.
|
|
||||||
// Do the id checks before the QIs and IsPrivilegedScript() checks,
|
|
||||||
// since they're cheaper and will tend to fail most of the time
|
|
||||||
// anyway.
|
|
||||||
(((id == rt->GetStringID(XPCJSRuntime::IDX_BASEURIOBJECT) ||
|
|
||||||
id == rt->GetStringID(XPCJSRuntime::IDX_NODEPRINCIPAL)) &&
|
|
||||||
Is<nsINode>(wrapper)) ||
|
|
||||||
(id == rt->GetStringID(XPCJSRuntime::IDX_DOCUMENTURIOBJECT) &&
|
|
||||||
Is<nsIDocument>(wrapper))) &&
|
|
||||||
IsPrivilegedScript())) {
|
|
||||||
bool status;
|
bool status;
|
||||||
JSWrapper::Action action = set ? JSWrapper::SET : JSWrapper::GET;
|
JSWrapper::Action action = set ? JSWrapper::SET : JSWrapper::GET;
|
||||||
desc->obj = NULL; // default value
|
desc->obj = NULL; // default value
|
||||||
|
@ -576,14 +451,7 @@ XrayWrapper<Base>::resolveOwnProperty(JSContext *cx, JSObject *wrapper, jsid id,
|
||||||
|
|
||||||
desc->obj = wrapper;
|
desc->obj = wrapper;
|
||||||
desc->attrs = JSPROP_ENUMERATE|JSPROP_SHARED;
|
desc->attrs = JSPROP_ENUMERATE|JSPROP_SHARED;
|
||||||
if (id == rt->GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT))
|
|
||||||
desc->getter = wrappedJSObject_getter;
|
desc->getter = wrappedJSObject_getter;
|
||||||
else if (id == rt->GetStringID(XPCJSRuntime::IDX_BASEURIOBJECT))
|
|
||||||
desc->getter = baseURIObject_getter;
|
|
||||||
else if (id == rt->GetStringID(XPCJSRuntime::IDX_DOCUMENTURIOBJECT))
|
|
||||||
desc->getter = documentURIObject_getter;
|
|
||||||
else
|
|
||||||
desc->getter = nodePrincipal_getter;
|
|
||||||
desc->setter = NULL;
|
desc->setter = NULL;
|
||||||
desc->shortid = 0;
|
desc->shortid = 0;
|
||||||
desc->value = JSVAL_VOID;
|
desc->value = JSVAL_VOID;
|
||||||
|
@ -672,7 +540,7 @@ XrayWrapper<Base>::getPropertyDescriptor(JSContext *cx, JSObject *wrapper, jsid
|
||||||
ResolvingId resolving(holder, id);
|
ResolvingId resolving(holder, id);
|
||||||
|
|
||||||
// Redirect access straight to the wrapper if we should be transparent.
|
// Redirect access straight to the wrapper if we should be transparent.
|
||||||
if (XrayUtils::IsTransparent(cx, wrapper)) {
|
if (Transparent(cx, wrapper)) {
|
||||||
JSObject *wnObject = GetWrappedNativeObjectFromHolder(holder);
|
JSObject *wnObject = GetWrappedNativeObjectFromHolder(holder);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -743,7 +611,7 @@ XrayWrapper<Base>::getOwnPropertyDescriptor(JSContext *cx, JSObject *wrapper, js
|
||||||
// NB: Nothing we do here acts on the wrapped native itself, so we don't
|
// NB: Nothing we do here acts on the wrapped native itself, so we don't
|
||||||
// enter our policy.
|
// enter our policy.
|
||||||
// Redirect access straight to the wrapper if we should be transparent.
|
// Redirect access straight to the wrapper if we should be transparent.
|
||||||
if (XrayUtils::IsTransparent(cx, wrapper)) {
|
if (Transparent(cx, wrapper)) {
|
||||||
JSObject *wnObject = GetWrappedNativeObjectFromHolder(holder);
|
JSObject *wnObject = GetWrappedNativeObjectFromHolder(holder);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -774,7 +642,7 @@ XrayWrapper<Base>::defineProperty(JSContext *cx, JSObject *wrapper, jsid id,
|
||||||
JSPropertyDescriptor *jsdesc = Jsvalify(desc);
|
JSPropertyDescriptor *jsdesc = Jsvalify(desc);
|
||||||
|
|
||||||
// Redirect access straight to the wrapper if we should be transparent.
|
// Redirect access straight to the wrapper if we should be transparent.
|
||||||
if (XrayUtils::IsTransparent(cx, wrapper)) {
|
if (Transparent(cx, wrapper)) {
|
||||||
JSObject *wnObject = GetWrappedNativeObjectFromHolder(holder);
|
JSObject *wnObject = GetWrappedNativeObjectFromHolder(holder);
|
||||||
|
|
||||||
JSAutoEnterCompartment ac;
|
JSAutoEnterCompartment ac;
|
||||||
|
@ -823,7 +691,7 @@ EnumerateNames(JSContext *cx, JSObject *wrapper, uintN flags, js::AutoIdVector &
|
||||||
JSObject *wnObject = GetWrappedNativeObjectFromHolder(holder);
|
JSObject *wnObject = GetWrappedNativeObjectFromHolder(holder);
|
||||||
|
|
||||||
// Redirect access straight to the wrapper if we should be transparent.
|
// Redirect access straight to the wrapper if we should be transparent.
|
||||||
if (XrayUtils::IsTransparent(cx, wrapper)) {
|
if (Transparent(cx, wrapper)) {
|
||||||
JSAutoEnterCompartment ac;
|
JSAutoEnterCompartment ac;
|
||||||
if (!ac.enter(cx, wnObject))
|
if (!ac.enter(cx, wnObject))
|
||||||
return false;
|
return false;
|
||||||
|
@ -880,7 +748,7 @@ XrayWrapper<Base>::delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp)
|
||||||
JSBool b;
|
JSBool b;
|
||||||
|
|
||||||
// Redirect access straight to the wrapper if we should be transparent.
|
// Redirect access straight to the wrapper if we should be transparent.
|
||||||
if (XrayUtils::IsTransparent(cx, wrapper)) {
|
if (Transparent(cx, wrapper)) {
|
||||||
JSObject *wnObject = GetWrappedNativeObjectFromHolder(holder);
|
JSObject *wnObject = GetWrappedNativeObjectFromHolder(holder);
|
||||||
|
|
||||||
JSAutoEnterCompartment ac;
|
JSAutoEnterCompartment ac;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче