Compare commits

..

1 Commits

Author SHA1 Message Date
(no author)
258dc9fead This commit was manufactured by cvs2svn to create branch 'src'.
git-svn-id: svn://10.0.0.236/branches/src@33658 18797224-902f-48f8-a5cc-f745e15eee43
1999-06-03 23:10:01 +00:00
137 changed files with 18627 additions and 15753 deletions

View File

@@ -1,364 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Terry Hayes <thayes@netscape.com>
* Javier Delgadillo <javi@netscape.com>
* Oleg Romashin <romaxa@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* Derived from nsNSSDialogs http://landfill.mozilla.org/mxr-test/seamonkey/source/security/manager/pki/src/nsNSSDialogs.cpp
*/
#include <strings.h>
#include "nsIURI.h"
#include "EmbedPrivate.h"
#include "nsServiceManagerUtils.h"
#include "nsIWebNavigationInfo.h"
#include "nsDocShellCID.h"
#include "nsCOMPtr.h"
#ifdef MOZILLA_INTERNAL_API
#include "nsString.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#else
#include "nsStringAPI.h"
#endif
#include "nsIPrompt.h"
#include "nsIDOMWindowInternal.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsIStringBundle.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIX509Cert.h"
#include "nsIX509CertDB.h"
#include "nsILocaleService.h"
#include "nsIDateTimeFormat.h"
#include "nsDateTimeFormatCID.h"
#include "EmbedCertificates.h"
#include "nsIKeygenThread.h"
#include "nsIX509CertValidity.h"
#include "nsICRLInfo.h"
#include "gtkmozembed.h"
#define PIPSTRING_BUNDLE_URL "chrome://pippki/locale/pippki.properties"
static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
EmbedCertificates::EmbedCertificates(void)
{
}
EmbedCertificates::~EmbedCertificates()
{
}
NS_IMPL_THREADSAFE_ADDREF(EmbedCertificates)
NS_IMPL_THREADSAFE_RELEASE(EmbedCertificates)
NS_INTERFACE_MAP_BEGIN(EmbedCertificates)
NS_INTERFACE_MAP_ENTRY(nsITokenPasswordDialogs)
NS_INTERFACE_MAP_ENTRY(nsIBadCertListener)
#ifdef BAD_CERT_LISTENER2
NS_INTERFACE_MAP_ENTRY(nsIBadCertListener2)
#endif
NS_INTERFACE_MAP_ENTRY(nsICertificateDialogs)
NS_INTERFACE_MAP_ENTRY(nsIClientAuthDialogs)
NS_INTERFACE_MAP_ENTRY(nsICertPickDialogs)
NS_INTERFACE_MAP_ENTRY(nsITokenDialogs)
NS_INTERFACE_MAP_ENTRY(nsIGeneratingKeypairInfoDialogs)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMCryptoDialogs)
NS_INTERFACE_MAP_END
nsresult
EmbedCertificates::Init(void)
{
nsresult rv;
nsCOMPtr<nsIStringBundleService> service = do_GetService(kCStringBundleServiceCID, &rv);
if (NS_FAILED(rv)) return NS_OK;
rv = service->CreateBundle(PIPSTRING_BUNDLE_URL,
getter_AddRefs(mPIPStringBundle));
return NS_OK;
}
nsresult
EmbedCertificates::SetPassword(nsIInterfaceRequestor *ctx,
const PRUnichar *tokenName, PRBool* _canceled)
{
*_canceled = PR_FALSE;
return NS_OK;
}
nsresult
EmbedCertificates::GetPassword(nsIInterfaceRequestor *ctx,
const PRUnichar *tokenName,
PRUnichar **_password,
PRBool* _canceled)
{
*_canceled = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
EmbedCertificates::ConfirmUnknownIssuer(nsIInterfaceRequestor *socketInfo,
nsIX509Cert *cert, PRInt16 *outAddType,
PRBool *_retval)
{
*outAddType = ADD_TRUSTED_FOR_SESSION;
*_retval = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
EmbedCertificates::ConfirmMismatchDomain(nsIInterfaceRequestor *socketInfo,
const nsACString &targetURL,
nsIX509Cert *cert, PRBool *_retval)
{
*_retval = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
EmbedCertificates::ConfirmCertExpired(nsIInterfaceRequestor *socketInfo,
nsIX509Cert *cert, PRBool *_retval)
{
*_retval = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
EmbedCertificates::NotifyCrlNextupdate(nsIInterfaceRequestor *socketInfo,
const nsACString &targetURL, nsIX509Cert *cert)
{
return NS_OK;
}
NS_IMETHODIMP
EmbedCertificates::CrlImportStatusDialog(nsIInterfaceRequestor *ctx, nsICRLInfo *crl)
{
return NS_OK;
}
NS_IMETHODIMP
EmbedCertificates::ConfirmDownloadCACert(nsIInterfaceRequestor *ctx,
nsIX509Cert *cert,
PRUint32 *_trust,
PRBool *_retval)
{
*_retval = PR_TRUE;
*_trust |= nsIX509CertDB::TRUSTED_SSL;
*_trust |= nsIX509CertDB::TRUSTED_EMAIL;
*_trust |= nsIX509CertDB::TRUSTED_OBJSIGN;
return NS_OK;
}
NS_IMETHODIMP
EmbedCertificates::NotifyCACertExists(nsIInterfaceRequestor *ctx)
{
return NS_OK;
}
NS_IMETHODIMP
EmbedCertificates::ChooseCertificate(
nsIInterfaceRequestor *ctx,
const PRUnichar *cn,
const PRUnichar *organization,
const PRUnichar *issuer,
const PRUnichar **certNickList,
const PRUnichar **certDetailsList,
PRUint32 count,
PRInt32 *selectedIndex,
PRBool *canceled)
{
*canceled = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
EmbedCertificates::PickCertificate(
nsIInterfaceRequestor *ctx,
const PRUnichar **certNickList,
const PRUnichar **certDetailsList,
PRUint32 count,
PRInt32 *selectedIndex,
PRBool *canceled)
{
*canceled = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
EmbedCertificates::SetPKCS12FilePassword(
nsIInterfaceRequestor *ctx,
nsAString &_password,
PRBool *_retval)
{
/* The person who wrote this method implementation did
* not read the contract.
*/
*_retval = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
EmbedCertificates::GetPKCS12FilePassword(
nsIInterfaceRequestor *ctx,
nsAString &_password,
PRBool *_retval)
{
/* The person who wrote this method implementation did
* not read the contract.
*/
*_retval = PR_FALSE;
return NS_OK;
}
/* void viewCert (in nsIX509Cert cert); */
NS_IMETHODIMP
EmbedCertificates::ViewCert(
nsIInterfaceRequestor *ctx,
nsIX509Cert *cert)
{
return NS_OK;
}
NS_IMETHODIMP
EmbedCertificates::DisplayGeneratingKeypairInfo(nsIInterfaceRequestor *aCtx, nsIKeygenThread *runnable)
{
return NS_OK;
}
NS_IMETHODIMP
EmbedCertificates::ChooseToken(
nsIInterfaceRequestor *aCtx,
const PRUnichar **aTokenList,
PRUint32 aCount,
PRUnichar **aTokenChosen,
PRBool *aCanceled)
{
*aCanceled = PR_FALSE;
return NS_OK;
}
/* boolean ConfirmKeyEscrow (in nsIX509Cert escrowAuthority); */
NS_IMETHODIMP
EmbedCertificates::ConfirmKeyEscrow(nsIX509Cert *escrowAuthority, PRBool *_retval)
{
*_retval = PR_TRUE;
return NS_OK;
}
#ifdef BAD_CERT_LISTENER2
NS_IMETHODIMP
EmbedCertificates::ConfirmBadCertificate(
nsIInterfaceRequestor *ctx,
nsIX509Cert *cert,
PRBool aSecSuccess,
PRUint32 aError,
PRBool *_retval)
{
nsresult rv;
gpointer pCert = NULL;
guint messint = 0;
nsCOMPtr<nsIDOMWindow> parent(do_GetInterface(ctx));
GtkMozEmbedCommon * common = nsnull;
GtkMozEmbed *parentWidget = GTK_MOZ_EMBED(GetGtkWidgetForDOMWindow(parent));
if (!parentWidget) {
EmbedCommon * embedcommon = EmbedCommon::GetInstance();
if (embedcommon)
common = GTK_MOZ_EMBED_COMMON(embedcommon->mCommon);
}
if (!(aError & nsIX509Cert::VERIFIED_OK)) {
pCert = (gpointer)cert;
messint = GTK_MOZ_EMBED_CERT_VERIFIED_OK;
if (aError & nsIX509Cert::NOT_VERIFIED_UNKNOWN) {
messint |= GTK_MOZ_EMBED_CERT_NOT_VERIFIED_UNKNOWN;
}
if (aError & nsIX509Cert::CERT_EXPIRED || aError & nsIX509Cert::CERT_REVOKED) {
nsCOMPtr<nsIX509CertValidity> validity;
rv = cert->GetValidity(getter_AddRefs(validity));
if (NS_SUCCEEDED(rv)) {
PRTime notBefore, notAfter, timeToUse;
PRTime now = PR_Now();
rv = validity->GetNotBefore(&notBefore);
if (NS_FAILED(rv))
return rv;
rv = validity->GetNotAfter(&notAfter);
if (NS_FAILED(rv))
return rv;
if (LL_CMP(now, >, notAfter)) {
messint |= GTK_MOZ_EMBED_CERT_EXPIRED;
timeToUse = notAfter;
} else {
messint |= GTK_MOZ_EMBED_CERT_REVOKED;
timeToUse = notBefore;
}
}
}
if (aError & nsIX509Cert::CERT_NOT_TRUSTED) {
messint |= GTK_MOZ_EMBED_CERT_UNTRUSTED;
}
if (aError & nsIX509Cert::ISSUER_UNKNOWN) {
messint |= GTK_MOZ_EMBED_CERT_ISSUER_UNKNOWN;
}
if (aError & nsIX509Cert::ISSUER_NOT_TRUSTED) {
messint |= GTK_MOZ_EMBED_CERT_ISSUER_UNTRUSTED;
}
if (aError & nsIX509Cert::INVALID_CA) {
messint |= GTK_MOZ_EMBED_CERT_INVALID_CA;
}
if (aError & nsIX509Cert::USAGE_NOT_ALLOWED) {
}
PRBool retVal = PR_FALSE;
if (common) {
g_signal_emit_by_name(common, "certificate-error", pCert, messint, &retVal);
}
if (retVal == PR_TRUE) {
*_retval = PR_FALSE;
rv = NS_ERROR_FAILURE;
} else {
rv = NS_OK;
*_retval = PR_TRUE;
}
pCert = NULL;
} else {
rv = NS_OK;
*_retval = PR_TRUE;
}
return rv;
}
#endif

View File

@@ -1,96 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Terry Hayes <thayes@netscape.com>
* Javier Delgadillo <javi@netscape.com>
* Oleg Romashin <romaxa@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* Derived from nsNSSDialogs http://landfill.mozilla.org/mxr-test/seamonkey/source/security/manager/pki/src/nsNSSDialogs.h
*/
#ifndef __EmbedCertificates_h
#define __EmbedCertificates_h
#include "nsITokenPasswordDialogs.h"
#include "nsIBadCertListener.h"
#ifdef BAD_CERT_LISTENER2
#include "nsIBadCertListener2.h"
#endif
#include "nsICertificateDialogs.h"
#include "nsIClientAuthDialogs.h"
#include "nsICertPickDialogs.h"
#include "nsITokenDialogs.h"
#include "nsIDOMCryptoDialogs.h"
#include "nsIGenKeypairInfoDlg.h"
#include "nsCOMPtr.h"
#include "nsIStringBundle.h"
#define EMBED_CERTIFICATES_CID \
{ 0x518e071f, 0x1dd2, 0x11b2, \
{ 0x93, 0x7e, 0xc4, 0x5f, 0x14, 0xde, 0xf7, 0x78 }}
#define EMBED_CERTIFICATES_DESCRIPTION "Certificates Listener Impl"
class EmbedPrivate;
class EmbedCertificates
: public nsITokenPasswordDialogs,
public nsIBadCertListener,
#ifdef BAD_CERT_LISTENER2
public nsIBadCertListener2,
#endif
public nsICertificateDialogs,
public nsIClientAuthDialogs,
public nsICertPickDialogs,
public nsITokenDialogs,
public nsIDOMCryptoDialogs,
public nsIGeneratingKeypairInfoDialogs
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSITOKENPASSWORDDIALOGS
NS_DECL_NSIBADCERTLISTENER
#ifdef BAD_CERT_LISTENER2
NS_DECL_NSIBADCERTLISTENER2
#endif
NS_DECL_NSICERTIFICATEDIALOGS
NS_DECL_NSICLIENTAUTHDIALOGS
NS_DECL_NSICERTPICKDIALOGS
NS_DECL_NSITOKENDIALOGS
NS_DECL_NSIDOMCRYPTODIALOGS
NS_DECL_NSIGENERATINGKEYPAIRINFODIALOGS
EmbedCertificates();
virtual ~EmbedCertificates();
nsresult Init(void);
protected:
nsCOMPtr<nsIStringBundle> mPIPStringBundle;
};
#endif /* __EmbedCertificates_h */

View File

@@ -1,182 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <strings.h>
#include "nsIURI.h"
#include "EmbedContentListener.h"
#include "EmbedPrivate.h"
#include "nsServiceManagerUtils.h"
#include "nsIWebNavigationInfo.h"
#include "nsDocShellCID.h"
EmbedContentListener::EmbedContentListener(void)
{
mOwner = nsnull;
}
EmbedContentListener::~EmbedContentListener()
{
}
NS_IMPL_ISUPPORTS2(EmbedContentListener,
nsIURIContentListener,
nsISupportsWeakReference)
nsresult
EmbedContentListener::Init(EmbedPrivate *aOwner)
{
mOwner = aOwner;
return NS_OK;
}
NS_IMETHODIMP
EmbedContentListener::OnStartURIOpen(nsIURI *aURI,
PRBool *aAbortOpen)
{
nsresult rv;
if (mOwner->mOpenBlock) {
*aAbortOpen = mOwner->mOpenBlock;
mOwner->mOpenBlock = PR_FALSE;
return NS_OK;
}
nsCAutoString specString;
rv = aURI->GetSpec(specString);
if (NS_FAILED(rv))
return rv;
gint return_val = FALSE;
/* checks if URI scheme is mailto */
aURI->SchemeIs("mailto", &return_val);
if (return_val) {
/* stops URI opening to emit "mailto" signal */
*aAbortOpen = TRUE;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[MAILTO],
specString.get());
return NS_OK;
}
// otherwise ...
return_val = FALSE;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[OPEN_URI],
specString.get(), &return_val);
*aAbortOpen = return_val;
return NS_OK;
}
NS_IMETHODIMP
EmbedContentListener::DoContent(const char *aContentType,
PRBool aIsContentPreferred,
nsIRequest *aRequest,
nsIStreamListener **aContentHandler,
PRBool *aAbortProcess)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedContentListener::IsPreferred(const char *aContentType,
char **aDesiredContentType,
PRBool *aCanHandleContent)
{
return CanHandleContent(aContentType, PR_TRUE, aDesiredContentType,
aCanHandleContent);
}
NS_IMETHODIMP
EmbedContentListener::CanHandleContent(const char *aContentType,
PRBool aIsContentPreferred,
char **aDesiredContentType,
PRBool *_retval)
{
*_retval = PR_FALSE;
*aDesiredContentType = nsnull;
if (aContentType) {
nsCOMPtr<nsIWebNavigationInfo> webNavInfo(
do_GetService(NS_WEBNAVIGATION_INFO_CONTRACTID));
if (webNavInfo) {
PRUint32 canHandle;
nsresult rv =
webNavInfo->IsTypeSupported(nsDependentCString(aContentType),
mOwner ? mOwner->mNavigation.get() : nsnull,
&canHandle); //FIXME XXX MEMLEAK
NS_ENSURE_SUCCESS(rv, rv);
*_retval = (canHandle != nsIWebNavigationInfo::UNSUPPORTED);
}
}
return NS_OK;
}
NS_IMETHODIMP
EmbedContentListener::GetLoadCookie(nsISupports **aLoadCookie)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedContentListener::SetLoadCookie(nsISupports *aLoadCookie)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedContentListener::GetParentContentListener(nsIURIContentListener **aParent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
EmbedContentListener::SetParentContentListener(nsIURIContentListener *aParent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@@ -1,68 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __EmbedContentListener_h
#define __EmbedContentListener_h
#include "nsIURIContentListener.h"
#include "nsWeakReference.h"
class EmbedPrivate;
class EmbedContentListener : public nsIURIContentListener,
public nsSupportsWeakReference
{
public:
EmbedContentListener();
virtual ~EmbedContentListener();
nsresult Init(EmbedPrivate *aOwner);
NS_DECL_ISUPPORTS
NS_DECL_NSIURICONTENTLISTENER
private:
EmbedPrivate *mOwner;
};
#endif /* __EmbedContentListener_h */

View File

@@ -1,634 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
/*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Oleg Romashin. Portions created by Oleg Romashin are Copyright (C) Oleg Romashin. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Oleg Romashin <romaxa@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "EmbedContextMenuInfo.h"
#include "nsIImageLoadingContent.h"
#include "imgILoader.h"
#include "nsIDOMDocument.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIDOMHTMLElement.h"
#include "nsIDOMHTMLHtmlElement.h"
#include "nsIDOMHTMLAnchorElement.h"
#include "nsIDOMHTMLImageElement.h"
#include "nsIDOMHTMLAreaElement.h"
#include "nsIDOMHTMLLinkElement.h"
#include "nsIDOMDocumentView.h"
#include "nsIDOMAbstractView.h"
#include "nsIDOMViewCSS.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIDOMCSSValue.h"
#include "nsIDOMCSSPrimitiveValue.h"
#include "nsNetUtil.h"
#include "nsUnicharUtils.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMNSEvent.h"
#include "nsIDOMWindow.h"
#include "nsIDOMWindowCollection.h"
#include "nsIWebBrowser.h"
#include "nsIDOM3Document.h"
#include "nsIContent.h"
#include "nsIPresShell.h"
#include "nsIFormControl.h"
#include "nsIDOMNSHTMLInputElement.h"
#include "nsIDOMNSHTMLTextAreaElement.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMHTMLTextAreaElement.h"
#include "nsIDOMNSHTMLDocument.h"
#include "nsIDOMNodeList.h"
#include "nsISelection.h"
#include "nsIDocument.h"
#include "EmbedPrivate.h"
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <glib.h>
#if defined(FIXED_BUG347731) || !defined(MOZ_ENABLE_LIBXUL)
#include "nsIFrame.h"
#endif
//*****************************************************************************
// class EmbedContextMenuInfo
//*****************************************************************************
EmbedContextMenuInfo::EmbedContextMenuInfo(EmbedPrivate *aOwner) : mCtxFrameNum(-1), mEmbedCtxType(0)
{
mOwner = aOwner;
mEventNode = nsnull;
mCtxDocument = nsnull;
mNSHHTMLElement = nsnull;
mNSHHTMLElementSc = nsnull;
mCtxEvent = nsnull;
mEventNode = nsnull;
mFormRect = nsRect(0,0,0,0);
}
EmbedContextMenuInfo::~EmbedContextMenuInfo(void)
{
mEventNode = nsnull;
mCtxDocument = nsnull;
mNSHHTMLElement = nsnull;
mNSHHTMLElementSc = nsnull;
mCtxEvent = nsnull;
mEventNode = nsnull;
}
NS_IMPL_ADDREF(EmbedContextMenuInfo)
NS_IMPL_RELEASE(EmbedContextMenuInfo)
NS_INTERFACE_MAP_BEGIN(EmbedContextMenuInfo)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
nsresult
EmbedContextMenuInfo::SetFrameIndex()
{
nsCOMPtr<nsIDOMWindowCollection> frames;
mCtxDomWindow->GetFrames(getter_AddRefs(frames));
nsCOMPtr<nsIDOMWindow> currentWindow;
PRUint32 frameCount = 0;
frames->GetLength(&frameCount);
for (unsigned int i= 0; i < frameCount; i++) {
frames->Item(i, getter_AddRefs(currentWindow));
nsCOMPtr<nsIDOMDocument> currentDoc;
currentWindow->GetDocument(getter_AddRefs(currentDoc));
if (currentDoc == mCtxDocument) {
mCtxFrameNum = i;
mCtxDomWindow = currentWindow;
nsCOMPtr<nsIDocument> doc = do_QueryInterface(currentDoc);
if (doc)
mCtxDocTitle = doc->GetDocumentTitle();
return NS_OK;
}
}
return NS_ERROR_FAILURE;
}
nsresult
EmbedContextMenuInfo::GetFormControlType(nsIDOMEvent* aEvent)
{
if (!aEvent)
return NS_OK;
nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aEvent));
nsCOMPtr<nsIDOMEventTarget> target;
nsevent->GetOriginalTarget(getter_AddRefs(target));
// mOrigTarget = target;
if (SetFormControlType(target)) {
nsCOMPtr<nsIDOMNode> eventNode = do_QueryInterface(target);
if (!eventNode)
return NS_OK;
//Frame Stuff
nsCOMPtr<nsIDOMDocument> domDoc;
nsresult rv = eventNode->GetOwnerDocument(getter_AddRefs(domDoc));
if (!NS_SUCCEEDED(rv) || !domDoc) {
return NS_OK;
}
mEventNode = eventNode;
mCtxDocument = domDoc;
nsCOMPtr<nsIDocument> doc = do_QueryInterface(mCtxDocument);
if (!doc)
return NS_OK;
nsIPresShell *presShell = doc->GetShellAt(0);
if (!presShell)
return NS_OK;
nsCOMPtr<nsIContent> tgContent = do_QueryInterface(mEventTarget);
nsIFrame* frame = nsnull;
#if defined(FIXED_BUG347731) || !defined(MOZ_ENABLE_LIBXUL)
#ifdef MOZILLA_1_8_BRANCH
presShell->GetPrimaryFrameFor(tgContent, &frame);
#else
frame = presShell->GetPrimaryFrameFor(tgContent);
#endif
if (frame)
mFormRect = frame->GetScreenRectExternal();
#endif
return NS_OK;
}
return NS_ERROR_FAILURE;
}
nsresult
EmbedContextMenuInfo::SetFormControlType(nsIDOMEventTarget *originalTarget)
{
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIContent> targetContent = do_QueryInterface(originalTarget);
mCtxFormType = 0;
#ifdef MOZILLA_1_8_BRANCH
if (targetContent && targetContent->IsContentOfType(nsIContent::eHTML_FORM_CONTROL)) {
#else
if (targetContent && targetContent->IsNodeOfType(nsIContent::eHTML_FORM_CONTROL)) {
#endif
nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(targetContent));
if (formControl) {
mCtxFormType = formControl->GetType();
rv = NS_OK;
//#ifdef MOZ_LOGGING
switch (mCtxFormType) {
case NS_FORM_BUTTON_BUTTON:
break;
case NS_FORM_BUTTON_RESET:
break;
case NS_FORM_BUTTON_SUBMIT:
break;
case NS_FORM_INPUT_BUTTON:
break;
case NS_FORM_INPUT_CHECKBOX:
break;
case NS_FORM_INPUT_FILE:
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_INPUT;
break;
case NS_FORM_INPUT_HIDDEN:
break;
case NS_FORM_INPUT_RESET:
break;
case NS_FORM_INPUT_IMAGE:
break;
case NS_FORM_INPUT_PASSWORD:
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_INPUT;
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_IPASSWORD;
break;
case NS_FORM_INPUT_RADIO:
break;
case NS_FORM_INPUT_SUBMIT:
break;
case NS_FORM_INPUT_TEXT:
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_INPUT;
break;
case NS_FORM_LABEL:
break;
case NS_FORM_OPTION:
break;
case NS_FORM_OPTGROUP:
break;
case NS_FORM_LEGEND:
break;
case NS_FORM_SELECT:
break;
case NS_FORM_TEXTAREA:
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_INPUT;
break;
case NS_FORM_OBJECT:
break;
default:
break;
}
if (mEmbedCtxType & GTK_MOZ_EMBED_CTX_INPUT) {
PRBool rdonly = PR_FALSE;
if (mCtxFormType == NS_FORM_TEXTAREA) {
nsCOMPtr<nsIDOMHTMLTextAreaElement> input;
input = do_QueryInterface(mEventNode, &rv);
if (!NS_FAILED(rv) && input)
rv = input->GetReadOnly(&rdonly);
if (!NS_FAILED(rv) && rdonly) {
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_ROINPUT;
}
} else {
nsCOMPtr<nsIDOMHTMLInputElement> input;
input = do_QueryInterface(mEventNode, &rv);
if (!NS_FAILED(rv) && input)
rv = input->GetReadOnly(&rdonly);
if (!NS_FAILED(rv) && rdonly) {
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_ROINPUT;
}
}
}
//#endif
}
}
return rv;
}
const char*
EmbedContextMenuInfo::GetSelectedText()
{
nsString cString;
nsresult rv = NS_ERROR_FAILURE;
if (mCtxFormType != 0 && mEventNode) {
PRInt32 TextLength = 0, selStart = 0, selEnd = 0;
if (mCtxFormType == NS_FORM_INPUT_TEXT || mCtxFormType == NS_FORM_INPUT_FILE) {
nsCOMPtr<nsIDOMNSHTMLInputElement> nsinput = do_QueryInterface(mEventNode, &rv);
if (NS_SUCCEEDED(rv) && nsinput)
nsinput->GetTextLength(&TextLength);
if (TextLength > 0) {
nsinput->GetSelectionEnd(&selEnd);
nsinput->GetSelectionStart(&selStart);
if (selStart < selEnd || mCtxFormType == NS_FORM_INPUT_FILE) {
nsCOMPtr<nsIDOMHTMLInputElement> input = do_QueryInterface(mEventNode, &rv);
rv = input->GetValue(cString);
}
}
} else if (mCtxFormType == NS_FORM_TEXTAREA) {
nsCOMPtr<nsIDOMNSHTMLTextAreaElement> nsinput = do_QueryInterface(mEventNode, &rv);
if (NS_SUCCEEDED(rv) && nsinput)
nsinput->GetTextLength(&TextLength);
if (TextLength > 0) {
nsinput->GetSelectionStart(&selStart);
nsinput->GetSelectionEnd(&selEnd);
if (selStart < selEnd) {
nsCOMPtr<nsIDOMHTMLTextAreaElement> input = do_QueryInterface(mEventNode, &rv);
rv = input->GetValue(cString);
}
}
}
if (NS_SUCCEEDED(rv) && !cString.IsEmpty()) {
if (selStart < selEnd) {
cString.Cut(0, selStart);
cString.Cut(selEnd-selStart, TextLength);
}
rv = NS_OK;
}
} else if (mCtxDocument) {
nsCOMPtr<nsIDOMNSHTMLDocument> htmlDoc = do_QueryInterface(mCtxDocument, &rv);
if (NS_FAILED(rv) || !htmlDoc)
return nsnull;
rv = htmlDoc->GetSelection(cString);
if (NS_FAILED(rv) || cString.IsEmpty())
return nsnull;
rv = NS_OK;
}
if (rv == NS_OK) {
return NS_ConvertUTF16toUTF8(cString).get();
}
return nsnull;
}
nsresult
EmbedContextMenuInfo::CheckDomImageElement(nsIDOMNode *node, nsString& aHref,
PRInt32 *aWidth, PRInt32 *aHeight)
{
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMHTMLImageElement> image =
do_QueryInterface(node, &rv);
if (image) {
rv = image->GetSrc(aHref);
if (NS_FAILED(rv)) {
return rv;
}
rv = image->GetWidth(aWidth);
rv = image->GetHeight(aHeight);
rv = NS_OK;
}
return rv;
}
nsresult
EmbedContextMenuInfo::GetImageRequest(imgIRequest **aRequest, nsIDOMNode *aDOMNode)
{
NS_ENSURE_ARG(aDOMNode);
NS_ENSURE_ARG_POINTER(aRequest);
// Get content
nsCOMPtr<nsIImageLoadingContent> content(do_QueryInterface(aDOMNode));
NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
return content->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
aRequest);
}
nsresult
EmbedContextMenuInfo::CheckDomHtmlNode(nsIDOMNode *aNode)
{
nsresult rv = NS_ERROR_FAILURE;
nsString uTag;
PRUint16 dnode_type;
nsCOMPtr<nsIDOMNode> node;
if (!aNode && mEventNode)
node = mEventNode;
nsCOMPtr<nsIDOMHTMLElement> element = do_QueryInterface(node, &rv);
if (!element) {
element = do_QueryInterface(mOrigNode, &rv);
if (element) {
node = mOrigNode;
element = do_QueryInterface(node, &rv);
}
}
rv = node->GetNodeType(&dnode_type);
if (NS_FAILED(rv)) {
return rv;
}
if (!((nsIDOMNode::ELEMENT_NODE == dnode_type) && element)) {
return rv;
}
nsCOMPtr<nsIDOMNSHTMLElement> nodeElement = do_QueryInterface(node, &rv);
if (NS_SUCCEEDED(rv) && nodeElement) {
mNSHHTMLElement = nodeElement;
} else {
mNSHHTMLElement = nsnull;
}
rv = element->GetLocalName(uTag);
if (NS_FAILED(rv)) {
return rv;
}
if (uTag.LowerCaseEqualsLiteral("object")) {
}
else if (uTag.LowerCaseEqualsLiteral("html")) {
}
else if (uTag.LowerCaseEqualsLiteral("a")) {
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(node);
anchor->GetHref(mCtxHref);
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_LINK;
if (anchor && !mCtxHref.IsEmpty()) {
if (mCtxHref.LowerCaseEqualsLiteral("text/smartbookmark")) {
nsCOMPtr<nsIDOMNode> childNode;
node->GetFirstChild(getter_AddRefs(childNode));
if (childNode) {
PRInt32 width, height;
rv = CheckDomImageElement(node, mCtxImgHref, &width, &height);
if (NS_SUCCEEDED(rv))
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_IMAGE;
}
} else if (StringBeginsWith(mCtxHref, NS_LITERAL_STRING("mailto:"))) {
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_EMAIL;
}
}
}
else if (uTag.LowerCaseEqualsLiteral("area")) {
nsCOMPtr<nsIDOMHTMLAreaElement> area = do_QueryInterface(node, &rv);
if (NS_SUCCEEDED(rv) && area) {
PRBool aNoHref = PR_FALSE;
rv = area->GetNoHref(&aNoHref);
if (aNoHref == PR_FALSE)
rv = area->GetHref(mCtxHref);
else
rv = area->GetTarget(mCtxHref);
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_LINK;
rv = NS_OK;
}
}
else if (uTag.LowerCaseEqualsLiteral("img")) {
PRInt32 width, height;
rv = CheckDomImageElement(node, mCtxImgHref, &width, &height);
if (NS_SUCCEEDED(rv))
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_IMAGE;
} else {
rv = NS_ERROR_FAILURE;
}
return rv;
}
nsresult
EmbedContextMenuInfo::UpdateContextData(void *aEvent)
{
NS_ENSURE_ARG_POINTER(aEvent);
nsresult rv;
nsCOMPtr<nsIDOMEvent> event = do_QueryInterface((nsISupports*)aEvent, &rv);
if (NS_FAILED(rv) || !event)
return NS_ERROR_FAILURE;
return UpdateContextData(event);
}
nsresult
EmbedContextMenuInfo::GetElementForScroll(nsIDOMEvent *aEvent)
{
if (!aEvent) return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aEvent));
nsCOMPtr<nsIDOMEventTarget> target;
nsevent->GetOriginalTarget(getter_AddRefs(target));
if (!target) return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIDOMNode> targetDOMNode(do_QueryInterface(target));
if (!targetDOMNode) return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIDOMDocument> targetDOMDocument;
targetDOMNode->GetOwnerDocument(getter_AddRefs(targetDOMDocument));
if (!targetDOMDocument) return NS_ERROR_UNEXPECTED;
return GetElementForScroll(targetDOMDocument);
}
nsresult
EmbedContextMenuInfo::GetElementForScroll(nsIDOMDocument *targetDOMDocument)
{
nsCOMPtr<nsIDOMElement> targetDOMElement;
targetDOMDocument->GetDocumentElement(getter_AddRefs(targetDOMElement));
if (!targetDOMElement) return NS_ERROR_UNEXPECTED;
nsString bodyName(NS_LITERAL_STRING("body"));
nsCOMPtr<nsIDOMNodeList> bodyList;
targetDOMElement->GetElementsByTagName(bodyName, getter_AddRefs(bodyList));
PRUint32 i = 0;
bodyList->GetLength(&i);
if (i) {
nsCOMPtr<nsIDOMNode> domBodyNode;
bodyList->Item(0, getter_AddRefs(domBodyNode));
if (!domBodyNode) return NS_ERROR_UNEXPECTED;
mNSHHTMLElementSc = do_QueryInterface(domBodyNode);
if (!mNSHHTMLElementSc) return NS_ERROR_UNEXPECTED;
}
return NS_OK;
}
nsresult
EmbedContextMenuInfo::UpdateContextData(nsIDOMEvent *aDOMEvent)
{
if (mCtxEvent == aDOMEvent)
return NS_OK;
nsresult rv = nsnull;
mCtxEvent = aDOMEvent;
NS_ENSURE_ARG_POINTER(mCtxEvent);
PRUint16 eventphase;
mCtxEvent->GetEventPhase(&eventphase);
if (!eventphase) {
mCtxEvent = nsnull;
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDOMEventTarget> originalTarget = nsnull;
nsCOMPtr<nsIDOMNode> originalNode = nsnull;
nsCOMPtr<nsIDOMNSEvent> aEvent = do_QueryInterface(mCtxEvent, &rv);
if (NS_FAILED(rv) || !aEvent)
return NS_OK;
nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(mCtxEvent, &rv));
if (mouseEvent) {
((nsIDOMMouseEvent*)mouseEvent)->GetClientX(&mX);
((nsIDOMMouseEvent*)mouseEvent)->GetClientY(&mY);
}
if (aEvent)
rv = aEvent->GetOriginalTarget(getter_AddRefs(originalTarget));
originalNode = do_QueryInterface(originalTarget);
if (NS_FAILED(rv) || !originalNode)
return NS_ERROR_NULL_POINTER;
// nsresult SelText = mOwner->ClipBoardAction(GTK_MOZ_EMBED_CAN_COPY);
if (originalNode == mOrigNode)
return NS_OK;
mEmbedCtxType = GTK_MOZ_EMBED_CTX_NONE;
mOrigNode = originalNode;
if (mOrigNode) {
nsString SOrigNode;
mOrigNode->GetNodeName(SOrigNode);
if (SOrigNode.EqualsLiteral("#document"))
return NS_OK;
if (SOrigNode.EqualsLiteral("xul:thumb")
|| SOrigNode.EqualsLiteral("xul:slider")
|| SOrigNode.EqualsLiteral("xul:scrollbarbutton")
|| SOrigNode.EqualsLiteral("xul:vbox")
|| SOrigNode.EqualsLiteral("xul:spacer")) {
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_XUL;
return NS_OK;
}
}
if (mCtxEvent)
rv = mCtxEvent->GetTarget(getter_AddRefs(mEventTarget));
if (NS_FAILED(rv) || !mEventTarget) {
return NS_OK;
}
nsCOMPtr<nsIDOMNode> eventNode = do_QueryInterface(mEventTarget, &rv);
mEventNode = eventNode;
//Frame Stuff
nsCOMPtr<nsIDOMDocument> domDoc;
if (mEventNode)
rv = mEventNode->GetOwnerDocument(getter_AddRefs(domDoc));
if (!NS_SUCCEEDED(rv) || !domDoc) {
// return NS_OK;
}
if (NS_SUCCEEDED(rv) && domDoc && mCtxDocument != domDoc) {
mCtxDocument = domDoc;
mNSHHTMLElementSc = nsnull;
nsCOMPtr<nsIDOM3Document> docuri = do_QueryInterface(mCtxDocument);
docuri->GetDocumentURI(mCtxURI);
NS_ENSURE_ARG_POINTER(mOwner);
nsCOMPtr<nsIWebBrowser> webBrowser;
mOwner->mWindow->GetWebBrowser(getter_AddRefs(webBrowser));
webBrowser->GetContentDOMWindow(getter_AddRefs(mCtxDomWindow));
nsCOMPtr<nsIDOMDocument> mainDocument;
mCtxDomWindow->GetDocument(getter_AddRefs(mainDocument));
if (!mainDocument) {
return NS_OK;
}
mCtxFrameNum = -1;
if (mainDocument != domDoc) {
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_IFRAME;
SetFrameIndex();
}
}
nsCOMPtr<nsIDOMElement> targetDOMElement;
mCtxDocument->GetDocumentElement(getter_AddRefs(targetDOMElement));
if (!targetDOMElement) return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIDOMNSHTMLDocument> htmlDoc = do_QueryInterface(mCtxDocument);
if (htmlDoc) {
nsString DMode;
htmlDoc->GetDesignMode(DMode);
if (DMode.EqualsLiteral("on")) {
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_INPUT;
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_RICHEDIT;
}
}
nsCOMPtr<nsIDocument> doc = do_QueryInterface(mCtxDocument);
if (!doc)
return NS_OK;
nsIPresShell *presShell = doc->GetShellAt(0);
if (!presShell)
return NS_OK;
nsCOMPtr<nsIContent> tgContent = do_QueryInterface(mEventTarget);
nsIFrame* frame = nsnull;
#if defined(FIXED_BUG347731) || !defined(MOZ_ENABLE_LIBXUL)
if (mEmbedCtxType & GTK_MOZ_EMBED_CTX_RICHEDIT)
frame = presShell->GetRootFrame();
else {
#ifdef MOZILLA_1_8_BRANCH
frame = nsnull;
presShell->GetPrimaryFrameFor(tgContent, &frame);
#else
frame = presShell->GetPrimaryFrameFor(tgContent);
#endif
}
if (frame) {
mFormRect = frame->GetScreenRectExternal();
}
#endif
if (NS_SUCCEEDED(SetFormControlType(mEventTarget))) {
return NS_OK;
}
CheckDomHtmlNode();
nsCOMPtr<nsIDOMNode> node = mEventNode;
nsCOMPtr<nsIDOMNode> parentNode;
node->GetParentNode(getter_AddRefs(parentNode));
node = parentNode;
while (node) {
if (NS_FAILED(CheckDomHtmlNode()))
break;
node->GetParentNode(getter_AddRefs(parentNode));
node = parentNode;
}
mEmbedCtxType |= GTK_MOZ_EMBED_CTX_DOCUMENT;
return NS_OK;
}

View File

@@ -1,101 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
/*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Mozilla browser.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Oleg Romashin. Portions created by Oleg Romashin are Copyright (C) Oleg Romashin. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Oleg Romashin <romaxa@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef EmbedContextMenuInfo_h__
#define EmbedContextMenuInfo_h__
#include "nsCOMPtr.h"
#include "nsIDOMNode.h"
#include "nsIDOMEvent.h"
#include "imgIContainer.h"
#include "imgIRequest.h"
#include "nsIDOMEventTarget.h"
#include "nsRect.h"
// for strings
#ifdef MOZILLA_INTERNAL_API
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#endif
#include "EmbedWindow.h"
#include "nsIDOMNSHTMLElement.h"
//*****************************************************************************
// class EmbedContextMenuInfo
//
//*****************************************************************************
class EmbedContextMenuInfo : public nsISupports
{
public:
EmbedContextMenuInfo(EmbedPrivate *aOwner);
virtual ~EmbedContextMenuInfo(void);
NS_DECL_ISUPPORTS
nsresult GetFormControlType(nsIDOMEvent *aDOMEvent);
nsresult UpdateContextData(nsIDOMEvent *aDOMEvent);
nsresult UpdateContextData(void *aEvent);
const char* GetSelectedText();
nsresult GetElementForScroll(nsIDOMDocument *targetDOMDocument);
nsresult GetElementForScroll(nsIDOMEvent *aEvent);
nsresult CheckDomImageElement(nsIDOMNode *node, nsString& aHref,
PRInt32 *aWidth, PRInt32 *aHeight);
nsresult GetImageRequest(imgIRequest **aRequest, nsIDOMNode *aDOMNode);
nsString GetCtxDocTitle(void) { return mCtxDocTitle; };
PRInt32 mX, mY, mObjWidth, mObjHeight, mCtxFrameNum;
nsString mCtxURI, mCtxHref, mCtxImgHref;
PRUint32 mEmbedCtxType;
PRInt32 mCtxFormType;
nsCOMPtr<nsIDOMNode> mEventNode;
nsCOMPtr<nsIDOMEventTarget> mEventTarget;
nsCOMPtr<nsIDOMDocument>mCtxDocument;
nsRect mFormRect;
nsCOMPtr<nsIDOMWindow> mCtxDomWindow;
nsCOMPtr<nsIDOMEvent> mCtxEvent;
nsCOMPtr<nsIDOMNSHTMLElement> mNSHHTMLElement;
nsCOMPtr<nsIDOMNSHTMLElement> mNSHHTMLElementSc;
private:
nsresult SetFrameIndex();
nsresult SetFormControlType(nsIDOMEventTarget *originalTarget);
nsresult CheckDomHtmlNode(nsIDOMNode *aNode = nsnull);
EmbedPrivate *mOwner;
nsCOMPtr<nsIDOMNode> mOrigNode;
nsString mCtxDocTitle;
}; // class EmbedContextMenuInfo
#endif // EmbedContextMenuInfo_h__

View File

@@ -1,328 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* Derived from GContentHandler http://landfill.mozilla.org/mxr-test/gnome/source/galeon/mozilla/ContentHandler.cpp
*/
#include "EmbedDownloadMgr.h"
#include "EmbedGtkTools.h"
#ifdef MOZILLA_INTERNAL_API
#include "nsXPIDLString.h"
#else
#include "nsComponentManagerUtils.h"
#endif
#include "nsIChannel.h"
#include "nsIWebProgress.h"
#include "nsIDOMWindow.h"
#include "nsIURI.h"
#include "nsCRT.h"
#include "nsIPromptService.h"
#include "nsIWebProgressListener2.h"
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIURI.h"
#include "nsIURL.h"
#include "nsIFile.h"
#include "nsIDOMWindow.h"
#include "nsIExternalHelperAppService.h"
#include "nsCExternalHandlerService.h"
#include "nsMemory.h"
#include "nsNetError.h"
#include "nsIStreamListener.h"
#include "nsIFile.h"
#include "nsILocalFile.h"
#include "nsNetCID.h"
#include <unistd.h>
#include "gtkmozembed_download.h"
#include "nsIIOService.h"
#define UNKNOWN_FILE_SIZE -1
class EmbedDownloadMgr;
class ProgressListener : public nsIWebProgressListener2
{
public:
ProgressListener(EmbedDownload *aDownload):mDownload(aDownload)
{
};
~ProgressListener(void)
{
};
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_NSIWEBPROGRESSLISTENER2
EmbedDownload *mDownload;
};
NS_IMPL_ISUPPORTS2(ProgressListener, nsIWebProgressListener2, nsIWebProgressListener)
NS_IMPL_ISUPPORTS1(EmbedDownloadMgr, nsIHelperAppLauncherDialog)
EmbedDownloadMgr::EmbedDownloadMgr(void)
{
}
EmbedDownloadMgr::~EmbedDownloadMgr(void)
{
}
static gchar *
RemoveSchemeFromFilePath(gchar *path)
{
gchar *new_path = path;
if (!strncmp(path, "file://", 7)) {
/* XXX this should really look for the first non / after file:/ instead of
* assuming file://tmp v. file:///tmp
*/
new_path = g_strdup(path+sizeof("file:/"));
g_free(path);
}
return new_path;
}
NS_IMETHODIMP
EmbedDownloadMgr::Show(nsIHelperAppLauncher *aLauncher,
nsISupports *aContext,
PRUint32 aForced)
{
nsresult rv;
/* create a Download object */
GtkObject* instance = gtk_moz_embed_download_new();
mDownload = (EmbedDownload *) GTK_MOZ_EMBED_DOWNLOAD(instance)->data;
mDownload->parent = instance;
rv = GetDownloadInfo(aLauncher, aContext);
/* Retrieve GtkMozEmbed object from DOM Window */
nsCOMPtr<nsIDOMWindow> parentDOMWindow = do_GetInterface(aContext);
mDownload->gtkMozEmbedParentWidget = GetGtkWidgetForDOMWindow(parentDOMWindow);
gtk_signal_emit(GTK_OBJECT(mDownload->gtkMozEmbedParentWidget),
moz_embed_signals[DOWNLOAD_REQUEST],
mDownload->server,
mDownload->file_name,
mDownload->file_type,
(gulong) mDownload->file_size,
1);
gtk_signal_emit(GTK_OBJECT(mDownload->parent),
moz_embed_download_signals[DOWNLOAD_STARTED_SIGNAL],
&mDownload->file_name_with_path);
if (!mDownload->file_name_with_path) {
gtk_moz_embed_download_do_command(GTK_MOZ_EMBED_DOWNLOAD(mDownload->parent),
GTK_MOZ_EMBED_DOWNLOAD_CANCEL);
return NS_OK;
}
mDownload->file_name_with_path = RemoveSchemeFromFilePath(mDownload->file_name_with_path);
return aLauncher->SaveToDisk(nsnull, PR_FALSE);
}
NS_METHOD
EmbedDownloadMgr::GetDownloadInfo(nsIHelperAppLauncher *aLauncher,
nsISupports *aContext)
{
/* File type */
nsCOMPtr<nsIMIMEInfo> mimeInfo;
nsresult rv = aLauncher->GetMIMEInfo(getter_AddRefs(mimeInfo));
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
nsCAutoString mimeType;
rv = mimeInfo->GetMIMEType(mimeType);
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
/* File name */
nsCAutoString tempFileName;
nsAutoString suggestedFileName;
rv = aLauncher->GetSuggestedFileName(suggestedFileName);
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
tempFileName = NS_ConvertUTF16toUTF8(suggestedFileName);
/* Complete source URL */
nsCOMPtr<nsIURI> uri;
rv = aLauncher->GetSource(getter_AddRefs(uri));
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
nsCAutoString spec;
rv = uri->Resolve(NS_LITERAL_CSTRING("."), spec);
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
/* Sets download object to keep control of each download. */
mDownload->launcher = aLauncher;
mDownload->downloaded_size = -1;
mDownload->file_name = g_strdup((gchar *) tempFileName.get());
mDownload->server = g_strconcat(spec.get(), (gchar *) mDownload->file_name, NULL);
mDownload->file_type = g_strdup(mimeType.get());
mDownload->file_size = UNKNOWN_FILE_SIZE;
return NS_OK;
}
NS_IMETHODIMP EmbedDownloadMgr::PromptForSaveToFile(nsIHelperAppLauncher *aLauncher,
nsISupports *aWindowContext,
const PRUnichar *aDefaultFile,
const PRUnichar *aSuggestedFileExtension,
nsILocalFile **_retval)
{
*_retval = nsnull;
nsCAutoString filePath;
filePath.Assign(mDownload->file_name_with_path);
nsCOMPtr<nsILocalFile> destFile;
NS_NewNativeLocalFile(filePath,
PR_TRUE,
getter_AddRefs(destFile));
if (!destFile)
return NS_ERROR_OUT_OF_MEMORY;
/* Progress listener to follow the download and connecting it to
the launcher which controls the download. */
nsCOMPtr<nsIWebProgressListener2> listener = new ProgressListener(mDownload);
if (!listener)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = aLauncher->SetWebProgressListener(listener);
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
NS_ADDREF(*_retval = destFile);
return NS_OK;
}
/* nsIWebProgressListener Functions
all these methods must be here due to nsIWebProgressListener/2 inheritance */
NS_IMETHODIMP ProgressListener::OnStatusChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsresult aStatus,
const PRUnichar *aMessage)
{
if (NS_SUCCEEDED(aStatus))
return NS_OK;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP ProgressListener::OnStateChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest, PRUint32 aStateFlags,
nsresult aStatus)
{
if (NS_FAILED(aStatus))
return NS_ERROR_FAILURE;
if (aStateFlags & STATE_STOP)
gtk_signal_emit(GTK_OBJECT(mDownload->parent),
moz_embed_download_signals[DOWNLOAD_COMPLETED_SIGNAL]);
return NS_OK;
}
NS_IMETHODIMP ProgressListener::OnProgressChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest, PRInt32 aCurSelfProgress,
PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress,
PRInt32 aMaxTotalProgress)
{
return OnProgressChange64(aWebProgress,
aRequest,
aCurSelfProgress,
aMaxSelfProgress,
aCurTotalProgress,
aMaxTotalProgress);
}
NS_IMETHODIMP ProgressListener::OnLocationChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest, nsIURI *location)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP ProgressListener::OnSecurityChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest, PRUint32 state)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* nsIWebProgressListener2 method */
NS_IMETHODIMP ProgressListener::OnProgressChange64(nsIWebProgress *aWebProgress,
nsIRequest *aRequest, PRInt64 aCurSelfProgress,
PRInt64 aMaxSelfProgress, PRInt64 aCurTotalProgress,
PRInt64 aMaxTotalProgress)
{
mDownload->request = aRequest;
if (aMaxSelfProgress != UNKNOWN_FILE_SIZE) {
gtk_signal_emit(GTK_OBJECT(mDownload->parent),
moz_embed_download_signals[DOWNLOAD_PROGRESS_SIGNAL],
(gulong) aCurSelfProgress, (gulong) aMaxSelfProgress, 1);
}
else {
gtk_signal_emit(GTK_OBJECT(mDownload->parent),
moz_embed_download_signals[DOWNLOAD_PROGRESS_SIGNAL],
(gulong) aCurSelfProgress, 0, 1);
}
/* storing current downloaded size. */
mDownload->downloaded_size = (gulong) aCurSelfProgress;
return NS_OK;
}
NS_IMETHODIMP ProgressListener::OnRefreshAttempted(nsIWebProgress *aWebProgress,
nsIURI *aUri, PRInt32 aDelay,
PRBool aSameUri,
PRBool *allowRefresh)
{
*allowRefresh = PR_TRUE;
return NS_OK;
}

View File

@@ -1,98 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* Derived from GContentHandler http://landfill.mozilla.org/mxr-test/gnome/source/galeon/mozilla/ContentHandler.h
*/
#ifndef __EmbedDownloadMgr_h
#define __EmbedDownloadMgr_h
#include "EmbedPrivate.h"
#include "nsIHelperAppLauncherDialog.h"
#include "nsIMIMEInfo.h"
#include "nsCOMPtr.h"
#include "nsIExternalHelperAppService.h"
#include "nsIRequest.h"
#include "nsILocalFile.h"
#include "nsWeakReference.h"
#define EMBED_DOWNLOADMGR_DESCRIPTION "MicroB Download Manager"
#define EMBED_DOWNLOADMGR_CID {0x53df12a2, 0x1f4a, 0x4382, {0x99, 0x4e, 0xed, 0x62, 0xcf, 0x0d, 0x6b, 0x3a}}
class nsIURI;
class nsIFile;
class nsIFactory;
class nsExternalAppHandler;
typedef struct _EmbedDownload EmbedDownload;
struct _EmbedDownload
{
GtkObject* parent;
GtkWidget* gtkMozEmbedParentWidget;/** Associated gtkmozembed widget */
char* file_name; /** < The file's name */
char* file_name_with_path; /** < The file's name */
const char* server; /** < The server's name */
const char* file_type; /** < The file's type */
const char* handler_app; /** < The application's name */
PRInt64 file_size; /** < The file's size */
PRInt64 downloaded_size; /** < The download's size */
gboolean is_paused; /** < If download is paused or not */
gboolean open_with; /** < If the file can be opened by other application */
/* Pointer to mozilla interfaces */
nsIHelperAppLauncher* launcher; /** < The mozilla's download dialog */
nsIRequest* request; /** < The download request */
};
class EmbedDownloadMgr : public nsIHelperAppLauncherDialog
{
public:
EmbedDownloadMgr();
virtual ~EmbedDownloadMgr();
NS_DECL_ISUPPORTS
NS_DECL_NSIHELPERAPPLAUNCHERDIALOG
private:
/** Gets all informations about a file which is being downloaded.
*/
NS_METHOD GetDownloadInfo(nsIHelperAppLauncher *aLauncher, nsISupports *aContext);
EmbedDownload *mDownload;
};
#endif /* __EmbedDownloadMgr_h */

View File

@@ -1,955 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Oleg Romashin <romaxa@gmail.com>
* Tomaz Noleto <tnoleto@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCOMPtr.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMNSEvent.h"
#include "nsIDOMKeyEvent.h"
#include "nsIDOMUIEvent.h"
#include "nsIDOMDocument.h"
#include "nsIDocument.h"
#include "nsIContent.h"
#include "nsIPresShell.h"
#include "nsIDOMNodeList.h"
#include "EmbedEventListener.h"
#include "EmbedPrivate.h"
#include "gtkmozembed_internal.h"
static PRInt32 sLongPressTimer = 0, mLongMPressDelay = 1000;
static PRInt32 sX = 0, sY = 0;
static PRBool sMPressed = PR_FALSE, sIsScrolling = PR_FALSE;
static char* gFavLocation = NULL;
EmbedEventListener::EmbedEventListener(void)
{
mOwner = nsnull;
}
EmbedEventListener::~EmbedEventListener()
{
delete mCtxInfo;
}
NS_IMPL_ADDREF(EmbedEventListener)
NS_IMPL_RELEASE(EmbedEventListener)
NS_INTERFACE_MAP_BEGIN(EmbedEventListener)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMKeyListener)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMKeyListener)
NS_INTERFACE_MAP_ENTRY(nsIDOMKeyListener)
NS_INTERFACE_MAP_ENTRY(nsIDOMMouseListener)
NS_INTERFACE_MAP_ENTRY(nsIDOMUIListener)
NS_INTERFACE_MAP_ENTRY(nsIDOMMouseMotionListener)
NS_INTERFACE_MAP_ENTRY(nsIDOMFocusListener)
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
NS_INTERFACE_MAP_END
nsresult
EmbedEventListener::Init(EmbedPrivate *aOwner)
{
mOwner = aOwner;
mCtxInfo = nsnull;
mClickCount = 1;
#ifdef MOZ_WIDGET_GTK2
mCtxInfo = new EmbedContextMenuInfo(aOwner);
#endif
mOwner->mNeedFav = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::HandleLink(nsIDOMNode* node)
{
nsresult rv;
nsCOMPtr<nsIDOMElement> linkElement;
linkElement = do_QueryInterface(node);
if (!linkElement) return NS_ERROR_FAILURE;
nsString name;
rv = linkElement->GetAttribute(NS_LITERAL_STRING("rel"), name);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
nsString link;
rv = linkElement->GetAttribute(NS_LITERAL_STRING("href"), link);
if (NS_FAILED(rv) || link.IsEmpty()) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMDocument> domDoc;
rv = node->GetOwnerDocument(getter_AddRefs(domDoc));
if (NS_FAILED(rv) || !domDoc) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOM3Node> domnode = do_QueryInterface(domDoc);
if (!domnode) return NS_ERROR_FAILURE;
nsString spec;
domnode->GetBaseURI(spec);
nsCOMPtr<nsIURI> baseURI;
rv = NewURI(getter_AddRefs(baseURI), NS_ConvertUTF16toUTF8(spec).get());
if (NS_FAILED(rv) || !baseURI) return NS_ERROR_FAILURE;
nsCString url;
rv = baseURI->Resolve(NS_ConvertUTF16toUTF8(link), url);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
nsString type;
rv = linkElement->GetAttribute(NS_LITERAL_STRING("type"), type);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
nsString title;
rv = linkElement->GetAttribute(NS_LITERAL_STRING("title"), title);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
// XXX This does not handle |BLAH ICON POWER"
if (mOwner->mNeedFav && (name.LowerCaseEqualsLiteral("icon") ||
name.LowerCaseEqualsLiteral("shortcut icon"))) {
mOwner->mNeedFav = PR_FALSE;
this->GetFaviconFromURI(url.get());
}
else if (name.LowerCaseEqualsLiteral("alternate") &&
type.LowerCaseEqualsLiteral("application/rss+xml")) {
NS_ConvertUTF16toUTF8 narrowTitle(title);
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[RSS_REQUEST],
(gchar *)url.get(),
narrowTitle.get());
}
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::HandleEvent(nsIDOMEvent* aDOMEvent)
{
nsString eventType;
aDOMEvent->GetType(eventType);
#ifdef MOZ_WIDGET_GTK2
if (eventType.EqualsLiteral("focus"))
if (mCtxInfo->GetFormControlType(aDOMEvent)) {
if (mCtxInfo->mEmbedCtxType & GTK_MOZ_EMBED_CTX_INPUT) {
gint return_val = FALSE;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[DOM_FOCUS],
(void *)aDOMEvent, &return_val);
if (return_val) {
aDOMEvent->StopPropagation();
aDOMEvent->PreventDefault();
}
}
}
#endif
if (eventType.EqualsLiteral("DOMLinkAdded")) {
nsresult rv;
nsCOMPtr<nsIDOMEventTarget> eventTarget;
aDOMEvent->GetTarget(getter_AddRefs(eventTarget));
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(eventTarget, &rv);
if (NS_FAILED(rv) || !node)
return NS_ERROR_FAILURE;
HandleLink(node);
} else if (eventType.EqualsLiteral("load")) {
nsIWebBrowser *webBrowser = nsnull;
gtk_moz_embed_get_nsIWebBrowser(mOwner->mOwningWidget, &webBrowser);
if (!webBrowser) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMWindow> DOMWindow;
webBrowser->GetContentDOMWindow(getter_AddRefs(DOMWindow));
if (!DOMWindow) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMDocument> doc;
DOMWindow->GetDocument(getter_AddRefs(doc));
if (!doc) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMNodeList> nodelist = nsnull;
doc->GetElementsByTagName( NS_LITERAL_STRING( "rss" ), getter_AddRefs( nodelist ));
if (nodelist) {
PRUint32 length = 0;
nodelist->GetLength(&length);
if (length >= 1) {
char *url = gtk_moz_embed_get_location(mOwner->mOwningWidget);
char *title = gtk_moz_embed_get_title(mOwner->mOwningWidget);
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[RSS_REQUEST],
(gchar*)url,
(gchar*)title);
if (url)
NS_Free(url);
if (title)
NS_Free(title);
}
}
}
else if (mOwner->mNeedFav) {
mOwner->mNeedFav = PR_FALSE;
nsCString favicon_url = mOwner->mPrePath;
favicon_url.AppendLiteral("/favicon.ico");
this->GetFaviconFromURI(favicon_url.get());
}
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::KeyDown(nsIDOMEvent* aDOMEvent)
{
nsCOMPtr<nsIDOMKeyEvent> keyEvent;
keyEvent = do_QueryInterface(aDOMEvent);
if (!keyEvent)
return NS_OK;
// Return FALSE to this function to mark the event as not
// consumed...
gint return_val = FALSE;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[DOM_KEY_DOWN],
(void *)keyEvent, &return_val);
if (return_val) {
aDOMEvent->StopPropagation();
aDOMEvent->PreventDefault();
}
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::KeyUp(nsIDOMEvent* aDOMEvent)
{
nsCOMPtr<nsIDOMKeyEvent> keyEvent;
keyEvent = do_QueryInterface(aDOMEvent);
if (!keyEvent)
return NS_OK;
// return FALSE to this function to mark this event as not
// consumed...
gint return_val = FALSE;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[DOM_KEY_UP],
(void *)keyEvent, &return_val);
if (return_val) {
aDOMEvent->StopPropagation();
aDOMEvent->PreventDefault();
} else {
//mCtxInfo->UpdateContextData(aDOMEvent);
}
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::KeyPress(nsIDOMEvent* aDOMEvent)
{
nsCOMPtr<nsIDOMKeyEvent> keyEvent;
keyEvent = do_QueryInterface(aDOMEvent);
if (!keyEvent)
return NS_OK;
// Return TRUE from your signal handler to mark the event as consumed.
gint return_val = FALSE;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[DOM_KEY_PRESS],
(void *)keyEvent, &return_val);
if (return_val) {
aDOMEvent->StopPropagation();
aDOMEvent->PreventDefault();
}
return NS_OK;
}
static gboolean
sLongMPress(void *aOwningWidget)
{
// Return TRUE from your signal handler to mark the event as consumed.
if (!sMPressed || sIsScrolling)
return FALSE;
sMPressed = PR_FALSE;
gint return_val = FALSE;
gtk_signal_emit(GTK_OBJECT(aOwningWidget),
moz_embed_signals[DOM_MOUSE_LONG_PRESS],
(void *)0, &return_val);
if (return_val) {
sMPressed = PR_FALSE;
}
return FALSE;
}
NS_IMETHODIMP
EmbedEventListener::MouseDown(nsIDOMEvent* aDOMEvent)
{
nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
mouseEvent = do_QueryInterface(aDOMEvent);
if (!mouseEvent)
return NS_OK;
// Return TRUE from your signal handler to mark the event as consumed.
sMPressed = PR_TRUE;
gint return_val = FALSE;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[DOM_MOUSE_DOWN],
(void *)mouseEvent, &return_val);
if (return_val) {
mClickCount = 2;
sMPressed = PR_FALSE;
#if 1
if (sLongPressTimer)
g_source_remove(sLongPressTimer);
#else
aDOMEvent->StopPropagation();
aDOMEvent->PreventDefault();
#endif
} else {
mClickCount = 1;
sLongPressTimer = g_timeout_add(mLongMPressDelay, sLongMPress, mOwner->mOwningWidget);
((nsIDOMMouseEvent*)mouseEvent)->GetScreenX(&sX);
((nsIDOMMouseEvent*)mouseEvent)->GetScreenY(&sY);
}
// handling event internally.
#ifdef MOZ_WIDGET_GTK2
HandleSelection(mouseEvent);
#endif
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::MouseUp(nsIDOMEvent* aDOMEvent)
{
nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
mouseEvent = do_QueryInterface(aDOMEvent);
if (!mouseEvent)
return NS_OK;
// handling event internally, first.
HandleSelection(mouseEvent);
// Return TRUE from your signal handler to mark the event as consumed.
if (sLongPressTimer)
g_source_remove(sLongPressTimer);
sMPressed = PR_FALSE;
mOwner->mOpenBlock = sIsScrolling;
sIsScrolling = sMPressed;
gint return_val = FALSE;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[DOM_MOUSE_UP],
(void *)mouseEvent, &return_val);
if (return_val) {
aDOMEvent->StopPropagation();
aDOMEvent->PreventDefault();
}
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::MouseClick(nsIDOMEvent* aDOMEvent)
{
nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
mouseEvent = do_QueryInterface(aDOMEvent);
if (!mouseEvent)
return NS_OK;
// Return TRUE from your signal handler to mark the event as consumed.
sMPressed = PR_FALSE;
gint return_val = FALSE;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[DOM_MOUSE_CLICK],
(void *)mouseEvent, &return_val);
if (return_val) {
aDOMEvent->StopPropagation();
aDOMEvent->PreventDefault();
}
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::MouseDblClick(nsIDOMEvent* aDOMEvent)
{
nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
mouseEvent = do_QueryInterface(aDOMEvent);
if (!mouseEvent)
return NS_OK;
// Return TRUE from your signal handler to mark the event as consumed.
if (sLongPressTimer)
g_source_remove(sLongPressTimer);
sMPressed = PR_FALSE;
gint return_val = FALSE;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[DOM_MOUSE_DBL_CLICK],
(void *)mouseEvent, &return_val);
if (return_val) {
aDOMEvent->StopPropagation();
aDOMEvent->PreventDefault();
}
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::MouseOver(nsIDOMEvent* aDOMEvent)
{
nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
mouseEvent = do_QueryInterface(aDOMEvent);
if (!mouseEvent)
return NS_OK;
// Return TRUE from your signal handler to mark the event as consumed.
gint return_val = FALSE;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[DOM_MOUSE_OVER],
(void *)mouseEvent, &return_val);
if (return_val) {
aDOMEvent->StopPropagation();
aDOMEvent->PreventDefault();
} else {
//mCtxInfo->UpdateContextData(aDOMEvent);
}
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::MouseOut(nsIDOMEvent* aDOMEvent)
{
nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
mouseEvent = do_QueryInterface(aDOMEvent);
if (!mouseEvent)
return NS_OK;
// Return TRUE from your signal handler to mark the event as consumed.
gint return_val = FALSE;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[DOM_MOUSE_OUT],
(void *)mouseEvent, &return_val);
if (return_val) {
aDOMEvent->StopPropagation();
aDOMEvent->PreventDefault();
}
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::Activate(nsIDOMEvent* aDOMEvent)
{
nsCOMPtr<nsIDOMUIEvent> uiEvent = do_QueryInterface(aDOMEvent);
if (!uiEvent)
return NS_OK;
// Return TRUE from your signal handler to mark the event as consumed.
gint return_val = FALSE;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[DOM_ACTIVATE],
(void *)uiEvent, &return_val);
if (return_val) {
aDOMEvent->StopPropagation();
aDOMEvent->PreventDefault();
}
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::FocusIn(nsIDOMEvent* aDOMEvent)
{
nsCOMPtr<nsIDOMUIEvent> uiEvent = do_QueryInterface(aDOMEvent);
if (!uiEvent)
return NS_OK;
// Return TRUE from your signal handler to mark the event as consumed.
gint return_val = FALSE;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[DOM_FOCUS_IN],
(void *)uiEvent, &return_val);
if (return_val) {
aDOMEvent->StopPropagation();
aDOMEvent->PreventDefault();
}
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::FocusOut(nsIDOMEvent* aDOMEvent)
{
nsCOMPtr<nsIDOMUIEvent> uiEvent = do_QueryInterface(aDOMEvent);
if (!uiEvent)
return NS_OK;
// Return TRUE from your signal handler to mark the event as consumed.
gint return_val = FALSE;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[DOM_FOCUS_OUT],
(void *)uiEvent, &return_val);
if (return_val) {
aDOMEvent->StopPropagation();
aDOMEvent->PreventDefault();
}
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::MouseMove(nsIDOMEvent* aDOMEvent)
{
if (mCurSelCon)
mCurSelCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
if (sMPressed &&
gtk_signal_handler_pending(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[DOM_MOUSE_SCROLL], TRUE)) {
// Return TRUE from your signal handler to mark the event as consumed.
nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aDOMEvent);
if (!mouseEvent)
return NS_OK;
PRInt32 newX, newY, subX, subY;
((nsIDOMMouseEvent*)mouseEvent)->GetScreenX(&newX);
((nsIDOMMouseEvent*)mouseEvent)->GetScreenY(&newY);
subX = newX - sX;
subY = newY - sY;
nsresult rv = NS_OK;
if (ABS(subX) > 10 || ABS(subY) > 10 || (sIsScrolling && sMPressed)) {
if (!sIsScrolling) {
gint return_val = FALSE;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[DOM_MOUSE_SCROLL],
(void *)mouseEvent, &return_val);
if (!return_val) {
sIsScrolling = PR_TRUE;
#ifdef MOZ_WIDGET_GTK2
if (mCtxInfo)
rv = mCtxInfo->GetElementForScroll(aDOMEvent);
#endif
} else {
sMPressed = PR_FALSE;
sIsScrolling = PR_FALSE;
}
}
if (sIsScrolling)
{
if (sLongPressTimer)
g_source_remove(sLongPressTimer);
#ifdef MOZ_WIDGET_GTK2
if (mCtxInfo->mNSHHTMLElementSc) {
PRInt32 x, y;
mCtxInfo->mNSHHTMLElementSc->GetScrollTop(&y);
mCtxInfo->mNSHHTMLElementSc->GetScrollLeft(&x);
#ifdef MOZ_SCROLL_TOP_LEFT_HACK
rv = mCtxInfo->mNSHHTMLElementSc->ScrollTopLeft(y - subY, x - subX);
#endif
} else
#endif
{
rv = NS_ERROR_UNEXPECTED;
}
if (rv == NS_ERROR_UNEXPECTED) {
nsCOMPtr<nsIDOMWindow> DOMWindow;
nsIWebBrowser *webBrowser = nsnull;
gtk_moz_embed_get_nsIWebBrowser(mOwner->mOwningWidget, &webBrowser);
webBrowser->GetContentDOMWindow(getter_AddRefs(DOMWindow));
DOMWindow->ScrollBy(-subX, -subY);
}
}
sX = newX;
sY = newY;
sIsScrolling = sMPressed;
}
}
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::DragMove(nsIDOMEvent* aMouseEvent)
{
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::Focus(nsIDOMEvent* aEvent)
{
nsString eventType;
aEvent->GetType(eventType);
#ifdef MOZ_WIDGET_GTK2
if (eventType.EqualsLiteral("focus") &&
mCtxInfo->GetFormControlType(aEvent) &&
mCtxInfo->mEmbedCtxType & GTK_MOZ_EMBED_CTX_INPUT) {
gint return_val = FALSE;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[DOM_FOCUS],
(void *)aEvent, &return_val);
if (return_val) {
aEvent->StopPropagation();
aEvent->PreventDefault();
}
}
#endif
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::Blur(nsIDOMEvent* aEvent)
{
gint return_val = FALSE;
mFocusInternalFrame = PR_FALSE;
nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aEvent));
nsCOMPtr<nsIDOMEventTarget> target;
nsevent->GetOriginalTarget(getter_AddRefs(target));
if (!target)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIContent> targetContent = do_QueryInterface(target);
if (targetContent) {
#ifdef MOZILLA_1_8_BRANCH
if (targetContent->IsContentOfType(nsIContent::eHTML_FORM_CONTROL)) {
#else
if (targetContent->IsNodeOfType(nsIContent::eHTML_FORM_CONTROL)) {
#endif
if (sLongPressTimer)
g_source_remove(sLongPressTimer);
sMPressed = sIsScrolling ? PR_FALSE : sMPressed;
sIsScrolling = PR_FALSE;
}
}
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::HandleSelection(nsIDOMMouseEvent* aDOMMouseEvent)
{
nsresult rv;
#ifdef MOZ_WIDGET_GTK2
/* This function gets called everytime that a mousedown or a mouseup
* event occurs.
*/
nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aDOMMouseEvent));
nsCOMPtr<nsIDOMEventTarget> target;
rv = nsevent->GetOriginalTarget(getter_AddRefs(target));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDOMNode> eventNode = do_QueryInterface(target);
nsCOMPtr<nsIDOMDocument> domDoc;
rv = eventNode->GetOwnerDocument(getter_AddRefs(domDoc));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc, &rv);
if (NS_FAILED(rv) || !doc)
return NS_ERROR_FAILURE;
nsIPresShell *presShell = doc->GetShellAt(0);
/* Gets nsISelectionController interface for the current context */
mCurSelCon = do_QueryInterface(presShell);
if (!mCurSelCon)
return NS_ERROR_FAILURE;
/* Gets event type */
nsString eventType;
rv = aDOMMouseEvent->GetType(eventType);
if (NS_FAILED(rv))
return rv;
/* Updates context to check which context is being clicked on */
mCtxInfo->UpdateContextData(aDOMMouseEvent);
/* If a mousedown after 1 click is done (and if clicked context is not a XUL
* one (e.g. scrollbar), the selection is disabled for that context.
*/
if (mCtxInfo->mEmbedCtxType & GTK_MOZ_EMBED_CTX_XUL || mCtxInfo->mEmbedCtxType & GTK_MOZ_EMBED_CTX_RICHEDIT)
return rv;
if (eventType.EqualsLiteral("mousedown")) {
if (mClickCount == 1)
rv = mCurSelCon->SetDisplaySelection(nsISelectionController::SELECTION_OFF);
} // mousedown
/* If a mouseup occurs, the selection for context is enabled again (despite of
* number of clicks). If this event occurs after 1 click, the selection of
* both last and current contexts are cleaned up.
*/
if (eventType.EqualsLiteral("mouseup")) {
/* Selection controller of current event context */
if (mCurSelCon) {
rv = mCurSelCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
if (mClickCount == 1) {
nsCOMPtr<nsISelection> domSel;
mCurSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
getter_AddRefs(domSel));
rv = domSel->RemoveAllRanges();
}
}
/* Selection controller of previous event context */
if (mLastSelCon) {
rv = mLastSelCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
if (mClickCount == 1) {
nsCOMPtr<nsISelection> domSel;
mLastSelCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
getter_AddRefs(domSel));
rv = domSel->RemoveAllRanges();
}
}
/* If 1 click was done (despite the event type), sets the last context's
* selection controller with current one
*/
if (mClickCount == 1)
mLastSelCon = mCurSelCon;
} // mouseup
#endif
return rv;
}
nsresult
EmbedEventListener::NewURI(nsIURI **result,
const char *spec)
{
nsresult rv;
nsCString cSpec(spec);
nsCOMPtr<nsIIOService> ioService;
rv = GetIOService(getter_AddRefs(ioService));
if (NS_FAILED(rv))
return rv;
rv = ioService->NewURI(cSpec, nsnull, nsnull, result);
return rv;
}
nsresult
EmbedEventListener::GetIOService(nsIIOService **ioService)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> mgr;
NS_GetServiceManager(getter_AddRefs(mgr));
if (!mgr) return NS_ERROR_FAILURE;
rv = mgr->GetServiceByContractID("@mozilla.org/network/io-service;1",
NS_GET_IID(nsIIOService),
(void **)ioService);
return rv;
}
#ifdef MOZ_WIDGET_GTK2
void
EmbedEventListener::GeneratePixBuf()
{
GdkPixbuf *pixbuf = NULL;
pixbuf = gdk_pixbuf_new_from_file(::gFavLocation, NULL);
if (!pixbuf) {
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[ICON_CHANGED],
NULL );
// remove the wrong favicon
// FIXME: need better impl...
nsCOMPtr<nsILocalFile> faviconFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
if (!faviconFile) {
NS_Free(::gFavLocation);
gFavLocation = nsnull;
return;
}
nsCString faviconLocation(::gFavLocation);
faviconFile->InitWithNativePath(faviconLocation);
faviconFile->Remove(FALSE);
NS_Free(::gFavLocation);
gFavLocation = nsnull;
return;
}
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[ICON_CHANGED],
pixbuf );
//mOwner->mNeedFav = PR_FALSE;
NS_Free(::gFavLocation);
gFavLocation = nsnull;
}
#endif
void
EmbedEventListener::GetFaviconFromURI(const char* aURI)
{
gchar *file_name = NS_strdup(aURI);
gchar *favicon_uri = NS_strdup(aURI);
gint i = 0;
gint rv = 0;
nsCOMPtr<nsIWebBrowserPersist> persist = do_CreateInstance(NS_WEBBROWSERPERSIST_CONTRACTID);
if (!persist) {
NS_Free(file_name);
NS_Free(favicon_uri);
return;
}
persist->SetProgressListener(this);
while (file_name[i] != '\0') {
if (file_name[i] == '/' || file_name[i] == ':')
file_name[i] = '_';
i++;
}
nsCString fileName(file_name);
nsCOMPtr<nsILocalFile> favicon_dir = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
if (!favicon_dir) {
NS_Free(favicon_uri);
NS_Free(file_name);
return;
}
nsCString faviconDir("~/.mozilla/favicon");
favicon_dir->InitWithNativePath(faviconDir);
PRBool isExist;
rv = favicon_dir->Exists(&isExist);
if (NS_SUCCEEDED(rv) && !isExist) {
rv = favicon_dir->Create(nsIFile::DIRECTORY_TYPE,0775);
if (NS_FAILED(rv)) {
NS_Free(file_name);
NS_Free(favicon_uri);
return;
}
}
nsCAutoString favicon_path("~/.mozilla/favicon");
nsCOMPtr<nsILocalFile> target_file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
if (!target_file) {
NS_Free(file_name);
NS_Free(favicon_uri);
return;
}
target_file->InitWithNativePath(favicon_path);
target_file->Append(NS_ConvertUTF8toUTF16(fileName));
nsString path;
target_file->GetPath(path);
::gFavLocation = NS_strdup(NS_ConvertUTF16toUTF8(path).get());
nsCOMPtr<nsIIOService> ios(do_GetService(NS_IOSERVICE_CONTRACTID));
if (!ios) {
NS_Free(file_name);
NS_Free(favicon_uri);
NS_Free(::gFavLocation);
gFavLocation = nsnull;
return;
}
nsCOMPtr<nsIURI> uri;
rv = ios->NewURI(nsDependentCString(favicon_uri), "", nsnull, getter_AddRefs(uri));
if (!uri) {
NS_Free(file_name);
NS_Free(favicon_uri);
NS_Free(::gFavLocation);
gFavLocation = nsnull;
return;
}
NS_Free(file_name);
NS_Free(favicon_uri);
// save the favicon if the icon does not exist
rv = target_file->Exists(&isExist);
if (NS_SUCCEEDED(rv) && !isExist) {
rv = persist->SaveURI(uri, nsnull, nsnull, nsnull, "", target_file);
if (NS_FAILED(rv)) {
return;
}
}
else {
#ifdef MOZ_WIDGET_GTK2
GeneratePixBuf();
#endif
}
}
NS_IMETHODIMP
EmbedEventListener::OnStateChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRUint32 aStateFlags,
nsresult aStatus)
{
/* if (!(aStateFlags & (STATE_STOP | STATE_IS_NETWORK | STATE_IS_DOCUMENT))){*/
#ifdef MOZ_WIDGET_GTK2
if (aStateFlags & STATE_STOP)
/* FINISH DOWNLOADING */
/* XXX sometimes this==0x0 and it cause crash in GeneratePixBuf, need workaround check for this */
if (NS_SUCCEEDED(aStatus) && this)
GeneratePixBuf();
#endif
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::OnProgressChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 aCurSelfProgress,
PRInt32 aMaxSelfProgress,
PRInt32 aCurTotalProgress,
PRInt32 aMaxTotalProgress)
{
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::OnLocationChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsIURI *aLocation)
{
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::OnStatusChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsresult aStatus,
const PRUnichar *aMessage)
{
return NS_OK;
}
NS_IMETHODIMP
EmbedEventListener::OnSecurityChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRUint32 aState)
{
return NS_OK;
}

View File

@@ -1,149 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Oleg Romashin <romaxa@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __EmbedEventListener_h
#define __EmbedEventListener_h
#include "nsIDOMKeyListener.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMUIListener.h"
#include "nsIDOMMouseMotionListener.h"
#include "nsIDOMEventListener.h"
#include "nsIDOMFocusListener.h"
#include "EmbedContextMenuInfo.h"
#include "nsIDOMNode.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIURI.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMEvent.h"
#include "nsIDOM3Node.h"
#include "nsIURI.h"
#include "nsIIOService.h"
#include "nsNetCID.h"
#include "nsCOMPtr.h"
#include "nsIFileURL.h"
#include "nsILocalFile.h"
#include "nsIFile.h"
#include "nsIWebBrowserPersist.h"
#include "nsCWebBrowserPersist.h"
#include "nsIWebProgressListener.h"
#include "nsISelectionController.h"
#include "nsIDOMMouseEvent.h"
#include "nsXPCOMStrings.h"
#include "nsCRTGlue.h"
class EmbedPrivate;
class EmbedEventListener : public nsIDOMKeyListener,
public nsIDOMMouseListener,
public nsIDOMUIListener,
public nsIDOMMouseMotionListener,
public nsIWebProgressListener,
public nsIDOMFocusListener
{
public:
EmbedEventListener();
virtual ~EmbedEventListener();
nsresult Init(EmbedPrivate *aOwner);
NS_DECL_ISUPPORTS
// NS_DECL_NSIDOMEVENTLISTENER
// nsIDOMEventListener
NS_DECL_NSIWEBPROGRESSLISTENER
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
NS_IMETHOD HandleLink(nsIDOMNode* node);
// nsIDOMKeyListener
NS_IMETHOD KeyDown(nsIDOMEvent* aDOMEvent);
NS_IMETHOD KeyUp(nsIDOMEvent* aDOMEvent);
NS_IMETHOD KeyPress(nsIDOMEvent* aDOMEvent);
// nsIDOMMouseListener
NS_IMETHOD MouseDown(nsIDOMEvent* aDOMEvent);
NS_IMETHOD MouseUp(nsIDOMEvent* aDOMEvent);
NS_IMETHOD MouseClick(nsIDOMEvent* aDOMEvent);
NS_IMETHOD MouseDblClick(nsIDOMEvent* aDOMEvent);
NS_IMETHOD MouseOver(nsIDOMEvent* aDOMEvent);
NS_IMETHOD MouseOut(nsIDOMEvent* aDOMEvent);
// nsIDOMUIListener
NS_IMETHOD Activate(nsIDOMEvent* aDOMEvent);
NS_IMETHOD FocusIn(nsIDOMEvent* aDOMEvent);
NS_IMETHOD FocusOut(nsIDOMEvent* aDOMEvent);
// nsIDOMMouseMotionListener
NS_IMETHOD MouseMove(nsIDOMEvent* aDOMEvent);
NS_IMETHOD DragMove(nsIDOMEvent* aMouseEvent);
EmbedContextMenuInfo* GetContextInfo() { return mCtxInfo; };
// nsIDOMFocusListener
NS_IMETHOD Focus(nsIDOMEvent* aEvent);
NS_IMETHOD Blur(nsIDOMEvent* aEvent);
NS_IMETHOD HandleSelection(nsIDOMMouseEvent* aDOMMouseEvent);
nsresult NewURI (nsIURI **result,
const char *spec);
nsresult GetIOService (nsIIOService **ioService);
void GeneratePixBuf ();
void GetFaviconFromURI (const char* aURI);
private:
EmbedPrivate *mOwner;
EmbedContextMenuInfo *mCtxInfo;
// Selection and some clipboard stuff
nsCOMPtr<nsISelectionController> mCurSelCon;
nsCOMPtr<nsISelectionController> mLastSelCon;
PRBool mFocusInternalFrame;
PRInt32 mClickCount;
};
#endif /* __EmbedEventListener_h */

View File

@@ -1,207 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
/*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* Contributor(s):
* Antonio Gomes <tonikitoo@gmail.com>
* Oleg Romashin <romaxa@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "EmbedFilePicker.h"
#include "EmbedGtkTools.h"
#include "nsIFileURL.h"
#include "nsILocalFile.h"
#include "nsIDOMWindow.h"
#include "nsStringGlue.h"
#include "nsNetUtil.h"
#include "prenv.h"
#ifdef MOZ_LOGGING
#include <stdlib.h>
#endif
NS_IMPL_ISUPPORTS1(EmbedFilePicker, nsIFilePicker)
EmbedFilePicker::EmbedFilePicker(): mParent (nsnull),
mMode(nsIFilePicker::modeOpen)
{
}
EmbedFilePicker::~EmbedFilePicker()
{
}
/* void init (in nsIDOMWindowInternal parent, in wstring title, in short mode); */
NS_IMETHODIMP EmbedFilePicker::Init(nsIDOMWindow *parent, const nsAString &title, PRInt16 mode)
{
mParent = parent;
mMode = mode;
return NS_OK;
}
/* void appendFilters (in long filterMask); */
NS_IMETHODIMP EmbedFilePicker::AppendFilters(PRInt32 filterMask)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void appendFilter (in wstring title, in wstring filter); */
NS_IMETHODIMP EmbedFilePicker::AppendFilter(const nsAString &title, const nsAString &filter)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute wstring defaultString; */
NS_IMETHODIMP EmbedFilePicker::GetDefaultString(nsAString &aDefaultString)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP EmbedFilePicker::SetDefaultString(const nsAString &aDefaultString)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute wstring defaultExtension; */
NS_IMETHODIMP EmbedFilePicker::GetDefaultExtension(nsAString &aDefaultExtension)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP EmbedFilePicker::SetDefaultExtension(const nsAString &aDefaultExtension)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute long filterIndex; */
NS_IMETHODIMP EmbedFilePicker::GetFilterIndex(PRInt32 *aFilterIndex)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP EmbedFilePicker::SetFilterIndex(PRInt32 aFilterIndex)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* attribute nsILocalFile displayDirectory; */
NS_IMETHODIMP EmbedFilePicker::GetDisplayDirectory(nsILocalFile **aDisplayDirectory)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP EmbedFilePicker::SetDisplayDirectory(nsILocalFile *aDisplayDirectory)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* readonly attribute nsILocalFile file; */
NS_IMETHODIMP EmbedFilePicker::GetFile(nsILocalFile **aFile)
{
NS_ENSURE_ARG_POINTER(aFile);
if (mFilename.IsEmpty())
return NS_OK;
nsCOMPtr<nsIURI> baseURI;
nsresult rv = NS_NewURI(getter_AddRefs(baseURI), mFilename);
nsCOMPtr<nsIFileURL> fileURL(do_QueryInterface(baseURI, &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIFile> file;
rv = fileURL->GetFile(getter_AddRefs(file));
nsCOMPtr<nsILocalFile> localfile;
localfile = do_QueryInterface(file, &rv);
if (NS_SUCCEEDED(rv)) {
NS_ADDREF(*aFile = localfile);
return NS_OK;
}
NS_ENSURE_TRUE(mParent, NS_OK);
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(mParent);
NS_ENSURE_TRUE(parentWidget, NS_OK);
/* XXX this message isn't really sure what it's trying to say */
g_signal_emit_by_name(GTK_OBJECT(parentWidget), "alert", "File protocol not supported.", NULL);
return NS_OK;
}
/* readonly attribute nsIFileURL fileURL; */
NS_IMETHODIMP EmbedFilePicker::GetFileURL(nsIFileURL **aFileURL)
{
NS_ENSURE_ARG_POINTER(aFileURL);
*aFileURL = nsnull;
nsCOMPtr<nsILocalFile> file;
GetFile(getter_AddRefs(file));
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
nsCOMPtr<nsIFileURL> fileURL = do_CreateInstance(NS_STANDARDURL_CONTRACTID);
NS_ENSURE_TRUE(fileURL, NS_ERROR_OUT_OF_MEMORY);
fileURL->SetFile(file);
NS_ADDREF(*aFileURL = fileURL);
return NS_OK;
}
/* readonly attribute nsISimpleEnumerator files; */
NS_IMETHODIMP EmbedFilePicker::GetFiles(nsISimpleEnumerator * *aFiles)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* short show (); */
NS_IMETHODIMP EmbedFilePicker::Show(PRInt16 *_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
NS_ENSURE_TRUE(mParent, NS_OK);
GtkWidget *parentWidget = GetGtkWidgetForDOMWindow(mParent);
NS_ENSURE_TRUE(parentWidget, NS_OK);
gboolean response = 0;
char *retname = nsnull;
g_signal_emit_by_name(GTK_OBJECT(parentWidget),
"upload_dialog",
PR_GetEnv("HOME"),
"",
&retname,
&response,
NULL);
*_retval = response ? nsIFilePicker::returnOK : nsIFilePicker::returnCancel;
mFilename = retname;
if (retname)
NS_Free(retname);
return NS_OK;
}

View File

@@ -1,72 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
/*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __EmbedFilePicker_h
#define __EmbedFilePicker_h
#include "nsIFilePicker.h"
#include "nsISupports.h"
#include "nsNetCID.h"
#include "gtkmozembed.h"
#include "gtkmozembed_common.h"
#include "EmbedPrivate.h"
#define EMBED_FILEPICKER_CID \
{ /* f097d33b-1c97-48a6-af4c-07022857eb7c */ \
0xf097d33b, \
0x1c97, \
0x48a6, \
{0xaf, 0x4c, 0x07, 0x02, 0x28, 0x57, 0xeb, 0x7c} \
}
#define EMBED_FILEPICKER_CONTRACTID "@mozilla.org/filepicker;1"
#define EMBED_FILEPICKER_CLASSNAME "File Picker Implementation"
class EmbedFilePicker : public nsIFilePicker
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFILEPICKER
EmbedFilePicker();
protected:
nsIDOMWindow *mParent;
PRInt16 mMode;
nsCString mFilename;
private:
~EmbedFilePicker();
};
#endif

View File

@@ -1,920 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
* Oleg Romashin <romaxa@gmail.com>
* (from original mozilla/embedding/lite/nsEmbedGlobalHistory.cpp)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/* XXX This file is probably out of sync with its original.
* This is a bad thing
*/
#include "EmbedGlobalHistory.h"
#include "nsIObserverService.h"
#include "nsAutoPtr.h"
#include "nsIURI.h"
#include "nsInt64.h"
#include "nsIIOService.h"
#include "nsNetUtil.h"
#include "gtkmozembed_common.h"
#include "nsISeekableStream.h"
#ifndef MOZILLA_INTERNAL_API
#include "nsCRT.h"
#endif
#include "nsILineInputStream.h"
// Constants
#define defaultSeparator 1
// Number of changes in history before automatic flush
static const PRInt32 kNewEntriesBetweenFlush = 10;
static const PRInt32 kMaxSafeReadEntriesCount = 2000;
// Default expiration interval: used if can't get preference service value
static const PRUint32 kDefaultExpirationIntervalDays = 7;
// Mozilla and EAL standard are different each other
static const PRInt64 kMSecsPerDay = LL_INIT(0, 60 * 60 * 24 * 1000);
static const PRInt64 kOneThousand = LL_INIT(0, 1000);
// The history list and the entries counter
static GList *mURLList; /** < The history list */
static PRInt64 mExpirationInterval; /** < Expiration interval time */
static EmbedGlobalHistory *sEmbedGlobalHistory = nsnull;
//*****************************************************************************
// HistoryEntryOld: an entry object and its methods
//*****************************************************************************
class HistoryEntry
{
public:
PRInt64 mLastVisitTime; // Millisecs
PRPackedBool mWritten; // TRUE if ever persisted
nsCString mTitle; // The entry title
nsCString mUrl; // The url itself
};
#define CLOSE_FILE_HANDLE(file_handle) \
PR_BEGIN_MACRO \
if (file_handle) { \
close_output_stream(file_handle); \
NS_RELEASE(file_handle); \
} \
PR_END_MACRO
static void close_output_stream(OUTPUT_STREAM *file_handle)
{
file_handle->Close();
return;
}
static bool file_handle_uri_exists(LOCAL_FILE *uri)
{
g_return_val_if_fail(uri, false);
PRBool exists = PR_FALSE;
uri->Exists(&exists);
return exists;
}
static LOCAL_FILE* file_handle_uri_new(const char *uri)
{
g_return_val_if_fail(uri, nsnull);
nsresult rv;
LOCAL_FILE *historyFile = nsnull;
rv = NS_NewNativeLocalFile(nsDependentCString(uri), 1, &historyFile);
return historyFile;
}
static void file_handle_uri_release(LOCAL_FILE *uri)
{
g_return_if_fail(uri);
NS_RELEASE(uri);
}
static bool file_handle_create_uri(OUTPUT_STREAM **file_handle, LOCAL_FILE *uri)
{
g_return_val_if_fail(file_handle, false);
nsresult rv;
rv = NS_NewLocalFileOutputStream(file_handle, uri, PR_RDWR | PR_APPEND | PR_CREATE_FILE, 0660);
return NS_SUCCEEDED(rv);
}
static bool file_handle_open_uri(OUTPUT_STREAM **file_handle, LOCAL_FILE *uri)
{
g_return_val_if_fail(file_handle, false);
nsresult rv;
rv = NS_NewLocalFileOutputStream(file_handle, uri, PR_RDWR, 0660);
return NS_SUCCEEDED(rv);
}
static bool file_handle_seek(OUTPUT_STREAM *file_handle, gboolean end)
{
g_return_val_if_fail(file_handle, false);
nsresult rv;
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(file_handle, &rv);
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, end ? -1 : 0);
return NS_SUCCEEDED(rv);
}
static bool file_handle_truncate(OUTPUT_STREAM *file_handle)
{
g_return_val_if_fail(file_handle, false);
nsresult rv;
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(file_handle, &rv);
rv = seekable->SetEOF();
return NS_SUCCEEDED(rv);
}
static guint64 file_handle_write(OUTPUT_STREAM *file_handle, gpointer line)
{
g_return_val_if_fail(file_handle, 0);
PRUint32 amt = 0;
nsresult rv;
rv = file_handle->Write((char*)line, strlen((char*)line), &amt);
/* XXX booleans are not equivalent to guint64 */
return NS_SUCCEEDED(rv);
}
// Static Routine Prototypes
//GnomeVFSHandle
static nsresult writeEntry(OUTPUT_STREAM *file_handle, HistoryEntry *entry);
// when an entry is visited
nsresult OnVisited(HistoryEntry *entry)
{
NS_ENSURE_ARG(entry);
entry->mLastVisitTime = PR_Now();
LL_DIV(entry->mLastVisitTime, entry->mLastVisitTime, kOneThousand);
return NS_OK;
}
// Return the last time an entry was visited
PRInt64 GetLastVisitTime(HistoryEntry *entry)
{
NS_ENSURE_ARG(entry);
return entry->mLastVisitTime;
}
// Change the last time an entry was visited
nsresult SetLastVisitTime(HistoryEntry *entry, const PRInt64& aTime)
{
NS_ENSURE_ARG(entry);
NS_ENSURE_ARG_POINTER(aTime);
entry->mLastVisitTime = aTime;
return NS_OK;
}
// Return TRUE if an entry has been written
PRBool GetIsWritten(HistoryEntry *entry)
{
NS_ENSURE_ARG(entry);
return entry->mWritten;
}
// Set TRUE when an entry is visited
nsresult SetIsWritten(HistoryEntry *entry)
{
NS_ENSURE_ARG(entry);
entry->mWritten = PR_TRUE;
return NS_OK;
}
// Change the entry title
#define SET_TITLE(entry, aTitle) (entry->mTitle.Assign(aTitle))
// Return the entry title
#define GET_TITLE(entry) (entry && !entry->mTitle.IsEmpty() ? entry->mTitle.get() : "")
// Change the entry title
nsresult SET_URL(HistoryEntry *aEntry, const char *aUrl)
{
NS_ENSURE_ARG(aEntry);
NS_ENSURE_ARG(aUrl);
aEntry->mUrl.Assign(aUrl);
return NS_OK;
}
// Return the entry url
const char* GET_URL(HistoryEntry *aEntry)
{
return (aEntry && !aEntry->mUrl.IsEmpty()) ? aEntry->mUrl.get() : "";
}
// Traverse the history list trying to find a frame
int history_entry_find_exist(gconstpointer a, gconstpointer b)
{
return g_ascii_strcasecmp((char*)GET_URL((HistoryEntry *)a), (char *) b);
}
// Traverse the history list looking for the correct place to add a new item
int find_insertion_place(gconstpointer a, gconstpointer b)
{
PRInt64 lastVisitTime = GetLastVisitTime((HistoryEntry *) a);
PRInt64 tempTime = GetLastVisitTime((HistoryEntry *) b);
return LL_CMP(lastVisitTime, <, tempTime);
}
// Check whether an entry has expired
PRBool entryHasExpired(HistoryEntry *entry)
{
// convert "now" from microsecs to millisecs
PRInt64 nowInMilliSecs = PR_Now();
LL_DIV(nowInMilliSecs, nowInMilliSecs, kOneThousand);
// determine when the entry would have expired
PRInt64 expirationIntervalAgo;
LL_SUB(expirationIntervalAgo, nowInMilliSecs, mExpirationInterval);
PRInt64 lastVisitTime = GetLastVisitTime(entry);
return LL_CMP(lastVisitTime, <, expirationIntervalAgo);
}
// Traverse the history list to get all the entry data
void history_entry_foreach_to_remove(gpointer data, gpointer user_data)
{
HistoryEntry *entry = (HistoryEntry *) data;
if (entry) {
entry->mLastVisitTime = 0;
delete entry;
}
}
//*****************************************************************************
// EmbedGlobalHistory - Creation/Destruction
//*****************************************************************************
NS_IMPL_ISUPPORTS2(EmbedGlobalHistory, nsIGlobalHistory2, nsIObserver)
/* static */
EmbedGlobalHistory*
EmbedGlobalHistory::GetInstance()
{
if (!sEmbedGlobalHistory)
{
sEmbedGlobalHistory = new EmbedGlobalHistory();
if (!sEmbedGlobalHistory)
return nsnull;
NS_ADDREF(sEmbedGlobalHistory); // addref the global
if (NS_FAILED(sEmbedGlobalHistory->Init()))
{
NS_RELEASE(sEmbedGlobalHistory);
return nsnull;
}
}
else
NS_ADDREF(sEmbedGlobalHistory); // addref the return result
return sEmbedGlobalHistory;
}
/* static */
void
EmbedGlobalHistory::DeleteInstance()
{
if (sEmbedGlobalHistory)
{
delete sEmbedGlobalHistory;
}
}
// The global history component constructor
EmbedGlobalHistory::EmbedGlobalHistory()
: mFileHandle(nsnull)
{
if (!mURLList) {
mDataIsLoaded = PR_FALSE;
mFlushModeFullWriteNeeded = PR_FALSE;
mEntriesAddedSinceFlush = 0;
mHistoryFile = nsnull;
LL_I2L(mExpirationInterval, kDefaultExpirationIntervalDays);
LL_MUL(mExpirationInterval, mExpirationInterval, kMSecsPerDay);
}
}
// The global history component destructor
EmbedGlobalHistory::~EmbedGlobalHistory()
{
LoadData();
FlushData(kFlushModeFullWrite);
if (mURLList) {
g_list_foreach(mURLList, (GFunc) history_entry_foreach_to_remove, NULL);
g_list_free(mURLList);
mURLList = NULL;
}
if (mFileHandle) {
CLOSE_FILE_HANDLE(mFileHandle);
}
if (mHistoryFile) {
g_free(mHistoryFile);
mHistoryFile = nsnull;
}
if (sEmbedGlobalHistory)
sEmbedGlobalHistory = nsnull;
}
// Initialize the global history component
NS_IMETHODIMP EmbedGlobalHistory::Init()
{
if (mURLList) return NS_OK;
// Get Pref and convert to millisecs
PRInt32 expireDays;
int success = gtk_moz_embed_common_get_pref(G_TYPE_INT, EMBED_HISTORY_PREF_EXPIRE_DAYS, &expireDays);
if (success) {
LL_I2L(mExpirationInterval, expireDays);
LL_MUL(mExpirationInterval, mExpirationInterval, kMSecsPerDay);
}
// register to observe profile changes
nsCOMPtr<nsIObserverService> observerService =
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
NS_ASSERTION(observerService, "failed to get observer service");
if (observerService) {
observerService->AddObserver(this, "quit-application", PR_FALSE);
observerService->AddObserver(this, "RemoveEntries", PR_FALSE);
}
nsresult rv = InitFile();
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
rv = LoadData();
NS_ENSURE_SUCCESS(rv, rv);
return rv;
}
#define BROKEN_RV_HANDLING_CODE(rv) PR_BEGIN_MACRO \
if (NS_FAILED(rv)) { \
/* OOPS the coder (not timeless) didn't handle this case well at all. \
* unfortunately the coder will remain anonymous. \
* XXX please fix me. \
*/ \
} \
PR_END_MACRO
#define BROKEN_STRING_GETTER(out) PR_BEGIN_MACRO \
/* OOPS the coder (not timeless) decided not to do anything in this \
* method, but to return NS_OK anyway. That's not very polite. \
*/ \
out.Truncate(); \
PR_END_MACRO
#define BROKEN_STRING_BUILDER(var) PR_BEGIN_MACRO \
/* This is just wrong */ \
PR_END_MACRO
#define UNACCEPTABLE_CRASHY_GLIB_ALLOCATION(newed) PR_BEGIN_MACRO \
/* OOPS this code is using a glib allocation function which \
* will cause the application to crash when it runs out of \
* memory. This is not cool. either g_try methods should be \
* used or malloc, or new (note that gecko /will/ be replacing \
* its operator new such that new will not throw exceptions). \
* XXX please fix me. \
*/ \
if (!newed) { \
} \
PR_END_MACRO
#define ALLOC_NOT_CHECKED(newed) PR_BEGIN_MACRO \
/* This might not crash, but the code probably isn't really \
* designed to handle it, perhaps the code should be fixed? \
*/ \
if (!newed) { \
} \
PR_END_MACRO
//*****************************************************************************
// EmbedGlobalHistory::nsIGlobalHistory
//*****************************************************************************
// Add a new URI to the history
NS_IMETHODIMP EmbedGlobalHistory::AddURI(nsIURI *aURI, PRBool aRedirect, PRBool aToplevel, nsIURI *aReferrer)
{
NS_ENSURE_ARG(aURI);
nsCAutoString URISpec;
aURI->GetSpec(URISpec);
const char *aURL = URISpec.get();
if (!aToplevel)
return NS_OK;
PRBool isHTTP, isHTTPS;
nsresult rv = NS_OK;
rv |= aURI->SchemeIs("http", &isHTTP);
rv |= aURI->SchemeIs("https", &isHTTPS);
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
// Only get valid uri schemes
if (!isHTTP && !isHTTPS)
{
/* the following blacklist is silly.
* if there's some need to whitelist http(s) + ftp,
* that's what we should do.
*/
PRBool isAbout, isImap, isNews, isMailbox, isViewSource, isChrome, isData, isJavascript;
rv = aURI->SchemeIs("about", &isAbout);
rv |= aURI->SchemeIs("imap", &isImap);
rv |= aURI->SchemeIs("news", &isNews);
rv |= aURI->SchemeIs("mailbox", &isMailbox);
rv |= aURI->SchemeIs("view-source", &isViewSource);
rv |= aURI->SchemeIs("chrome", &isChrome);
rv |= aURI->SchemeIs("data", &isData);
rv |= aURI->SchemeIs("javascript", &isJavascript);
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
if (isAbout ||
isImap ||
isNews ||
isMailbox ||
isViewSource ||
isChrome ||
isData ||
isJavascript) {
return NS_OK;
}
}
#ifdef DEBUG
NS_WARNING("[HISTORY] Visited URL: %s\n", aURL);
#endif
rv = LoadData();
NS_ENSURE_SUCCESS(rv, rv);
GList *node = g_list_find_custom(mURLList, aURL, (GCompareFunc) history_entry_find_exist);
HistoryEntry *entry = NULL;
if (node && node->data)
entry = (HistoryEntry *)(node->data);
nsCAutoString hostname;
aURI->GetHost(hostname);
// It is not in the history
if (!entry) {
entry = new HistoryEntry;
ALLOC_NOT_CHECKED(entry);
rv |= OnVisited(entry);
SET_TITLE(entry, hostname);
rv |= SET_URL(entry, aURL);
BROKEN_RV_HANDLING_CODE(rv);
unsigned int listSize = g_list_length(mURLList);
if (listSize+1 > kDefaultMaxSize) {
GList *last = g_list_last(mURLList);
mURLList = g_list_remove(mURLList, last->data);
}
mURLList = g_list_insert_sorted(mURLList, entry,
(GCompareFunc) find_insertion_place);
// Flush after kNewEntriesBetweenFlush changes
BROKEN_RV_HANDLING_CODE(rv);
if (++mEntriesAddedSinceFlush >= kNewEntriesBetweenFlush)
rv |= FlushData(kFlushModeAppend);
// At this point, something understands there's a new global history item
} else {
// update the last visited time
rv |= OnVisited(entry);
SET_TITLE(entry, hostname);
// Move the element to the start of the list
BROKEN_RV_HANDLING_CODE(rv);
mURLList = g_list_remove(mURLList, entry);
mURLList = g_list_insert_sorted(mURLList, entry, (GCompareFunc) find_insertion_place);
// Flush after kNewEntriesBetweenFlush changes
BROKEN_RV_HANDLING_CODE(rv);
mFlushModeFullWriteNeeded = PR_TRUE;
if (++mEntriesAddedSinceFlush >= kNewEntriesBetweenFlush)
rv |= FlushData(kFlushModeFullWrite);
}
return rv;
}
// Return TRUE if the url is already in history
NS_IMETHODIMP EmbedGlobalHistory::IsVisited(nsIURI *aURI, PRBool *_retval)
{
NS_ENSURE_ARG(aURI);
NS_ENSURE_ARG_POINTER(_retval);
nsCAutoString URISpec;
aURI->GetSpec(URISpec);
const char *aURL = URISpec.get();
nsresult rv = LoadData();
NS_ENSURE_SUCCESS(rv, rv);
GList *node = g_list_find_custom(mURLList, aURL,
(GCompareFunc) history_entry_find_exist);
*_retval = (node && node->data);
return rv;
}
// It is called when Mozilla get real name of a URL
NS_IMETHODIMP EmbedGlobalHistory::SetPageTitle(nsIURI *aURI,
const nsAString & aTitle)
{
NS_ENSURE_ARG(aURI);
nsresult rv;
// skip about: URIs to avoid reading in the db (about:blank, especially)
PRBool isAbout;
rv = aURI->SchemeIs("about", &isAbout);
NS_ENSURE_SUCCESS(rv, rv);
if (isAbout)
return NS_OK;
nsCAutoString URISpec;
aURI->GetSpec(URISpec);
const char *aURL = URISpec.get();
rv |= LoadData();
BROKEN_RV_HANDLING_CODE(rv);
NS_ENSURE_SUCCESS(rv, rv);
GList *node = g_list_find_custom(mURLList, aURL,
(GCompareFunc) history_entry_find_exist);
HistoryEntry *entry = NULL;
if (node)
entry = (HistoryEntry *)(node->data);
if (entry) {
SET_TITLE(entry, NS_ConvertUTF16toUTF8(aTitle).get());
BROKEN_RV_HANDLING_CODE(rv);
mFlushModeFullWriteNeeded = PR_TRUE;
if (++mEntriesAddedSinceFlush >= kNewEntriesBetweenFlush)
rv |= FlushData(kFlushModeFullWrite);
BROKEN_RV_HANDLING_CODE(rv);
}
return rv;
}
nsresult EmbedGlobalHistory::RemoveEntries(const PRUnichar *url, int time)
{
nsresult rv = NS_ERROR_FAILURE;
if (!mURLList)
return rv;
if (url) {
GList *node = g_list_find_custom(mURLList, NS_ConvertUTF16toUTF8(url).get(), (GCompareFunc) history_entry_find_exist);
if (!node) return rv;
if (node->data) {
HistoryEntry *entry = NS_STATIC_CAST(HistoryEntry *,
node->data);
entry->mLastVisitTime = 0;
delete entry;
mURLList = g_list_remove(mURLList, entry);
}
} else {
g_list_foreach (mURLList, (GFunc) history_entry_foreach_to_remove, NULL);
g_list_free(mURLList);
mURLList = NULL;
}
mFlushModeFullWriteNeeded = PR_TRUE;
mEntriesAddedSinceFlush++;
rv = FlushData(kFlushModeFullWrite);
return rv;
}
//*****************************************************************************
// EmbedGlobalHistory::nsIObserver
//*****************************************************************************
NS_IMETHODIMP EmbedGlobalHistory::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
nsresult rv = NS_OK;
// used when the browser is closed and the EmbedGlobalHistory destructor is not called
if (strcmp(aTopic, "quit-application") == 0) {
rv = LoadData();
// we have to sort the list before flush it
rv |= FlushData(kFlushModeFullWrite);
if (mURLList) {
g_list_foreach(mURLList, (GFunc) history_entry_foreach_to_remove, NULL);
g_list_free(mURLList);
mURLList = NULL;
}
if (mFileHandle) {
CLOSE_FILE_HANDLE(mFileHandle);
}
} else if (strcmp(aTopic, "RemoveEntries") == 0) {
rv |= RemoveEntries(aData, 0);
}
return rv;
}
static nsresult
GetHistoryFileName(char **aHistoryFile)
{
NS_ENSURE_ARG_POINTER(aHistoryFile);
// Get the history file in our profile dir.
// Notice we are not just getting NS_APP_HISTORY_50_FILE
// because it is used by the "real" global history component.
if (EmbedPrivate::sProfileDir) {
nsCString path;
EmbedPrivate::sProfileDir->GetNativePath(path);
*aHistoryFile = g_strdup_printf("%s/history.dat", path.get());
BROKEN_STRING_BUILDER(aHistoryFile);
} else {
*aHistoryFile = g_strdup_printf("%s/history.dat", g_get_tmp_dir());
BROKEN_STRING_BUILDER(aHistoryFile);
}
return NS_OK;
}
//*****************************************************************************
// EmbedGlobalHistory
//*****************************************************************************
// Open/Create the history.dat file if it does not exist
nsresult EmbedGlobalHistory::InitFile()
{
if (!mHistoryFile) {
if (NS_FAILED(GetHistoryFileName(&mHistoryFile)))
return NS_ERROR_FAILURE;
}
LOCAL_FILE *uri = file_handle_uri_new(mHistoryFile);
if (!uri)
return NS_ERROR_FAILURE;
gboolean rs = FALSE;
if (!file_handle_uri_exists(uri)) {
if (!file_handle_create_uri(&mFileHandle, uri)) {
NS_WARNING("Could not create a history file\n");
file_handle_uri_release(uri);
return NS_ERROR_FAILURE;
}
CLOSE_FILE_HANDLE(mFileHandle);
}
rs = file_handle_open_uri(&mFileHandle, uri);
file_handle_uri_release(uri);
if (!rs) {
NS_WARNING("Could not open a history file\n");
return NS_ERROR_FAILURE;
}
return NS_OK;
}
// Get the data from history.dat file
nsresult EmbedGlobalHistory::LoadData()
{
nsresult rv = NS_OK;
if (!mDataIsLoaded) {
mDataIsLoaded = PR_TRUE;
LOCAL_FILE *uri = file_handle_uri_new(mHistoryFile);
if (uri) {
rv |= ReadEntries(uri);
file_handle_uri_release(uri);
}
}
return rv;
}
// Call a function to write each entry in the history hash table
nsresult EmbedGlobalHistory::WriteEntryIfWritten(GList *list, OUTPUT_STREAM *file_handle)
{
if (!file_handle)
return NS_ERROR_FAILURE;
unsigned int counter = g_list_length(list);
while (counter > 0) {
HistoryEntry *entry = NS_STATIC_CAST(HistoryEntry*, g_list_nth_data(list, counter-1));
counter--;
if (!entry || entryHasExpired(entry)) {
continue;
}
writeEntry(file_handle, entry);
}
return NS_OK;
}
// Call a function to write each unwritten entry in the history hash table
nsresult EmbedGlobalHistory::WriteEntryIfUnwritten(GList *list, OUTPUT_STREAM *file_handle)
{
if (!file_handle)
return NS_ERROR_FAILURE;
unsigned int counter = g_list_length(list);
while (counter > 0) {
HistoryEntry *entry = NS_STATIC_CAST(HistoryEntry*, g_list_nth_data(list, counter-1));
if (!entry || entryHasExpired(entry)) {
counter--;
continue;
}
if (!GetIsWritten(entry))
writeEntry(file_handle, entry);
counter--;
}
return NS_OK;
}
// Write the history in history.dat file
nsresult EmbedGlobalHistory::FlushData(PRIntn mode)
{
nsresult rv = NS_OK;
if (mEntriesAddedSinceFlush == 0)
return NS_OK;
if (!mHistoryFile)
{
rv = InitFile();
NS_ENSURE_SUCCESS(rv, rv);
rv = FlushData(kFlushModeFullWrite);
return rv;
}
LOCAL_FILE *uri = file_handle_uri_new(mHistoryFile);
if (!uri) return NS_ERROR_FAILURE;
gboolean rs = file_handle_uri_exists(uri);
file_handle_uri_release(uri);
if (!rs && NS_FAILED(rv))
return NS_ERROR_FAILURE;
if (mode == kFlushModeFullWrite || mFlushModeFullWriteNeeded == PR_TRUE)
{
if (!file_handle_seek(mFileHandle, FALSE))
return NS_ERROR_FAILURE;
if (!file_handle_truncate(mFileHandle))
return NS_ERROR_FAILURE;
WriteEntryIfWritten(mURLList, mFileHandle);
mFlushModeFullWriteNeeded = PR_FALSE;
}
else
{
if (!file_handle_seek(mFileHandle, TRUE))
return NS_ERROR_FAILURE;
WriteEntryIfUnwritten(mURLList, mFileHandle);
}
mEntriesAddedSinceFlush = 0;
return NS_OK;
}
// Split an entry in last visit time, title and url.
// Add a stored entry in the history.dat file in the history hash table
nsresult EmbedGlobalHistory::GetEntry(const char *entry)
{
char separator = (char) defaultSeparator;
int pos = 0;
nsInt64 outValue = 0;
while (PR_TRUE) {
PRInt32 digit;
if (entry[pos] == separator) {
pos++;
break;
}
if (entry[pos] == '\0' || !isdigit(entry[pos]))
return NS_ERROR_FAILURE;
digit = entry[pos] - '0';
outValue *= nsInt64(10);
outValue += nsInt64(digit);
pos++;
}
char url[1024], title[1024];
int urlLength= 0, titleLength= 0, numStrings=1;
// get the url and title
// FIXME
while(PR_TRUE) {
if (entry[pos] == separator) {
numStrings++;
pos++;
continue;
}
if (numStrings > 2)
break;
if (numStrings==1) {
url[urlLength++] = entry[pos];
} else {
title[titleLength++] = entry[pos];
}
pos++;
}
url[urlLength]='\0';
title[titleLength]='\0';
HistoryEntry *newEntry = new HistoryEntry;
if (!newEntry)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = NS_OK;
SET_TITLE(newEntry, title);
rv |= SetLastVisitTime(newEntry, outValue);
rv |= SetIsWritten(newEntry);
rv |= SET_URL(newEntry, url);
BROKEN_RV_HANDLING_CODE(rv);
// Check wheter the entry has expired
if (!entryHasExpired(newEntry)) {
mURLList = g_list_prepend(mURLList, newEntry);
}
return rv;
}
// Get the history entries from history.dat file
nsresult EmbedGlobalHistory::ReadEntries(LOCAL_FILE *file_uri)
{
if (!file_uri)
return NS_ERROR_FAILURE;
nsresult rv = NS_OK;
nsCOMPtr<nsIInputStream> fileStream;
NS_NewLocalFileInputStream(getter_AddRefs(fileStream), file_uri);
if (!fileStream)
return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsILineInputStream> lineStream = do_QueryInterface(fileStream, &rv);
NS_ASSERTION(lineStream, "File stream is not an nsILineInputStream");
// Read the header
nsCString utf8Buffer;
PRBool moreData = PR_FALSE;
PRInt32 safe_limit = 0;
do {
rv = lineStream->ReadLine(utf8Buffer, &moreData);
safe_limit++;
if (NS_FAILED(rv))
return NS_OK;
if (utf8Buffer.IsEmpty())
continue;
rv = GetEntry(utf8Buffer.get());
} while (moreData && safe_limit < kMaxSafeReadEntriesCount);
fileStream->Close();
return rv;
}
//*****************************************************************************
// Static Functions
//*****************************************************************************
// Get last visit time from a string
static nsresult writePRInt64(char time[14], const PRInt64& inValue)
{
nsInt64 value(inValue);
if (value == nsInt64(0)) {
strcpy(time, "0");
return NS_OK;
}
nsCAutoString tempString;
while (value != nsInt64(0)) {
PRInt32 ones = PRInt32(value % nsInt64(10));
value /= nsInt64(10);
tempString.Insert(char('0' + ones), 0);
}
strcpy(time,(char *) tempString.get());
return NS_OK;
}
// Write an entry in the history.dat file
nsresult writeEntry(OUTPUT_STREAM *file_handle, HistoryEntry *entry)
{
nsresult rv = NS_OK;
char sep = (char) defaultSeparator;
char time[14];
writePRInt64(time, GetLastVisitTime(entry));
char *line = g_strdup_printf("%s%c%s%c%s%c\n", time, sep, GET_URL(entry), sep, GET_TITLE(entry), sep);
BROKEN_STRING_BUILDER(line);
guint64 size = file_handle_write(file_handle, (gpointer)line);
if (size != strlen(line))
rv = NS_ERROR_FAILURE;
rv |= SetIsWritten(entry);
g_free(line);
return rv;
}
nsresult EmbedGlobalHistory::GetContentList(GtkMozHistoryItem **GtkHI, int *count)
{
if (!mURLList) return NS_ERROR_FAILURE;
unsigned int num_items = 0;
*GtkHI = g_new0(GtkMozHistoryItem, g_list_length(mURLList));
UNACCEPTABLE_CRASHY_GLIB_ALLOCATION(*GtkHI);
GtkMozHistoryItem * item = (GtkMozHistoryItem *)*GtkHI;
while (num_items < g_list_length(mURLList)) {
HistoryEntry *entry = NS_STATIC_CAST(HistoryEntry*,
g_list_nth_data(mURLList, num_items));
// verify if the entry has expired and discard it
if (entryHasExpired(entry)) {
break;
}
glong accessed;
PRInt64 temp, outValue;
LL_MUL(outValue, GetLastVisitTime(entry), kOneThousand);
LL_DIV(temp, outValue, PR_USEC_PER_SEC);
LL_L2I(accessed, temp);
// Set the External history list
item[num_items].title = GET_TITLE(entry);
BROKEN_STRING_BUILDER(item[num_items].title);
item[num_items].url = GET_URL(entry);
item[num_items].accessed = accessed;
num_items++;
}
*count = num_items;
return NS_OK;
}

View File

@@ -1,128 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Conrad Carlen <ccarlen@netscape.com>
* Changes: andre.pedralho@indt.org.br (from original: mozilla/embedding/lite/nsEmbedGlobalHistory.h)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __EMBEDGLOBALHISTORY_h
#define __EMBEDGLOBALHISTORY_h
#include "nsIGlobalHistory2.h"
#include "nsIObserver.h"
#include "EmbedPrivate.h"
#include <prenv.h>
#include <gtk/gtk.h>
#include "nsDocShellCID.h"
#define OUTPUT_STREAM nsIOutputStream
#define LOCAL_FILE nsILocalFile
//#include "gtkmozembed_common.h"
/* {2f977d51-5485-11d4-87e2-0010a4e75ef2} */
#define NS_EMBEDGLOBALHISTORY_CID \
{ 0x2f977d51, 0x5485, 0x11d4, \
{ 0x87, 0xe2, 0x00, 0x10, 0xa4, 0xe7, 0x5e, 0xf2 } }
#define EMBED_HISTORY_PREF_EXPIRE_DAYS "browser.history_expire_days"
/** The Mozilla History Class
* This class is responsible for handling the history stuff.
*/
class EmbedGlobalHistory: public nsIGlobalHistory2,
public nsIObserver
{
public:
EmbedGlobalHistory();
virtual ~EmbedGlobalHistory();
static EmbedGlobalHistory* GetInstance();
static void DeleteInstance();
NS_IMETHOD Init();
nsresult GetContentList(GtkMozHistoryItem**, int *count);
NS_DECL_ISUPPORTS
NS_DECL_NSIGLOBALHISTORY2
NS_DECL_NSIOBSERVER
nsresult RemoveEntries(const PRUnichar *url = nsnull, int time = 0);
protected:
enum {
kFlushModeAppend, /** < Add a new entry in the history file */
kFlushModeFullWrite /** < Rewrite all history file */
};
/** Initiates the history file
* @return NS_OK on the success.
*/
nsresult InitFile();
/** Loads the history file
* @return NS_OK on the success.
*/
nsresult LoadData();
/** Writes entries in the history file
* @param list The internal history list.
* @param handle A Gnome VFS handle.
* @return NS_OK on the success.
*/
nsresult WriteEntryIfWritten(GList *list, OUTPUT_STREAM *file_handle);
/** Writes entries in the history file
* @param list The internal history list.
* @param handle A Gnome VFS handle.
* @return NS_OK on the success.
*/
nsresult WriteEntryIfUnwritten(GList *list, OUTPUT_STREAM *file_handle);
/** Writes entries in the history file
* @param mode How to write in the history file
* @return NS_OK on the success.
*/
nsresult FlushData(PRIntn mode = kFlushModeFullWrite);
/** Remove entries from the URL table
* @return NS_OK on the success.
*/
nsresult ResetData();
/** Reads the history entries using GnomeVFS
* @param vfs_handle A Gnome VFS handle.
* @return NS_OK on the success.
*/
nsresult ReadEntries(LOCAL_FILE *file_uri);
/** Gets a history entry
* @param name The history entry name.
* @return NS_OK if the history entry name was gotten.
*/
nsresult GetEntry(const char *);
protected:
OUTPUT_STREAM *mFileHandle; /** < The History File handle */
PRBool mDataIsLoaded; /** < If the data is loaded */
PRBool mFlushModeFullWriteNeeded;/** < If needs a full flush */
PRInt32 mEntriesAddedSinceFlush; /** < Number of entries added since flush */
gchar* mHistoryFile; /** < The history file path */
};
// Default maximum history entries
static const PRUint32 kDefaultMaxSize = 1000;
#endif

View File

@@ -1,88 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=4 sts=2 tw=80 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Oleg Romashin. Portions created by Oleg Romashin are Copyright (C) Oleg Romashin. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Oleg Romashin <romaxa@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "EmbedGtkTools.h"
#ifndef MOZILLA_INTERNAL_API
#include "nsServiceManagerUtils.h"
#endif
#include "EmbedPrivate.h"
GtkWidget * GetGtkWidgetForDOMWindow(nsIDOMWindow* aDOMWindow)
{
nsCOMPtr<nsIWindowWatcher> wwatch = do_GetService("@mozilla.org/embedcomp/window-watcher;1");
if (!aDOMWindow)
return NULL;
nsCOMPtr<nsIWebBrowserChrome> chrome;
wwatch->GetChromeForWindow(aDOMWindow, getter_AddRefs(chrome));
if (!chrome) {
return GTK_WIDGET(EmbedCommon::GetAnyLiveWidget());
}
nsCOMPtr<nsIEmbeddingSiteWindow> siteWindow = nsnull;
siteWindow = do_QueryInterface(chrome);
if (!siteWindow) {
return GTK_WIDGET(EmbedCommon::GetAnyLiveWidget());
}
GtkWidget* parentWidget;
siteWindow->GetSiteWindow((void**)&parentWidget);
if (GTK_IS_WIDGET(parentWidget))
return parentWidget;
return NULL;
}
GtkWindow * GetGtkWindowForDOMWindow(nsIDOMWindow* aDOMWindow)
{
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aDOMWindow);
if (!parentWidget)
return NULL;
GtkWidget* gtkWin = gtk_widget_get_toplevel(parentWidget);
if (GTK_WIDGET_TOPLEVEL(gtkWin))
return GTK_WINDOW(gtkWin);
return NULL;
}
nsresult GetContentViewer(nsIWebBrowser *webBrowser, nsIContentViewer **aViewer)
{
g_return_val_if_fail(webBrowser, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShell> docShell(do_GetInterface((nsISupports*)webBrowser));
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
return docShell->GetContentViewer(aViewer);
}

View File

@@ -1,67 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Oleg Romashin. Portions created by Oleg Romashin are Copyright (C) Oleg Romashin. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Oleg Romashin <romaxa@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __EmbedTools_h
#define __EmbedTools_h
#include "nsCOMPtr.h"
#ifdef MOZILLA_INTERNAL_API
#include "nsString.h"
#else
#include "nsStringAPI.h"
#endif
#include "nsIDOMWindow.h"
#include "nsIWindowWatcher.h"
#include "nsIWebBrowserChrome.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsIServiceManager.h"
#include "nsIContentViewer.h"
#include "nsIDocShell.h"
#include "nsIInterfaceRequestorUtils.h"
#include <gtk/gtk.h>
GtkWidget*
GetGtkWidgetForDOMWindow(nsIDOMWindow* aDOMWindow);
GtkWindow*
GetGtkWindowForDOMWindow(nsIDOMWindow* aDOMWindow);
nsresult
GetContentViewer(nsIWebBrowser *webBrowser, nsIContentViewer **aViewer);
#endif /* __EmbedTools_h */

File diff suppressed because it is too large Load Diff

View File

@@ -1,227 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Password Manager.
*
* The Initial Developer of the Original Code is
* Brian Ryner.
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@brianryner.com>
* Changes: romaxa@gmail.com (from original: mozilla/toolkit/components/passwordmgr/base/nsPasswordManager.h)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCPasswordManager.h"
#include "nsClassHashtable.h"
#include "nsDataHashtable.h"
#include "nsCOMPtr.h"
#include "nsIObserver.h"
#include "nsWeakReference.h"
#include "nsIFormSubmitObserver.h"
#include "nsIWebProgressListener.h"
#include "nsIDOMFocusListener.h"
#include "nsIDOMLoadListener.h"
#include "nsIStringBundle.h"
#include "nsIPrefBranch.h"
#include "nsIPromptFactory.h"
#include "nsIAuthPromptWrapper.h"
#include "nsCOMPtr.h"
#include "nsIPrompt.h"
#include "nsIAuthPrompt2.h"
#include "EmbedPrivate.h"
#define EMBED_PASSWORDMANAGER_DESCRIPTION "MicroB PSM Dialog Impl"
/* 360565c4-2ef3-4f6a-bab9-94cca891b2a7 */
#define EMBED_PASSWORDMANAGER_CID \
{0x360565c4, 0x2ef3, 0x4f6a, {0xba, 0xb9, 0x94, 0xcc, 0xa8, 0x91, 0xb2, 0xa7}}
class nsIFile;
class nsIStringBundle;
class nsIComponentManager;
class nsIContent;
class nsIDOMWindowInternal;
class nsIURI;
class nsIDOMHTMLInputElement;
class nsIDOMWindow;
class nsIPromptService2;
struct nsModuleComponentInfo;
class EmbedPasswordMgr : public nsIPasswordManager,
public nsIPasswordManagerInternal,
public nsIObserver,
public nsIFormSubmitObserver,
public nsIWebProgressListener,
public nsIDOMFocusListener,
public nsIPromptFactory,
public nsIDOMLoadListener,
public nsSupportsWeakReference
{
public:
class SignonDataEntry;
class SignonHashEntry;
class PasswordEntry;
EmbedPasswordMgr();
virtual ~EmbedPasswordMgr();
static EmbedPasswordMgr* GetInstance();
static EmbedPasswordMgr* GetInstance(EmbedPrivate *aOwner);
nsresult Init();
static PRBool SingleSignonEnabled();
static NS_METHOD Register(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* aRegistryLocation,
const char* aComponentType,
const nsModuleComponentInfo* aInfo);
static NS_METHOD Unregister(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* aRegistryLocation,
const nsModuleComponentInfo* aInfo);
static void Shutdown();
static void GetLocalizedString(const nsAString& key,
nsAString& aResult,
PRBool aFormatted = PR_FALSE,
const PRUnichar** aFormatArgs = nsnull,
PRUint32 aFormatArgsLength = 0);
static nsresult DecryptData(const nsAString& aData, nsAString& aPlaintext);
static nsresult EncryptData(const nsAString& aPlaintext,
nsACString& aEncrypted);
static nsresult EncryptDataUCS2(const nsAString& aPlaintext,
nsAString& aEncrypted);
nsresult InsertLogin(const char* username, const char* password = nsnull);
nsresult RemovePasswords(const char *aHostName, const char *aUserName);
nsresult RemovePasswordsByIndex(PRUint32 aIndex);
nsresult IsEqualToLastHostQuery(nsCString& aHost);
NS_DECL_ISUPPORTS
NS_DECL_NSIPASSWORDMANAGER
NS_DECL_NSIPASSWORDMANAGERINTERNAL
NS_DECL_NSIOBSERVER
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_NSIPROMPTFACTORY
// nsIFormSubmitObserver
NS_IMETHOD Notify(nsIContent* aFormNode,
nsIDOMWindowInternal* aWindow,
nsIURI* aActionURL,
PRBool* aCancelSubmit);
// nsIDOMFocusListener
NS_IMETHOD Focus(nsIDOMEvent* aEvent);
NS_IMETHOD Blur(nsIDOMEvent* aEvent);
// nsIDOMEventListener
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
// nsIDOMLoadListener
NS_IMETHOD Load(nsIDOMEvent* aEvent);
NS_IMETHOD Unload(nsIDOMEvent* aEvent);
NS_IMETHOD BeforeUnload(nsIDOMEvent* aEvent);
NS_IMETHOD Abort(nsIDOMEvent* aEvent);
NS_IMETHOD Error(nsIDOMEvent* aEvent);
protected:
void WritePasswords(nsIFile* aPasswordFile);
void AddSignonData(const nsACString& aRealm, SignonDataEntry* aEntry);
nsresult FindPasswordEntryInternal(const SignonDataEntry* aEntry,
const nsAString& aUser,
const nsAString& aPassword,
const nsAString& aUserField,
SignonDataEntry** aResult);
nsresult FillPassword(nsIDOMEvent* aEvent = nsnull);
void AttachToInput(nsIDOMHTMLInputElement* aElement);
PRBool GetPasswordRealm(nsIURI* aURI, nsACString& aRealm);
static PLDHashOperator PR_CALLBACK FindEntryEnumerator(const nsACString& aKey,
SignonHashEntry* aEntry,
void* aUserData);
static PLDHashOperator PR_CALLBACK WriteRejectEntryEnumerator(const nsACString& aKey,
PRInt32 aEntry,
void* aUserData);
static PLDHashOperator PR_CALLBACK WriteSignonEntryEnumerator(const nsACString& aKey,
SignonHashEntry* aEntry,
void* aUserData);
static PLDHashOperator PR_CALLBACK BuildArrayEnumerator(const nsACString& aKey,
SignonHashEntry* aEntry,
void* aUserData);
static PLDHashOperator PR_CALLBACK BuildRejectArrayEnumerator(const nsACString& aKey,
PRInt32 aEntry,
void* aUserData);
static PLDHashOperator PR_CALLBACK RemoveForDOMDocumentEnumerator(nsISupports* aKey,
PRInt32& aEntry,
void* aUserData);
static void EnsureDecoderRing();
nsClassHashtable<nsCStringHashKey,SignonHashEntry> mSignonTable;
nsDataHashtable<nsCStringHashKey,PRInt32> mRejectTable;
nsDataHashtable<nsISupportsHashKey,PRInt32> mAutoCompleteInputs;
nsCOMPtr<nsIFile> mSignonFile;
nsCOMPtr<nsIPrefBranch> mPrefBranch;
nsIDOMHTMLInputElement* mAutoCompletingField;
nsIDOMHTMLInputElement* mGlobalUserField;
nsIDOMHTMLInputElement* mGlobalPassField;
SignonHashEntry * mLastSignonHashEntry;
int lastIndex;
nsCAutoString mLastHostQuery;
EmbedCommon* mCommonObject;
public:
PRBool mFormAttachCount;
// nsAString mLastHostQuery;
};
/* 1baf3398-f759-4a72-a21f-0abdc9cc9960 */
#define NS_SINGLE_SIGNON_PROMPT_CID \
{0x1baf3398, 0xf759, 0x4a72, {0xa2, 0x1f, 0x0a, 0xbd, 0xc9, 0xcc, 0x99, 0x60}}
// Our wrapper for username/password prompts - this allows us to prefill
// the password dialog and add a "remember this password" checkbox.
class EmbedSignonPrompt : public nsIAuthPromptWrapper
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIAUTHPROMPT
NS_DECL_NSIAUTHPROMPTWRAPPER
EmbedSignonPrompt() {}
virtual ~EmbedSignonPrompt() {}
protected:
void GetLocalizedString(const nsAString& aKey, nsAString& aResult);
nsCOMPtr<nsIPrompt> mPrompt;
};
// A wrapper for the newer nsIAuthPrompt2 interface
// Its purpose is the same as nsSingleSignonPrompt, but wraps an nsIDOMWindow
// instead of an nsIPrompt.
class EmbedSignonPrompt2 : public nsIAuthPrompt2
{
public:
EmbedSignonPrompt2(nsIPromptService2* aService, nsIDOMWindow* aParent);
NS_DECL_ISUPPORTS
NS_DECL_NSIAUTHPROMPT2
private:
~EmbedSignonPrompt2();
nsCOMPtr<nsIPromptService2> mService;
nsCOMPtr<nsIDOMWindow> mParent;
};

File diff suppressed because it is too large Load Diff

View File

@@ -1,268 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __EmbedPrivate_h
#define __EmbedPrivate_h
#include "nsCOMPtr.h"
#ifdef MOZILLA_INTERNAL_API
#include "nsString.h"
#else
#include "nsStringAPI.h"
#include "nsComponentManagerUtils.h"
#include "nsServiceManagerUtils.h"
#endif
#include "nsIWebNavigation.h"
#include "nsISHistory.h"
// for our one function that gets the EmbedPrivate via the chrome
// object.
#include "nsIWebBrowserChrome.h"
#include "nsIAppShell.h"
#include "nsIDOMEventReceiver.h"
#include "nsVoidArray.h"
// app component registration
#include "nsIGenericFactory.h"
#include "nsIComponentRegistrar.h"
#include "nsIDocCharset.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIWebBrowserFind.h"
// for the focus hacking we need to do
#include "nsIFocusController.h"
// for frames
#include "nsIDOMWindowCollection.h"
#include "gtkmozembedprivate.h"
#include "nsICacheEntryDescriptor.h"
#include "EmbedGtkTools.h"
class EmbedProgress;
class EmbedWindow;
class EmbedContentListener;
class EmbedEventListener;
class nsPIDOMWindow;
class nsIDirectoryServiceProvider;
class EmbedCommon {
public:
EmbedCommon() {
};
~EmbedCommon() { };
static EmbedCommon* GetInstance();
static void DeleteInstance();
nsresult Init(void);
GtkObject *mCommon;
static GtkMozEmbed* GetAnyLiveWidget();
};
class EmbedPrivate {
public:
EmbedPrivate();
~EmbedPrivate();
nsresult Init (GtkMozEmbed *aOwningWidget);
nsresult Realize (PRBool *aAlreadRealized);
void Unrealize (void);
void Show (void);
void Hide (void);
void Resize (PRUint32 aWidth, PRUint32 aHeight);
void Destroy (void);
void SetURI (const char *aURI);
void LoadCurrentURI (void);
void Reload (PRUint32 reloadFlags);
void SetChromeMask (PRUint32 chromeMask);
void ApplyChromeMask ();
static void PushStartup (void);
static void PopStartup (void);
static void SetPath (const char *aPath);
static void SetCompPath (const char *aPath);
static void SetAppComponents (const nsModuleComponentInfo* aComps,
int aNumComponents);
static void SetProfilePath (const char *aDir, const char *aName);
static void SetDirectoryServiceProvider (nsIDirectoryServiceProvider * appFileLocProvider);
nsresult OpenStream (const char *aBaseURI, const char *aContentType);
nsresult AppendToStream (const PRUint8 *aData, PRUint32 aLen);
nsresult CloseStream (void);
// This function will find the specific EmbedPrivate object for a
// given nsIWebBrowserChrome.
static EmbedPrivate *FindPrivateForBrowser(nsIWebBrowserChrome *aBrowser);
// This is an upcall that will come from the progress listener
// whenever there is a content state change. We need this so we can
// attach event listeners.
void ContentStateChange (void);
// This is an upcall from the progress listener when content is
// finished loading. We have this so that if it's chrome content
// that we can size to content properly and show ourselves if
// visibility is set.
void ContentFinishedLoading(void);
#ifdef MOZ_WIDGET_GTK
// these let the widget code know when the toplevel window gets and
// looses focus.
void TopLevelFocusIn (void);
void TopLevelFocusOut(void);
#endif
// these are when the widget itself gets focus in and focus out
// events
void ChildFocusIn (void);
void ChildFocusOut(void);
PRBool ClipBoardAction(GtkMozEmbedClipboard type);
char* GetEncoding ();
nsresult SetEncoding (const char *encoding);
PRBool FindText(const char *exp, PRBool reverse,
PRBool whole_word, PRBool case_sensitive,
PRBool restart);
void SetScrollTop(PRUint32 aTop);
nsresult ScrollToSelectedNode(nsIDOMNode *aDOMNode);
nsresult InsertTextToNode(nsIDOMNode *aDOMNode, const char *string);
nsresult GetFocusController(nsIFocusController **controller);
nsresult GetDOMWindowByNode(nsIDOMNode *aNode, nsIDOMWindow * *aDOMWindow);
nsresult GetZoom(PRInt32 *aZoomLevel, nsISupports *aContext = nsnull);
nsresult SetZoom(PRInt32 aZoomLevel, nsISupports *aContext = nsnull);
nsresult HasFrames(PRUint32 *numberOfFrames);
nsresult GetMIMEInfo(const char **aMime, nsIDOMNode *aDOMNode = nsnull);
nsresult GetCacheEntry(const char *aStorage,
const char *aKeyName,
PRUint32 aAccess,
PRBool aIsBlocking,
nsICacheEntryDescriptor **aDescriptor);
nsresult GetSHistoryList(GtkMozHistoryItem **GtkHI,
GtkMozEmbedSessionHistory type, gint *count);
#ifdef MOZ_ACCESSIBILITY_ATK
void *GetAtkObjectForCurrentDocument();
#endif
GtkMozEmbed *mOwningWidget;
// all of the objects that we own
EmbedWindow *mWindow;
nsCOMPtr<nsISupports> mWindowGuard;
EmbedProgress *mProgress;
nsCOMPtr<nsISupports> mProgressGuard;
EmbedContentListener *mContentListener;
nsCOMPtr<nsISupports> mContentListenerGuard;
EmbedEventListener *mEventListener;
nsCOMPtr<nsISupports> mEventListenerGuard;
nsCOMPtr<nsIWebNavigation> mNavigation;
nsCOMPtr<nsISHistory> mSessionHistory;
// our event receiver
nsCOMPtr<nsIDOMEventReceiver> mEventReceiver;
// the currently loaded uri
nsString mURI;
nsCString mPrePath;
// the number of widgets that have been created
static PRUint32 sWidgetCount;
// the path to the GRE
static char *sPath;
// the path to components
static char *sCompPath;
// the list of application-specific components to register
static const nsModuleComponentInfo *sAppComps;
static int sNumAppComps;
// the appshell we have created
static nsIAppShell *sAppShell;
// the list of all open windows
static nsVoidArray *sWindowList;
// what is our profile path?
static nsILocalFile *sProfileDir;
static nsISupports *sProfileLock;
static nsIDirectoryServiceProvider * sAppFileLocProvider;
// chrome mask
PRUint32 mChromeMask;
// is this a chrome window?
PRBool mIsChrome;
// has the chrome finished loading?
PRBool mChromeLoaded;
// has the network finished loading?
PRBool mLoadFinished;
// saved window ID for reparenting later
GtkWidget *mMozWindowWidget;
// has someone called Destroy() on us?
PRBool mIsDestroyed;
//Open Blocker for Create Window class //Fixme...
//I just tried to block it on earlier moment
PRBool mOpenBlock;
PRBool mNeedFav;
private:
// is the chrome listener attached yet?
PRBool mListenersAttached;
PRBool mDoResizeEmbed;
void GetListener (void);
void AttachListeners(void);
void DetachListeners(void);
// this will get the PIDOMWindow for this widget
nsresult GetPIDOMWindow (nsPIDOMWindow **aPIWin);
static nsresult RegisterAppComponents();
// offscreen window methods and the offscreen widget
static void EnsureOffscreenWindow(void);
static void DestroyOffscreenWindow(void);
static GtkWidget *sOffscreenWindow;
static GtkWidget *sOffscreenFixed;
};
#endif /* __EmbedPrivate_h */

View File

@@ -1,324 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Antonio Gomes <tonikitoo@gmail.com>
* Oleg Romashin <romaxa@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "EmbedProgress.h"
#ifdef MOZILLA_INTERNAL_API
#include "nsXPIDLString.h"
#endif
#include "nsIChannel.h"
#include "nsIHttpChannel.h"
#include "nsIWebProgress.h"
#include "nsIDOMWindow.h"
#include "EmbedPasswordMgr.h"
#include "nsIURI.h"
#include "nsCRT.h"
static PRInt32 sStopSignalTimer = 0;
static gboolean
progress_emit_stop(void * data)
{
g_return_val_if_fail(data, FALSE);
EmbedPrivate *owner = (EmbedPrivate*)data;
if (!owner->mLoadFinished) {
owner->mLoadFinished = PR_TRUE;
gtk_signal_emit(GTK_OBJECT(owner->mOwningWidget),
moz_embed_signals[NET_STOP]);
}
return FALSE;
}
EmbedProgress::EmbedProgress(void)
{
mOwner = nsnull;
}
EmbedProgress::~EmbedProgress()
{
}
NS_IMPL_ISUPPORTS2(EmbedProgress,
nsIWebProgressListener,
nsISupportsWeakReference)
nsresult
EmbedProgress::Init(EmbedPrivate *aOwner)
{
mOwner = aOwner;
mStopLevel = 0;
return NS_OK;
}
NS_IMETHODIMP
EmbedProgress::OnStateChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRUint32 aStateFlags,
nsresult aStatus)
{
// give the widget a chance to attach any listeners
mOwner->ContentStateChange();
if (sStopSignalTimer &&
(
(aStateFlags & GTK_MOZ_EMBED_FLAG_TRANSFERRING)
|| (aStateFlags & GTK_MOZ_EMBED_FLAG_REDIRECTING)
|| (aStateFlags & GTK_MOZ_EMBED_FLAG_NEGOTIATING)
)
) {
g_source_remove(sStopSignalTimer);
mStopLevel = 0;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[NET_START]);
mOwner->mLoadFinished = PR_FALSE;
}
// if we've got the start flag, emit the signal
if ((aStateFlags & GTK_MOZ_EMBED_FLAG_IS_NETWORK) &&
(aStateFlags & GTK_MOZ_EMBED_FLAG_START)) {
// FIXME: workaround for broken progress values.
mOwner->mOwningWidget->current_number_of_requests = 0;
mOwner->mOwningWidget->total_number_of_requests = 0;
if (mOwner->mLoadFinished) {
mOwner->mLoadFinished = PR_FALSE;
mStopLevel = 0;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[NET_START]);
}
}
// get the uri for this request
nsCString tmpString;
RequestToURIString(aRequest, tmpString);
// FIXME: workaround for broken progress values.
if (mOwner->mOwningWidget) {
if (aStateFlags & GTK_MOZ_EMBED_FLAG_IS_REQUEST) {
if (aStateFlags & GTK_MOZ_EMBED_FLAG_START)
mOwner->mOwningWidget->total_number_of_requests ++;
else if (aStateFlags & GTK_MOZ_EMBED_FLAG_STOP)
mOwner->mOwningWidget->current_number_of_requests++;
}
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[PROGRESS_ALL],
(const gchar *) tmpString.get(),
mOwner->mOwningWidget->current_number_of_requests,
mOwner->mOwningWidget->total_number_of_requests);
}
// is it the same as the current URI?
if (mOwner->mURI.Equals(NS_ConvertUTF8toUTF16(tmpString))) {
// for people who know what they are doing
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[NET_STATE],
aStateFlags, aStatus);
}
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[NET_STATE_ALL],
(const gchar *)tmpString.get(),
(gint)aStateFlags, (gint)aStatus);
// and for stop, too
if (aStateFlags & GTK_MOZ_EMBED_FLAG_STOP) {
if (aStateFlags & GTK_MOZ_EMBED_FLAG_IS_REQUEST)
mStopLevel = 1;
if (aStateFlags & GTK_MOZ_EMBED_FLAG_IS_DOCUMENT)
mStopLevel = mStopLevel == 1 ? 2 : 0;
if (aStateFlags & GTK_MOZ_EMBED_FLAG_IS_WINDOW) {
mStopLevel = mStopLevel == 2 ? 3 : 0;
}
}
if (aStateFlags & GTK_MOZ_EMBED_FLAG_STOP) {
if (aStateFlags & GTK_MOZ_EMBED_FLAG_IS_NETWORK) {
if (sStopSignalTimer)
g_source_remove(sStopSignalTimer);
progress_emit_stop(mOwner);
// let our owner know that the load finished
mOwner->ContentFinishedLoading();
} else if (mStopLevel == 3) {
if (sStopSignalTimer)
g_source_remove(sStopSignalTimer);
mStopLevel = 0;
sStopSignalTimer = g_timeout_add(1000, progress_emit_stop, mOwner);
}
}
return NS_OK;
}
NS_IMETHODIMP
EmbedProgress::OnProgressChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 aCurSelfProgress,
PRInt32 aMaxSelfProgress,
PRInt32 aCurTotalProgress,
PRInt32 aMaxTotalProgress)
{
nsCString tmpString;
RequestToURIString(aRequest, tmpString);
// is it the same as the current uri?
if (mOwner->mURI.Equals(NS_ConvertUTF8toUTF16(tmpString))) {
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[PROGRESS],
aCurTotalProgress, aMaxTotalProgress);
}
return NS_OK;
}
NS_IMETHODIMP
EmbedProgress::OnLocationChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsIURI *aLocation)
{
nsCAutoString newURI;
nsCAutoString prePath;
NS_ENSURE_ARG_POINTER(aLocation);
aLocation->GetSpec(newURI);
aLocation->GetPrePath(prePath);
// Make sure that this is the primary frame change and not
// just a subframe.
PRBool isSubFrameLoad = PR_FALSE;
if (aWebProgress) {
nsCOMPtr<nsIDOMWindow> domWindow;
nsCOMPtr<nsIDOMWindow> topDomWindow;
aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
// get the root dom window
if (domWindow)
domWindow->GetTop(getter_AddRefs(topDomWindow));
if (domWindow != topDomWindow)
isSubFrameLoad = PR_TRUE;
}
if (!isSubFrameLoad) {
mOwner->SetURI(newURI.get());
mOwner->mPrePath.Assign(prePath.get());
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[LOCATION]);
}
mOwner->mNeedFav = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
EmbedProgress::OnStatusChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
nsresult aStatus,
const PRUnichar *aMessage)
{
// need to make a copy so we can safely cast to a void *
PRUnichar *tmpString = NS_strdup(aMessage);
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[STATUS_CHANGE],
NS_STATIC_CAST(void *, aRequest),
NS_STATIC_CAST(gint, aStatus),
NS_STATIC_CAST(void *, tmpString));
NS_Free(tmpString);
return NS_OK;
}
NS_IMETHODIMP
EmbedProgress::OnSecurityChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRUint32 aState)
{
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[SECURITY_CHANGE],
NS_STATIC_CAST(void *, aRequest),
aState);
return NS_OK;
}
/* static */
void
EmbedProgress::RequestToURIString(nsIRequest *aRequest, nsCString& aString)
{
// is it a channel
nsCOMPtr<nsIChannel> channel;
channel = do_QueryInterface(aRequest);
if (!channel)
return;
nsCOMPtr<nsIURI> uri;
channel->GetURI(getter_AddRefs(uri));
if (!uri)
return;
uri->GetSpec(aString);
}
nsresult
EmbedProgress::HandleHTTPStatus(nsIRequest *aRequest, const char *aUri, PRBool &aSucceeded)
{
nsresult rv;
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aRequest, &rv));
aSucceeded = PR_FALSE;
if (NS_FAILED(rv) || !httpChannel)
return NS_ERROR_FAILURE;
rv = httpChannel->GetRequestSucceeded(&aSucceeded);
if (aSucceeded)
return NS_OK;
PRUint32 responseCode = 0;
nsCString responseText;
rv = httpChannel->GetResponseStatus(&responseCode);
// it has to handle more http errors code ??? 401 ? responseCode >= 500 && responseCode <= 505
rv = httpChannel->GetResponseStatusText(responseText);
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[NETWORK_ERROR],
responseCode, responseText.get(), (const gchar*)aUri);
return rv;
}

View File

@@ -1,69 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __EmbedProgress_h
#define __EmbedProgress_h
#include "nsIWebProgressListener.h"
#include "nsWeakReference.h"
#include "EmbedPrivate.h"
class EmbedProgress : public nsIWebProgressListener,
public nsSupportsWeakReference
{
public:
EmbedProgress();
virtual ~EmbedProgress();
nsresult Init(EmbedPrivate *aOwner);
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBPROGRESSLISTENER
private:
static void RequestToURIString(nsIRequest *aRequest, nsCString& aString);
nsresult HandleHTTPStatus(nsIRequest *aRequest, const char *aUri, PRBool &aSucceeded);
EmbedPrivate *mOwner;
PRBool mStopLevel;
};
#endif /* __EmbedProgress_h */

View File

@@ -1,434 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=4 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@brianryner.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "EmbedPrompter.h"
#define ALLOC_NOT_CHECKED(newed) PR_BEGIN_MACRO \
/* This might not crash, but the code probably isn't really \
* designed to handle it, perhaps the code should be fixed? \
*/ \
if (!newed) { \
} \
PR_END_MACRO
enum {
INCLUDE_USERNAME = 1 << 0,
INCLUDE_PASSWORD = 1 << 1,
INCLUDE_CHECKBOX = 1 << 2,
INCLUDE_CANCEL = 1 << 3
};
struct DialogDescription {
int flags;
gchar* icon;
};
// This table contains the optional widgets and icons associated with
// each type of dialog.
static const DialogDescription DialogTable[] = {
{ 0, GTK_STOCK_DIALOG_WARNING }, // ALERT
{ INCLUDE_CHECKBOX, GTK_STOCK_DIALOG_WARNING }, // ALERT_CHECK
{ INCLUDE_CANCEL, GTK_STOCK_DIALOG_QUESTION }, // CONFIRM
{ INCLUDE_CHECKBOX |
INCLUDE_CANCEL, GTK_STOCK_DIALOG_QUESTION }, // CONFIRM_CHECK
{ INCLUDE_CANCEL |
INCLUDE_CHECKBOX, GTK_STOCK_DIALOG_QUESTION }, // PROMPT
{ INCLUDE_CANCEL |
INCLUDE_USERNAME |
INCLUDE_PASSWORD |
INCLUDE_CHECKBOX, GTK_STOCK_DIALOG_QUESTION }, // PROMPT_USER_PASS
{ INCLUDE_CANCEL |
INCLUDE_PASSWORD |
INCLUDE_CHECKBOX, GTK_STOCK_DIALOG_QUESTION }, // PROMPT_PASS
{ INCLUDE_CANCEL, GTK_STOCK_DIALOG_QUESTION }, // SELECT
{ INCLUDE_CANCEL |
INCLUDE_CHECKBOX, GTK_STOCK_DIALOG_QUESTION } // UNIVERSAL
};
EmbedPrompter::EmbedPrompter(void)
: mCheckValue(PR_FALSE),
mItemList(nsnull),
mItemCount(0),
mButtonPressed(0),
mConfirmResult(PR_FALSE),
mSelectedItem(0),
mWindow(NULL),
mUserField(NULL),
mPassField(NULL),
mTextField(NULL),
mOptionMenu(NULL),
mCheckBox(NULL)
{
}
EmbedPrompter::~EmbedPrompter(void)
{
if (mItemList)
delete[] mItemList;
}
nsresult
EmbedPrompter::Create(PromptType aType, GtkWindow* aParentWindow)
{
mWindow = gtk_dialog_new_with_buttons(
mTitle.get(),
aParentWindow,
(GtkDialogFlags)0,
NULL);
// only add the dialog to the window group if the parent already has a window group,
// so as not to break app's expectations about modal dialogs.
if (aParentWindow && aParentWindow->group) {
gtk_window_group_add_window(aParentWindow->group, GTK_WINDOW(mWindow));
}
// gtk will resize this for us as necessary
gtk_window_set_default_size(GTK_WINDOW(mWindow), 100, 50);
// this HBox will contain the icon, and a vbox which contains the
// dialog text and other widgets.
GtkWidget* dialogHBox = gtk_hbox_new(FALSE, 12);
// Set up dialog properties according to the GNOME HIG
// (http://developer.gnome.org/projects/gup/hig/1.0/windows.html#alert-windows)
gtk_container_set_border_width(GTK_CONTAINER(mWindow), 6);
gtk_dialog_set_has_separator(GTK_DIALOG(mWindow), FALSE);
gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(mWindow)->vbox), 12);
gtk_container_set_border_width(GTK_CONTAINER(dialogHBox), 6);
// This is the VBox which will contain the label and other controls.
GtkWidget* contentsVBox = gtk_vbox_new(FALSE, 12);
// get the stock icon for this dialog and put it in the box
const gchar* iconDesc = DialogTable[aType].icon;
GtkWidget* icon = gtk_image_new_from_stock(iconDesc, GTK_ICON_SIZE_DIALOG);
gtk_misc_set_alignment(GTK_MISC(icon), 0.5, 0.0);
gtk_box_pack_start(GTK_BOX(dialogHBox), icon, FALSE, FALSE, 0);
// now pack the label into the vbox
GtkWidget* label = gtk_label_new(mMessageText.get());
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
gtk_label_set_selectable(GTK_LABEL(label), TRUE);
gtk_box_pack_start(GTK_BOX(contentsVBox), label, FALSE, FALSE, 0);
int widgetFlags = DialogTable[aType].flags;
if (widgetFlags & (INCLUDE_USERNAME | INCLUDE_PASSWORD)) {
// If we're creating a username and/or password field, make an hbox
// which will contain two vboxes, one for the labels and one for the
// text fields. This will let us line up the textfields.
GtkWidget* userPassHBox = gtk_hbox_new(FALSE, 12);
GtkWidget* userPassLabels = gtk_vbox_new(TRUE, 6);
GtkWidget* userPassFields = gtk_vbox_new(TRUE, 6);
if (widgetFlags & INCLUDE_USERNAME) {
GtkWidget* userLabel = gtk_label_new("User Name:");
gtk_box_pack_start(GTK_BOX(userPassLabels), userLabel, FALSE,
FALSE, 0);
mUserField = gtk_entry_new();
if (!mUser.IsEmpty())
gtk_entry_set_text(GTK_ENTRY(mUserField), mUser.get());
gtk_entry_set_activates_default(GTK_ENTRY(mUserField), TRUE);
gtk_box_pack_start(
GTK_BOX(userPassFields),
mUserField,
FALSE,
FALSE,
0);
}
if (widgetFlags & INCLUDE_PASSWORD) {
GtkWidget* passLabel = gtk_label_new("Password:");
gtk_box_pack_start(
GTK_BOX(userPassLabels),
passLabel,
FALSE,
FALSE,
0);
mPassField = gtk_entry_new();
if (!mPass.IsEmpty())
gtk_entry_set_text(GTK_ENTRY(mPassField), mPass.get());
gtk_entry_set_visibility(GTK_ENTRY(mPassField), FALSE);
gtk_entry_set_activates_default(GTK_ENTRY(mPassField), TRUE);
gtk_box_pack_start(
GTK_BOX(userPassFields),
mPassField,
FALSE,
FALSE,
0);
}
gtk_box_pack_start(
GTK_BOX(userPassHBox),
userPassLabels,
FALSE,
FALSE,
0);
gtk_box_pack_start(
GTK_BOX(userPassHBox),
userPassFields,
FALSE,
FALSE,
0);
gtk_box_pack_start(
GTK_BOX(contentsVBox),
userPassHBox,
FALSE,
FALSE,
0);
}
if (aType == TYPE_PROMPT) {
mTextField = gtk_entry_new();
if (!mTextValue.IsEmpty())
gtk_entry_set_text(GTK_ENTRY(mTextField), mTextValue.get());
gtk_entry_set_activates_default(GTK_ENTRY(mTextField), TRUE);
gtk_box_pack_start(GTK_BOX(contentsVBox), mTextField, FALSE, FALSE, 0);
}
// Add a checkbox
if ((widgetFlags & INCLUDE_CHECKBOX) && !mCheckMessage.IsEmpty()) {
mCheckBox = gtk_check_button_new_with_label(mCheckMessage.get());
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mCheckBox),
mCheckValue);
gtk_label_set_line_wrap(
GTK_LABEL(gtk_bin_get_child(GTK_BIN(mCheckBox))),
TRUE);
gtk_box_pack_start(GTK_BOX(contentsVBox), mCheckBox, FALSE, FALSE, 0);
}
// Add a dropdown menu
if (aType == TYPE_SELECT) {
// Build up a GtkMenu containing the items
GtkWidget* menu = gtk_menu_new();
for (PRUint32 i = 0; i < mItemCount; ++i) {
GtkWidget* item = gtk_menu_item_new_with_label(mItemList[i].get());
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
}
// Now create an OptionMenu and set this as the menu
mOptionMenu = gtk_option_menu_new();
gtk_option_menu_set_menu(GTK_OPTION_MENU(mOptionMenu), menu);
gtk_box_pack_start(GTK_BOX(contentsVBox), mOptionMenu, FALSE, FALSE, 0);
}
if (aType == TYPE_UNIVERSAL) {
// Create buttons based on the flags passed in.
for (int i = EMBED_MAX_BUTTONS; i >= 0; --i) {
if (!mButtonLabels[i].IsEmpty())
gtk_dialog_add_button(GTK_DIALOG(mWindow),
mButtonLabels[i].get(), i);
}
gtk_dialog_set_default_response(GTK_DIALOG(mWindow), 0);
} else {
// Create standard ok and cancel buttons
if (widgetFlags & INCLUDE_CANCEL)
gtk_dialog_add_button(GTK_DIALOG(mWindow), GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL);
GtkWidget* okButton = gtk_dialog_add_button(GTK_DIALOG(mWindow),
GTK_STOCK_OK,
GTK_RESPONSE_ACCEPT);
gtk_widget_grab_default(okButton);
}
// Pack the contentsVBox into the dialogHBox and the dialog.
gtk_box_pack_start(GTK_BOX(dialogHBox), contentsVBox, FALSE, FALSE, 0);
gtk_box_pack_start(
GTK_BOX(GTK_DIALOG(mWindow)->vbox),
dialogHBox,
FALSE,
FALSE,
0);
return NS_OK;
}
void
EmbedPrompter::SetTitle(const PRUnichar *aTitle)
{
mTitle.Assign(NS_ConvertUTF16toUTF8(aTitle));
}
void
EmbedPrompter::SetTextValue(const PRUnichar *aTextValue)
{
mTextValue.Assign(NS_ConvertUTF16toUTF8(aTextValue));
}
void
EmbedPrompter::SetCheckMessage(const PRUnichar *aMessage)
{
mCheckMessage.Assign(NS_ConvertUTF16toUTF8(aMessage));
}
void
EmbedPrompter::SetMessageText(const PRUnichar *aMessageText)
{
mMessageText.Assign(NS_ConvertUTF16toUTF8(aMessageText));
}
void
EmbedPrompter::SetUser(const PRUnichar *aUser)
{
mUser.Assign(NS_ConvertUTF16toUTF8(aUser));
}
void
EmbedPrompter::SetPassword(const PRUnichar *aPass)
{
mPass.Assign(NS_ConvertUTF16toUTF8(aPass));
}
void
EmbedPrompter::SetCheckValue(const PRBool aValue)
{
mCheckValue = aValue;
}
void
EmbedPrompter::SetItems(const PRUnichar** aItemArray, PRUint32 aCount)
{
if (mItemList)
delete[] mItemList;
mItemCount = aCount;
mItemList = new nsCString[aCount];
ALLOC_NOT_CHECKED(mItemList);
for (PRUint32 i = 0; i < aCount; ++i)
mItemList[i].Assign(NS_ConvertUTF16toUTF8(aItemArray[i]));
}
void
EmbedPrompter::SetButtons(const PRUnichar* aButton0Label,
const PRUnichar* aButton1Label,
const PRUnichar* aButton2Label)
{
mButtonLabels[0].Assign(NS_ConvertUTF16toUTF8(aButton0Label));
mButtonLabels[1].Assign(NS_ConvertUTF16toUTF8(aButton1Label));
mButtonLabels[2].Assign(NS_ConvertUTF16toUTF8(aButton2Label));
}
void
EmbedPrompter::GetCheckValue(PRBool *aValue)
{
*aValue = mCheckValue;
}
void
EmbedPrompter::GetConfirmValue(PRBool *aConfirmValue)
{
*aConfirmValue = mConfirmResult;
}
void
EmbedPrompter::GetTextValue(PRUnichar **aTextValue)
{
*aTextValue = ToNewUnicode(NS_ConvertUTF8toUTF16(mTextValue));
}
void
EmbedPrompter::GetUser(PRUnichar **aUser)
{
*aUser = ToNewUnicode(NS_ConvertUTF8toUTF16(mUser));
}
void
EmbedPrompter::GetPassword(PRUnichar **aPass)
{
*aPass = ToNewUnicode(NS_ConvertUTF8toUTF16(mPass));
}
void
EmbedPrompter::GetSelectedItem(PRInt32 *aIndex)
{
*aIndex = mSelectedItem;
}
void
EmbedPrompter::GetButtonPressed(PRInt32 *aButton)
{
*aButton = mButtonPressed;
}
void
EmbedPrompter::Run(void)
{
gtk_widget_show_all(mWindow);
gint response = gtk_dialog_run(GTK_DIALOG(mWindow));
switch (response) {
case GTK_RESPONSE_NONE:
case GTK_RESPONSE_CANCEL:
case GTK_RESPONSE_DELETE_EVENT:
mConfirmResult = PR_FALSE;
break;
case GTK_RESPONSE_ACCEPT:
mConfirmResult = PR_TRUE;
SaveDialogValues();
break;
default:
mButtonPressed = response;
SaveDialogValues();
}
gtk_widget_destroy(mWindow);
}
void
EmbedPrompter::SaveDialogValues()
{
if (mUserField)
mUser.Assign(gtk_entry_get_text(GTK_ENTRY(mUserField)));
if (mPassField)
mPass.Assign(gtk_entry_get_text(GTK_ENTRY(mPassField)));
if (mCheckBox)
mCheckValue = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mCheckBox));
if (mTextField)
mTextValue.Assign(gtk_entry_get_text(GTK_ENTRY(mTextField)));
if (mOptionMenu)
mSelectedItem = gtk_option_menu_get_history(GTK_OPTION_MENU(mOptionMenu));
}

View File

@@ -1,119 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Brian Ryner <bryner@brianryner.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifdef MOZILLA_INTERNAL_API
#include "nsString.h"
#include "nsReadableUtils.h"
#else
#include "nsStringAPI.h"
#endif
#include <gtk/gtk.h>
#include <stdlib.h>
#define EMBED_MAX_BUTTONS 3
class EmbedPrompter {
public:
EmbedPrompter();
~EmbedPrompter();
enum PromptType {
TYPE_ALERT,
TYPE_ALERT_CHECK,
TYPE_CONFIRM,
TYPE_CONFIRM_CHECK,
TYPE_PROMPT,
TYPE_PROMPT_USER_PASS,
TYPE_PROMPT_PASS,
TYPE_SELECT,
TYPE_UNIVERSAL
};
nsresult Create(PromptType aType, GtkWindow* aParentWindow);
void SetTitle(const PRUnichar *aTitle);
void SetTextValue(const PRUnichar *aTextValue);
void SetCheckMessage(const PRUnichar *aCheckMessage);
void SetCheckValue(const PRBool aValue);
void SetMessageText(const PRUnichar *aMessageText);
void SetUser(const PRUnichar *aUser);
void SetPassword(const PRUnichar *aPass);
void SetButtons(const PRUnichar* aButton0Label,
const PRUnichar* aButton1Label,
const PRUnichar* aButton2Label);
void SetItems(const PRUnichar **aItemArray, PRUint32 aCount);
void GetCheckValue(PRBool *aValue);
void GetConfirmValue(PRBool *aConfirmValue);
void GetTextValue(PRUnichar **aTextValue);
void GetUser(PRUnichar **aUser);
void GetPassword(PRUnichar **aPass);
void GetButtonPressed(PRInt32 *aButton);
void GetSelectedItem(PRInt32 *aIndex);
void Run(void);
private:
void SaveDialogValues();
nsCString mTitle;
nsCString mMessageText;
nsCString mTextValue;
nsCString mCheckMessage;
PRBool mCheckValue;
nsCString mUser;
nsCString mPass;
nsCString mButtonLabels[EMBED_MAX_BUTTONS];
nsCString *mItemList;
PRUint32 mItemCount;
PRInt32 mButtonPressed;
PRBool mConfirmResult;
PRInt32 mSelectedItem;
GtkWidget *mWindow;
GtkWidget *mUserField;
GtkWidget *mPassField;
GtkWidget *mTextField;
GtkWidget *mOptionMenu;
GtkWidget *mCheckBox;
};

View File

@@ -1,507 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCWebBrowser.h"
#include "nsIComponentManager.h"
#include "nsIDocShellTreeItem.h"
#include "nsIWidget.h"
#ifdef MOZILLA_INTERNAL_API
#include "nsReadableUtils.h"
#else
#include "nsComponentManagerUtils.h"
#endif
#include "EmbedWindow.h"
#include "EmbedPrivate.h"
#include "EmbedPrompter.h"
GtkWidget *EmbedWindow::sTipWindow = nsnull;
EmbedWindow::EmbedWindow(void)
{
mOwner = nsnull;
mVisibility = PR_FALSE;
mIsModal = PR_FALSE;
}
EmbedWindow::~EmbedWindow(void)
{
ExitModalEventLoop(PR_FALSE);
}
nsresult
EmbedWindow::Init(EmbedPrivate *aOwner)
{
// save our owner for later
mOwner = aOwner;
// create our nsIWebBrowser object and set up some basic defaults.
mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID);
if (!mWebBrowser)
return NS_ERROR_FAILURE;
mWebBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome *, this));
nsCOMPtr<nsIDocShellTreeItem> item = do_QueryInterface(mWebBrowser);
item->SetItemType(nsIDocShellTreeItem::typeContentWrapper);
return NS_OK;
}
nsresult
EmbedWindow::CreateWindow(void)
{
nsresult rv;
GtkWidget *ownerAsWidget = GTK_WIDGET(mOwner->mOwningWidget);
// Get the base window interface for the web browser object and
// create the window.
mBaseWindow = do_QueryInterface(mWebBrowser);
rv = mBaseWindow->InitWindow(GTK_WIDGET(mOwner->mOwningWidget),
nsnull,
0, 0,
ownerAsWidget->allocation.width,
ownerAsWidget->allocation.height);
if (NS_FAILED(rv))
return rv;
rv = mBaseWindow->Create();
if (NS_FAILED(rv))
return rv;
return NS_OK;
}
void
EmbedWindow::ReleaseChildren(void)
{
ExitModalEventLoop(PR_FALSE);
mBaseWindow->Destroy();
mBaseWindow = 0;
mWebBrowser = 0;
}
// nsISupports
NS_IMPL_ADDREF(EmbedWindow)
NS_IMPL_RELEASE(EmbedWindow)
NS_INTERFACE_MAP_BEGIN(EmbedWindow)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowserChrome)
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChromeFocus)
NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow)
// NS_INTERFACE_MAP_ENTRY(nsITooltipListener)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_END
// nsIWebBrowserChrome
NS_IMETHODIMP
EmbedWindow::SetStatus(PRUint32 aStatusType, const PRUnichar *aStatus)
{
switch (aStatusType) {
case STATUS_SCRIPT:
{
mJSStatus = aStatus; //FIXME MEMORY LEAK
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[JS_STATUS]);
}
break;
case STATUS_SCRIPT_DEFAULT:
// Gee, that's nice.
break;
case STATUS_LINK:
{
mLinkMessage = aStatus;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[LINK_MESSAGE]);
}
break;
}
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::GetWebBrowser(nsIWebBrowser **aWebBrowser)
{
*aWebBrowser = mWebBrowser;
NS_IF_ADDREF(*aWebBrowser);
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::SetWebBrowser(nsIWebBrowser *aWebBrowser)
{
mWebBrowser = aWebBrowser;
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::GetChromeFlags(PRUint32 *aChromeFlags)
{
*aChromeFlags = mOwner->mChromeMask;
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::SetChromeFlags(PRUint32 aChromeFlags)
{
mOwner->SetChromeMask(aChromeFlags);
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::DestroyBrowserWindow(void)
{
// mark the owner as destroyed so it won't emit events anymore.
mOwner->mIsDestroyed = PR_TRUE;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[DESTROY_BROWSER]);
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
{
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[SIZE_TO], aCX, aCY);
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::ShowAsModal(void)
{
mIsModal = PR_TRUE;
GtkWidget *toplevel;
toplevel = gtk_widget_get_toplevel(GTK_WIDGET(mOwner->mOwningWidget));
gtk_grab_add(toplevel);
gtk_main();
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::IsWindowModal(PRBool *_retval)
{
*_retval = mIsModal;
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::ExitModalEventLoop(nsresult aStatus)
{
if (mIsModal) {
GtkWidget *toplevel;
toplevel = gtk_widget_get_toplevel(GTK_WIDGET(mOwner->mOwningWidget));
gtk_grab_remove(toplevel);
mIsModal = PR_FALSE;
gtk_main_quit();
}
return NS_OK;
}
// nsIWebBrowserChromeFocus
NS_IMETHODIMP
EmbedWindow::FocusNextElement()
{
#ifdef MOZ_WIDGET_GTK
GtkWidget* parent = GTK_WIDGET(mOwner->mOwningWidget)->parent;
if (GTK_IS_CONTAINER(parent))
gtk_container_focus(GTK_CONTAINER(parent),
GTK_DIR_TAB_FORWARD);
#endif
#ifdef MOZ_WIDGET_GTK2
GtkWidget *toplevel;
toplevel = gtk_widget_get_toplevel(GTK_WIDGET(mOwner->mOwningWidget));
if (!GTK_WIDGET_TOPLEVEL(toplevel))
return NS_OK;
g_signal_emit_by_name(G_OBJECT(toplevel), "move_focus",
GTK_DIR_TAB_FORWARD);
#endif
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::FocusPrevElement()
{
#ifdef MOZ_WIDGET_GTK
GtkWidget* parent = GTK_WIDGET(mOwner->mOwningWidget)->parent;
if (GTK_IS_CONTAINER(parent))
gtk_container_focus(GTK_CONTAINER(parent),
GTK_DIR_TAB_BACKWARD);
#endif
#ifdef MOZ_WIDGET_GTK2
GtkWidget *toplevel;
toplevel = gtk_widget_get_toplevel(GTK_WIDGET(mOwner->mOwningWidget));
if (!GTK_WIDGET_TOPLEVEL(toplevel))
return NS_OK;
g_signal_emit_by_name(G_OBJECT(toplevel), "move_focus",
GTK_DIR_TAB_BACKWARD);
#endif
return NS_OK;
}
// nsIEmbeddingSiteWindow
NS_IMETHODIMP
EmbedWindow::SetDimensions(PRUint32 aFlags, PRInt32 aX, PRInt32 aY,
PRInt32 aCX, PRInt32 aCY)
{
if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION &&
(aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))) {
return mBaseWindow->SetPositionAndSize(aX, aY, aCX, aCY, PR_TRUE);
}
else if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) {
return mBaseWindow->SetPosition(aX, aY);
}
else if (aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)) {
return mBaseWindow->SetSize(aCX, aCY, PR_TRUE);
}
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP
EmbedWindow::GetDimensions(PRUint32 aFlags, PRInt32 *aX,
PRInt32 *aY, PRInt32 *aCX, PRInt32 *aCY)
{
if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION &&
(aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))) {
return mBaseWindow->GetPositionAndSize(aX, aY, aCX, aCY);
}
else if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) {
return mBaseWindow->GetPosition(aX, aY);
}
else if (aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)) {
return mBaseWindow->GetSize(aCX, aCY);
}
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP
EmbedWindow::SetFocus(void)
{
// XXX might have to do more here.
return mBaseWindow->SetFocus();
}
NS_IMETHODIMP
EmbedWindow::GetTitle(PRUnichar **aTitle)
{
*aTitle = ToNewUnicode(mTitle);
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::SetTitle(const PRUnichar *aTitle)
{
mTitle = aTitle;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[TITLE]);
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::GetSiteWindow(void **aSiteWindow)
{
GtkWidget *ownerAsWidget(GTK_WIDGET(mOwner->mOwningWidget));
*aSiteWindow = NS_STATIC_CAST(void *, ownerAsWidget);
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::GetVisibility(PRBool *aVisibility)
{
*aVisibility = mVisibility ||
!mOwner->mIsChrome &&
mOwner->mOwningWidget &&
GTK_WIDGET_MAPPED(mOwner->mOwningWidget);
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::SetVisibility(PRBool aVisibility)
{
// We always set the visibility so that if it's chrome and we finish
// the load we know that we have to show the window.
mVisibility = aVisibility;
// if this is a chrome window and the chrome hasn't finished loading
// yet then don't show the window yet.
if (mOwner->mIsChrome && !mOwner->mChromeLoaded)
return NS_OK;
gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
moz_embed_signals[VISIBILITY],
aVisibility);
return NS_OK;
}
// nsITooltipListener
#if 0
static gint
tooltips_paint_window(GtkWidget *window)
{
// draw tooltip style border around the text
gtk_paint_flat_box(window->style, window->window,
GTK_STATE_NORMAL, GTK_SHADOW_OUT,
NULL, window, "tooltip",
0, 0,
window->allocation.width, window->allocation.height);
return FALSE;
}
NS_IMETHODIMP
EmbedWindow::OnShowTooltip(PRInt32 aXCoords, PRInt32 aYCoords,
const PRUnichar *aTipText)
{
nsAutoString tipText(aTipText);
#ifdef MOZ_WIDGET_GTK
const char* tipString = ToNewCString(tipText);
#endif
#ifdef MOZ_WIDGET_GTK2
const char* tipString = ToNewUTF8String(tipText);
#endif
if (sTipWindow)
gtk_widget_destroy(sTipWindow);
// get the root origin for this content window
nsCOMPtr<nsIWidget> mainWidget;
mBaseWindow->GetMainWidget(getter_AddRefs(mainWidget));
GdkWindow *window;
window = NS_STATIC_CAST(GdkWindow *,
mainWidget->GetNativeData(NS_NATIVE_WINDOW));
gint root_x, root_y;
gdk_window_get_origin(window, &root_x, &root_y);
// XXX work around until I can get pink to figure out why
// tooltips vanish if they show up right at the origin of the
// cursor.
root_y += 10;
sTipWindow = gtk_window_new(GTK_WINDOW_POPUP);
gtk_widget_set_app_paintable(sTipWindow, TRUE);
gtk_window_set_policy(GTK_WINDOW(sTipWindow), FALSE, FALSE, TRUE);
// needed to get colors + fonts etc correctly
gtk_widget_set_name(sTipWindow, "gtk-tooltips");
// set up the popup window as a transient of the widget.
GtkWidget *toplevel_window;
toplevel_window = gtk_widget_get_toplevel(GTK_WIDGET(mOwner->mOwningWidget));
if (!GTK_WINDOW(toplevel_window)) {
NS_ERROR("no gtk window in hierarchy!\n");
return NS_ERROR_FAILURE;
}
gtk_window_set_transient_for(GTK_WINDOW(sTipWindow),
GTK_WINDOW(toplevel_window));
// realize the widget
gtk_widget_realize(sTipWindow);
gtk_signal_connect(GTK_OBJECT(sTipWindow), "expose_event",
GTK_SIGNAL_FUNC(tooltips_paint_window), NULL);
// set up the label for the tooltip
GtkWidget *label = gtk_label_new(tipString);
// wrap automatically
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
gtk_container_add(GTK_CONTAINER(sTipWindow), label);
gtk_container_set_border_width(GTK_CONTAINER(sTipWindow), 4);
// set the coords for the widget
gtk_widget_set_uposition(sTipWindow, aXCoords + root_x,
aYCoords + root_y);
// and show it.
gtk_widget_show_all(sTipWindow);
#ifdef MOZ_WIDGET_GTK
gtk_widget_popup(sTipWindow, aXCoords + root_x, aYCoords + root_y); */
#endif /* MOZ_WIDGET_GTK */
nsMemory::Free((void*)tipString);
return NS_OK;
}
NS_IMETHODIMP
EmbedWindow::OnHideTooltip(void)
{
if (sTipWindow)
gtk_widget_destroy(sTipWindow);
sTipWindow = NULL;
return NS_OK;
}
#endif
// nsIInterfaceRequestor
NS_IMETHODIMP
EmbedWindow::GetInterface(const nsIID &aIID, void** aInstancePtr)
{
nsresult rv;
rv = QueryInterface(aIID, aInstancePtr);
// pass it up to the web browser object
if (NS_FAILED(rv) || !*aInstancePtr) {
nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(mWebBrowser);
return ir->GetInterface(aIID, aInstancePtr);
}
return rv;
}

View File

@@ -1,107 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __EmbedWindow_h
#define __EmbedWindow_h
#ifdef MOZILLA_INTERNAL_API
#include "nsString.h"
#else
#include "nsStringAPI.h"
#endif
#include "nsIWebBrowserChrome.h"
#include "nsIWebBrowserChromeFocus.h"
#include "nsIEmbeddingSiteWindow.h"
//#include "nsITooltipListener.h"
#include "nsISupports.h"
#include "nsIWebBrowser.h"
#include "nsIBaseWindow.h"
#include "nsIInterfaceRequestor.h"
#include "nsCOMPtr.h"
#include <gtk/gtk.h>
class EmbedPrivate;
class EmbedWindow : public nsIWebBrowserChrome,
public nsIWebBrowserChromeFocus,
public nsIEmbeddingSiteWindow,
// public nsITooltipListener,
public nsIInterfaceRequestor
{
public:
EmbedWindow();
virtual ~EmbedWindow();
nsresult Init (EmbedPrivate *aOwner);
nsresult CreateWindow (void);
void ReleaseChildren (void);
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBBROWSERCHROME
NS_DECL_NSIWEBBROWSERCHROMEFOCUS
NS_DECL_NSIEMBEDDINGSITEWINDOW
// NS_DECL_NSITOOLTIPLISTENER
NS_DECL_NSIINTERFACEREQUESTOR
nsString mTitle;
nsString mJSStatus;
nsString mLinkMessage;
nsCOMPtr<nsIBaseWindow> mBaseWindow; // [OWNER]
private:
EmbedPrivate *mOwner;
nsCOMPtr<nsIWebBrowser> mWebBrowser; // [OWNER]
static GtkWidget *sTipWindow;
PRBool mVisibility;
PRBool mIsModal;
};
#endif /* __EmbedWindow_h */

View File

@@ -1,117 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "EmbedWindowCreator.h"
#include "EmbedPrivate.h"
#include "EmbedWindow.h"
// in order to create orphaned windows
#include "gtkmozembedprivate.h"
EmbedWindowCreator::EmbedWindowCreator(PRBool *aOpenBlockPtr)
{
mOpenBlock = aOpenBlockPtr;
}
EmbedWindowCreator::~EmbedWindowCreator()
{
}
NS_IMPL_ISUPPORTS1(EmbedWindowCreator, nsIWindowCreator)
NS_IMETHODIMP
EmbedWindowCreator::CreateChromeWindow(nsIWebBrowserChrome *aParent,
PRUint32 aChromeFlags,
nsIWebBrowserChrome **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
if (mOpenBlock) {
if (*mOpenBlock == PR_TRUE) {
*mOpenBlock = PR_FALSE;
return NS_ERROR_FAILURE;
}
}
GtkMozEmbed *newEmbed = nsnull;
// No parent? Ask via the singleton object instead.
if (!aParent) {
gtk_moz_embed_single_create_window(&newEmbed,
(guint)aChromeFlags);
} else {
// Find the EmbedPrivate object for this web browser chrome object.
EmbedPrivate *embedPrivate = EmbedPrivate::FindPrivateForBrowser(aParent);
if (!embedPrivate)
return NS_ERROR_FAILURE;
gtk_signal_emit(GTK_OBJECT(embedPrivate->mOwningWidget),
moz_embed_signals[NEW_WINDOW],
&newEmbed, (guint)aChromeFlags);
}
// check to make sure that we made a new window
if (!newEmbed)
return NS_ERROR_FAILURE;
// The window _must_ be realized before we pass it back to the
// function that created it. Functions that create new windows
// will do things like GetDocShell() and the widget has to be
// realized before that can happen.
gtk_widget_realize(GTK_WIDGET(newEmbed));
EmbedPrivate *newEmbedPrivate = NS_STATIC_CAST(EmbedPrivate *,
newEmbed->data);
// set the chrome flag on the new window if it's a chrome open
if (aChromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME)
newEmbedPrivate->mIsChrome = PR_TRUE;
*_retval = NS_STATIC_CAST(nsIWebBrowserChrome *,
(newEmbedPrivate->mWindow));
if (*_retval) {
NS_ADDREF(*_retval);
return NS_OK;
}
return NS_ERROR_FAILURE;
}

View File

@@ -1,58 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __EmbedWindowCreator_h
#define __EmbedWindowCreator_h
#include "nsIWindowCreator.h"
class EmbedWindowCreator : public nsIWindowCreator
{
public:
EmbedWindowCreator(PRBool *aOpenBlockPtr);
virtual ~EmbedWindowCreator();
NS_DECL_ISUPPORTS
NS_DECL_NSIWINDOWCREATOR
private:
PRBool *mOpenBlock;
};
#endif /* __EmbedWindowCreator_h */

View File

@@ -1,587 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=4 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@brianryner.com>
* Oleg Romashin <romaxa@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "GtkPromptService.h"
#include "EmbedGtkTools.h"
#include "gtkmozembedprivate.h"
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
#include "EmbedPrompter.h"
#endif
#ifdef MOZILLA_INTERNAL_API
#include "nsString.h"
#else
#include "nsStringAPI.h"
#endif
#include "nsIWindowWatcher.h"
#include "nsIWebBrowserChrome.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#define UNACCEPTABLE_CRASHY_GLIB_ALLOCATION(newed) PR_BEGIN_MACRO \
/* OOPS this code is using a glib allocation function which \
* will cause the application to crash when it runs out of \
* memory. This is not cool. either g_try methods should be \
* used or malloc, or new (note that gecko /will/ be replacing \
* its operator new such that new will not throw exceptions). \
* XXX please fix me. \
*/ \
if (!newed) { \
} \
PR_END_MACRO
GtkPromptService::GtkPromptService()
{
}
GtkPromptService::~GtkPromptService()
{
}
NS_IMPL_ISUPPORTS2(GtkPromptService, nsIPromptService, nsICookiePromptService)
NS_IMETHODIMP
GtkPromptService::Alert(
nsIDOMWindow* aParent,
const PRUnichar* aDialogTitle,
const PRUnichar* aDialogText)
{
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aParent);
if (parentWidget && gtk_signal_handler_pending(parentWidget, moz_embed_signals[ALERT], TRUE)) {
gtk_signal_emit(GTK_OBJECT(parentWidget),
moz_embed_signals[ALERT],
(const gchar *) NS_ConvertUTF16toUTF8(aDialogTitle).get(),
(const gchar *) NS_ConvertUTF16toUTF8(aDialogText).get());
return NS_OK;
}
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
EmbedPrompter prompter;
prompter.SetTitle(aDialogTitle ? aDialogTitle : NS_LITERAL_STRING("Alert").get());
prompter.SetMessageText(aDialogText);
prompter.Create(EmbedPrompter::TYPE_ALERT,
GetGtkWindowForDOMWindow(aParent));
prompter.Run();
#endif
return NS_OK;
}
NS_IMETHODIMP
GtkPromptService::AlertCheck(
nsIDOMWindow* aParent,
const PRUnichar* aDialogTitle,
const PRUnichar* aDialogText,
const PRUnichar* aCheckMsg,
PRBool* aCheckValue)
{
NS_ENSURE_ARG_POINTER(aCheckValue);
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aParent);
if (parentWidget && gtk_signal_handler_pending(parentWidget, moz_embed_signals[ALERT_CHECK], TRUE)) {
gtk_signal_emit(GTK_OBJECT(parentWidget),
moz_embed_signals[ALERT_CHECK],
NS_ConvertUTF16toUTF8(aDialogTitle).get(),
NS_ConvertUTF16toUTF8(aDialogTitle).get(),
NS_ConvertUTF16toUTF8(aCheckMsg).get(),
aCheckValue);
return NS_OK;
}
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
EmbedPrompter prompter;
prompter.SetTitle(aDialogTitle ? aDialogTitle : NS_LITERAL_STRING("Alert").get());
prompter.SetMessageText(aDialogText);
prompter.SetCheckMessage(aCheckMsg);
prompter.SetCheckValue(*aCheckValue);
prompter.Create(EmbedPrompter::TYPE_ALERT_CHECK,
GetGtkWindowForDOMWindow(aParent));
prompter.Run();
prompter.GetCheckValue(aCheckValue);
#endif
return NS_OK;
}
NS_IMETHODIMP
GtkPromptService::Confirm(
nsIDOMWindow* aParent,
const PRUnichar* aDialogTitle,
const PRUnichar* aDialogText,
PRBool* aConfirm)
{
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aParent);
if (parentWidget && gtk_signal_handler_pending(parentWidget, moz_embed_signals[CONFIRM], TRUE)) {
gtk_signal_emit(GTK_OBJECT(parentWidget),
moz_embed_signals[CONFIRM],
NS_ConvertUTF16toUTF8(aDialogTitle).get(), NS_ConvertUTF16toUTF8(aDialogText).get(), aConfirm);
return NS_OK;
}
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
EmbedPrompter prompter;
prompter.SetTitle(aDialogTitle ? aDialogTitle : NS_LITERAL_STRING("Confirm").get());
prompter.SetMessageText(aDialogText);
prompter.Create(EmbedPrompter::TYPE_CONFIRM,
GetGtkWindowForDOMWindow(aParent));
prompter.Run();
prompter.GetConfirmValue(aConfirm);
#endif
return NS_OK;
}
NS_IMETHODIMP
GtkPromptService::ConfirmCheck(
nsIDOMWindow* aParent,
const PRUnichar* aDialogTitle,
const PRUnichar* aDialogText,
const PRUnichar* aCheckMsg,
PRBool* aCheckValue,
PRBool* aConfirm)
{
NS_ENSURE_ARG_POINTER(aCheckValue);
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aParent);
if (parentWidget && gtk_signal_handler_pending(parentWidget, moz_embed_signals[CONFIRM_CHECK], TRUE)) {
gtk_signal_emit(GTK_OBJECT(parentWidget),
moz_embed_signals[CONFIRM_CHECK],
NS_ConvertUTF16toUTF8(aDialogTitle).get(),
NS_ConvertUTF16toUTF8(aDialogTitle).get(),
NS_ConvertUTF16toUTF8(aCheckMsg).get(),
aCheckValue,
aConfirm);
return NS_OK;
}
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
EmbedPrompter prompter;
prompter.SetTitle(aDialogTitle ? aDialogTitle : NS_LITERAL_STRING("Confirm").get());
prompter.SetMessageText(aDialogText);
prompter.SetCheckMessage(aCheckMsg);
prompter.SetCheckValue(*aCheckValue);
prompter.Create(EmbedPrompter::TYPE_CONFIRM_CHECK,
GetGtkWindowForDOMWindow(aParent));
prompter.Run();
prompter.GetCheckValue(aCheckValue);
prompter.GetConfirmValue(aConfirm);
#endif
return NS_OK;
}
NS_IMETHODIMP
GtkPromptService::ConfirmEx(
nsIDOMWindow* aParent,
const PRUnichar* aDialogTitle,
const PRUnichar* aDialogText,
PRUint32 aButtonFlags,
const PRUnichar* aButton0Title,
const PRUnichar* aButton1Title,
const PRUnichar* aButton2Title,
const PRUnichar* aCheckMsg,
PRBool* aCheckValue,
PRInt32* aRetVal)
{
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aParent);
if (parentWidget && gtk_signal_handler_pending(parentWidget, moz_embed_signals[CONFIRM_EX], TRUE)) {
gtk_signal_emit(GTK_OBJECT(parentWidget),
moz_embed_signals[CONFIRM_EX],
NS_ConvertUTF16toUTF8(aDialogTitle).get(),
NS_ConvertUTF16toUTF8(aDialogText).get(),
aButtonFlags,
NS_ConvertUTF16toUTF8(aButton0Title).get(),
NS_ConvertUTF16toUTF8(aButton1Title).get(),
NS_ConvertUTF16toUTF8(aButton2Title).get(),
NS_ConvertUTF16toUTF8(aCheckMsg).get(),
aCheckValue,
aRetVal);
return NS_OK;
}
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
EmbedPrompter prompter;
prompter.SetTitle(aDialogTitle ? aDialogTitle : NS_LITERAL_STRING("Confirm").get());
prompter.SetMessageText(aDialogText);
nsAutoString button0Label, button1Label, button2Label;
GetButtonLabel(aButtonFlags, BUTTON_POS_0, aButton0Title, button0Label);
GetButtonLabel(aButtonFlags, BUTTON_POS_1, aButton1Title, button1Label);
GetButtonLabel(aButtonFlags, BUTTON_POS_2, aButton2Title, button2Label);
prompter.SetButtons(button0Label.get(),
button1Label.get(),
button2Label.get());
if (aCheckMsg)
prompter.SetCheckMessage(aCheckMsg);
if (aCheckValue)
prompter.SetCheckValue(*aCheckValue);
prompter.Create(EmbedPrompter::TYPE_UNIVERSAL,
GetGtkWindowForDOMWindow(aParent));
prompter.Run();
if (aCheckValue)
prompter.GetCheckValue(aCheckValue);
prompter.GetButtonPressed(aRetVal);
#endif
return NS_OK;
}
#define XXX_ALLOCATOR_MISMATCH_XPCOM_GLIB(confused) PR_BEGIN_MACRO \
/* There is no way that this unforunate and confused object can \
* possibly be handled correctly. It started its life as an \
* XPCOM allocated pointer. \
* Then someone called it a gchar which confused it. \
* Then it was passed to a random function which probably \
* assumed it had ownership. \
* Finally it was freed using g_free. \
* This pointer is seriously confused. \
* XXX please please please help this pointer find some way to \
* rest in peace. \
*/ \
PR_END_MACRO
NS_IMETHODIMP
GtkPromptService::Prompt(
nsIDOMWindow* aParent,
const PRUnichar* aDialogTitle,
const PRUnichar* aDialogText,
PRUnichar** aValue,
const PRUnichar* aCheckMsg,
PRBool* aCheckValue,
PRBool* aConfirm)
{
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aParent);
if (parentWidget && gtk_signal_handler_pending(parentWidget, moz_embed_signals[PROMPT], TRUE)) {
gchar * value = ToNewCString(NS_ConvertUTF16toUTF8(*aValue));
XXX_ALLOCATOR_MISMATCH_XPCOM_GLIB(value);
gtk_signal_emit(GTK_OBJECT(parentWidget),
moz_embed_signals[PROMPT],
NS_ConvertUTF16toUTF8(aDialogTitle).get(),
NS_ConvertUTF16toUTF8(aDialogText).get(),
&value,
NS_ConvertUTF16toUTF8(aCheckMsg).get(),
aCheckValue,
aConfirm,
NULL);
if (*aConfirm) {
if (*aValue)
NS_Free(*aValue);
*aValue = ToNewUnicode(NS_ConvertUTF8toUTF16(value));
}
g_free(value);
return NS_OK;
}
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
EmbedPrompter prompter;
prompter.SetTitle(aDialogTitle ? aDialogTitle : NS_LITERAL_STRING("Prompt").get());
prompter.SetMessageText(aDialogText);
prompter.SetTextValue(*aValue);
if (aCheckMsg)
prompter.SetCheckMessage(aCheckMsg);
if (aCheckValue)
prompter.SetCheckValue(*aCheckValue);
prompter.Create(EmbedPrompter::TYPE_PROMPT,
GetGtkWindowForDOMWindow(aParent));
prompter.Run();
if (aCheckValue)
prompter.GetCheckValue(aCheckValue);
prompter.GetConfirmValue(aConfirm);
if (*aConfirm) {
if (*aValue)
NS_Free(*aValue);
prompter.GetTextValue(aValue);
}
#endif
return NS_OK;
}
NS_IMETHODIMP
GtkPromptService::PromptUsernameAndPassword(
nsIDOMWindow* aParent,
const PRUnichar* aDialogTitle,
const PRUnichar* aDialogText,
PRUnichar** aUsername,
PRUnichar** aPassword,
const PRUnichar* aCheckMsg,
PRBool* aCheckValue,
PRBool* aConfirm)
{
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aParent);
if (parentWidget && gtk_signal_handler_pending(parentWidget, moz_embed_signals[PROMPT_AUTH], TRUE)) {
gchar * username = ToNewCString(NS_ConvertUTF16toUTF8(*aUsername));
XXX_ALLOCATOR_MISMATCH_XPCOM_GLIB(username);
gchar * password = ToNewCString(NS_ConvertUTF16toUTF8(*aPassword));
XXX_ALLOCATOR_MISMATCH_XPCOM_GLIB(password);
gtk_signal_emit(GTK_OBJECT(parentWidget),
moz_embed_signals[PROMPT_AUTH],
NS_ConvertUTF16toUTF8(aDialogTitle).get(),
NS_ConvertUTF16toUTF8(aDialogText).get(),
&username, &password,
NS_ConvertUTF16toUTF8(aCheckMsg).get(),
aCheckValue, aConfirm);
if (*aConfirm) {
if (*aUsername)
NS_Free(*aUsername);
*aUsername = ToNewUnicode(NS_ConvertUTF8toUTF16(username));
if (*aPassword)
NS_Free(*aPassword);
*aPassword = ToNewUnicode(NS_ConvertUTF8toUTF16(password));
}
g_free(username);
g_free(password);
return NS_OK;
}
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
EmbedPrompter prompter;
prompter.SetTitle(aDialogTitle ? aDialogTitle : NS_LITERAL_STRING("Prompt").get());
prompter.SetMessageText(aDialogText);
prompter.SetUser(*aUsername);
prompter.SetPassword(*aPassword);
if (aCheckMsg)
prompter.SetCheckMessage(aCheckMsg);
if (aCheckValue)
prompter.SetCheckValue(*aCheckValue);
prompter.Create(EmbedPrompter::TYPE_PROMPT_USER_PASS,
GetGtkWindowForDOMWindow(aParent));
prompter.Run();
if (aCheckValue)
prompter.GetCheckValue(aCheckValue);
prompter.GetConfirmValue(aConfirm);
if (*aConfirm) {
if (*aUsername)
NS_Free(*aUsername);
prompter.GetUser(aUsername);
if (*aPassword)
NS_Free(*aPassword);
prompter.GetPassword(aPassword);
}
#endif
return NS_OK;
}
NS_IMETHODIMP
GtkPromptService::PromptPassword(
nsIDOMWindow* aParent,
const PRUnichar* aDialogTitle,
const PRUnichar* aDialogText,
PRUnichar** aPassword,
const PRUnichar* aCheckMsg,
PRBool* aCheckValue, PRBool* aConfirm)
{
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aParent);
if (parentWidget && gtk_signal_handler_pending(parentWidget, moz_embed_signals[PROMPT_AUTH], TRUE)) {
gchar * password = ToNewCString(NS_ConvertUTF16toUTF8(*aPassword));
XXX_ALLOCATOR_MISMATCH_XPCOM_GLIB(password);
gtk_signal_emit(GTK_OBJECT(parentWidget),
moz_embed_signals[PROMPT_AUTH],
NS_ConvertUTF16toUTF8(aDialogTitle).get(),
NS_ConvertUTF16toUTF8(aDialogText).get(),
NULL,
&password,
NS_ConvertUTF16toUTF8(aCheckMsg).get(),
aCheckValue,
aConfirm);
if (*aConfirm) {
if (*aPassword)
NS_Free(*aPassword);
*aPassword = ToNewUnicode(NS_ConvertUTF8toUTF16(password));
}
g_free(password);
return NS_OK;
}
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
EmbedPrompter prompter;
prompter.SetTitle(aDialogTitle ? aDialogTitle : NS_LITERAL_STRING("Prompt").get());
prompter.SetMessageText(aDialogText);
prompter.SetPassword(*aPassword);
if (aCheckMsg)
prompter.SetCheckMessage(aCheckMsg);
if (aCheckValue)
prompter.SetCheckValue(*aCheckValue);
prompter.Create(EmbedPrompter::TYPE_PROMPT_PASS,
GetGtkWindowForDOMWindow(aParent));
prompter.Run();
if (aCheckValue)
prompter.GetCheckValue(aCheckValue);
prompter.GetConfirmValue(aConfirm);
if (*aConfirm) {
if (*aPassword)
NS_Free(*aPassword);
prompter.GetPassword(aPassword);
}
#endif
return NS_OK;
}
NS_IMETHODIMP
GtkPromptService::Select(
nsIDOMWindow* aParent,
const PRUnichar* aDialogTitle,
const PRUnichar* aDialogText,
PRUint32 aCount,
const PRUnichar** aSelectList,
PRInt32* outSelection,
PRBool* aConfirm)
{
GtkWidget* parentWidget = GetGtkWidgetForDOMWindow(aParent);
if (parentWidget && gtk_signal_handler_pending(parentWidget, moz_embed_signals[SELECT], TRUE)) {
GList * list = NULL;
nsCString *itemList = new nsCString[aCount];
NS_ENSURE_TRUE(itemList, NS_ERROR_OUT_OF_MEMORY);
for (PRUint32 i = 0; i < aCount; ++i) {
itemList[i] = ToNewCString(NS_ConvertUTF16toUTF8(aSelectList[i]));
list = g_list_append(list, (gpointer)itemList[i].get());
}
gtk_signal_emit(GTK_OBJECT(parentWidget),
moz_embed_signals[SELECT],
NS_ConvertUTF16toUTF8(aDialogTitle).get(),
NS_ConvertUTF16toUTF8(aDialogText).get(),
(const GList**)&list,
outSelection,
aConfirm);
delete[] itemList;
g_list_free(list);
return NS_OK;
}
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
EmbedPrompter prompter;
prompter.SetTitle(aDialogTitle ? aDialogTitle : NS_LITERAL_STRING("Select").get());
prompter.SetMessageText(aDialogText);
prompter.SetItems(aSelectList, aCount);
prompter.Create(EmbedPrompter::TYPE_SELECT,
GetGtkWindowForDOMWindow(aParent));
prompter.Run();
prompter.GetSelectedItem(outSelection);
prompter.GetConfirmValue(aConfirm);
#endif
return NS_OK;
}
/* nsCookiePromptService */
NS_IMETHODIMP
GtkPromptService::CookieDialog(
nsIDOMWindow *aParent,
nsICookie *aCookie,
const nsACString &aHostname,
PRInt32 aCookiesFromHost,
PRBool aChangingCookie,
PRBool *aRememberDecision,
PRInt32 *aAccept)
{
/* FIXME - missing gint actions and gboolean illegal_path */
gint actions = 1;
nsCString hostName(aHostname);
nsCString aName;
aCookie->GetName(aName);
nsCString aValue;
aCookie->GetValue(aValue);
nsCString aDomain;
aCookie->GetHost(aDomain);
nsCString aPath;
aCookie->GetPath(aPath);
/* We have to investigate a value to use here */
gboolean illegal_path = FALSE;
PRUint64 aExpires;
aCookie->GetExpires(&aExpires);
nsCOMPtr<nsIDOMWindow> domWindow(do_QueryInterface(aParent));
GtkMozEmbed *parentWidget = GTK_MOZ_EMBED(GetGtkWidgetForDOMWindow(domWindow));
GtkMozEmbedCookie *cookie_struct = g_new0(GtkMozEmbedCookie, 1);
UNACCEPTABLE_CRASHY_GLIB_ALLOCATION(cookie_struct);
if (parentWidget && cookie_struct) {
g_signal_emit_by_name(
GTK_OBJECT(parentWidget->common),
"ask-cookie",
cookie_struct,
actions,
(const gchar *) hostName.get(),
(const gchar *) aName.get(),
(const gchar *) aValue.get(),
(const gchar *) aDomain.get(),
(const gchar *) aPath.get(),
illegal_path,
aExpires,
NULL);
}
*aRememberDecision = cookie_struct->remember_decision;
*aAccept = cookie_struct->accept;
return NS_OK;
}
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
void
GtkPromptService::GetButtonLabel(
PRUint32 aFlags,
PRUint32 aPos,
const PRUnichar* aStringValue,
nsAString& aLabel)
{
PRUint32 posFlag = (aFlags & (255 * aPos)) / aPos;
switch (posFlag) {
case 0:
break;
case BUTTON_TITLE_OK:
aLabel.AssignLiteral(GTK_STOCK_OK);
break;
case BUTTON_TITLE_CANCEL:
aLabel.AssignLiteral(GTK_STOCK_CANCEL);
break;
case BUTTON_TITLE_YES:
aLabel.AssignLiteral(GTK_STOCK_YES);
break;
case BUTTON_TITLE_NO:
aLabel.AssignLiteral(GTK_STOCK_NO);
break;
case BUTTON_TITLE_SAVE:
aLabel.AssignLiteral(GTK_STOCK_SAVE);
break;
case BUTTON_TITLE_DONT_SAVE:
aLabel.AssignLiteral("Don't Save");
break;
case BUTTON_TITLE_REVERT:
aLabel.AssignLiteral("Revert");
break;
case BUTTON_TITLE_IS_STRING:
aLabel = aStringValue;
break;
default:
NS_WARNING("Unexpected button flags");
}
}
#endif

View File

@@ -1,72 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@brianryner.com>
* Oleg Romashin <romaxa@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsIPromptService.h"
#include "nsICookiePromptService.h"
#include "nsICookie.h"
#include "nsNetCID.h"
#include <gtk/gtk.h>
#ifdef MOZILLA_INTERNAL_API
#include "nsString.h"
#else
#include "nsStringAPI.h"
#endif
#define NS_PROMPTSERVICE_CID \
{0x95611356, 0xf583, 0x46f5, {0x81, 0xff, 0x4b, 0x3e, 0x01, 0x62, 0xc6, 0x19}}
class nsIDOMWindow;
class GtkPromptService : public nsIPromptService,
public nsICookiePromptService
{
public:
GtkPromptService();
virtual ~GtkPromptService();
NS_DECL_ISUPPORTS
NS_DECL_NSIPROMPTSERVICE
NS_DECL_NSICOOKIEPROMPTSERVICE
#ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
private:
void GetButtonLabel(PRUint32 aFlags, PRUint32 aPos,
const PRUnichar* aStringValue, nsAString &aLabel);
#endif
};

View File

@@ -1,231 +0,0 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is the Mozilla browser.
#
# The Initial Developer of the Original Code is
# Christopher Blizzard.
# Portions created by the Initial Developer are Copyright (C) 1999
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Christopher Blizzard <blizzard@mozilla.org>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = gtkembedmoz
LIBRARY_NAME = gtkembedmoz
LIBXUL_LIBRARY = 1
FORCE_STATIC_LIB = 1
LOCAL_INCLUDES += \
-I. \
$(NULL)
#Temporary define for full migration from libxul
#MOZ_GTKEMBED_DYN = 1
ifdef MOZ_GTKEMBED_DYN
#DEFINES += -DFIXED_BUG347731
FORCE_SHARED_LIB = 1
ifdef MOZ_ENABLE_LIBXUL
LIBXUL_LIBRARY =
endif
endif
DEFINES += -DIMPL_XREAPI
# New Stuff in GtkMozEmbed
ifdef MOZ_MICROBEMBED
DEFINES += -DBAD_CERT_LISTENER2
#Probably scrolling can be fixed without this hack
DEFINES += -DMOZ_SCROLL_TOP_LEFT_HACK
MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT = 1
DEFINES += -DMOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
MOZ_GTKPASSWORD_INTERFACE = 1
DEFINES += -DMOZ_GTKPASSWORD_INTERFACE
endif
REQUIRES = xpcom \
string \
content \
docshell \
necko \
widget \
dom \
gfx \
intl \
imglib2 \
layout \
locale \
unicharutil \
uriloader \
webbrwsr \
shistory \
composer \
editor \
embed_base \
windowwatcher \
webshell \
pipnss \
history \
pref \
nspr \
xulapp \
exthandler \
mimetype \
chardet \
find \
webbrowserpersist \
cookie \
nkcache \
pipboot \
$(NULL)
ifdef ACCESSIBILITY
REQUIRES += accessibility
endif
CPPSRCS = \
gtkmozembed2.cpp \
EmbedPrivate.cpp \
EmbedWindow.cpp \
EmbedProgress.cpp \
EmbedContentListener.cpp \
EmbedEventListener.cpp \
EmbedWindowCreator.cpp \
EmbedGtkTools.cpp \
$(NULL)
ifdef MOZ_ENABLE_GTK2
CPPSRCS += \
gtkmozembed_common.cpp \
gtkmozembed_download.cpp \
EmbedContextMenuInfo.cpp \
EmbedCertificates.cpp \
EmbedDownloadMgr.cpp \
EmbedGlobalHistory.cpp \
EmbedFilePicker.cpp \
$(NULL)
ifdef MOZ_GTKPASSWORD_INTERFACE
CPPSRCS += \
EmbedPasswordMgr.cpp \
$(NULL)
XPIDLSRCS += \
nsIPassword.idl \
nsIPasswordInternal.idl \
$(NULL)
endif
CSRCS = \
gtkmozembedmarshal.c
CPPSRCS += \
GtkPromptService.cpp \
$(NULL)
ifndef MOZ_NO_GECKO_UI_FALLBACK_1_8_COMPAT
CPPSRCS += \
EmbedPrompter.cpp \
$(NULL)
endif
endif
include $(topsrcdir)/config/config.mk
EXPORTS = \
gtkmozembed.h \
gtkmozembed_glue.cpp \
gtkmozembed_internal.h \
$(NULL)
ifdef MOZ_ENABLE_GTK2
EXPORTS += \
gtkmozembed_common.h \
gtkmozembed_download.h \
$(NULL)
endif
ifdef MOZ_GTKEMBED_DYN
ifneq (,$(filter gtk gtk2 qt xlib,$(MOZ_WIDGET_TOOLKIT)))
EXTRA_DSO_LDOPTS += \
$(DIST)/lib/libxpcomglue_s.$(LIB_SUFFIX) \
$(MOZ_COMPONENT_LIBS) \
$(MOZ_GTK2_LIBS) \
$(NULL)
#Any Idea what can be used instead -lxul in FF configuration?
ifndef MOZ_ENABLE_LIBXUL
EXTRA_DSO_LDOPTS += \
-lxul \
$(NULL)
endif
endif
endif
include $(topsrcdir)/config/rules.mk
ifeq ($(OS_ARCH), SunOS)
ifndef GNU_CC
# When using Sun's WorkShop compiler, including
# /wherever/workshop-5.0/SC5.0/include/CC/std/time.h
# causes most of these compiles to fail with:
# line 29: Error: Multiple declaration for std::tm.
# So, this gets around the problem.
DEFINES += -D_TIME_H=1
endif
endif
CXXFLAGS += $(MOZ_GTK_CFLAGS) $(MOZ_GTK2_CFLAGS)
CFLAGS += $(MOZ_GTK_CFLAGS) $(MOZ_GTK2_CFLAGS)
ifdef MOZ_GNOMEVFS_CFLAGS
CXXFLAGS += $(MOZ_GNOMEVFS_CFLAGS)
CFLAGS += $(MOZ_GNOMEVFS_CFLAGS)
endif
DEFINES += -D_IMPL_GTKMOZEMBED
MARSHAL_FILE = gtkmozembedmarshal
MARSHAL_PREFIX = gtkmozembed
$(MARSHAL_FILE).h: $(MARSHAL_FILE).list
glib-genmarshal --prefix=$(MARSHAL_PREFIX) $(srcdir)/$(MARSHAL_FILE).list --skip-source --header > $(MARSHAL_FILE).h
$(MARSHAL_FILE).c: $(MARSHAL_FILE).list $(MARSHAL_FILE).h
glib-genmarshal --prefix=$(MARSHAL_PREFIX) $(srcdir)/$(MARSHAL_FILE).list --skip-source --body > $(MARSHAL_FILE).c

View File

@@ -1,396 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Ramiro Estrugo <ramiro@eazel.com>
* Oleg Romashin <romaxa@gmail.com>
* Antonio Gomes <tonikitoo@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef gtkmozembed_h
#define gtkmozembed_h
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <stddef.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#ifdef MOZILLA_CLIENT
#include "nscore.h"
#else /* MOZILLA_CLIENT */
#ifndef nscore_h__
/* Because this header may be included from files which not part of the mozilla
build system, define macros from nscore.h */
#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
#define NS_HIDDEN __attribute__((visibility("hidden")))
#else
#define NS_HIDDEN
#endif
#define NS_FROZENCALL
#define NS_EXPORT_(type) type
#define NS_IMPORT_(type) type
#endif /* nscore_h__ */
#endif /* MOZILLA_CLIENT */
#ifdef XPCOM_GLUE
#define GTKMOZEMBED_API(type, name, params) \
typedef type (NS_FROZENCALL * name##Type) params; \
extern name##Type name NS_HIDDEN;
#else /* XPCOM_GLUE */
#ifdef _IMPL_GTKMOZEMBED
#define GTKMOZEMBED_API(type, name, params) NS_EXPORT_(type) name params;
#else
#define GTKMOZEMBED_API(type,name, params) NS_IMPORT_(type) name params;
#endif
#endif /* XPCOM_GLUE */
/** @struct GtkWebHistoryItem.
* Defines a web history item.
*/
typedef struct _GtkMozHistoryItem GtkMozHistoryItem;
struct _GtkMozHistoryItem
{
const gchar *title; /** < URL title */
const gchar *url; /** < URL */
long accessed; /** < The last time that the URL was accessed */
};
#ifdef MOZ_WIDGET_GTK2
#include "gtkmozembed_common.h"
#endif
#define GTK_TYPE_MOZ_EMBED (gtk_moz_embed_get_type())
#define GTK_MOZ_EMBED(obj) GTK_CHECK_CAST((obj), GTK_TYPE_MOZ_EMBED, GtkMozEmbed)
#define GTK_MOZ_EMBED_CLASS(klass) GTK_CHECK_CLASS_CAST((klass), GTK_TYPE_MOZ_EMBED, GtkMozEmbedClass)
#define GTK_IS_MOZ_EMBED(obj) GTK_CHECK_TYPE((obj), GTK_TYPE_MOZ_EMBED)
#define GTK_IS_MOZ_EMBED_CLASS(klass) GTK_CHECK_CLASS_TYPE((klass), GTK_TYPE_MOZ_EMBED)
typedef struct _GtkMozEmbed GtkMozEmbed;
typedef struct _GtkMozEmbedClass GtkMozEmbedClass;
struct _GtkMozEmbed
{
GtkBin bin;
void *data;
GtkObject *common;
/* FIXME: This is a temporary solution for incorrect progress values
* being passed up. Oleg has mentioned something about a bug in JS.
*/
gint current_number_of_requests;
gint total_number_of_requests;
gint number_of_frames_loaded;
};
struct _GtkMozEmbedClass
{
GtkBinClass parent_class;
void (* link_message) (GtkMozEmbed *embed);
void (* js_status) (GtkMozEmbed *embed);
void (* location) (GtkMozEmbed *embed);
void (* title) (GtkMozEmbed *embed);
void (* progress) (GtkMozEmbed *embed, gint curprogress,
gint maxprogress);
void (* progress_all) (GtkMozEmbed *embed, const gchar *aURI,
gint curprogress, gint maxprogress);
void (* net_state) (GtkMozEmbed *embed, gint state, guint status);
void (* net_state_all) (GtkMozEmbed *embed, const gchar *aURI,
gint state, guint status);
void (* net_start) (GtkMozEmbed *embed);
void (* net_stop) (GtkMozEmbed *embed);
void (* new_window) (GtkMozEmbed *embed, GtkMozEmbed **newEmbed,
guint chromemask);
void (* visibility) (GtkMozEmbed *embed, gboolean visibility);
void (* destroy_brsr) (GtkMozEmbed *embed);
gint (* open_uri) (GtkMozEmbed *embed, const char *aURI);
void (* size_to) (GtkMozEmbed *embed, gint width, gint height);
gint (* dom_key_down) (GtkMozEmbed *embed, gpointer dom_event);
gint (* dom_key_press) (GtkMozEmbed *embed, gpointer dom_event);
gint (* dom_key_up) (GtkMozEmbed *embed, gpointer dom_event);
gint (* dom_mouse_down) (GtkMozEmbed *embed, gpointer dom_event);
gint (* dom_mouse_up) (GtkMozEmbed *embed, gpointer dom_event);
gint (* dom_mouse_click) (GtkMozEmbed *embed, gpointer dom_event);
gint (* dom_mouse_dbl_click) (GtkMozEmbed *embed, gpointer dom_event);
gint (* dom_mouse_over) (GtkMozEmbed *embed, gpointer dom_event);
gint (* dom_mouse_out) (GtkMozEmbed *embed, gpointer dom_event);
/* gint (* dom_mouse_move) (GtkMozEmbed *embed, gpointer dom_event); */
gint (* dom_mouse_scroll) (GtkMozEmbed *embed, gpointer dom_event);
gint (* dom_mouse_long_press)(GtkMozEmbed *embed, gpointer dom_event);
gint (* dom_focus) (GtkMozEmbed *embed, gpointer dom_event);
gint (* dom_blur) (GtkMozEmbed *embed, gpointer dom_event);
void (* security_change) (GtkMozEmbed *embed, gpointer request,
guint state);
void (* status_change) (GtkMozEmbed *embed, gpointer request,
gint status, gpointer message);
gint (* dom_activate) (GtkMozEmbed *embed, gpointer dom_event);
gint (* dom_focus_in) (GtkMozEmbed *embed, gpointer dom_event);
gint (* dom_focus_out) (GtkMozEmbed *embed, gpointer dom_event);
void (* alert) (GtkMozEmbed *embed, const char *title, const char *text);
void (* alert_check) (GtkMozEmbed *embed, const char *title, const char *text,
const char *check_msg, gboolean *check_val);
gboolean (* confirm) (GtkMozEmbed *embed, const char *title, const char *text);
gboolean (* confirm_check) (GtkMozEmbed *embed, const char *title, const char *text,
const char *check_msg, gboolean *check_val);
gint (* confirm_ex) (GtkMozEmbed *embed, const char *title, const char *text, guint bt_flags,
const char *button1, const char *button2, const char *button3,
const char *check_msg, gboolean *check_val);
gboolean (* prompt) (GtkMozEmbed *embed, const char *title, const char *text,
char **value, const char *check_msg, gboolean *check_val);
gboolean (* prompt_auth) (GtkMozEmbed *embed, const char *title, const char *text,
char **user, char **pass, const char *check_msg, gboolean *check_val);
gboolean (* select) (GtkMozEmbed *embed, const char *title, const char *text,
GList *list, gint *selected_item);
void (* download_request)(GtkMozEmbed *, const char *, const char *, const char *, long, int, gpointer);
gboolean (* upload_dialog) (GtkMozEmbed *, const char *, const char *, char **);
void (* icon_changed) (GtkMozEmbed *, gpointer*);
void (* mailto) (GtkMozEmbed *, gchar *);
void (* network_error) (GtkMozEmbed *, gchar *, const gint, const gchar **);
void (* rss_request) (GtkMozEmbed *, gchar *, gchar *);
};
GTKMOZEMBED_API(GtkType, gtk_moz_embed_get_type, (void))
GTKMOZEMBED_API(GtkWidget*, gtk_moz_embed_new, (void))
GTKMOZEMBED_API(void, gtk_moz_embed_push_startup, (void))
GTKMOZEMBED_API(void, gtk_moz_embed_pop_startup, (void))
/* Tell gtkmozembed where the gtkmozembed libs live. If this is not specified,
The MOZILLA_FIVE_HOME environment variable is checked. */
GTKMOZEMBED_API(void, gtk_moz_embed_set_path, (const char *aPath))
GTKMOZEMBED_API(void, gtk_moz_embed_set_comp_path, (const char *aPath))
GTKMOZEMBED_API(void, gtk_moz_embed_set_profile_path, (const char *aDir, const char *aName))
GTKMOZEMBED_API(void, gtk_moz_embed_load_url, (GtkMozEmbed *embed, const char *url))
GTKMOZEMBED_API(void, gtk_moz_embed_stop_load, (GtkMozEmbed *embed))
GTKMOZEMBED_API(gboolean, gtk_moz_embed_can_go_back, (GtkMozEmbed *embed))
GTKMOZEMBED_API(gboolean, gtk_moz_embed_can_go_forward, (GtkMozEmbed *embed))
GTKMOZEMBED_API(void, gtk_moz_embed_go_back, (GtkMozEmbed *embed))
GTKMOZEMBED_API(void, gtk_moz_embed_go_forward, (GtkMozEmbed *embed))
GTKMOZEMBED_API(void, gtk_moz_embed_render_data, (GtkMozEmbed *embed, const char *data, guint32 len,
const char *base_uri, const char *mime_type))
GTKMOZEMBED_API(void, gtk_moz_embed_open_stream, (GtkMozEmbed *embed,
const char *base_uri, const char *mime_type))
GTKMOZEMBED_API(void, gtk_moz_embed_append_data, (GtkMozEmbed *embed,
const char *data, guint32 len))
GTKMOZEMBED_API(void, gtk_moz_embed_close_stream, (GtkMozEmbed *embed))
GTKMOZEMBED_API(gchar*, gtk_moz_embed_get_link_message, (GtkMozEmbed *embed))
GTKMOZEMBED_API(gchar*, gtk_moz_embed_get_js_status, (GtkMozEmbed *embed))
GTKMOZEMBED_API(gchar*, gtk_moz_embed_get_title, (GtkMozEmbed *embed))
GTKMOZEMBED_API(gchar*, gtk_moz_embed_get_location, (GtkMozEmbed *embed))
GTKMOZEMBED_API(void, gtk_moz_embed_reload, (GtkMozEmbed *embed, gint32 flags))
GTKMOZEMBED_API(void, gtk_moz_embed_set_chrome_mask, (GtkMozEmbed *embed, guint32 flags))
GTKMOZEMBED_API(guint32, gtk_moz_embed_get_chrome_mask, (GtkMozEmbed *embed))
GTKMOZEMBED_API(gboolean, gtk_moz_embed_get_zoom_level, (GtkMozEmbed *embed, gint*, gpointer))
GTKMOZEMBED_API(gboolean, gtk_moz_embed_set_zoom_level, (GtkMozEmbed *embed, gint, gpointer))
GTKMOZEMBED_API(gboolean, gtk_moz_embed_find_text, (GtkMozEmbed *embed, const gchar*, gboolean, gboolean, gboolean, gboolean, gint))
GTKMOZEMBED_API(gboolean, gtk_moz_embed_clipboard, (GtkMozEmbed *embed, guint, gint))
GTKMOZEMBED_API(void, gtk_moz_embed_notify_plugins, (GtkMozEmbed *embed, guint))
GTKMOZEMBED_API(void, gtk_moz_embed_check_logins, (GtkMozEmbed *embed))
GTKMOZEMBED_API(char*, gtk_moz_embed_get_encoding, (GtkMozEmbed *embed, gint))
GTKMOZEMBED_API(void, gtk_moz_embed_set_encoding, (GtkMozEmbed *embed, const gchar *, gint))
GTKMOZEMBED_API(guint, gtk_moz_embed_get_context_info, (GtkMozEmbed *embed, gpointer event, gpointer *node,
gint *x, gint *y, gint *docindex,
const gchar **url, const gchar **objurl, const gchar **docurl))
GTKMOZEMBED_API(const gchar*, gtk_moz_embed_get_selection, (GtkMozEmbed *embed))
GTKMOZEMBED_API(gboolean, gtk_moz_embed_get_doc_info, (GtkMozEmbed *embed, gpointer node, gint docindex, const gchar**title,
const gchar**location, const gchar **file_type, guint *file_size,
gint *width, gint *height))
GTKMOZEMBED_API(gboolean, gtk_moz_embed_insert_text, (GtkMozEmbed *embed, const gchar*, gpointer node))
GTKMOZEMBED_API(gboolean, gtk_moz_embed_save_target, (GtkMozEmbed *embed, gchar*, gchar*, gint))
GTKMOZEMBED_API(gint, gtk_moz_embed_get_shistory_list, (GtkMozEmbed *embed, GtkMozHistoryItem **GtkHI, guint type))
GTKMOZEMBED_API(gint, gtk_moz_embed_get_shistory_index, (GtkMozEmbed *embed))
GTKMOZEMBED_API(void, gtk_moz_embed_shistory_goto_index, (GtkMozEmbed *embed, gint index))
GTKMOZEMBED_API(gboolean, gtk_moz_embed_get_server_cert, (GtkMozEmbed *embed, gpointer *aCert, gpointer))
typedef enum
{
GTK_MOZ_EMBED_BACK_SHISTORY,
GTK_MOZ_EMBED_FORWARD_SHISTORY
} GtkMozEmbedSessionHistory;
typedef enum
{
GTK_MOZ_EMBED_SELECT_ALL,
GTK_MOZ_EMBED_CAN_SELECT,
GTK_MOZ_EMBED_CUT,
GTK_MOZ_EMBED_COPY,
GTK_MOZ_EMBED_PASTE,
GTK_MOZ_EMBED_CAN_CUT,
GTK_MOZ_EMBED_CAN_PASTE,
GTK_MOZ_EMBED_CAN_COPY
} GtkMozEmbedClipboard;
typedef enum
{
GTK_MOZ_EMBED_CTX_NONE = 0,
GTK_MOZ_EMBED_CTX_XUL = 1 << 1,
GTK_MOZ_EMBED_CTX_SIDEBAR = 1 << 2,
GTK_MOZ_EMBED_CTX_DOCUMENT = 1 << 3,
GTK_MOZ_EMBED_CTX_LINK = 1 << 4,
GTK_MOZ_EMBED_CTX_IMAGE = 1 << 5,
GTK_MOZ_EMBED_CTX_IFRAME = 1 << 6,
GTK_MOZ_EMBED_CTX_INPUT = 1 << 7,
GTK_MOZ_EMBED_CTX_IPASSWORD = 1 << 8,
GTK_MOZ_EMBED_CTX_EMAIL = 1 << 9,
GTK_MOZ_EMBED_CTX_RICHEDIT = 1 << 10,
GTK_MOZ_EMBED_CTX_ROINPUT = 1 << 11
} GtkMozEmbedContext;
typedef enum
{
GTK_MOZ_EMBED_DIALOG_BUTTON_OK,
GTK_MOZ_EMBED_DIALOG_BUTTON_CANCEL,
GTK_MOZ_EMBED_DIALOG_BUTTON_YES,
GTK_MOZ_EMBED_DIALOG_BUTTON_NO,
GTK_MOZ_EMBED_DIALOG_BUTTON_SAVE,
GTK_MOZ_EMBED_DIALOG_BUTTON_DONT_SAVE,
GTK_MOZ_EMBED_DIALOG_BUTTON_REVERT,
GTK_MOZ_EMBED_DIALOG_BUTTON_STRING
} GtkMozEmbedDialogButtons;
/* These are straight out of nsIWebProgressListener.h */
typedef enum
{
GTK_MOZ_EMBED_FLAG_START = 1,
GTK_MOZ_EMBED_FLAG_REDIRECTING = 2,
GTK_MOZ_EMBED_FLAG_TRANSFERRING = 4,
GTK_MOZ_EMBED_FLAG_NEGOTIATING = 8,
GTK_MOZ_EMBED_FLAG_STOP = 16,
GTK_MOZ_EMBED_FLAG_IS_REQUEST = 65536,
GTK_MOZ_EMBED_FLAG_IS_DOCUMENT = 131072,
GTK_MOZ_EMBED_FLAG_IS_NETWORK = 262144,
GTK_MOZ_EMBED_FLAG_IS_WINDOW = 524288,
GTK_MOZ_EMBED_FLAG_RESTORING = 16777216
} GtkMozEmbedProgressFlags;
/* These are from various networking headers */
typedef enum
{
/* NS_ERROR_UNKNOWN_HOST */
GTK_MOZ_EMBED_STATUS_FAILED_DNS = 2152398878U,
/* NS_ERROR_CONNECTION_REFUSED */
GTK_MOZ_EMBED_STATUS_FAILED_CONNECT = 2152398861U,
/* NS_ERROR_NET_TIMEOUT */
GTK_MOZ_EMBED_STATUS_FAILED_TIMEOUT = 2152398862U,
/* NS_BINDING_ABORTED */
GTK_MOZ_EMBED_STATUS_FAILED_USERCANCELED = 2152398850U,
/* NS_ERROR_PROXY_CONNECTION_REFUSED */
GTK_MOZ_EMBED_STATUS_PROXY_FAILED = 2152398920U
} GtkMozEmbedStatusFlags;
/* These used to be straight out of nsIWebNavigation.h until the API
changed. Now there's a mapping table that maps these values to the
internal values. */
typedef enum
{
GTK_MOZ_EMBED_FLAG_RELOADNORMAL = 0,
GTK_MOZ_EMBED_FLAG_RELOADBYPASSCACHE = 1,
GTK_MOZ_EMBED_FLAG_RELOADBYPASSPROXY = 2,
GTK_MOZ_EMBED_FLAG_RELOADBYPASSPROXYANDCACHE = 3,
GTK_MOZ_EMBED_FLAG_RELOADCHARSETCHANGE = 4
} GtkMozEmbedReloadFlags;
/* These are straight out of nsIWebBrowserChrome.h */
typedef enum
{
GTK_MOZ_EMBED_FLAG_DEFAULTCHROME = 1U,
GTK_MOZ_EMBED_FLAG_WINDOWBORDERSON = 2U,
GTK_MOZ_EMBED_FLAG_WINDOWCLOSEON = 4U,
GTK_MOZ_EMBED_FLAG_WINDOWRESIZEON = 8U,
GTK_MOZ_EMBED_FLAG_MENUBARON = 16U,
GTK_MOZ_EMBED_FLAG_TOOLBARON = 32U,
GTK_MOZ_EMBED_FLAG_LOCATIONBARON = 64U,
GTK_MOZ_EMBED_FLAG_STATUSBARON = 128U,
GTK_MOZ_EMBED_FLAG_PERSONALTOOLBARON = 256U,
GTK_MOZ_EMBED_FLAG_SCROLLBARSON = 512U,
GTK_MOZ_EMBED_FLAG_TITLEBARON = 1024U,
GTK_MOZ_EMBED_FLAG_EXTRACHROMEON = 2048U,
GTK_MOZ_EMBED_FLAG_ALLCHROME = 4094U,
GTK_MOZ_EMBED_FLAG_WINDOWRAISED = 33554432U,
GTK_MOZ_EMBED_FLAG_WINDOWLOWERED = 67108864U,
GTK_MOZ_EMBED_FLAG_CENTERSCREEN = 134217728U,
GTK_MOZ_EMBED_FLAG_DEPENDENT = 268435456U,
GTK_MOZ_EMBED_FLAG_MODAL = 536870912U,
GTK_MOZ_EMBED_FLAG_OPENASDIALOG = 1073741824U,
GTK_MOZ_EMBED_FLAG_OPENASCHROME = 2147483648U
} GtkMozEmbedChromeFlags;
/* this is a singleton object that you can hook up to to get signals
that are not handed out on a per widget basis. */
#define GTK_TYPE_MOZ_EMBED_SINGLE (gtk_moz_embed_single_get_type())
#define GTK_MOZ_EMBED_SINGLE(obj) GTK_CHECK_CAST((obj), GTK_TYPE_MOZ_EMBED_SINGLE, GtkMozEmbedSingle)
#define GTK_MOZ_EMBED_SINGLE_CLASS(klass) GTK_CHEK_CLASS_CAST((klass), GTK_TYPE_MOZ_EMBED_SINGLE, GtkMozEmbedSingleClass)
#define GTK_IS_MOZ_EMBED_SINGLE(obj) GTK_CHECK_TYPE((obj), GTK_TYPE_MOZ_EMBED_SINGLE)
#define GTK_IS_MOZ_EMBED_SINGLE_CLASS(klass) GTK_CHECK_CLASS_TYPE((klass), GTK_TYPE_MOZ_EMBED)
typedef struct _GtkMozEmbedSingle GtkMozEmbedSingle;
typedef struct _GtkMozEmbedSingleClass GtkMozEmbedSingleClass;
struct _GtkMozEmbedSingle
{
GtkObject object;
void *data;
};
struct _GtkMozEmbedSingleClass
{
GtkObjectClass parent_class;
void (* new_window_orphan) (GtkMozEmbedSingle *embed,
GtkMozEmbed **newEmbed,
guint chromemask);
};
GTKMOZEMBED_API(GtkType, gtk_moz_embed_single_get_type, (void))
GTKMOZEMBED_API(GtkMozEmbedSingle *, gtk_moz_embed_single_get, (void))
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* gtkmozembed_h */

File diff suppressed because it is too large Load Diff

View File

@@ -1,752 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Ramiro Estrugo <ramiro@eazel.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <stdio.h>
#include "gtkmozembed.h"
#include "gtkmozembed_common.h"
#include "gtkmozembedprivate.h"
#include "gtkmozembed_internal.h"
#include "EmbedPrivate.h"
#include "EmbedWindow.h"
#ifdef MOZ_GTKPASSWORD_INTERFACE
#include "EmbedPasswordMgr.h"
#include "nsIPassword.h"
#endif
#include "EmbedGlobalHistory.h"
//#include "EmbedDownloadMgr.h"
// so we can do our get_nsIWebBrowser later...
#include "nsIWebBrowser.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsIPref.h"
#include "nsICookieManager.h"
#include "nsIPermissionManager.h"
#include "nsNetCID.h"
#include "nsICookie.h"
#include "nsIX509Cert.h"
// for strings
#ifdef MOZILLA_INTERNAL_API
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsString.h"
#else
#include "nsStringAPI.h"
#include "nsComponentManagerUtils.h"
#include "nsServiceManagerUtils.h"
#endif
// for plugins
#include "nsIDOMNavigator.h"
#include "nsIDOMPluginArray.h"
#include "nsIDOMPlugin.h"
#include <plugin/nsIPluginHost.h>
#include "nsIDOMMimeType.h"
#include "nsIObserverService.h"
//for security
#include "nsIWebProgressListener.h"
//for cache
#include "nsICacheService.h"
#include "nsICache.h"
#ifdef MOZ_WIDGET_GTK2
#include "gtkmozembedmarshal.h"
#define NEW_TOOLKIT_STRING(x) g_strdup(NS_ConvertUTF16toUTF8(x).get())
#define GET_TOOLKIT_STRING(x) NS_ConvertUTF16toUTF8(x).get()
#define GET_OBJECT_CLASS_TYPE(x) G_OBJECT_CLASS_TYPE(x)
#endif /* MOZ_WIDGET_GTK2 */
#ifdef MOZ_WIDGET_GTK
// so we can get callbacks from the mozarea
#include <gtkmozarea.h>
// so we get the right marshaler for gtk 1.2
#define gtkmozembed_VOID__INT_UINT \
gtk_marshal_NONE__INT_INT
#define gtkmozembed_VOID__STRING_INT_INT \
gtk_marshal_NONE__POINTER_INT_INT
#define gtkmozembed_VOID__STRING_INT_UINT \
gtk_marshal_NONE__POINTER_INT_INT
#define gtkmozembed_VOID__POINTER_INT_POINTER \
gtk_marshal_NONE__POINTER_INT_POINTER
#define gtkmozembed_BOOL__STRING \
gtk_marshal_BOOL__POINTER
#define gtkmozembed_VOID__INT_INT_BOOLEAN \
gtk_marshal_NONE__INT_INT_BOOLEAN
#define G_SIGNAL_TYPE_STATIC_SCOPE 0
#define NEW_TOOLKIT_STRING(x) g_strdup(NS_LossyConvertUTF16toASCII(x).get())
#define GET_TOOLKIT_STRING(x) NS_LossyConvertUTF16toASCII(x).get()
#define GET_OBJECT_CLASS_TYPE(x) (GTK_OBJECT_CLASS(x)->type)
#endif /* MOZ_WIDGET_GTK */
#define UNACCEPTABLE_CRASHY_GLIB_ALLOCATION(newed) PR_BEGIN_MACRO \
/* OOPS this code is using a glib allocation function which \
* will cause the application to crash when it runs out of \
* memory. This is not cool. either g_try methods should be \
* used or malloc, or new (note that gecko /will/ be replacing \
* its operator new such that new will not throw exceptions). \
* XXX please fix me. \
*/ \
if (!newed) { \
} \
PR_END_MACRO
#define ALLOC_NOT_CHECKED(newed) PR_BEGIN_MACRO \
/* This might not crash, but the code probably isn't really \
* designed to handle it, perhaps the code should be fixed? \
*/ \
if (!newed) { \
} \
PR_END_MACRO
// CID used to get the plugin manager
static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID);
// class and instance initialization
static void
gtk_moz_embed_common_class_init(GtkMozEmbedCommonClass *klass);
static void
gtk_moz_embed_common_init(GtkMozEmbedCommon *embed);
static GtkObjectClass *common_parent_class = NULL;
// GtkObject methods
static void
gtk_moz_embed_common_destroy(GtkObject *object);
guint moz_embed_common_signals[COMMON_LAST_SIGNAL] = { 0 };
// GtkObject + class-related functions
GtkType
gtk_moz_embed_common_get_type(void)
{
static GtkType moz_embed_common_type = 0;
if (!moz_embed_common_type)
{
static const GtkTypeInfo moz_embed_common_info =
{
"GtkMozEmbedCommon",
sizeof(GtkMozEmbedCommon),
sizeof(GtkMozEmbedCommonClass),
(GtkClassInitFunc)gtk_moz_embed_common_class_init,
(GtkObjectInitFunc)gtk_moz_embed_common_init,
0,
0,
0
};
moz_embed_common_type = gtk_type_unique(GTK_TYPE_BIN, &moz_embed_common_info);
}
return moz_embed_common_type;
}
static void
gtk_moz_embed_common_class_init(GtkMozEmbedCommonClass *klass)
{
GtkObjectClass *object_class;
object_class = GTK_OBJECT_CLASS(klass);
common_parent_class = (GtkObjectClass *)gtk_type_class(gtk_object_get_type());
object_class->destroy = gtk_moz_embed_common_destroy;
moz_embed_common_signals[COMMON_CERT_ERROR] =
gtk_signal_new("certificate-error",
GTK_RUN_LAST,
GET_OBJECT_CLASS_TYPE(klass),
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass,
certificate_error),
gtkmozembed_BOOL__POINTER_UINT,
G_TYPE_BOOLEAN,
2,
GTK_TYPE_POINTER,
GTK_TYPE_UINT);
moz_embed_common_signals[COMMON_SELECT_LOGIN] =
gtk_signal_new("select-login",
GTK_RUN_LAST,
GET_OBJECT_CLASS_TYPE(klass),
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass,
select_login),
gtk_marshal_INT__POINTER,
G_TYPE_INT,
1,
G_TYPE_POINTER);
moz_embed_common_signals[COMMON_REMEMBER_LOGIN] =
gtk_signal_new("remember-login",
GTK_RUN_LAST,
GET_OBJECT_CLASS_TYPE(klass),
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass,
remember_login),
gtkmozembed_INT__VOID,
G_TYPE_INT, 0);
// set up our signals
moz_embed_common_signals[COMMON_ASK_COOKIE] =
gtk_signal_new("ask-cookie",
GTK_RUN_FIRST,
GET_OBJECT_CLASS_TYPE(klass),
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass, ask_cookie),
gtkmozembed_VOID__POINTER_INT_STRING_STRING_STRING_STRING_STRING_BOOLEAN_INT,
G_TYPE_NONE, 9,
GTK_TYPE_POINTER,
GTK_TYPE_INT,
GTK_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
GTK_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
GTK_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
GTK_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
GTK_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
GTK_TYPE_BOOL,
GTK_TYPE_INT);
/*
moz_embed_common_signals[COMMON_CERT_DIALOG] =
gtk_signal_new("certificate-dialog",
GTK_RUN_LAST,
GET_OBJECT_CLASS_TYPE(klass),
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass,
certificate_dialog),
gtk_marshal_BOOL__POINTER,
G_TYPE_BOOLEAN, 1, GTK_TYPE_POINTER);
moz_embed_common_signals[COMMON_CERT_PASSWD_DIALOG] =
gtk_signal_new("certificate-password-dialog",
GTK_RUN_FIRST,
GET_OBJECT_CLASS_TYPE(klass),
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass,
certificate_password_dialog),
gtkmozembed_VOID__STRING_STRING_POINTER,
G_TYPE_NONE,
3,
GTK_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
GTK_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
GTK_TYPE_POINTER);
moz_embed_common_signals[COMMON_CERT_DETAILS_DIALOG] =
gtk_signal_new("certificate-details",
GTK_RUN_FIRST,
GET_OBJECT_CLASS_TYPE(klass),
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass,
certificate_details),
gtk_marshal_VOID__POINTER,
G_TYPE_NONE,
1,
GTK_TYPE_POINTER);
moz_embed_common_signals[COMMON_HISTORY_ADDED] =
gtk_signal_new("global-history-item-added",
GTK_RUN_FIRST,
GET_OBJECT_CLASS_TYPE(klass),
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass,
history_added),
gtk_marshal_VOID__STRING,
G_TYPE_NONE,
1,
GTK_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
moz_embed_common_signals[COMMON_ON_SUBMIT_SIGNAL] =
gtk_signal_new("on-submit",
GTK_RUN_LAST,
GET_OBJECT_CLASS_TYPE(klass),
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass,
on_submit),
gtkmozembed_INT__VOID,
G_TYPE_INT, 0);
moz_embed_common_signals[COMMON_MODAL_DIALOG] =
gtk_signal_new("modal_dialog",
GTK_RUN_LAST,
GET_OBJECT_CLASS_TYPE(klass),
GTK_SIGNAL_OFFSET(GtkMozEmbedCommonClass,
modal_dialog),
gtkmozembed_INT__STRING_STRING_INT_INT_INT_INT,
G_TYPE_INT,
6,
G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INT, G_TYPE_INT,
G_TYPE_INT, G_TYPE_INT);
*/
#ifdef MOZ_WIDGET_GTK
gtk_object_class_add_signals(object_class, moz_embed_common_signals,
COMMON_LAST_SIGNAL);
#endif /* MOZ_WIDGET_GTK */
}
static void
gtk_moz_embed_common_init(GtkMozEmbedCommon *common)
{
// this is a placeholder for later in case we need to stash data at
// a later data and maintain backwards compatibility.
common->data = nsnull;
EmbedCommon *priv = EmbedCommon::GetInstance();
priv->mCommon = GTK_OBJECT(common);
common->data = priv;
EmbedGlobalHistory::GetInstance();
}
static void
gtk_moz_embed_common_destroy(GtkObject *object)
{
g_return_if_fail(object != NULL);
g_return_if_fail(GTK_IS_MOZ_EMBED_COMMON(object));
GtkMozEmbedCommon *embed = nsnull;
EmbedCommon *commonPrivate = nsnull;
embed = GTK_MOZ_EMBED_COMMON(object);
commonPrivate = (EmbedCommon *)embed->data;
if (commonPrivate) {
delete commonPrivate;
embed->data = NULL;
}
}
GtkWidget *
gtk_moz_embed_common_new(void)
{
GtkWidget *widget = (GtkWidget*) gtk_type_new(gtk_moz_embed_common_get_type());
gtk_widget_set_name(widget, "gtkmozembedcommon");
return (GtkWidget *) widget;
}
gboolean
gtk_moz_embed_common_set_pref(GtkType type, gchar *name, gpointer value)
{
g_return_val_if_fail (name != NULL, FALSE);
nsCOMPtr<nsIPref> pref = do_GetService(NS_PREF_CONTRACTID);
if (pref) {
nsresult rv = NS_ERROR_FAILURE;
switch (type) {
case GTK_TYPE_BOOL:
{
/* I doubt this cast pair is correct */
rv = pref->SetBoolPref(name, !!*(int*)value);
break;
}
case GTK_TYPE_INT:
{
/* I doubt this cast pair is correct */
rv = pref->SetIntPref(name, *(int*)value);
break;
}
case GTK_TYPE_STRING:
{
g_return_val_if_fail (value, FALSE);
rv = pref->SetCharPref(name, (gchar*)value);
break;
}
default:
break;
}
return NS_SUCCEEDED(rv);
}
return FALSE;
}
gboolean
gtk_moz_embed_common_get_pref(GtkType type, gchar *name, gpointer value)
{
g_return_val_if_fail (name != NULL, FALSE);
nsCOMPtr<nsIPref> pref = do_GetService(NS_PREF_CONTRACTID);
nsresult rv = NS_ERROR_FAILURE;
if (pref){
switch (type) {
case GTK_TYPE_BOOL:
{
rv = pref->GetBoolPref(name, (gboolean*)value);
break;
}
case GTK_TYPE_INT:
{
rv = pref->GetIntPref(name, (gint*)value);
break;
}
case GTK_TYPE_STRING:
{
rv = pref->GetCharPref(name, (gchar**)value);
break;
}
default:
break;
}
return NS_SUCCEEDED(rv);
}
return FALSE;
}
gboolean
gtk_moz_embed_common_save_prefs()
{
nsCOMPtr<nsIPrefService> prefService = do_GetService(NS_PREF_CONTRACTID);
g_return_val_if_fail (prefService != nsnull, FALSE);
if (prefService == nsnull)
return FALSE;
nsresult rv = prefService->SavePrefFile (nsnull);
return NS_SUCCEEDED(rv);
}
gint
gtk_moz_embed_common_get_logins(const char* uri, GList **list)
{
gint ret = 0;
#ifdef MOZ_GTKPASSWORD_INTERFACE
EmbedPasswordMgr *passwordManager = EmbedPasswordMgr::GetInstance();
nsCOMPtr<nsISimpleEnumerator> passwordEnumerator;
nsresult result = passwordManager->GetEnumerator(getter_AddRefs(passwordEnumerator));
PRBool enumResult;
for (passwordEnumerator->HasMoreElements(&enumResult) ;
enumResult == PR_TRUE ;
passwordEnumerator->HasMoreElements(&enumResult))
{
nsCOMPtr<nsIPassword> nsPassword;
result = passwordEnumerator->GetNext(getter_AddRefs(nsPassword));
if (NS_FAILED(result)) {
/* this almost certainly leaks logins */
return ret;
}
nsCString host;
nsPassword->GetHost(host);
nsCString nsCURI(uri);
if (uri) {
if (!StringBeginsWith(nsCURI, host)
// && !StringBeginsWith(host, nsCURI)
)
continue;
} else if (!passwordManager->IsEqualToLastHostQuery(host))
continue;
if (list) {
nsString unicodeName;
nsString unicodePassword;
nsPassword->GetUser(unicodeName);
nsPassword->GetPassword(unicodePassword);
GtkMozLogin * login = g_new0(GtkMozLogin, 1);
UNACCEPTABLE_CRASHY_GLIB_ALLOCATION(login);
login->user = ToNewUTF8String(unicodeName);
ALLOC_NOT_CHECKED(login->user);
login->pass = ToNewUTF8String(unicodePassword);
ALLOC_NOT_CHECKED(login->pass);
login->host = NS_strdup(host.get());
ALLOC_NOT_CHECKED(login->host);
login->index = ret;
*list = g_list_append(*list, login);
}
ret++;
}
#endif
return ret;
}
gboolean
gtk_moz_embed_common_remove_passwords(const gchar *host, const gchar *user, gint index)
{
#ifdef MOZ_GTKPASSWORD_INTERFACE
EmbedPasswordMgr *passwordManager = EmbedPasswordMgr::GetInstance();
if (index >= 0) {
passwordManager->RemovePasswordsByIndex(index);
} else {
passwordManager->RemovePasswords(host, user);
}
#endif
return TRUE;
}
gint
gtk_moz_embed_common_get_history_list(GtkMozHistoryItem **GtkHI)
{
gint count = 0;
EmbedGlobalHistory *history = EmbedGlobalHistory::GetInstance();
history->GetContentList(GtkHI, &count);
return count;
}
gint
gtk_moz_embed_common_remove_history(gchar *url, gint time) {
nsresult rv;
// The global history service
nsCOMPtr<nsIGlobalHistory2> globalHistory(do_GetService("@mozilla.org/browser/global-history;2"));
if (!globalHistory) return NS_ERROR_NULL_POINTER;
// The browser history interface
nsCOMPtr<nsIObserver> myHistory = do_QueryInterface(globalHistory, &rv);
if (!myHistory) return NS_ERROR_NULL_POINTER ;
if (!url)
myHistory->Observe(nsnull, "RemoveEntries", nsnull);
else {
EmbedGlobalHistory *history = EmbedGlobalHistory::GetInstance();
PRUnichar *uniurl = ToNewUnicode(NS_ConvertUTF8toUTF16(url));
rv = history->RemoveEntries(uniurl, time);
NS_Free(uniurl);
}
return 1;
}
GSList*
gtk_moz_embed_common_get_cookie_list(void)
{
GSList *cookies = NULL;
nsresult result;
nsCOMPtr<nsICookieManager> cookieManager =
do_GetService(NS_COOKIEMANAGER_CONTRACTID);
nsCOMPtr<nsISimpleEnumerator> cookieEnumerator;
result = cookieManager->GetEnumerator(getter_AddRefs(cookieEnumerator));
g_return_val_if_fail(NS_SUCCEEDED(result), NULL);
PRBool enumResult;
for (cookieEnumerator->HasMoreElements(&enumResult);
enumResult == PR_TRUE;
cookieEnumerator->HasMoreElements(&enumResult))
{
GtkMozCookieList *c;
nsCOMPtr<nsICookie> nsCookie;
result = cookieEnumerator->GetNext(getter_AddRefs(nsCookie));
g_return_val_if_fail(NS_SUCCEEDED(result), NULL);
c = g_new0(GtkMozCookieList, 1);
UNACCEPTABLE_CRASHY_GLIB_ALLOCATION(c);
nsCAutoString transfer;
nsCookie->GetHost(transfer);
c->domain = g_strdup(transfer.get());
nsCookie->GetName(transfer);
c->name = g_strdup(transfer.get());
nsCookie->GetValue(transfer);
c->value = g_strdup(transfer.get());
nsCookie->GetPath(transfer);
/* this almost certainly leaks g_strconcat */
if (strchr(c->domain,'.'))
c->path = g_strdup(g_strconcat("http://*",c->domain,"/",NULL));
else
c->path = g_strdup(g_strconcat("http://",c->domain,"/",NULL));
cookies = g_slist_prepend(cookies, c);
}
cookies = g_slist_reverse(cookies);
return cookies;
}
gint
gtk_moz_embed_common_delete_all_cookies(GSList *deletedCookies)
{
nsCOMPtr<nsIPermissionManager> permissionManager =
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
if (!permissionManager)
return 1;
permissionManager->RemoveAll();
if (!deletedCookies)
return 1;
nsCOMPtr<nsICookieManager> cookieManager =
do_GetService(NS_COOKIEMANAGER_CONTRACTID);
if (!cookieManager)
return 1;
cookieManager->RemoveAll();
g_slist_free(deletedCookies);
return 0;//False in GWebStatus means OK, as opposed to gboolean in C
}
unsigned char *
gtk_moz_embed_common_nsx509_to_raw(void *nsIX509Ptr, guint *len)
{
if (!nsIX509Ptr)
return NULL;
unsigned char *data;
((nsIX509Cert*)nsIX509Ptr)->GetRawDER(len, (PRUint8 **)&data);
if (!data)
return NULL;
return data;
}
gint
gtk_moz_embed_common_get_plugins_list(GList **pluginArray)
{
nsresult rv;
nsCOMPtr<nsIPluginManager> pluginMan =
do_GetService(kPluginManagerCID, &rv);
if (NS_FAILED(rv)) {
g_print("Could not get the plugin manager\n");
return -1;
}
pluginMan->ReloadPlugins(PR_TRUE); //FIXME XXX MEMLEAK
nsCOMPtr<nsIPluginHost> pluginHost =
do_GetService(kPluginManagerCID, &rv);
if (NS_FAILED(rv))
return -1;
PRUint32 aLength;
pluginHost->GetPluginCount(&aLength);
if (!pluginArray)
return (gint)aLength;
nsIDOMPlugin **aItems = nsnull;
aItems = new nsIDOMPlugin*[aLength];
if (!aItems)
return -1; //NO MEMORY
rv = pluginHost->GetPlugins(aLength, aItems);
if (NS_FAILED(rv)) {
delete [] aItems;
return -1;
}
nsString string;
for (int plugin_index = 0; plugin_index < (gint) aLength; plugin_index++)
{
GtkMozPlugin *list_item = g_new0(GtkMozPlugin, 1);
UNACCEPTABLE_CRASHY_GLIB_ALLOCATION(list_item);
rv = aItems[plugin_index]->GetName(string);
if (!NS_FAILED(rv))
list_item->title = g_strdup(NS_ConvertUTF16toUTF8(string).get());
aItems[plugin_index]->GetFilename(string);
if (!NS_FAILED(rv))
list_item->path = g_strdup(NS_ConvertUTF16toUTF8(string).get());
nsCOMPtr<nsIDOMMimeType> mimeType;
PRUint32 mime_count = 0;
rv = aItems[plugin_index]->GetLength(&mime_count);
if (NS_FAILED(rv))
continue;
nsString single_mime;
string.SetLength(0);
for (int mime_index = 0; mime_index < mime_count; ++mime_index) {
rv = aItems[plugin_index]->Item(mime_index, getter_AddRefs(mimeType));
if (NS_FAILED(rv))
continue;
rv = mimeType->GetDescription(single_mime);
if (!NS_FAILED(rv)) {
string.Append(single_mime);
string.AppendLiteral(";");
}
}
list_item->type = g_strdup(NS_ConvertUTF16toUTF8(string).get());
if (!NS_FAILED(rv))
*pluginArray = g_list_append(*pluginArray, list_item);
}
delete [] aItems;
return (gint)aLength;
}
void
gtk_moz_embed_common_reload_plugins()
{
nsresult rv;
nsCOMPtr<nsIPluginManager> pluginMan =
do_GetService(kPluginManagerCID, &rv);
pluginMan->ReloadPlugins(PR_TRUE); //FIXME XXX MEMLEAK
}
guint
gtk_moz_embed_common_get_security_mode(guint sec_state)
{
GtkMozEmbedSecurityMode sec_mode;
switch (sec_state) {
case nsIWebProgressListener::STATE_IS_INSECURE:
sec_mode = GTK_MOZ_EMBED_NO_SECURITY;
//g_print("GTK_MOZ_EMBED_NO_SECURITY\n");
break;
case nsIWebProgressListener::STATE_IS_BROKEN:
sec_mode = GTK_MOZ_EMBED_NO_SECURITY;
//g_print("GTK_MOZ_EMBED_NO_SECURITY\n");
break;
case nsIWebProgressListener::STATE_IS_SECURE|
nsIWebProgressListener::STATE_SECURE_HIGH:
sec_mode = GTK_MOZ_EMBED_HIGH_SECURITY;
//g_print("GTK_MOZ_EMBED_HIGH_SECURITY");
break;
case nsIWebProgressListener::STATE_IS_SECURE|
nsIWebProgressListener::STATE_SECURE_MED:
sec_mode = GTK_MOZ_EMBED_MEDIUM_SECURITY;
//g_print("GTK_MOZ_EMBED_MEDIUM_SECURITY\n");
break;
case nsIWebProgressListener::STATE_IS_SECURE|
nsIWebProgressListener::STATE_SECURE_LOW:
sec_mode = GTK_MOZ_EMBED_LOW_SECURITY;
//g_print("GTK_MOZ_EMBED_LOW_SECURITY\n");
break;
default:
sec_mode = GTK_MOZ_EMBED_UNKNOWN_SECURITY;
//g_print("GTK_MOZ_EMBED_UNKNOWN_SECURITY\n");
break;
}
return sec_mode;
}
gint
gtk_moz_embed_common_clear_cache(void)
{
nsCacheStoragePolicy storagePolicy;
nsCOMPtr<nsICacheService> cacheService = do_GetService(NS_CACHESERVICE_CONTRACTID);
if (cacheService)
{
//clean disk cache and memory cache
storagePolicy = nsICache::STORE_ANYWHERE;
cacheService->EvictEntries(storagePolicy);
return 0;
}
return 1;
}
gboolean
gtk_moz_embed_common_observe(const gchar* service_id,
gpointer object,
const gchar* topic,
gunichar* data)
{
nsresult rv;
if (service_id) {
nsCOMPtr<nsISupports> service = do_GetService(service_id, &rv);
NS_ENSURE_SUCCESS(rv, FALSE);
nsCOMPtr<nsIObserver> Observer = do_QueryInterface(service, &rv);
NS_ENSURE_SUCCESS(rv, FALSE);
rv = Observer->Observe((nsISupports*)object, topic, (PRUnichar*)data);
} else {
//This is the correct?
nsCOMPtr<nsIObserverService> obsService =
do_GetService("@mozilla.org/observer-service;1", &rv);
if (obsService)
rv = obsService->NotifyObservers((nsISupports*)object, topic, (PRUnichar*)data);
}
return NS_FAILED(rv) ? FALSE : TRUE;
}

View File

@@ -1,209 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Ramiro Estrugo <ramiro@eazel.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef gtkmozembed_common_h
#define gtkmozembed_common_h
#include "gtkmozembed.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <stddef.h>
#include <gtk/gtk.h>
#ifdef MOZILLA_CLIENT
#include "nscore.h"
#else // MOZILLA_CLIENT
#ifndef nscore_h__
/* Because this header may be included from files which not part of the mozilla
build system, define macros from nscore.h */
#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
#define NS_HIDDEN __attribute__((visibility("hidden")))
#else
#define NS_HIDDEN
#endif
#define NS_FROZENCALL
#define NS_EXPORT_(type) type
#define NS_IMPORT_(type) type
#endif // nscore_h__
#endif // MOZILLA_CLIENT
#ifdef XPCOM_GLUE
#define GTKMOZEMBED_API(type, name, params) \
typedef type (NS_FROZENCALL * name##Type) params; \
extern name##Type name NS_HIDDEN;
#else // XPCOM_GLUE
#ifdef _IMPL_GTKMOZEMBED
#define GTKMOZEMBED_API(type, name, params) NS_EXPORT_(type) name params;
#else
#define GTKMOZEMBED_API(type,name, params) NS_IMPORT_(type) name params;
#endif
#endif // XPCOM_GLUE
#define GTK_TYPE_MOZ_EMBED_COMMON (gtk_moz_embed_common_get_type())
#define GTK_MOZ_EMBED_COMMON(obj) GTK_CHECK_CAST((obj), GTK_TYPE_MOZ_EMBED_COMMON, GtkMozEmbedCommon)
#define GTK_MOZ_EMBED_COMMON_CLASS(klass) GTK_CHECK_CLASS_CAST((klass), GTK_TYPE_MOZ_EMBED_COMMON, GtkMozEmbedCommonClass)
#define GTK_IS_MOZ_EMBED_COMMON(obj) GTK_CHECK_TYPE((obj), GTK_TYPE_MOZ_EMBED_COMMON)
#define GTK_IS_MOZ_EMBED_COMMON_CLASS(klass) GTK_CHECK_CLASS_TYPE((klass), GTK_TYPE_MOZ_EMBED_COMMON)
typedef struct _GtkMozEmbedCommon GtkMozEmbedCommon;
typedef struct _GtkMozEmbedCommonClass GtkMozEmbedCommonClass;
struct _GtkMozEmbedCommon
{
GtkBin object;
void *data;
};
struct _GtkMozEmbedCommonClass
{
GtkBinClass parent_class;
gboolean (* certificate_error) (GObject *, GObject*, guint);
gint (* select_login) (GObject *, GList*);
gint (* remember_login) (GObject *);
void (* ask_cookie) (GObject * , gint , const gchar * , const gchar * , const gchar * ,
const gchar *, const gchar * , gboolean , gint , GObject *);
// void (* ask_cookie) (GObject * , gpointer , gint , const gchar * , const gchar * , const gchar * ,
// const gchar *, const gchar * , gboolean , gint , GObject *);
// gint (* modal_dialog) (GObject *, const gchar *, const gchar *, gint, gint, gint, gint);
// gboolean (* certificate_dialog) (GObject * , GObject *);
// void (*certificate_password_dialog) (GObject *, const gchar *, const gchar *, gchar **);
// void (*certificate_details) (GObject *, gpointer );
// gint (*on_submit) (GObject *);
// gint (*select_match) (GObject *, gpointer);
// void (*history_added) (GObject *, const gchar *, GObject*);
};
typedef enum
{
GTK_MOZ_EMBED_CERT_VERIFIED_OK = 0x0000,
GTK_MOZ_EMBED_CERT_UNTRUSTED = 0x0001,
GTK_MOZ_EMBED_CERT_NOT_VERIFIED_UNKNOWN = 0x0002,
GTK_MOZ_EMBED_CERT_EXPIRED = 0x0004,
GTK_MOZ_EMBED_CERT_REVOKED = 0x0008,
GTK_MOZ_EMBED_UNKNOWN_CERT = 0x0010,
GTK_MOZ_EMBED_CERT_ISSUER_UNTRUSTED = 0x0020,
GTK_MOZ_EMBED_CERT_ISSUER_UNKNOWN = 0x0040,
GTK_MOZ_EMBED_CERT_INVALID_CA = 0x0080
} GtkMozEmbedCertificateType;
typedef enum
{
GTK_MOZ_EMBED_LOGIN_REMEMBER_FOR_THIS_SITE,
GTK_MOZ_EMBED_LOGIN_REMEMBER_FOR_THIS_SERVER,
GTK_MOZ_EMBED_LOGIN_NOT_NOW,
GTK_MOZ_EMBED_LOGIN_NEVER_FOR_SITE,
GTK_MOZ_EMBED_LOGIN_NEVER_FOR_SERVER
} GtkMozEmbedLoginType;
/* GTK_MOZ_EMBED_CERT_USAGE_NOT_ALLOWED,
GTK_MOZ_EMBED_CA_CERT,
GTK_MOZ_EMBED_USER_CERT,
GTK_MOZ_EMBED_EMAIL_CERT,
GTK_MOZ_EMBED_SERVER_CERT
*/
/** GtkMozEmbedSecurityMode.
* Enumerates security modes.
*/
typedef enum
{
GTK_MOZ_EMBED_NO_SECURITY = 0,
GTK_MOZ_EMBED_LOW_SECURITY,
GTK_MOZ_EMBED_MEDIUM_SECURITY,
GTK_MOZ_EMBED_HIGH_SECURITY,
GTK_MOZ_EMBED_UNKNOWN_SECURITY
} GtkMozEmbedSecurityMode;
typedef struct _GtkMozCookieList GtkMozCookieList;
struct _GtkMozCookieList
{
gchar *domain; /** < The domain's name */
gchar *name; /** < The cookie's name */
gchar *value; /** < The cookie's value */
gchar *path; /** < The cookie's path */
};
typedef struct _GtkMozEmbedCookie GtkMozEmbedCookie;
struct _GtkMozEmbedCookie
{
gboolean remember_decision;
gboolean accept;
};
/** @struct GtkMozPlugin.
* Defines a Mozilla Plugin.
*/
typedef struct _GtkMozPlugin GtkMozPlugin;
struct _GtkMozPlugin
{
gchar *title; /** < Plugin title */
gchar *path; /** < Plugin path */
gchar *type; /** < Plugin type */
gboolean isDisabled; /** < is plugin enabled */
};
typedef struct _GtkMozLogin GtkMozLogin;
struct _GtkMozLogin
{
const gchar *user; /** < Plugin title */
const gchar *pass; /** < Plugin path */
const gchar *host; /** < Plugin type */
guint index;
};
GTKMOZEMBED_API(GtkType, gtk_moz_embed_common_get_type, (void))
GTKMOZEMBED_API(GtkWidget*, gtk_moz_embed_common_new, (void))
GTKMOZEMBED_API(gboolean, gtk_moz_embed_common_set_pref, (GtkType type, gchar*, gpointer))
GTKMOZEMBED_API(gboolean, gtk_moz_embed_common_get_pref, (GtkType type, gchar*, gpointer))
GTKMOZEMBED_API(gboolean, gtk_moz_embed_common_save_prefs, (void))
GTKMOZEMBED_API(gboolean, gtk_moz_embed_common_login, (GtkWidget *embed, const gchar* username))
GTKMOZEMBED_API(gboolean, gtk_moz_embed_common_remove_passwords, (const gchar *host, const gchar *user, gint index))
GTKMOZEMBED_API(gint, gtk_moz_embed_common_get_logins, (const char* uri, GList **list))
GTKMOZEMBED_API(gint, gtk_moz_embed_common_get_history_list, (GtkMozHistoryItem **GtkHI))
GTKMOZEMBED_API(gint, gtk_moz_embed_common_remove_history, (gchar *url, gint time))
GTKMOZEMBED_API(GSList*, gtk_moz_embed_common_get_cookie_list, (void))
GTKMOZEMBED_API(gint, gtk_moz_embed_common_delete_all_cookies,(GSList *deletedCookies))
GTKMOZEMBED_API(unsigned char*, gtk_moz_embed_common_nsx509_to_raw, (void *nsIX509Ptr, guint *len))
GTKMOZEMBED_API(gint, gtk_moz_embed_common_get_plugins_list, (GList **pluginArray))
GTKMOZEMBED_API(void, gtk_moz_embed_common_reload_plugins, (void))
GTKMOZEMBED_API(guint, gtk_moz_embed_common_get_security_mode, (guint sec_state))
GTKMOZEMBED_API(gint, gtk_moz_embed_common_clear_cache, (void))
GTKMOZEMBED_API(gboolean, gtk_moz_embed_common_observe, (const gchar*, gpointer, const gchar*, gunichar*))
/*typedef struct _GtkMozEmbedCertContext GtkMozEmbedCertContext;
struct _GtkMozEmbedCertContext
{
GObject * cert;
guint message;
GtkWidget *parent;
};*/
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* gtkmozembed_common_h */

View File

@@ -1,313 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Ramiro Estrugo <ramiro@eazel.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <stdio.h>
#include "gtkmozembed.h"
#include "gtkmozembed_download.h"
#include "gtkmozembedprivate.h"
#include "gtkmozembed_internal.h"
#include "EmbedPrivate.h"
#include "EmbedWindow.h"
#include "EmbedDownloadMgr.h"
// so we can do our get_nsIWebBrowser later...
#include "nsIWebBrowser.h"
// for strings
#ifdef MOZILLA_INTERNAL_API
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#else
#include "nsStringAPI.h"
#endif
#ifdef MOZ_WIDGET_GTK2
#include "gtkmozembedmarshal.h"
#define NEW_TOOLKIT_STRING(x) g_strdup(NS_ConvertUTF16toUTF8(x).get())
#define GET_TOOLKIT_STRING(x) NS_ConvertUTF16toUTF8(x).get()
#define GET_OBJECT_CLASS_TYPE(x) G_OBJECT_CLASS_TYPE(x)
#endif /* MOZ_WIDGET_GTK2 */
#ifdef MOZ_WIDGET_GTK
// so we can get callbacks from the mozarea
#include <gtkmozarea.h>
// so we get the right marshaler for gtk 1.2
#define gtkmozembed_VOID__INT_UINT \
gtk_marshal_NONE__INT_INT
#define gtkmozembed_VOID__STRING_INT_INT \
gtk_marshal_NONE__POINTER_INT_INT
#define gtkmozembed_VOID__STRING_INT_UINT \
gtk_marshal_NONE__POINTER_INT_INT
#define gtkmozembed_VOID__POINTER_INT_POINTER \
gtk_marshal_NONE__POINTER_INT_POINTER
#define gtkmozembed_BOOL__STRING \
gtk_marshal_BOOL__POINTER
#define gtkmozembed_VOID__INT_INT_BOOLEAN \
gtk_marshal_NONE__INT_INT_BOOLEAN
#define G_SIGNAL_TYPE_STATIC_SCOPE 0
#define NEW_TOOLKIT_STRING(x) g_strdup(NS_LossyConvertUTF16toASCII(x).get())
#define GET_TOOLKIT_STRING(x) NS_LossyConvertUTF16toASCII(x).get()
#define GET_OBJECT_CLASS_TYPE(x) (GTK_OBJECT_CLASS(x)->type)
#endif /* MOZ_WIDGET_GTK */
static void gtk_moz_embed_download_set_latest_object(GtkObject *o);
static GtkObject *latest_download_object = nsnull;
// class and instance initialization
guint moz_embed_download_signals[DOWNLOAD_LAST_SIGNAL] = { 0 };
static void gtk_moz_embed_download_class_init(GtkMozEmbedDownloadClass *klass);
static void gtk_moz_embed_download_init(GtkMozEmbedDownload *embed);
static void gtk_moz_embed_download_destroy(GtkObject *object);
GtkObject * gtk_moz_embed_download_new(void);
// GtkObject + class-related functions
GtkType
gtk_moz_embed_download_get_type(void)
{
static GtkType moz_embed_download_type = 0;
if (!moz_embed_download_type)
{
static const GtkTypeInfo moz_embed_download_info =
{
"GtkMozEmbedDownload",
sizeof(GtkMozEmbedDownload),
sizeof(GtkMozEmbedDownloadClass),
(GtkClassInitFunc)gtk_moz_embed_download_class_init,
(GtkObjectInitFunc)gtk_moz_embed_download_init,
0,
0,
0
};
moz_embed_download_type = gtk_type_unique(GTK_TYPE_OBJECT, &moz_embed_download_info);
}
return moz_embed_download_type;
}
static void
gtk_moz_embed_download_class_init(GtkMozEmbedDownloadClass *klass)
{
GtkObjectClass *object_class;
object_class = GTK_OBJECT_CLASS(klass);
object_class->destroy = gtk_moz_embed_download_destroy;
// set up our signals
moz_embed_download_signals[DOWNLOAD_STARTED_SIGNAL] =
gtk_signal_new("started",
GTK_RUN_FIRST,
GET_OBJECT_CLASS_TYPE(klass),
GTK_SIGNAL_OFFSET(GtkMozEmbedDownloadClass, started),
gtk_marshal_NONE__POINTER,
GTK_TYPE_NONE,
1,
G_TYPE_POINTER);
moz_embed_download_signals[DOWNLOAD_COMPLETED_SIGNAL] =
gtk_signal_new("completed",
GTK_RUN_FIRST,
GET_OBJECT_CLASS_TYPE(klass),
GTK_SIGNAL_OFFSET(GtkMozEmbedDownloadClass, completed),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
moz_embed_download_signals[DOWNLOAD_FAILED_SIGNAL] =
gtk_signal_new("error",
GTK_RUN_FIRST,
GET_OBJECT_CLASS_TYPE(klass),
GTK_SIGNAL_OFFSET(GtkMozEmbedDownloadClass, error),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
moz_embed_download_signals[DOWNLOAD_DESTROYED_SIGNAL] =
gtk_signal_new("aborted",
GTK_RUN_FIRST,
GET_OBJECT_CLASS_TYPE(klass),
GTK_SIGNAL_OFFSET(GtkMozEmbedDownloadClass, aborted),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
moz_embed_download_signals[DOWNLOAD_PROGRESS_SIGNAL] =
gtk_signal_new("progress",
GTK_RUN_FIRST,
GET_OBJECT_CLASS_TYPE(klass),
GTK_SIGNAL_OFFSET(GtkMozEmbedDownloadClass, progress),
gtkmozembed_VOID__ULONG_ULONG_ULONG,
GTK_TYPE_NONE,
3,
G_TYPE_ULONG,
G_TYPE_ULONG,
G_TYPE_ULONG);
#ifdef MOZ_WIDGET_GTK
gtk_object_class_add_signals(object_class, moz_embed_download_signals,
DOWNLOAD_LAST_SIGNAL);
#endif /* MOZ_WIDGET_GTK */
}
static void
gtk_moz_embed_download_init(GtkMozEmbedDownload *download)
{
// this is a placeholder for later in case we need to stash data at
// a later data and maintain backwards compatibility.
download->data = nsnull;
EmbedDownload *priv = new EmbedDownload();
download->data = priv;
}
static void
gtk_moz_embed_download_destroy(GtkObject *object)
{
g_return_if_fail(object != NULL);
g_return_if_fail(GTK_IS_MOZ_EMBED_DOWNLOAD(object));
GtkMozEmbedDownload *embed;
EmbedDownload *downloadPrivate;
embed = GTK_MOZ_EMBED_DOWNLOAD(object);
downloadPrivate = (EmbedDownload *)embed->data;
if (downloadPrivate) {
delete downloadPrivate;
embed->data = NULL;
}
}
GtkObject *
gtk_moz_embed_download_new(void)
{
GtkObject *instance = (GtkObject *) gtk_type_new(gtk_moz_embed_download_get_type());
gtk_moz_embed_download_set_latest_object(instance);
return instance;
}
GtkObject *
gtk_moz_embed_download_get_latest_object(void)
{
return latest_download_object;
}
static void
gtk_moz_embed_download_set_latest_object(GtkObject *obj)
{
latest_download_object = obj;
return ;
}
void
gtk_moz_embed_download_do_command(GtkMozEmbedDownload *item, guint command)
{
EmbedDownload *download_priv = (EmbedDownload *) item->data;
if (!download_priv)
return;
if (command == GTK_MOZ_EMBED_DOWNLOAD_CANCEL) {
download_priv->launcher->Cancel(GTK_MOZ_EMBED_STATUS_FAILED_USERCANCELED);
download_priv->launcher->SetWebProgressListener(nsnull);
return;
}
if (command == GTK_MOZ_EMBED_DOWNLOAD_RESUME) {
download_priv->request->Resume();
download_priv->is_paused = FALSE;
return;
}
if (command == GTK_MOZ_EMBED_DOWNLOAD_PAUSE) {
if (download_priv->request) {
download_priv->request->Suspend();
download_priv->is_paused = TRUE;
}
return;
}
if (command == GTK_MOZ_EMBED_DOWNLOAD_RELOAD) {
if (download_priv->gtkMozEmbedParentWidget) {}
}
// FIXME: missing GTK_MOZ_EMBED_DOWNLOAD_STORE and GTK_MOZ_EMBED_DOWNLOAD_RESTORE implementation.
}
gchar*
gtk_moz_embed_download_get_file_name(GtkMozEmbedDownload *item)
{
EmbedDownload *download_priv = (EmbedDownload *) item->data;
if (!download_priv)
return nsnull;
return (gchar *) download_priv->file_name;
}
gchar*
gtk_moz_embed_download_get_url(GtkMozEmbedDownload *item)
{
EmbedDownload *download_priv = (EmbedDownload *) item->data;
if (!download_priv)
return nsnull;
// FIXME : 'server' is storing the wrong value. See EmbedDownloadMgr.cpp l. 189.
return (gchar *) download_priv->server;
}
glong
gtk_moz_embed_download_get_progress(GtkMozEmbedDownload *item)
{
EmbedDownload *download_priv = (EmbedDownload *) item->data;
if (!download_priv)
return -1;
return (glong) download_priv->downloaded_size;
}
glong
gtk_moz_embed_download_get_file_size(GtkMozEmbedDownload *item)
{
EmbedDownload *download_priv = (EmbedDownload *) item->data;
if (!download_priv)
return -1;
return (glong) download_priv->file_size;
}

View File

@@ -1,123 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
* Ramiro Estrugo <ramiro@eazel.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef gtkmozembed_download_h
#define gtkmozembed_download_h
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <stddef.h>
#include <gtk/gtk.h>
#ifdef MOZILLA_CLIENT
#include "nscore.h"
#else // MOZILLA_CLIENT
#ifndef nscore_h__
/* Because this header may be included from files which not part of the mozilla
build system, define macros from nscore.h */
#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
#define NS_HIDDEN __attribute__((visibility("hidden")))
#else
#define NS_HIDDEN
#endif
#define NS_FROZENCALL
#define NS_EXPORT_(type) type
#define NS_IMPORT_(type) type
#endif // nscore_h__
#endif // MOZILLA_CLIENT
#ifdef XPCOM_GLUE
#define GTKMOZEMBED_API(type, name, params) \
typedef type (NS_FROZENCALL * name##Type) params; \
extern name##Type name NS_HIDDEN;
#else // XPCOM_GLUE
#ifdef _IMPL_GTKMOZEMBED
#define GTKMOZEMBED_API(type, name, params) NS_EXPORT_(type) name params;
#else
#define GTKMOZEMBED_API(type,name, params) NS_IMPORT_(type) name params;
#endif
#endif // XPCOM_GLUE
#define GTK_TYPE_MOZ_EMBED_DOWNLOAD (gtk_moz_embed_download_get_type())
#define GTK_MOZ_EMBED_DOWNLOAD(obj) GTK_CHECK_CAST((obj), GTK_TYPE_MOZ_EMBED_DOWNLOAD, GtkMozEmbedDownload)
#define GTK_MOZ_EMBED_DOWNLOAD_CLASS(klass) GTK_CHECK_CLASS_CAST((klass), GTK_TYPE_MOZ_EMBED_DOWNLOAD, GtkMozEmbedDownloadClass)
#define GTK_IS_MOZ_EMBED_DOWNLOAD(obj) GTK_CHECK_TYPE((obj), GTK_TYPE_MOZ_EMBED_DOWNLOAD)
#define GTK_IS_MOZ_EMBED_DOWNLOAD_CLASS(klass) GTK_CHECK_CLASS_TYPE((klass), GTK_TYPE_MOZ_EMBED_DOWNLOAD)
typedef struct _GtkMozEmbedDownload GtkMozEmbedDownload;
typedef struct _GtkMozEmbedDownloadClass GtkMozEmbedDownloadClass;
struct _GtkMozEmbedDownload
{
GtkObject object;
void *data;
};
struct _GtkMozEmbedDownloadClass
{
GtkObjectClass parent_class;
void (*started) (GtkMozEmbedDownload* item, gchar **file_name_with_path);
void (*completed) (GtkMozEmbedDownload* item);
void (*error) (GtkMozEmbedDownload* item);
void (*aborted) (GtkMozEmbedDownload* item);
void (*progress) (GtkMozEmbedDownload* item, gulong downloaded_bytes, gulong total_bytes, gdouble kbps);
};
typedef enum
{
GTK_MOZ_EMBED_DOWNLOAD_RESUME,
GTK_MOZ_EMBED_DOWNLOAD_CANCEL,
GTK_MOZ_EMBED_DOWNLOAD_PAUSE,
GTK_MOZ_EMBED_DOWNLOAD_RELOAD,
GTK_MOZ_EMBED_DOWNLOAD_STORE,
GTK_MOZ_EMBED_DOWNLOAD_RESTORE
} GtkMozEmbedDownloadActions;
GTKMOZEMBED_API(GtkType, gtk_moz_embed_download_get_type, (void))
GTKMOZEMBED_API(GtkObject *, gtk_moz_embed_download_new, (void))
GTKMOZEMBED_API(GtkObject *, gtk_moz_embed_download_get_latest_object, (void))
GTKMOZEMBED_API(void, gtk_moz_embed_download_do_command, (GtkMozEmbedDownload *item, guint command))
GTKMOZEMBED_API(void, gtk_moz_embed_download_do_command, (GtkMozEmbedDownload *item, guint command))
GTKMOZEMBED_API(void, gtk_moz_embed_download_do_command, (GtkMozEmbedDownload *item, guint command))
GTKMOZEMBED_API(void, gtk_moz_embed_download_do_command, (GtkMozEmbedDownload *item, guint command))
GTKMOZEMBED_API(gchar*, gtk_moz_embed_download_get_file_name, (GtkMozEmbedDownload *item))
GTKMOZEMBED_API(gchar*, gtk_moz_embed_download_get_url, (GtkMozEmbedDownload *item))
GTKMOZEMBED_API(glong, gtk_moz_embed_download_get_progress, (GtkMozEmbedDownload *item))
GTKMOZEMBED_API(glong, gtk_moz_embed_download_get_file_size, (GtkMozEmbedDownload *item))
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* gtkmozembed_download_h */

View File

@@ -1,135 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla embedding.
*
* The Initial Developer of the Original Code is
* Benjamin Smedberg <benjamin@smedbergs.us>.
*
* Portions created by the Initial Developer are Copyright (C) 2005
* the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// This file is an implementation file, meant to be #included in a
// single C++ file of an embedding application. It is called after
// XPCOMGlueStartup to glue the gtkmozembed functions.
#include "gtkmozembed.h"
#include "gtkmozembed_internal.h"
#ifdef MOZ_WIDGET_GTK2
#include "gtkmozembed_common.h"
#include "gtkmozembed_download.h"
#endif
#include "nsXPCOMGlue.h"
#ifndef XPCOM_GLUE
#error This file only makes sense when XPCOM_GLUE is defined.
#endif
#ifdef MOZ_WIDGET_GTK2
#define GTKMOZEMBED2_FUNCTIONS \
GTKF(gtk_moz_embed_download_get_type) \
GTKF(gtk_moz_embed_download_new) \
GTKF(gtk_moz_embed_common_get_type) \
GTKF(gtk_moz_embed_common_new) \
GTKF(gtk_moz_embed_common_set_pref) \
GTKF(gtk_moz_embed_common_get_pref) \
GTKF(gtk_moz_embed_common_save_prefs) \
GTKF(gtk_moz_embed_common_remove_passwords) \
GTKF(gtk_moz_embed_common_get_history_list) \
GTKF(gtk_moz_embed_get_zoom_level) \
GTKF(gtk_moz_embed_set_zoom_level) \
GTKF(gtk_moz_embed_find_text) \
GTKF(gtk_moz_embed_clipboard) \
GTKF(gtk_moz_embed_notify_plugins) \
GTKF(gtk_moz_embed_get_context_info) \
GTKF(gtk_moz_embed_get_selection) \
GTKF(gtk_moz_embed_get_doc_info) \
GTKF(gtk_moz_embed_insert_text) \
GTKF(gtk_moz_embed_common_nsx509_to_raw) \
GTKF(gtk_moz_embed_common_observe) \
GTKF(gtk_moz_embed_get_shistory_list) \
GTKF(gtk_moz_embed_get_shistory_index) \
GTKF(gtk_moz_embed_shistory_goto_index) \
GTKF(gtk_moz_embed_get_server_cert) \
GTKF(gtk_moz_embed_get_nsIWebBrowser)
#else
#define GTKMOZEMBED2_FUNCTIONS
#endif
#define GTKMOZEMBED_FUNCTIONS \
GTKF(gtk_moz_embed_get_type) \
GTKF(gtk_moz_embed_new) \
GTKF(gtk_moz_embed_push_startup) \
GTKF(gtk_moz_embed_pop_startup) \
GTKF(gtk_moz_embed_set_path) \
GTKF(gtk_moz_embed_set_comp_path) \
GTKF(gtk_moz_embed_set_profile_path) \
GTKF(gtk_moz_embed_load_url) \
GTKF(gtk_moz_embed_stop_load) \
GTKF(gtk_moz_embed_can_go_back) \
GTKF(gtk_moz_embed_can_go_forward) \
GTKF(gtk_moz_embed_go_back) \
GTKF(gtk_moz_embed_go_forward) \
GTKF(gtk_moz_embed_render_data) \
GTKF(gtk_moz_embed_open_stream) \
GTKF(gtk_moz_embed_append_data) \
GTKF(gtk_moz_embed_close_stream) \
GTKF(gtk_moz_embed_get_link_message) \
GTKF(gtk_moz_embed_get_js_status) \
GTKF(gtk_moz_embed_get_title) \
GTKF(gtk_moz_embed_get_location) \
GTKF(gtk_moz_embed_reload) \
GTKF(gtk_moz_embed_set_chrome_mask) \
GTKF(gtk_moz_embed_get_chrome_mask) \
GTKF(gtk_moz_embed_single_get_type) \
GTKF(gtk_moz_embed_single_get) \
GTKMOZEMBED2_FUNCTIONS
#define GTKF(fname) fname##Type fname;
GTKMOZEMBED_FUNCTIONS
#undef GTKF
#define GTKF(fname) { #fname, (NSFuncPtr*) &fname },
static const nsDynamicFunctionLoad GtkSymbols[] = {
GTKMOZEMBED_FUNCTIONS
{ nsnull, nsnull }
};
#undef GTKF
static nsresult
GTKEmbedGlueStartup()
{
return XPCOMGlueLoadXULFunctions(GtkSymbols);
}

View File

@@ -1,76 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef gtkmozembed_internal_h
#define gtkmozembed_internal_h
#include "nsIWebBrowser.h"
#include "nsXPCOM.h"
#include <stdlib.h>
struct nsModuleComponentInfo;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
GTKMOZEMBED_API(void,
gtk_moz_embed_get_nsIWebBrowser, (GtkMozEmbed *embed,
nsIWebBrowser **retval))
GTKMOZEMBED_API(PRUnichar*,
gtk_moz_embed_get_title_unichar, (GtkMozEmbed *embed))
GTKMOZEMBED_API(PRUnichar*,
gtk_moz_embed_get_js_status_unichar, (GtkMozEmbed *embed))
GTKMOZEMBED_API(PRUnichar*,
gtk_moz_embed_get_link_message_unichar, (GtkMozEmbed *embed))
GTKMOZEMBED_API(void,
gtk_moz_embed_set_directory_service_provider, (nsIDirectoryServiceProvider *appFileLocProvider))
GTKMOZEMBED_API(void,
gtk_moz_embed_set_app_components, (const nsModuleComponentInfo *aComps,
int aNumComps))
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* gtkmozembed_internal_h */

View File

@@ -1,31 +0,0 @@
BOOL:STRING
BOOL:STRING,STRING
BOOL:STRING,STRING,POINTER
BOOL:STRING,STRING,POINTER,INT
BOOL:STRING,STRING,POINTER,POINTER,STRING,POINTER
BOOL:STRING,STRING,POINTER,STRING,POINTER
BOOL:STRING,STRING,STRING,POINTER
INT:STRING,INT,INT,INT,INT,INT
INT:STRING,STRING,INT,INT,INT,INT
INT:STRING,STRING,UINT,STRING,STRING,STRING,STRING,POINTER
INT:VOID
STRING:STRING,STRING
VOID:BOOL
VOID:INT,INT,BOOL
VOID:INT,STRING
VOID:INT,STRING,STRING
VOID:INT,UINT
VOID:POINTER,INT,POINTER
VOID:POINTER,INT,STRING,STRING,STRING,STRING,STRING,BOOLEAN,INT
VOID:POINTER,STRING,BOOL,BOOL
VOID:STRING,INT,INT
VOID:STRING,INT,UINT
VOID:STRING,STRING
VOID:STRING,STRING,POINTER
VOID:STRING,STRING,STRING,ULONG,INT
VOID:STRING,STRING,STRING,POINTER
VOID:UINT,INT,INT,STRING,STRING,STRING,STRING
VOID:ULONG,ULONG,ULONG
BOOL:POINTER,UINT
VOID:POINTER
BOOL:STRING,STRING,POINTER

View File

@@ -1,147 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard. All Rights Reserved.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef gtkmozembedprivate_h
#define gtkmozembedprivate_h
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include "gtkmozembed.h"
/* signals */
enum {
LINK_MESSAGE,
JS_STATUS,
LOCATION,
TITLE,
PROGRESS,
PROGRESS_ALL,
NET_STATE,
NET_STATE_ALL,
NET_START,
NET_STOP,
NEW_WINDOW,
VISIBILITY,
DESTROY_BROWSER,
OPEN_URI,
SIZE_TO,
DOM_KEY_DOWN,
DOM_KEY_PRESS,
DOM_KEY_UP,
DOM_MOUSE_DOWN,
DOM_MOUSE_UP,
DOM_MOUSE_CLICK,
DOM_MOUSE_DBL_CLICK,
DOM_MOUSE_OVER,
DOM_MOUSE_OUT,
SECURITY_CHANGE,
STATUS_CHANGE,
DOM_ACTIVATE,
DOM_FOCUS_IN,
DOM_FOCUS_OUT,
ALERT,
ALERT_CHECK,
CONFIRM,
CONFIRM_CHECK,
CONFIRM_EX,
PROMPT,
PROMPT_AUTH,
SELECT,
DOWNLOAD_REQUEST,
DOM_MOUSE_SCROLL,
DOM_MOUSE_LONG_PRESS,
DOM_FOCUS,
DOM_BLUR,
UPLOAD_DIALOG,
ICON_CHANGED,
MAILTO,
NETWORK_ERROR,
RSS_REQUEST,
EMBED_LAST_SIGNAL
};
// DOM_MOUSE_MOVE,
extern guint moz_embed_signals[EMBED_LAST_SIGNAL];
#if 0
enum {
COMMON_CERT_DIALOG,
COMMON_CERT_PASSWD_DIALOG,
COMMON_CERT_DETAILS_DIALOG,
COMMON_HISTORY_ADDED,
COMMON_ON_SUBMIT_SIGNAL,
COMMON_SELECT_MATCH_SIGNAL,
COMMON_MODAL_DIALOG,
COMMON_LAST_SIGNAL
};
#endif
enum {
COMMON_CERT_ERROR,
COMMON_SELECT_LOGIN,
COMMON_REMEMBER_LOGIN,
COMMON_ASK_COOKIE,
COMMON_LAST_SIGNAL
};
extern guint moz_embed_common_signals[COMMON_LAST_SIGNAL];
enum
{
DOWNLOAD_STARTED_SIGNAL,
DOWNLOAD_STOPPED_SIGNAL,
DOWNLOAD_COMPLETED_SIGNAL,
DOWNLOAD_FAILED_SIGNAL,
DOWNLOAD_DESTROYED_SIGNAL,
DOWNLOAD_PROGRESS_SIGNAL,
DOWNLOAD_LAST_SIGNAL
};
extern guint moz_embed_download_signals[DOWNLOAD_LAST_SIGNAL];
extern void gtk_moz_embed_single_create_window(GtkMozEmbed **aNewEmbed,
guint aChromeFlags);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* gtkmozembedprivate_h */

View File

@@ -1,79 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications, Inc.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
[scriptable, uuid(CF39C2B0-1E4B-11d5-A549-0010A401EB10)]
/**
* An optional interface for clients wishing to access a
* password object
*
* @status FROZEN
*/
interface nsIPassword : nsISupports {
/**
* the name of the host corresponding to the login being saved
*
* The form of the host depends on how the nsIPassword object was created
*
* - if it was created as a result of submitting a form to a site, then the
* host is the url of the site, as obtained from a call to GetSpec
*
* - if it was created as a result of another app (e.g., mailnews) calling a
* prompt routine such at PromptUsernameAndPassword, then the host is whatever
* arbitrary string the app decided to pass in.
*
* Whatever form it is in, it will be used by the password manager to uniquely
* identify the login realm, so that "newsserver:119" is not the same thing as
* "newsserver".
*/
readonly attribute AUTF8String host;
/**
* the user name portion of the login
*/
readonly attribute AString user;
/**
* the password portion of the login
*/
readonly attribute AString password;
};

View File

@@ -1,57 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Google Inc.
* Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@meer.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsIPassword.idl"
/**
* This interface is supported by password manager entries to expose the
* fieldnames passed to nsIPasswordManagerInternal's addUserFull method.
*/
[scriptable, uuid(2cc35c67-978f-42a9-a958-16e97ad2f4c8)]
interface nsIPasswordInternal : nsIPassword
{
/**
* The name of the field that contained the username.
*/
readonly attribute AString userFieldName;
/**
* The name of the field that contained the password.
*/
readonly attribute AString passwordFieldName;
};

View File

@@ -0,0 +1,39 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Communicator client code,
# released March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
# Contributors:
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
DEPTH = ..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,30 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Communicator client code,
# released March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
# Contributors:
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
DEPTH=..
DIRS= public res src
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,33 @@
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:NC="http://home.netscape.com/NC-rdf#">
<RDF:Bag ID="NC:SoftwareUpdateRoot">
<RDF:li>
<RDF:Bag ID="NC:NewSoftwareToday" NC:title="New Software">
<RDF:li>
<RDF:Description ID="AimUpdate344">
<NC:type resource="http://home.netscape.com/NC-rdf#SoftwarePackage" />
<NC:title>AOL AIM</NC:title>
<NC:description>An Instant Message Client</NC:description>
<NC:version>3.4.1.12</NC:version>
<NC:registryKey>/AOL/AIM/</NC:registryKey>
<NC:url>http://home.netscape.com/index.html</NC:url>
</RDF:Description>
</RDF:li>
<RDF:li>
<RDF:Description ID="PGPPlugin345">
<NC:type resource="http://home.netscape.com/NC-rdf#SoftwarePackage" />
<NC:title>PGP Plugin For Mozilla</NC:title>
<NC:description>A high grade encryption plugin</NC:description>
<NC:version>1.1.2.0</NC:version>
<NC:registryKey>/PGP/ROCKS/</NC:registryKey>
<NC:url>http://home.netscape.com/index.html</NC:url>
</RDF:Description>
</RDF:li>
</RDF:Bag>
</RDF:li>
</RDF:Bag>
</RDF:RDF>

View File

@@ -0,0 +1,57 @@
window {
display: block;
}
tree {
display: table;
background-color: #FFFFFF;
border: none;
border-spacing: 0px;
width: 100%;
}
treecol {
display: table-column;
width: 200px;
}
treeitem {
display: table-row;
}
treehead {
display: table-header-group;
}
treebody {
display: table-row-group;
}
treecell {
display: table-cell;
font-family: Verdana, Sans-Serif;
font-size: 8pt;
}
treecell[selectedcell] {
background-color: yellow;
}
treehead treeitem treecell {
background-color: #c0c0c0;
border: outset 1px;
border-color: white #707070 #707070 white;
padding-left: 4px;
}
treeitem[type="http://home.netscape.com/NC-rdf#SoftwarePackage"] > treecell > titledbutton {
list-style-image: url("resource:/res/rdf/SoftwareUpdatePackage.gif");
}
treeitem[type="http://home.netscape.com/NC-rdf#Folder"] > treecell > titledbutton {
list-style-image: url("resource:/res/rdf/bookmark-folder-closed.gif");
treeitem[type="http://home.netscape.com/NC-rdf#Folder"][open="true"] > treecell > titledbutton {
list-style-image: url("resource:/res/rdf/bookmark-folder-open.gif");
}

View File

@@ -0,0 +1,123 @@
// the rdf service
var RDF = Components.classes['component://netscape/rdf/rdf-service'].getService();
RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
function getAttr(registry,service,attr_name)
{
var attr = registry.GetTarget(service,
RDF.GetResource('http://home.netscape.com/NC-rdf#' + attr_name),
true);
if (attr)
attr = attr.QueryInterface(Components.interfaces.nsIRDFLiteral);
if (attr)
attr = attr.Value;
return attr;
}
function Init()
{
// this is the main rdf file.
var mainRegistry = RDF.GetDataSource('resource://res/rdf/SoftwareUpdates.rdf');
var mainContainer = Components.classes['component://netscape/rdf/container'].createInstance();
mainContainer = mainContainer.QueryInterface(Components.interfaces.nsIRDFContainer);
mainContainer.Init(mainRegistry, RDF.GetResource('NC:SoftwareUpdateDataSources'));
// Now enumerate all of the softwareupdate datasources.
var mainEnumerator = mainContainer.GetElements();
while (mainEnumerator.HasMoreElements())
{
var aDistributor = mainEnumerator.GetNext();
aDistributor = aDistributor.QueryInterface(Components.interfaces.nsIRDFResource);
var distributorContainer = Components.classes['component://netscape/rdf/container'].createInstance();
distributorContainer = distributorContainer.QueryInterface(Components.interfaces.nsIRDFContainer);
var distributorRegistry = RDF.GetDataSource(aDistributor.Value);
var distributorResource = RDF.GetResource('NC:SoftwareUpdateRoot');
distributorContainer.Init(distributorRegistry, distributorResource);
// Now enumerate all of the distributorContainer's packages.
var distributorEnumerator = distributorContainer.GetElements();
while (distributorEnumerator.HasMoreElements())
{
var aPackage = distributorEnumerator.GetNext();
aPackage = aPackage.QueryInterface(Components.interfaces.nsIRDFResource);
// remove any that we do not want.
if (getAttr(distributorRegistry, aPackage, 'title') == "AOL AIM")
{
//distributorContainer.RemoveElement(aPackage, true);
}
}
var tree = document.getElementById('tree');
// Add it to the tree control's composite datasource.
tree.database.AddDataSource(distributorRegistry);
}
// Install all of the stylesheets in the softwareupdate Registry into the
// panel.
// TODO
// XXX hack to force the tree to rebuild
var treebody = document.getElementById('NC:SoftwareUpdateRoot');
treebody.setAttribute('id', 'NC:SoftwareUpdateRoot');
}
function OpenURL(event, node)
{
if (node.getAttribute('type') == "http://home.netscape.com/NC-rdf#SoftwarePackage")
{
url = node.getAttribute('url');
/*window.open(url,'bookmarks');*/
var toolkitCore = XPAppCoresManager.Find("ToolkitCore");
if (!toolkitCore)
{
toolkitCore = new ToolkitCore();
if (toolkitCore)
{
toolkitCore.Init("ToolkitCore");
}
}
if (toolkitCore)
{
toolkitCore.ShowWindow(url,window);
}
dump("OpenURL(" + url + ")\n");
return true;
}
return false;
}
// To get around "window.onload" not working in viewer.
function Boot()
{
var tree = document.getElementById('tree');
if (tree == null) {
setTimeout(Boot, 0);
}
else {
Init();
}
}
setTimeout('Boot()', 0);

View File

@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<?xml-stylesheet href="resource:/res/rdf/sidebar.css" type="text/css"?>
<?xml-stylesheet href="resource:/res/rdf/SoftwareUpdate.css" type="text/css"?>
<window
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<html:script src="SoftwareUpdate.js"/>
<tree id="tree"
flex="100%"
datasources="rdf:softwareupdates"
ondblclick="return OpenURL(event, event.target.parentNode);">
<treecol rdf:resource="http://home.netscape.com/NC-rdf#title" />
<treecol rdf:resource="http://home.netscape.com/NC-rdf#description" />
<treecol rdf:resource="http://home.netscape.com/NC-rdf#version" />
<treehead>
<treeitem>
<treecell>Title</treecell>
<treecell>Description</treecell>
<treecell>Version</treecell>
</treeitem>
</treehead>
<treebody id="NC:SoftwareUpdateRoot" rdf:containment="http://home.netscape.com/NC-rdf#child" />
</tree>
</window>

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

View File

@@ -0,0 +1,7 @@
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:NC="http://home.netscape.com/softwareupdate-schema#">
<RDF:Bag ID="NC:SoftwareUpdateDataSources">
<RDF:li resource="resource:/res/rdf/SoftwareUpdate-Source-1.rdf" />
</RDF:Bag>
</RDF:RDF>

View File

@@ -0,0 +1,6 @@
#
# This is a list of local files which get copied to the mozilla:dist directory
#
nsISoftwareUpdate.h
nsSoftwareUpdateIIDs.h

View File

@@ -0,0 +1,47 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Communicator client code,
# released March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
# Contributors:
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xpinstall
XPIDLSRCS = nsIXPInstallProgress.idl
EXPORTS = \
nsIDOMInstallTriggerGlobal.h \
nsIDOMInstallVersion.h \
nsSoftwareUpdateIIDs.h \
nsISoftwareUpdate.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,113 @@
interface Install
{
/* IID: { 0x18c2f988, 0xb09f, 0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}} */
const int BAD_PACKAGE_NAME = -200;
const int UNEXPECTED_ERROR = -201;
const int ACCESS_DENIED = -202;
const int TOO_MANY_CERTIFICATES = -203; /* Installer file must have 1 certificate */
const int NO_INSTALLER_CERTIFICATE = -204; /* Installer file must have a certificate */
const int NO_CERTIFICATE = -205; /* Extracted file is not signed */
const int NO_MATCHING_CERTIFICATE = -206; /* Extracted file does not match installer certificate */
const int UNKNOWN_JAR_FILE = -207; /* JAR file has not been opened */
const int INVALID_ARGUMENTS = -208; /* Bad arguments to a function */
const int ILLEGAL_RELATIVE_PATH = -209; /* Illegal relative path */
const int USER_CANCELLED = -210; /* User cancelled */
const int INSTALL_NOT_STARTED = -211;
const int SILENT_MODE_DENIED = -212;
const int NO_SUCH_COMPONENT = -213; /* no such component in the registry. */
const int FILE_DOES_NOT_EXIST = -214; /* File cannot be deleted as it does not exist */
const int FILE_READ_ONLY = -215; /* File cannot be deleted as it is read only. */
const int FILE_IS_DIRECTORY = -216; /* File cannot be deleted as it is a directory */
const int NETWORK_FILE_IS_IN_USE = -217; /* File on the network is in-use */
const int APPLE_SINGLE_ERR = -218; /* error in AppleSingle unpacking */
const int INVALID_PATH_ERR = -219; /* GetFolder() did not like the folderID */
const int PATCH_BAD_DIFF = -220; /* error in GDIFF patch */
const int PATCH_BAD_CHECKSUM_TARGET = -221; /* source file doesn't checksum */
const int PATCH_BAD_CHECKSUM_RESULT = -222; /* final patched file fails checksum */
const int UNINSTALL_FAILED = -223; /* error while uninstalling a package */
const int GESTALT_UNKNOWN_ERR = -5550;
const int GESTALT_INVALID_ARGUMENT = -5551;
const int SUCCESS = 0;
const int REBOOT_NEEDED = 999;
/* install types */
const int LIMITED_INSTALL = 0;
const int FULL_INSTALL = 1;
const int NO_STATUS_DLG = 2;
const int NO_FINALIZE_DLG = 4;
// these should not be public...
/* message IDs*/
const int SU_INSTALL_FILE_UNEXPECTED_MSG_ID = 0;
const int SU_DETAILS_REPLACE_FILE_MSG_ID = 1;
const int SU_DETAILS_INSTALL_FILE_MSG_ID = 2;
//////////////////////////
readonly attribute wstring UserPackageName;
readonly attribute wstring RegPackageName;
void Install();
void AbortInstall();
long AddDirectory( in wstring regName,
in wstring version,
in wstring jarSource,
in InstallFolder folder,
in wstring subdir,
in boolean forceMode );
long AddSubcomponent( in wstring regName,
in wstring version,
in wstring jarSource,
in InstallFolder folder,
in wstring targetName,
in boolean forceMode );
long DeleteComponent( in wstring registryName);
long DeleteFile( in InstallFolder folder,
in wstring relativeFileName );
long DiskSpaceAvailable( in InstallFolder folder );
long Execute(in wstring jarSource, in wstring args);
long FinalizeInstall();
long Gestalt (in wstring selector);
InstallFolder GetComponentFolder( in wstring regName,
in wstring subdirectory);
InstallFolder GetFolder(in wstring targetFolder,
in wstring subdirectory);
long GetLastError();
long GetWinProfile(in InstallFolder folder, in wstring file);
long GetWinRegistry();
long Patch( in wstring regName,
in wstring version,
in wstring jarSource,
in InstallFolder folder,
in wstring targetName );
void ResetError();
void SetPackageFolder( in InstallFolder folder );
long StartInstall( in wstring userPackageName,
in wstring packageName,
in wstring version,
in long flags );
long Uninstall( in wstring packageName);
};

View File

@@ -0,0 +1,24 @@
interface InstallTriggerGlobal
{
/* IID: { 0x18c2f987, 0xb09f, 0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}} */
const int MAJOR_DIFF = 4;
const int MINOR_DIFF = 3;
const int REL_DIFF = 2;
const int BLD_DIFF = 1;
const int EQUAL = 0;
boolean UpdateEnabled ();
long StartSoftwareUpdate(in wstring URL);
long ConditionalSoftwareUpdate( in wstring URL,
in wstring regName,
in long diffLevel,
in wstring version,
in long mode);
long CompareVersion( in wstring regName, in wstring version );
};

View File

@@ -0,0 +1,34 @@
interface InstallVersion
{
/* IID: { 0x18c2f986, 0xb09f, 0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}} */
const int EQUAL = 0;
const int BLD_DIFF = 1;
const int BLD_DIFF_MINUS = -1;
const int REL_DIFF = 2;
const int REL_DIFF_MINUS = -2;
const int MINOR_DIFF = 3;
const int MINOR_DIFF_MINUS = -3;
const int MAJOR_DIFF = 4;
const int MAJOR_DIFF_MINUS = -4;
attribute int major;
attribute int minor;
attribute int release;
attribute int build;
void InstallVersion();
void init(in wstring versionString);
/*
void init(in int major, in int minor, in int release, in int build);
*/
wstring toString();
/* int compareTo(in wstring version);
int compareTo(in int major, in int minor, in int release, in int build);
*/
int compareTo(in InstallVersion versionObject);
};

View File

@@ -0,0 +1,36 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Communicator client code,
# released March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
# Contributors:
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
MODULE=xpinstall
DEPTH=..\..
EXPORTS= nsIDOMInstallTriggerGlobal.h \
nsIDOMInstallVersion.h \
nsSoftwareUpdateIIDs.h \
nsISoftwareUpdate.h
XPIDLSRCS = .\nsIXPInstallProgress.idl
include <$(DEPTH)\config\config.mak>
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1 @@
#error

View File

@@ -0,0 +1,96 @@
/* -*- 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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMInstallTriggerGlobal_h__
#define nsIDOMInstallTriggerGlobal_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#define NS_IDOMINSTALLTRIGGERGLOBAL_IID \
{ 0x18c2f987, 0xb09f, 0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}}
class nsIDOMInstallTriggerGlobal : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IDOMINSTALLTRIGGERGLOBAL_IID; return iid; }
enum {
MAJOR_DIFF = 4,
MINOR_DIFF = 3,
REL_DIFF = 2,
BLD_DIFF = 1,
EQUAL = 0
};
NS_IMETHOD UpdateEnabled(PRBool* aReturn)=0;
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn)=0;
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn)=0;
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn)=0;
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn)=0;
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn)=0;
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn)=0;
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn)=0;
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn)=0;
NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn)=0;
NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn)=0;
NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn)=0;
};
#define NS_DECL_IDOMINSTALLTRIGGERGLOBAL \
NS_IMETHOD UpdateEnabled(PRBool* aReturn); \
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn); \
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn); \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn); \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn); \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn); \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn); \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn); \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn); \
NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn); \
NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn); \
NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn); \
#define NS_FORWARD_IDOMINSTALLTRIGGERGLOBAL(_to) \
NS_IMETHOD UpdateEnabled(PRBool* aReturn) { return _to##UpdateEnabled(aReturn); } \
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn) { return _to##StartSoftwareUpdate(aURL, aFlags, aReturn); } \
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn) { return _to##StartSoftwareUpdate(aURL, aReturn); } \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aRegName, aDiffLevel, aVersion, aMode, aReturn); } \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aRegName, aDiffLevel, aVersion, aMode, aReturn); } \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, nsIDOMInstallVersion* aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aMode, aReturn); } \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aMode, aReturn); } \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aReturn); } \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aReturn); } \
NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn) { return _to##CompareVersion(aRegName, aMajor, aMinor, aRelease, aBuild, aReturn); } \
NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn) { return _to##CompareVersion(aRegName, aVersion, aReturn); } \
NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn) { return _to##CompareVersion(aRegName, aVersion, aReturn); } \
extern nsresult NS_InitInstallTriggerGlobalClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptInstallTriggerGlobal(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMInstallTriggerGlobal_h__

View File

@@ -0,0 +1,107 @@
/* -*- 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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMInstallVersion_h__
#define nsIDOMInstallVersion_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMInstallVersion;
#define NS_IDOMINSTALLVERSION_IID \
{ 0x18c2f986, 0xb09f, 0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}}
class nsIDOMInstallVersion : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IDOMINSTALLVERSION_IID; return iid; }
enum {
EQUAL = 0,
BLD_DIFF = 1,
BLD_DIFF_MINUS = -1,
REL_DIFF = 2,
REL_DIFF_MINUS = -2,
MINOR_DIFF = 3,
MINOR_DIFF_MINUS = -3,
MAJOR_DIFF = 4,
MAJOR_DIFF_MINUS = -4
};
NS_IMETHOD GetMajor(PRInt32* aMajor)=0;
NS_IMETHOD SetMajor(PRInt32 aMajor)=0;
NS_IMETHOD GetMinor(PRInt32* aMinor)=0;
NS_IMETHOD SetMinor(PRInt32 aMinor)=0;
NS_IMETHOD GetRelease(PRInt32* aRelease)=0;
NS_IMETHOD SetRelease(PRInt32 aRelease)=0;
NS_IMETHOD GetBuild(PRInt32* aBuild)=0;
NS_IMETHOD SetBuild(PRInt32 aBuild)=0;
NS_IMETHOD Init(const nsString& aVersionString)=0;
NS_IMETHOD ToString(nsString& aReturn)=0;
NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersionObject, PRInt32* aReturn)=0;
NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn)=0;
NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn)=0;
};
#define NS_DECL_IDOMINSTALLVERSION \
NS_IMETHOD GetMajor(PRInt32* aMajor); \
NS_IMETHOD SetMajor(PRInt32 aMajor); \
NS_IMETHOD GetMinor(PRInt32* aMinor); \
NS_IMETHOD SetMinor(PRInt32 aMinor); \
NS_IMETHOD GetRelease(PRInt32* aRelease); \
NS_IMETHOD SetRelease(PRInt32 aRelease); \
NS_IMETHOD GetBuild(PRInt32* aBuild); \
NS_IMETHOD SetBuild(PRInt32 aBuild); \
NS_IMETHOD Init(const nsString& aVersionString); \
NS_IMETHOD ToString(nsString& aReturn); \
NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersionObject, PRInt32* aReturn); \
NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn); \
NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn); \
#define NS_FORWARD_IDOMINSTALLVERSION(_to) \
NS_IMETHOD GetMajor(PRInt32* aMajor) { return _to##GetMajor(aMajor); } \
NS_IMETHOD SetMajor(PRInt32 aMajor) { return _to##SetMajor(aMajor); } \
NS_IMETHOD GetMinor(PRInt32* aMinor) { return _to##GetMinor(aMinor); } \
NS_IMETHOD SetMinor(PRInt32 aMinor) { return _to##SetMinor(aMinor); } \
NS_IMETHOD GetRelease(PRInt32* aRelease) { return _to##GetRelease(aRelease); } \
NS_IMETHOD SetRelease(PRInt32 aRelease) { return _to##SetRelease(aRelease); } \
NS_IMETHOD GetBuild(PRInt32* aBuild) { return _to##GetBuild(aBuild); } \
NS_IMETHOD SetBuild(PRInt32 aBuild) { return _to##SetBuild(aBuild); } \
NS_IMETHOD Init(const nsString& aVersionString) { return _to##Init(aVersionString); } \
NS_IMETHOD ToString(nsString& aReturn) { return _to##ToString(aReturn); } \
NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersionObject, PRInt32* aReturn) { return _to##CompareTo(aVersionObject, aReturn); } \
NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn) { return _to##CompareTo(aString, aReturn); } \
NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn) { return _to##CompareTo(aMajor, aMinor, aRelease, aBuild, aReturn); } \
extern nsresult NS_InitInstallVersionClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptInstallVersion(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMInstallVersion_h__

View File

@@ -0,0 +1,85 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsISoftwareUpdate_h__
#define nsISoftwareUpdate_h__
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsString.h"
#include "nsIXPInstallProgress.h"
#define NS_IXPINSTALLCOMPONENT_PROGID NS_IAPPSHELLCOMPONENT_PROGID "/xpinstall"
#define NS_IXPINSTALLCOMPONENT_CLASSNAME "Mozilla XPInstall Component"
#define NS_ISOFTWAREUPDATE_IID \
{ 0x18c2f992, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}\
}
class nsISoftwareUpdate : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISOFTWAREUPDATE_IID)
NS_IMETHOD InstallJar(const nsString& fromURL,
const nsString& localFile,
long flags) = 0;
NS_IMETHOD RegisterNotifier(nsIXPInstallProgress *notifier) = 0;
NS_IMETHOD InstallPending(void) = 0;
/* FIX: these should be in a private interface */
NS_IMETHOD InstallJarCallBack() = 0;
NS_IMETHOD GetTopLevelNotifier(nsIXPInstallProgress **notifier) = 0;
};
class nsSoftwareUpdateFactory : public nsIFactory
{
public:
nsSoftwareUpdateFactory();
virtual ~nsSoftwareUpdateFactory();
NS_DECL_ISUPPORTS
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
};
#endif // nsISoftwareUpdate_h__

View File

@@ -0,0 +1,30 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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.
*/
#include "nsISupports.idl"
[uuid(eea90d40-b059-11d2-915e-c12b696c9333)]
interface nsIXPInstallProgress : nsISupports
{
void BeforeJavascriptEvaluation();
void AfterJavascriptEvaluation();
void InstallStarted([const] in string UIPackageName);
void ItemScheduled([const] in string message );
void InstallFinalization([const] in string message, in long itemNum, in long totNum );
void InstallAborted();
};

View File

@@ -0,0 +1,93 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsIXPInstallProgressNotifier_h__
#define nsIXPInstallProgressNotifier_h__
class nsIXPInstallProgressNotifier
{
public:
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function name : BeforeJavascriptEvaluation
// Description : This will be called when prior to the install script being evaluate
// Return type : void
// Argument : void
///////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void BeforeJavascriptEvaluation(void) = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function name : AfterJavascriptEvaluation
// Description : This will be called after the install script has being evaluated
// Return type : void
// Argument : void
///////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void AfterJavascriptEvaluation(void) = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function name : InstallStarted
// Description : This will be called when StartInstall has been called
// Return type : void
// Argument : char* UIPackageName - User Package Name
///////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void InstallStarted(const char* UIPackageName) = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function name : ItemScheduled
// Description : This will be called when items are being scheduled
// Return type : Any value returned other than zero, will be treated as an error and the script will be aborted
// Argument : The message that should be displayed to the user
///////////////////////////////////////////////////////////////////////////////////////////////////////
virtual long ItemScheduled( const char* message ) = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function name : InstallFinalization
// Description : This will be called when the installation is in its Finalize stage
// Return type : void
// Argument : char* message - The message that should be displayed to the user
// Argument : long itemNum - This is the current item number
// Argument : long totNum - This is the total number of items
///////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void InstallFinalization( const char* message, long itemNum, long totNum ) = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function name : InstallAborted
// Description : This will be called when the install is aborted
// Return type : void
// Argument : void
///////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void InstallAborted(void) = 0;
};
#endif

View File

@@ -0,0 +1,64 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsSoftwareUpdateIIDs_h___
#define nsSoftwareUpdateIIDs_h___
#define NS_SoftwareUpdate_CID \
{ /* 18c2f989-b09f-11d2-bcde-00805f0e1353 */ \
0x18c2f989, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
}
#define NS_SoftwareUpdateInstall_CID \
{ /* 18c2f98b-b09f-11d2-bcde-00805f0e1353 */ \
0x18c2f98b, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
}
#define NS_SoftwareUpdateInstallTrigger_CID \
{ /* 18c2f98d-b09f-11d2-bcde-00805f0e1353 */ \
0x18c2f98d, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
}
#define NS_SoftwareUpdateInstallVersion_CID \
{ /* 18c2f98f-b09f-11d2-bcde-00805f0e1353 */ \
0x18c2f98f, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
}
#endif /* nsSoftwareUpdateIIDs_h___ */

View File

@@ -0,0 +1,3 @@
progress.xul
progress.css
progress.html

View File

@@ -0,0 +1,34 @@
#!gmake
#
# 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.
DEPTH=../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk
EXPORT_RESOURCE_XPINSTALL = \
$(srcdir)/progress.xul \
$(srcdir)/progress.html \
$(srcdir)/progress.css \
$(NULL)
install::
$(INSTALL) $(EXPORT_RESOURCE_XPINSTALL) $(DIST)/bin/res/xpinstall

View File

@@ -0,0 +1,31 @@
#!nmake
#
# 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.
DEPTH=..\..
IGNORE_MANIFEST=1
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) progress.xul $(DIST)\bin\res\xpinstall
$(MAKE_INSTALL) progress.css $(DIST)\bin\res\xpinstall
$(MAKE_INSTALL) progress.html $(DIST)\bin\res\xpinstall
clobber::
rm -f $(DIST)\res\xpinstall\progress.xul
rm -f $(DIST)\res\xpinstall\progress.css
rm -f $(DIST)\res\xpinstall\progress.html

View File

@@ -0,0 +1,3 @@
TD {
font: 10pt sans-serif;
}

View File

@@ -0,0 +1,16 @@
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<body bgcolor="#C0C0C0" style="overflow:visible; margin: 0px; color-background: rgb(192,192,192);">
<center>
<table BORDER COLS=5 WIDTH="99%" style="color-background:rgb(192,192,192);">
<tr>
<td WIDTH="3%" NOWRAP style="border: 1px inset rgb(192,192,192);">&nbsp</td>
<td WIDTH="3%" NOWRAP style="border: 1px inset rgb(192,192,192);">&nbsp</td>
<td WIDTH="3%" NOWRAP style="border: 1px inset rgb(192,192,192);">&nbsp</td>
<td WIDTH="10%" NOWRAP style="border: 1px inset rgb(192,192,192);">&nbsp</td>
<td WIDTH="81%" NOWRAP style="border: 1px inset rgb(192,192,192);">&nbsp</td>
</tr>
</table>
</center>
</body>
</html>

View File

@@ -0,0 +1,67 @@
<?xml version="1.0"?>
<?xml-stylesheet href="../samples/xul.css" type="text/css"?>
<?xml-stylesheet href="progress.css" type="text/css"?>
<!DOCTYPE window
[
<!ENTITY downloadWindow.title "XPInstall Progress">
<!ENTITY status "Status:">
<!ENTITY cancelButtonTitle "Cancel">
]
>
<window xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="XPInstall Progress"
width="425"
height="225">
<data>
<broadcaster id="data.canceled" type="string" value="false"/>
</data>
<html:script>
function cancelInstall()
{
var cancelData = document.getElementById("data.canceled");
cancelData.setAttribute( "value", "true");
}
</html:script>
<html:center>
<html:table style="width:100%;">
<html:tr>
<html:td align="center">
<html:input id="dialog.uiPackageName" readonly="" style="background-color:lightgray;width:300px;"/>
</html:td>
</html:tr>
<html:tr>
<html:td nowrap="" style="border: 1px rgb(192,192,192);" align="center">
<html:input id="dialog.currentAction" readonly="" style="background-color:lightgray;width:450px;"/>
</html:td>
</html:tr>
<html:tr>
<html:td align="center" width="15%" nowrap="" style="border: 1px rgb(192,192,192);">
<progressmeter id="dialog.progress" mode="undetermined" style="width:300px;height:16px;">
</progressmeter>
</html:td>
</html:tr>
<html:tr>
<html:td align="center" width="3%" nowrap="" style="border: 1px rgb(192,192,192);">
<html:button onclick="cancelInstall()" height="12">
&cancelButtonTitle;
</html:button>
</html:td>
</html:tr>
</html:table>
</html:center>
</window>

View File

@@ -0,0 +1,61 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Communicator client code,
# released March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
# Contributors:
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
DEPTH = ../..
topsrcdir = @top_srcdir@
VPATH = @srcdir@
srcdir = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xpinstall
LIBRARY_NAME = xpinstall
IS_COMPONENT = 1
REQUIRES = dom js netlib raptor xpcom
CPPSRCS = \
nsSoftwareUpdate.cpp \
nsInstall.cpp \
nsInstallDelete.cpp \
nsInstallExecute.cpp \
nsInstallFile.cpp \
nsInstallFolder.cpp \
nsInstallPatch.cpp \
nsInstallUninstall.cpp \
nsInstallTrigger.cpp \
nsInstallResources.cpp \
nsJSInstall.cpp \
nsJSInstallTriggerGlobal.cpp\
nsSoftwareUpdateRun.cpp \
nsSoftwareUpdateStream.cpp \
nsTopProgressNotifier.cpp \
nsLoggingProgressNotifier \
ScheduledTasks.cpp \
nsInstallFileOpItem.cpp \
$(NULL)
INCLUDES += -I$(srcdir)/../public
include $(topsrcdir)/config/rules.mk

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,233 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Douglas Turner <dougt@netscape.com>
*/
#ifndef SU_PAS_H
#define SU_PAS_H
#include <Errors.h>
#include <Types.h>
#include <Files.h>
#include <Script.h>
#include <Resources.h>
typedef struct PASHeader /* header portion of Patchable AppleSingle */
{
UInt32 magicNum; /* internal file type tag = 0x00244200*/
UInt32 versionNum; /* format version: 1 = 0x00010000 */
UInt8 filler[16]; /* filler */
UInt16 numEntries; /* number of entries which follow */
} PASHeader ;
typedef struct PASEntry /* one Patchable AppleSingle entry descriptor */
{
UInt32 entryID; /* entry type: see list, 0 invalid */
UInt32 entryOffset; /* offset, in bytes, from beginning */
/* of file to this entry's data */
UInt32 entryLength; /* length of data in octets */
} PASEntry;
typedef struct PASMiscInfo
{
short fileHasResFork;
short fileResAttrs;
OSType fileType;
OSType fileCreator;
UInt32 fileFlags;
} PASMiscInfo;
typedef struct PASResFork
{
short NumberOfTypes;
} PASResFork;
typedef struct PASResource
{
short attr;
short attrID;
OSType attrType;
Str255 attrName;
unsigned long length;
} PASResource;
#if PRAGMA_ALIGN_SUPPORTED
#pragma options align=reset
#endif
#define kCreator 'MOSS'
#define kType 'PASf'
#define PAS_BUFFER_SIZE (1024*512)
#define PAS_MAGIC_NUM (0x00244200)
#define PAS_VERSION (0x00010000)
enum
{
ePas_Data = 1,
ePas_Misc,
ePas_Resource
};
#ifdef __cplusplus
extern "C" {
#endif
/* Prototypes */
OSErr PAS_EncodeFile(FSSpec *inSpec, FSSpec *outSpec);
OSErr PAS_DecodeFile(FSSpec *inSpec, FSSpec *outSpec);
#ifdef __cplusplus
}
#endif
#endif /* SU_PAS_H */

View File

@@ -0,0 +1,380 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#include "nscore.h"
#include "NSReg.h"
#include "nsFileSpec.h"
#include "nsFileStream.h"
#include "nsInstall.h" // for error codes
#include "prmem.h"
#include "ScheduledTasks.h"
#ifdef _WINDOWS
#include <sys/stat.h>
#include <windows.h>
BOOL WIN32_IsMoveFileExBroken()
{
/* the NT option MOVEFILE_DELAY_UNTIL_REBOOT is broken on
* Windows NT 3.51 Service Pack 4 and NT 4.0 before Service Pack 2
*/
BOOL broken = FALSE;
OSVERSIONINFO osinfo;
// they *all* appear broken--better to have one way that works.
return TRUE;
osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (GetVersionEx(&osinfo) && osinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
if ( osinfo.dwMajorVersion == 3 && osinfo.dwMinorVersion == 51 )
{
if ( 0 == stricmp(osinfo.szCSDVersion,"Service Pack 4"))
{
broken = TRUE;
}
}
else if ( osinfo.dwMajorVersion == 4 )
{
if (osinfo.szCSDVersion[0] == '\0' ||
(0 == stricmp(osinfo.szCSDVersion,"Service Pack 1")))
{
broken = TRUE;
}
}
}
return broken;
}
PRInt32 DoWindowsReplaceExistingFileStuff(const char* currentName, const char* finalName)
{
PRInt32 err = 0;
char* final = strdup(finalName);
char* current = strdup(currentName);
/* couldn't delete, probably in use. Schedule for later */
DWORD dwVersion, dwWindowsMajorVersion;
/* Get OS version info */
dwVersion = GetVersion();
dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
/* Get build numbers for Windows NT or Win32s */
if (dwVersion < 0x80000000) // Windows NT
{
/* On Windows NT */
if ( WIN32_IsMoveFileExBroken() )
{
/* the MOVEFILE_DELAY_UNTIL_REBOOT option doesn't work on
* NT 3.51 SP4 or on NT 4.0 until SP2
*/
struct stat statbuf;
PRBool nameFound = PR_FALSE;
char tmpname[_MAX_PATH];
strncpy( tmpname, finalName, _MAX_PATH );
int len = strlen(tmpname);
while (!nameFound && len < _MAX_PATH )
{
tmpname[len-1] = '~';
tmpname[len] = '\0';
if ( stat(tmpname, &statbuf) != 0 )
nameFound = TRUE;
else
len++;
}
if ( nameFound )
{
if ( MoveFile( finalName, tmpname ) )
{
if ( MoveFile( currentName, finalName ) )
{
DeleteFileNowOrSchedule(nsFileSpec(tmpname));
}
else
{
/* 2nd move failed, put old file back */
MoveFile( tmpname, finalName );
}
}
else
{
/* non-executable in use; schedule for later */
return -1; // let the start registry stuff do our work!
}
}
}
else if ( MoveFileEx(currentName, finalName, MOVEFILE_DELAY_UNTIL_REBOOT) )
{
err = 0;
}
}
else // Windows 95 or Win16
{
/*
* Place an entry in the WININIT.INI file in the Windows directory
* to delete finalName and rename currentName to be finalName at reboot
*/
int strlen;
char Src[_MAX_PATH]; // 8.3 name
char Dest[_MAX_PATH]; // 8.3 name
strlen = GetShortPathName( (LPCTSTR)currentName, (LPTSTR)Src, (DWORD)sizeof(Src) );
if ( strlen > 0 )
{
free(current);
current = strdup(Src);
}
strlen = GetShortPathName( (LPCTSTR) finalName, (LPTSTR) Dest, (DWORD) sizeof(Dest));
if ( strlen > 0 )
{
free(final);
final = strdup(Dest);
}
/* NOTE: use OEM filenames! Even though it looks like a Windows
* .INI file, WININIT.INI is processed under DOS
*/
AnsiToOem( final, final );
AnsiToOem( current, current );
if ( WritePrivateProfileString( "Rename", final, current, "WININIT.INI" ) )
err = 0;
}
free(final);
free(current);
return err;
}
#endif
REGERR DeleteFileNowOrSchedule(nsFileSpec& filename)
{
REGERR result = 0;
filename.Delete(false);
if (filename.Exists())
{
RKEY newkey;
HREG reg;
if ( REGERR_OK == NR_RegOpen("", &reg) )
{
if (REGERR_OK == NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY, &newkey) )
{
// FIX should be using nsPersistentFileDescriptor!!!
result = NR_RegSetEntry( reg, newkey, (char*)(const char*)filename.GetNativePathCString(), REGTYPE_ENTRY_FILE, nsnull, 0);
if (result == REGERR_OK)
result = nsInstall::REBOOT_NEEDED;
}
NR_RegClose(reg);
}
}
return result;
}
/* tmp file is the bad one that we want to replace with target. */
REGERR ReplaceFileNowOrSchedule(nsFileSpec& replacementFile, nsFileSpec& doomedFile )
{
REGERR result = 0;
if(replacementFile == doomedFile)
{
/* do not have to do anything */
return result;
}
doomedFile.Delete(false);
if (! doomedFile.Exists() )
{
// Now that we have move the existing file, we can move the mExtracedFile into place.
nsFileSpec parentofFinalFile;
doomedFile.GetParent(parentofFinalFile);
result = replacementFile.Move(parentofFinalFile);
if ( NS_SUCCEEDED(result) )
{
char* leafName = doomedFile.GetLeafName();
replacementFile.Rename(leafName);
nsCRT::free(leafName);
}
}
else
{
#ifdef _WINDOWS
if (DoWindowsReplaceExistingFileStuff(replacementFile.GetNativePathCString(), doomedFile.GetNativePathCString()) == 0)
return 0;
#endif
RKEY newkey;
HREG reg;
if ( REGERR_OK == NR_RegOpen("", &reg) )
{
result = NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY, &newkey);
if ( result == REGERR_OK )
{
char* replacementFileName = (char*)(const char*)replacementFile.GetNativePathCString();
result = NR_RegSetEntry( reg, newkey, (char*)(const char*)doomedFile.GetNativePathCString(), REGTYPE_ENTRY_FILE, replacementFileName, strlen(replacementFileName));
if (result == REGERR_OK)
result = nsInstall::REBOOT_NEEDED;
}
NR_RegClose(reg);
}
}
return result;
}
void DeleteScheduledFiles(void);
void ReplaceScheduledFiles(void);
extern "C" void PerformScheduledTasks(void *data)
{
DeleteScheduledFiles();
ReplaceScheduledFiles();
}
void DeleteScheduledFiles(void)
{
HREG reg;
if (REGERR_OK == NR_RegOpen("", &reg))
{
RKEY key;
REGENUM state;
/* perform scheduled file deletions and replacements (PC only) */
if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY,&key))
{
char buf[MAXREGNAMELEN];
while (REGERR_OK == NR_RegEnumEntries(reg, key, &state, buf, sizeof(buf), NULL ))
{
nsFileSpec doomedFile(buf);
doomedFile.Delete(PR_FALSE);
if (! doomedFile.Exists())
{
NR_RegDeleteEntry( reg, key, buf );
}
}
/* delete list node if empty */
if (REGERR_NOMORE == NR_RegEnumEntries( reg, key, &state, buf, sizeof(buf), NULL ))
{
NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY);
}
}
NR_RegClose(reg);
}
}
void ReplaceScheduledFiles(void)
{
HREG reg;
if (REGERR_OK == NR_RegOpen("", &reg))
{
RKEY key;
REGENUM state;
/* replace files if any listed */
if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY, &key))
{
char tmpfile[MAXREGNAMELEN];
char target[MAXREGNAMELEN];
state = 0;
while (REGERR_OK == NR_RegEnumEntries(reg, key, &state, tmpfile, sizeof(tmpfile), NULL ))
{
nsFileSpec replaceFile(tmpfile);
if (! replaceFile.Exists() )
{
NR_RegDeleteEntry( reg, key, tmpfile );
}
else if ( REGERR_OK != NR_RegGetEntryString( reg, key, tmpfile, target, sizeof(target) ) )
{
/* can't read target filename, corruption? */
NR_RegDeleteEntry( reg, key, tmpfile );
}
else
{
nsFileSpec targetFile(target);
targetFile.Delete(PR_FALSE);
if (!targetFile.Exists())
{
nsFileSpec parentofTarget;
targetFile.GetParent(parentofTarget);
nsresult result = replaceFile.Move(parentofTarget);
if ( NS_SUCCEEDED(result) )
{
char* leafName = targetFile.GetLeafName();
replaceFile.Rename(leafName);
nsCRT::free(leafName);
NR_RegDeleteEntry( reg, key, tmpfile );
}
}
}
}
/* delete list node if empty */
if (REGERR_NOMORE == NR_RegEnumEntries(reg, key, &state, tmpfile, sizeof(tmpfile), NULL ))
{
NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY);
}
}
NR_RegClose(reg);
}
}

View File

@@ -0,0 +1,42 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef __SCHEDULEDTASKS_H__
#define __SCHEDULEDTASKS_H__
#include "NSReg.h"
#include "nsFileSpec.h"
REGERR DeleteFileNowOrSchedule(nsFileSpec& filename);
REGERR ReplaceFileNowOrSchedule(nsFileSpec& tmpfile, nsFileSpec& target );
extern "C" void PerformScheduledTasks(void *data);
#endif

View File

@@ -0,0 +1,135 @@
/* -*- Mode: C; tab-width: 4; 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.
*/
/*--------------------------------------------------------------
* GDIFF.H
*
* Constants used in processing the GDIFF format
*--------------------------------------------------------------*/
#include "prio.h"
#include "nsFileSpec.h"
#define GDIFF_MAGIC "\xD1\xFF\xD1\xFF"
#define GDIFF_MAGIC_LEN 4
#define GDIFF_VER 5
#define GDIFF_EOF "\0"
#define GDIFF_VER_POS 4
#define GDIFF_CS_POS 5
#define GDIFF_CSLEN_POS 6
#define GDIFF_HEADERSIZE 7
#define GDIFF_APPDATALEN 4
#define GDIFF_CS_NONE 0
#define GDIFF_CS_MD5 1
#define GDIFF_CS_SHA 2
#define GDIFF_CS_CRC32 32
#define CRC32_LEN 4
/*--------------------------------------
* GDIFF opcodes
*------------------------------------*/
#define ENDDIFF 0
#define ADD8MAX 246
#define ADD16 247
#define ADD32 248
#define COPY16BYTE 249
#define COPY16SHORT 250
#define COPY16LONG 251
#define COPY32BYTE 252
#define COPY32SHORT 253
#define COPY32LONG 254
#define COPY64 255
/* instruction sizes */
#define ADD16SIZE 2
#define ADD32SIZE 4
#define COPY16BYTESIZE 3
#define COPY16SHORTSIZE 4
#define COPY16LONGSIZE 6
#define COPY32BYTESIZE 5
#define COPY32SHORTSIZE 6
#define COPY32LONGSIZE 8
#define COPY64SIZE 12
/*--------------------------------------
* error codes
*------------------------------------*/
#define GDIFF_OK 0
#define GDIFF_ERR_UNKNOWN -1
#define GDIFF_ERR_ARGS -2
#define GDIFF_ERR_ACCESS -3
#define GDIFF_ERR_MEM -4
#define GDIFF_ERR_HEADER -5
#define GDIFF_ERR_BADDIFF -6
#define GDIFF_ERR_OPCODE -7
#define GDIFF_ERR_OLDFILE -8
#define GDIFF_ERR_CHKSUMTYPE -9
#define GDIFF_ERR_CHECKSUM -10
#define GDIFF_ERR_CHECKSUM_TARGET -11
#define GDIFF_ERR_CHECKSUM_RESULT -12
/*--------------------------------------
* types
*------------------------------------*/
#ifndef AIX
#ifdef OSF1
#include <sys/types.h>
#else
typedef unsigned char uchar;
#endif
#endif
typedef struct _diffdata {
PRFileDesc* fSrc;
PRFileDesc* fOut;
PRFileDesc* fDiff;
uint8 checksumType;
uint8 checksumLength;
uchar* oldChecksum;
uchar* newChecksum;
PRBool bMacAppleSingle;
PRBool bWin32BoundImage;
uchar* databuf;
uint32 bufsize;
} DIFFDATA;
typedef DIFFDATA* pDIFFDATA;
/*--------------------------------------
* miscellaneous
*------------------------------------*/
#define APPFLAG_W32BOUND "autoinstall:Win32PE"
#define APPFLAG_APPLESINGLE "autoinstall:AppleSingle"
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

View File

@@ -0,0 +1,111 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Communicator client code,
# released March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
# Contributors:
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
DEPTH=..\..
IGNORE_MANIFEST=1
MAKE_OBJ_TYPE = DLL
MODULE=xpinstall
DLL=.\$(OBJDIR)\$(MODULE).dll
DEFINES=-D_IMPL_NS_DOM -DWIN32_LEAN_AND_MEAN
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
LINCS= \
-I$(PUBLIC)\xpinstall \
-I$(PUBLIC)\jar \
-I$(PUBLIC)\libreg \
-I$(PUBLIC)\netlib \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\pref \
-I$(PUBLIC)\rdf \
-I$(PUBLIC)\js \
-I$(PUBLIC)\dom \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\nspr2 \
-I$(PUBLIC)\zlib \
-I$(PUBLIC)\xpfe\components \
$(NULL)
LLIBS = \
$(DIST)\lib\jar50.lib \
$(DIST)\lib\libreg32.lib \
$(DIST)\lib\netlib.lib \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\js3250.lib \
$(DIST)\lib\jsdombase_s.lib \
$(DIST)\lib\jsdomevents_s.lib \
$(DIST)\lib\zlib.lib \
$(DIST)\lib\plc3.lib \
$(LIBNSPR) \
$(NULL)
OBJS = \
.\$(OBJDIR)\nsInstall.obj \
.\$(OBJDIR)\nsInstallTrigger.obj \
.\$(OBJDIR)\nsInstallVersion.obj \
.\$(OBJDIR)\nsInstallFolder.obj \
.\$(OBJDIR)\nsJSInstall.obj \
.\$(OBJDIR)\nsJSInstallTriggerGlobal.obj \
.\$(OBJDIR)\nsJSInstallVersion.obj \
.\$(OBJDIR)\nsSoftwareUpdate.obj \
.\$(OBJDIR)\nsSoftwareUpdateRun.obj \
.\$(OBJDIR)\nsSoftwareUpdateStream.obj \
.\$(OBJDIR)\nsInstallFile.obj \
.\$(OBJDIR)\nsInstallDelete.obj \
.\$(OBJDIR)\nsInstallExecute.obj \
.\$(OBJDIR)\nsInstallPatch.obj \
.\$(OBJDIR)\nsInstallUninstall.obj \
.\$(OBJDIR)\nsInstallResources.obj \
.\$(OBJDIR)\nsTopProgressNotifier.obj \
.\$(OBJDIR)\nsLoggingProgressNotifier.obj\
.\$(OBJDIR)\ScheduledTasks.obj \
.\$(OBJDIR)\nsWinReg.obj \
.\$(OBJDIR)\nsJSWinReg.obj \
.\$(OBJDIR)\nsWinRegItem.obj \
.\$(OBJDIR)\nsWinRegValue.obj \
.\$(OBJDIR)\nsWinProfile.obj \
.\$(OBJDIR)\nsJSWinProfile.obj \
.\$(OBJDIR)\nsWinProfileItem.obj \
.\$(OBJDIR)\nsInstallProgressDialog.obj \
.\$(OBJDIR)\nsInstallFileOpItem.obj \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).lib $(DIST)\lib
$(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).dll $(DIST)\bin\components
clobber::
rm -f $(DIST)\lib\$(MODULE).lib
rm -f $(DIST)\bin\components\$(MODULE).dll

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,265 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef __NS_INSTALL_H__
#define __NS_INSTALL_H__
#include "nscore.h"
#include "nsISupports.h"
#include "jsapi.h"
#include "plevent.h"
#include "nsString.h"
#include "nsFileSpec.h"
#include "nsVector.h"
#include "nsHashtable.h"
#include "nsSoftwareUpdate.h"
#include "nsInstallObject.h"
#include "nsInstallVersion.h"
#include "nsIXPInstallProgress.h"
class nsInstallInfo
{
public:
nsInstallInfo(const nsString& fromURL, const nsString& localFile, long flags);
nsInstallInfo(nsVector* fromURL, nsVector* localFiles, long flags);
virtual ~nsInstallInfo();
nsString& GetFromURL(PRUint32 index = 0);
nsString& GetLocalFile(PRUint32 index = 0);
void GetArguments(nsString& args, PRUint32 index = 0);
long GetFlags();
PRBool IsMultipleTrigger();
static void DeleteVector(nsVector* vector);
private:
PRBool mMultipleTrigger;
nsresult mError;
long mFlags;
nsVector *mFromURLs;
nsVector *mLocalFiles;
};
class nsInstall
{
friend class nsWinReg;
friend class nsWinProfile;
public:
enum
{
BAD_PACKAGE_NAME = -200,
UNEXPECTED_ERROR = -201,
ACCESS_DENIED = -202,
TOO_MANY_CERTIFICATES = -203,
NO_INSTALLER_CERTIFICATE = -204,
NO_CERTIFICATE = -205,
NO_MATCHING_CERTIFICATE = -206,
UNKNOWN_JAR_FILE = -207,
INVALID_ARGUMENTS = -208,
ILLEGAL_RELATIVE_PATH = -209,
USER_CANCELLED = -210,
INSTALL_NOT_STARTED = -211,
SILENT_MODE_DENIED = -212,
NO_SUCH_COMPONENT = -213,
FILE_DOES_NOT_EXIST = -214,
FILE_READ_ONLY = -215,
FILE_IS_DIRECTORY = -216,
NETWORK_FILE_IS_IN_USE = -217,
APPLE_SINGLE_ERR = -218,
INVALID_PATH_ERR = -219,
PATCH_BAD_DIFF = -220,
PATCH_BAD_CHECKSUM_TARGET = -221,
PATCH_BAD_CHECKSUM_RESULT = -222,
UNINSTALL_FAILED = -223,
GESTALT_UNKNOWN_ERR = -5550,
GESTALT_INVALID_ARGUMENT = -5551,
SUCCESS = 0,
REBOOT_NEEDED = 999,
LIMITED_INSTALL = 0,
FULL_INSTALL = 1,
NO_STATUS_DLG = 2,
NO_FINALIZE_DLG = 4,
INSTALL_FILE_UNEXPECTED_MSG_ID = 0,
DETAILS_REPLACE_FILE_MSG_ID = 1,
DETAILS_INSTALL_FILE_MSG_ID = 2
};
nsInstall();
virtual ~nsInstall();
PRInt32 SetScriptObject(void* aScriptObject);
PRInt32 SaveWinRegPrototype(void* aScriptObject);
PRInt32 SaveWinProfilePrototype(void* aScriptObject);
JSObject* RetrieveWinRegPrototype(void);
JSObject* RetrieveWinProfilePrototype(void);
PRInt32 GetUserPackageName(nsString& aUserPackageName);
PRInt32 GetRegPackageName(nsString& aRegPackageName);
PRInt32 AbortInstall();
PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRBool aForceMode, PRInt32* aReturn);
PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRInt32* aReturn);
PRInt32 AddDirectory(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRInt32* aReturn);
PRInt32 AddDirectory(const nsString& aJarSource, PRInt32* aReturn);
PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRBool aForceMode, PRInt32* aReturn);
PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn);
PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn);
PRInt32 AddSubcomponent(const nsString& aJarSource, PRInt32* aReturn);
PRInt32 DeleteComponent(const nsString& aRegistryName, PRInt32* aReturn);
PRInt32 DeleteFile(const nsString& aFolder, const nsString& aRelativeFileName, PRInt32* aReturn);
PRInt32 DiskSpaceAvailable(const nsString& aFolder, PRInt32* aReturn);
PRInt32 Execute(const nsString& aJarSource, const nsString& aArgs, PRInt32* aReturn);
PRInt32 Execute(const nsString& aJarSource, PRInt32* aReturn);
PRInt32 FinalizeInstall(PRInt32* aReturn);
PRInt32 Gestalt(const nsString& aSelector, PRInt32* aReturn);
PRInt32 GetComponentFolder(const nsString& aComponentName, const nsString& aSubdirectory, nsString** aFolder);
PRInt32 GetComponentFolder(const nsString& aComponentName, nsString** aFolder);
PRInt32 GetFolder(const nsString& aTargetFolder, const nsString& aSubdirectory, nsString** aFolder);
PRInt32 GetFolder(const nsString& aTargetFolder, nsString** aFolder);
PRInt32 GetLastError(PRInt32* aReturn);
PRInt32 GetWinProfile(const nsString& aFolder, const nsString& aFile, JSContext* jscontext, JSClass* WinProfileClass, jsval* aReturn);
PRInt32 GetWinRegistry(JSContext* jscontext, JSClass* WinRegClass, jsval* aReturn);
PRInt32 Patch(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn);
PRInt32 Patch(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn);
PRInt32 ResetError();
PRInt32 SetPackageFolder(const nsString& aFolder);
PRInt32 StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32* aReturn);
PRInt32 Uninstall(const nsString& aPackageName, PRInt32* aReturn);
PRInt32 FileOpDirCreate(nsFileSpec& aTarget, PRInt32* aReturn);
PRInt32 FileOpDirGetParent(nsFileSpec& aTarget, nsFileSpec* aReturn);
PRInt32 FileOpDirRemove(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 FileOpDirRename(nsFileSpec& aSrc, nsFileSpec& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileCopy(nsFileSpec& aSrc, nsFileSpec& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileDelete(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 FileOpFileExists(nsFileSpec& aTarget, PRBool* aReturn);
PRInt32 FileOpFileExecute(nsFileSpec& aTarget, nsString& aParams, PRInt32* aReturn);
PRInt32 FileOpFileGetNativeVersion(nsFileSpec& aTarget, nsString* aReturn);
PRInt32 FileOpFileGetDiskSpaceAvailable(nsFileSpec& aTarget, PRUint32* aReturn);
PRInt32 FileOpFileGetModDate(nsFileSpec& aTarget, nsFileSpec::TimeStamp* aReturn);
PRInt32 FileOpFileGetSize(nsFileSpec& aTarget, PRUint32* aReturn);
PRInt32 FileOpFileIsDirectory(nsFileSpec& aTarget, PRBool* aReturn);
PRInt32 FileOpFileIsFile(nsFileSpec& aTarget, PRBool* aReturn);
PRInt32 FileOpFileModDateChanged(nsFileSpec& aTarget, nsFileSpec::TimeStamp& aOldStamp, PRBool* aReturn);
PRInt32 FileOpFileMove(nsFileSpec& aSrc, nsFileSpec& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileRename(nsFileSpec& aSrc, nsFileSpec& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileWinShortcutCreate(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 FileOpFileMacAliasCreate(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 FileOpFileUnixLinkCreate(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedName, nsFileSpec** aRealName);
void AddPatch(nsHashKey *aKey, nsFileSpec* fileName);
void GetPatch(nsHashKey *aKey, nsFileSpec* fileName);
void GetJarFileLocation(nsString& aFile);
void SetJarFileLocation(const nsString& aFile);
void GetInstallArguments(nsString& args);
void SetInstallArguments(const nsString& args);
private:
JSObject* mScriptObject;
JSObject* mWinRegObject;
JSObject* mWinProfileObject;
nsString mJarFileLocation;
void* mJarFileData;
nsString mInstallArguments;
PRBool mUserCancelled;
PRBool mUninstallPackage;
PRBool mRegisterPackage;
nsString mRegistryPackageName; /* Name of the package we are installing */
nsString mUIName; /* User-readable package name */
nsInstallVersion* mVersionInfo; /* Component version info */
nsVector* mInstalledFiles;
nsHashtable* mPatchList;
nsIXPInstallProgress *mNotifier;
PRInt32 mLastError;
void ParseFlags(int flags);
PRInt32 SanityCheck(void);
void GetTime(nsString &aString);
PRInt32 GetQualifiedRegName(const nsString& name, nsString& qualifiedRegName );
PRInt32 GetQualifiedPackageName( const nsString& name, nsString& qualifiedName );
void CurrentUserNode(nsString& userRegNode);
PRBool BadRegName(const nsString& regName);
PRInt32 SaveError(PRInt32 errcode);
void CleanUp();
PRInt32 OpenJARFile(void);
void CloseJARFile(void);
PRInt32 ExtractDirEntries(const nsString& directory, nsVector *paths);
PRInt32 ScheduleForInstall(nsInstallObject* ob);
};
#endif

View File

@@ -0,0 +1,235 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#include "prmem.h"
#include "nsFileSpec.h"
#include "VerReg.h"
#include "ScheduledTasks.h"
#include "nsInstallDelete.h"
#include "nsInstallResources.h"
#include "nsInstall.h"
#include "nsIDOMInstallVersion.h"
nsInstallDelete::nsInstallDelete( nsInstall* inInstall,
const nsString& folderSpec,
const nsString& inPartialPath,
PRInt32 *error)
: nsInstallObject(inInstall)
{
if ((folderSpec == "null") || (inInstall == NULL))
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
mDeleteStatus = DELETE_FILE;
mFinalFile = nsnull;
mRegistryName = "";
mFinalFile = new nsFileSpec(folderSpec);
*mFinalFile += inPartialPath;
*error = ProcessInstallDelete();
}
nsInstallDelete::nsInstallDelete( nsInstall* inInstall,
const nsString& inComponentName,
PRInt32 *error)
: nsInstallObject(inInstall)
{
if (inInstall == NULL)
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
mDeleteStatus = DELETE_COMPONENT;
mFinalFile = nsnull;
mRegistryName = inComponentName;
*error = ProcessInstallDelete();
}
nsInstallDelete::~nsInstallDelete()
{
if (mFinalFile == nsnull)
delete mFinalFile;
}
PRInt32 nsInstallDelete::Prepare()
{
// no set-up necessary
return nsInstall::SUCCESS;
}
PRInt32 nsInstallDelete::Complete()
{
PRInt32 err = nsInstall::SUCCESS;
if (mInstall == NULL)
return nsInstall::INVALID_ARGUMENTS;
if (mDeleteStatus == DELETE_COMPONENT)
{
char* temp = mRegistryName.ToNewCString();
err = VR_Remove(temp);
delete [] temp;
}
if ((mDeleteStatus == DELETE_FILE) || (err == REGERR_OK))
{
err = NativeComplete();
}
else
{
err = nsInstall::UNEXPECTED_ERROR;
}
return err;
}
void nsInstallDelete::Abort()
{
}
char* nsInstallDelete::toString()
{
char* buffer = new char[1024];
if (mDeleteStatus == DELETE_COMPONENT)
{
sprintf( buffer, nsInstallResources::GetDeleteComponentString(), nsAutoCString(mRegistryName));
}
else
{
if (mFinalFile)
sprintf( buffer, nsInstallResources::GetDeleteFileString(), mFinalFile->GetCString());
}
return buffer;
}
PRBool
nsInstallDelete::CanUninstall()
{
return PR_FALSE;
}
PRBool
nsInstallDelete::RegisterPackageNode()
{
return PR_FALSE;
}
PRInt32 nsInstallDelete::ProcessInstallDelete()
{
PRInt32 err;
char* tempCString = nsnull;
if (mDeleteStatus == DELETE_COMPONENT)
{
/* Check if the component is in the registry */
tempCString = mRegistryName.ToNewCString();
err = VR_InRegistry( tempCString );
if (err != REGERR_OK)
{
return err;
}
else
{
char* tempRegistryString;
tempRegistryString = (char*)PR_Calloc(MAXREGPATHLEN, sizeof(char));
err = VR_GetPath( tempCString , MAXREGPATHLEN, tempRegistryString);
if (err == REGERR_OK)
{
if (mFinalFile)
delete mFinalFile;
mFinalFile = new nsFileSpec(tempRegistryString);
}
PR_FREEIF(tempRegistryString);
}
}
if(tempCString)
delete [] tempCString;
if (mFinalFile->Exists())
{
if (mFinalFile->IsFile())
{
err = nsInstall::SUCCESS;
}
else
{
err = nsInstall::FILE_IS_DIRECTORY;
}
}
else
{
err = nsInstall::FILE_DOES_NOT_EXIST;
}
return err;
}
PRInt32 nsInstallDelete::NativeComplete()
{
if (mFinalFile->Exists())
{
if (mFinalFile->IsFile())
{
return DeleteFileNowOrSchedule(*mFinalFile);
}
else
{
return nsInstall::FILE_IS_DIRECTORY;
}
}
return nsInstall::FILE_DOES_NOT_EXIST;
}

View File

@@ -0,0 +1,78 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsInstallDelete_h__
#define nsInstallDelete_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
#define DELETE_COMPONENT 1
#define DELETE_FILE 2
class nsInstallDelete : public nsInstallObject
{
public:
nsInstallDelete( nsInstall* inInstall,
const nsString& folderSpec,
const nsString& inPartialPath,
PRInt32 *error);
nsInstallDelete( nsInstall* inInstall,
const nsString& ,
PRInt32 *error);
virtual ~nsInstallDelete();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
/* Private Fields */
nsFileSpec* mFinalFile;
nsString mRegistryName;
PRInt32 mDeleteStatus;
PRInt32 ProcessInstallDelete();
PRInt32 NativeComplete();
};
#endif /* nsInstallDelete_h__ */

View File

@@ -0,0 +1,136 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#include "prmem.h"
#include "nsFileSpec.h"
#include "VerReg.h"
#include "nsInstallExecute.h"
#include "nsInstallResources.h"
#include "ScheduledTasks.h"
#include "nsInstall.h"
#include "nsIDOMInstallVersion.h"
nsInstallExecute:: nsInstallExecute( nsInstall* inInstall,
const nsString& inJarLocation,
const nsString& inArgs,
PRInt32 *error)
: nsInstallObject(inInstall)
{
if ((inInstall == nsnull) || (inJarLocation == "null"))
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
mJarLocation = inJarLocation;
mArgs = inArgs;
mExecutableFile = nsnull;
}
nsInstallExecute::~nsInstallExecute()
{
if (mExecutableFile)
delete mExecutableFile;
}
PRInt32 nsInstallExecute::Prepare()
{
if (mInstall == NULL || mJarLocation == "null")
return nsInstall::INVALID_ARGUMENTS;
return mInstall->ExtractFileFromJar(mJarLocation, nsnull, &mExecutableFile);
}
PRInt32 nsInstallExecute::Complete()
{
if (mExecutableFile == nsnull)
return nsInstall::INVALID_ARGUMENTS;
nsFileSpec app( *mExecutableFile);
if (!app.Exists())
{
return nsInstall::INVALID_ARGUMENTS;
}
PRInt32 result = app.Execute( mArgs );
DeleteFileNowOrSchedule( app );
return result;
}
void nsInstallExecute::Abort()
{
/* Get the names */
if (mExecutableFile == nsnull)
return;
DeleteFileNowOrSchedule(*mExecutableFile);
}
char* nsInstallExecute::toString()
{
char* buffer = new char[1024];
// if the FileSpec is NULL, just us the in jar file name.
if (mExecutableFile == nsnull)
{
char *tempString = mJarLocation.ToNewCString();
sprintf( buffer, nsInstallResources::GetExecuteString(), tempString);
delete [] tempString;
}
else
{
sprintf( buffer, nsInstallResources::GetExecuteString(), mExecutableFile->GetCString());
}
return buffer;
}
PRBool
nsInstallExecute::CanUninstall()
{
return PR_FALSE;
}
PRBool
nsInstallExecute::RegisterPackageNode()
{
return PR_FALSE;
}

View File

@@ -0,0 +1,73 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsInstallExecute_h__
#define nsInstallExecute_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
#include "nsIDOMInstallVersion.h"
class nsInstallExecute : public nsInstallObject
{
public:
nsInstallExecute( nsInstall* inInstall,
const nsString& inJarLocation,
const nsString& inArgs,
PRInt32 *error);
virtual ~nsInstallExecute();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
nsString mJarLocation; // Location in the JAR
nsString mArgs; // command line arguments
nsFileSpec *mExecutableFile; // temporary file location
PRInt32 NativeComplete(void);
void NativeAbort(void);
};
#endif /* nsInstallExecute_h__ */

View File

@@ -0,0 +1,366 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#include "nsInstallFile.h"
#include "nsFileSpec.h"
#include "VerReg.h"
#include "ScheduledTasks.h"
#include "nsInstall.h"
#include "nsIDOMInstallVersion.h"
#include "nsInstallResources.h"
/* Public Methods */
/* Constructor
inInstall - softUpdate object we belong to
inComponentName - full path of the registry component
inVInfo - full version info
inJarLocation - location inside the JAR file
inFinalFileSpec - final location on disk
*/
nsInstallFile::nsInstallFile(nsInstall* inInstall,
const nsString& inComponentName,
const nsString& inVInfo,
const nsString& inJarLocation,
const nsString& folderSpec,
const nsString& inPartialPath,
PRBool forceInstall,
PRInt32 *error)
: nsInstallObject(inInstall)
{
mVersionRegistryName = nsnull;
mJarLocation = nsnull;
mExtracedFile = nsnull;
mFinalFile = nsnull;
mVersionInfo = nsnull;
mUpgradeFile = PR_FALSE;
if ((folderSpec == "null") || (inInstall == NULL))
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
/* Check for existence of the newer version */
PRBool versionNewer = PR_FALSE; // Is this a newer version
char* qualifiedRegNameString = inComponentName.ToNewCString();
if ( (forceInstall == PR_FALSE ) && (inVInfo != "") && ( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) )
{
nsInstallVersion *newVersion = new nsInstallVersion();
newVersion->Init(inVInfo);
VERSION versionStruct;
VR_GetVersion( qualifiedRegNameString, &versionStruct );
nsInstallVersion* oldVersion = new nsInstallVersion();
oldVersion->Init(versionStruct.major,
versionStruct.minor,
versionStruct.release,
versionStruct.build);
PRInt32 areTheyEqual;
newVersion->CompareTo(oldVersion, &areTheyEqual);
delete oldVersion;
delete newVersion;
if (areTheyEqual == nsIDOMInstallVersion::MAJOR_DIFF_MINUS ||
areTheyEqual == nsIDOMInstallVersion::MINOR_DIFF_MINUS ||
areTheyEqual == nsIDOMInstallVersion::REL_DIFF_MINUS ||
areTheyEqual == nsIDOMInstallVersion::BLD_DIFF_MINUS )
{
// the file to be installed is OLDER than what is on disk. Return error
delete qualifiedRegNameString;
*error = areTheyEqual;
return;
}
}
delete qualifiedRegNameString;
mFinalFile = new nsFileSpec(folderSpec);
*mFinalFile += inPartialPath;
mReplaceFile = mFinalFile->Exists();
if (mReplaceFile == PR_FALSE)
{
nsFileSpec parent;
mFinalFile->GetParent(parent);
nsFileSpec makeDirs(parent.GetCString(), PR_TRUE);
}
mForceInstall = forceInstall;
mVersionRegistryName = new nsString(inComponentName);
mJarLocation = new nsString(inJarLocation);
mVersionInfo = new nsString(inVInfo);
nsString regPackageName;
mInstall->GetRegPackageName(regPackageName);
// determine Child status
if ( regPackageName == "" )
{
// in the "current communicator package" absolute pathnames (start
// with slash) indicate shared files -- all others are children
mChildFile = ( mVersionRegistryName->CharAt(0) != '/' );
}
else
{
// there is no "starts with" api in nsString. LAME!
nsString startsWith;
mVersionRegistryName->Left(startsWith, regPackageName.Length());
if (startsWith.Equals(regPackageName))
{
mChildFile = true;
}
else
{
mChildFile = false;
}
}
}
nsInstallFile::~nsInstallFile()
{
if (mVersionRegistryName)
delete mVersionRegistryName;
if (mJarLocation)
delete mJarLocation;
if (mExtracedFile)
delete mExtracedFile;
if (mFinalFile)
delete mFinalFile;
if (mVersionInfo)
delete mVersionInfo;
}
/* Prepare
* Extracts file out of the JAR archive
*/
PRInt32 nsInstallFile::Prepare()
{
if (mInstall == nsnull || mFinalFile == nsnull || mJarLocation == nsnull )
return nsInstall::INVALID_ARGUMENTS;
return mInstall->ExtractFileFromJar(*mJarLocation, mFinalFile, &mExtracedFile);
}
/* Complete
* Completes the install:
* - move the downloaded file to the final location
* - updates the registry
*/
PRInt32 nsInstallFile::Complete()
{
PRInt32 err;
if (mInstall == nsnull || mVersionRegistryName == nsnull || mFinalFile == nsnull )
{
return nsInstall::INVALID_ARGUMENTS;
}
err = CompleteFileMove();
if ( 0 == err || nsInstall::REBOOT_NEEDED == err )
{
err = RegisterInVersionRegistry();
}
return err;
}
void nsInstallFile::Abort()
{
if (mExtracedFile != nsnull)
mExtracedFile->Delete(PR_FALSE);
}
char* nsInstallFile::toString()
{
char* buffer = new char[1024];
if (mFinalFile == nsnull)
{
sprintf( buffer, nsInstallResources::GetInstallFileString(), nsnull);
}
else if (mReplaceFile)
{
// we are replacing this file.
sprintf( buffer, nsInstallResources::GetReplaceFileString(), mFinalFile->GetCString());
}
else
{
sprintf( buffer, nsInstallResources::GetInstallFileString(), mFinalFile->GetCString());
}
return buffer;
}
PRInt32 nsInstallFile::CompleteFileMove()
{
int result = 0;
if (mExtracedFile == nsnull)
{
return -1;
}
if ( *mExtracedFile == *mFinalFile )
{
/* No need to rename, they are the same */
result = 0;
}
else
{
result = ReplaceFileNowOrSchedule(*mExtracedFile, *mFinalFile );
}
return result;
}
PRInt32
nsInstallFile::RegisterInVersionRegistry()
{
int refCount;
nsString regPackageName;
mInstall->GetRegPackageName(regPackageName);
// Register file and log for Uninstall
if (!mChildFile)
{
int found;
if (regPackageName != "")
{
found = VR_UninstallFileExistsInList( (char*)(const char*)nsAutoCString(regPackageName) ,
(char*)(const char*)nsAutoCString(*mVersionRegistryName));
}
else
{
found = VR_UninstallFileExistsInList( "", (char*)(const char*)nsAutoCString(*mVersionRegistryName) );
}
if (found != REGERR_OK)
mUpgradeFile = PR_FALSE;
else
mUpgradeFile = PR_TRUE;
}
else if (REGERR_OK == VR_InRegistry( (char*)(const char*)nsAutoCString(*mVersionRegistryName)))
{
mUpgradeFile = PR_TRUE;
}
else
{
mUpgradeFile = PR_FALSE;
}
if ( REGERR_OK != VR_GetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), &refCount ))
{
refCount = 0;
}
VR_Install( (char*)(const char*)nsAutoCString(*mVersionRegistryName),
(char*)(const char*)mFinalFile->GetNativePathCString(), // DO NOT CHANGE THIS.
(char*)(const char*)nsAutoCString(*mVersionInfo),
PR_FALSE );
if (mUpgradeFile)
{
if (refCount == 0)
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 1 );
else
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), refCount ); //FIX?? what should the ref count be/
}
else
{
if (refCount != 0)
{
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), refCount + 1 );
}
else
{
if (mReplaceFile)
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 2 );
else
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 1 );
}
}
if ( !mChildFile && !mUpgradeFile )
{
if (regPackageName != "")
{
VR_UninstallAddFileToList( (char*)(const char*)nsAutoCString(regPackageName),
(char*)(const char*)nsAutoCString(*mVersionRegistryName));
}
else
{
VR_UninstallAddFileToList( "", (char*)(const char*)nsAutoCString(*mVersionRegistryName) );
}
}
return nsInstall::SUCCESS;
}
/* CanUninstall
* InstallFile() installs files which can be uninstalled,
* hence this function returns true.
*/
PRBool
nsInstallFile::CanUninstall()
{
return TRUE;
}
/* RegisterPackageNode
* InstallFile() installs files which need to be registered,
* hence this function returns true.
*/
PRBool
nsInstallFile::RegisterPackageNode()
{
return TRUE;
}

View File

@@ -0,0 +1,93 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsInstallFile_h__
#define nsInstallFile_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
#include "nsInstallVersion.h"
class nsInstallFile : public nsInstallObject
{
public:
/*************************************************************
* Public Methods
*
* Constructor
* inSoftUpdate - softUpdate object we belong to
* inComponentName - full path of the registry component
* inVInfo - full version info
* inJarLocation - location inside the JAR file
* inFinalFileSpec - final location on disk
*************************************************************/
nsInstallFile( nsInstall* inInstall,
const nsString& inVRName,
const nsString& inVInfo,
const nsString& inJarLocation,
const nsString& folderSpec,
const nsString& inPartialPath,
PRBool forceInstall,
PRInt32 *error);
virtual ~nsInstallFile();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
/* Private Fields */
nsString* mVersionInfo; /* Version info for this file*/
nsString* mJarLocation; /* Location in the JAR */
nsFileSpec* mExtracedFile; /* temporary file location */
nsFileSpec* mFinalFile; /* final file destination */
nsString* mVersionRegistryName; /* full version path */
PRBool mForceInstall; /* whether install is forced */
PRBool mReplaceFile; /* whether file exists */
PRBool mChildFile; /* whether file is a child */
PRBool mUpgradeFile; /* whether file is an upgrade */
PRInt32 CompleteFileMove();
PRInt32 RegisterInVersionRegistry();
};
#endif /* nsInstallFile_h__ */

View File

@@ -0,0 +1,38 @@
/* -*- Mode: C++; tab-width: 4; 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.
*/
#ifndef nsInstallFileOpEnums_h__
#define nsInstallFileOpEnums_h__
typedef enum nsInstallFileOpEnums {
NS_FOP_DIR_CREATE = 0,
NS_FOP_DIR_REMOVE = 1,
NS_FOP_DIR_RENAME = 2,
NS_FOP_FILE_COPY = 3,
NS_FOP_FILE_DELETE = 4,
NS_FOP_FILE_EXECUTE = 5,
NS_FOP_FILE_MOVE = 6,
NS_FOP_FILE_RENAME = 7,
NS_FOP_WIN_SHORTCUT_CREATE = 8,
NS_FOP_MAC_ALIAS_CREATE = 9,
NS_FOP_UNIX_LINK_CREATE = 10,
NS_FOP_FILE_SET_STAT = 11
} nsInstallFileOpEnums;
#endif /* nsInstallFileOpEnums_h__ */

View File

@@ -0,0 +1,316 @@
/* -*- Mode: C++; tab-width: 4; 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.
*/
#include "nspr.h"
#include "nsInstall.h"
#include "nsInstallFileOpEnums.h"
#include "nsInstallFileOpItem.h"
/* Public Methods */
nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsFileSpec& aTarget,
PRInt32 aFlags,
PRInt32* aReturn)
:nsInstallObject(aInstallObj)
{
mIObj = aInstallObj;
mCommand = aCommand;
mFlags = aFlags;
mSrc = nsnull;
mParams = nsnull;
mTarget = new nsFileSpec(aTarget);
*aReturn = NS_OK;
}
nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsFileSpec& aSrc,
nsFileSpec& aTarget,
PRInt32* aReturn)
:nsInstallObject(aInstallObj)
{
mIObj = aInstallObj;
mCommand = aCommand;
mFlags = 0;
mSrc = new nsFileSpec(aSrc);
mParams = nsnull;
mTarget = new nsFileSpec(aTarget);
*aReturn = NS_OK;
}
nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsFileSpec& aTarget,
PRInt32* aReturn)
:nsInstallObject(aInstallObj)
{
mIObj = aInstallObj;
mCommand = aCommand;
mFlags = 0;
mSrc = nsnull;
mParams = nsnull;
mTarget = new nsFileSpec(aTarget);
*aReturn = NS_OK;
}
nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsFileSpec& aTarget,
nsString& aParams,
PRInt32* aReturn)
:nsInstallObject(aInstallObj)
{
mIObj = aInstallObj;
mCommand = aCommand;
mFlags = 0;
mSrc = nsnull;
mParams = new nsString(aParams);
mTarget = new nsFileSpec(aTarget);
*aReturn = NS_OK;
}
nsInstallFileOpItem::~nsInstallFileOpItem()
{
if(mSrc)
delete mSrc;
if(mTarget)
delete mTarget;
}
PRInt32 nsInstallFileOpItem::Complete()
{
PRInt32 aReturn = NS_OK;
switch(mCommand)
{
case NS_FOP_DIR_CREATE:
NativeFileOpDirCreate(mTarget);
break;
case NS_FOP_DIR_REMOVE:
NativeFileOpDirRemove(mTarget, mFlags);
break;
case NS_FOP_DIR_RENAME:
NativeFileOpDirRename(mSrc, mTarget);
break;
case NS_FOP_FILE_COPY:
NativeFileOpFileCopy(mSrc, mTarget);
break;
case NS_FOP_FILE_DELETE:
NativeFileOpFileDelete(mTarget, mFlags);
break;
case NS_FOP_FILE_EXECUTE:
NativeFileOpFileExecute(mTarget, mParams);
break;
case NS_FOP_FILE_MOVE:
NativeFileOpFileMove(mSrc, mTarget);
break;
case NS_FOP_FILE_RENAME:
NativeFileOpFileRename(mSrc, mTarget);
break;
case NS_FOP_WIN_SHORTCUT_CREATE:
NativeFileOpWinShortcutCreate();
break;
case NS_FOP_MAC_ALIAS_CREATE:
NativeFileOpMacAliasCreate();
break;
case NS_FOP_UNIX_LINK_CREATE:
NativeFileOpUnixLinkCreate();
break;
}
return aReturn;
}
float nsInstallFileOpItem::GetInstallOrder()
{
return 3;
}
char* nsInstallFileOpItem::toString()
{
nsString result;
char* resultCString;
switch(mCommand)
{
case NS_FOP_FILE_COPY:
result = "Copy file: ";
result.Append(mSrc->GetNativePathCString());
result.Append(" to ");
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
case NS_FOP_FILE_DELETE:
result = "Delete file: ";
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
case NS_FOP_FILE_MOVE:
result = "Move file: ";
result.Append(mSrc->GetNativePathCString());
result.Append(" to ");
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
case NS_FOP_FILE_RENAME:
result = "Rename file: ";
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
case NS_FOP_DIR_CREATE:
result = "Create Folder: ";
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
case NS_FOP_DIR_REMOVE:
result = "Remove Folder: ";
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
case NS_FOP_WIN_SHORTCUT_CREATE:
break;
case NS_FOP_MAC_ALIAS_CREATE:
break;
case NS_FOP_UNIX_LINK_CREATE:
break;
case NS_FOP_FILE_SET_STAT:
result = "Set file stat: ";
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
default:
result = "Unkown file operation command!";
resultCString = result.ToNewCString();
break;
}
return resultCString;
}
PRInt32 nsInstallFileOpItem::Prepare()
{
return NULL;
}
void nsInstallFileOpItem::Abort()
{
}
/* Private Methods */
/* CanUninstall
* InstallFileOpItem() does not install any files which can be uninstalled,
* hence this function returns false.
*/
PRBool
nsInstallFileOpItem::CanUninstall()
{
return FALSE;
}
/* RegisterPackageNode
* InstallFileOpItem() does notinstall files which need to be registered,
* hence this function returns false.
*/
PRBool
nsInstallFileOpItem::RegisterPackageNode()
{
return FALSE;
}
//
// File operation functions begin here
//
PRInt32
nsInstallFileOpItem::NativeFileOpDirCreate(nsFileSpec* aTarget)
{
aTarget->CreateDirectory();
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpDirRemove(nsFileSpec* aTarget, PRInt32 aFlags)
{
aTarget->Delete(aFlags);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpDirRename(nsFileSpec* aSrc, nsFileSpec* aTarget)
{
aSrc->Rename(*aTarget);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpFileCopy(nsFileSpec* aSrc, nsFileSpec* aTarget)
{
aSrc->Copy(*aTarget);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpFileDelete(nsFileSpec* aTarget, PRInt32 aFlags)
{
aTarget->Delete(aFlags);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpFileExecute(nsFileSpec* aTarget, nsString* aParams)
{
aTarget->Execute(*aParams);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpFileMove(nsFileSpec* aSrc, nsFileSpec* aTarget)
{
aSrc->Move(*aTarget);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpFileRename(nsFileSpec* aSrc, nsFileSpec* aTarget)
{
aSrc->Rename(*aTarget);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpWinShortcutCreate()
{
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpMacAliasCreate()
{
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpUnixLinkCreate()
{
return NS_OK;
}

View File

@@ -0,0 +1,111 @@
/* -*- Mode: C++; tab-width: 4; 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.
*/
#ifndef nsInstallFileOpItem_h__
#define nsInstallFileOpItem_h__
#include "prtypes.h"
#include "nsFileSpec.h"
#include "nsSoftwareUpdate.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
class nsInstallFileOpItem : public nsInstallObject
{
public:
/* Public Fields */
/* Public Methods */
// used by:
// FileOpFileDelete()
nsInstallFileOpItem(nsInstall* installObj,
PRInt32 aCommand,
nsFileSpec& aTarget,
PRInt32 aFlags,
PRInt32* aReturn);
// used by:
// FileOpDirRemove()
// FileOpDirRename()
// FileOpFileCopy()
// FileOpFileMove()
// FileOpFileRename()
nsInstallFileOpItem(nsInstall* installObj,
PRInt32 aCommand,
nsFileSpec& aSrc,
nsFileSpec& aTarget,
PRInt32* aReturn);
// used by:
// FileOpDirCreate()
nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsFileSpec& aTarget,
PRInt32* aReturn);
// used by:
// FileOpFileExecute()
nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsFileSpec& aTarget,
nsString& aParams,
PRInt32* aReturn);
~nsInstallFileOpItem();
PRInt32 Prepare(void);
PRInt32 Complete();
char* toString();
void Abort();
float GetInstallOrder();
/* should these be protected? */
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
/* Private Fields */
nsInstall* mIObj; // initiating Install object
nsFileSpec* mSrc;
nsFileSpec* mTarget;
nsString* mParams;
long mFStat;
PRInt32 mFlags;
PRInt32 mCommand;
/* Private Methods */
PRInt32 NativeFileOpDirCreate(nsFileSpec* aTarget);
PRInt32 NativeFileOpDirRemove(nsFileSpec* aTarget, PRInt32 aFlags);
PRInt32 NativeFileOpDirRename(nsFileSpec* aSrc, nsFileSpec* aTarget);
PRInt32 NativeFileOpFileCopy(nsFileSpec* aSrc, nsFileSpec* aTarget);
PRInt32 NativeFileOpFileDelete(nsFileSpec* aTarget, PRInt32 aFlags);
PRInt32 NativeFileOpFileExecute(nsFileSpec* aTarget, nsString* aParams);
PRInt32 NativeFileOpFileMove(nsFileSpec* aSrc, nsFileSpec* aTarget);
PRInt32 NativeFileOpFileRename(nsFileSpec* aSrc, nsFileSpec* aTarget);
PRInt32 NativeFileOpWinShortcutCreate();
PRInt32 NativeFileOpMacAliasCreate();
PRInt32 NativeFileOpUnixLinkCreate();
};
#endif /* nsInstallFileOpItem_h__ */

View File

@@ -0,0 +1,336 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#include "nsInstall.h"
#include "nsInstallFolder.h"
#include "nscore.h"
#include "prtypes.h"
#include "nsRepository.h"
#include "nsString.h"
#include "nsFileSpec.h"
#include "nsSpecialSystemDirectory.h"
#include "nsFileLocations.h"
#include "nsIFileLocator.h"
struct DirectoryTable
{
char * directoryName; /* The formal directory name */
PRInt32 folderEnum; /* Directory ID */
};
struct DirectoryTable DirectoryTable[] =
{
{"Plugins", 100 },
{"Program", 101 },
{"Communicator", 102 },
{"User Pick", 103 },
{"Temporary", 104 },
{"Installed", 105 },
{"Current User", 106 },
{"Preferences", 107 },
{"OS Drive", 108 },
{"file:///", 109 },
{"Components", 110 },
{"Chrome", 111 },
{"Win System", 200 },
{"Windows", 201 },
{"Mac System", 300 },
{"Mac Desktop", 301 },
{"Mac Trash", 302 },
{"Mac Startup", 303 },
{"Mac Shutdown", 304 },
{"Mac Apple Menu", 305 },
{"Mac Control Panel", 306 },
{"Mac Extension", 307 },
{"Mac Fonts", 308 },
{"Mac Preferences", 309 },
{"Mac Documents", 310 },
{"Unix Local", 400 },
{"Unix Lib", 401 },
{"", -1 }
};
nsInstallFolder::nsInstallFolder(const nsString& aFolderID)
{
mFileSpec = nsnull;
SetDirectoryPath( aFolderID, "");
}
nsInstallFolder::nsInstallFolder(const nsString& aFolderID, const nsString& aRelativePath)
{
mFileSpec = nsnull;
/*
aFolderID can be either a Folder enum in which case we merely pass it to SetDirectoryPath, or
it can be a Directory. If it is the later, it must already exist and of course be a directory
not a file.
*/
nsFileSpec dirCheck(aFolderID);
if ( (dirCheck.Error() == NS_OK) && (dirCheck.IsDirectory()) && (dirCheck.Exists()))
{
nsString tempString = aFolderID;
tempString += aRelativePath;
mFileSpec = new nsFileSpec(tempString);
// make sure that the directory is created.
nsFileSpec(mFileSpec->GetCString(), PR_TRUE);
}
else
{
SetDirectoryPath( aFolderID, aRelativePath);
}
}
nsInstallFolder::~nsInstallFolder()
{
if (mFileSpec != nsnull)
delete mFileSpec;
}
void
nsInstallFolder::GetDirectoryPath(nsString& aDirectoryPath)
{
aDirectoryPath = "";
if (mFileSpec != nsnull)
{
// We want the a NATIVE path.
aDirectoryPath.SetString(mFileSpec->GetCString());
}
}
void
nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRelativePath)
{
if ( aFolderID.EqualsIgnoreCase("User Pick") )
{
PickDefaultDirectory();
return;
}
else if ( aFolderID.EqualsIgnoreCase("Installed") )
{
mFileSpec = new nsFileSpec(aRelativePath, PR_TRUE); // creates the directories to the relative path.
return;
}
else
{
PRInt32 folderDirSpecID = MapNameToEnum(aFolderID);
switch (folderDirSpecID)
{
case 100: /////////////////////////////////////////////////////////// Plugins
SetAppShellDirectory(nsSpecialFileSpec::App_PluginsDirectory );
break;
case 101: /////////////////////////////////////////////////////////// Program
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_CurrentProcessDirectory ));
break;
case 102: /////////////////////////////////////////////////////////// Communicator
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_CurrentProcessDirectory ));
break;
case 103: /////////////////////////////////////////////////////////// User Pick
// we should never be here.
mFileSpec = nsnull;
break;
case 104: /////////////////////////////////////////////////////////// Temporary
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_TemporaryDirectory ));
break;
case 105: /////////////////////////////////////////////////////////// Installed
// we should never be here.
mFileSpec = nsnull;
break;
case 106: /////////////////////////////////////////////////////////// Current User
SetAppShellDirectory(nsSpecialFileSpec::App_UserProfileDirectory50 );
break;
case 107: /////////////////////////////////////////////////////////// Preferences
SetAppShellDirectory(nsSpecialFileSpec::App_PrefsDirectory50 );
break;
case 108: /////////////////////////////////////////////////////////// OS Drive
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_DriveDirectory ));
break;
case 109: /////////////////////////////////////////////////////////// File URL
{
nsString tempFileURLString = aFolderID;
tempFileURLString += aRelativePath;
mFileSpec = new nsFileSpec( nsFileURL(tempFileURLString) );
}
break;
case 110: /////////////////////////////////////////////////////////// Components
SetAppShellDirectory(nsSpecialFileSpec::App_ComponentsDirectory );
break;
case 111: /////////////////////////////////////////////////////////// Chrome
SetAppShellDirectory(nsSpecialFileSpec::App_ChromeDirectory );
break;
case 200: /////////////////////////////////////////////////////////// Win System
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Win_SystemDirectory ));
break;
case 201: /////////////////////////////////////////////////////////// Windows
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Win_WindowsDirectory ));
break;
case 300: /////////////////////////////////////////////////////////// Mac System
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_SystemDirectory ));
break;
case 301: /////////////////////////////////////////////////////////// Mac Desktop
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_DesktopDirectory ));
break;
case 302: /////////////////////////////////////////////////////////// Mac Trash
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_TrashDirectory ));
break;
case 303: /////////////////////////////////////////////////////////// Mac Startup
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_StartupDirectory ));
break;
case 304: /////////////////////////////////////////////////////////// Mac Shutdown
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_StartupDirectory ));
break;
case 305: /////////////////////////////////////////////////////////// Mac Apple Menu
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_AppleMenuDirectory ));
break;
case 306: /////////////////////////////////////////////////////////// Mac Control Panel
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_ControlPanelDirectory ));
break;
case 307: /////////////////////////////////////////////////////////// Mac Extension
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_ExtensionDirectory ));
break;
case 308: /////////////////////////////////////////////////////////// Mac Fonts
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_FontsDirectory ));
break;
case 309: /////////////////////////////////////////////////////////// Mac Preferences
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_PreferencesDirectory ));
break;
case 310: /////////////////////////////////////////////////////////// Mac Documents
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_DocumentsDirectory ));
break;
case 400: /////////////////////////////////////////////////////////// Unix Local
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Unix_LocalDirectory ));
break;
case 401: /////////////////////////////////////////////////////////// Unix Lib
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Unix_LibDirectory ));
break;
case -1:
default:
mFileSpec = nsnull;
return;
}
#ifndef XP_MAC
if (aRelativePath.Length() > 0)
{
nsString tempPath(aRelativePath);
if (aRelativePath.Last() != '/' || aRelativePath.Last() != '\\')
tempPath += '/';
*mFileSpec += tempPath;
}
#endif
// make sure that the directory is created.
nsFileSpec(mFileSpec->GetCString(), PR_TRUE);
}
}
void nsInstallFolder::PickDefaultDirectory()
{
//FIX: Need to put up a dialog here and set mFileSpec
return;
}
/* MapNameToEnum
* maps name from the directory table to its enum */
PRInt32
nsInstallFolder::MapNameToEnum(const nsString& name)
{
int i = 0;
if ( name == "null")
return -1;
while ( DirectoryTable[i].directoryName[0] != 0 )
{
if ( name.EqualsIgnoreCase(DirectoryTable[i].directoryName) )
return DirectoryTable[i].folderEnum;
i++;
}
return -1;
}
static NS_DEFINE_IID(kFileLocatorIID, NS_IFILELOCATOR_IID);
static NS_DEFINE_IID(kFileLocatorCID, NS_FILELOCATOR_CID);
void
nsInstallFolder::SetAppShellDirectory(PRUint32 value)
{
nsIFileLocator * appShellLocator;
nsresult rv = nsComponentManager::CreateInstance(kFileLocatorCID,
nsnull,
kFileLocatorIID,
(void**) &appShellLocator);
if ( NS_SUCCEEDED(rv) )
{
mFileSpec = new nsFileSpec();
appShellLocator->GetFileLocation(value, mFileSpec);
NS_RELEASE(appShellLocator);
}
}

View File

@@ -0,0 +1,58 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef __NS_INSTALLFOLDER_H__
#define __NS_INSTALLFOLDER_H__
#include "nscore.h"
#include "prtypes.h"
#include "nsString.h"
#include "nsFileSpec.h"
#include "nsSpecialSystemDirectory.h"
class nsInstallFolder
{
public:
nsInstallFolder(const nsString& aFolderID);
nsInstallFolder(const nsString& aFolderID, const nsString& aRelativePath);
virtual ~nsInstallFolder();
void GetDirectoryPath(nsString& aDirectoryPath);
private:
nsFileSpec* mFileSpec;
void SetDirectoryPath(const nsString& aFolderID, const nsString& aRelativePath);
void PickDefaultDirectory();
PRInt32 MapNameToEnum(const nsString& name);
void SetAppShellDirectory(PRUint32 value);
};
#endif

View File

@@ -0,0 +1,52 @@
/* -*- Mode: C++; tab-width: 4; 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.
*/
#ifndef nsInstallObject_h__
#define nsInstallObject_h__
#include "prtypes.h"
class nsInstall;
class nsInstallObject
{
public:
/* Public Methods */
nsInstallObject(nsInstall* inInstall) {mInstall = inInstall; }
/* Override with your set-up action */
virtual PRInt32 Prepare() = 0;
/* Override with your Completion action */
virtual PRInt32 Complete() = 0;
/* Override with an explanatory string for the progress dialog */
virtual char* toString() = 0;
/* Override with your clean-up function */
virtual void Abort() = 0;
/* should these be protected? */
virtual PRBool CanUninstall() = 0;
virtual PRBool RegisterPackageNode() = 0;
protected:
nsInstall* mInstall;
};
#endif /* nsInstallObject_h__ */

View File

@@ -0,0 +1,986 @@
/* -*- Mode: C++; tab-width: 4; 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.
*/
#include "nsFileSpec.h"
#include "prmem.h"
#include "nsInstall.h"
#include "nsInstallPatch.h"
#include "nsInstallResources.h"
#include "nsIDOMInstallVersion.h"
#include "zlib.h"
#include "gdiff.h"
#include "VerReg.h"
#include "ScheduledTasks.h"
#include "plstr.h"
#include "xp_file.h" /* for XP_PlatformFileToURL */
#ifdef XP_MAC
#include "PatchableAppleSingle.h"
#endif
#define BUFSIZE 32768
#define OPSIZE 1
#define MAXCMDSIZE 12
#define SRCFILE 0
#define OUTFILE 1
#define getshort(s) (uint16)( ((uchar)*(s) << 8) + ((uchar)*((s)+1)) )
#define getlong(s) \
(uint32)( ((uchar)*(s) << 24) + ((uchar)*((s)+1) << 16 ) + \
((uchar)*((s)+2) << 8) + ((uchar)*((s)+3)) )
static int32 gdiff_parseHeader( pDIFFDATA dd );
static int32 gdiff_validateFile( pDIFFDATA dd, int file );
static int32 gdiff_valCRC32( pDIFFDATA dd, PRFileDesc* fh, uint32 chksum );
static int32 gdiff_ApplyPatch( pDIFFDATA dd );
static int32 gdiff_getdiff( pDIFFDATA dd, uchar *buffer, uint32 length );
static int32 gdiff_add( pDIFFDATA dd, uint32 count );
static int32 gdiff_copy( pDIFFDATA dd, uint32 position, uint32 count );
static int32 gdiff_validateFile( pDIFFDATA dd, int file );
nsInstallPatch::nsInstallPatch( nsInstall* inInstall,
const nsString& inVRName,
const nsString& inVInfo,
const nsString& inJarLocation,
PRInt32 *error)
: nsInstallObject(inInstall)
{
char tempTargetFile[MAXREGPATHLEN];
char* tempVersionString = inVRName.ToNewCString();
PRInt32 err = VR_GetPath(tempVersionString, MAXREGPATHLEN, tempTargetFile );
delete [] tempVersionString;
if (err != REGERR_OK)
{
*error = nsInstall::NO_SUCH_COMPONENT;
return;
}
nsString folderSpec(tempTargetFile);
mPatchFile = nsnull;
mTargetFile = nsnull;
mPatchedFile = nsnull;
mRegistryName = new nsString(inVRName);
mJarLocation = new nsString(inJarLocation);
mTargetFile = new nsFileSpec(folderSpec);
mVersionInfo = new nsInstallVersion();
mVersionInfo->Init(inVInfo);
}
nsInstallPatch::nsInstallPatch( nsInstall* inInstall,
const nsString& inVRName,
const nsString& inVInfo,
const nsString& inJarLocation,
const nsString& folderSpec,
const nsString& inPartialPath,
PRInt32 *error)
: nsInstallObject(inInstall)
{
if ((inInstall == nsnull) || (inVRName == "null") || (inJarLocation == "null"))
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
mPatchFile = nsnull;
mTargetFile = nsnull;
mPatchedFile = nsnull;
mRegistryName = new nsString(inVRName);
mJarLocation = new nsString(inJarLocation);
mVersionInfo = new nsInstallVersion();
mVersionInfo->Init(inVInfo);
mTargetFile = new nsFileSpec(folderSpec);
if(inPartialPath != "null")
*mTargetFile += inPartialPath;
}
nsInstallPatch::~nsInstallPatch()
{
if (mVersionInfo)
delete mVersionInfo;
if (mTargetFile)
delete mTargetFile;
if (mJarLocation)
delete mJarLocation;
if (mRegistryName)
delete mRegistryName;
if (mPatchedFile)
delete mPatchedFile;
if (mPatchFile)
delete mPatchFile;
}
PRInt32 nsInstallPatch::Prepare()
{
PRInt32 err;
PRBool deleteOldSrc;
if (mTargetFile == nsnull)
return nsInstall::INVALID_ARGUMENTS;
if (mTargetFile->Exists())
{
if (mTargetFile->IsFile())
{
err = nsInstall::SUCCESS;
}
else
{
err = nsInstall::FILE_IS_DIRECTORY;
}
}
else
{
err = nsInstall::FILE_DOES_NOT_EXIST;
}
if (err != nsInstall::SUCCESS)
{
return err;
}
err = mInstall->ExtractFileFromJar(*mJarLocation, mTargetFile, &mPatchFile);
nsFileSpec *fileName = nsnull;
nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) );
mInstall->GetPatch(&ikey, fileName);
if (fileName != nsnull)
{
deleteOldSrc = PR_TRUE;
}
else
{
fileName = mTargetFile;
deleteOldSrc = PR_FALSE;
}
err = NativePatch( *fileName, // the file to patch
*mPatchFile, // the patch that was extracted from the jarfile
&mPatchedFile); // the new patched file
if (err != nsInstall::SUCCESS)
{
return err;
}
PR_ASSERT(mPatchedFile != nsnull);
mInstall->AddPatch(&ikey, mPatchedFile );
if ( deleteOldSrc )
{
DeleteFileNowOrSchedule(*fileName );
}
return err;
}
PRInt32 nsInstallPatch::Complete()
{
if ((mInstall == nsnull) || (mVersionInfo == nsnull) || (mPatchedFile == nsnull) || (mTargetFile == nsnull))
{
return nsInstall::INVALID_ARGUMENTS;
}
PRInt32 err = nsInstall::SUCCESS;
nsFileSpec *fileName = nsnull;
nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) );
mInstall->GetPatch(&ikey, fileName);
if (fileName != nsnull && (*fileName == *mPatchedFile) )
{
// the patch has not been superceded--do final replacement
err = ReplaceFileNowOrSchedule( *mTargetFile, *mPatchedFile);
if ( 0 == err || nsInstall::REBOOT_NEEDED == err )
{
nsString tempVersionString;
mVersionInfo->ToString(tempVersionString);
char* tempRegName = mRegistryName->ToNewCString();
char* tempVersion = tempVersionString.ToNewCString();
err = VR_Install( tempRegName,
(char*) (const char *) nsNSPRPath(*mTargetFile),
tempVersion,
PR_FALSE );
delete [] tempRegName;
delete [] tempVersion;
}
else
{
err = nsInstall::UNEXPECTED_ERROR;
}
}
else
{
// nothing -- old intermediate patched file was
// deleted by a superceding patch
}
return err;
}
void nsInstallPatch::Abort()
{
nsFileSpec *fileName = nsnull;
nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) );
mInstall->GetPatch(&ikey, fileName);
if (fileName != nsnull && (*fileName == *mPatchedFile) )
{
DeleteFileNowOrSchedule( *mPatchedFile );
}
}
char* nsInstallPatch::toString()
{
char* buffer = new char[1024];
// FIX! sprintf( buffer, nsInstallResources::GetPatchFileString(), mPatchedFile->GetCString());
return buffer;
}
PRBool
nsInstallPatch::CanUninstall()
{
return PR_FALSE;
}
PRBool
nsInstallPatch::RegisterPackageNode()
{
return PR_FALSE;
}
PRInt32
nsInstallPatch::NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patchFile, nsFileSpec **newFile)
{
DIFFDATA *dd;
PRInt32 status = GDIFF_ERR_MEM;
char *tmpurl = NULL;
char *realfile = PL_strdup(nsNSPRPath(sourceFile)); // needs to be sourceFile!!!
nsFileSpec outFileSpec = sourceFile;
dd = (DIFFDATA *)PR_Calloc( 1, sizeof(DIFFDATA));
if (dd != NULL)
{
dd->databuf = (uchar*)PR_Malloc(BUFSIZE);
if (dd->databuf == NULL)
{
status = GDIFF_ERR_MEM;
goto cleanup;
}
dd->bufsize = BUFSIZE;
// validate patch header & check for special instructions
dd->fDiff = PR_Open (nsNSPRPath(patchFile), PR_RDONLY, 0666);
if (dd->fDiff != NULL)
{
status = gdiff_parseHeader(dd);
} else {
status = GDIFF_ERR_ACCESS;
}
#ifdef dono
#ifdef WIN32
/* unbind Win32 images */
if ( dd->bWin32BoundImage && status == GDIFF_OK ) {
tmpurl = WH_TempName( xpURL, NULL );
if ( tmpurl != NULL ) {
if (su_unbind( srcfile, srctype, tmpurl, xpURL ))
{
PL_strfree(realfile);
realfile = tmpurl;
realtype = xpURL;
}
}
else
status = GDIFF_ERR_MEM;
}
#endif
#endif
#ifdef XP_MAC
if ( dd->bMacAppleSingle && status == GDIFF_OK )
{
// create a tmp file, so that we can AppleSingle the src file
nsSpecialSystemDirectory tempMacFile(nsSpecialSystemDirectory::OS_TemporaryDirectory);
nsString srcName = sourceFile.GetLeafName();
tempMacFile.SetLeafName(srcName);
tempMacFile.MakeUnique();
// Encode!
// Encode src file, and put into temp file
FSSpec sourceSpec = sourceFile.GetFSSpec();
FSSpec tempSpec = tempMacFile.GetFSSpec();
status = PAS_EncodeFile(&sourceSpec, &tempSpec);
if (status == noErr)
{
// set
PL_strfree(realfile);
realfile = PL_strdup(nsNSPRPath(tempMacFile));
}
}
#endif
if (status != NS_OK)
goto cleanup;
// make a unique file at the same location of our source file (FILENAME-ptch.EXT)
nsString patchFileName = "-ptch";
nsString newFileName = sourceFile.GetLeafName();
PRInt32 index;
if ((index = newFileName.RFind(".")) > 0)
{
nsString extention;
nsString fileName;
newFileName.Right(extention, (newFileName.Length() - index) );
newFileName.Left(fileName, (newFileName.Length() - (newFileName.Length() - index)));
newFileName = fileName + patchFileName + extention;
} else {
newFileName += patchFileName;
}
outFileSpec.SetLeafName(newFileName); //????
outFileSpec.MakeUnique();
char *outFile = PL_strdup(nsNSPRPath(outFileSpec));
// apply patch to the source file
dd->fSrc = PR_Open ( realfile, PR_RDONLY, 0666);
dd->fOut = PR_Open ( outFile, PR_RDWR|PR_CREATE_FILE|PR_TRUNCATE, 0666);
if (dd->fSrc != NULL && dd->fOut != NULL)
{
status = gdiff_validateFile (dd, SRCFILE);
// specify why diff failed
if (status == GDIFF_ERR_CHECKSUM)
status = GDIFF_ERR_CHECKSUM_TARGET;
if (status == GDIFF_OK)
status = gdiff_ApplyPatch(dd);
if (status == GDIFF_OK)
status = gdiff_validateFile (dd, OUTFILE);
if (status == GDIFF_ERR_CHECKSUM)
status = GDIFF_ERR_CHECKSUM_RESULT;
if (status == GDIFF_OK)
{
*newFile = &outFileSpec;
if ( outFile != nsnull)
PL_strfree( outFile );
}
} else {
status = GDIFF_ERR_ACCESS;
}
}
#ifdef XP_MAC
if ( dd->bMacAppleSingle && status == GDIFF_OK )
{
// create another file, so that we can decode somewhere
nsFileSpec anotherName = outFileSpec;
anotherName.MakeUnique();
// Close the out file so that we can read it
PR_Close( dd->fOut );
dd->fOut = NULL;
FSSpec outSpec = outFileSpec.GetFSSpec();
FSSpec anotherSpec = anotherName.GetFSSpec();
status = PAS_DecodeFile(&outSpec, &anotherSpec);
if (status != noErr)
{
goto cleanup;
}
nsFileSpec parent;
outFileSpec.GetParent(parent);
outFileSpec.Delete(PR_FALSE);
anotherName.Copy(parent);
*newFile = &anotherName;
}
#endif
cleanup:
if ( dd != NULL )
{
if ( dd->fSrc != nsnull )
PR_Close( dd->fSrc );
if ( dd->fDiff != nsnull )
PR_Close( dd->fDiff );
if ( dd->fOut != nsnull )
{
PR_Close( dd->fOut );
}
if ( status != GDIFF_OK )
//XP_FileRemove( outfile, outtype );
newFile = NULL;
PR_FREEIF( dd->databuf );
PR_FREEIF( dd->oldChecksum );
PR_FREEIF( dd->newChecksum );
PR_DELETE(dd);
}
if ( tmpurl != NULL ) {
//XP_FileRemove( tmpurl, xpURL );
tmpurl = NULL;
PR_DELETE( tmpurl );
}
/* lets map any GDIFF error to nice SU errors */
switch (status)
{
case GDIFF_OK:
break;
case GDIFF_ERR_HEADER:
case GDIFF_ERR_BADDIFF:
case GDIFF_ERR_OPCODE:
case GDIFF_ERR_CHKSUMTYPE:
status = nsInstall::PATCH_BAD_DIFF;
break;
case GDIFF_ERR_CHECKSUM_TARGET:
status = nsInstall::PATCH_BAD_CHECKSUM_TARGET;
break;
case GDIFF_ERR_CHECKSUM_RESULT:
status = nsInstall::PATCH_BAD_CHECKSUM_RESULT;
break;
case GDIFF_ERR_OLDFILE:
case GDIFF_ERR_ACCESS:
case GDIFF_ERR_MEM:
case GDIFF_ERR_UNKNOWN:
default:
status = nsInstall::UNEXPECTED_ERROR;
break;
}
return status;
// return -1; //old return value
}
void*
nsInstallPatch::HashFilePath(const nsFilePath& aPath)
{
PRUint32 rv = 0;
char* cPath = PL_strdup(nsNSPRPath(aPath));
if(cPath != nsnull)
{
char ch;
char* filePath = PL_strdup(cPath);
PRUint32 cnt=0;
while ((ch = *filePath++) != 0)
{
// FYI: rv = rv*37 + ch
rv = ((rv << 5) + (rv << 2) + rv) + ch;
cnt++;
}
for (PRUint32 i=0; i<=cnt; i++)
*filePath--;
PL_strfree(filePath);
}
PL_strfree(cPath);
return (void*)rv;
}
/*---------------------------------------------------------
* gdiff_parseHeader()
*
* reads and validates the GDIFF header info
*---------------------------------------------------------
*/
static
int32 gdiff_parseHeader( pDIFFDATA dd )
{
int32 err = GDIFF_OK;
uint8 cslen;
uint8 oldcslen;
uint8 newcslen;
uint32 nRead;
uchar header[GDIFF_HEADERSIZE];
/* Read the fixed-size part of the header */
nRead = PR_Read (dd->fDiff, header, GDIFF_HEADERSIZE);
if ( nRead != GDIFF_HEADERSIZE ||
memcmp( header, GDIFF_MAGIC, GDIFF_MAGIC_LEN ) != 0 ||
header[GDIFF_VER_POS] != GDIFF_VER )
{
err = GDIFF_ERR_HEADER;
}
else
{
/* get the checksum information */
dd->checksumType = header[GDIFF_CS_POS];
cslen = header[GDIFF_CSLEN_POS];
if ( cslen > 0 )
{
oldcslen = cslen / 2;
newcslen = cslen - oldcslen;
PR_ASSERT( newcslen == oldcslen );
dd->checksumLength = oldcslen;
dd->oldChecksum = (uchar*)PR_MALLOC(oldcslen);
dd->newChecksum = (uchar*)PR_MALLOC(newcslen);
if ( dd->oldChecksum != NULL && dd->newChecksum != NULL )
{
nRead = PR_Read (dd->fDiff, dd->oldChecksum, oldcslen);
if ( nRead == oldcslen )
{
nRead = PR_Read (dd->fDiff, dd->newChecksum, newcslen);
if ( nRead != newcslen ) {
err = GDIFF_ERR_HEADER;
}
}
else {
err = GDIFF_ERR_HEADER;
}
}
else {
err = GDIFF_ERR_MEM;
}
}
/* get application data, if any */
if ( err == GDIFF_OK )
{
uint32 appdataSize;
uchar *buf;
uchar lenbuf[GDIFF_APPDATALEN];
nRead = PR_Read(dd->fDiff, lenbuf, GDIFF_APPDATALEN);
if ( nRead == GDIFF_APPDATALEN )
{
appdataSize = getlong(lenbuf);
if ( appdataSize > 0 )
{
buf = (uchar *)PR_MALLOC( appdataSize );
if ( buf != NULL )
{
nRead = PR_Read (dd->fDiff, buf, appdataSize);
if ( nRead == appdataSize )
{
if ( 0 == memcmp( buf, APPFLAG_W32BOUND, appdataSize ) )
dd->bWin32BoundImage = TRUE;
if ( 0 == memcmp( buf, APPFLAG_APPLESINGLE, appdataSize ) )
dd->bMacAppleSingle = TRUE;
}
else {
err = GDIFF_ERR_HEADER;
}
PR_DELETE( buf );
}
else {
err = GDIFF_ERR_MEM;
}
}
}
else {
err = GDIFF_ERR_HEADER;
}
}
}
return (err);
}
/*---------------------------------------------------------
* gdiff_validateFile()
*
* computes the checksum of the file and compares it to
* the value stored in the GDIFF header
*---------------------------------------------------------
*/
static
int32 gdiff_validateFile( pDIFFDATA dd, int file )
{
int32 result;
PRFileDesc* fh;
uchar* chksum;
/* which file are we dealing with? */
if ( file == SRCFILE ) {
fh = dd->fSrc;
chksum = dd->oldChecksum;
}
else { /* OUTFILE */
fh = dd->fOut;
chksum = dd->newChecksum;
}
/* make sure file's at beginning */
PR_Seek( fh, 0, PR_SEEK_SET );
/* calculate appropriate checksum */
switch (dd->checksumType)
{
case GDIFF_CS_NONE:
result = GDIFF_OK;
break;
case GDIFF_CS_CRC32:
if ( dd->checksumLength == CRC32_LEN )
result = gdiff_valCRC32( dd, fh, getlong(chksum) );
else
result = GDIFF_ERR_HEADER;
break;
case GDIFF_CS_MD5:
case GDIFF_CS_SHA:
default:
/* unsupported checksum type */
result = GDIFF_ERR_CHKSUMTYPE;
break;
}
/* reset file position to beginning and return status */
PR_Seek( fh, 0, PR_SEEK_SET );
return (result);
}
/*---------------------------------------------------------
* gdiff_valCRC32()
*
* computes the checksum of the file and compares it to
* the passed in checksum. Assumes file is positioned at
* beginning.
*---------------------------------------------------------
*/
static
int32 gdiff_valCRC32( pDIFFDATA dd, PRFileDesc* fh, uint32 chksum )
{
uint32 crc;
uint32 nRead;
crc = crc32(0L, Z_NULL, 0);
nRead = PR_Read (fh, dd->databuf, dd->bufsize);
while ( nRead > 0 )
{
crc = crc32( crc, dd->databuf, nRead );
nRead = PR_Read (fh, dd->databuf, dd->bufsize);
}
if ( crc == chksum )
return GDIFF_OK;
else
return GDIFF_ERR_CHECKSUM;
}
/*---------------------------------------------------------
* gdiff_ApplyPatch()
*
* Combines patch data with source file to produce the
* new target file. Assumes all three files have been
* opened, GDIFF header read, and all other setup complete
*
* The GDIFF patch is processed sequentially which random
* access is neccessary for the source file.
*---------------------------------------------------------
*/
static
int32 gdiff_ApplyPatch( pDIFFDATA dd )
{
int32 err;
XP_Bool done;
uint32 position;
uint32 count;
uchar opcode;
uchar cmdbuf[MAXCMDSIZE];
done = FALSE;
while ( !done ) {
err = gdiff_getdiff( dd, &opcode, OPSIZE );
if ( err != GDIFF_OK )
break;
switch (opcode)
{
case ENDDIFF:
done = TRUE;
break;
case ADD16:
err = gdiff_getdiff( dd, cmdbuf, ADD16SIZE );
if ( err == GDIFF_OK ) {
err = gdiff_add( dd, getshort( cmdbuf ) );
}
break;
case ADD32:
err = gdiff_getdiff( dd, cmdbuf, ADD32SIZE );
if ( err == GDIFF_OK ) {
err = gdiff_add( dd, getlong( cmdbuf ) );
}
break;
case COPY16BYTE:
err = gdiff_getdiff( dd, cmdbuf, COPY16BYTESIZE );
if ( err == GDIFF_OK ) {
position = getshort( cmdbuf );
count = *(cmdbuf + sizeof(short));
err = gdiff_copy( dd, position, count );
}
break;
case COPY16SHORT:
err = gdiff_getdiff( dd, cmdbuf, COPY16SHORTSIZE );
if ( err == GDIFF_OK ) {
position = getshort( cmdbuf );
count = getshort(cmdbuf + sizeof(short));
err = gdiff_copy( dd, position, count );
}
break;
case COPY16LONG:
err = gdiff_getdiff( dd, cmdbuf, COPY16LONGSIZE );
if ( err == GDIFF_OK ) {
position = getshort( cmdbuf );
count = getlong(cmdbuf + sizeof(short));
err = gdiff_copy( dd, position, count );
}
break;
case COPY32BYTE:
err = gdiff_getdiff( dd, cmdbuf, COPY32BYTESIZE );
if ( err == GDIFF_OK ) {
position = getlong( cmdbuf );
count = *(cmdbuf + sizeof(long));
err = gdiff_copy( dd, position, count );
}
break;
case COPY32SHORT:
err = gdiff_getdiff( dd, cmdbuf, COPY32SHORTSIZE );
if ( err == GDIFF_OK ) {
position = getlong( cmdbuf );
count = getshort(cmdbuf + sizeof(long));
err = gdiff_copy( dd, position, count );
}
break;
case COPY32LONG:
err = gdiff_getdiff( dd, cmdbuf, COPY32LONGSIZE );
if ( err == GDIFF_OK ) {
position = getlong( cmdbuf );
count = getlong(cmdbuf + sizeof(long));
err = gdiff_copy( dd, position, count );
}
break;
case COPY64:
/* we don't support 64-bit file positioning yet */
err = GDIFF_ERR_OPCODE;
break;
default:
err = gdiff_add( dd, opcode );
break;
}
if ( err != GDIFF_OK )
done = TRUE;
}
/* return status */
return (err);
}
/*---------------------------------------------------------
* gdiff_getdiff()
*
* reads the next "length" bytes of the diff into "buffer"
*
* XXX: need a diff buffer to optimize reads!
*---------------------------------------------------------
*/
static
int32 gdiff_getdiff( pDIFFDATA dd, uchar *buffer, uint32 length )
{
uint32 bytesRead;
bytesRead = PR_Read (dd->fDiff, buffer, length);
if ( bytesRead != length )
return GDIFF_ERR_BADDIFF;
return GDIFF_OK;
}
/*---------------------------------------------------------
* gdiff_add()
*
* append "count" bytes from diff file to new file
*---------------------------------------------------------
*/
static
int32 gdiff_add( pDIFFDATA dd, uint32 count )
{
int32 err = GDIFF_OK;
uint32 nRead;
uint32 chunksize;
while ( count > 0 ) {
chunksize = ( count > dd->bufsize) ? dd->bufsize : count;
nRead = PR_Read (dd->fDiff, dd->databuf, chunksize);
if ( nRead != chunksize ) {
err = GDIFF_ERR_BADDIFF;
break;
}
PR_Write (dd->fOut, dd->databuf, chunksize);
count -= chunksize;
}
return (err);
}
/*---------------------------------------------------------
* gdiff_copy()
*
* copy "count" bytes from "position" in source file
*---------------------------------------------------------
*/
static
int32 gdiff_copy( pDIFFDATA dd, uint32 position, uint32 count )
{
int32 err = GDIFF_OK;
uint32 nRead;
uint32 chunksize;
PR_Seek (dd->fSrc, position, PR_SEEK_SET);
while ( count > 0 ) {
chunksize = (count > dd->bufsize) ? dd->bufsize : count;
nRead = PR_Read (dd->fSrc, dd->databuf, chunksize);
if ( nRead != chunksize ) {
err = GDIFF_ERR_OLDFILE;
break;
}
PR_Write (dd->fOut, dd->databuf, chunksize);
count -= chunksize;
}
return (err);
}

View File

@@ -0,0 +1,79 @@
/* -*- Mode: C++; tab-width: 4; 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.
*/
#ifndef nsInstallPatch_h__
#define nsInstallPatch_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
#include "nsInstallFolder.h"
#include "nsInstallVersion.h"
class nsInstallPatch : public nsInstallObject
{
public:
nsInstallPatch( nsInstall* inInstall,
const nsString& inVRName,
const nsString& inVInfo,
const nsString& inJarLocation,
const nsString& folderSpec,
const nsString& inPartialPath,
PRInt32 *error);
nsInstallPatch( nsInstall* inInstall,
const nsString& inVRName,
const nsString& inVInfo,
const nsString& inJarLocation,
PRInt32 *error);
virtual ~nsInstallPatch();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
nsInstallVersion *mVersionInfo;
nsFileSpec *mTargetFile;
nsFileSpec *mPatchFile;
nsFileSpec *mPatchedFile;
nsString *mJarLocation;
nsString *mRegistryName;
PRInt32 NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patchfile, nsFileSpec **newFile);
void* HashFilePath(const nsFilePath& aPath);
};
#endif /* nsInstallPatch_h__ */

View File

@@ -0,0 +1,343 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Douglas Turner <dougt@netscape.com>
*/
#include "nsIXPInstallProgress.h"
#include "nsInstallProgressDialog.h"
#include "nsIAppShellComponentImpl.h"
#include "nsIServiceManager.h"
#include "nsIDocumentViewer.h"
#include "nsIContent.h"
#include "nsINameSpaceManager.h"
#include "nsIContentViewer.h"
#include "nsIDOMElement.h"
#include "nsINetService.h"
#include "nsIWebShell.h"
#include "nsIWebShellWindow.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID( kAppShellServiceCID, NS_APPSHELL_SERVICE_CID );
static NS_DEFINE_IID( kNetServiceCID, NS_NETSERVICE_CID );
// Utility to set element attribute.
static nsresult setAttribute( nsIDOMXULDocument *doc,
const char *id,
const char *name,
const nsString &value ) {
nsresult rv = NS_OK;
if ( doc ) {
// Find specified element.
nsCOMPtr<nsIDOMElement> elem;
rv = doc->GetElementById( id, getter_AddRefs( elem ) );
if ( elem ) {
// Set the text attribute.
rv = elem->SetAttribute( name, value );
if ( NS_SUCCEEDED( rv ) ) {
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: SetAttribute failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetElementById failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
} else {
rv = NS_ERROR_NULL_POINTER;
}
return rv;
}
// Utility to get element attribute.
static nsresult getAttribute( nsIDOMXULDocument *doc,
const char *id,
const char *name,
nsString &value ) {
nsresult rv = NS_OK;
if ( doc ) {
// Find specified element.
nsCOMPtr<nsIDOMElement> elem;
rv = doc->GetElementById( id, getter_AddRefs( elem ) );
if ( elem ) {
// Set the text attribute.
rv = elem->GetAttribute( name, value );
if ( NS_SUCCEEDED( rv ) ) {
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: SetAttribute failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetElementById failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
} else {
rv = NS_ERROR_NULL_POINTER;
}
return rv;
}
nsInstallProgressDialog::nsInstallProgressDialog()
{
NS_INIT_REFCNT();
mWindow = nsnull;
mDocument = nsnull;
}
nsInstallProgressDialog::~nsInstallProgressDialog()
{
}
NS_IMPL_ADDREF( nsInstallProgressDialog );
NS_IMPL_RELEASE( nsInstallProgressDialog );
NS_IMETHODIMP
nsInstallProgressDialog::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL) {
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if (aIID.Equals(nsIXPInstallProgress::GetIID())) {
*aInstancePtr = (void*) ((nsInstallProgressDialog*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIXULWindowCallbacks::GetIID())) {
*aInstancePtr = (void*) ((nsIXULWindowCallbacks*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*) (nsISupports*)((nsIXPInstallProgress*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_ERROR_NO_INTERFACE;
}
NS_IMETHODIMP
nsInstallProgressDialog::BeforeJavascriptEvaluation()
{
nsresult rv = NS_OK;
// Get app shell service.
nsIAppShellService *appShell;
rv = nsServiceManager::GetService( kAppShellServiceCID,
nsIAppShellService::GetIID(),
(nsISupports**)&appShell );
if ( NS_SUCCEEDED( rv ) )
{
// Open "progress" dialog.
nsIURL *url;
rv = NS_NewURL( &url, "resource:/res/xpinstall/progress.xul" );
if ( NS_SUCCEEDED(rv) )
{
nsIWebShellWindow *newWindow;
rv = appShell->CreateTopLevelWindow( nsnull,
url,
PR_TRUE,
newWindow,
nsnull,
this, // callbacks??
0,
0 );
if ( NS_SUCCEEDED( rv ) )
{
mWindow = newWindow;
NS_RELEASE( newWindow );
if (mWindow != nsnull)
mWindow->Show(PR_TRUE);
}
else
{
DEBUG_PRINTF( PR_STDOUT, "Error creating progress dialog, rv=0x%X\n", (int)rv );
}
NS_RELEASE( url );
}
nsServiceManager::ReleaseService( kAppShellServiceCID, appShell );
}
else
{
DEBUG_PRINTF( PR_STDOUT, "Unable to get app shell service, rv=0x%X\n", (int)rv );
}
return NS_OK;
}
NS_IMETHODIMP
nsInstallProgressDialog::AfterJavascriptEvaluation()
{
if (mWindow)
{
mWindow->Close();
}
return NS_OK;
}
NS_IMETHODIMP
nsInstallProgressDialog::InstallStarted(const char *UIPackageName)
{
setAttribute( mDocument, "dialog.uiPackageName", "value", nsString(UIPackageName) );
return NS_OK;
}
NS_IMETHODIMP
nsInstallProgressDialog::ItemScheduled(const char *message)
{
PRInt32 maxChars = 40;
nsString theMessage(message);
PRInt32 len = theMessage.Length();
if (len > maxChars)
{
PRInt32 offset = (len/2) - ((len - maxChars)/2);
PRInt32 count = (len - maxChars);
theMessage.Cut(offset, count);
theMessage.Insert(nsString("..."), offset);
}
setAttribute( mDocument, "dialog.currentAction", "value", theMessage );
nsString aValue;
getAttribute( mDocument, "data.canceled", "value", aValue );
if (aValue.EqualsIgnoreCase("true"))
return -1;
return NS_OK;
}
NS_IMETHODIMP
nsInstallProgressDialog::InstallFinalization(const char *message, PRInt32 itemNum, PRInt32 totNum)
{
PRInt32 maxChars = 40;
nsString theMessage(message);
PRInt32 len = theMessage.Length();
if (len > maxChars)
{
PRInt32 offset = (len/2) - ((len - maxChars)/2);
PRInt32 count = (len - maxChars);
theMessage.Cut(offset, count);
theMessage.Insert(nsString("..."), offset);
}
setAttribute( mDocument, "dialog.currentAction", "value", theMessage );
nsresult rv = NS_OK;
char buf[16];
PR_snprintf( buf, sizeof buf, "%lu", totNum );
setAttribute( mDocument, "dialog.progress", "max", buf );
if (totNum != 0)
{
PR_snprintf( buf, sizeof buf, "%lu", ((totNum-itemNum)/totNum) );
}
else
{
PR_snprintf( buf, sizeof buf, "%lu", 0 );
}
setAttribute( mDocument, "dialog.progress", "value", buf );
return NS_OK;
}
NS_IMETHODIMP
nsInstallProgressDialog::InstallAborted()
{
return NS_OK;
}
// Do startup stuff from C++ side.
NS_IMETHODIMP
nsInstallProgressDialog::ConstructBeforeJavaScript(nsIWebShell *aWebShell)
{
nsresult rv = NS_OK;
// Get content viewer from the web shell.
nsCOMPtr<nsIContentViewer> contentViewer;
rv = aWebShell ? aWebShell->GetContentViewer(getter_AddRefs(contentViewer))
: NS_ERROR_NULL_POINTER;
if ( contentViewer ) {
// Up-cast to a document viewer.
nsCOMPtr<nsIDocumentViewer> docViewer( do_QueryInterface( contentViewer, &rv ) );
if ( docViewer ) {
// Get the document from the doc viewer.
nsCOMPtr<nsIDocument> document;
rv = docViewer->GetDocument(*getter_AddRefs(document));
if ( document ) {
// Upcast to XUL document.
mDocument = do_QueryInterface( document, &rv );
if ( ! mDocument )
{
DEBUG_PRINTF( PR_STDOUT, "%s %d: Upcast to nsIDOMXULDocument failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
}
else
{
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetDocument failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
}
else
{
DEBUG_PRINTF( PR_STDOUT, "%s %d: Upcast to nsIDocumentViewer failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
}
else
{
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetContentViewer failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
return rv;
}

View File

@@ -0,0 +1,67 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Douglas Turner <dougt@netscape.com>
*/
#ifndef __nsInstallProgressDialog_h__
#define __nsInstallProgressDialog_h__
#include "nsIXPInstallProgress.h"
#include "nsISupports.h"
#include "nsISupportsUtils.h"
#include "nsCOMPtr.h"
#include "nsIWebShell.h"
#include "nsIWebShellWindow.h"
#include "nsIXULWindowCallbacks.h"
#include "nsIDocument.h"
#include "nsIDOMXULDocument.h"
class nsInstallProgressDialog : public nsIXPInstallProgress, public nsIXULWindowCallbacks
{
public:
nsInstallProgressDialog();
virtual ~nsInstallProgressDialog();
NS_DECL_ISUPPORTS
NS_IMETHOD BeforeJavascriptEvaluation();
NS_IMETHOD AfterJavascriptEvaluation();
NS_IMETHOD InstallStarted(const char *UIPackageName);
NS_IMETHOD ItemScheduled(const char *message);
NS_IMETHOD InstallFinalization(const char *message, PRInt32 itemNum, PRInt32 totNum);
NS_IMETHOD InstallAborted();
// Declare implementations of nsIXULWindowCallbacks interface functions.
NS_IMETHOD ConstructBeforeJavaScript(nsIWebShell *aWebShell);
NS_IMETHOD ConstructAfterJavaScript(nsIWebShell *aWebShell) { return NS_OK; }
private:
nsCOMPtr<nsIDOMXULDocument> mDocument;
nsCOMPtr<nsIWebShellWindow> mWindow;
};
#endif

View File

@@ -0,0 +1,67 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#include "nsInstallResources.h"
char* nsInstallResources::GetInstallFileString(void)
{
return "Installing: %s";
}
char* nsInstallResources::GetReplaceFileString(void)
{
return "Replacing %s";
}
char* nsInstallResources::GetDeleteFileString(void)
{
return "Deleting file: %s";
}
char* nsInstallResources::GetDeleteComponentString(void)
{
return "Deleting component: %s";
}
char* nsInstallResources::GetExecuteString(void)
{
return "Executing: %s";
}
char* nsInstallResources::GetExecuteWithArgsString(void)
{
return "Executing: %s with argument: %s";
}
char* nsInstallResources::GetPatchFileString(void)
{
return "Patching: %s";
}
char* nsInstallResources::GetUninstallString(void)
{
return "Uninstalling: %s";
}

View File

@@ -0,0 +1,45 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef __NS_INSTALLRESOURCES_H__
#define __NS_INSTALLRESOURCES_H__
class nsInstallResources
{
public:
static char* GetInstallFileString(void);
static char* GetReplaceFileString(void);
static char* GetDeleteFileString(void);
static char* GetDeleteComponentString(void);
static char* GetExecuteString(void);
static char* GetExecuteWithArgsString(void);
static char* GetPatchFileString(void);
static char* GetUninstallString(void);
};
#endif

View File

@@ -0,0 +1,359 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsSoftwareUpdate.h"
#include "nsSoftwareUpdateStream.h"
#include "nsInstallTrigger.h"
#include "nsIDOMInstallTriggerGlobal.h"
#include "nscore.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPref.h"
#include "nsRepository.h"
#include "nsIServiceManager.h"
#include "nsSpecialSystemDirectory.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIInstallTrigger_IID, NS_IDOMINSTALLTRIGGERGLOBAL_IID);
static NS_DEFINE_IID(kIInstallTrigger_CID, NS_SoftwareUpdateInstallTrigger_CID);
nsInstallTrigger::nsInstallTrigger()
{
mScriptObject = nsnull;
NS_INIT_REFCNT();
}
nsInstallTrigger::~nsInstallTrigger()
{
}
NS_IMETHODIMP
nsInstallTrigger::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL)
{
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if ( aIID.Equals(kIScriptObjectOwnerIID))
{
*aInstancePtr = (void*) ((nsIScriptObjectOwner*)this);
AddRef();
return NS_OK;
}
else if ( aIID.Equals(kIInstallTrigger_IID) )
{
*aInstancePtr = (void*) ((nsIDOMInstallTriggerGlobal*)this);
AddRef();
return NS_OK;
}
else if ( aIID.Equals(kISupportsIID) )
{
*aInstancePtr = (void*)(nsISupports*)(nsIScriptObjectOwner*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsInstallTrigger)
NS_IMPL_RELEASE(nsInstallTrigger)
NS_IMETHODIMP
nsInstallTrigger::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
nsresult res = NS_OK;
if (nsnull == mScriptObject)
{
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
res = NS_NewScriptInstallTriggerGlobal( aContext,
(nsISupports *)(nsIDOMInstallTriggerGlobal*)this,
(nsISupports *)global,
&mScriptObject);
NS_IF_RELEASE(global);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
nsInstallTrigger::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
static NS_DEFINE_IID(kPrefsIID, NS_IPREF_IID);
static NS_DEFINE_IID(kPrefsCID, NS_PREF_CID);
NS_IMETHODIMP
nsInstallTrigger::UpdateEnabled(PRBool* aReturn)
{
nsIPref * prefs;
nsresult rv = nsServiceManager::GetService(kPrefsCID,
kPrefsIID,
(nsISupports**) &prefs);
if ( NS_SUCCEEDED(rv) )
{
rv = prefs->GetBoolPref( (const char*) AUTOUPDATE_ENABLE_PREF, aReturn);
if (NS_FAILED(rv))
{
*aReturn = PR_FALSE;
}
NS_RELEASE(prefs);
}
else
{
*aReturn = PR_FALSE; /* no prefs manager. set to false */
}
//FIX!!!!!!!!!!
*aReturn = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn)
{
nsString localFile;
CreateTempFileFromURL(aURL, localFile);
// start the download (this will clean itself up)
nsSoftwareUpdateListener *downloader = new nsSoftwareUpdateListener(aURL, localFile, aFlags);
*aReturn = NS_OK; // maybe we should do something more.
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn)
{
nsString localFile;
CreateTempFileFromURL(aURL, localFile);
// start the download (this will clean itself up)
nsSoftwareUpdateListener *downloader = new nsSoftwareUpdateListener(aURL, localFile, 0);
*aReturn = NS_OK; // maybe we should do something more.
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn)
{
return NS_OK;
}
// this will take a nsIUrl, and create a temporary file. If it is local, we just us it.
void
nsInstallTrigger::CreateTempFileFromURL(const nsString& aURL, nsString& tempFileString)
{
// Checking to see if the url is local
if ( aURL.EqualsIgnoreCase("file://", 7) )
{
tempFileString.SetString( nsNSPRPath(nsFileURL(aURL)) );
}
else
{
nsSpecialSystemDirectory tempFile(nsSpecialSystemDirectory::OS_TemporaryDirectory);
PRInt32 result = aURL.RFind("/");
if (result != -1)
{
nsString jarName;
aURL.Right(jarName, (aURL.Length() - result) );
PRInt32 argOffset = jarName.RFind("?");
if (argOffset != -1)
{
// we need to remove ? and everything after it
jarName.Truncate(argOffset);
}
tempFile += jarName;
}
else
{
tempFile += "xpinstall.jar";
}
tempFile.MakeUnique();
tempFileString.SetString( nsNSPRPath( nsFilePath(tempFile) ) );
}
}
/////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////
nsInstallTriggerFactory::nsInstallTriggerFactory(void)
{
NS_INIT_REFCNT();
}
nsInstallTriggerFactory::~nsInstallTriggerFactory(void)
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
NS_IMETHODIMP
nsInstallTriggerFactory::QueryInterface(const nsIID &aIID, void **aResult)
{
if (! aResult)
return NS_ERROR_NULL_POINTER;
// Always NULL result, in case of failure
*aResult = nsnull;
if (aIID.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsISupports*, this);
AddRef();
return NS_OK;
} else if (aIID.Equals(kIFactoryIID)) {
*aResult = NS_STATIC_CAST(nsIFactory*, this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsInstallTriggerFactory);
NS_IMPL_RELEASE(nsInstallTriggerFactory);
NS_IMETHODIMP
nsInstallTriggerFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
if (! aResult)
return NS_ERROR_NULL_POINTER;
*aResult = nsnull;
nsresult rv;
nsInstallTrigger *inst = new nsInstallTrigger();
if (! inst)
return NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(rv = inst->QueryInterface(aIID, aResult)))
{
// We didn't get the right interface.
NS_ERROR("didn't support the interface you wanted");
}
return rv;
}
NS_IMETHODIMP
nsInstallTriggerFactory::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}

Some files were not shown because too many files have changed in this diff Show More