Hi,

I am currently having troubles while accessing to an HTMLEmbed element ( a flash player ) within a loaded page :
I can get the DOM object, *probably* can create the related JSObject, but I cannot get the SetVariable property ( which I can see with the DOM Inspector ) , neither call this function...


I am probably doing somethin wrong while creating my JsContext... But I dont't know what !!

If someone, on earth or below, can help me , I can assume that he / she would graduate a higher karma for this life and maybe for the next ones...

Regards,

static
nsresult GetContextFromDocument(nsIDocument *aDocument, JSContext **cx)
{
  *cx = nsnull;

  nsCOMPtr<nsIScriptGlobalObject> sgo;
  aDocument->GetScriptGlobalObject(getter_AddRefs(sgo));

  if (!sgo) {
    // No script global, no context.

    return NS_OK;
  }

  nsCOMPtr<nsIScriptContext> scx;
  sgo->GetContext(getter_AddRefs(scx));

  if (!scx) {
    // No context left in the old scope...

    return NS_OK;
  }

  *cx = (JSContext *)scx->GetNativeContext();

  return NS_OK;
}

void myFunc()
{

nsresult rv;
nsCOMPtr<nsIDOMDocument> doc;
webNav->GetDocument(getter_AddRefs(doc)) ;
// gets the XPConnect component
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
// gets the JSContext
nsCOMPtr<nsIDocument> idoc = do_QueryInterface(doc);
GetContextFromDocument(idoc,&cx);
nsCOMPtr<nsIDOMElement> element;
doc->GetElementById(NS_LITERAL_STRING("myFlash"),getter_AddRefs(element));
nsCOMPtr<nsIDOMNodeList> childNodes;
element->GetChildNodes(getter_AddRefs(childNodes));
PRUint32 length;
childNodes->GetLength(&length);
for (int i=0; i<length;i++)
{
nsCOMPtr<nsIDOMNode> subNode;
childNodes->Item(i,getter_AddRefs(subNode));
nsCOMPtr<nsIClassInfo> test;
subNode->QueryInterface(NS_GET_IID(nsIClassInfo),
getter_AddRefs(test));
if (test)
{
nsCOMPtr<nsISupports> s; nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
xpc->WrapNative(cx, ::JS_GetGlobalObject(cx), subNode,NS_GET_IID(nsIDOMNode),
getter_AddRefs(wrapper));
if (wrapper)
{
JSObject *jsobj;
native_wrapper->GetJSObject(&jsobj);
helper->PostCreate(native_wrapper, cx, jsobj);
PRBool res ;
jsval fval;
// DOES NOT WORK
helper->GetProperty(native_wrapper, cx, jsobj, STRING_TO_JSVAL("SetVariable"), &fval, &res);
// DOES NOT WORK : fval is JSVAL_VOID
JS_GetProperty(cx, jsobj,"SetVariable", &fval);
// DOES NOT WORK EITHER
jsval argv[3], retval;
argv[0] = OBJECT_TO_JSVAL(jsobj);
argv[1] = STRING_TO_JSVAL("myVar");
argv[2] = STRING_TO_JSVAL("test");
JS_CallFunctionName(cx, jsobj,
"SetVariable", 3, argv, &retval))
}
}
}


_______________________________________________
mozilla-embedding mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-embedding

Reply via email to