зеркало из https://github.com/mozilla/gecko-dev.git
Fixes 293331. r=dveditz, sr=jst, a=chase
This commit is contained in:
Родитель
ffc365fb08
Коммит
bcc5146681
|
@ -240,13 +240,13 @@ InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *arg
|
|||
if (nsnull == nativeThis && (JS_FALSE == CreateNativeObject(cx, obj, &nativeThis)) )
|
||||
return JS_TRUE;
|
||||
|
||||
|
||||
|
||||
// make sure XPInstall is enabled, return false if not
|
||||
nsIScriptGlobalObject *globalObject = nsnull;
|
||||
nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
|
||||
if (scriptContext)
|
||||
globalObject = scriptContext->GetGlobalObject();
|
||||
|
||||
globalObject = scriptContext->GetGlobalObject();
|
||||
|
||||
PRBool enabled = PR_FALSE;
|
||||
nativeThis->UpdateEnabled(globalObject, XPI_WHITELIST, &enabled);
|
||||
if (!enabled || !globalObject)
|
||||
|
@ -262,6 +262,21 @@ InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *arg
|
|||
}
|
||||
|
||||
|
||||
nsCOMPtr<nsIScriptSecurityManager> secman(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID));
|
||||
if (!secman)
|
||||
{
|
||||
JS_ReportError(cx, "Could not the script security manager service.");
|
||||
return JS_FALSE;
|
||||
}
|
||||
// get the principal. if it doesn't exist, die.
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
secman->GetSubjectPrincipal(getter_AddRefs(principal));
|
||||
if (!principal)
|
||||
{
|
||||
JS_ReportError(cx, "Could not get the Subject Principal during InstallTrigger.Install()");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
// get window.location to construct relative URLs
|
||||
nsCOMPtr<nsIURI> baseURL;
|
||||
JSObject* global = JS_GetGlobalObject(cx);
|
||||
|
@ -285,6 +300,8 @@ InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *arg
|
|||
if (!trigger)
|
||||
return JS_FALSE;
|
||||
|
||||
trigger->SetPrincipal(principal);
|
||||
|
||||
JSIdArray *ida = JS_Enumerate( cx, JSVAL_TO_OBJECT(argv[0]) );
|
||||
if ( ida )
|
||||
{
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIJSContextStack.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
|
||||
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
|
||||
|
@ -235,6 +236,32 @@ static void* handleTriggerEvent(XPITriggerEvent* event)
|
|||
do_GetService("@mozilla.org/js/xpc/ContextStack;1");
|
||||
if (stack)
|
||||
stack->Push(event->cx);
|
||||
|
||||
nsCOMPtr<nsIScriptSecurityManager> secman =
|
||||
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
|
||||
|
||||
if (!secman)
|
||||
{
|
||||
JS_ReportError(event->cx, "Could not get script security manager service");
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
secman->GetSubjectPrincipal(getter_AddRefs(principal));
|
||||
if (!principal)
|
||||
{
|
||||
JS_ReportError(event->cx, "Could not get principal from script security manager");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRBool equals = PR_FALSE;
|
||||
principal->Equals(event->princ, &equals);
|
||||
|
||||
if (!equals)
|
||||
{
|
||||
JS_ReportError(event->cx, "Principal of callback context is different then InstallTriggers");
|
||||
return 0;
|
||||
}
|
||||
|
||||
JS_CallFunctionValue( event->cx,
|
||||
JSVAL_TO_OBJECT(event->global),
|
||||
|
@ -279,6 +306,7 @@ void nsXPITriggerInfo::SendStatus(const PRUnichar* URL, PRInt32 status)
|
|||
event->URL = URL;
|
||||
event->status = status;
|
||||
event->cx = mCx;
|
||||
event->princ = mPrincipal;
|
||||
|
||||
JSObject *obj = nsnull;
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ typedef struct XPITriggerEvent {
|
|||
jsval global;
|
||||
jsval cbval;
|
||||
nsCOMPtr<nsISupports> ref;
|
||||
nsCOMPtr<nsIPrincipal> princ;
|
||||
} XPITriggerEvent;
|
||||
|
||||
|
||||
|
@ -83,13 +84,13 @@ class nsXPITriggerItem
|
|||
nsCOMPtr<nsIOutputStream> mOutStream;
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
|
||||
void SetPrincipal(nsIPrincipal* aPrincipal);
|
||||
|
||||
PRBool IsFileURL() { return StringBeginsWith(mURL, NS_LITERAL_STRING("file:/")); }
|
||||
PRBool IsRelativeURL();
|
||||
|
||||
const PRUnichar* GetSafeURLString();
|
||||
|
||||
void SetPrincipal(nsIPrincipal* aPrincipal);
|
||||
private:
|
||||
//-- prevent inadvertent copies and assignments
|
||||
nsXPITriggerItem& operator=(const nsXPITriggerItem& rhs);
|
||||
|
@ -118,6 +119,9 @@ class nsXPITriggerInfo
|
|||
|
||||
void SendStatus(const PRUnichar* URL, PRInt32 status);
|
||||
|
||||
void SetPrincipal(nsIPrincipal* aPrinc) { mPrincipal = aPrinc; }
|
||||
|
||||
|
||||
private:
|
||||
nsVoidArray mItems;
|
||||
JSContext *mCx;
|
||||
|
@ -125,6 +129,8 @@ class nsXPITriggerInfo
|
|||
jsval mCbval;
|
||||
PRThread* mThread;
|
||||
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
|
||||
//-- prevent inadvertent copies and assignments
|
||||
nsXPITriggerInfo& operator=(const nsXPITriggerInfo& rhs);
|
||||
nsXPITriggerInfo(const nsXPITriggerInfo& rhs);
|
||||
|
|
Загрузка…
Ссылка в новой задаче