first hack to get relative URLS working in triggers

This commit is contained in:
dveditz%netscape.com 1999-11-22 12:01:19 +00:00
Родитель cea3644efe
Коммит 705f624786
3 изменённых файлов: 39 добавлений и 0 удалений

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

@ -148,12 +148,32 @@ InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *arg
if (nsnull == nativeThis && (JS_FALSE == CreateNativeObject(cx, obj, &nativeThis)) ) if (nsnull == nativeThis && (JS_FALSE == CreateNativeObject(cx, obj, &nativeThis)) )
return JS_FALSE; return JS_FALSE;
// make sure XPInstall is enabled, return false if not // make sure XPInstall is enabled, return false if not
PRBool enabled = PR_FALSE; PRBool enabled = PR_FALSE;
nativeThis->UpdateEnabled(&enabled); nativeThis->UpdateEnabled(&enabled);
if (!enabled) if (!enabled)
return JS_TRUE; return JS_TRUE;
// get window.location to construct relative URLs
nsString baseURL;
JSObject* global = JS_GetGlobalObject(cx);
if (global)
{
jsval v;
if (JS_GetProperty(cx,global,"location",&v))
{
ConvertJSValToStr( baseURL, cx, v );
PRInt32 lastslash = baseURL.RFindChar('/');
if (lastslash != kNotFound)
{
baseURL.Truncate(lastslash+1);
}
}
}
// parse associative array of installs // parse associative array of installs
if ( argc >= 1 && JSVAL_IS_OBJECT(argv[0]) ) if ( argc >= 1 && JSVAL_IS_OBJECT(argv[0]) )
{ {
@ -179,7 +199,13 @@ InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *arg
{ {
nsXPITriggerItem *item = new nsXPITriggerItem( name, URL ); nsXPITriggerItem *item = new nsXPITriggerItem( name, URL );
if ( item ) if ( item )
{
if ( item->IsRelativeURL() )
{
item->mURL.Insert( baseURL, 0 );
}
trigger->Add( item ); trigger->Add( item );
}
else else
; // XXX signal error somehow ; // XXX signal error somehow
} }
@ -189,12 +215,14 @@ InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *arg
JS_DestroyIdArray( cx, ida ); JS_DestroyIdArray( cx, ida );
} }
// save callback function if any (ignore bad args for now) // save callback function if any (ignore bad args for now)
if ( argc >= 2 && JS_TypeOfValue(cx,argv[1]) == JSTYPE_FUNCTION ) if ( argc >= 2 && JS_TypeOfValue(cx,argv[1]) == JSTYPE_FUNCTION )
{ {
trigger->SaveCallback( cx, argv[1] ); trigger->SaveCallback( cx, argv[1] );
} }
// pass on only if good stuff found // pass on only if good stuff found
if (trigger->Size() > 0) if (trigger->Size() > 0)
{ {

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

@ -63,6 +63,16 @@ nsXPITriggerItem::~nsXPITriggerItem()
MOZ_COUNT_DTOR(nsXPITriggerItem); MOZ_COUNT_DTOR(nsXPITriggerItem);
} }
PRBool nsXPITriggerItem::IsRelativeURL()
{
PRInt32 cpos = mURL.FindChar(':');
if (cpos == kNotFound)
return PR_TRUE;
PRInt32 spos = mURL.FindChar('/');
return (cpos > spos);
}
// //
// nsXPITriggerInfo // nsXPITriggerInfo

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

@ -62,6 +62,7 @@ class nsXPITriggerItem
nsCOMPtr<nsIFileSpec> mFile; nsCOMPtr<nsIFileSpec> mFile;
PRBool IsFileURL() { return mURL.Equals("file:/",PR_FALSE,6); } PRBool IsFileURL() { return mURL.Equals("file:/",PR_FALSE,6); }
PRBool IsRelativeURL();
private: private:
//-- prevent inadvertent copies and assignments //-- prevent inadvertent copies and assignments