On Thursday, October 24, 2013 9:04:13 PM UTC+5:30, Vasu Yadav wrote:
> On Thursday, September 19, 2013 10:06:30 AM UTC+5:30, Vasu Yadav wrote:
> 
> > Hi 
> 
> > 
> 
> > 
> 
> > 
> 
> > We are facing problem with our Add-ons support for FireFox 24.Firefox is 
> > crashing. In earlier approach we was using 'JS_GetGlobalObject' to get 
> > global object from docShell. 
> > https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_GetGlobalObject?redirectlocale=en-US&redirectslug=SpiderMonkey%2FJSAPI_Reference%2FJS_GetGlobalObject
> >  
> 
> > 
> 
> > 
> 
> > 
> 
> > As per given above link- I should use use JS_GetGlobalForObject or 
> > JS_GetGlobalForScopeChain instead of JS_GetGlobalObject. I tried both of 
> > them and additionally I tried GetNativeGlobal(), GetGlobalJSObject() . but 
> > none of them work out. Firefox is crashing in all the cases . 
> 
> > 
> 
> > 
> 
> > 
> 
> > Could anybody help me for this issue? what are required changes need to fix 
> > this problem. I have paste code for yours reference. 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > bool CFFGBrowser::GetJSGlobalContextAndWindow(nsIDocShell *docShell, 
> > JSContext **jsContext, 
> 
> > 
> 
> > 
> 
> > 
> 
> > jsval &window)
> 
> > 
> 
> > 
> 
> > 
> 
> > {
> 
> > 
> 
> > 
> 
> > 
> 
> > bool isSuccess = false;
> 
> > 
> 
> > 
> 
> > 
> 
> > nsresult rv;
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > do 
> 
> > 
> 
> > 
> 
> > 
> 
> > {
> 
> > 
> 
> > 
> 
> > 
> 
> > nsCOMPtr< nsIScriptGlobalObject > scriptObj = do_GetInterface( docShell, 
> > &rv ); 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > if( NS_FAILED( rv ) )
> 
> > 
> 
> > 
> 
> > 
> 
> > {
> 
> > 
> 
> > 
> 
> > 
> 
> > break;
> 
> > 
> 
> > 
> 
> > 
> 
> > }
> 
> > 
> 
> > 
> 
> > 
> 
> > nsCOMPtr< nsIScriptContext > scriptContext = scriptObj->GetContext(); 
> 
> > 
> 
> > 
> 
> > 
> 
> > if ( !scriptContext )
> 
> > 
> 
> > 
> 
> > 
> 
> > {
> 
> > 
> 
> > 
> 
> > 
> 
> > break;
> 
> > 
> 
> > 
> 
> > 
> 
> > }
> 
> > 
> 
> > 
> 
> > 
> 
> > *jsContext = static_cast<JSContext*>( scriptContext->GetNativeContext());
> 
> > 
> 
> > 
> 
> > 
> 
> > //JSObject *globalObj1 = scriptContext->GetNativeGlobal();
> 
> > 
> 
> > 
> 
> > 
> 
> > JSObject *globalObj = scriptObj->GetGlobalJSObject();
> 
> > 
> 
> > 
> 
> > 
> 
> > CLogFile::Info(111, "CFFGBrowser::GetJSGlobalContextAndObject 
> > -start...3.2.");
> 
> > 
> 
> > 
> 
> > 
> 
> > //JSObject *globalObj = JS_GetArrayPrototype(*jsContext,globalObj1);
> 
> > 
> 
> > 
> 
> > 
> 
> > //JS::Rooted<JSObject*> globalObj(*jsContext, 
> > JS_GetGlobalForScopeChain(*jsContext));
> 
> > 
> 
> > 
> 
> > 
> 
> > //JS::RootedObject*globalObj =static_cast<JSObject*>( 
> > scriptContext->GetNativeGlobal());
> 
> > 
> 
> > 
> 
> > 
> 
> > //JSObject *globalObj2 = JS_GetGlobalForScopeChain(*jsContext);
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > //JSObject *globalObj3 = JS_GetGlobalForObject(*jsContext,globalObj2);
> 
> > 
> 
> > 
> 
> > 
> 
> > //JSObject *globalObj = JS_GetGlobalForScopeChain(scriptContext); 
> 
> > 
> 
> > 
> 
> > 
> 
> > if ( !jsContext )
> 
> > 
> 
> > 
> 
> > 
> 
> > {
> 
> > 
> 
> > 
> 
> > 
> 
> > break;
> 
> > 
> 
> > 
> 
> > 
> 
> > }
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > if (!globalObj )
> 
> > 
> 
> > 
> 
> > 
> 
> > {
> 
> > 
> 
> > 
> 
> > 
> 
> > break;
> 
> > 
> 
> > 
> 
> > 
> 
> > }
> 
> > 
> 
> > 
> 
> > 
> 
> > JSBool isSucceeded = JS_GetProperty( *jsContext, globalObj, "window", 
> > &window );
> 
> > 
> 
> > 
> 
> > 
> 
> > if ( ( isSucceeded != JS_TRUE ) || ( window == JSVAL_VOID ) )
> 
> > 
> 
> > 
> 
> > 
> 
> > {
> 
> > 
> 
> > 
> 
> > 
> 
> > break;
> 
> > 
> 
> > 
> 
> > 
> 
> > }
> 
> > 
> 
> > 
> 
> > 
> 
> >  jsval jsargs[1];
> 
> > 
> 
> >    //jsval jscaptureSSLText   = JSVAL_NULL, rval = JSVAL_NULL;
> 
> > 
> 
> >    jsval rval = JSVAL_NULL;
> 
> > 
> 
> >    jsargs[0] = INT_TO_JSVAL(0);
> 
> > 
> 
> >    //JS::HandleValue captureSSLVal = JS::RootedValue(jsContext, 
> > jscaptureSSLText);
> 
> > 
> 
> >    JS::RootedValue captureSSLVal(*jsContext, jsargs[0]);
> 
> > 
> 
> >    JS::RootedValue windowVal(*jsContext, window);
> 
> > 
> 
> >    JS::RootedObject windowObj (*jsContext, JSVAL_TO_OBJECT(window));
> 
> > 
> 
> >    //JS_CallFunctionName
> 
> > 
> 
> >    JSBool isSucceededd = JS_CallFunctionName(*jsContext,      
> 
> > 
> 
> >             globalObj,
> 
> > 
> 
> >             "KeynoteCaptureSSLText",
> 
> > 
> 
> >             1,               
> 
> > 
> 
> >             jsargs,     
> 
> > 
> 
> >             &rval);
> 
> > 
> 
> >  isSuccess = true;
> 
> > 
> 
> > 
> 
> > 
> 
> > }while(false);
> 
> > 
> 
> > 
> 
> > 
> 
> > return isSuccess;
> 
> > 
> 
> > 
> 
> > 
> 
> > }
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > Regards
> 
> > 
> 
> > 
> 
> > 
> 
> > Vasu
> 
> 
> 
> 
> 
> 
> 
> Now, I have got pass through below items.
> 
> 1) create instance of JS XPCOM component, 
> 
> 2) Call javascript XPCOM component function from C++ code 
> 
> 3) Able to pass interface pointer from C++ code to JS function
> 
> 
> 
> My plan is to pass a nsIDocShell pointer to javascript component and then let 
> the javascript component execute the given javascript in a content window. 
> ex. get/set window property, call a global function in window
> 
> 
> 
> Can you please let me know 
> 
> - how can I find a global window object for a nsIDocshell in my javascript 
> XPCOM component
> 
> - how can I execute a javascript in that window

Vasu,

Iam a kind of new bee and I need to do the same thing as what you have done.
Need my C++ XPCOM to call JS function (page script or content script). Since it 
is not supported now, it has to be glued vie JS XPCOM. Do you have the working 
example as how you done? I need the working example badly.

Thanks
Shan'
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to