nsDocShell now implements nsIScriptContextOwner.

This commit is contained in:
tbogard%aol.net 1999-11-30 01:06:59 +00:00
Родитель 8a6d48f576
Коммит 2ba249643b
2 изменённых файлов: 104 добавлений и 3 удалений

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

@ -108,6 +108,7 @@ NS_INTERFACE_MAP_BEGIN(nsDocShell)
NS_INTERFACE_MAP_ENTRY(nsIScrollable) NS_INTERFACE_MAP_ENTRY(nsIScrollable)
NS_INTERFACE_MAP_ENTRY(nsITextScroll) NS_INTERFACE_MAP_ENTRY(nsITextScroll)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY(nsIScriptContextOwner)
NS_INTERFACE_MAP_END NS_INTERFACE_MAP_END
//***************************************************************************** //*****************************************************************************
@ -1428,6 +1429,84 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID& aIID, void** aSink)
return NS_OK; return NS_OK;
} }
//*****************************************************************************
// nsDocShell::nsIScriptContextOwner
//*****************************************************************************
NS_IMETHODIMP nsDocShell::GetScriptContext(nsIScriptContext** aContext)
{
NS_ENSURE_ARG_POINTER(aContext);
NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE);
*aContext = mScriptContext;
NS_IF_ADDREF(*aContext);
return NS_OK;
}
NS_IMETHODIMP nsDocShell::GetScriptGlobalObject(nsIScriptGlobalObject** aGlobal)
{
NS_ENSURE_ARG_POINTER(aGlobal);
NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE);
*aGlobal = mScriptContext->GetGlobalObject();
NS_IF_ADDREF(*aGlobal);
return NS_OK;
}
NS_IMETHODIMP nsDocShell::ReleaseScriptContext(nsIScriptContext *aContext)
{
NS_IF_RELEASE(aContext);
mScriptContext = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsDocShell::ReportScriptError(const char* aErrorString,
const char* aFileName, PRInt32 aLineNo, const char* aLineBuf)
{
//XXX Needs some international work.
nsAutoString error;
error.SetString("JavaScript Error: ");
error.Append(aErrorString);
error += "\n";
if(aFileName)
{
error += "URL: ";
error += aFileName;
error += "\n";
}
if(aLineNo)
{
error += "LineNo: ";
error.Append(aLineNo, 10);
error += "\n";
}
if(aLineBuf)
{
error += "Line text: '";
error += aLineBuf;
error += "'\n";
}
// XXX Should not do a printf
char* errorStr = error.ToNewCString();
if(errorStr)
{
printf("%s\n", errorStr);
nsCRT::free(errorStr);
}
//XXXEMBEDDING Call embedding app with the error.
// XXX Turn it off for now...there should be an Error method too
//Alert(error.GetUnicode());
return NS_OK;
}
//***************************************************************************** //*****************************************************************************
// nsDocShell::nsIContentViewerContainer // nsDocShell::nsIContentViewerContainer
//***************************************************************************** //*****************************************************************************
@ -1584,6 +1663,27 @@ nsresult nsDocShell::EnsureContentListener()
return NS_OK; return NS_OK;
} }
nsresult nsDocShell::EnsureScriptEnvironment()
{
if(mScriptContext)
return NS_OK;
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
NS_ENSURE_SUCCESS(NS_NewScriptGlobalObject(getter_AddRefs(scriptGlobalObject)),
NS_ERROR_FAILURE);
//XXXWEBSHELL
//mScriptGlobal->SetDocShell(NS_STATIC_CAST(nsIDocShell*, this));
NS_ENSURE_SUCCESS(NS_CreateScriptContext(scriptGlobalObject,
getter_AddRefs(mScriptContext)), NS_ERROR_FAILURE);
mScriptContext->SetOwner(NS_STATIC_CAST(nsIScriptContextOwner*, this));
return NS_OK;
}
void nsDocShell::SetCurrentURI(nsIURI* aUri) void nsDocShell::SetCurrentURI(nsIURI* aUri)
{ {
mCurrentURI = aUri; //This assignment addrefs mCurrentURI = aUri; //This assignment addrefs

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

@ -65,7 +65,8 @@ class nsDocShell : public nsIDocShell,
public nsIScrollable, public nsIScrollable,
public nsITextScroll, public nsITextScroll,
public nsIContentViewerContainer, public nsIContentViewerContainer,
public nsIInterfaceRequestor public nsIInterfaceRequestor,
public nsIScriptContextOwner
{ {
friend class nsDSURIContentListener; friend class nsDSURIContentListener;
@ -78,6 +79,7 @@ public:
NS_DECL_NSISCROLLABLE NS_DECL_NSISCROLLABLE
NS_DECL_NSITEXTSCROLL NS_DECL_NSITEXTSCROLL
NS_DECL_NSIINTERFACEREQUESTOR NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSISCRIPTCONTEXTOWNER
// XXX: move to a macro // XXX: move to a macro
// nsIContentViewerContainer // nsIContentViewerContainer
@ -93,8 +95,6 @@ public:
static NS_METHOD Create(nsISupports* aOuter, const nsIID& aIID, void** ppv); static NS_METHOD Create(nsISupports* aOuter, const nsIID& aIID, void** ppv);
protected: protected:
nsDocShell(); nsDocShell();
virtual ~nsDocShell(); virtual ~nsDocShell();
@ -104,6 +104,7 @@ protected:
PRInt32* aOffset); PRInt32* aOffset);
nsresult GetRootScrollableView(nsIScrollableView** aOutScrollView); nsresult GetRootScrollableView(nsIScrollableView** aOutScrollView);
nsresult EnsureContentListener(); nsresult EnsureContentListener();
nsresult EnsureScriptEnvironment();
void SetCurrentURI(nsIURI* aUri); void SetCurrentURI(nsIURI* aUri);
nsresult CreateContentViewer(const char* aContentType, const char* aCommand, nsresult CreateContentViewer(const char* aContentType, const char* aCommand,