1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Dave Townsend <dtownsend@oxymoronical.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
41 #include "nsAutoPtr.h"
42 #include "nsIScriptContext.h"
43 #include "nsIScriptObjectOwner.h"
44 #include "nsIScriptGlobalObject.h"
47 #include "nsIDOMInstallTriggerGlobal.h"
48 #include "nsPIDOMWindow.h"
49 #include "nsIDOMDocument.h"
50 #include "nsIDocument.h"
51 #include "nsIDocShell.h"
52 #include "nsIObserverService.h"
53 #include "nsInstallTrigger.h"
54 #include "nsXPITriggerInfo.h"
55 #include "nsDOMJSUtils.h"
56 #include "nsXPIInstallInfo.h"
58 #include "nsIComponentManager.h"
59 #include "nsNetUtil.h"
60 #include "nsIScriptSecurityManager.h"
62 #include "nsSoftwareUpdateIIDs.h"
64 void ConvertJSValToStr(nsString
& aString
,
70 if ( !JSVAL_IS_NULL(aValue
) &&
71 (jsstring
= JS_ValueToString(aContext
, aValue
)) != nsnull
)
73 aString
.Assign(reinterpret_cast<const PRUnichar
*>(JS_GetStringChars(jsstring
)));
82 FinalizeInstallTriggerGlobal(JSContext
*cx
, JSObject
*obj
);
84 /***********************************************************************/
86 // class for InstallTriggerGlobal
88 JSClass InstallTriggerGlobalClass
= {
98 FinalizeInstallTriggerGlobal
103 // InstallTriggerGlobal finalizer
106 FinalizeInstallTriggerGlobal(JSContext
*cx
, JSObject
*obj
)
108 nsISupports
*nativeThis
= (nsISupports
*)JS_GetPrivate(cx
, obj
);
110 if (nsnull
!= nativeThis
) {
112 nsIScriptObjectOwner
*owner
= nsnull
;
113 if (NS_OK
== nativeThis
->QueryInterface(NS_GET_IID(nsIScriptObjectOwner
),
115 owner
->SetScriptObject(nsnull
);
119 // The addref was part of JSObject construction
120 NS_RELEASE(nativeThis
);
124 static JSBool
CreateNativeObject(JSContext
*cx
, JSObject
*obj
, nsIDOMInstallTriggerGlobal
**aResult
)
127 nsIScriptObjectOwner
*owner
= nsnull
;
128 nsIDOMInstallTriggerGlobal
*nativeThis
;
130 static NS_DEFINE_CID(kInstallTrigger_CID
,
131 NS_SoftwareUpdateInstallTrigger_CID
);
133 result
= CallCreateInstance(kInstallTrigger_CID
, &nativeThis
);
134 if (NS_FAILED(result
)) return JS_FALSE
;
136 result
= nativeThis
->QueryInterface(NS_GET_IID(nsIScriptObjectOwner
),
141 NS_RELEASE(nativeThis
);
145 owner
->SetScriptObject((void *)obj
);
146 JS_SetPrivate(cx
, obj
, nativeThis
);
148 *aResult
= nativeThis
;
150 NS_RELEASE(nativeThis
); // we only want one refcnt. JSUtils cleans us up.
155 // Helper function for URI verification
158 InstallTriggerCheckLoadURIFromScript(JSContext
*cx
, const nsAString
& uriStr
)
161 nsCOMPtr
<nsIScriptSecurityManager
> secman(
162 do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID
,&rv
));
163 NS_ENSURE_SUCCESS(rv
, rv
);
165 // get the script principal
166 nsCOMPtr
<nsIPrincipal
> principal
;
167 rv
= secman
->GetSubjectPrincipal(getter_AddRefs(principal
));
168 NS_ENSURE_SUCCESS(rv
, rv
);
170 return NS_ERROR_FAILURE
;
172 // convert the requested URL string to a URI
173 // Note that we use a null base URI here, since that's what we use when we
174 // actually convert the string into a URI to load.
175 nsCOMPtr
<nsIURI
> uri
;
176 rv
= NS_NewURI(getter_AddRefs(uri
), uriStr
);
177 NS_ENSURE_SUCCESS(rv
, rv
);
179 // are we allowed to load this one?
180 rv
= secman
->CheckLoadURIWithPrincipal(principal
, uri
,
181 nsIScriptSecurityManager::DISALLOW_INHERIT_PRINCIPAL
);
186 // Helper function to get native object
188 // This is our own version of JS_GetInstancePrivate() that in addition
189 // performs the delayed creation of the native InstallTrigger if necessary
191 static nsIDOMInstallTriggerGlobal
* getTriggerNative(JSContext
*cx
, JSObject
*obj
)
193 if (!JS_InstanceOf(cx
, obj
, &InstallTriggerGlobalClass
, nsnull
))
196 nsIDOMInstallTriggerGlobal
*native
= (nsIDOMInstallTriggerGlobal
*)JS_GetPrivate(cx
, obj
);
198 // xpinstall script contexts delay creation of the native.
199 CreateNativeObject(cx
, obj
, &native
);
205 // Native method UpdateEnabled
208 InstallTriggerGlobalUpdateEnabled(JSContext
*cx
, JSObject
*obj
, uintN argc
, jsval
*argv
, jsval
*rval
)
210 nsIDOMInstallTriggerGlobal
*nativeThis
= getTriggerNative(cx
, obj
);
216 nsIScriptGlobalObject
*globalObject
= nsnull
;
217 nsIScriptContext
*scriptContext
= GetScriptContextFromJSContext(cx
);
219 globalObject
= scriptContext
->GetGlobalObject();
221 PRBool nativeRet
= PR_FALSE
;
223 nativeThis
->UpdateEnabled(globalObject
, XPI_GLOBAL
, &nativeRet
);
225 *rval
= BOOLEAN_TO_JSVAL(nativeRet
);
231 // Native method Install
234 InstallTriggerGlobalInstall(JSContext
*cx
, JSObject
*obj
, uintN argc
, jsval
*argv
, jsval
*rval
)
236 nsIDOMInstallTriggerGlobal
*nativeThis
= getTriggerNative(cx
, obj
);
242 // make sure XPInstall is enabled, return false if not
243 nsIScriptGlobalObject
*globalObject
= nsnull
;
244 nsIScriptContext
*scriptContext
= GetScriptContextFromJSContext(cx
);
246 globalObject
= scriptContext
->GetGlobalObject();
251 nsCOMPtr
<nsIScriptSecurityManager
> secman(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID
));
254 JS_ReportError(cx
, "Could not the script security manager service.");
257 // get the principal. if it doesn't exist, die.
258 nsCOMPtr
<nsIPrincipal
> principal
;
259 secman
->GetSubjectPrincipal(getter_AddRefs(principal
));
262 JS_ReportError(cx
, "Could not get the Subject Principal during InstallTrigger.Install()");
266 // get window.location to construct relative URLs
267 nsCOMPtr
<nsIURI
> baseURL
;
268 JSObject
* global
= JS_GetGlobalObject(cx
);
272 if (JS_GetProperty(cx
,global
,"location",&v
))
274 nsAutoString location
;
275 ConvertJSValToStr( location
, cx
, v
);
276 NS_NewURI(getter_AddRefs(baseURL
), location
);
280 PRBool abortLoad
= PR_FALSE
;
282 // parse associative array of installs
283 if ( argc
>= 1 && JSVAL_IS_OBJECT(argv
[0]) && JSVAL_TO_OBJECT(argv
[0]) )
285 nsXPITriggerInfo
*trigger
= new nsXPITriggerInfo();
289 trigger
->SetPrincipal(principal
);
291 JSIdArray
*ida
= JS_Enumerate( cx
, JSVAL_TO_OBJECT(argv
[0]) );
295 const PRUnichar
*name
, *URL
;
296 const PRUnichar
*iconURL
= nsnull
;
299 for (int i
= 0; i
< ida
->length
&& !abortLoad
; i
++ )
301 JS_IdToValue( cx
, ida
->vector
[i
], &v
);
302 JSString
* str
= JS_ValueToString( cx
, v
);
309 name
= reinterpret_cast<const PRUnichar
*>(JS_GetStringChars( str
));
311 URL
= iconURL
= nsnull
;
313 JS_GetUCProperty( cx
, JSVAL_TO_OBJECT(argv
[0]), reinterpret_cast<const jschar
*>(name
), nsCRT::strlen(name
), &v
);
314 if ( JSVAL_IS_OBJECT(v
) && JSVAL_TO_OBJECT(v
) )
317 if (JS_GetProperty( cx
, JSVAL_TO_OBJECT(v
), "URL", &v2
) && !JSVAL_IS_VOID(v2
))
318 URL
= reinterpret_cast<const PRUnichar
*>(JS_GetStringChars( JS_ValueToString( cx
, v2
) ));
320 if (JS_GetProperty( cx
, JSVAL_TO_OBJECT(v
), "IconURL", &v2
) && !JSVAL_IS_VOID(v2
))
321 iconURL
= reinterpret_cast<const PRUnichar
*>(JS_GetStringChars( JS_ValueToString( cx
, v2
) ));
323 if (JS_GetProperty( cx
, JSVAL_TO_OBJECT(v
), "Hash", &v2
) && !JSVAL_IS_VOID(v2
))
324 hash
= reinterpret_cast<const char*>(JS_GetStringBytes( JS_ValueToString( cx
, v2
) ));
328 URL
= reinterpret_cast<const PRUnichar
*>(JS_GetStringChars( JS_ValueToString( cx
, v
) ));
333 // Get relative URL to load
334 nsAutoString
xpiURL(URL
);
337 nsCAutoString resolvedURL
;
338 baseURL
->Resolve(NS_ConvertUTF16toUTF8(xpiURL
), resolvedURL
);
339 xpiURL
= NS_ConvertUTF8toUTF16(resolvedURL
);
342 nsAutoString
icon(iconURL
);
343 if (iconURL
&& baseURL
)
345 nsCAutoString resolvedIcon
;
346 baseURL
->Resolve(NS_ConvertUTF16toUTF8(icon
), resolvedIcon
);
347 icon
= NS_ConvertUTF8toUTF16(resolvedIcon
);
350 // Make sure we're allowed to load this URL and the icon URL
351 nsresult rv
= InstallTriggerCheckLoadURIFromScript(cx
, xpiURL
);
355 if (!abortLoad
&& iconURL
)
357 rv
= InstallTriggerCheckLoadURIFromScript(cx
, icon
);
364 // Add the install item to the trigger collection
365 nsXPITriggerItem
*item
=
366 new nsXPITriggerItem( name
, xpiURL
.get(), icon
.get(), hash
);
369 trigger
->Add( item
);
378 JS_DestroyIdArray( cx
, ida
);
382 // pass on only if good stuff found
383 if (!abortLoad
&& trigger
->Size() > 0)
385 nsCOMPtr
<nsIURI
> checkuri
;
386 nsresult rv
= nativeThis
->GetOriginatingURI(globalObject
,
387 getter_AddRefs(checkuri
));
388 if (NS_SUCCEEDED(rv
))
390 nsCOMPtr
<nsIDOMWindowInternal
> win(do_QueryInterface(globalObject
));
391 nsCOMPtr
<nsIXPIInstallInfo
> installInfo
=
392 new nsXPIInstallInfo(win
, checkuri
, trigger
, 0);
395 // installInfo now owns triggers
396 PRBool enabled
= PR_FALSE
;
397 nativeThis
->UpdateEnabled(checkuri
, XPI_WHITELIST
, &enabled
);
400 nsCOMPtr
<nsIObserverService
> os(do_GetService("@mozilla.org/observer-service;1"));
402 os
->NotifyObservers(installInfo
,
403 "xpinstall-install-blocked",
408 // save callback function if any (ignore bad args for now)
409 if ( argc
>= 2 && JS_TypeOfValue(cx
,argv
[1]) == JSTYPE_FUNCTION
)
411 trigger
->SaveCallback( cx
, argv
[1] );
415 nativeThis
->StartInstall(installInfo
, &result
);
416 *rval
= BOOLEAN_TO_JSVAL(result
);
422 // didn't pass it on so we must delete trigger
426 JS_ReportError(cx
, "Incorrect arguments to InstallTrigger.Install()");
432 // Native method InstallChrome
435 InstallTriggerGlobalInstallChrome(JSContext
*cx
, JSObject
*obj
, uintN argc
, jsval
*argv
, jsval
*rval
)
437 nsIDOMInstallTriggerGlobal
*nativeThis
= getTriggerNative(cx
, obj
);
441 uint32 chromeType
= NOT_CHROME
;
442 nsAutoString sourceURL
;
447 // get chromeType first, the update enabled check for skins skips whitelisting
449 JS_ValueToECMAUint32(cx
, argv
[0], &chromeType
);
451 // make sure XPInstall is enabled, return if not
452 nsIScriptGlobalObject
*globalObject
= nsnull
;
453 nsIScriptContext
*scriptContext
= GetScriptContextFromJSContext(cx
);
455 globalObject
= scriptContext
->GetGlobalObject();
460 // get window.location to construct relative URLs
461 nsCOMPtr
<nsIURI
> baseURL
;
462 JSObject
* global
= JS_GetGlobalObject(cx
);
466 if (JS_GetProperty(cx
,global
,"location",&v
))
468 nsAutoString location
;
469 ConvertJSValToStr( location
, cx
, v
);
470 NS_NewURI(getter_AddRefs(baseURL
), location
);
477 ConvertJSValToStr(sourceURL
, cx
, argv
[1]);
478 ConvertJSValToStr(name
, cx
, argv
[2]);
482 nsCAutoString resolvedURL
;
483 baseURL
->Resolve(NS_ConvertUTF16toUTF8(sourceURL
), resolvedURL
);
484 sourceURL
= NS_ConvertUTF8toUTF16(resolvedURL
);
487 // Make sure caller is allowed to load this url.
488 nsresult rv
= InstallTriggerCheckLoadURIFromScript(cx
, sourceURL
);
492 if ( chromeType
& CHROME_ALL
)
494 // there's at least one known chrome type
495 nsCOMPtr
<nsIURI
> checkuri
;
496 nsresult rv
= nativeThis
->GetOriginatingURI(globalObject
,
497 getter_AddRefs(checkuri
));
498 if (NS_SUCCEEDED(rv
))
500 nsAutoPtr
<nsXPITriggerInfo
> trigger(new nsXPITriggerInfo());
501 nsAutoPtr
<nsXPITriggerItem
> item(new nsXPITriggerItem(name
.get(),
506 // trigger will free item when complete
507 trigger
->Add(item
.forget());
508 nsCOMPtr
<nsIDOMWindowInternal
> win(do_QueryInterface(globalObject
));
509 nsCOMPtr
<nsIXPIInstallInfo
> installInfo
=
510 new nsXPIInstallInfo(win
, checkuri
, trigger
, chromeType
);
513 // installInfo owns trigger now
515 PRBool enabled
= PR_FALSE
;
516 nativeThis
->UpdateEnabled(checkuri
, XPI_WHITELIST
,
520 nsCOMPtr
<nsIObserverService
> os(do_GetService("@mozilla.org/observer-service;1"));
522 os
->NotifyObservers(installInfo
,
523 "xpinstall-install-blocked",
528 PRBool nativeRet
= PR_FALSE
;
529 nativeThis
->StartInstall(installInfo
, &nativeRet
);
530 *rval
= BOOLEAN_TO_JSVAL(nativeRet
);
542 // Native method StartSoftwareUpdate
545 InstallTriggerGlobalStartSoftwareUpdate(JSContext
*cx
, JSObject
*obj
, uintN argc
, jsval
*argv
, jsval
*rval
)
547 nsIDOMInstallTriggerGlobal
*nativeThis
= getTriggerNative(cx
, obj
);
556 nsIScriptGlobalObject
*globalObject
= nsnull
;
557 nsIScriptContext
*scriptContext
= GetScriptContextFromJSContext(cx
);
559 globalObject
= scriptContext
->GetGlobalObject();
564 // get window.location to construct relative URLs
565 nsCOMPtr
<nsIURI
> baseURL
;
566 JSObject
* global
= JS_GetGlobalObject(cx
);
570 if (JS_GetProperty(cx
,global
,"location",&v
))
572 nsAutoString location
;
573 ConvertJSValToStr( location
, cx
, v
);
574 NS_NewURI(getter_AddRefs(baseURL
), location
);
582 ConvertJSValToStr(xpiURL
, cx
, argv
[0]);
585 nsCAutoString resolvedURL
;
586 baseURL
->Resolve(NS_ConvertUTF16toUTF8(xpiURL
), resolvedURL
);
587 xpiURL
= NS_ConvertUTF8toUTF16(resolvedURL
);
590 // Make sure caller is allowed to load this url.
591 nsresult rv
= InstallTriggerCheckLoadURIFromScript(cx
, xpiURL
);
595 if (argc
>= 2 && !JS_ValueToInt32(cx
, argv
[1], (int32
*)&flags
))
597 JS_ReportError(cx
, "StartSoftwareUpdate() 2nd parameter must be a number");
601 nsCOMPtr
<nsIURI
> checkuri
;
602 rv
= nativeThis
->GetOriginatingURI(globalObject
, getter_AddRefs(checkuri
));
603 if (NS_SUCCEEDED(rv
))
605 nsAutoPtr
<nsXPITriggerInfo
> trigger(new nsXPITriggerInfo());
606 nsAutoPtr
<nsXPITriggerItem
> item(new nsXPITriggerItem(0,
611 // trigger will free item when complete
612 trigger
->Add(item
.forget());
613 nsCOMPtr
<nsIDOMWindowInternal
> win(do_QueryInterface(globalObject
));
614 nsCOMPtr
<nsIXPIInstallInfo
> installInfo
=
615 new nsXPIInstallInfo(win
, checkuri
, trigger
, 0);
618 // From here trigger is owned by installInfo until passed on to nsXPInstallManager
620 PRBool enabled
= PR_FALSE
;
621 nativeThis
->UpdateEnabled(checkuri
, XPI_WHITELIST
, &enabled
);
624 nsCOMPtr
<nsIObserverService
> os(do_GetService("@mozilla.org/observer-service;1"));
626 os
->NotifyObservers(installInfo
,
627 "xpinstall-install-blocked",
632 nativeThis
->StartInstall(installInfo
, &nativeRet
);
633 *rval
= BOOLEAN_TO_JSVAL(nativeRet
);
641 JS_ReportError(cx
, "Function StartSoftwareUpdate requires 1 parameters");
650 // InstallTriggerGlobal class methods
652 static JSFunctionSpec InstallTriggerGlobalMethods
[] =
654 {"UpdateEnabled", InstallTriggerGlobalUpdateEnabled
, 0,0,0},
655 {"StartSoftwareUpdate", InstallTriggerGlobalStartSoftwareUpdate
, 2,0,0},
656 {"updateEnabled", InstallTriggerGlobalUpdateEnabled
, 0,0,0},
657 {"enabled", InstallTriggerGlobalUpdateEnabled
, 0,0,0},
658 {"install", InstallTriggerGlobalInstall
, 2,0,0},
659 {"installChrome", InstallTriggerGlobalInstallChrome
, 2,0,0},
660 {"startSoftwareUpdate", InstallTriggerGlobalStartSoftwareUpdate
, 2,0,0},
661 {nsnull
,nsnull
,0,0,0}
665 static JSConstDoubleSpec diff_constants
[] =
667 { nsIDOMInstallTriggerGlobal::MAJOR_DIFF
, "MAJOR_DIFF" },
668 { nsIDOMInstallTriggerGlobal::MINOR_DIFF
, "MINOR_DIFF" },
669 { nsIDOMInstallTriggerGlobal::REL_DIFF
, "REL_DIFF" },
670 { nsIDOMInstallTriggerGlobal::BLD_DIFF
, "BLD_DIFF" },
671 { nsIDOMInstallTriggerGlobal::EQUAL
, "EQUAL" },
672 { nsIDOMInstallTriggerGlobal::NOT_FOUND
, "NOT_FOUND" },
673 { CHROME_SKIN
, "SKIN" },
674 { CHROME_LOCALE
, "LOCALE" },
675 { CHROME_CONTENT
, "CONTENT" },
676 { CHROME_ALL
, "PACKAGE" },
682 nsresult
InitInstallTriggerGlobalClass(JSContext
*jscontext
, JSObject
*global
, void** prototype
)
684 JSObject
*proto
= nsnull
;
686 if (prototype
!= nsnull
)
689 proto
= JS_InitClass(jscontext
, // context
690 global
, // global object
691 nsnull
, // parent proto
692 &InstallTriggerGlobalClass
, // JSClass
693 nsnull
, // JSNative ctor
695 nsnull
, // proto props
696 nsnull
, // proto funcs
697 nsnull
, // ctor props (static)
698 InstallTriggerGlobalMethods
); // ctor funcs (static)
701 if (nsnull
== proto
) return NS_ERROR_FAILURE
;
703 if ( PR_FALSE
== JS_DefineConstDoubles(jscontext
, proto
, diff_constants
) )
704 return NS_ERROR_FAILURE
;
706 if (prototype
!= nsnull
)
715 // InstallTriggerGlobal class initialization
717 nsresult
NS_InitInstallTriggerGlobalClass(nsIScriptContext
*aContext
, void **aPrototype
)
719 JSContext
*jscontext
= (JSContext
*)aContext
->GetNativeContext();
720 JSObject
*proto
= nsnull
;
721 JSObject
*constructor
= nsnull
;
722 JSObject
*global
= JS_GetGlobalObject(jscontext
);
725 if ((PR_TRUE
!= JS_LookupProperty(jscontext
, global
, "InstallTriggerGlobal", &vp
)) ||
726 !JSVAL_IS_OBJECT(vp
) ||
727 ((constructor
= JSVAL_TO_OBJECT(vp
)) == nsnull
) ||
728 (PR_TRUE
!= JS_LookupProperty(jscontext
, JSVAL_TO_OBJECT(vp
), "prototype", &vp
)) ||
729 !JSVAL_IS_OBJECT(vp
))
731 nsresult rv
= InitInstallTriggerGlobalClass(jscontext
, global
, (void**)&proto
);
732 if (NS_FAILED(rv
)) return rv
;
734 else if ((nsnull
!= constructor
) && JSVAL_IS_OBJECT(vp
))
736 proto
= JSVAL_TO_OBJECT(vp
);
740 return NS_ERROR_FAILURE
;
751 // Method for creating a new InstallTriggerGlobal JavaScript object
754 NS_NewScriptInstallTriggerGlobal(nsIScriptContext
*aContext
,
755 nsISupports
*aSupports
, nsISupports
*aParent
,
758 NS_PRECONDITION(nsnull
!= aContext
&& nsnull
!= aSupports
&&
760 "null argument to NS_NewScriptInstallTriggerGlobal");
763 JSObject
*parent
= nsnull
;
764 JSContext
*jscontext
= (JSContext
*)aContext
->GetNativeContext();
765 nsresult result
= NS_OK
;
766 nsIDOMInstallTriggerGlobal
*installTriggerGlobal
;
768 nsCOMPtr
<nsIScriptObjectOwner
> owner(do_QueryInterface(aParent
));
771 if (NS_OK
!= owner
->GetScriptObject(aContext
, (void **)&parent
)) {
772 return NS_ERROR_FAILURE
;
775 nsCOMPtr
<nsIScriptGlobalObject
> sgo(do_QueryInterface(aParent
));
778 parent
= sgo
->GetGlobalJSObject();
780 return NS_ERROR_FAILURE
;
784 if (NS_OK
!= NS_InitInstallTriggerGlobalClass(aContext
, (void **)&proto
)) {
785 return NS_ERROR_FAILURE
;
788 result
= CallQueryInterface(aSupports
, &installTriggerGlobal
);
789 if (NS_OK
!= result
) {
793 // create a js object for this class
794 *aReturn
= JS_NewObject(jscontext
, &InstallTriggerGlobalClass
, proto
, parent
);
795 if (nsnull
!= *aReturn
) {
796 // connect the native object to the js object
797 JS_SetPrivate(jscontext
, (JSObject
*)*aReturn
, installTriggerGlobal
);
800 NS_RELEASE(installTriggerGlobal
);
801 return NS_ERROR_FAILURE
;