1998-07-16 01:16:47 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
|
1999-05-15 00:48:39 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-07-24 05:05:42 +00:00
|
|
|
#include "nsGlobalWindow.h"
|
1998-07-16 01:16:47 +00:00
|
|
|
#include "nscore.h"
|
1998-10-01 22:21:59 +00:00
|
|
|
#include "nsRect.h"
|
1998-07-24 05:05:42 +00:00
|
|
|
#include "nslayout.h"
|
1998-07-16 01:16:47 +00:00
|
|
|
#include "prmem.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
#include "plstr.h"
|
|
|
|
#include "prinrval.h"
|
|
|
|
#include "nsIFactory.h"
|
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
1998-09-17 00:55:35 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1998-07-16 01:16:47 +00:00
|
|
|
#include "nsITimer.h"
|
1998-07-24 05:05:42 +00:00
|
|
|
#include "nsEventListenerManager.h"
|
|
|
|
#include "nsIEventStateManager.h"
|
|
|
|
#include "nsDOMEvent.h"
|
1999-06-09 19:04:18 +00:00
|
|
|
#include "nsIDOMBarProp.h"
|
1998-07-24 05:05:42 +00:00
|
|
|
#include "nsIDOMMouseListener.h"
|
|
|
|
#include "nsIDOMKeyListener.h"
|
|
|
|
#include "nsIDOMMouseMotionListener.h"
|
1998-08-13 23:37:54 +00:00
|
|
|
#include "nsIDOMFocusListener.h"
|
|
|
|
#include "nsIDOMFormListener.h"
|
|
|
|
#include "nsIDOMLoadListener.h"
|
|
|
|
#include "nsIDOMDragListener.h"
|
1998-10-06 20:59:39 +00:00
|
|
|
#include "nsIDOMPaintListener.h"
|
1999-06-11 23:57:25 +00:00
|
|
|
#include "nsJSUtils.h"
|
1998-07-24 05:05:42 +00:00
|
|
|
#include "nsIScriptEventListener.h"
|
|
|
|
#include "nsIPrivateDOMEvent.h"
|
1998-08-07 04:45:03 +00:00
|
|
|
#include "nsIBrowserWindow.h"
|
|
|
|
#include "nsIWebShell.h"
|
|
|
|
#include "nsIScriptContextOwner.h"
|
1998-09-03 01:19:58 +00:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIURL.h"
|
1999-04-28 20:33:43 +00:00
|
|
|
#include "nsIPref.h"
|
1998-08-07 04:45:03 +00:00
|
|
|
#include "nsCRT.h"
|
1998-10-01 22:21:59 +00:00
|
|
|
#include "nsRect.h"
|
1999-07-01 19:38:49 +00:00
|
|
|
#ifdef NECKO
|
|
|
|
#include "nsIPrompt.h"
|
|
|
|
#else
|
1998-11-24 07:44:39 +00:00
|
|
|
#include "nsINetSupport.h"
|
1999-06-23 03:29:44 +00:00
|
|
|
#endif
|
1999-01-27 04:15:19 +00:00
|
|
|
#include "nsIContentViewer.h"
|
1999-07-02 19:43:26 +00:00
|
|
|
#include "nsIDocumentViewer.h"
|
|
|
|
#include "nsIPresShell.h"
|
1999-01-28 23:12:54 +00:00
|
|
|
#include "nsScreen.h"
|
|
|
|
#include "nsHistory.h"
|
1999-06-09 19:04:18 +00:00
|
|
|
#include "nsBarProps.h"
|
1999-07-07 07:50:03 +00:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
#ifndef NECKO
|
|
|
|
#include "nsINetService.h"
|
|
|
|
#else
|
|
|
|
#include "nsIIOService.h"
|
1999-06-23 03:29:44 +00:00
|
|
|
#include "nsIURL.h"
|
1999-07-11 15:46:10 +00:00
|
|
|
#include "nsNeckoUtil.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
|
|
|
#endif // NECKO
|
1998-07-16 01:16:47 +00:00
|
|
|
|
1999-05-08 16:37:53 +00:00
|
|
|
#if defined(OJI)
|
|
|
|
#include "nsIJVMManager.h"
|
|
|
|
#endif
|
|
|
|
|
1999-04-20 19:41:17 +00:00
|
|
|
#include "nsMimeTypeArray.h"
|
|
|
|
#include "nsPluginArray.h"
|
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
#include "jsapi.h"
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
|
1999-07-07 07:50:03 +00:00
|
|
|
static NS_DEFINE_IID(kIScriptGlobalObjectDataIID, NS_ISCRIPTGLOBALOBJECTDATA_IID);
|
1998-07-16 01:16:47 +00:00
|
|
|
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
1998-07-24 05:05:42 +00:00
|
|
|
static NS_DEFINE_IID(kIScriptEventListenerIID, NS_ISCRIPTEVENTLISTENER_IID);
|
1998-07-16 01:16:47 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMWindowIID, NS_IDOMWINDOW_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMNavigatorIID, NS_IDOMNAVIGATOR_IID);
|
1998-07-24 05:05:42 +00:00
|
|
|
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMMouseMotionListenerIID, NS_IDOMMOUSEMOTIONLISTENER_IID);
|
1998-08-13 23:37:54 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMFocusListenerIID, NS_IDOMFOCUSLISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMFormListenerIID, NS_IDOMFORMLISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMLoadListenerIID, NS_IDOMLOADLISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMDragListenerIID, NS_IDOMDRAGLISTENER_IID);
|
1998-10-06 20:59:39 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMPaintListenerIID, NS_IDOMPAINTLISTENER_IID);
|
1998-07-24 05:05:42 +00:00
|
|
|
static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
|
|
|
|
static NS_DEFINE_IID(kIPrivateDOMEventIID, NS_IPRIVATEDOMEVENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMEventCapturerIID, NS_IDOMEVENTCAPTURER_IID);
|
1998-07-31 22:09:03 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
|
1999-03-28 22:19:42 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMEventTargetIID, NS_IDOMEVENTTARGET_IID);
|
1998-08-07 04:45:03 +00:00
|
|
|
static NS_DEFINE_IID(kIBrowserWindowIID, NS_IBROWSER_WINDOW_IID);
|
|
|
|
static NS_DEFINE_IID(kIScriptContextOwnerIID, NS_ISCRIPTCONTEXTOWNER_IID);
|
1998-09-03 01:19:58 +00:00
|
|
|
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
1999-07-02 19:43:26 +00:00
|
|
|
static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID);
|
1999-06-18 17:34:08 +00:00
|
|
|
#ifndef NECKO
|
1999-06-23 03:29:44 +00:00
|
|
|
static NS_DEFINE_IID(kINetSupportIID, NS_INETSUPPORT_IID);
|
1998-09-17 00:55:35 +00:00
|
|
|
static NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID);
|
|
|
|
static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID);
|
1999-06-18 17:34:08 +00:00
|
|
|
#endif // NECKO
|
1998-07-16 01:16:47 +00:00
|
|
|
|
1999-04-28 20:33:43 +00:00
|
|
|
static NS_DEFINE_IID(kIPrefIID, NS_IPREF_IID);
|
|
|
|
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
GlobalWindowImpl::GlobalWindowImpl()
|
|
|
|
{
|
1998-07-21 16:41:42 +00:00
|
|
|
NS_INIT_REFCNT();
|
1998-07-16 01:16:47 +00:00
|
|
|
mContext = nsnull;
|
|
|
|
mScriptObject = nsnull;
|
|
|
|
mDocument = nsnull;
|
|
|
|
mNavigator = nsnull;
|
1999-01-28 23:12:54 +00:00
|
|
|
mScreen = nsnull;
|
|
|
|
mHistory = nsnull;
|
1999-06-09 19:04:18 +00:00
|
|
|
mMenubar = nsnull;
|
|
|
|
mToolbar = nsnull;
|
|
|
|
mLocationbar = nsnull;
|
|
|
|
mPersonalbar = nsnull;
|
|
|
|
mStatusbar = nsnull;
|
|
|
|
mScrollbars = nsnull;
|
1998-08-13 04:34:53 +00:00
|
|
|
mLocation = nsnull;
|
1998-08-21 21:39:27 +00:00
|
|
|
mFrames = nsnull;
|
1998-09-03 01:19:58 +00:00
|
|
|
mOpener = nsnull;
|
1999-07-07 07:50:03 +00:00
|
|
|
mPrincipals = nsnull;
|
1998-07-16 01:16:47 +00:00
|
|
|
|
|
|
|
mTimeouts = nsnull;
|
|
|
|
mTimeoutInsertionPoint = nsnull;
|
|
|
|
mRunningTimeout = nsnull;
|
|
|
|
mTimeoutPublicIdCounter = 1;
|
1998-07-24 05:05:42 +00:00
|
|
|
mListenerManager = nsnull;
|
1999-05-17 18:52:21 +00:00
|
|
|
|
1999-05-17 21:39:35 +00:00
|
|
|
mFirstDocumentLoad = PR_TRUE;
|
1999-05-27 21:06:51 +00:00
|
|
|
|
|
|
|
mChromeDocument = nsnull;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GlobalWindowImpl::~GlobalWindowImpl()
|
1999-06-15 03:17:11 +00:00
|
|
|
{
|
1999-07-07 07:50:03 +00:00
|
|
|
if (mPrincipals && mContext) {
|
|
|
|
JSPRINCIPALS_DROP((JSContext*)mContext->GetNativeContext(), mPrincipals);
|
|
|
|
}
|
|
|
|
|
1998-09-03 01:19:58 +00:00
|
|
|
NS_IF_RELEASE(mContext);
|
|
|
|
NS_IF_RELEASE(mDocument);
|
1998-07-16 01:16:47 +00:00
|
|
|
NS_IF_RELEASE(mNavigator);
|
1999-01-28 23:12:54 +00:00
|
|
|
NS_IF_RELEASE(mScreen);
|
|
|
|
NS_IF_RELEASE(mHistory);
|
1999-06-09 19:04:18 +00:00
|
|
|
NS_IF_RELEASE(mMenubar);
|
|
|
|
NS_IF_RELEASE(mToolbar);
|
|
|
|
NS_IF_RELEASE(mLocationbar);
|
|
|
|
NS_IF_RELEASE(mPersonalbar);
|
|
|
|
NS_IF_RELEASE(mStatusbar);
|
|
|
|
NS_IF_RELEASE(mScrollbars);
|
1998-08-13 04:34:53 +00:00
|
|
|
NS_IF_RELEASE(mLocation);
|
1998-08-21 21:39:27 +00:00
|
|
|
NS_IF_RELEASE(mFrames);
|
1998-09-03 01:19:58 +00:00
|
|
|
NS_IF_RELEASE(mOpener);
|
1998-07-24 05:05:42 +00:00
|
|
|
NS_IF_RELEASE(mListenerManager);
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(GlobalWindowImpl)
|
|
|
|
NS_IMPL_RELEASE(GlobalWindowImpl)
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GlobalWindowImpl::QueryInterface(const nsIID& aIID,
|
|
|
|
void** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIScriptGlobalObjectIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIScriptGlobalObject*)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-07-07 07:50:03 +00:00
|
|
|
if (aIID.Equals(kIScriptGlobalObjectDataIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIScriptGlobalObjectData*)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-07-16 01:16:47 +00:00
|
|
|
if (aIID.Equals(kIDOMWindowIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIDOMWindow*)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
|
|
*aInstancePtrResult = (void*)(nsISupports*)(nsIScriptGlobalObject*)this;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-07-24 05:05:42 +00:00
|
|
|
if (aIID.Equals(kIJSScriptObjectIID)) {
|
|
|
|
*aInstancePtrResult = (void*)(nsISupports*)(nsIJSScriptObject*)this;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDOMEventCapturerIID)) {
|
|
|
|
*aInstancePtrResult = (void*)(nsISupports*)(nsIDOMEventCapturer*)this;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-07-31 22:09:03 +00:00
|
|
|
if (aIID.Equals(kIDOMEventReceiverIID)) {
|
|
|
|
*aInstancePtrResult = (void*)(nsISupports*)(nsIDOMEventReceiver*)this;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-03-28 22:19:42 +00:00
|
|
|
if (aIID.Equals(kIDOMEventTargetIID)) {
|
|
|
|
*aInstancePtrResult = (void*)(nsISupports*)(nsIDOMEventTarget*)this;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-07-16 01:16:47 +00:00
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1998-09-17 01:53:52 +00:00
|
|
|
GlobalWindowImpl::SetScriptObject(void *aScriptObject)
|
1998-07-16 01:16:47 +00:00
|
|
|
{
|
1998-09-17 01:53:52 +00:00
|
|
|
mScriptObject = aScriptObject;
|
1998-07-16 01:16:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GlobalWindowImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
|
|
|
|
nsresult res = NS_OK;
|
|
|
|
if (nsnull == mScriptObject) {
|
1998-07-21 16:41:42 +00:00
|
|
|
res = NS_NewScriptWindow(aContext, (nsIDOMWindow*)this,
|
|
|
|
nsnull, &mScriptObject);
|
1998-08-20 22:25:21 +00:00
|
|
|
aContext->AddNamedReference(&mScriptObject, mScriptObject,
|
|
|
|
"window_object");
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*aScriptObject = mScriptObject;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
GlobalWindowImpl::SetContext(nsIScriptContext *aContext)
|
|
|
|
{
|
|
|
|
if (mContext) {
|
|
|
|
NS_RELEASE(mContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
mContext = aContext;
|
|
|
|
NS_ADDREF(mContext);
|
|
|
|
}
|
|
|
|
|
1999-05-14 03:10:51 +00:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
GlobalWindowImpl::GetContext(nsIScriptContext **aContext)
|
|
|
|
{
|
|
|
|
*aContext = mContext;
|
|
|
|
NS_IF_ADDREF(*aContext);
|
|
|
|
}
|
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
GlobalWindowImpl::SetNewDocument(nsIDOMDocument *aDocument)
|
|
|
|
{
|
1999-05-17 21:39:35 +00:00
|
|
|
if (mFirstDocumentLoad) {
|
|
|
|
mFirstDocumentLoad = PR_FALSE;
|
1999-05-17 18:52:21 +00:00
|
|
|
mDocument = aDocument;
|
|
|
|
NS_IF_ADDREF(mDocument);
|
|
|
|
return;
|
|
|
|
}
|
1999-06-15 03:17:11 +00:00
|
|
|
|
1999-07-27 20:51:39 +00:00
|
|
|
if (mDocument) {
|
|
|
|
nsIDocument* doc;
|
|
|
|
nsIURI* docURL = 0;
|
|
|
|
|
|
|
|
if (mDocument && NS_SUCCEEDED(mDocument->QueryInterface(kIDocumentIID, (void**)&doc))) {
|
|
|
|
docURL = doc->GetDocumentURL();
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (docURL) {
|
|
|
|
#ifdef NECKO
|
|
|
|
char* str;
|
|
|
|
docURL->GetSpec(&str);
|
|
|
|
#else
|
|
|
|
PRUnichar* str;
|
|
|
|
docURL->ToString(&str);
|
|
|
|
#endif
|
|
|
|
nsAutoString url = str;
|
|
|
|
|
|
|
|
//about:blank URL's do not have ClearScope called on page change.
|
|
|
|
if (url != "about:blank") {
|
|
|
|
ClearAllTimeouts();
|
1999-06-15 03:17:11 +00:00
|
|
|
|
1999-07-27 20:51:39 +00:00
|
|
|
if (mListenerManager) {
|
|
|
|
mListenerManager->RemoveAllListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((nsnull != mScriptObject) &&
|
|
|
|
(nsnull != mContext) /* &&
|
|
|
|
(nsnull != aDocument) XXXbe why commented out? */ ) {
|
|
|
|
JS_ClearScope((JSContext *)mContext->GetNativeContext(),
|
|
|
|
(JSObject *)mScriptObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef NECKO
|
|
|
|
nsCRT::free(str);
|
|
|
|
#else
|
|
|
|
delete[] str;
|
|
|
|
#endif
|
|
|
|
}
|
1999-07-19 19:54:34 +00:00
|
|
|
}
|
|
|
|
|
1999-07-27 20:51:39 +00:00
|
|
|
//XXX Should this be outside the about:blank clearscope exception?
|
1999-07-07 07:50:03 +00:00
|
|
|
if (mPrincipals && mContext) {
|
|
|
|
JSPRINCIPALS_DROP((JSContext *)mContext->GetNativeContext(), mPrincipals);
|
|
|
|
mPrincipals = nsnull;
|
|
|
|
}
|
|
|
|
|
1999-06-15 03:17:11 +00:00
|
|
|
if (nsnull != mDocument) {
|
1998-07-16 01:16:47 +00:00
|
|
|
NS_RELEASE(mDocument);
|
1999-06-15 03:17:11 +00:00
|
|
|
}
|
1999-04-02 06:22:00 +00:00
|
|
|
|
1999-06-15 03:17:11 +00:00
|
|
|
if (nsnull != mContext) {
|
1999-04-02 06:22:00 +00:00
|
|
|
mContext->GC();
|
1999-06-15 03:17:11 +00:00
|
|
|
}
|
1998-07-16 01:16:47 +00:00
|
|
|
|
|
|
|
mDocument = aDocument;
|
|
|
|
|
|
|
|
if (nsnull != mDocument) {
|
|
|
|
NS_ADDREF(mDocument);
|
|
|
|
|
|
|
|
if (nsnull != mContext) {
|
|
|
|
mContext->InitContext(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-07 04:45:03 +00:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
GlobalWindowImpl::SetWebShell(nsIWebShell *aWebShell)
|
|
|
|
{
|
|
|
|
//mWebShell isn't refcnt'd here. WebShell calls SetWebShell(nsnull) when deleted.
|
1999-06-15 03:17:11 +00:00
|
|
|
|
|
|
|
// When SetWebShell(nsnull) is called, drop our references to the
|
|
|
|
// script object (held via a named JS root) and the script context
|
|
|
|
// itself.
|
|
|
|
if ((nsnull == aWebShell) && (nsnull != mContext)) {
|
|
|
|
if (nsnull != mScriptObject) {
|
|
|
|
mContext->RemoveReference(&mScriptObject, mScriptObject);
|
|
|
|
mScriptObject = nsnull;
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(mContext);
|
|
|
|
}
|
1998-08-07 04:45:03 +00:00
|
|
|
mWebShell = aWebShell;
|
1998-08-13 04:34:53 +00:00
|
|
|
if (nsnull != mLocation) {
|
|
|
|
mLocation->SetWebShell(aWebShell);
|
|
|
|
}
|
1999-01-28 23:12:54 +00:00
|
|
|
if (nsnull != mHistory) {
|
|
|
|
mHistory->SetWebShell(aWebShell);
|
|
|
|
}
|
1998-08-21 21:39:27 +00:00
|
|
|
if (nsnull != mFrames) {
|
|
|
|
mFrames->SetWebShell(aWebShell);
|
|
|
|
}
|
1999-05-27 21:06:51 +00:00
|
|
|
|
1999-06-09 19:04:18 +00:00
|
|
|
if (mWebShell) {
|
|
|
|
// tell our member elements about the new browserwindow
|
|
|
|
|
1999-06-19 22:15:14 +00:00
|
|
|
if (nsnull != mMenubar) {
|
|
|
|
nsCOMPtr<nsIBrowserWindow> browser;
|
|
|
|
GetBrowserWindowInterface(*getter_AddRefs(browser));
|
1999-06-09 19:04:18 +00:00
|
|
|
mMenubar->SetBrowserWindow(browser);
|
1999-06-19 22:15:14 +00:00
|
|
|
}
|
1999-06-09 19:04:18 +00:00
|
|
|
// Get our enclosing chrome shell and retrieve its global window impl, so that we can
|
|
|
|
// do some forwarding to the chrome document.
|
|
|
|
nsCOMPtr<nsIWebShell> chromeShell;
|
|
|
|
mWebShell->GetContainingChromeShell(getter_AddRefs(chromeShell));
|
|
|
|
if (chromeShell) {
|
1999-06-26 21:48:29 +00:00
|
|
|
nsCOMPtr<nsIDOMWindow> chromeWindow;
|
|
|
|
WebShellToDOMWindow(chromeShell, getter_AddRefs(chromeWindow));
|
|
|
|
if (chromeWindow) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> chromeDoc;
|
|
|
|
chromeWindow->GetDocument(getter_AddRefs(chromeDoc));
|
|
|
|
nsCOMPtr<nsIDocument> realDoc = do_QueryInterface(chromeDoc);
|
|
|
|
mChromeDocument = realDoc.get(); // Don't addref it
|
1999-06-09 19:04:18 +00:00
|
|
|
}
|
|
|
|
}
|
1999-05-27 21:06:51 +00:00
|
|
|
}
|
1998-08-07 04:45:03 +00:00
|
|
|
}
|
|
|
|
|
1999-02-10 16:25:11 +00:00
|
|
|
NS_IMETHODIMP_(void) // XXX This may be temporary - rods
|
|
|
|
GlobalWindowImpl::GetWebShell(nsIWebShell **aWebShell)
|
|
|
|
{
|
|
|
|
if (nsnull != mWebShell) {
|
|
|
|
*aWebShell = mWebShell;
|
|
|
|
NS_ADDREF(mWebShell);
|
|
|
|
} else {
|
|
|
|
//*mWebShell = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1998-09-03 01:19:58 +00:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
GlobalWindowImpl::SetOpenerWindow(nsIDOMWindow *aOpener)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mOpener);
|
|
|
|
mOpener = aOpener;
|
|
|
|
NS_IF_ADDREF(mOpener);
|
|
|
|
}
|
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetWindow(nsIDOMWindow** aWindow)
|
|
|
|
{
|
|
|
|
*aWindow = this;
|
|
|
|
NS_ADDREF(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetSelf(nsIDOMWindow** aWindow)
|
|
|
|
{
|
|
|
|
*aWindow = this;
|
|
|
|
NS_ADDREF(this);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetDocument(nsIDOMDocument** aDocument)
|
|
|
|
{
|
|
|
|
*aDocument = mDocument;
|
1999-03-11 23:17:29 +00:00
|
|
|
NS_IF_ADDREF(mDocument);
|
1998-07-16 01:16:47 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetNavigator(nsIDOMNavigator** aNavigator)
|
|
|
|
{
|
|
|
|
if (nsnull == mNavigator) {
|
|
|
|
mNavigator = new NavigatorImpl();
|
|
|
|
NS_IF_ADDREF(mNavigator);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aNavigator = mNavigator;
|
|
|
|
NS_IF_ADDREF(mNavigator);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-28 23:12:54 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetScreen(nsIDOMScreen** aScreen)
|
|
|
|
{
|
1999-06-15 03:17:11 +00:00
|
|
|
if ((nsnull == mScreen) && (nsnull != mWebShell)) {
|
1999-06-11 21:19:24 +00:00
|
|
|
mScreen = new ScreenImpl( mWebShell );
|
1999-01-28 23:12:54 +00:00
|
|
|
NS_IF_ADDREF(mScreen);
|
|
|
|
}
|
1999-06-15 03:17:11 +00:00
|
|
|
|
1999-01-28 23:12:54 +00:00
|
|
|
*aScreen = mScreen;
|
|
|
|
NS_IF_ADDREF(mScreen);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetHistory(nsIDOMHistory** aHistory)
|
|
|
|
{
|
1999-06-15 03:17:11 +00:00
|
|
|
if ((nsnull == mHistory) && (nsnull != mWebShell)) {
|
1999-01-28 23:12:54 +00:00
|
|
|
mHistory = new HistoryImpl();
|
|
|
|
if (nsnull != mHistory) {
|
|
|
|
NS_ADDREF(mHistory);
|
|
|
|
mHistory->SetWebShell(mWebShell);
|
|
|
|
}
|
|
|
|
}
|
1999-06-15 03:17:11 +00:00
|
|
|
|
1999-01-28 23:12:54 +00:00
|
|
|
*aHistory = mHistory;
|
|
|
|
NS_IF_ADDREF(mHistory);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-09 19:04:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetMenubar(nsIDOMBarProp** aMenubar)
|
|
|
|
{
|
|
|
|
if (nsnull == mMenubar) {
|
|
|
|
mMenubar = new MenubarPropImpl();
|
|
|
|
if (nsnull != mMenubar) {
|
|
|
|
NS_ADDREF(mMenubar);
|
1999-06-19 22:15:14 +00:00
|
|
|
nsIBrowserWindow *browser = nsnull;
|
|
|
|
if ((nsnull != mWebShell) && NS_OK == GetBrowserWindowInterface(browser)) {
|
1999-06-09 19:04:18 +00:00
|
|
|
mMenubar->SetBrowserWindow(browser);
|
1999-06-19 22:15:14 +00:00
|
|
|
NS_IF_RELEASE(browser);
|
|
|
|
}
|
1999-06-09 19:04:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aMenubar = mMenubar;
|
|
|
|
NS_IF_ADDREF(mMenubar);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetToolbar(nsIDOMBarProp** aToolbar)
|
|
|
|
{
|
|
|
|
if (nsnull == mToolbar) {
|
|
|
|
mToolbar = new ToolbarPropImpl();
|
|
|
|
if (nsnull != mToolbar) {
|
|
|
|
NS_ADDREF(mToolbar);
|
1999-06-19 22:15:14 +00:00
|
|
|
nsIBrowserWindow *browser = nsnull;
|
|
|
|
if ((nsnull != mWebShell) && NS_OK == GetBrowserWindowInterface(browser)) {
|
1999-06-09 19:04:18 +00:00
|
|
|
mToolbar->SetBrowserWindow(browser);
|
1999-06-19 22:15:14 +00:00
|
|
|
NS_IF_RELEASE(browser);
|
|
|
|
}
|
1999-06-09 19:04:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aToolbar = mToolbar;
|
|
|
|
NS_IF_ADDREF(mToolbar);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetLocationbar(nsIDOMBarProp** aLocationbar)
|
|
|
|
{
|
|
|
|
if (nsnull == mLocationbar) {
|
|
|
|
mLocationbar = new LocationbarPropImpl();
|
|
|
|
if (nsnull != mLocationbar) {
|
|
|
|
NS_ADDREF(mLocationbar);
|
1999-06-19 22:15:14 +00:00
|
|
|
nsIBrowserWindow *browser = nsnull;
|
|
|
|
if ((nsnull != mWebShell) && NS_OK == GetBrowserWindowInterface(browser)) {
|
1999-06-09 19:04:18 +00:00
|
|
|
mLocationbar->SetBrowserWindow(browser);
|
1999-06-19 22:15:14 +00:00
|
|
|
NS_IF_RELEASE(browser);
|
|
|
|
}
|
1999-06-09 19:04:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aLocationbar = mLocationbar;
|
|
|
|
NS_IF_ADDREF(mLocationbar);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetPersonalbar(nsIDOMBarProp** aPersonalbar)
|
|
|
|
{
|
|
|
|
if (nsnull == mPersonalbar) {
|
|
|
|
mPersonalbar = new PersonalbarPropImpl();
|
|
|
|
if (nsnull != mPersonalbar) {
|
|
|
|
NS_ADDREF(mPersonalbar);
|
1999-06-19 22:15:14 +00:00
|
|
|
nsIBrowserWindow *browser = nsnull;
|
|
|
|
if ((nsnull != mWebShell) && NS_OK == GetBrowserWindowInterface(browser)) {
|
1999-06-09 19:04:18 +00:00
|
|
|
mPersonalbar->SetBrowserWindow(browser);
|
1999-06-19 22:15:14 +00:00
|
|
|
NS_IF_RELEASE(browser);
|
|
|
|
}
|
1999-06-09 19:04:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aPersonalbar = mPersonalbar;
|
|
|
|
NS_IF_ADDREF(mPersonalbar);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetStatusbar(nsIDOMBarProp** aStatusbar)
|
|
|
|
{
|
|
|
|
if (nsnull == mStatusbar) {
|
|
|
|
mStatusbar = new StatusbarPropImpl();
|
|
|
|
if (nsnull != mStatusbar) {
|
|
|
|
NS_ADDREF(mStatusbar);
|
1999-06-19 22:15:14 +00:00
|
|
|
nsIBrowserWindow *browser = nsnull;
|
|
|
|
if ((nsnull != mWebShell) && NS_OK == GetBrowserWindowInterface(browser)) {
|
1999-06-09 19:04:18 +00:00
|
|
|
mStatusbar->SetBrowserWindow(browser);
|
1999-06-19 22:15:14 +00:00
|
|
|
NS_IF_RELEASE(browser);
|
|
|
|
}
|
1999-06-09 19:04:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aStatusbar = mStatusbar;
|
|
|
|
NS_IF_ADDREF(mStatusbar);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetScrollbars(nsIDOMBarProp** aScrollbars)
|
|
|
|
{
|
|
|
|
if (nsnull == mScrollbars) {
|
|
|
|
mScrollbars = new ScrollbarsPropImpl();
|
|
|
|
if (nsnull != mScrollbars) {
|
|
|
|
NS_ADDREF(mScrollbars);
|
1999-06-19 22:15:14 +00:00
|
|
|
nsIBrowserWindow *browser = nsnull;
|
|
|
|
if ((nsnull != mWebShell) && NS_OK == GetBrowserWindowInterface(browser)) {
|
1999-06-09 19:04:18 +00:00
|
|
|
mScrollbars->SetBrowserWindow(browser);
|
1999-06-19 22:15:14 +00:00
|
|
|
NS_IF_RELEASE(browser);
|
|
|
|
}
|
1999-06-09 19:04:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aScrollbars = mScrollbars;
|
|
|
|
NS_IF_ADDREF(mScrollbars);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetDirectories(nsIDOMBarProp** aDirectories)
|
|
|
|
{
|
|
|
|
return GetPersonalbar(aDirectories);
|
|
|
|
}
|
|
|
|
|
1998-08-13 23:37:54 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetOpener(nsIDOMWindow** aOpener)
|
|
|
|
{
|
1998-09-03 01:19:58 +00:00
|
|
|
*aOpener = mOpener;
|
1998-08-13 23:37:54 +00:00
|
|
|
NS_IF_ADDREF(*aOpener);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-03 01:19:58 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::SetOpener(nsIDOMWindow* aOpener)
|
|
|
|
{
|
1999-05-18 10:27:31 +00:00
|
|
|
NS_IF_RELEASE(mOpener);
|
|
|
|
mOpener = aOpener;
|
|
|
|
NS_IF_ADDREF(mOpener);
|
1998-09-03 01:19:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-08-13 23:37:54 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetParent(nsIDOMWindow** aParent)
|
|
|
|
{
|
|
|
|
nsresult ret = NS_OK;
|
1998-08-15 00:13:51 +00:00
|
|
|
|
1999-06-15 03:17:11 +00:00
|
|
|
*aParent = nsnull;
|
|
|
|
if (nsnull != mWebShell) {
|
1999-06-26 21:48:29 +00:00
|
|
|
nsIWebShell *parentWebShell;
|
|
|
|
mWebShell->GetParent(parentWebShell);
|
1999-06-15 03:17:11 +00:00
|
|
|
|
1999-06-26 21:48:29 +00:00
|
|
|
if (nsnull != parentWebShell) {
|
|
|
|
ret = WebShellToDOMWindow(parentWebShell, aParent);
|
|
|
|
NS_RELEASE(parentWebShell);
|
1999-06-15 03:17:11 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aParent = this;
|
|
|
|
NS_ADDREF(this);
|
|
|
|
}
|
1998-08-13 23:37:54 +00:00
|
|
|
}
|
1998-08-15 00:13:51 +00:00
|
|
|
|
1998-08-13 23:37:54 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetLocation(nsIDOMLocation** aLocation)
|
|
|
|
{
|
1999-06-15 03:17:11 +00:00
|
|
|
if ((nsnull == mLocation) && (nsnull != mWebShell)) {
|
1998-08-13 04:34:53 +00:00
|
|
|
mLocation = new LocationImpl(mWebShell);
|
|
|
|
NS_IF_ADDREF(mLocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aLocation = mLocation;
|
|
|
|
NS_IF_ADDREF(mLocation);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-08-07 04:45:03 +00:00
|
|
|
NS_IMETHODIMP
|
1998-08-13 23:37:54 +00:00
|
|
|
GlobalWindowImpl::GetTop(nsIDOMWindow** aTop)
|
1998-08-07 04:45:03 +00:00
|
|
|
{
|
1998-08-13 23:37:54 +00:00
|
|
|
nsresult ret = NS_OK;
|
|
|
|
|
1998-08-15 00:13:51 +00:00
|
|
|
*aTop = nsnull;
|
1999-06-15 03:17:11 +00:00
|
|
|
if (nsnull != mWebShell) {
|
1999-06-26 21:48:29 +00:00
|
|
|
nsIWebShell *rootWebShell;
|
|
|
|
mWebShell->GetRootWebShell(rootWebShell);
|
|
|
|
if (nsnull != rootWebShell) {
|
|
|
|
WebShellToDOMWindow(rootWebShell, aTop);
|
|
|
|
NS_RELEASE(rootWebShell);
|
1998-08-13 23:37:54 +00:00
|
|
|
}
|
|
|
|
}
|
1999-06-15 03:17:11 +00:00
|
|
|
|
1998-08-13 23:37:54 +00:00
|
|
|
return ret;
|
|
|
|
}
|
1998-08-07 04:45:03 +00:00
|
|
|
|
1999-06-26 21:48:29 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetContent(nsIDOMWindow** aContent)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
*aContent = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIBrowserWindow> browser;
|
|
|
|
rv = GetBrowserWindowInterface(*getter_AddRefs(browser));
|
|
|
|
if (NS_SUCCEEDED(rv) && browser) {
|
|
|
|
nsCOMPtr<nsIWebShell> contentShell;
|
|
|
|
rv = browser->GetContentWebShell(getter_AddRefs(contentShell));
|
|
|
|
if (NS_SUCCEEDED(rv) && contentShell)
|
|
|
|
rv = WebShellToDOMWindow(contentShell, aContent);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-08-13 23:37:54 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetClosed(PRBool* aClosed)
|
|
|
|
{
|
1999-02-01 23:21:58 +00:00
|
|
|
if (nsnull == mWebShell) {
|
1998-08-13 23:37:54 +00:00
|
|
|
*aClosed = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aClosed = PR_FALSE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-08-21 21:39:27 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetFrames(nsIDOMWindowCollection** aFrames)
|
|
|
|
{
|
1999-06-15 03:17:11 +00:00
|
|
|
if ((nsnull == mFrames) && (nsnull != mWebShell)) {
|
1999-02-01 18:14:20 +00:00
|
|
|
mFrames = new nsDOMWindowList(mWebShell);
|
1998-08-21 21:39:27 +00:00
|
|
|
if (nsnull == mFrames) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
NS_ADDREF(mFrames);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aFrames = (nsIDOMWindowCollection *)mFrames;
|
1999-06-15 03:17:11 +00:00
|
|
|
NS_IF_ADDREF(mFrames);
|
1998-08-21 21:39:27 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-08-13 23:37:54 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetStatus(nsString& aStatus)
|
|
|
|
{
|
|
|
|
nsIBrowserWindow *mBrowser;
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
1999-02-14 06:37:24 +00:00
|
|
|
const PRUnichar *status;
|
1998-08-14 23:08:54 +00:00
|
|
|
mBrowser->GetStatus(&status);
|
|
|
|
aStatus = status;
|
1998-08-13 23:37:54 +00:00
|
|
|
NS_RELEASE(mBrowser);
|
|
|
|
}
|
1999-06-15 03:25:41 +00:00
|
|
|
else {
|
|
|
|
aStatus.Truncate();
|
|
|
|
}
|
1998-08-13 23:37:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::SetStatus(const nsString& aStatus)
|
|
|
|
{
|
|
|
|
nsIBrowserWindow *mBrowser;
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
1999-04-05 09:07:07 +00:00
|
|
|
mBrowser->SetStatus(aStatus.GetUnicode());
|
1998-08-13 23:37:54 +00:00
|
|
|
NS_RELEASE(mBrowser);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetDefaultStatus(nsString& aDefaultStatus)
|
|
|
|
{
|
1999-07-26 15:02:19 +00:00
|
|
|
nsIBrowserWindow *mBrowser;
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
const PRUnichar *status;
|
|
|
|
mBrowser->GetDefaultStatus(&status);
|
|
|
|
aDefaultStatus = status;
|
|
|
|
NS_RELEASE(mBrowser);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aDefaultStatus.Truncate();
|
|
|
|
}
|
1998-08-13 23:37:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::SetDefaultStatus(const nsString& aDefaultStatus)
|
|
|
|
{
|
1999-07-26 15:02:19 +00:00
|
|
|
nsIBrowserWindow *mBrowser;
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
mBrowser->SetDefaultStatus(aDefaultStatus.GetUnicode());
|
|
|
|
NS_RELEASE(mBrowser);
|
|
|
|
}
|
1998-08-13 23:37:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetName(nsString& aName)
|
|
|
|
{
|
1999-06-15 03:17:11 +00:00
|
|
|
const PRUnichar *name = nsnull;
|
|
|
|
if (nsnull != mWebShell) {
|
|
|
|
mWebShell->GetName(&name);
|
|
|
|
}
|
1998-08-14 23:08:54 +00:00
|
|
|
aName = name;
|
1998-08-13 23:37:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::SetName(const nsString& aName)
|
|
|
|
{
|
1999-06-15 03:17:11 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
if (nsnull != mWebShell) {
|
|
|
|
result = mWebShell->SetName(aName.GetUnicode());
|
|
|
|
}
|
|
|
|
return result;
|
1998-08-07 04:45:03 +00:00
|
|
|
}
|
|
|
|
|
1999-07-16 01:14:59 +00:00
|
|
|
|
1998-10-01 22:21:59 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetInnerWidth(PRInt32* aInnerWidth)
|
|
|
|
{
|
|
|
|
nsIBrowserWindow *mBrowser;
|
1999-07-22 07:07:50 +00:00
|
|
|
nsIDOMWindow* parent = nsnull;
|
|
|
|
|
|
|
|
GetParent(&parent);
|
|
|
|
if (parent == this) {
|
|
|
|
// We are in a top level window. Use browser window's bounds.
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
nsRect r;
|
|
|
|
mBrowser->GetContentBounds(r);
|
|
|
|
*aInnerWidth = r.width;
|
|
|
|
NS_RELEASE(mBrowser);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aInnerWidth = 0;
|
|
|
|
}
|
1998-10-01 22:21:59 +00:00
|
|
|
}
|
1999-03-29 23:48:47 +00:00
|
|
|
else {
|
1999-07-22 07:07:50 +00:00
|
|
|
// We are in an (i)frame. Use webshell bounds.
|
|
|
|
if (mWebShell) {
|
|
|
|
PRInt32 x,y,w,h;
|
|
|
|
mWebShell->GetBounds(x, y, w, h);
|
|
|
|
*aInnerWidth = w;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aInnerWidth = 0;
|
|
|
|
}
|
1999-03-29 23:48:47 +00:00
|
|
|
}
|
1999-07-22 07:07:50 +00:00
|
|
|
|
|
|
|
NS_RELEASE(parent);
|
1998-10-01 22:21:59 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::SetInnerWidth(PRInt32 aInnerWidth)
|
|
|
|
{
|
|
|
|
nsIBrowserWindow *mBrowser;
|
|
|
|
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
nsRect r;
|
1999-07-04 04:09:54 +00:00
|
|
|
mBrowser->GetContentBounds(r);
|
1998-10-01 22:21:59 +00:00
|
|
|
|
1999-07-04 04:09:54 +00:00
|
|
|
mBrowser->SizeContentTo(aInnerWidth, r.height);
|
1998-10-01 22:21:59 +00:00
|
|
|
NS_RELEASE(mBrowser);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetInnerHeight(PRInt32* aInnerHeight)
|
|
|
|
{
|
|
|
|
nsIBrowserWindow *mBrowser;
|
1999-07-22 07:07:50 +00:00
|
|
|
nsIDOMWindow* parent = nsnull;
|
|
|
|
|
|
|
|
GetParent(&parent);
|
|
|
|
if (parent == this) {
|
|
|
|
// We are in a top level window. Use browser window's bounds.
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
nsRect r;
|
|
|
|
mBrowser->GetContentBounds(r);
|
|
|
|
*aInnerHeight = r.height;
|
|
|
|
NS_RELEASE(mBrowser);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aInnerHeight = 0;
|
|
|
|
}
|
1998-10-01 22:21:59 +00:00
|
|
|
}
|
1999-03-29 23:48:47 +00:00
|
|
|
else {
|
1999-07-22 07:07:50 +00:00
|
|
|
// We are in an (i)frame. Use webshell bounds.
|
|
|
|
if (mWebShell) {
|
|
|
|
PRInt32 x,y,w,h;
|
|
|
|
mWebShell->GetBounds(x, y, w, h);
|
|
|
|
*aInnerHeight = h;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aInnerHeight = 0;
|
|
|
|
}
|
1999-03-29 23:48:47 +00:00
|
|
|
}
|
|
|
|
|
1999-07-22 07:07:50 +00:00
|
|
|
NS_RELEASE(parent);
|
1998-10-01 22:21:59 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::SetInnerHeight(PRInt32 aInnerHeight)
|
|
|
|
{
|
|
|
|
nsIBrowserWindow *mBrowser;
|
|
|
|
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
nsRect r;
|
1999-07-04 04:09:54 +00:00
|
|
|
mBrowser->GetContentBounds(r);
|
1998-10-01 22:21:59 +00:00
|
|
|
|
1999-07-04 04:09:54 +00:00
|
|
|
mBrowser->SizeContentTo(r.width, aInnerHeight);
|
1998-10-01 22:21:59 +00:00
|
|
|
NS_RELEASE(mBrowser);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetOuterWidth(PRInt32* aOuterWidth)
|
|
|
|
{
|
1999-07-28 07:03:29 +00:00
|
|
|
nsIBrowserWindow *mBrowser;
|
1999-07-22 07:07:50 +00:00
|
|
|
|
1999-07-28 07:03:29 +00:00
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
nsRect r;
|
|
|
|
mBrowser->GetWindowBounds(r);
|
|
|
|
*aOuterWidth = r.width;
|
|
|
|
NS_RELEASE(mBrowser);
|
1998-10-01 22:21:59 +00:00
|
|
|
}
|
1999-03-29 23:48:47 +00:00
|
|
|
else {
|
1999-07-28 07:03:29 +00:00
|
|
|
*aOuterWidth = 0;
|
1999-03-29 23:48:47 +00:00
|
|
|
}
|
1999-07-28 07:03:29 +00:00
|
|
|
|
1998-10-01 22:21:59 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::SetOuterWidth(PRInt32 aOuterWidth)
|
|
|
|
{
|
|
|
|
nsIBrowserWindow *mBrowser;
|
|
|
|
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
nsRect r;
|
|
|
|
mBrowser->GetWindowBounds(r);
|
|
|
|
|
1999-07-04 04:09:54 +00:00
|
|
|
mBrowser->SizeWindowTo(aOuterWidth, r.height);
|
1998-10-01 22:21:59 +00:00
|
|
|
NS_RELEASE(mBrowser);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetOuterHeight(PRInt32* aOuterHeight)
|
|
|
|
{
|
|
|
|
nsIBrowserWindow *mBrowser;
|
1999-07-28 07:03:29 +00:00
|
|
|
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
nsRect r;
|
|
|
|
mBrowser->GetWindowBounds(r);
|
|
|
|
*aOuterHeight = r.height;
|
|
|
|
NS_RELEASE(mBrowser);
|
1998-10-01 22:21:59 +00:00
|
|
|
}
|
1999-03-29 23:48:47 +00:00
|
|
|
else {
|
1999-07-28 07:03:29 +00:00
|
|
|
*aOuterHeight = 0;
|
1999-03-29 23:48:47 +00:00
|
|
|
}
|
1998-10-01 22:21:59 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::SetOuterHeight(PRInt32 aOuterHeight)
|
|
|
|
{
|
|
|
|
nsIBrowserWindow *mBrowser;
|
|
|
|
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
nsRect r;
|
|
|
|
mBrowser->GetWindowBounds(r);
|
|
|
|
|
1999-07-04 04:09:54 +00:00
|
|
|
mBrowser->SizeWindowTo(r.width, aOuterHeight);
|
1998-10-01 22:21:59 +00:00
|
|
|
NS_RELEASE(mBrowser);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetScreenX(PRInt32* aScreenX)
|
|
|
|
{
|
|
|
|
nsIBrowserWindow *mBrowser;
|
|
|
|
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
nsRect r;
|
|
|
|
mBrowser->GetWindowBounds(r);
|
|
|
|
*aScreenX = r.x;
|
|
|
|
NS_RELEASE(mBrowser);
|
|
|
|
}
|
1999-06-15 03:25:41 +00:00
|
|
|
else {
|
|
|
|
*aScreenX = nsnull;
|
|
|
|
}
|
1998-10-01 22:21:59 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::SetScreenX(PRInt32 aScreenX)
|
|
|
|
{
|
|
|
|
nsIBrowserWindow *mBrowser;
|
|
|
|
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
nsRect r;
|
|
|
|
mBrowser->GetWindowBounds(r);
|
|
|
|
|
|
|
|
mBrowser->MoveTo(aScreenX, r.y);
|
|
|
|
NS_RELEASE(mBrowser);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetScreenY(PRInt32* aScreenY)
|
|
|
|
{
|
|
|
|
nsIBrowserWindow *mBrowser;
|
|
|
|
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
nsRect r;
|
|
|
|
mBrowser->GetWindowBounds(r);
|
|
|
|
*aScreenY = r.y;
|
|
|
|
NS_RELEASE(mBrowser);
|
|
|
|
}
|
1999-06-15 03:25:41 +00:00
|
|
|
else {
|
|
|
|
*aScreenY = nsnull;
|
|
|
|
}
|
1998-10-01 22:21:59 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::SetScreenY(PRInt32 aScreenY)
|
|
|
|
{
|
|
|
|
nsIBrowserWindow *mBrowser;
|
|
|
|
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
nsRect r;
|
|
|
|
mBrowser->GetWindowBounds(r);
|
|
|
|
|
|
|
|
mBrowser->MoveTo(r.x, aScreenY);
|
|
|
|
NS_RELEASE(mBrowser);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetPageXOffset(PRInt32* aPageXOffset)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::SetPageXOffset(PRInt32 aPageXOffset)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetPageYOffset(PRInt32* aPageYOffset)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::SetPageYOffset(PRInt32 aPageYOffset)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::Dump(const nsString& aStr)
|
|
|
|
{
|
|
|
|
char *cstr = aStr.ToNewCString();
|
|
|
|
|
1999-08-03 12:43:06 +00:00
|
|
|
#ifdef XP_MAC
|
|
|
|
// have to convert \r to \n so that printing to the console works
|
|
|
|
char *c = cstr, *cEnd = cstr + aStr.Length();
|
|
|
|
while (c < cEnd)
|
|
|
|
{
|
|
|
|
if (*c == '\r')
|
|
|
|
*c = '\n';
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
if (nsnull != cstr) {
|
|
|
|
printf("%s", cstr);
|
|
|
|
delete [] cstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-18 17:34:08 +00:00
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
NS_IMETHODIMP
|
1999-06-11 23:57:25 +00:00
|
|
|
GlobalWindowImpl::Alert(JSContext *cx, jsval *argv, PRUint32 argc)
|
1998-07-16 01:16:47 +00:00
|
|
|
{
|
1999-06-15 03:17:11 +00:00
|
|
|
nsresult ret = NS_OK;
|
1999-06-11 23:57:25 +00:00
|
|
|
nsAutoString str;
|
|
|
|
|
1999-06-15 03:17:11 +00:00
|
|
|
if (nsnull != mWebShell) {
|
|
|
|
if (argc > 0) {
|
|
|
|
nsJSUtils::nsConvertJSValToString(str, cx, argv[0]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
str.SetString("undefined");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIWebShell *rootWebShell;
|
|
|
|
ret = mWebShell->GetRootWebShellEvenIfChrome(rootWebShell);
|
|
|
|
if (nsnull != rootWebShell) {
|
|
|
|
nsIWebShellContainer *rootContainer;
|
|
|
|
ret = rootWebShell->GetContainer(rootContainer);
|
|
|
|
if (nsnull != rootContainer) {
|
1999-06-23 03:29:44 +00:00
|
|
|
#ifdef NECKO
|
1999-07-01 19:38:49 +00:00
|
|
|
nsIPrompt *prompter;
|
|
|
|
if (NS_OK == (ret = rootContainer->QueryInterface(nsIPrompt::GetIID(), (void**)&prompter))) {
|
|
|
|
ret = prompter->Alert(str.GetUnicode());
|
|
|
|
NS_RELEASE(prompter);
|
|
|
|
}
|
1999-06-23 03:29:44 +00:00
|
|
|
#else
|
1999-06-15 03:17:11 +00:00
|
|
|
nsINetSupport *support;
|
1998-11-24 07:44:39 +00:00
|
|
|
if (NS_OK == (ret = rootContainer->QueryInterface(kINetSupportIID, (void**)&support))) {
|
1999-06-11 23:57:25 +00:00
|
|
|
support->Alert(str);
|
|
|
|
NS_RELEASE(support);
|
|
|
|
}
|
1999-06-23 03:29:44 +00:00
|
|
|
#endif
|
1999-06-15 03:17:11 +00:00
|
|
|
NS_RELEASE(rootContainer);
|
|
|
|
}
|
|
|
|
NS_RELEASE(rootWebShell);
|
1999-06-11 23:57:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::Confirm(JSContext *cx, jsval *argv, PRUint32 argc, PRBool* aReturn)
|
|
|
|
{
|
1999-06-15 03:17:11 +00:00
|
|
|
nsresult ret = NS_OK;
|
1999-06-11 23:57:25 +00:00
|
|
|
nsAutoString str;
|
|
|
|
|
1999-06-15 03:17:11 +00:00
|
|
|
*aReturn = PR_FALSE;
|
|
|
|
if (nsnull != mWebShell) {
|
|
|
|
if (argc > 0) {
|
|
|
|
nsJSUtils::nsConvertJSValToString(str, cx, argv[0]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
str.SetString("undefined");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIWebShell *rootWebShell;
|
|
|
|
ret = mWebShell->GetRootWebShellEvenIfChrome(rootWebShell);
|
|
|
|
if (nsnull != rootWebShell) {
|
|
|
|
nsIWebShellContainer *rootContainer;
|
|
|
|
ret = rootWebShell->GetContainer(rootContainer);
|
|
|
|
if (nsnull != rootContainer) {
|
1999-06-23 03:29:44 +00:00
|
|
|
#ifdef NECKO
|
1999-07-01 19:38:49 +00:00
|
|
|
nsIPrompt *prompter;
|
|
|
|
if (NS_OK == (ret = rootContainer->QueryInterface(nsIPrompt::GetIID(), (void**)&prompter))) {
|
|
|
|
ret = prompter->Confirm(str.GetUnicode(), aReturn);
|
|
|
|
NS_RELEASE(prompter);
|
|
|
|
}
|
1999-06-23 03:29:44 +00:00
|
|
|
#else
|
1999-06-15 03:17:11 +00:00
|
|
|
nsINetSupport *support;
|
1999-06-11 23:57:25 +00:00
|
|
|
if (NS_OK == (ret = rootContainer->QueryInterface(kINetSupportIID, (void**)&support))) {
|
|
|
|
*aReturn = support->Confirm(str);
|
|
|
|
NS_RELEASE(support);
|
|
|
|
}
|
1999-06-23 03:29:44 +00:00
|
|
|
#endif
|
1999-06-15 03:17:11 +00:00
|
|
|
NS_RELEASE(rootContainer);
|
|
|
|
}
|
|
|
|
NS_RELEASE(rootWebShell);
|
1999-06-11 23:57:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::Prompt(JSContext *cx, jsval *argv, PRUint32 argc, nsString& aReturn)
|
|
|
|
{
|
1999-06-15 03:17:11 +00:00
|
|
|
nsresult ret = NS_OK;
|
1999-06-11 23:57:25 +00:00
|
|
|
nsAutoString str, initial;
|
|
|
|
|
1999-06-15 03:17:11 +00:00
|
|
|
aReturn.Truncate();
|
|
|
|
if (nsnull != mWebShell) {
|
|
|
|
if (argc > 0) {
|
|
|
|
nsJSUtils::nsConvertJSValToString(str, cx, argv[0]);
|
|
|
|
|
|
|
|
if (argc > 1) {
|
|
|
|
nsJSUtils::nsConvertJSValToString(initial, cx, argv[1]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
initial.SetString("undefined");
|
|
|
|
}
|
1999-06-11 23:57:25 +00:00
|
|
|
}
|
|
|
|
|
1999-06-15 03:17:11 +00:00
|
|
|
nsIWebShell *rootWebShell;
|
|
|
|
ret = mWebShell->GetRootWebShellEvenIfChrome(rootWebShell);
|
|
|
|
if (nsnull != rootWebShell) {
|
|
|
|
nsIWebShellContainer *rootContainer;
|
|
|
|
ret = rootWebShell->GetContainer(rootContainer);
|
|
|
|
if (nsnull != rootContainer) {
|
1999-06-23 03:29:44 +00:00
|
|
|
#ifdef NECKO
|
1999-07-01 19:38:49 +00:00
|
|
|
nsIPrompt *prompter;
|
|
|
|
if (NS_OK == (ret = rootContainer->QueryInterface(nsIPrompt::GetIID(), (void**)&prompter))) {
|
|
|
|
PRBool b;
|
|
|
|
PRUnichar* uniResult = nsnull;
|
|
|
|
ret = prompter->Prompt(str.GetUnicode(), initial.GetUnicode(), &uniResult, &b);
|
|
|
|
aReturn = uniResult;
|
|
|
|
if (NS_FAILED(ret) || !b) {
|
|
|
|
// XXX Need to check return value and return null if the
|
|
|
|
// user hits cancel. Currently, we can only return a
|
|
|
|
// string reference.
|
|
|
|
aReturn.SetString("");
|
|
|
|
}
|
|
|
|
NS_RELEASE(prompter);
|
|
|
|
}
|
1999-06-23 03:29:44 +00:00
|
|
|
#else
|
1999-06-15 03:17:11 +00:00
|
|
|
nsINetSupport *support;
|
1999-06-11 23:57:25 +00:00
|
|
|
if (NS_OK == (ret = rootContainer->QueryInterface(kINetSupportIID, (void**)&support))) {
|
|
|
|
if (!support->Prompt(str, initial, aReturn)) {
|
|
|
|
// XXX Need to check return value and return null if the
|
|
|
|
// user hits cancel. Currently, we can only return a
|
|
|
|
// string reference.
|
|
|
|
aReturn.SetString("");
|
|
|
|
}
|
1998-11-24 07:44:39 +00:00
|
|
|
NS_RELEASE(support);
|
|
|
|
}
|
1999-06-23 03:29:44 +00:00
|
|
|
#endif
|
1999-06-15 03:17:11 +00:00
|
|
|
NS_RELEASE(rootContainer);
|
|
|
|
}
|
|
|
|
NS_RELEASE(rootWebShell);
|
1998-11-24 07:44:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
1998-09-03 01:19:58 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::Focus()
|
|
|
|
{
|
1999-06-22 03:11:15 +00:00
|
|
|
nsIBrowserWindow *browser;
|
1999-07-12 23:40:01 +00:00
|
|
|
if (NS_OK == GetBrowserWindowInterface(browser)) {
|
|
|
|
browser->Show();
|
|
|
|
NS_RELEASE( browser);
|
1999-06-22 03:11:15 +00:00
|
|
|
}
|
1999-07-02 19:43:26 +00:00
|
|
|
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
nsIContentViewer *viewer = nsnull;
|
|
|
|
mWebShell->GetContentViewer(&viewer);
|
|
|
|
if (viewer) {
|
|
|
|
nsIDocumentViewer* docv = nsnull;
|
|
|
|
viewer->QueryInterface(kIDocumentViewerIID, (void**) &docv);
|
|
|
|
if (nsnull != docv) {
|
|
|
|
nsIPresContext* cx = nsnull;
|
|
|
|
docv->GetPresContext(cx);
|
1999-07-12 23:40:01 +00:00
|
|
|
if (nsnull != cx) {
|
1999-07-02 19:43:26 +00:00
|
|
|
nsIPresShell *shell = nsnull;
|
1999-07-12 23:40:01 +00:00
|
|
|
cx->GetShell(&shell);
|
1999-07-02 19:43:26 +00:00
|
|
|
if (nsnull != shell) {
|
|
|
|
nsIViewManager *vm = nsnull;
|
|
|
|
shell->GetViewManager(&vm);
|
|
|
|
if (nsnull != vm) {
|
|
|
|
nsIView *rootview = nsnull;
|
|
|
|
vm->GetRootView(rootview);
|
|
|
|
if (rootview) {
|
|
|
|
nsIWidget* widget;
|
|
|
|
rootview->GetWidget(widget);
|
|
|
|
if (widget) {
|
|
|
|
result = widget->SetFocus();
|
|
|
|
NS_RELEASE(widget);
|
|
|
|
}
|
|
|
|
}
|
1999-07-12 23:40:01 +00:00
|
|
|
NS_RELEASE(vm);
|
1999-07-02 19:43:26 +00:00
|
|
|
}
|
1999-07-12 23:40:01 +00:00
|
|
|
NS_RELEASE(shell);
|
1999-07-02 19:43:26 +00:00
|
|
|
}
|
1999-07-12 23:40:01 +00:00
|
|
|
NS_RELEASE(cx);
|
|
|
|
}
|
1999-07-02 19:43:26 +00:00
|
|
|
NS_RELEASE(docv);
|
|
|
|
}
|
|
|
|
NS_RELEASE(viewer);
|
1999-06-15 03:17:11 +00:00
|
|
|
}
|
1999-07-02 19:43:26 +00:00
|
|
|
|
1999-06-15 03:17:11 +00:00
|
|
|
return result;
|
1998-09-03 01:19:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::Blur()
|
|
|
|
{
|
1999-06-15 03:17:11 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
if (nsnull != mWebShell) {
|
|
|
|
result = mWebShell->RemoveFocus();
|
|
|
|
}
|
|
|
|
return result;
|
1998-09-03 01:19:58 +00:00
|
|
|
}
|
|
|
|
|
1998-09-04 00:46:06 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::Close()
|
|
|
|
{
|
1999-08-09 22:28:09 +00:00
|
|
|
// Note: the basic security check, rejecting windows not opened through JS,
|
|
|
|
// has been removed. This was approved long ago by ...you're going to call me
|
|
|
|
// on this, aren't you... well it was. And anyway, a better means is coming.
|
|
|
|
// In the new world of application-level interfaces being written in JS, this
|
|
|
|
// security check was causing problems.
|
|
|
|
nsIBrowserWindow *mBrowser;
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
mBrowser->Close();
|
|
|
|
NS_RELEASE(mBrowser);
|
1998-09-04 00:46:06 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-10-07 18:06:23 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::Forward()
|
|
|
|
{
|
1999-06-15 03:17:11 +00:00
|
|
|
nsresult result = NS_OK;
|
1999-01-28 23:12:54 +00:00
|
|
|
nsIBrowserWindow *mBrowser;
|
1998-10-07 18:06:23 +00:00
|
|
|
|
1999-01-28 23:12:54 +00:00
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
//XXX tbi
|
|
|
|
//mBrowser->Forward();
|
|
|
|
NS_RELEASE(mBrowser);
|
1999-06-15 03:17:11 +00:00
|
|
|
} else if (nsnull != mWebShell) {
|
|
|
|
result = mWebShell->Forward(); // I added this - rods
|
1999-01-28 23:12:54 +00:00
|
|
|
}
|
1999-06-15 03:17:11 +00:00
|
|
|
return result;
|
1998-10-07 18:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::Back()
|
|
|
|
{
|
1999-06-15 03:17:11 +00:00
|
|
|
nsresult result = NS_OK;
|
1999-01-28 23:12:54 +00:00
|
|
|
nsIBrowserWindow *mBrowser;
|
|
|
|
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
//XXX tbi
|
|
|
|
//mBrowser->Back();
|
|
|
|
NS_RELEASE(mBrowser);
|
1999-06-15 03:17:11 +00:00
|
|
|
} else if (nsnull != mWebShell) {
|
|
|
|
result = mWebShell->Back();// I added this - rods
|
1999-01-28 23:12:54 +00:00
|
|
|
}
|
1999-06-15 03:17:11 +00:00
|
|
|
return result;
|
1998-10-07 18:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::Home()
|
|
|
|
{
|
1999-04-28 20:33:43 +00:00
|
|
|
char *url = nsnull;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsString homeURL;
|
|
|
|
|
1999-06-15 03:17:11 +00:00
|
|
|
if (nsnull == mWebShell) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-04-28 20:33:43 +00:00
|
|
|
NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv);
|
1999-07-12 23:40:01 +00:00
|
|
|
if (NS_FAILED(rv) || !prefs) {
|
|
|
|
return rv;
|
1999-04-28 20:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if we get here, we know prefs is not null
|
|
|
|
rv = prefs->CopyCharPref(PREF_BROWSER_STARTUP_HOMEPAGE, &url);
|
1999-05-26 21:43:42 +00:00
|
|
|
if (NS_FAILED(rv) || (!url)) {
|
1999-04-28 20:33:43 +00:00
|
|
|
// if all else fails, use this
|
1999-07-06 22:40:20 +00:00
|
|
|
#ifdef DEBUG_seth
|
|
|
|
printf("all else failed. using %s as the home page\n",DEFAULT_HOME_PAGE);
|
|
|
|
#endif
|
1999-04-28 20:33:43 +00:00
|
|
|
homeURL = DEFAULT_HOME_PAGE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
homeURL = url;
|
|
|
|
}
|
|
|
|
PR_FREEIF(url);
|
1998-10-07 18:06:23 +00:00
|
|
|
PRUnichar* urlToLoad = homeURL.ToNewUnicode();
|
1999-06-15 03:17:11 +00:00
|
|
|
rv = mWebShell->LoadURL(urlToLoad);
|
1999-03-11 22:53:02 +00:00
|
|
|
delete[] urlToLoad;
|
1999-06-15 03:17:11 +00:00
|
|
|
return rv;
|
1998-10-07 18:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::Stop()
|
|
|
|
{
|
1999-06-15 03:17:11 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
if (nsnull != mWebShell) {
|
|
|
|
result = mWebShell->Stop();
|
|
|
|
}
|
|
|
|
return result;
|
1998-10-07 18:06:23 +00:00
|
|
|
}
|
|
|
|
|
1999-01-27 04:15:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::Print()
|
|
|
|
{
|
1999-06-15 03:17:11 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
if (nsnull != mWebShell) {
|
|
|
|
nsIContentViewer *viewer = nsnull;
|
|
|
|
|
|
|
|
mWebShell->GetContentViewer(&viewer);
|
|
|
|
|
|
|
|
if (nsnull != viewer) {
|
|
|
|
result = viewer->Print();
|
|
|
|
NS_RELEASE(viewer);
|
|
|
|
}
|
1999-01-27 04:15:19 +00:00
|
|
|
}
|
1999-06-15 03:17:11 +00:00
|
|
|
|
|
|
|
return result;
|
1999-01-27 04:15:19 +00:00
|
|
|
}
|
|
|
|
|
1998-10-01 22:21:59 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::MoveTo(PRInt32 aXPos, PRInt32 aYPos)
|
|
|
|
{
|
|
|
|
nsIBrowserWindow *mBrowser;
|
|
|
|
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
mBrowser->MoveTo(aXPos, aYPos);
|
|
|
|
NS_RELEASE(mBrowser);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::MoveBy(PRInt32 aXDif, PRInt32 aYDif)
|
|
|
|
{
|
|
|
|
nsIBrowserWindow *mBrowser;
|
|
|
|
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
nsRect r;
|
|
|
|
mBrowser->GetWindowBounds(r);
|
|
|
|
|
|
|
|
mBrowser->MoveTo(r.x + aXDif, r.y + aYDif);
|
|
|
|
NS_RELEASE(mBrowser);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::ResizeTo(PRInt32 aWidth, PRInt32 aHeight)
|
|
|
|
{
|
|
|
|
nsIBrowserWindow *mBrowser;
|
|
|
|
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
1999-07-04 04:09:54 +00:00
|
|
|
mBrowser->SizeWindowTo(aWidth, aHeight);
|
1998-10-01 22:21:59 +00:00
|
|
|
NS_RELEASE(mBrowser);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::ResizeBy(PRInt32 aWidthDif, PRInt32 aHeightDif)
|
|
|
|
{
|
|
|
|
nsIBrowserWindow *mBrowser;
|
|
|
|
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(mBrowser)) {
|
|
|
|
nsRect r;
|
|
|
|
mBrowser->GetWindowBounds(r);
|
|
|
|
|
1999-07-04 04:09:54 +00:00
|
|
|
mBrowser->SizeWindowTo(r.width + aWidthDif, r.height + aHeightDif);
|
1998-10-01 22:21:59 +00:00
|
|
|
NS_RELEASE(mBrowser);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::ScrollTo(PRInt32 aXScroll, PRInt32 aYScroll)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::ScrollBy(PRInt32 aXScrollDif, PRInt32 aYScrollDif)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
nsresult
|
|
|
|
GlobalWindowImpl::ClearTimeoutOrInterval(PRInt32 aTimerID)
|
|
|
|
{
|
|
|
|
PRUint32 public_id;
|
|
|
|
nsTimeoutImpl **top, *timeout;
|
|
|
|
|
|
|
|
public_id = (PRUint32)aTimerID;
|
|
|
|
if (!public_id) /* id of zero is reserved for internal use */
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-07-12 23:40:01 +00:00
|
|
|
for (top = &mTimeouts; (timeout = *top) != NULL; top = &timeout->next) {
|
1998-07-16 01:16:47 +00:00
|
|
|
if (timeout->public_id == public_id) {
|
|
|
|
if (mRunningTimeout == timeout) {
|
|
|
|
/* We're running from inside the timeout. Mark this
|
|
|
|
timeout for deferred deletion by the code in
|
|
|
|
win_run_timeout() */
|
|
|
|
timeout->interval = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Delete the timeout from the pending timeout list */
|
|
|
|
*top = timeout->next;
|
|
|
|
if (timeout->timer) {
|
|
|
|
timeout->timer->Cancel();
|
|
|
|
NS_RELEASE(timeout->timer);
|
|
|
|
DropTimeout(timeout);
|
|
|
|
}
|
|
|
|
DropTimeout(timeout);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::ClearTimeout(PRInt32 aTimerID)
|
|
|
|
{
|
|
|
|
return ClearTimeoutOrInterval(aTimerID);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::ClearInterval(PRInt32 aTimerID)
|
|
|
|
{
|
|
|
|
return ClearTimeoutOrInterval(aTimerID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GlobalWindowImpl::ClearAllTimeouts()
|
|
|
|
{
|
|
|
|
nsTimeoutImpl *timeout, *next;
|
|
|
|
|
|
|
|
for (timeout = mTimeouts; timeout; timeout = next) {
|
|
|
|
/* If RunTimeout() is higher up on the stack for this
|
|
|
|
window, e.g. as a result of document.write from a timeout,
|
|
|
|
then we need to reset the list insertion point for
|
|
|
|
newly-created timeouts in case the user adds a timeout,
|
|
|
|
before we pop the stack back to RunTimeout. */
|
1999-06-11 21:49:41 +00:00
|
|
|
if (mRunningTimeout == timeout) {
|
1998-07-16 01:16:47 +00:00
|
|
|
mTimeoutInsertionPoint = nsnull;
|
1999-06-11 21:49:41 +00:00
|
|
|
}
|
1998-07-16 01:16:47 +00:00
|
|
|
|
|
|
|
next = timeout->next;
|
|
|
|
if (timeout->timer) {
|
|
|
|
timeout->timer->Cancel();
|
|
|
|
NS_RELEASE(timeout->timer);
|
|
|
|
// Drop the count since the timer isn't going to hold on
|
|
|
|
// anymore.
|
|
|
|
DropTimeout(timeout);
|
|
|
|
}
|
|
|
|
// Drop the count since we're removing it from the list.
|
|
|
|
DropTimeout(timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
mTimeouts = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GlobalWindowImpl::HoldTimeout(nsTimeoutImpl *aTimeout)
|
|
|
|
{
|
|
|
|
aTimeout->ref_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-07-08 23:02:07 +00:00
|
|
|
GlobalWindowImpl::DropTimeout(nsTimeoutImpl *aTimeout,
|
|
|
|
nsIScriptContext* aContext)
|
1998-07-16 01:16:47 +00:00
|
|
|
{
|
|
|
|
JSContext *cx;
|
|
|
|
|
|
|
|
if (--aTimeout->ref_count > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-07-12 23:40:01 +00:00
|
|
|
cx = (JSContext *)(aContext ? aContext : mContext)->GetNativeContext();
|
1998-07-16 01:16:47 +00:00
|
|
|
|
|
|
|
if (aTimeout->expr) {
|
1999-07-12 23:40:01 +00:00
|
|
|
JS_RemoveRoot(cx, &aTimeout->expr);
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
else if (aTimeout->funobj) {
|
|
|
|
JS_RemoveRoot(cx, &aTimeout->funobj);
|
|
|
|
if (aTimeout->argv) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < aTimeout->argc; i++)
|
|
|
|
JS_RemoveRoot(cx, &aTimeout->argv[i]);
|
|
|
|
PR_FREEIF(aTimeout->argv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(aTimeout->timer);
|
|
|
|
PR_FREEIF(aTimeout->filename);
|
|
|
|
NS_IF_RELEASE(aTimeout->window);
|
|
|
|
PR_DELETE(aTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GlobalWindowImpl::InsertTimeoutIntoList(nsTimeoutImpl **aList,
|
|
|
|
nsTimeoutImpl *aTimeout)
|
|
|
|
{
|
|
|
|
nsTimeoutImpl *to;
|
|
|
|
|
|
|
|
while ((to = *aList) != nsnull) {
|
|
|
|
if (LL_CMP(to->when, >, aTimeout->when))
|
|
|
|
break;
|
|
|
|
aList = &to->next;
|
|
|
|
}
|
|
|
|
aTimeout->next = to;
|
|
|
|
*aList = aTimeout;
|
|
|
|
// Increment the ref_count since we're in the list
|
|
|
|
HoldTimeout(aTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGlobalWindow_RunTimeout(nsITimer *aTimer, void *aClosure)
|
|
|
|
{
|
|
|
|
nsTimeoutImpl *timeout = (nsTimeoutImpl *)aClosure;
|
|
|
|
|
1999-06-11 21:49:41 +00:00
|
|
|
if (timeout->window->RunTimeout(timeout)) {
|
|
|
|
// Drop the ref_count since the timer won't be holding on to the
|
|
|
|
// timeout struct anymore
|
|
|
|
timeout->window->DropTimeout(timeout);
|
|
|
|
}
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
1999-06-11 21:49:41 +00:00
|
|
|
PRBool
|
1998-07-16 01:16:47 +00:00
|
|
|
GlobalWindowImpl::RunTimeout(nsTimeoutImpl *aTimeout)
|
|
|
|
{
|
|
|
|
nsTimeoutImpl *next, *timeout;
|
|
|
|
nsTimeoutImpl *last_expired_timeout;
|
|
|
|
nsTimeoutImpl dummy_timeout;
|
|
|
|
JSContext *cx;
|
|
|
|
PRInt64 now;
|
|
|
|
jsval result;
|
|
|
|
nsITimer *timer;
|
|
|
|
|
1999-07-08 23:02:07 +00:00
|
|
|
/* Make sure that the window or the script context don't go away as
|
|
|
|
a result of running timeouts */
|
1999-06-11 21:49:41 +00:00
|
|
|
GlobalWindowImpl* temp = this;
|
|
|
|
NS_ADDREF(temp);
|
1999-07-08 23:02:07 +00:00
|
|
|
nsIScriptContext* tempContext = mContext;
|
|
|
|
NS_ADDREF(tempContext);
|
1999-06-11 21:49:41 +00:00
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
timer = aTimeout->timer;
|
|
|
|
cx = (JSContext *)mContext->GetNativeContext();
|
|
|
|
|
1999-07-12 23:40:01 +00:00
|
|
|
/* A native timer has gone off. See which of our timeouts need
|
|
|
|
servicing */
|
1998-07-16 01:16:47 +00:00
|
|
|
LL_I2L(now, PR_IntervalNow());
|
|
|
|
|
|
|
|
/* The timeout list is kept in deadline order. Discover the
|
|
|
|
latest timeout whose deadline has expired. On some platforms,
|
|
|
|
native timeout events fire "early", so we need to test the
|
|
|
|
timer as well as the deadline. */
|
|
|
|
last_expired_timeout = nsnull;
|
|
|
|
for (timeout = mTimeouts; timeout; timeout = timeout->next) {
|
|
|
|
if ((timeout == aTimeout) || !LL_CMP(timeout->when, >, now))
|
|
|
|
last_expired_timeout = timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Maybe the timeout that the event was fired for has been deleted
|
|
|
|
and there are no others timeouts with deadlines that make them
|
|
|
|
eligible for execution yet. Go away. */
|
1999-06-11 21:49:41 +00:00
|
|
|
if (!last_expired_timeout) {
|
|
|
|
NS_RELEASE(temp);
|
1999-07-08 23:02:07 +00:00
|
|
|
NS_RELEASE(tempContext);
|
1999-06-11 21:49:41 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-07-16 01:16:47 +00:00
|
|
|
|
|
|
|
/* Insert a dummy timeout into the list of timeouts between the portion
|
|
|
|
of the list that we are about to process now and those timeouts that
|
|
|
|
will be processed in a future call to win_run_timeout(). This dummy
|
|
|
|
timeout serves as the head of the list for any timeouts inserted as
|
|
|
|
a result of running a timeout. */
|
|
|
|
dummy_timeout.timer = NULL;
|
|
|
|
dummy_timeout.public_id = 0;
|
|
|
|
dummy_timeout.next = last_expired_timeout->next;
|
|
|
|
last_expired_timeout->next = &dummy_timeout;
|
|
|
|
|
|
|
|
/* Don't let ClearWindowTimeouts throw away our stack-allocated
|
|
|
|
dummy timeout. */
|
|
|
|
dummy_timeout.ref_count = 2;
|
|
|
|
|
|
|
|
mTimeoutInsertionPoint = &dummy_timeout.next;
|
|
|
|
|
|
|
|
for (timeout = mTimeouts; timeout != &dummy_timeout; timeout = next) {
|
|
|
|
next = timeout->next;
|
|
|
|
|
|
|
|
/* Hold the timeout in case expr or funobj releases its doc. */
|
1999-06-11 21:49:41 +00:00
|
|
|
HoldTimeout(timeout);
|
1998-07-16 01:16:47 +00:00
|
|
|
mRunningTimeout = timeout;
|
|
|
|
|
|
|
|
if (timeout->expr) {
|
|
|
|
/* Evaluate the timeout expression. */
|
1999-03-12 22:24:30 +00:00
|
|
|
#if 0
|
|
|
|
// V says it would be nice if we could have a chokepoint
|
|
|
|
// for calling scripts instead of making a bunch of
|
|
|
|
// ScriptEvaluated() calls to clean things up. MMP
|
|
|
|
PRBool isundefined;
|
|
|
|
mContext->EvaluateString(nsAutoString(timeout->expr),
|
|
|
|
timeout->filename,
|
|
|
|
timeout->lineno, nsAutoString(""), &isundefined);
|
|
|
|
#endif
|
1999-07-12 23:40:01 +00:00
|
|
|
JS_EvaluateUCScriptForPrincipals(cx,
|
|
|
|
(JSObject *)mScriptObject,
|
|
|
|
timeout->principals,
|
|
|
|
JS_GetStringChars(timeout->expr),
|
|
|
|
JS_GetStringLength(timeout->expr),
|
|
|
|
timeout->filename,
|
|
|
|
timeout->lineno,
|
|
|
|
&result);
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
PRInt64 lateness64;
|
|
|
|
PRInt32 lateness;
|
|
|
|
|
|
|
|
/* Add "secret" final argument that indicates timeout
|
|
|
|
lateness in milliseconds */
|
|
|
|
LL_SUB(lateness64, now, timeout->when);
|
|
|
|
LL_L2I(lateness, lateness64);
|
|
|
|
lateness = PR_IntervalToMilliseconds(lateness);
|
|
|
|
timeout->argv[timeout->argc] = INT_TO_JSVAL((jsint)lateness);
|
|
|
|
JS_CallFunctionValue(cx, (JSObject *)mScriptObject,
|
|
|
|
OBJECT_TO_JSVAL(timeout->funobj),
|
|
|
|
timeout->argc + 1, timeout->argv, &result);
|
|
|
|
}
|
|
|
|
|
1999-07-08 23:02:07 +00:00
|
|
|
tempContext->ScriptEvaluated();
|
1999-03-12 22:24:30 +00:00
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
mRunningTimeout = nsnull;
|
1999-06-11 21:49:41 +00:00
|
|
|
/* If the temporary reference is the only one that is keeping
|
|
|
|
the timeout around, the document was released and we should
|
|
|
|
restart this function. */
|
|
|
|
if (timeout->ref_count == 1) {
|
1999-07-08 23:02:07 +00:00
|
|
|
DropTimeout(timeout, tempContext);
|
1999-06-11 21:49:41 +00:00
|
|
|
NS_RELEASE(temp);
|
1999-07-08 23:02:07 +00:00
|
|
|
NS_RELEASE(tempContext);
|
1999-06-11 21:49:41 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-07-08 23:02:07 +00:00
|
|
|
DropTimeout(timeout, tempContext);
|
1998-07-16 01:16:47 +00:00
|
|
|
|
|
|
|
/* If we have a regular interval timer, we re-fire the
|
|
|
|
* timeout, accounting for clock drift.
|
|
|
|
*/
|
|
|
|
if (timeout->interval) {
|
|
|
|
/* Compute time to next timeout for interval timer. */
|
|
|
|
PRInt32 delay32;
|
|
|
|
PRInt64 interval, delay;
|
|
|
|
LL_I2L(interval, PR_MillisecondsToInterval(timeout->interval));
|
|
|
|
LL_ADD(timeout->when, timeout->when, interval);
|
|
|
|
LL_I2L(now, PR_IntervalNow());
|
|
|
|
LL_SUB(delay, timeout->when, now);
|
|
|
|
LL_L2I(delay32, delay);
|
|
|
|
|
|
|
|
/* If the next interval timeout is already supposed to
|
|
|
|
* have happened then run the timeout immediately.
|
|
|
|
*/
|
|
|
|
if (delay32 < 0) {
|
|
|
|
delay32 = 0;
|
|
|
|
}
|
|
|
|
delay32 = PR_IntervalToMilliseconds(delay32);
|
|
|
|
|
|
|
|
NS_IF_RELEASE(timeout->timer);
|
|
|
|
|
|
|
|
/* Reschedule timeout. Account for possible error return in
|
|
|
|
code below that checks for zero toid. */
|
|
|
|
nsresult err = NS_NewTimer(&timeout->timer);
|
|
|
|
if (NS_OK != err) {
|
1999-06-11 21:49:41 +00:00
|
|
|
NS_RELEASE(temp);
|
1999-07-08 23:02:07 +00:00
|
|
|
NS_RELEASE(tempContext);
|
1999-06-11 21:49:41 +00:00
|
|
|
return PR_TRUE;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = timeout->timer->Init(nsGlobalWindow_RunTimeout, timeout,
|
|
|
|
delay32);
|
|
|
|
if (NS_OK != err) {
|
1999-06-11 21:49:41 +00:00
|
|
|
NS_RELEASE(temp);
|
1999-07-08 23:02:07 +00:00
|
|
|
NS_RELEASE(tempContext);
|
1999-06-11 21:49:41 +00:00
|
|
|
return PR_TRUE;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
// Increment ref_count to indicate that this timer is holding
|
|
|
|
// on to the timeout struct.
|
|
|
|
HoldTimeout(timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Running a timeout can cause another timeout to be deleted,
|
|
|
|
so we need to reset the pointer to the following timeout. */
|
|
|
|
next = timeout->next;
|
|
|
|
mTimeouts = next;
|
|
|
|
// Drop timeout struct since it's out of the list
|
1999-07-08 23:02:07 +00:00
|
|
|
DropTimeout(timeout, tempContext);
|
1998-07-16 01:16:47 +00:00
|
|
|
|
|
|
|
/* Free the timeout if this is not a repeating interval
|
|
|
|
* timeout (or if it was an interval timeout, but we were
|
|
|
|
* unsuccessful at rescheduling it.)
|
|
|
|
*/
|
|
|
|
if (timeout->interval && timeout->timer) {
|
|
|
|
/* Reschedule an interval timeout */
|
|
|
|
/* Insert interval timeout onto list sorted in deadline order. */
|
|
|
|
InsertTimeoutIntoList(mTimeoutInsertionPoint, timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Take the dummy timeout off the head of the list */
|
|
|
|
mTimeouts = dummy_timeout.next;
|
|
|
|
mTimeoutInsertionPoint = nsnull;
|
1999-06-11 21:49:41 +00:00
|
|
|
|
1999-07-08 23:02:07 +00:00
|
|
|
/* Get rid of our temporary reference to ourselves and the
|
|
|
|
script context */
|
1999-06-11 21:49:41 +00:00
|
|
|
NS_RELEASE(temp);
|
1999-07-08 23:02:07 +00:00
|
|
|
NS_RELEASE(tempContext);
|
1999-06-11 21:49:41 +00:00
|
|
|
return PR_TRUE;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *kSetIntervalStr = "setInterval";
|
|
|
|
static const char *kSetTimeoutStr = "setTimeout";
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GlobalWindowImpl::SetTimeoutOrInterval(JSContext *cx,
|
|
|
|
jsval *argv,
|
|
|
|
PRUint32 argc,
|
|
|
|
PRInt32* aReturn,
|
|
|
|
PRBool aIsInterval)
|
|
|
|
{
|
1999-07-12 23:40:01 +00:00
|
|
|
JSString *expr = nsnull;
|
1998-07-16 01:16:47 +00:00
|
|
|
JSObject *funobj = nsnull;
|
|
|
|
nsTimeoutImpl *timeout, **insertion_point;
|
|
|
|
jsdouble interval;
|
|
|
|
PRInt64 now, delta;
|
1999-07-07 07:50:03 +00:00
|
|
|
JSPrincipals* principals;
|
|
|
|
|
|
|
|
if (NS_FAILED(GetPrincipals((void**)&principals))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1998-07-16 01:16:47 +00:00
|
|
|
|
1999-07-12 23:40:01 +00:00
|
|
|
if (argc < 2) {
|
|
|
|
JS_ReportError(cx, "Function %s requires at least 2 parameters",
|
|
|
|
aIsInterval ? kSetIntervalStr : kSetTimeoutStr);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1998-07-16 01:16:47 +00:00
|
|
|
|
1999-07-12 23:40:01 +00:00
|
|
|
if (!JS_ValueToNumber(cx, argv[1], &interval)) {
|
|
|
|
JS_ReportError(cx,
|
|
|
|
"Second argument to %s must be a millisecond interval",
|
|
|
|
aIsInterval ? kSetIntervalStr : kSetTimeoutStr);
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (JS_TypeOfValue(cx, argv[0])) {
|
|
|
|
case JSTYPE_FUNCTION:
|
|
|
|
funobj = JSVAL_TO_OBJECT(argv[0]);
|
|
|
|
break;
|
|
|
|
case JSTYPE_STRING:
|
|
|
|
case JSTYPE_OBJECT:
|
|
|
|
if (!(expr = JS_ValueToString(cx, argv[0])))
|
1998-07-16 01:16:47 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
1999-07-12 23:40:01 +00:00
|
|
|
if (nsnull == expr)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
argv[0] = STRING_TO_JSVAL(expr);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
JS_ReportError(cx, "useless %s call (missing quotes around argument?)",
|
|
|
|
aIsInterval ? kSetIntervalStr : kSetTimeoutStr);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
timeout = PR_NEWZAP(nsTimeoutImpl);
|
|
|
|
if (nsnull == timeout)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
// Initial ref_count to indicate that this timeout struct will
|
|
|
|
// be held as the closure of a timer.
|
|
|
|
timeout->ref_count = 1;
|
|
|
|
if (aIsInterval)
|
|
|
|
timeout->interval = (PRInt32)interval;
|
|
|
|
if (expr) {
|
|
|
|
if (!JS_AddNamedRoot(cx, &timeout->expr, "timeout.expr")) {
|
|
|
|
PR_DELETE(timeout);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
1999-07-12 23:40:01 +00:00
|
|
|
timeout->expr = expr;
|
|
|
|
}
|
|
|
|
else if (funobj) {
|
|
|
|
int i;
|
1998-07-16 01:16:47 +00:00
|
|
|
|
1999-07-12 23:40:01 +00:00
|
|
|
/* Leave an extra slot for a secret final argument that
|
|
|
|
indicates to the called function how "late" the timeout is. */
|
|
|
|
timeout->argv = (jsval *)PR_MALLOC((argc - 1) * sizeof(jsval));
|
|
|
|
if (nsnull == timeout->argv) {
|
|
|
|
DropTimeout(timeout);
|
1998-07-16 01:16:47 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
1999-07-12 23:40:01 +00:00
|
|
|
if (!JS_AddNamedRoot(cx, &timeout->funobj, "timeout.funobj")) {
|
|
|
|
DropTimeout(timeout);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1998-07-16 01:16:47 +00:00
|
|
|
timeout->funobj = funobj;
|
1999-07-12 23:40:01 +00:00
|
|
|
|
|
|
|
timeout->argc = 0;
|
|
|
|
for (i = 2; (PRUint32)i < argc; i++) {
|
|
|
|
timeout->argv[i - 2] = argv[i];
|
|
|
|
if (!JS_AddNamedRoot(cx, &timeout->argv[i - 2], "timeout.argv[i]")) {
|
1998-07-16 01:16:47 +00:00
|
|
|
DropTimeout(timeout);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-07-12 23:40:01 +00:00
|
|
|
timeout->argc++;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
1999-07-12 23:40:01 +00:00
|
|
|
}
|
1998-07-16 01:16:47 +00:00
|
|
|
|
1999-07-12 23:40:01 +00:00
|
|
|
timeout->principals = principals;
|
|
|
|
|
|
|
|
LL_I2L(now, PR_IntervalNow());
|
|
|
|
LL_D2L(delta, PR_MillisecondsToInterval((PRUint32)interval));
|
|
|
|
LL_ADD(timeout->when, now, delta);
|
1998-07-16 01:16:47 +00:00
|
|
|
|
1999-07-12 23:40:01 +00:00
|
|
|
nsresult err = NS_NewTimer(&timeout->timer);
|
|
|
|
if (NS_OK != err) {
|
|
|
|
DropTimeout(timeout);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = timeout->timer->Init(nsGlobalWindow_RunTimeout, timeout,
|
|
|
|
(PRInt32)interval);
|
|
|
|
if (NS_OK != err) {
|
|
|
|
DropTimeout(timeout);
|
|
|
|
return err;
|
|
|
|
}
|
1998-07-16 01:16:47 +00:00
|
|
|
|
1999-07-12 23:40:01 +00:00
|
|
|
timeout->window = this;
|
|
|
|
NS_ADDREF(this);
|
1998-07-16 01:16:47 +00:00
|
|
|
|
1999-07-12 23:40:01 +00:00
|
|
|
insertion_point = (mTimeoutInsertionPoint == NULL)
|
|
|
|
? &mTimeouts
|
|
|
|
: mTimeoutInsertionPoint;
|
|
|
|
|
|
|
|
InsertTimeoutIntoList(insertion_point, timeout);
|
|
|
|
timeout->public_id = ++mTimeoutPublicIdCounter;
|
|
|
|
*aReturn = timeout->public_id;
|
1998-07-16 01:16:47 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::SetTimeout(JSContext *cx,
|
|
|
|
jsval *argv,
|
|
|
|
PRUint32 argc,
|
|
|
|
PRInt32* aReturn)
|
|
|
|
{
|
|
|
|
return SetTimeoutOrInterval(cx, argv, argc, aReturn, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::SetInterval(JSContext *cx,
|
|
|
|
jsval *argv,
|
|
|
|
PRUint32 argc,
|
|
|
|
PRInt32* aReturn)
|
|
|
|
{
|
|
|
|
return SetTimeoutOrInterval(cx, argv, argc, aReturn, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
1998-08-07 04:45:03 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::Open(JSContext *cx,
|
|
|
|
jsval *argv,
|
|
|
|
PRUint32 argc,
|
1998-09-03 01:19:58 +00:00
|
|
|
nsIDOMWindow** aReturn)
|
1998-08-07 04:45:03 +00:00
|
|
|
{
|
1999-05-17 18:52:21 +00:00
|
|
|
return OpenInternal(cx, argv, argc, PR_FALSE, aReturn);
|
|
|
|
}
|
|
|
|
|
|
|
|
// like Open, but attaches to the new window any extra parameters past [features]
|
|
|
|
// as a JS property named "arguments"
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::OpenDialog(JSContext *cx,
|
|
|
|
jsval *argv,
|
|
|
|
PRUint32 argc,
|
|
|
|
nsIDOMWindow** aReturn)
|
|
|
|
{
|
|
|
|
return OpenInternal(cx, argv, argc, PR_TRUE, aReturn);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GlobalWindowImpl::OpenInternal(JSContext *cx,
|
|
|
|
jsval *argv,
|
|
|
|
PRUint32 argc,
|
1999-08-07 02:51:03 +00:00
|
|
|
PRBool aDialog,
|
1999-05-17 18:52:21 +00:00
|
|
|
nsIDOMWindow** aReturn)
|
|
|
|
{
|
|
|
|
PRUint32 chromeFlags;
|
1998-09-18 00:35:55 +00:00
|
|
|
nsAutoString mAbsURL, name;
|
1998-08-07 04:45:03 +00:00
|
|
|
JSString* str;
|
1999-05-17 18:52:21 +00:00
|
|
|
char* options;
|
1998-09-03 01:19:58 +00:00
|
|
|
*aReturn = nsnull;
|
1998-08-07 04:45:03 +00:00
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
JSString *mJSStrURL = JS_ValueToString(cx, argv[0]);
|
1998-09-03 01:19:58 +00:00
|
|
|
if (nsnull == mJSStrURL || nsnull == mDocument) {
|
1998-08-07 04:45:03 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1998-09-03 01:19:58 +00:00
|
|
|
|
|
|
|
nsAutoString mURL, mEmpty;
|
1999-06-23 03:29:44 +00:00
|
|
|
nsIURI* mDocURL = 0;
|
1998-09-03 01:19:58 +00:00
|
|
|
nsIDocument* mDoc;
|
|
|
|
|
1998-08-07 04:45:03 +00:00
|
|
|
mURL.SetString(JS_GetStringChars(mJSStrURL));
|
1998-09-03 01:19:58 +00:00
|
|
|
|
|
|
|
if (NS_OK == mDocument->QueryInterface(kIDocumentIID, (void**)&mDoc)) {
|
|
|
|
mDocURL = mDoc->GetDocumentURL();
|
|
|
|
NS_RELEASE(mDoc);
|
|
|
|
}
|
1999-06-18 17:34:08 +00:00
|
|
|
|
|
|
|
#ifndef NECKO
|
1998-09-03 01:19:58 +00:00
|
|
|
if (NS_OK != NS_MakeAbsoluteURL(mDocURL, mEmpty, mURL, mAbsURL)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-06-18 17:34:08 +00:00
|
|
|
#else
|
|
|
|
nsresult rv;
|
|
|
|
nsIURI *baseUri = nsnull;
|
|
|
|
rv = mDocURL->QueryInterface(nsIURI::GetIID(), (void**)&baseUri);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-07-11 15:46:10 +00:00
|
|
|
rv = NS_MakeAbsoluteURI(mURL, baseUri, mAbsURL);
|
1999-06-18 17:34:08 +00:00
|
|
|
NS_RELEASE(baseUri);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
#endif // NECKO
|
|
|
|
|
1998-08-07 04:45:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sanity-check the optional window_name argument. */
|
|
|
|
if (argc > 1) {
|
|
|
|
JSString *mJSStrName = JS_ValueToString(cx, argv[1]);
|
|
|
|
if (nsnull == mJSStrName) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1998-09-18 00:35:55 +00:00
|
|
|
name.SetString(JS_GetStringChars(mJSStrName));
|
1998-08-07 04:45:03 +00:00
|
|
|
|
1998-09-18 00:35:55 +00:00
|
|
|
if (NS_OK != CheckWindowName(cx, name)) {
|
1998-08-07 04:45:03 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
1998-09-18 00:35:55 +00:00
|
|
|
name.SetString("");
|
1998-08-07 04:45:03 +00:00
|
|
|
}
|
|
|
|
|
1999-05-17 18:52:21 +00:00
|
|
|
options = nsnull;
|
1998-08-07 04:45:03 +00:00
|
|
|
if (argc > 2) {
|
|
|
|
if (!(str = JS_ValueToString(cx, argv[2]))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-05-17 18:52:21 +00:00
|
|
|
options = JS_GetStringBytes(str);
|
1998-08-07 04:45:03 +00:00
|
|
|
}
|
1999-08-07 02:51:03 +00:00
|
|
|
chromeFlags = CalculateChromeFlags(options, aDialog);
|
1998-08-07 04:45:03 +00:00
|
|
|
|
1999-04-20 22:35:11 +00:00
|
|
|
nsIWebShell *newOuterShell = nsnull;
|
1999-05-17 18:52:21 +00:00
|
|
|
nsIWebShellContainer *webShellContainer;
|
|
|
|
|
1998-08-07 04:45:03 +00:00
|
|
|
/* XXX check for existing window of same name. If exists, set url and
|
|
|
|
* update chrome */
|
1999-06-15 03:17:11 +00:00
|
|
|
if ((nsnull != mWebShell) &&
|
|
|
|
(NS_OK == mWebShell->GetContainer(webShellContainer)) &&
|
|
|
|
(nsnull != webShellContainer)) {
|
1999-07-06 23:13:10 +00:00
|
|
|
|
|
|
|
PRBool windowIsNew;
|
|
|
|
|
1998-09-18 00:35:55 +00:00
|
|
|
// Check for existing window of same name.
|
1999-07-06 23:13:10 +00:00
|
|
|
windowIsNew = PR_FALSE;
|
1999-04-20 22:35:11 +00:00
|
|
|
webShellContainer->FindWebShellWithName(name.GetUnicode(), newOuterShell);
|
|
|
|
if (nsnull == newOuterShell) {
|
1999-07-12 23:40:01 +00:00
|
|
|
// No window of that name, and we are allowed to create a new one now.
|
1999-05-17 18:52:21 +00:00
|
|
|
webShellContainer->NewWebShell(chromeFlags, PR_FALSE, newOuterShell);
|
1999-07-06 23:13:10 +00:00
|
|
|
windowIsNew = PR_TRUE;
|
1998-09-18 00:35:55 +00:00
|
|
|
}
|
1999-04-19 21:08:12 +00:00
|
|
|
|
1999-04-20 22:35:11 +00:00
|
|
|
if (nsnull != newOuterShell) {
|
1999-05-17 18:52:21 +00:00
|
|
|
if (NS_SUCCEEDED(ReadyOpenedWebShell(newOuterShell, aReturn))) {
|
1999-08-07 02:51:03 +00:00
|
|
|
if (aDialog && argc > 3)
|
1999-05-17 18:52:21 +00:00
|
|
|
AttachArguments(*aReturn, argv+3, argc-3);
|
|
|
|
newOuterShell->SetName(name.GetUnicode());
|
|
|
|
newOuterShell->LoadURL(mAbsURL.GetUnicode());
|
1999-08-07 02:51:03 +00:00
|
|
|
SizeAndShowOpenedWebShell(newOuterShell, options, windowIsNew, aDialog);
|
1999-05-17 18:52:21 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(newOuterShell);
|
1998-09-09 01:19:11 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(webShellContainer);
|
|
|
|
}
|
|
|
|
|
1999-05-17 18:52:21 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// attach the given array of JS values to the given window, as a property array
|
|
|
|
// named "arguments"
|
|
|
|
nsresult
|
|
|
|
GlobalWindowImpl::AttachArguments(nsIDOMWindow *aWindow, jsval *argv, PRUint32 argc)
|
|
|
|
{
|
|
|
|
if (argc == 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// copy the extra parameters into a JS Array and attach it
|
|
|
|
JSObject *args;
|
|
|
|
JSObject *scriptObject;
|
|
|
|
nsIScriptGlobalObject *scriptGlobal;
|
|
|
|
nsIScriptObjectOwner *owner;
|
|
|
|
JSContext *jsContext;
|
|
|
|
nsIScriptContext *scriptContext;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(aWindow->QueryInterface(kIScriptGlobalObjectIID, (void **)&scriptGlobal))) {
|
|
|
|
scriptGlobal->GetContext(&scriptContext);
|
|
|
|
if (scriptContext) {
|
|
|
|
jsContext = (JSContext *) scriptContext->GetNativeContext();
|
|
|
|
if (NS_SUCCEEDED(aWindow->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner))) {
|
|
|
|
owner->GetScriptObject(scriptContext, (void **) &scriptObject);
|
|
|
|
args = JS_NewArrayObject(jsContext, argc, argv);
|
|
|
|
if (args) {
|
|
|
|
jsval argsVal = OBJECT_TO_JSVAL(args);
|
|
|
|
// JS_DefineProperty(jsContext, scriptObject, "arguments",
|
|
|
|
// argsVal, NULL, NULL, JSPROP_PERMANENT);
|
|
|
|
JS_SetProperty(jsContext, scriptObject, "arguments", &argsVal);
|
|
|
|
}
|
|
|
|
NS_RELEASE(owner);
|
|
|
|
}
|
|
|
|
NS_RELEASE(scriptContext);
|
1998-12-29 03:53:07 +00:00
|
|
|
}
|
1999-05-17 18:52:21 +00:00
|
|
|
NS_RELEASE(scriptGlobal);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-08-07 04:45:03 +00:00
|
|
|
|
|
|
|
|
1999-08-07 02:51:03 +00:00
|
|
|
/**
|
|
|
|
* Calculate the chrome bitmask from a string list of features.
|
|
|
|
* @param aFeatures a string containing a list of named chrome features
|
|
|
|
* @param aDialog affects the assumptions made about unnamed features
|
|
|
|
* @return the chrome bitmask
|
|
|
|
*/
|
1999-05-17 18:52:21 +00:00
|
|
|
PRUint32
|
1999-08-07 02:51:03 +00:00
|
|
|
GlobalWindowImpl::CalculateChromeFlags(char *aFeatures, PRBool aDialog) {
|
1998-08-07 04:45:03 +00:00
|
|
|
|
1999-07-27 22:42:34 +00:00
|
|
|
PRUint32 chromeFlags;
|
1998-09-04 00:46:06 +00:00
|
|
|
|
1999-05-17 18:52:21 +00:00
|
|
|
if (nsnull == aFeatures)
|
1999-08-07 02:51:03 +00:00
|
|
|
if (aDialog)
|
|
|
|
return NS_CHROME_ALL_CHROME |
|
|
|
|
NS_CHROME_OPEN_AS_DIALOG | NS_CHROME_OPEN_AS_CHROME;
|
|
|
|
else
|
|
|
|
return NS_CHROME_ALL_CHROME;
|
1998-08-07 04:45:03 +00:00
|
|
|
|
1999-07-08 02:04:32 +00:00
|
|
|
PRBool presenceFlag = PR_FALSE;
|
1999-07-27 06:34:25 +00:00
|
|
|
|
1999-08-07 02:51:03 +00:00
|
|
|
/* This function has become complicated since browser windows and
|
|
|
|
dialogs diverged. The difference is, browser windows assume all
|
|
|
|
chrome not explicitly mentioned is off, if the features string
|
|
|
|
is not null. Exceptions are some OS border chrome new with Mozilla.
|
|
|
|
Dialogs interpret a (mostly) empty features string to mean
|
|
|
|
"OS's choice," and also support an "all" flag explicitly disallowed
|
|
|
|
in the standards-compliant window.(normal)open. */
|
|
|
|
|
1999-07-27 22:42:34 +00:00
|
|
|
chromeFlags = NS_CHROME_WINDOW_BORDERS_ON;
|
1999-08-07 02:51:03 +00:00
|
|
|
if (aDialog && WinHasOption(aFeatures, "all", presenceFlag))
|
|
|
|
chromeFlags = NS_CHROME_ALL_CHROME;
|
|
|
|
|
|
|
|
/* Next, allow explicitly named options to override the initial settings */
|
1999-07-27 22:42:34 +00:00
|
|
|
|
1999-07-27 06:34:25 +00:00
|
|
|
chromeFlags |= WinHasOption(aFeatures, "titlebar", presenceFlag) ? NS_CHROME_TITLEBAR_ON : 0;
|
|
|
|
chromeFlags |= WinHasOption(aFeatures, "close", presenceFlag) ? NS_CHROME_WINDOW_CLOSE_ON : 0;
|
1999-07-08 02:04:32 +00:00
|
|
|
chromeFlags |= WinHasOption(aFeatures, "toolbar", presenceFlag) ? NS_CHROME_TOOL_BAR_ON : 0;
|
|
|
|
chromeFlags |= WinHasOption(aFeatures, "location", presenceFlag) ? NS_CHROME_LOCATION_BAR_ON : 0;
|
|
|
|
chromeFlags |= (WinHasOption(aFeatures, "directories", presenceFlag) | WinHasOption(aFeatures, "personalbar", presenceFlag))
|
1999-05-17 18:52:21 +00:00
|
|
|
? NS_CHROME_PERSONAL_TOOLBAR_ON : 0;
|
1999-07-08 02:04:32 +00:00
|
|
|
chromeFlags |= WinHasOption(aFeatures, "status", presenceFlag) ? NS_CHROME_STATUS_BAR_ON : 0;
|
|
|
|
chromeFlags |= WinHasOption(aFeatures, "menubar", presenceFlag) ? NS_CHROME_MENU_BAR_ON : 0;
|
|
|
|
chromeFlags |= WinHasOption(aFeatures, "scrollbars", presenceFlag) ? NS_CHROME_SCROLLBARS_ON : 0;
|
|
|
|
chromeFlags |= WinHasOption(aFeatures, "resizable", presenceFlag) ? NS_CHROME_WINDOW_RESIZE_ON : 0;
|
1999-08-07 02:51:03 +00:00
|
|
|
|
|
|
|
/* OK.
|
|
|
|
Normal browser windows, in spite of a stated pattern of turning off
|
|
|
|
all chrome not mentioned explicitly, will want the new OS chrome (window
|
|
|
|
borders, titlebars, closebox) on, unless explicitly turned off.
|
|
|
|
Dialogs, on the other hand, take the absence of any explicit settings
|
|
|
|
to mean "OS' choice." */
|
|
|
|
|
|
|
|
// default titlebar and closebox to "on," if not mentioned at all
|
1999-07-27 06:34:25 +00:00
|
|
|
if (!PL_strcasestr(aFeatures, "titlebar"))
|
|
|
|
chromeFlags |= NS_CHROME_TITLEBAR_ON;
|
|
|
|
if (!PL_strcasestr(aFeatures, "close"))
|
|
|
|
chromeFlags |= NS_CHROME_WINDOW_CLOSE_ON;
|
1998-10-01 22:21:59 +00:00
|
|
|
|
1999-08-07 02:51:03 +00:00
|
|
|
if (aDialog && !presenceFlag)
|
|
|
|
chromeFlags = NS_CHROME_DEFAULT_CHROME;
|
1999-07-28 03:05:35 +00:00
|
|
|
|
1999-08-07 02:51:03 +00:00
|
|
|
/* Finally, once all the above normal chrome has been divined, deal
|
|
|
|
with the features that are more operating hints than appearance
|
|
|
|
instructions. */
|
1998-08-07 04:45:03 +00:00
|
|
|
|
1999-07-08 02:04:32 +00:00
|
|
|
chromeFlags |= WinHasOption(aFeatures, "chrome", presenceFlag) ? NS_CHROME_OPEN_AS_CHROME : 0;
|
|
|
|
chromeFlags |= WinHasOption(aFeatures, "modal", presenceFlag) ? NS_CHROME_MODAL : 0;
|
|
|
|
chromeFlags |= WinHasOption(aFeatures, "dialog", presenceFlag) ? NS_CHROME_OPEN_AS_DIALOG : 0;
|
1999-07-05 19:38:43 +00:00
|
|
|
|
1999-08-07 02:51:03 +00:00
|
|
|
/* and dialogs need to have the last word. assume dialogs are dialogs,
|
|
|
|
and opened as chrome, unless explicitly told otherwise. */
|
|
|
|
if (aDialog) {
|
|
|
|
if (!PL_strcasestr(aFeatures, "dialog"))
|
|
|
|
chromeFlags |= NS_CHROME_OPEN_AS_DIALOG;
|
|
|
|
if (!PL_strcasestr(aFeatures, "chrome"))
|
|
|
|
chromeFlags |= NS_CHROME_OPEN_AS_CHROME;
|
|
|
|
}
|
|
|
|
|
1999-05-17 18:52:21 +00:00
|
|
|
/*z-ordering, history, dependent
|
|
|
|
chromeFlags->topmost = WinHasOption(aFeatures, "alwaysRaised");
|
1999-08-07 02:51:03 +00:00
|
|
|
chromeFlags->bottommost = WinHasOption(aFeatures, "alwaysLowered");
|
1999-05-17 18:52:21 +00:00
|
|
|
chromeFlags->z_lock = WinHasOption(aFeatures, "z-lock");
|
1999-08-07 02:51:03 +00:00
|
|
|
chromeFlags->is_modal = WinHasOption(aFeatures, "modal");
|
1999-05-17 18:52:21 +00:00
|
|
|
chromeFlags->hide_title_bar = !(WinHasOption(aFeatures, "titlebar"));
|
1999-08-07 02:51:03 +00:00
|
|
|
chromeFlags->dependent = WinHasOption(aFeatures, "dependent");
|
|
|
|
chromeFlags->copy_history = FALSE;
|
1999-05-17 18:52:21 +00:00
|
|
|
*/
|
1998-08-07 04:45:03 +00:00
|
|
|
|
1999-05-17 18:52:21 +00:00
|
|
|
/* Allow disabling of commands only if there is no menubar */
|
|
|
|
/*if (!chromeFlags & NS_CHROME_MENU_BAR_ON) {
|
|
|
|
chromeFlags->disable_commands = !WinHasOption(aFeatures, "hotkeys");
|
|
|
|
if (XP_STRCASESTR(aFeatures,"hotkeys")==NULL)
|
|
|
|
chromeFlags->disable_commands = FALSE;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
/* XXX Add security check on z-ordering, modal, hide title, disable hotkeys */
|
|
|
|
|
|
|
|
/* XXX Add security check for sizing and positioning.
|
|
|
|
* See mozilla/lib/libmocha/lm_win.c for current constraints */
|
|
|
|
|
|
|
|
return chromeFlags;
|
1998-08-07 04:45:03 +00:00
|
|
|
}
|
|
|
|
|
1999-05-17 18:52:21 +00:00
|
|
|
// set the newly opened webshell's (window) size, and show it
|
|
|
|
nsresult
|
1999-08-07 02:51:03 +00:00
|
|
|
GlobalWindowImpl::SizeAndShowOpenedWebShell(nsIWebShell *aOuterShell,
|
|
|
|
char *aFeatures, PRBool aNewWindow, PRBool aDialog)
|
1999-05-14 03:10:51 +00:00
|
|
|
{
|
1999-05-17 18:52:21 +00:00
|
|
|
if (nsnull == aOuterShell)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-05-14 03:10:51 +00:00
|
|
|
|
1999-05-17 18:52:21 +00:00
|
|
|
nsRect defaultBounds;
|
|
|
|
PRInt32 top = 0, left = 0, height = 0, width = 0;
|
|
|
|
nsIBrowserWindow *thisWindow,
|
|
|
|
*openedWindow = nsnull;
|
|
|
|
|
|
|
|
// use this window's size as the default
|
1999-07-06 23:13:10 +00:00
|
|
|
if (aNewWindow && NS_SUCCEEDED(GetBrowserWindowInterface(thisWindow))) {
|
1999-05-17 18:52:21 +00:00
|
|
|
thisWindow->GetWindowBounds(defaultBounds);
|
|
|
|
NS_RELEASE(thisWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the nsIBrowserWindow corresponding to the given aOuterShell
|
|
|
|
nsIWebShell *rootShell;
|
1999-07-06 23:13:10 +00:00
|
|
|
aOuterShell->GetRootWebShellEvenIfChrome(rootShell);
|
|
|
|
if (nsnull != rootShell) {
|
1999-05-17 18:52:21 +00:00
|
|
|
nsIWebShellContainer *newContainer;
|
1999-07-06 23:13:10 +00:00
|
|
|
rootShell->GetContainer(newContainer);
|
|
|
|
if (nsnull != newContainer) {
|
|
|
|
if (NS_FAILED(newContainer->QueryInterface(kIBrowserWindowIID, (void**)&openedWindow)))
|
1999-05-17 18:52:21 +00:00
|
|
|
openedWindow = nsnull;
|
1999-07-06 23:13:10 +00:00
|
|
|
NS_RELEASE(newContainer);
|
|
|
|
}
|
|
|
|
NS_RELEASE(rootShell);
|
|
|
|
}
|
1999-05-17 18:52:21 +00:00
|
|
|
|
|
|
|
// set size
|
|
|
|
if (nsnull != openedWindow) {
|
|
|
|
|
1999-07-06 23:13:10 +00:00
|
|
|
nsRect contentOffsets; // constructor sets all values to 0
|
1999-07-07 00:29:05 +00:00
|
|
|
PRBool sizeSpecified = PR_FALSE;
|
1999-08-07 02:51:03 +00:00
|
|
|
PRUint32 chromeFlags = CalculateChromeFlags(aFeatures, aDialog);
|
|
|
|
PRBool openAsContent = (chromeFlags & NS_CHROME_OPEN_AS_CHROME) == 0;
|
1999-07-06 23:13:10 +00:00
|
|
|
|
|
|
|
// if it's an extant window, we are already our default size
|
|
|
|
if (!aNewWindow)
|
|
|
|
if (openAsContent) {
|
|
|
|
// defaultBounds are the content rect. also, save window size diffs
|
|
|
|
openedWindow->GetWindowBounds(contentOffsets);
|
|
|
|
openedWindow->GetContentBounds(defaultBounds);
|
|
|
|
contentOffsets.x -= defaultBounds.x;
|
|
|
|
contentOffsets.y -= defaultBounds.y;
|
|
|
|
contentOffsets.width -= defaultBounds.width;
|
|
|
|
contentOffsets.height -= defaultBounds.height;
|
|
|
|
} else
|
|
|
|
openedWindow->GetWindowBounds(defaultBounds);
|
1999-07-04 04:09:54 +00:00
|
|
|
|
1999-05-17 18:52:21 +00:00
|
|
|
if (nsnull != aFeatures) {
|
1999-08-07 02:51:03 +00:00
|
|
|
PRBool presenceFlag = PR_FALSE; // Unused. Yuck.
|
1999-07-04 04:09:54 +00:00
|
|
|
if (openAsContent) {
|
1999-07-08 02:04:32 +00:00
|
|
|
width = WinHasOption(aFeatures, "innerWidth", presenceFlag) | WinHasOption(aFeatures, "width", presenceFlag);
|
|
|
|
height = WinHasOption(aFeatures, "innerHeight", presenceFlag) | WinHasOption(aFeatures, "height", presenceFlag);
|
1999-07-04 04:09:54 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Chrome. Look for outerWidth, outerHeight, or width/height
|
1999-07-08 02:04:32 +00:00
|
|
|
width = WinHasOption(aFeatures, "outerWidth", presenceFlag) | WinHasOption(aFeatures, "width", presenceFlag);
|
|
|
|
height = WinHasOption(aFeatures, "outerHeight", presenceFlag) | WinHasOption(aFeatures, "height", presenceFlag);
|
1999-07-04 04:09:54 +00:00
|
|
|
}
|
1999-05-17 18:52:21 +00:00
|
|
|
|
1999-07-08 02:04:32 +00:00
|
|
|
left = WinHasOption(aFeatures, "left", presenceFlag) | WinHasOption(aFeatures, "screenX", presenceFlag);
|
|
|
|
top = WinHasOption(aFeatures, "top", presenceFlag) | WinHasOption(aFeatures, "screenY", presenceFlag);
|
1999-07-06 23:13:10 +00:00
|
|
|
|
|
|
|
if (left)
|
|
|
|
defaultBounds.x = left;
|
|
|
|
if (top)
|
|
|
|
defaultBounds.y = top;
|
1999-07-07 00:29:05 +00:00
|
|
|
if (width) {
|
|
|
|
sizeSpecified = PR_TRUE;
|
1999-07-06 23:13:10 +00:00
|
|
|
defaultBounds.width = width;
|
1999-07-07 00:29:05 +00:00
|
|
|
}
|
|
|
|
if (height) {
|
|
|
|
sizeSpecified = PR_TRUE;
|
1999-07-06 23:13:10 +00:00
|
|
|
defaultBounds.height = height;
|
1999-07-07 00:29:05 +00:00
|
|
|
}
|
1999-05-17 18:52:21 +00:00
|
|
|
}
|
1999-05-14 03:10:51 +00:00
|
|
|
|
1999-05-17 18:52:21 +00:00
|
|
|
// beard: don't resize/reposition the window if it is the same web shell.
|
|
|
|
if (aOuterShell != mWebShell) {
|
1999-07-07 00:29:05 +00:00
|
|
|
|
|
|
|
// whimper. special treatment for windows which will be intrinsically sized.
|
|
|
|
// we can count on a Show() coming through at EndDocumentLoad time, and we
|
|
|
|
// can count on their size being wrong at this point, and flashing. so
|
|
|
|
// delay some things, if this is true.
|
|
|
|
PRBool sizeLater = PR_FALSE;
|
|
|
|
openedWindow->IsIntrinsicallySized(sizeLater);
|
|
|
|
|
1999-07-06 23:13:10 +00:00
|
|
|
if (openAsContent) {
|
|
|
|
openedWindow->SizeWindowTo(defaultBounds.width + contentOffsets.width,
|
|
|
|
defaultBounds.height + contentOffsets.height);
|
|
|
|
// oy. sizing the content makes sense: that's what the user asked for,
|
|
|
|
// however, it doesn't have the desired effect because all sizing
|
|
|
|
// functions eventually end up sizing the window, and the subwindows
|
|
|
|
// used to calculate the appropriate deltas are different. here we use
|
|
|
|
// the HTML content area; the window uses the main webshell. maybe
|
|
|
|
// i could calculate a triple offset, but commenting it out is easier,
|
|
|
|
// and probably effectively the same thing.
|
|
|
|
// openedWindow->SizeContentTo(defaultBounds.width, defaultBounds.height);
|
1999-07-07 00:29:05 +00:00
|
|
|
} else if (sizeSpecified)
|
1999-07-06 23:13:10 +00:00
|
|
|
openedWindow->SizeWindowTo(defaultBounds.width, defaultBounds.height);
|
1999-07-07 00:29:05 +00:00
|
|
|
|
1999-07-06 23:13:10 +00:00
|
|
|
openedWindow->MoveTo(defaultBounds.x + contentOffsets.x,
|
|
|
|
defaultBounds.y + contentOffsets.y);
|
1999-07-07 00:29:05 +00:00
|
|
|
|
1999-07-21 06:37:58 +00:00
|
|
|
if (sizeLater)
|
|
|
|
openedWindow->ShowAfterCreation();
|
|
|
|
else
|
1999-07-07 00:29:05 +00:00
|
|
|
openedWindow->Show();
|
1999-05-17 18:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(openedWindow);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the nsIDOMWindow corresponding to the given nsIWebShell
|
|
|
|
// note this forces the creation of a script context, if one has not already been created
|
|
|
|
// note it also sets the window's opener to this -- because it's just convenient, that's all
|
|
|
|
nsresult
|
|
|
|
GlobalWindowImpl::ReadyOpenedWebShell(nsIWebShell *aWebShell, nsIDOMWindow **aDOMWindow)
|
|
|
|
{
|
|
|
|
nsIScriptContextOwner *newContextOwner = nsnull;
|
|
|
|
nsIScriptGlobalObject *newGlobalObject = nsnull;
|
|
|
|
nsresult res;
|
|
|
|
|
|
|
|
*aDOMWindow = nsnull;
|
|
|
|
res = aWebShell->QueryInterface(kIScriptContextOwnerIID, (void**)&newContextOwner);
|
|
|
|
if (NS_SUCCEEDED(res)) {
|
|
|
|
res = newContextOwner->GetScriptGlobalObject(&newGlobalObject);
|
1999-05-14 03:10:51 +00:00
|
|
|
if (NS_SUCCEEDED(res)) {
|
1999-05-17 18:52:21 +00:00
|
|
|
res = newGlobalObject->QueryInterface(kIDOMWindowIID, (void**)aDOMWindow);
|
|
|
|
newGlobalObject->SetOpenerWindow(this); // damnit
|
|
|
|
NS_RELEASE(newGlobalObject);
|
1999-05-14 03:10:51 +00:00
|
|
|
}
|
1999-05-17 18:52:21 +00:00
|
|
|
NS_RELEASE(newContextOwner);
|
1999-05-14 03:10:51 +00:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
1999-06-26 21:48:29 +00:00
|
|
|
// simple utility conversion routine
|
|
|
|
nsresult
|
|
|
|
GlobalWindowImpl::WebShellToDOMWindow(nsIWebShell *aWebShell, nsIDOMWindow **aDOMWindow)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
NS_ASSERTION(aWebShell, "null in param to WebShellToDOMWindow");
|
|
|
|
NS_ASSERTION(aDOMWindow, "null out param to WebShellToDOMWindow");
|
|
|
|
|
|
|
|
*aDOMWindow = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptContextOwner> owner = do_QueryInterface(aWebShell, &rv);
|
|
|
|
if (owner) {
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> scriptobj;
|
|
|
|
rv = owner->GetScriptGlobalObject(getter_AddRefs(scriptobj));
|
|
|
|
if (NS_SUCCEEDED(rv) && scriptobj)
|
|
|
|
rv = scriptobj->QueryInterface(nsIDOMWindow::GetIID(), (void **) aDOMWindow);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-05-14 18:54:25 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::CreatePopup(nsIDOMElement* aElement, nsIDOMElement* aPopupContent,
|
|
|
|
PRInt32 aXPos, PRInt32 aYPos,
|
1999-06-09 08:36:06 +00:00
|
|
|
const nsString& aPopupType,
|
1999-07-01 00:07:41 +00:00
|
|
|
const nsString& anAnchorAlignment, const nsString& aPopupAlignment,
|
|
|
|
nsIDOMWindow** outPopup)
|
1999-05-14 18:54:25 +00:00
|
|
|
{
|
1999-06-15 03:17:11 +00:00
|
|
|
if (nsnull != mWebShell) {
|
|
|
|
// Pass this off to the parent.
|
|
|
|
nsCOMPtr<nsIWebShellContainer> webShellContainer = do_QueryInterface(mWebShell);
|
|
|
|
if (webShellContainer) {
|
|
|
|
webShellContainer->CreatePopup(aElement, aPopupContent, aXPos, aYPos, aPopupType,
|
1999-07-01 00:07:41 +00:00
|
|
|
anAnchorAlignment, aPopupAlignment, this, outPopup);
|
1999-06-15 03:17:11 +00:00
|
|
|
}
|
1999-05-15 00:48:39 +00:00
|
|
|
}
|
1999-05-14 18:54:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult
|
|
|
|
GlobalWindowImpl::CheckWindowName(JSContext *cx, nsString& aName)
|
1998-08-07 04:45:03 +00:00
|
|
|
{
|
1999-08-07 02:51:03 +00:00
|
|
|
PRInt32 strIndex;
|
1998-08-07 04:45:03 +00:00
|
|
|
PRUnichar mChar;
|
|
|
|
|
1999-08-07 02:51:03 +00:00
|
|
|
for (strIndex = 0; strIndex < aName.Length(); strIndex++) {
|
|
|
|
mChar = aName.CharAt(strIndex);
|
1998-08-07 04:45:03 +00:00
|
|
|
if (!nsString::IsAlpha(mChar) && !nsString::IsDigit(mChar) && mChar != '_') {
|
1999-04-23 19:52:04 +00:00
|
|
|
char* cp = aName.ToNewCString();
|
1998-08-07 04:45:03 +00:00
|
|
|
JS_ReportError(cx,
|
|
|
|
"illegal character '%c' ('\\%o') in window name %s",
|
1999-04-23 19:52:04 +00:00
|
|
|
mChar, mChar, cp);
|
|
|
|
delete [] cp;
|
1998-08-07 04:45:03 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-08-14 22:31:38 +00:00
|
|
|
PRInt32
|
1999-07-08 02:04:32 +00:00
|
|
|
GlobalWindowImpl::WinHasOption(char *options, char *name, PRBool& aPresenceFlag)
|
1998-08-07 04:45:03 +00:00
|
|
|
{
|
|
|
|
char *comma, *equal;
|
1998-08-14 22:31:38 +00:00
|
|
|
PRInt32 found = 0;
|
1998-08-07 04:45:03 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
comma = strchr(options, ',');
|
|
|
|
if (comma) *comma = '\0';
|
|
|
|
equal = strchr(options, '=');
|
|
|
|
if (equal) *equal = '\0';
|
|
|
|
if (nsCRT::strcasecmp(options, name) == 0) {
|
1999-07-08 02:04:32 +00:00
|
|
|
aPresenceFlag = PR_TRUE;
|
1998-08-07 04:45:03 +00:00
|
|
|
if (!equal || nsCRT::strcasecmp(equal + 1, "yes") == 0)
|
|
|
|
found = 1;
|
|
|
|
else
|
|
|
|
found = atoi(equal + 1);
|
|
|
|
}
|
|
|
|
if (equal) *equal = '=';
|
|
|
|
if (comma) *comma = ',';
|
|
|
|
if (found || !comma)
|
|
|
|
break;
|
|
|
|
options = comma + 1;
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult
|
|
|
|
GlobalWindowImpl::GetBrowserWindowInterface(nsIBrowserWindow*& aBrowser)
|
1998-08-07 04:45:03 +00:00
|
|
|
{
|
1999-06-15 03:17:11 +00:00
|
|
|
nsresult ret = NS_ERROR_FAILURE;
|
1998-08-07 04:45:03 +00:00
|
|
|
|
1999-06-15 03:17:11 +00:00
|
|
|
if (nsnull != mWebShell) {
|
|
|
|
nsIWebShell *mRootWebShell;
|
|
|
|
mWebShell->GetRootWebShellEvenIfChrome(mRootWebShell);
|
|
|
|
if (nsnull != mRootWebShell) {
|
|
|
|
nsIWebShellContainer *mRootContainer;
|
|
|
|
mRootWebShell->GetContainer(mRootContainer);
|
|
|
|
if (nsnull != mRootContainer) {
|
|
|
|
ret = mRootContainer->QueryInterface(kIBrowserWindowIID, (void**)&aBrowser);
|
|
|
|
NS_RELEASE(mRootContainer);
|
|
|
|
}
|
|
|
|
NS_RELEASE(mRootWebShell);
|
1998-08-07 04:45:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1998-08-13 23:37:54 +00:00
|
|
|
PRBool
|
|
|
|
GlobalWindowImpl::CheckForEventListener(JSContext *aContext, nsString& aPropName)
|
|
|
|
{
|
|
|
|
nsIEventListenerManager *mManager = nsnull;
|
|
|
|
|
|
|
|
if (aPropName == "onmousedown" || aPropName == "onmouseup" || aPropName == "onclick" ||
|
|
|
|
aPropName == "onmouseover" || aPropName == "onmouseout") {
|
|
|
|
if (NS_OK == GetListenerManager(&mManager)) {
|
|
|
|
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
|
|
|
|
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, kIDOMMouseListenerIID)) {
|
|
|
|
NS_RELEASE(mManager);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (aPropName == "onkeydown" || aPropName == "onkeyup" || aPropName == "onkeypress") {
|
|
|
|
if (NS_OK == GetListenerManager(&mManager)) {
|
|
|
|
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
|
|
|
|
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, kIDOMKeyListenerIID)) {
|
|
|
|
NS_RELEASE(mManager);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (aPropName == "onmousemove") {
|
|
|
|
if (NS_OK == GetListenerManager(&mManager)) {
|
|
|
|
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
|
|
|
|
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, kIDOMMouseMotionListenerIID)) {
|
|
|
|
NS_RELEASE(mManager);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (aPropName == "onfocus" || aPropName == "onblur") {
|
|
|
|
if (NS_OK == GetListenerManager(&mManager)) {
|
|
|
|
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
|
|
|
|
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, kIDOMFocusListenerIID)) {
|
|
|
|
NS_RELEASE(mManager);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-08-07 23:18:35 +00:00
|
|
|
else if (aPropName == "onsubmit" || aPropName == "onreset" || aPropName == "onchange" ||
|
|
|
|
aPropName == "onselect") {
|
1998-08-13 23:37:54 +00:00
|
|
|
if (NS_OK == GetListenerManager(&mManager)) {
|
|
|
|
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
|
|
|
|
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, kIDOMFormListenerIID)) {
|
|
|
|
NS_RELEASE(mManager);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (aPropName == "onload" || aPropName == "onunload" || aPropName == "onabort" ||
|
|
|
|
aPropName == "onerror") {
|
|
|
|
if (NS_OK == GetListenerManager(&mManager)) {
|
|
|
|
nsIScriptContext *mScriptCX = (nsIScriptContext *)JS_GetContextPrivate(aContext);
|
|
|
|
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this, kIDOMLoadListenerIID)) {
|
|
|
|
NS_RELEASE(mManager);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-10-06 20:59:39 +00:00
|
|
|
else if (aPropName == "onpaint") {
|
|
|
|
if (NS_OK == GetListenerManager(&mManager)) {
|
|
|
|
nsIScriptContext *mScriptCX = (nsIScriptContext *)
|
|
|
|
JS_GetContextPrivate(aContext);
|
|
|
|
if (NS_OK != mManager->RegisterScriptEventListener(mScriptCX, this,
|
|
|
|
kIDOMPaintListenerIID)) {
|
|
|
|
NS_RELEASE(mManager);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-08-13 23:37:54 +00:00
|
|
|
NS_IF_RELEASE(mManager);
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
1998-08-13 04:34:53 +00:00
|
|
|
GlobalWindowImpl::AddProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
1998-07-24 05:05:42 +00:00
|
|
|
{
|
1998-08-13 23:37:54 +00:00
|
|
|
if (JS_TypeOfValue(aContext, *aVp) == JSTYPE_FUNCTION && JSVAL_IS_STRING(aID)) {
|
|
|
|
nsString mPropName;
|
|
|
|
nsAutoString mPrefix;
|
|
|
|
mPropName.SetString(JS_GetStringChars(JS_ValueToString(aContext, aID)));
|
1999-04-05 09:07:07 +00:00
|
|
|
mPrefix.SetString(mPropName.GetUnicode(), 2);
|
1998-08-13 23:37:54 +00:00
|
|
|
if (mPrefix == "on") {
|
|
|
|
return CheckForEventListener(aContext, mPropName);
|
|
|
|
}
|
|
|
|
}
|
1998-07-24 05:05:42 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
PRBool
|
|
|
|
GlobalWindowImpl::DeleteProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
1998-07-24 05:05:42 +00:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
PRBool
|
|
|
|
GlobalWindowImpl::GetProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
1998-07-24 05:05:42 +00:00
|
|
|
{
|
1999-07-16 01:14:59 +00:00
|
|
|
if (JSVAL_IS_STRING(aID)) {
|
|
|
|
char* cString = JS_GetStringBytes(JS_ValueToString(aContext, aID));
|
|
|
|
if (PL_strcmp("location", cString) == 0) {
|
|
|
|
nsIDOMLocation *location;
|
1998-08-13 04:34:53 +00:00
|
|
|
|
1999-07-16 01:14:59 +00:00
|
|
|
if (NS_OK == GetLocation(&location)) {
|
|
|
|
if (location != nsnull) {
|
|
|
|
nsIScriptObjectOwner *owner = nsnull;
|
|
|
|
if (NS_OK == location->QueryInterface(kIScriptObjectOwnerIID,
|
|
|
|
(void**)&owner)) {
|
|
|
|
JSObject *object = nsnull;
|
|
|
|
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(aContext);
|
|
|
|
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
|
|
|
|
// set the return value
|
|
|
|
*aVp = OBJECT_TO_JSVAL(object);
|
|
|
|
}
|
|
|
|
NS_RELEASE(owner);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
1999-07-16 01:14:59 +00:00
|
|
|
NS_RELEASE(location);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aVp = JSVAL_NULL;
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
1999-07-16 01:14:59 +00:00
|
|
|
return PR_FALSE;
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
1999-07-16 01:14:59 +00:00
|
|
|
else if (PL_strcmp("title", cString) == 0) {
|
|
|
|
if (mWebShell) {
|
|
|
|
// See if we're a chrome shell.
|
|
|
|
nsWebShellType type;
|
|
|
|
mWebShell->GetWebShellType(type);
|
|
|
|
if (type == nsWebShellChrome) {
|
|
|
|
nsCOMPtr<nsIBrowserWindow> browser;
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(*getter_AddRefs(browser)) && browser) {
|
|
|
|
// We got a browser window interface
|
|
|
|
const PRUnichar* title;
|
|
|
|
browser->GetTitle(&title);
|
|
|
|
|
|
|
|
JSString* jsString = JS_NewUCStringCopyZ(aContext, (const jschar*)title);
|
|
|
|
if (!jsString)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
*aVp = STRING_TO_JSVAL(jsString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
1998-07-24 05:05:42 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-08-13 23:37:54 +00:00
|
|
|
PRBool
|
1998-08-13 04:34:53 +00:00
|
|
|
GlobalWindowImpl::SetProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
1998-07-24 05:05:42 +00:00
|
|
|
{
|
1999-08-03 23:16:48 +00:00
|
|
|
PRBool result = PR_TRUE;
|
1998-07-24 05:05:42 +00:00
|
|
|
if (JS_TypeOfValue(aContext, *aVp) == JSTYPE_FUNCTION && JSVAL_IS_STRING(aID)) {
|
1998-08-13 23:37:54 +00:00
|
|
|
nsString mPropName;
|
|
|
|
nsAutoString mPrefix;
|
|
|
|
mPropName.SetString(JS_GetStringChars(JS_ValueToString(aContext, aID)));
|
1999-04-05 09:07:07 +00:00
|
|
|
mPrefix.SetString(mPropName.GetUnicode(), 2);
|
1998-07-24 05:05:42 +00:00
|
|
|
if (mPrefix == "on") {
|
1999-08-03 23:16:48 +00:00
|
|
|
result = CheckForEventListener(aContext, mPropName);
|
1998-07-24 05:05:42 +00:00
|
|
|
}
|
|
|
|
}
|
1999-07-16 01:14:59 +00:00
|
|
|
else if (JSVAL_IS_STRING(aID)) {
|
|
|
|
char* cString = JS_GetStringBytes(JS_ValueToString(aContext, aID));
|
|
|
|
|
|
|
|
if (PL_strcmp("location", cString) == 0) {
|
1999-08-03 23:16:48 +00:00
|
|
|
nsCOMPtr<nsIDOMLocation> location;
|
1998-08-13 04:34:53 +00:00
|
|
|
|
1999-08-03 23:16:48 +00:00
|
|
|
if (NS_OK == GetLocation(getter_AddRefs(location))) {
|
|
|
|
nsCOMPtr<nsIJSScriptObject> scriptObj = do_QueryInterface(location);
|
|
|
|
JSString* str = JS_NewStringCopyZ(aContext, "href");
|
|
|
|
|
|
|
|
if (scriptObj && str) {
|
|
|
|
result = scriptObj->SetProperty(aContext, STRING_TO_JSVAL(str), aVp);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
1999-08-03 23:16:48 +00:00
|
|
|
else {
|
|
|
|
result = PR_FALSE;
|
|
|
|
}
|
1999-07-16 01:14:59 +00:00
|
|
|
}
|
|
|
|
else if (PL_strcmp("title", cString) == 0) {
|
|
|
|
if (mWebShell) {
|
|
|
|
// See if we're a chrome shell.
|
|
|
|
nsWebShellType type;
|
|
|
|
mWebShell->GetWebShellType(type);
|
|
|
|
if (type == nsWebShellChrome) {
|
|
|
|
nsCOMPtr<nsIBrowserWindow> browser;
|
|
|
|
if (NS_OK == GetBrowserWindowInterface(*getter_AddRefs(browser)) && browser) {
|
|
|
|
// We got a browser window interface
|
|
|
|
JSString *jsString = JS_ValueToString(aContext, *aVp);
|
1999-08-03 23:16:48 +00:00
|
|
|
if (!jsString) {
|
|
|
|
result = PR_FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const PRUnichar* uniTitle = JS_GetStringChars(jsString);
|
|
|
|
browser->SetTitle(uniTitle);
|
|
|
|
}
|
1999-07-16 01:14:59 +00:00
|
|
|
}
|
|
|
|
}
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-03 23:16:48 +00:00
|
|
|
return result;
|
1998-07-24 05:05:42 +00:00
|
|
|
}
|
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
PRBool
|
|
|
|
GlobalWindowImpl::EnumerateProperty(JSContext *aContext)
|
1998-07-24 05:05:42 +00:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
PRBool
|
|
|
|
GlobalWindowImpl::Resolve(JSContext *aContext, jsval aID)
|
1998-07-24 05:05:42 +00:00
|
|
|
{
|
1999-06-09 07:38:26 +00:00
|
|
|
if (JSVAL_IS_STRING(aID)) {
|
|
|
|
if (PL_strcmp("location", JS_GetStringBytes(JS_ValueToString(aContext, aID))) == 0) {
|
|
|
|
::JS_DefineProperty(aContext, (JSObject *)mScriptObject, "location",
|
|
|
|
JSVAL_NULL, nsnull, nsnull, 0);
|
|
|
|
}
|
1999-06-15 03:17:11 +00:00
|
|
|
else if (nsnull != mWebShell) {
|
1999-06-09 07:38:26 +00:00
|
|
|
PRInt32 count;
|
|
|
|
if (NS_SUCCEEDED(mWebShell->GetChildCount(count)) && count) {
|
|
|
|
nsIWebShell *child = nsnull;
|
|
|
|
nsAutoString name(JS_GetStringBytes(JS_ValueToString(aContext, aID)));
|
|
|
|
if (NS_SUCCEEDED(mWebShell->FindChildWithName(name.GetUnicode(), child))) {
|
|
|
|
if (child) {
|
|
|
|
JSObject *childObj;
|
|
|
|
//We found a subframe of the right name. The rest of this is to get its script object.
|
|
|
|
nsIScriptContextOwner *contextOwner;
|
|
|
|
if (NS_SUCCEEDED(child->QueryInterface(kIScriptContextOwnerIID, (void**)&contextOwner))) {
|
|
|
|
nsIScriptGlobalObject *childGlobalObj;
|
|
|
|
if (NS_SUCCEEDED(contextOwner->GetScriptGlobalObject(&childGlobalObj))) {
|
|
|
|
nsIScriptObjectOwner *objOwner;
|
|
|
|
if (NS_SUCCEEDED(childGlobalObj->QueryInterface(kIScriptObjectOwnerIID, (void**)&objOwner))) {
|
|
|
|
nsIScriptContext *scriptContext;
|
|
|
|
childGlobalObj->GetContext(&scriptContext);
|
|
|
|
if (scriptContext) {
|
|
|
|
objOwner->GetScriptObject(scriptContext, (void**)&childObj);
|
|
|
|
NS_RELEASE(scriptContext);
|
|
|
|
}
|
|
|
|
NS_RELEASE(objOwner);
|
|
|
|
}
|
|
|
|
NS_RELEASE(childGlobalObj);
|
|
|
|
}
|
|
|
|
NS_RELEASE(contextOwner);
|
|
|
|
}
|
|
|
|
//Okay, if we now have a childObj, we can define it and proceed.
|
|
|
|
if (childObj) {
|
|
|
|
::JS_DefineProperty(aContext, (JSObject *)mScriptObject,
|
|
|
|
JS_GetStringBytes(JS_ValueToString(aContext, aID)),
|
|
|
|
OBJECT_TO_JSVAL(childObj), nsnull, nsnull, 0);
|
|
|
|
}
|
|
|
|
NS_RELEASE(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-08-13 20:46:11 +00:00
|
|
|
}
|
|
|
|
|
1998-07-24 05:05:42 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
PRBool
|
|
|
|
GlobalWindowImpl::Convert(JSContext *aContext, jsval aID)
|
1998-07-24 05:05:42 +00:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
void
|
|
|
|
GlobalWindowImpl::Finalize(JSContext *aContext)
|
1998-07-24 05:05:42 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult
|
|
|
|
GlobalWindowImpl::GetListenerManager(nsIEventListenerManager **aInstancePtrResult)
|
1998-07-24 05:05:42 +00:00
|
|
|
{
|
|
|
|
if (nsnull != mListenerManager) {
|
|
|
|
return mListenerManager->QueryInterface(kIEventListenerManagerIID, (void**) aInstancePtrResult);;
|
|
|
|
}
|
|
|
|
//This is gonna get ugly. Can't use NS_NewEventListenerManager because of a circular link problem.
|
|
|
|
nsIDOMEventCapturer *mDoc;
|
|
|
|
if (nsnull != mDocument && NS_OK == mDocument->QueryInterface(kIDOMEventCapturerIID, (void**)&mDoc)) {
|
|
|
|
if (NS_OK == mDoc->GetNewListenerManager(aInstancePtrResult)) {
|
|
|
|
mListenerManager = *aInstancePtrResult;
|
|
|
|
NS_ADDREF(mListenerManager);
|
|
|
|
NS_RELEASE(mDoc);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-17 18:52:21 +00:00
|
|
|
NS_IF_RELEASE(mDoc);
|
1998-07-24 05:05:42 +00:00
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//XXX I need another way around the circular link problem.
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult
|
|
|
|
GlobalWindowImpl::GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult)
|
1998-07-24 05:05:42 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult
|
|
|
|
GlobalWindowImpl::HandleDOMEvent(nsIPresContext& aPresContext,
|
|
|
|
nsEvent* aEvent,
|
|
|
|
nsIDOMEvent** aDOMEvent,
|
|
|
|
PRUint32 aFlags,
|
|
|
|
nsEventStatus& aEventStatus)
|
1998-07-24 05:05:42 +00:00
|
|
|
{
|
|
|
|
nsresult mRet = NS_OK;
|
1998-08-02 04:15:08 +00:00
|
|
|
nsIDOMEvent* mDOMEvent = nsnull;
|
1998-07-24 05:05:42 +00:00
|
|
|
|
1999-03-28 22:19:42 +00:00
|
|
|
if (NS_EVENT_FLAG_INIT == aFlags) {
|
1998-07-24 05:05:42 +00:00
|
|
|
aDOMEvent = &mDOMEvent;
|
1999-07-19 19:54:34 +00:00
|
|
|
aEvent->flags = NS_EVENT_FLAG_NONE;
|
1998-07-24 05:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Capturing stage
|
1999-05-27 21:06:51 +00:00
|
|
|
if (NS_EVENT_FLAG_BUBBLE != aFlags && mChromeDocument) {
|
|
|
|
// Check chrome document capture here
|
|
|
|
mChromeDocument->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_CAPTURE, aEventStatus);
|
|
|
|
}
|
1998-09-09 01:19:11 +00:00
|
|
|
|
1998-07-24 05:05:42 +00:00
|
|
|
//Local handling stage
|
1999-07-19 19:54:34 +00:00
|
|
|
if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) {
|
|
|
|
aEvent->flags = aFlags;
|
1999-03-28 22:19:42 +00:00
|
|
|
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus);
|
1998-07-24 05:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Bubbling stage
|
1999-05-27 21:06:51 +00:00
|
|
|
if (NS_EVENT_FLAG_CAPTURE != aFlags && mChromeDocument) {
|
|
|
|
// Bubble to a chrome document if it exists
|
1999-05-28 04:39:59 +00:00
|
|
|
// XXX Need a way to know if an event should really bubble or not.
|
|
|
|
// For now filter out load and unload, since they cause problems.
|
|
|
|
if (aEvent->message != NS_PAGE_LOAD && aEvent->message != NS_PAGE_UNLOAD)
|
|
|
|
mChromeDocument->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_BUBBLE, aEventStatus);
|
1999-05-27 21:06:51 +00:00
|
|
|
}
|
1998-07-24 05:05:42 +00:00
|
|
|
|
1999-03-28 22:19:42 +00:00
|
|
|
if (NS_EVENT_FLAG_INIT == aFlags) {
|
1998-07-24 05:05:42 +00:00
|
|
|
// We're leaving the DOM event loop so if we created a DOM event, release here.
|
|
|
|
if (nsnull != *aDOMEvent) {
|
1998-09-15 21:31:58 +00:00
|
|
|
nsrefcnt rc;
|
1998-09-17 05:40:57 +00:00
|
|
|
NS_RELEASE2(*aDOMEvent, rc);
|
1998-09-15 21:31:58 +00:00
|
|
|
if (0 != rc) {
|
1998-07-24 05:05:42 +00:00
|
|
|
//Okay, so someone in the DOM loop (a listener, JS object) still has a ref to the DOM Event but
|
|
|
|
//the internal data hasn't been malloc'd. Force a copy of the data here so the DOM Event is still valid.
|
|
|
|
nsIPrivateDOMEvent *mPrivateEvent;
|
|
|
|
if (NS_OK == (*aDOMEvent)->QueryInterface(kIPrivateDOMEventIID, (void**)&mPrivateEvent)) {
|
|
|
|
mPrivateEvent->DuplicatePrivateData();
|
|
|
|
NS_RELEASE(mPrivateEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-08-02 04:15:08 +00:00
|
|
|
aDOMEvent = nsnull;
|
1998-07-24 05:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return mRet;
|
|
|
|
}
|
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult
|
1999-03-28 22:19:42 +00:00
|
|
|
GlobalWindowImpl::AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID)
|
1998-07-24 05:05:42 +00:00
|
|
|
{
|
|
|
|
nsIEventListenerManager *mManager;
|
|
|
|
|
|
|
|
if (NS_OK == GetListenerManager(&mManager)) {
|
1999-03-28 22:19:42 +00:00
|
|
|
mManager->AddEventListenerByIID(aListener, aIID, NS_EVENT_FLAG_BUBBLE);
|
1998-07-24 05:05:42 +00:00
|
|
|
NS_RELEASE(mManager);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult
|
1999-03-28 22:19:42 +00:00
|
|
|
GlobalWindowImpl::RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID)
|
1998-07-24 05:05:42 +00:00
|
|
|
{
|
|
|
|
if (nsnull != mListenerManager) {
|
1999-03-28 22:19:42 +00:00
|
|
|
mListenerManager->RemoveEventListenerByIID(aListener, aIID, NS_EVENT_FLAG_BUBBLE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GlobalWindowImpl::AddEventListener(const nsString& aType, nsIDOMEventListener* aListener,
|
1999-07-19 19:54:34 +00:00
|
|
|
PRBool aUseCapture)
|
1999-03-28 22:19:42 +00:00
|
|
|
{
|
|
|
|
nsIEventListenerManager *manager;
|
|
|
|
|
|
|
|
if (NS_OK == GetListenerManager(&manager)) {
|
1999-07-19 19:54:34 +00:00
|
|
|
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
|
1999-03-28 22:19:42 +00:00
|
|
|
|
|
|
|
manager->AddEventListenerByType(aListener, aType, flags);
|
|
|
|
NS_RELEASE(manager);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GlobalWindowImpl::RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener,
|
1999-07-19 19:54:34 +00:00
|
|
|
PRBool aUseCapture)
|
1999-03-28 22:19:42 +00:00
|
|
|
{
|
|
|
|
if (nsnull != mListenerManager) {
|
1999-07-19 19:54:34 +00:00
|
|
|
PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
|
1999-03-28 22:19:42 +00:00
|
|
|
|
|
|
|
mListenerManager->RemoveEventListenerByType(aListener, aType, flags);
|
1998-07-24 05:05:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult
|
1998-09-15 21:31:58 +00:00
|
|
|
GlobalWindowImpl::CaptureEvent(const nsString& aType)
|
1998-07-24 05:05:42 +00:00
|
|
|
{
|
|
|
|
nsIEventListenerManager *mManager;
|
|
|
|
|
|
|
|
if (NS_OK == GetListenerManager(&mManager)) {
|
1998-09-15 21:31:58 +00:00
|
|
|
//mManager->CaptureEvent(aListener);
|
1998-07-24 05:05:42 +00:00
|
|
|
NS_RELEASE(mManager);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult
|
1998-09-15 21:31:58 +00:00
|
|
|
GlobalWindowImpl::ReleaseEvent(const nsString& aType)
|
1998-07-24 05:05:42 +00:00
|
|
|
{
|
|
|
|
if (nsnull != mListenerManager) {
|
1998-09-15 21:31:58 +00:00
|
|
|
//mListenerManager->ReleaseEvent(aListener);
|
1998-07-24 05:05:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1999-07-07 07:50:03 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetPrincipals(void** aPrincipals)
|
|
|
|
{
|
|
|
|
if (!mPrincipals) {
|
|
|
|
if (mContext) {
|
|
|
|
nsIScriptSecurityManager* secMan = nsnull;
|
|
|
|
mContext->GetSecurityManager(&secMan);
|
|
|
|
if (secMan) {
|
|
|
|
nsAutoString codebase;
|
|
|
|
if (NS_SUCCEEDED(GetOrigin(&codebase))) {
|
|
|
|
secMan->NewJSPrincipals(nsnull, nsnull, &codebase, &mPrincipals);
|
|
|
|
}
|
|
|
|
NS_RELEASE(secMan);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mPrincipals) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
if (mContext) {
|
|
|
|
JSPRINCIPALS_HOLD((JSContext *)mContext->GetNativeContext(), mPrincipals);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aPrincipals = (void*)mPrincipals;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::SetPrincipals(void* aPrincipals)
|
|
|
|
{
|
|
|
|
if (mPrincipals && mContext) {
|
|
|
|
JSPRINCIPALS_DROP((JSContext *)mContext->GetNativeContext(), mPrincipals);
|
|
|
|
}
|
|
|
|
|
|
|
|
mPrincipals = (JSPrincipals*)aPrincipals;
|
|
|
|
|
|
|
|
if (mPrincipals && mContext) {
|
|
|
|
JSPRINCIPALS_HOLD((JSContext *)mContext->GetNativeContext(), mPrincipals);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
GlobalWindowImpl::GetOrigin(nsString* aOrigin)
|
|
|
|
{
|
|
|
|
nsIDocument* doc;
|
|
|
|
if (mDocument && NS_OK == mDocument->QueryInterface(kIDocumentIID, (void**)&doc)) {
|
|
|
|
nsIURI* docURL = doc->GetDocumentURL();
|
|
|
|
if (docURL) {
|
1999-07-07 10:05:59 +00:00
|
|
|
#ifdef NECKO
|
|
|
|
char* str;
|
|
|
|
docURL->GetSpec(&str);
|
|
|
|
#else
|
1999-07-07 07:50:03 +00:00
|
|
|
PRUnichar* str;
|
|
|
|
docURL->ToString(&str);
|
1999-07-07 10:05:59 +00:00
|
|
|
#endif
|
1999-07-07 07:50:03 +00:00
|
|
|
*aOrigin = str;
|
1999-07-07 10:05:59 +00:00
|
|
|
#ifdef NECKO
|
|
|
|
nsCRT::free(str);
|
|
|
|
#else
|
1999-07-17 13:08:45 +00:00
|
|
|
delete [] str;
|
1999-07-07 10:05:59 +00:00
|
|
|
#endif
|
1999-07-07 07:50:03 +00:00
|
|
|
NS_RELEASE(docURL);
|
|
|
|
}
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
//Old code from 4.0 to show what funcitonality needs replicating
|
|
|
|
History_entry *he;
|
|
|
|
const char *address;
|
|
|
|
JSContext *aCx;
|
|
|
|
MochaDecoder *decoder;
|
|
|
|
|
|
|
|
he = SHIST_GetCurrent(&context->hist);
|
|
|
|
if (he) {
|
|
|
|
address = he->wysiwyg_url;
|
|
|
|
if (!address)
|
|
|
|
address = he->address;
|
|
|
|
switch (NET_URL_Type(address)) {
|
|
|
|
case MOCHA_TYPE_URL:
|
|
|
|
/* This type cannot name the true origin (server) of JS code. */
|
|
|
|
break;
|
|
|
|
case VIEW_SOURCE_TYPE_URL:
|
|
|
|
NS_ASSERTION(0, "Invalid url type");
|
|
|
|
default:
|
|
|
|
return address;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context->grid_parent) {
|
|
|
|
address = FindCreatorURL(context->grid_parent);
|
|
|
|
if (address)
|
|
|
|
return address;
|
|
|
|
}
|
|
|
|
|
|
|
|
aCx = context->mocha_context;
|
|
|
|
if (aCx) {
|
|
|
|
decoder = JS_GetPrivate(aCx, JS_GetGlobalObject(aCx));
|
|
|
|
if (decoder && decoder->opener) {
|
|
|
|
/* self.opener property is valid, check its MWContext. */
|
|
|
|
MochaDecoder *opener = JS_GetPrivate(aCx, decoder->opener);
|
|
|
|
if (!opener->visited) {
|
|
|
|
opener->visited = PR_TRUE;
|
|
|
|
address = opener->window_context
|
|
|
|
? FindCreatorURL(opener->window_context)
|
|
|
|
: nsnull;
|
|
|
|
opener->visited = PR_FALSE;
|
|
|
|
if (address)
|
|
|
|
return address;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
extern "C" NS_DOM nsresult
|
|
|
|
NS_NewScriptGlobalObject(nsIScriptGlobalObject **aResult)
|
|
|
|
{
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = NULL;
|
|
|
|
|
|
|
|
GlobalWindowImpl *global = new GlobalWindowImpl();
|
|
|
|
if (nsnull == global) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return global->QueryInterface(kIScriptGlobalObjectIID, (void **)aResult);
|
|
|
|
}
|
|
|
|
|
1999-07-07 07:50:03 +00:00
|
|
|
|
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
//
|
|
|
|
// Navigator class implementation
|
|
|
|
//
|
|
|
|
NavigatorImpl::NavigatorImpl()
|
|
|
|
{
|
1998-07-21 16:41:42 +00:00
|
|
|
NS_INIT_REFCNT();
|
1998-07-16 01:16:47 +00:00
|
|
|
mScriptObject = nsnull;
|
1999-04-20 19:41:17 +00:00
|
|
|
mMimeTypes = nsnull;
|
|
|
|
mPlugins = nsnull;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NavigatorImpl::~NavigatorImpl()
|
|
|
|
{
|
1999-07-12 23:40:01 +00:00
|
|
|
NS_IF_RELEASE(mMimeTypes);
|
|
|
|
NS_IF_RELEASE(mPlugins);
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(NavigatorImpl)
|
|
|
|
NS_IMPL_RELEASE(NavigatorImpl)
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NavigatorImpl::QueryInterface(const nsIID& aIID,
|
|
|
|
void** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIScriptObjectOwner*)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDOMNavigatorIID)) {
|
|
|
|
*aInstancePtrResult = (void*) ((nsIDOMNavigator*)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
|
|
*aInstancePtrResult = (void*)(nsISupports*)(nsIScriptObjectOwner*)this;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1998-09-17 01:53:52 +00:00
|
|
|
NavigatorImpl::SetScriptObject(void *aScriptObject)
|
1998-07-16 01:16:47 +00:00
|
|
|
{
|
1998-09-17 01:53:52 +00:00
|
|
|
mScriptObject = aScriptObject;
|
1998-07-16 01:16:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NavigatorImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
|
|
|
|
nsresult res = NS_OK;
|
|
|
|
if (nsnull == mScriptObject) {
|
|
|
|
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
|
1998-09-04 23:03:16 +00:00
|
|
|
res = NS_NewScriptNavigator(aContext, (nsISupports *)(nsIDOMNavigator *)this, global, &mScriptObject);
|
1998-07-16 01:16:47 +00:00
|
|
|
NS_IF_RELEASE(global);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aScriptObject = mScriptObject;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
NavigatorImpl::GetUserAgent(nsString& aUserAgent)
|
|
|
|
{
|
1999-07-12 23:40:01 +00:00
|
|
|
nsresult res;
|
1999-06-18 17:34:08 +00:00
|
|
|
#ifndef NECKO
|
1999-07-12 23:40:01 +00:00
|
|
|
nsINetService *service = nsnull;
|
|
|
|
res = nsServiceManager::GetService(kNetServiceCID,
|
|
|
|
kINetServiceIID,
|
|
|
|
(nsISupports **)&service);
|
1999-08-03 19:00:51 +00:00
|
|
|
if (NS_SUCCEEDED(res) && (nsnull != service)) {
|
1999-07-12 23:40:01 +00:00
|
|
|
res = service->GetUserAgent(aUserAgent);
|
1999-08-03 19:00:51 +00:00
|
|
|
NS_RELEASE(service);
|
|
|
|
}
|
1999-06-18 17:34:08 +00:00
|
|
|
#else
|
1999-08-03 19:00:51 +00:00
|
|
|
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &res);
|
|
|
|
if (NS_SUCCEEDED(res) && (nsnull != service)) {
|
1999-07-12 23:40:01 +00:00
|
|
|
PRUnichar *ua = nsnull;
|
|
|
|
res = service->GetUserAgent(&ua);
|
|
|
|
aUserAgent = ua;
|
|
|
|
delete [] ua;
|
|
|
|
}
|
1999-08-03 19:00:51 +00:00
|
|
|
#endif // NECKO
|
|
|
|
|
1999-07-12 23:40:01 +00:00
|
|
|
return res;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
NavigatorImpl::GetAppCodeName(nsString& aAppCodeName)
|
|
|
|
{
|
1999-07-12 23:40:01 +00:00
|
|
|
nsresult res;
|
1999-06-18 17:34:08 +00:00
|
|
|
#ifndef NECKO
|
1999-07-12 23:40:01 +00:00
|
|
|
nsINetService *service = nsnull;
|
|
|
|
res = nsServiceManager::GetService(kNetServiceCID,
|
|
|
|
kINetServiceIID,
|
|
|
|
(nsISupports **)&service);
|
1999-08-03 19:00:51 +00:00
|
|
|
if (NS_SUCCEEDED(res) && (nsnull != service)) {
|
1999-07-12 23:40:01 +00:00
|
|
|
res = service->GetAppCodeName(aAppCodeName);
|
1999-08-03 19:00:51 +00:00
|
|
|
NS_RELEASE(service);
|
|
|
|
}
|
1999-06-18 17:34:08 +00:00
|
|
|
#else
|
1999-08-03 19:00:51 +00:00
|
|
|
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &res);
|
|
|
|
if (NS_SUCCEEDED(res) && (nsnull != service)) {
|
1999-07-12 23:40:01 +00:00
|
|
|
PRUnichar *appName = nsnull;
|
|
|
|
res = service->GetAppCodeName(&appName);
|
|
|
|
aAppCodeName = appName;
|
|
|
|
delete [] appName;
|
|
|
|
}
|
1999-08-03 19:00:51 +00:00
|
|
|
#endif // NECKO
|
1998-09-17 00:55:35 +00:00
|
|
|
|
1999-07-12 23:40:01 +00:00
|
|
|
return res;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
NavigatorImpl::GetAppVersion(nsString& aAppVersion)
|
|
|
|
{
|
1999-07-12 23:40:01 +00:00
|
|
|
nsresult res;
|
1999-06-18 17:34:08 +00:00
|
|
|
#ifndef NECKO
|
1999-07-12 23:40:01 +00:00
|
|
|
nsINetService *service = nsnull;
|
|
|
|
res = nsServiceManager::GetService(kNetServiceCID,
|
|
|
|
kINetServiceIID,
|
|
|
|
(nsISupports **)&service);
|
1999-08-03 19:00:51 +00:00
|
|
|
if (NS_SUCCEEDED(res) && (nsnull != service)) {
|
1999-07-12 23:40:01 +00:00
|
|
|
res = service->GetAppVersion(aAppVersion);
|
1999-08-03 19:00:51 +00:00
|
|
|
NS_RELEASE(service);
|
|
|
|
}
|
1999-06-18 17:34:08 +00:00
|
|
|
#else
|
1999-08-03 19:00:51 +00:00
|
|
|
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &res);
|
|
|
|
if (NS_SUCCEEDED(res) && (nsnull != service)) {
|
1999-07-12 23:40:01 +00:00
|
|
|
PRUnichar *appVer = nsnull;
|
|
|
|
res = service->GetAppVersion(&appVer);
|
|
|
|
aAppVersion = appVer;
|
|
|
|
delete [] appVer;
|
1999-06-18 17:34:08 +00:00
|
|
|
#endif // NECKO
|
1999-07-12 23:40:01 +00:00
|
|
|
}
|
1998-09-17 00:55:35 +00:00
|
|
|
|
1999-07-12 23:40:01 +00:00
|
|
|
return res;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
NavigatorImpl::GetAppName(nsString& aAppName)
|
|
|
|
{
|
1999-07-12 23:40:01 +00:00
|
|
|
nsresult res;
|
1999-06-18 17:34:08 +00:00
|
|
|
#ifndef NECKO
|
1999-07-12 23:40:01 +00:00
|
|
|
nsINetService *service = nsnull;
|
|
|
|
res = nsServiceManager::GetService(kNetServiceCID,
|
|
|
|
kINetServiceIID,
|
|
|
|
(nsISupports **)&service);
|
1999-08-03 19:00:51 +00:00
|
|
|
if (NS_SUCCEEDED(res) && (nsnull != service)) {
|
1999-07-12 23:40:01 +00:00
|
|
|
res = service->GetAppName(aAppName);
|
1999-08-03 19:00:51 +00:00
|
|
|
NS_RELEASE(service);
|
|
|
|
}
|
1999-06-18 17:34:08 +00:00
|
|
|
#else
|
1999-08-03 19:00:51 +00:00
|
|
|
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &res);
|
|
|
|
if (NS_SUCCEEDED(res) && (nsnull != service)) {
|
1999-07-12 23:40:01 +00:00
|
|
|
PRUnichar *appName = nsnull;
|
|
|
|
res = service->GetAppName(&appName);
|
|
|
|
aAppName = appName;
|
|
|
|
delete [] appName;
|
|
|
|
}
|
1999-08-03 19:00:51 +00:00
|
|
|
#endif // NECKO
|
1998-09-17 00:55:35 +00:00
|
|
|
|
1999-07-12 23:40:01 +00:00
|
|
|
return res;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
NavigatorImpl::GetLanguage(nsString& aLanguage)
|
|
|
|
{
|
1999-07-12 23:40:01 +00:00
|
|
|
nsresult res;
|
1999-06-18 17:34:08 +00:00
|
|
|
#ifndef NECKO
|
1999-07-12 23:40:01 +00:00
|
|
|
nsINetService *service = nsnull;
|
|
|
|
res = nsServiceManager::GetService(kNetServiceCID,
|
|
|
|
kINetServiceIID,
|
|
|
|
(nsISupports **)&service);
|
1999-08-03 19:00:51 +00:00
|
|
|
if (NS_SUCCEEDED(res) && (nsnull != service)) {
|
1999-07-12 23:40:01 +00:00
|
|
|
res = service->GetLanguage(aLanguage);
|
1999-08-03 19:00:51 +00:00
|
|
|
NS_RELEASE(service);
|
|
|
|
}
|
1999-06-18 17:34:08 +00:00
|
|
|
#else
|
1999-08-03 19:00:51 +00:00
|
|
|
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &res);
|
|
|
|
if (NS_SUCCEEDED(res) && (nsnull != service)) {
|
1999-07-12 23:40:01 +00:00
|
|
|
PRUnichar *lang = nsnull;
|
|
|
|
res = service->GetLanguage(&lang);
|
|
|
|
aLanguage = lang;
|
|
|
|
delete [] lang;
|
|
|
|
}
|
1999-08-03 19:00:51 +00:00
|
|
|
#endif // NECKO
|
1998-09-17 00:55:35 +00:00
|
|
|
|
1999-07-12 23:40:01 +00:00
|
|
|
return res;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
NavigatorImpl::GetPlatform(nsString& aPlatform)
|
|
|
|
{
|
1999-07-12 23:40:01 +00:00
|
|
|
nsresult res;
|
1999-06-18 17:34:08 +00:00
|
|
|
#ifndef NECKO
|
1999-07-12 23:40:01 +00:00
|
|
|
nsINetService *service = nsnull;
|
|
|
|
res = nsServiceManager::GetService(kNetServiceCID,
|
|
|
|
kINetServiceIID,
|
|
|
|
(nsISupports **)&service);
|
1999-08-03 19:00:51 +00:00
|
|
|
if (NS_SUCCEEDED(res) && (nsnull != service)) {
|
1999-07-12 23:40:01 +00:00
|
|
|
res = service->GetPlatform(aPlatform);
|
1999-08-03 19:00:51 +00:00
|
|
|
NS_RELEASE(service);
|
|
|
|
}
|
1999-06-18 17:34:08 +00:00
|
|
|
#else
|
1999-08-03 19:00:51 +00:00
|
|
|
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &res);
|
|
|
|
if (NS_SUCCEEDED(res) && (nsnull != service)) {
|
1999-07-12 23:40:01 +00:00
|
|
|
PRUnichar *plat = nsnull;
|
|
|
|
res = service->GetPlatform(&plat);
|
|
|
|
aPlatform = plat;
|
|
|
|
delete [] plat;
|
|
|
|
}
|
1999-08-03 19:00:51 +00:00
|
|
|
#endif // NECKO
|
1998-09-17 00:55:35 +00:00
|
|
|
|
1999-07-12 23:40:01 +00:00
|
|
|
return res;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
NavigatorImpl::GetSecurityPolicy(nsString& aSecurityPolicy)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-15 21:44:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
NavigatorImpl::GetMimeTypes(nsIDOMMimeTypeArray** aMimeTypes)
|
|
|
|
{
|
1999-04-20 19:41:17 +00:00
|
|
|
if (nsnull == mMimeTypes) {
|
|
|
|
mMimeTypes = new MimeTypeArrayImpl(this);
|
|
|
|
NS_IF_ADDREF(mMimeTypes);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aMimeTypes = mMimeTypes;
|
|
|
|
NS_IF_ADDREF(mMimeTypes);
|
|
|
|
|
1999-04-15 21:44:18 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
NavigatorImpl::GetPlugins(nsIDOMPluginArray** aPlugins)
|
|
|
|
{
|
1999-04-20 19:41:17 +00:00
|
|
|
if (nsnull == mPlugins) {
|
|
|
|
mPlugins = new PluginArrayImpl(this);
|
|
|
|
NS_IF_ADDREF(mPlugins);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aPlugins = mPlugins;
|
|
|
|
NS_IF_ADDREF(mPlugins);
|
|
|
|
|
1999-04-15 21:44:18 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-16 01:16:47 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
NavigatorImpl::JavaEnabled(PRBool* aReturn)
|
|
|
|
{
|
1999-05-08 17:24:43 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-07-16 01:16:47 +00:00
|
|
|
*aReturn = PR_FALSE;
|
1999-05-08 16:37:53 +00:00
|
|
|
|
1999-05-24 16:41:55 +00:00
|
|
|
// determine whether user has enabled java.
|
|
|
|
NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv);
|
1999-07-12 23:40:01 +00:00
|
|
|
if (NS_FAILED(rv) || prefs == nsnull) {
|
|
|
|
return rv;
|
1999-05-24 16:41:55 +00:00
|
|
|
}
|
|
|
|
|
1999-06-16 23:40:41 +00:00
|
|
|
// if pref doesn't exist, map result to false.
|
|
|
|
if (prefs->GetBoolPref("security.enable_java", aReturn) != NS_OK)
|
1999-07-12 23:40:01 +00:00
|
|
|
*aReturn = PR_FALSE;
|
1999-05-08 16:37:53 +00:00
|
|
|
|
|
|
|
return rv;
|
1998-07-16 01:16:47 +00:00
|
|
|
}
|