Bug 652376: Remove xpinstall dead code. r=dveditz

This commit is contained in:
Dave Townsend 2011-12-02 10:19:22 -08:00
parent 51a2a81fd3
commit d60ed5f8dc
85 changed files with 0 additions and 7322 deletions

View File

@ -1,57 +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 Communicator client code, released
# March 31, 1998.
#
# 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):
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
# Samir Gehani <sgehani@netscape.com>
# Dave Townsend <dtownsend@oxymoronical.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either of 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 = xpinstall
DIRS = public src
ifdef ENABLE_TESTS
DIRS += tests
endif
include $(topsrcdir)/config/rules.mk

View File

@ -1,65 +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 Communicator client code, released
# March 31, 1998.
#
# 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):
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
# Dave Townsend <dtownsend@oxymoronical.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either of 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 = xpinstall
GRE_MODULE = 1
XPIDLSRCS = \
nsIXPIDialogService.idl \
nsIXPIProgressDialog.idl \
nsIXPInstallManager.idl \
nsIXPIInstallInfo.idl \
nsPICertNotification.idl \
$(NULL)
EXPORTS = \
nsIDOMInstallTriggerGlobal.h \
nsSoftwareUpdateIIDs.h \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -1,82 +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):
* Dave Townsend <dtownsend@oxymoronical.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 nsIDOMInstallTriggerGlobal_h__
#define nsIDOMInstallTriggerGlobal_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#include "nsXPITriggerInfo.h"
#include "nsIXPIInstallInfo.h"
#define NS_IDOMINSTALLTRIGGERGLOBAL_IID \
{ 0x23bb93a4, 0xdaee, 0x4a47, \
{0x87, 0x76, 0xb1, 0x72, 0x35, 0x86, 0x2d, 0xac}}
class nsIDOMInstallTriggerGlobal : public nsISupports {
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOMINSTALLTRIGGERGLOBAL_IID)
enum {
NOT_FOUND = -5,
MAJOR_DIFF = 4,
MINOR_DIFF = 3,
REL_DIFF = 2,
BLD_DIFF = 1,
EQUAL = 0
};
NS_IMETHOD GetOriginatingURI(nsIScriptGlobalObject* aGlobalObject, nsIURI * *aUri)=0;
NS_IMETHOD UpdateEnabled(nsIScriptGlobalObject* aGlobalObject, bool aUseWhitelist, bool* aReturn)=0;
NS_IMETHOD UpdateEnabled(nsIURI* aURI, bool aUseWhitelist, bool* aReturn)=0;
NS_IMETHOD StartInstall(nsIXPIInstallInfo* aInstallInfo, bool* aReturn)=0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIDOMInstallTriggerGlobal,
NS_IDOMINSTALLTRIGGERGLOBAL_IID)
extern nsresult NS_InitInstallTriggerGlobalClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" nsresult NS_NewScriptInstallTriggerGlobal(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMInstallTriggerGlobal_h__

View File

@ -1,107 +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 XPInstall.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.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 "nsISupports.idl"
interface nsIDOMWindow;
interface nsIXPIProgressDialog;
interface nsIObserver;
/**
* A service provided by embedding applications to override
* the default XUL implmementation of XPInstall dialogs.
*
* Embedding applications which wish to override the default
* XUL dialogs need to create a component which implements
* this interface and registers with the Contract ID
* "@mozilla.org/embedui/xpinstall-dialog-service;1"
*/
[scriptable, uuid(8cdd8baa-1dd2-11b2-909a-f0178da5c5ff)]
interface nsIXPIDialogService : nsISupports
{
/**
* @brief Ask the user if it's OK to install
*
* When called the XPIDialogService implementation should pose an
* install confirmation dialog and return the user's response
*
* @param parent a window that can be used to parent the modal dialog
*
* @param packageList For each install package there will be three strings,
* a display name, a source URL, and a the name of the
* organization that signed this install. Note that the
* name of the signer is not verified. Verification
* happens when the the install has completely downloaded.
* Your user interface should only suggest that the
* install may be signed by this organization name.
* Note that an unsigned archive is indicated by an
* empty string.
*
* @param count The number of strings in the packageList. This
* will always be three times the number of
* packages.
*
* @return true to install, false to cancel
*/
boolean confirmInstall(in nsIDOMWindow parent,
[array, size_is(count)] in wstring packageList,
in unsigned long count);
/**
* @brief Create and open a download-and-install progress dialog
*
* When called the XPIDialogService implementation creates and opens
* a dialog to display the status of the install. When the dialog
* is ready to be used then the observer must be called: the subject
* is an nsIXPIProgressDialog that nsXPInstallManager can use to control
* the dialog, the topic is "xpinstall-progress" and the data is "open".
*
* If the user wishes to cancel the download, the dialog can call the
* observe method with the same subject and topic and the data "cancel".
*
* @note Unless this routine throws an exception the observer <b>must</b>
* be called or nsXPInstallManager will wait forever and never clean
* itself up.
*
* @param packageList three strings per package as in confirmInstall()
* @param count the number of strings in the list
* @param observer nsIObserver to receive messages from the dialog
*/
void openProgressDialog([array, size_is(count)] in wstring packageList,
in unsigned long count,
in nsIObserver observer);
};

View File

@ -1,74 +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 XPInstall.
*
* The Initial Developer of the Original Code is
* Dave Townsend <dtownsend@oxymoronical.com>.
*
* Portions created by the Initial Developer are Copyright (C) 2007
* 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"
[ptr] native triggerInfoPtr(nsXPITriggerInfo);
interface nsIDOMWindow;
interface nsIDocShell;
interface nsIURI;
/**
* Interface holding information about a triggered install that can be passed
* to and from script.
*/
[scriptable, uuid(5a4a775c-e452-4cf2-8ff8-d327ae24aec6)]
interface nsIXPIInstallInfo : nsISupports
{
/**
* The install triggers supplied by the install.
*/
[noscript, notxpcom] attribute triggerInfoPtr triggerInfo;
/**
* The original window that initiated the install.
*/
readonly attribute nsIDOMWindow originatingWindow;
/**
* The original URI calling the install. This is the URI that would have been
* checked against the whitelist if necessary.
*/
readonly attribute nsIURI originatingURI;
/**
* The chome type of the install.
*/
readonly attribute PRUint32 chromeType;
};

View File

@ -1,80 +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 XPInstall.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.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 "nsISupports.idl"
/**
* Interface to display XPInstall download and install status.
*/
[scriptable, uuid(ce8f744e-d5a5-41b3-911f-0fee3008b64e)]
interface nsIXPIProgressDialog : nsISupports
{
/**
* state values for onStateChange
*/
const short DOWNLOAD_START = 0;
const short DOWNLOAD_DONE = 1;
const short INSTALL_START = 2;
const short INSTALL_DONE = 3;
const short DIALOG_CLOSE = 4;
/**
* basic info to control the install progress dialog. The dialog can
* go away any time after it has received the DIALOG_CLOSE state message
* but needs to accept messages until that time even if it is not visible.
*
* Normally for each install package the dialog will receive the download
* and install messages in START/DONE pairs, but in the case of a download
* error the dialog will be sent only the DOWNLOAD_START followed by an
* INSTALL_DONE message with the value nsInstall::DOWNLOAD_ERROR
*
* @param index the package this message is about of those passed into
* openProgressDialog. ignored when state==DIALOG_CLOSE
* @param state the kind of message
* @param value final result when state==INSTALL_DONE, otherwise ignored
*/
void onStateChange( in unsigned long index, in short state, in long value );
/**
* download progress
*
* @param index the package to which this refers
* @param value number of bytes downloaded
* @param maxValue the total size
*/
void onProgress( in unsigned long index, in unsigned long long value, in unsigned long long maxValue );
};

View File

@ -1,84 +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 XPInstall.
*
* The Initial Developer of the Original Code is Ben Goodger.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@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 "nsISupports.idl"
interface nsIXPIProgressDialog;
interface nsIXPIInstallInfo;
/**
* Interface to XPInstallManager - manages download and install operations.
*/
[scriptable, uuid(83fdd52f-2d34-4e22-981d-cf3c4ae76faa)]
interface nsIXPInstallManager : nsISupports
{
/**
* Initiates a download and install operation of the supplied URLs
* and sends notifications to the supplied listener.
* @param aURLs array of XPI urls to download and install
* @param aURLCount number of XPI urls in aURLs
* @param aListener a listener to receive status notifications
*/
void initManagerFromChrome([array, size_is(aURLCount)] in wstring aURLs,
in unsigned long aURLCount,
in nsIXPIProgressDialog aListener);
/**
* Initiates a set of downloads and checks the supplied hashes after
* download. Just like initManagerFromChrome() in all other respects
* @param aURLs array of XPI urls to download and install
* @param aHashes array of hash strings to validate. The entire array
* or individual hashes can be null to indicate no
* checking. If supplied looks like "type:hash", like
* "md5:3232bc5624041c507db0965324188024".
* Supports the types in nsICryptoHash
* @param aURLCount number of XPI urls in aURLs and aHashes
* @param aListener a listener to receive status notifications
*/
void initManagerWithHashes([array, size_is(aURLCount)] in wstring aURLs,
[array, size_is(aURLCount)] in string aHashes,
in unsigned long aURLCount,
in nsIXPIProgressDialog aListener);
/**
* Initiates a set of downloads based on an install info object. Will
* display confirmation dialog as if the install info had been supplied
* by content.
* @param aInstallInfo The install info object providing install triggers
* and script context for the install.
*/
void initManagerWithInstallInfo(in nsIXPIInstallInfo aInstallInfo);
};

View File

@ -1,48 +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 XPInstall Signing.
*
* The Initial Developer of the Original Code is Doug Turner.
* Portions created by the Initial Developer are Copyright (C) 2002
* 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"
interface nsIURI;
interface nsIPrincipal;
[uuid(42cd7162-ea4a-4088-9888-63ea5095869e)]
interface nsPICertNotification : nsISupports
{
void onCertAvailable(in nsIURI aURI,
in nsISupports aContext,
in PRUint32 aStatus,
in nsIPrincipal aPrincipal);
};

View File

@ -1,62 +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 Communicator client code, released
* March 31, 1998.
*
* 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):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
* Dave Townsend <dtownsend@oxymoronical.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 nsSoftwareUpdateIIDs_h___
#define nsSoftwareUpdateIIDs_h___
#define NS_SoftwareUpdateInstallTrigger_CID \
{ /* 18c2f98d-b09f-11d2-bcde-00805f0e1353 */ \
0x18c2f98d, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
}
#define NS_XPInstallManager_CID \
{ /* {6a4d4c1e-a74a-4320-8124-16233a0183d6} */ \
0x6a4d4c1e, \
0xa74a, \
0x4320, \
{ 0x81, 0x24, 0x16, 0x23, 0x3a, 0x1, 0x83, 0xd6} \
}
#endif /* nsSoftwareUpdateIIDs_h___ */

View File

@ -1,2 +0,0 @@
pref("xpinstall.enabled", true);
pref("xpinstall.whitelist.required", true);

View File

@ -1,279 +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 XPInstall Signing.
*
* The Initial Developer of the Original Code is Doug Turner.
* Portions created by the Initial Developer are Copyright (C) 2002
* 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 "zlib.h"
#include "zipstruct.h"
#include "CertReader.h"
#include "nsCRT.h"
#include "nsIServiceManager.h"
#include "nsISignatureVerifier.h"
#include "nsIInputStream.h"
#include "nsIPrincipal.h"
#include "nsIURI.h"
#include "nsPICertNotification.h"
#include "nsNetUtil.h"
// just a guess at the max size of the cert.
#define MAX_SIGNATURE_SIZE (32*1024)
/*
* x t o i n t
*
* Converts a two byte ugly endianed integer
* to our platform's integer.
*
*/
static unsigned int xtoint (unsigned char *ii)
{
return (int) (ii [0]) | ((int) ii [1] << 8);
}
/*
* x t o l o n g
*
* Converts a four byte ugly endianed integer
* to our platform's integer.
*
*/
static unsigned long xtolong (unsigned char *ll)
{
unsigned long ret;
ret = ((((unsigned long) ll [0]) << 0) |
(((unsigned long) ll [1]) << 8) |
(((unsigned long) ll [2]) << 16) |
(((unsigned long) ll [3]) << 24) );
return ret;
}
static int my_inflate(unsigned char* compr, PRUint32 comprLen, unsigned char* uncompr, PRUint32 uncomprLen)
{
int err;
z_stream d_stream; /* decompression stream */
memset (&d_stream, 0, sizeof (d_stream));
// buffer is way to small to even deal with.
if (uncomprLen < 10)
return -1;
*uncompr = '\0';
if (inflateInit2 (&d_stream, -MAX_WBITS) != Z_OK)
return -1;
d_stream.next_in = compr;
d_stream.avail_in = (uInt)comprLen;
d_stream.next_out = uncompr;
d_stream.avail_out = (uInt)uncomprLen;
err = inflate(&d_stream, Z_NO_FLUSH);
if (err != Z_OK && err != Z_STREAM_END) {
inflateEnd(&d_stream);
return -1;
}
err = inflateEnd(&d_stream);
if (err != Z_OK) {
return -1;
}
return 0;
}
CertReader::CertReader(nsIURI* aURI, nsISupports* aContext, nsPICertNotification* aObs):
mContext(aContext),
mURI(aURI),
mObserver(aObs)
{
}
CertReader::~CertReader()
{
}
NS_IMPL_ISUPPORTS2(CertReader, nsIStreamListener, nsIRequestObserver)
NS_IMETHODIMP
CertReader::OnStartRequest(nsIRequest *request, nsISupports* context)
{
mVerifier = do_GetService(SIGNATURE_VERIFIER_CONTRACTID);
if (!mVerifier)
return NS_BINDING_ABORTED;
nsCOMPtr<nsILoadGroup> loadGroup;
nsresult rv = request->GetLoadGroup(getter_AddRefs(loadGroup));
if (NS_SUCCEEDED(rv) && loadGroup)
loadGroup->RemoveRequest(request, nsnull, NS_BINDING_RETARGETED);
mLeftoverBuffer.Truncate();
return NS_OK;
}
NS_IMETHODIMP
CertReader::OnDataAvailable(nsIRequest *request,
nsISupports* context,
nsIInputStream *aIStream,
PRUint32 aSourceOffset,
PRUint32 aLength)
{
if (!mVerifier)
return NS_BINDING_ABORTED;
char buf[4096];
PRUint32 amt, size;
nsresult rv;
while (aLength)
{
size = NS_MIN(aLength, sizeof(buf));
rv = aIStream->Read(buf, size, &amt);
if (NS_FAILED(rv))
return rv;
aLength -= amt;
mLeftoverBuffer.Append(buf, amt);
if (mLeftoverBuffer.Length() < ZIPLOCAL_SIZE)
continue;
const char* caret = mLeftoverBuffer.get();
ZipLocal_* ziplocal = (ZipLocal_*) caret;
if (xtolong(ziplocal->signature) != LOCALSIG)
return NS_BINDING_ABORTED;
// did we read the entire file entry into memory?
PRUint32 fileEntryLen = (ZIPLOCAL_SIZE +
xtoint(ziplocal->filename_len) +
xtoint(ziplocal->extrafield_len) +
xtolong(ziplocal->size));
// prevent downloading a huge file on an unsigned cert
if (fileEntryLen > MAX_SIGNATURE_SIZE)
return NS_BINDING_ABORTED;
if (mLeftoverBuffer.Length() < fileEntryLen)
{
// we are just going to buffer and continue.
continue;
}
// the assumption here is that we have the fileEntry in mLeftoverBuffer
int err = 0;
unsigned char* orgData = nsnull;
unsigned char* sigData = nsnull;
const char* data = (caret +
ZIPLOCAL_SIZE +
xtoint(ziplocal->filename_len) +
xtoint(ziplocal->extrafield_len));
PRUint32 sigSize = 0;
PRUint32 orgSize = xtolong ((unsigned char *) ziplocal->orglen);
PRUint32 cSize = xtolong ((unsigned char *) ziplocal->size);
switch (xtoint(ziplocal->method))
{
case STORED:
// file is uncompressed, can use the data where it is
sigSize = cSize;
sigData = (unsigned char*)data;
break;
case DEFLATED:
if (orgSize == 0 || orgSize > MAX_SIGNATURE_SIZE)
return NS_BINDING_ABORTED;
orgData = (unsigned char*)malloc(orgSize);
if (!orgData)
return NS_BINDING_ABORTED;
err = my_inflate((unsigned char*)data,
cSize,
orgData,
orgSize);
sigSize = orgSize;
sigData = orgData;
break;
default:
// unsupported compression method
err = Z_DATA_ERROR;
break;
}
if (err == 0)
{
PRInt32 verifyError;
rv = mVerifier->VerifySignature((char*)sigData, sigSize, nsnull, 0,
&verifyError, getter_AddRefs(mPrincipal));
}
if (orgData)
free(orgData);
// Cancel the load now that we've verified the signature
return NS_BINDING_ABORTED;
}
return NS_OK; // continue reading
}
NS_IMETHODIMP
CertReader::OnStopRequest(nsIRequest *request, nsISupports* context,
nsresult aStatus)
{
mObserver->OnCertAvailable(mURI,
mContext,
aStatus,
mPrincipal);
return NS_OK;
}

View File

@ -1,64 +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 XPInstall Signing.
*
* The Initial Developer of the Original Code is Doug Turner.
* Portions created by the Initial Developer are Copyright (C) 2002
* 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 "nsCOMPtr.h"
#include "nsIStreamListener.h"
#include "nsString.h"
class nsISignatureVerifier;
class nsIPrincipal;
class nsIURI;
class nsPICertNotification;
class CertReader : public nsIStreamListener
{
public:
CertReader(nsIURI* uri, nsISupports* aContext, nsPICertNotification* aObs);
virtual ~CertReader();
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
private:
nsCString mLeftoverBuffer;
nsCOMPtr<nsIPrincipal> mPrincipal;
nsCOMPtr<nsISignatureVerifier> mVerifier;
nsCOMPtr<nsISupports> mContext;
nsCOMPtr<nsIURI> mURI;
nsCOMPtr<nsPICertNotification> mObserver;
};

View File

@ -1,74 +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 Communicator client code, released
# March 31, 1998.
#
# 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):
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
# Dave Townsend <dtownsend@oxymoronical.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either of 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 = xpinstall
LIBRARY_NAME = xpinstall
EXPORT_LIBRARY = 1
IS_COMPONENT = 1
MODULE_NAME = nsSoftwareUpdate
GRE_MODULE = 1
LIBXUL_LIBRARY = 1
# XXX shouldn't need to export this
EXPORTS = nsXPITriggerInfo.h
CPPSRCS = \
CertReader.cpp \
nsInstallTrigger.cpp \
nsJSInstallTriggerGlobal.cpp \
nsSoftwareUpdate.cpp \
nsXPITriggerInfo.cpp \
nsXPInstallManager.cpp \
nsXPIInstallInfo.cpp \
$(NULL)
LOCAL_INCLUDES = -I$(srcdir)/../public
include $(topsrcdir)/config/rules.mk

View File

@ -1,117 +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 Communicator client code, released
* March 31, 1998.
*
* 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):
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
* Jens Bannmann <jens.b@web.de>
* Dave Townsend <dtownsend@oxymoronical.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 __NS_INSTALL_H__
#define __NS_INSTALL_H__
class nsInstall
{
public:
enum
{
BAD_PACKAGE_NAME = -200,
UNEXPECTED_ERROR = -201,
ACCESS_DENIED = -202,
EXECUTION_ERROR = -203,
NO_INSTALL_SCRIPT = -204,
NO_CERTIFICATE = -205,
NO_MATCHING_CERTIFICATE = -206,
CANT_READ_ARCHIVE = -207,
INVALID_ARGUMENTS = -208,
ILLEGAL_RELATIVE_PATH = -209,
USER_CANCELLED = -210,
INSTALL_NOT_STARTED = -211,
SILENT_MODE_DENIED = -212,
NO_SUCH_COMPONENT = -213,
DOES_NOT_EXIST = -214,
READ_ONLY = -215,
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,
PACKAGE_FOLDER_NOT_SET = -224,
EXTRACTION_FAILED = -225,
FILENAME_ALREADY_USED = -226,
INSTALL_CANCELLED = -227,
DOWNLOAD_ERROR = -228,
SCRIPT_ERROR = -229,
ALREADY_EXISTS = -230,
IS_FILE = -231,
SOURCE_DOES_NOT_EXIST = -232,
SOURCE_IS_DIRECTORY = -233,
SOURCE_IS_FILE = -234,
INSUFFICIENT_DISK_SPACE = -235,
FILENAME_TOO_LONG = -236,
UNABLE_TO_LOCATE_LIB_FUNCTION = -237,
UNABLE_TO_LOAD_LIBRARY = -238,
CHROME_REGISTRY_ERROR = -239,
MALFORMED_INSTALL = -240,
KEY_ACCESS_DENIED = -241,
KEY_DOES_NOT_EXIST = -242,
VALUE_DOES_NOT_EXIST = -243,
UNSUPPORTED_TYPE = -244,
INVALID_SIGNATURE = -260,
INVALID_HASH = -261,
INVALID_HASH_TYPE = -262,
OUT_OF_MEMORY = -299,
GESTALT_UNKNOWN_ERR = -5550,
GESTALT_INVALID_ARGUMENT = -5551,
SUCCESS = 0,
REBOOT_NEEDED = 999
};
};
#endif

View File

@ -1,453 +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 Communicator client code, released
* March 31, 1998.
*
* 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):
* Dave Townsend <dtownsend@oxymoronical.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 "nsXPInstallManager.h"
#include "nsInstallTrigger.h"
#include "nsIDOMInstallTriggerGlobal.h"
#include "nscore.h"
#include "nsAutoPtr.h"
#include "netCore.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsPIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIPermissionManager.h"
#include "nsIDocShell.h"
#include "nsNetUtil.h"
#include "nsIDOMDocument.h"
#include "nsIDocument.h"
#include "nsIPrincipal.h"
#include "nsIObserverService.h"
#include "nsIPropertyBag2.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsIContentHandler.h"
#include "nsIChannel.h"
#include "nsIURI.h"
#include "nsXPIInstallInfo.h"
nsInstallTrigger::nsInstallTrigger()
{
mScriptObject = nsnull;
}
nsInstallTrigger::~nsInstallTrigger()
{
}
NS_IMPL_THREADSAFE_ISUPPORTS3 (nsInstallTrigger,
nsIScriptObjectOwner,
nsIDOMInstallTriggerGlobal,
nsIContentHandler)
NS_IMETHODIMP
nsInstallTrigger::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
nsresult res = NS_OK;
if (nsnull == mScriptObject)
{
res = NS_NewScriptInstallTriggerGlobal(aContext,
(nsIDOMInstallTriggerGlobal*)this,
aContext->GetGlobalObject(),
&mScriptObject);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
nsInstallTrigger::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::HandleContent(const char * aContentType,
nsIInterfaceRequestor* aWindowContext,
nsIRequest* aRequest)
{
nsresult rv = NS_OK;
if (!aRequest)
return NS_ERROR_NULL_POINTER;
if (nsCRT::strcasecmp(aContentType, "application/x-xpinstall") != 0)
{
// We only support content-type application/x-xpinstall
return NS_ERROR_WONT_HANDLE_CONTENT;
}
// Save the URI so nsXPInstallManager can re-load it later
nsCOMPtr<nsIURI> uri;
nsCAutoString urispec;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
if (channel)
{
rv = channel->GetURI(getter_AddRefs(uri));
if (NS_SUCCEEDED(rv) && uri)
rv = uri->GetSpec(urispec);
}
if (NS_FAILED(rv))
return rv;
if (urispec.IsEmpty())
return NS_ERROR_ILLEGAL_VALUE;
// Save the referrer if any, for permission checks
NS_NAMED_LITERAL_STRING(referrerProperty, "docshell.internalReferrer");
bool useReferrer = false;
nsCOMPtr<nsIURI> referringURI;
nsCOMPtr<nsIPropertyBag2> channelprops(do_QueryInterface(channel));
if (channelprops)
{
// Get the referrer from the channel properties if we can (not all
// channels support our internal-referrer property).
//
// It's possible docshell explicitly set a null referrer in the case
// of typed, pasted, or bookmarked URLs and the like. In such a case
// we get a success return value with null pointer.
//
// A null referrer is automatically whitelisted as an explicit user
// action (though they'll still get the confirmation dialog). For a
// missing referrer we go to our fall-back plan of using the XPI
// location for whitelisting purposes.
rv = channelprops->GetPropertyAsInterface(referrerProperty,
NS_GET_IID(nsIURI),
getter_AddRefs(referringURI));
if (NS_SUCCEEDED(rv))
useReferrer = true;
}
// Cancel the current request. nsXPInstallManager restarts the download
// under its control (shared codepath with InstallTrigger)
aRequest->Cancel(NS_BINDING_ABORTED);
// Get the global object of the target window for StartSoftwareUpdate
nsCOMPtr<nsIScriptGlobalObjectOwner> globalObjectOwner =
do_QueryInterface(aWindowContext);
nsIScriptGlobalObject* globalObject =
globalObjectOwner ? globalObjectOwner->GetScriptGlobalObject() : nsnull;
if ( !globalObject )
return NS_ERROR_INVALID_ARG;
nsCOMPtr<nsIURI> checkuri;
if ( useReferrer )
{
// easiest and most common case: base decision on the page that
// contained the link
//
// NOTE: the XPI itself may be from elsewhere; the user can decide if
// they trust the actual source when they get the install confirmation
// dialog. The decision we're making here is whether the triggering
// site is one which is allowed to annoy the user with modal dialogs.
checkuri = referringURI;
}
else
{
// Now we're stumbing in the dark. In the most likely case the user
// simply clicked on an FTP link (no referrer) and it's perfectly
// sane to use the current window.
//
// On the other hand the user might be opening a non-http XPI link
// in an unrelated existing window (typed in location bar, bookmark,
// dragged link ...) in which case the current window is irrelevant.
// If we knew it was one of these explicit user actions we'd like to
// allow it, but we have no way of knowing that here.
//
// But there's no way to distinguish the innocent cases from a clever
// malicious site. If we used the target window then evil.com could
// embed a presumed allowed site (e.g. mozilla.org) in a frame, then
// change the location to the XPI and trigger the install. Or evil.com
// could do the same thing in a new window (more work to get around
// popup blocking, but possible).
//
// Our choices appear to be block this type of load entirely or to
// trust only the install URI. The former is unacceptably restrictive,
// the latter allows malicious sites to pester people with modal
// dialogs. As long as the trusted sites don't host bad content that's
// no worse than an endless stream of alert()s -- already possible.
// If the trusted sites don't even have an ftp server then even this
// level of annoyance is not possible.
//
// If a trusted site hosts an install with an exploitable flaw it
// might be possible that a malicious site would attempt to trick
// people into installing it, hoping to turn around and exploit it.
// This is not entirely far-fetched (it's been done with ActiveX
// controls) and will require community policing of the default
// trusted sites.
checkuri = uri;
}
nsAutoPtr<nsXPITriggerInfo> trigger(new nsXPITriggerInfo());
nsAutoPtr<nsXPITriggerItem> item(new nsXPITriggerItem(0, NS_ConvertUTF8toUTF16(urispec).get(),
nsnull));
if (trigger && item)
{
// trigger will own the item now
trigger->Add(item.forget());
nsCOMPtr<nsIDOMWindow> win = do_QueryInterface(globalObject);
nsCOMPtr<nsIXPIInstallInfo> installInfo =
new nsXPIInstallInfo(win, checkuri, trigger, 0);
if (installInfo)
{
// From here trigger is owned by installInfo until passed on to nsXPInstallManager
trigger.forget();
if (AllowInstall(checkuri))
{
return StartInstall(installInfo, nsnull);
}
else
{
nsCOMPtr<nsIObserverService> os =
mozilla::services::GetObserverService();
if (os)
os->NotifyObservers(installInfo,
"xpinstall-install-blocked",
nsnull);
return NS_ERROR_ABORT;
}
}
}
return NS_ERROR_OUT_OF_MEMORY;
}
// updateWhitelist
//
// Helper function called by nsInstallTrigger::AllowInstall().
// Interprets the pref as a comma-delimited list of hosts and adds each one
// to the permission manager using the given action. Clear pref when done.
static void updatePermissions( const char* aPref,
PRUint32 aPermission,
nsIPermissionManager* aPermissionManager,
nsIPrefBranch* aPrefBranch)
{
NS_PRECONDITION(aPref && aPermissionManager && aPrefBranch, "Null arguments!");
nsXPIDLCString hostlist;
nsresult rv = aPrefBranch->GetCharPref( aPref, getter_Copies(hostlist));
if (NS_SUCCEEDED(rv) && !hostlist.IsEmpty())
{
nsCAutoString host;
PRInt32 start=0, match=0;
nsresult rv;
nsCOMPtr<nsIURI> uri;
do {
match = hostlist.FindChar(',', start);
host = Substring(hostlist, start, match-start);
host.CompressWhitespace();
host.Insert("http://", 0);
rv = NS_NewURI(getter_AddRefs(uri), host);
if (NS_SUCCEEDED(rv))
{
aPermissionManager->Add( uri, XPI_PERMISSION, aPermission,
nsIPermissionManager::EXPIRE_NEVER, 0 );
}
start = match+1;
} while ( match > 0 );
// save empty list, we don't need to do this again
aPrefBranch->SetCharPref( aPref, "");
}
}
// Check whether an Install is allowed. The launching URI can be null,
// in which case only the global pref-setting matters.
bool
nsInstallTrigger::AllowInstall(nsIURI* aLaunchURI)
{
// Check the global setting.
bool xpiEnabled = false;
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
if ( !prefBranch)
{
return true; // no pref service in native install, it's OK
}
prefBranch->GetBoolPref( XPINSTALL_ENABLE_PREF, &xpiEnabled);
if ( !xpiEnabled )
{
// globally turned off
return false;
}
// Check permissions for the launching host if we have one
nsCOMPtr<nsIPermissionManager> permissionMgr =
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
if ( permissionMgr && aLaunchURI )
{
bool isChrome = false;
bool isFile = false;
aLaunchURI->SchemeIs( "chrome", &isChrome );
aLaunchURI->SchemeIs( "file", &isFile );
// file: and chrome: don't need whitelisted hosts
if ( !isChrome && !isFile )
{
// check prefs for permission updates before testing URI
updatePermissions( XPINSTALL_WHITELIST_ADD,
nsIPermissionManager::ALLOW_ACTION,
permissionMgr, prefBranch );
updatePermissions( XPINSTALL_WHITELIST_ADD_36,
nsIPermissionManager::ALLOW_ACTION,
permissionMgr, prefBranch );
updatePermissions( XPINSTALL_BLACKLIST_ADD,
nsIPermissionManager::DENY_ACTION,
permissionMgr, prefBranch );
bool requireWhitelist = true;
prefBranch->GetBoolPref( XPINSTALL_WHITELIST_REQUIRED, &requireWhitelist );
PRUint32 permission = nsIPermissionManager::UNKNOWN_ACTION;
permissionMgr->TestPermission( aLaunchURI, XPI_PERMISSION, &permission );
if ( permission == nsIPermissionManager::DENY_ACTION )
{
xpiEnabled = false;
}
else if ( requireWhitelist &&
permission != nsIPermissionManager::ALLOW_ACTION )
{
xpiEnabled = false;
}
}
}
return xpiEnabled;
}
NS_IMETHODIMP
nsInstallTrigger::GetOriginatingURI(nsIScriptGlobalObject* aGlobalObject, nsIURI * *aUri)
{
NS_ENSURE_ARG_POINTER(aGlobalObject);
*aUri = nsnull;
// find the current site
nsCOMPtr<nsIDOMDocument> domdoc;
nsCOMPtr<nsIDOMWindow> window(do_QueryInterface(aGlobalObject));
if ( window )
{
window->GetDocument(getter_AddRefs(domdoc));
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domdoc));
if ( doc )
NS_ADDREF(*aUri = doc->GetDocumentURI());
}
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::UpdateEnabled(nsIScriptGlobalObject* aGlobalObject, bool aUseWhitelist, bool* aReturn)
{
nsCOMPtr<nsIURI> uri;
nsresult rv = GetOriginatingURI(aGlobalObject, getter_AddRefs(uri));
NS_ENSURE_SUCCESS(rv, rv);
return UpdateEnabled(uri, aUseWhitelist, aReturn);
}
NS_IMETHODIMP
nsInstallTrigger::UpdateEnabled(nsIURI* aURI, bool aUseWhitelist, bool* aReturn)
{
// disallow unless we successfully find otherwise
*aReturn = false;
if (!aUseWhitelist)
{
// simple global pref check
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (prefBranch)
prefBranch->GetBoolPref( XPINSTALL_ENABLE_PREF, aReturn);
}
else if (aURI)
{
*aReturn = AllowInstall(aURI);
}
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::StartInstall(nsIXPIInstallInfo* aInstallInfo, bool* aReturn)
{
if (aReturn)
*aReturn = false;
nsXPInstallManager *mgr = new nsXPInstallManager();
if (mgr)
{
nsresult rv = mgr->InitManagerWithInstallInfo(aInstallInfo);
if (NS_SUCCEEDED(rv) && aReturn)
*aReturn = true;
return rv;
}
else
{
return NS_ERROR_OUT_OF_MEMORY;
}
}

View File

@ -1,65 +0,0 @@
#ifndef __NS_INSTALLTRIGGER_H__
#define __NS_INSTALLTRIGGER_H__
#include "nscore.h"
#include "nsString.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIScriptObjectOwner.h"
#include "prtypes.h"
#include "nsHashtable.h"
#include "nsIDOMInstallTriggerGlobal.h"
#include "nsXPITriggerInfo.h"
#include "nsIContentHandler.h"
#define NOT_CHROME 0
#define CHROME_SKIN 1
#define CHROME_LOCALE 2
#define CHROME_SAFEMAX CHROME_SKIN
#define CHROME_CONTENT 4
#define CHROME_ALL (CHROME_SKIN | CHROME_LOCALE | CHROME_CONTENT)
#define CHROME_PROFILE 8
#define CHROME_DELAYED 0x10
#define CHROME_SELECT 0x20
#define XPI_PERMISSION "install"
#define XPI_WHITELIST true
#define XPI_GLOBAL false
#define XPINSTALL_ENABLE_PREF "xpinstall.enabled"
#define XPINSTALL_WHITELIST_ADD "xpinstall.whitelist.add"
#define XPINSTALL_WHITELIST_ADD_36 "xpinstall.whitelist.add.36"
#define XPINSTALL_WHITELIST_REQUIRED "xpinstall.whitelist.required"
#define XPINSTALL_BLACKLIST_ADD "xpinstall.blacklist.add"
class nsInstallTrigger: public nsIScriptObjectOwner,
public nsIDOMInstallTriggerGlobal,
public nsIContentHandler
{
public:
nsInstallTrigger();
virtual ~nsInstallTrigger();
NS_DECL_ISUPPORTS
NS_DECL_NSICONTENTHANDLER
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void* aScriptObject);
NS_IMETHOD GetOriginatingURI(nsIScriptGlobalObject* aGlobalObject, nsIURI * *aUri);
NS_IMETHOD UpdateEnabled(nsIScriptGlobalObject* aGlobalObject, bool aUseWhitelist, bool* aReturn);
NS_IMETHOD UpdateEnabled(nsIURI* aURI, bool aUseWhitelist, bool* aReturn);
NS_IMETHOD StartInstall(nsIXPIInstallInfo* aInstallInfo, bool* aReturn);
private:
bool AllowInstall(nsIURI* aLaunchURI);
void *mScriptObject;
};
#define NS_INSTALLTRIGGERCOMPONENT_CONTRACTID "@mozilla.org/xpinstall/installtrigger;1"
#endif

View File

@ -1,834 +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):
* Dave Townsend <dtownsend@oxymoronical.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 "jsapi.h"
#include "nscore.h"
#include "nsAutoPtr.h"
#include "nsIScriptContext.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsCRT.h"
#include "nsString.h"
#include "nsIDOMInstallTriggerGlobal.h"
#include "nsPIDOMWindow.h"
#include "nsIDOMDocument.h"
#include "nsIDocument.h"
#include "nsIDocShell.h"
#include "nsIObserverService.h"
#include "nsInstallTrigger.h"
#include "nsXPITriggerInfo.h"
#include "nsDOMJSUtils.h"
#include "nsXPIInstallInfo.h"
#include "nsIComponentManager.h"
#include "nsNetUtil.h"
#include "nsIScriptSecurityManager.h"
#include "nsSoftwareUpdateIIDs.h"
void ConvertJSValToStr(nsString& aString,
JSContext* aContext,
jsval aValue)
{
JSString *jsstring;
if ( !JSVAL_IS_NULL(aValue) &&
(jsstring = JS_ValueToString(aContext, aValue)) != nsnull)
{
aString.Assign(reinterpret_cast<const PRUnichar*>(JS_GetStringChars(jsstring)));
}
else
{
aString.Truncate();
}
}
static void
FinalizeInstallTriggerGlobal(JSContext *cx, JSObject *obj);
/***********************************************************************/
//
// class for InstallTriggerGlobal
//
JSClass InstallTriggerGlobalClass = {
"InstallTrigger",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_PropertyStub,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
FinalizeInstallTriggerGlobal
};
//
// InstallTriggerGlobal finalizer
//
static void
FinalizeInstallTriggerGlobal(JSContext *cx, JSObject *obj)
{
nsISupports *nativeThis = (nsISupports*)JS_GetPrivate(cx, obj);
if (nsnull != nativeThis) {
// get the js object
nsIScriptObjectOwner *owner = nsnull;
if (NS_OK == nativeThis->QueryInterface(NS_GET_IID(nsIScriptObjectOwner),
(void**)&owner)) {
owner->SetScriptObject(nsnull);
NS_RELEASE(owner);
}
// The addref was part of JSObject construction
NS_RELEASE(nativeThis);
}
}
static JSBool CreateNativeObject(JSContext *cx, JSObject *obj, nsIDOMInstallTriggerGlobal **aResult)
{
nsresult result;
nsIScriptObjectOwner *owner = nsnull;
nsIDOMInstallTriggerGlobal *nativeThis;
static NS_DEFINE_CID(kInstallTrigger_CID,
NS_SoftwareUpdateInstallTrigger_CID);
result = CallCreateInstance(kInstallTrigger_CID, &nativeThis);
if (NS_FAILED(result)) return JS_FALSE;
result = nativeThis->QueryInterface(NS_GET_IID(nsIScriptObjectOwner),
(void **)&owner);
if (NS_OK != result)
{
NS_RELEASE(nativeThis);
return JS_FALSE;
}
owner->SetScriptObject((void *)obj);
JS_SetPrivate(cx, obj, nativeThis);
*aResult = nativeThis;
NS_RELEASE(nativeThis); // we only want one refcnt. JSUtils cleans us up.
return JS_TRUE;
}
//
// Helper function for URI verification
//
static nsresult
InstallTriggerCheckLoadURIFromScript(JSContext *cx, const nsAString& uriStr)
{
nsresult rv;
nsCOMPtr<nsIScriptSecurityManager> secman(
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID,&rv));
NS_ENSURE_SUCCESS(rv, rv);
// get the script principal
nsCOMPtr<nsIPrincipal> principal;
rv = secman->GetSubjectPrincipal(getter_AddRefs(principal));
NS_ENSURE_SUCCESS(rv, rv);
if (!principal)
return NS_ERROR_FAILURE;
// convert the requested URL string to a URI
// Note that we use a null base URI here, since that's what we use when we
// actually convert the string into a URI to load.
nsCOMPtr<nsIURI> uri;
rv = NS_NewURI(getter_AddRefs(uri), uriStr);
NS_ENSURE_SUCCESS(rv, rv);
// are we allowed to load this one?
rv = secman->CheckLoadURIWithPrincipal(principal, uri,
nsIScriptSecurityManager::DISALLOW_INHERIT_PRINCIPAL);
return rv;
}
//
// Helper function to get native object
//
// This is our own version of JS_GetInstancePrivate() that in addition
// performs the delayed creation of the native InstallTrigger if necessary
//
static nsIDOMInstallTriggerGlobal* getTriggerNative(JSContext *cx, JSObject *obj)
{
if (!JS_InstanceOf(cx, obj, &InstallTriggerGlobalClass, nsnull))
return nsnull;
nsIDOMInstallTriggerGlobal *native = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj);
if (!native) {
// xpinstall script contexts delay creation of the native.
CreateNativeObject(cx, obj, &native);
}
return native;
}
//
// Native method UpdateEnabled
//
static JSBool
InstallTriggerGlobalUpdateEnabled(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = getTriggerNative(cx, obj);
if (!nativeThis)
return JS_FALSE;
*rval = JSVAL_FALSE;
nsIScriptGlobalObject *globalObject = nsnull;
nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
if (scriptContext)
globalObject = scriptContext->GetGlobalObject();
bool nativeRet = false;
if (globalObject)
nativeThis->UpdateEnabled(globalObject, XPI_GLOBAL, &nativeRet);
*rval = BOOLEAN_TO_JSVAL(nativeRet);
return JS_TRUE;
}
//
// Native method Install
//
static JSBool
InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = getTriggerNative(cx, obj);
if (!nativeThis)
return JS_FALSE;
*rval = JSVAL_FALSE;
// make sure XPInstall is enabled, return false if not
nsIScriptGlobalObject *globalObject = nsnull;
nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
if (scriptContext)
globalObject = scriptContext->GetGlobalObject();
if (!globalObject)
return JS_TRUE;
nsCOMPtr<nsIScriptSecurityManager> secman(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID));
if (!secman)
{
JS_ReportError(cx, "Could not the script security manager service.");
return JS_FALSE;
}
// get the principal. if it doesn't exist, die.
nsCOMPtr<nsIPrincipal> principal;
nsresult rv = secman->GetSubjectPrincipal(getter_AddRefs(principal));
if (NS_FAILED(rv) || !principal)
{
JS_ReportError(cx, "Could not get the Subject Principal during InstallTrigger.Install()");
return JS_FALSE;
}
// get window.location to construct relative URLs
nsCOMPtr<nsIURI> baseURL;
JSObject* global = JS_GetGlobalObject(cx);
if (global)
{
jsval v;
if (JS_GetProperty(cx,global,"location",&v))
{
nsAutoString location;
ConvertJSValToStr( location, cx, v );
NS_NewURI(getter_AddRefs(baseURL), location);
}
}
bool abortLoad = false;
// parse associative array of installs
if ( argc >= 1 && JSVAL_IS_OBJECT(argv[0]) && JSVAL_TO_OBJECT(argv[0]) )
{
nsXPITriggerInfo *trigger = new nsXPITriggerInfo();
if (!trigger)
return JS_FALSE;
trigger->SetPrincipal(principal);
JSIdArray *ida = JS_Enumerate( cx, JSVAL_TO_OBJECT(argv[0]) );
if ( ida )
{
jsval v;
const PRUnichar *name, *URL;
const PRUnichar *iconURL = nsnull;
for (int i = 0; i < ida->length && !abortLoad; i++ )
{
JS_IdToValue( cx, ida->vector[i], &v );
JSString * str = JS_ValueToString( cx, v );
if (!str)
{
abortLoad = true;
break;
}
name = reinterpret_cast<const PRUnichar*>(JS_GetStringChars( str ));
URL = iconURL = nsnull;
JSAutoByteString hash;
JS_GetUCProperty( cx, JSVAL_TO_OBJECT(argv[0]), reinterpret_cast<const jschar*>(name), nsCRT::strlen(name), &v );
if ( JSVAL_IS_OBJECT(v) && JSVAL_TO_OBJECT(v) )
{
jsval v2;
if (JS_GetProperty( cx, JSVAL_TO_OBJECT(v), "URL", &v2 ) && !JSVAL_IS_VOID(v2)) {
JSString *str = JS_ValueToString(cx, v2);
if (!str) {
abortLoad = true;
break;
}
URL = reinterpret_cast<const PRUnichar*>(JS_GetStringChars(str));
}
if (JS_GetProperty( cx, JSVAL_TO_OBJECT(v), "IconURL", &v2 ) && !JSVAL_IS_VOID(v2)) {
JSString *str = JS_ValueToString(cx, v2);
if (!str) {
abortLoad = true;
break;
}
iconURL = reinterpret_cast<const PRUnichar*>(JS_GetStringChars(str));
}
if (JS_GetProperty( cx, JSVAL_TO_OBJECT(v), "Hash", &v2) && !JSVAL_IS_VOID(v2)) {
JSString *str = JS_ValueToString(cx, v2);
if (!str || !hash.encode(cx, str)) {
abortLoad = true;
break;
}
}
}
else
{
JSString *str = JS_ValueToString(cx, v);
if (!str) {
abortLoad = true;
break;
}
URL = reinterpret_cast<const PRUnichar*>(JS_GetStringChars(str));
}
if ( URL )
{
// Get relative URL to load
nsAutoString xpiURL(URL);
if (baseURL)
{
nsCAutoString resolvedURL;
baseURL->Resolve(NS_ConvertUTF16toUTF8(xpiURL), resolvedURL);
xpiURL = NS_ConvertUTF8toUTF16(resolvedURL);
}
nsAutoString icon(iconURL);
if (iconURL && baseURL)
{
nsCAutoString resolvedIcon;
baseURL->Resolve(NS_ConvertUTF16toUTF8(icon), resolvedIcon);
icon = NS_ConvertUTF8toUTF16(resolvedIcon);
}
// Make sure we're allowed to load this URL and the icon URL
rv = InstallTriggerCheckLoadURIFromScript(cx, xpiURL);
if (NS_FAILED(rv))
abortLoad = true;
if (!abortLoad && iconURL)
{
rv = InstallTriggerCheckLoadURIFromScript(cx, icon);
if (NS_FAILED(rv))
abortLoad = true;
}
if (!abortLoad)
{
// Add the install item to the trigger collection
nsXPITriggerItem *item =
new nsXPITriggerItem( name, xpiURL.get(), icon.get(), hash );
if ( item )
{
trigger->Add( item );
}
else
abortLoad = true;
}
}
else
abortLoad = true;
}
JS_DestroyIdArray( cx, ida );
}
// pass on only if good stuff found
if (!abortLoad && trigger->Size() > 0)
{
nsCOMPtr<nsIURI> checkuri;
rv = nativeThis->GetOriginatingURI(globalObject,
getter_AddRefs(checkuri));
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsIDOMWindow> win = do_QueryInterface(globalObject);
nsCOMPtr<nsIXPIInstallInfo> installInfo =
new nsXPIInstallInfo(win, checkuri, trigger, 0);
if (installInfo)
{
// installInfo now owns triggers
bool enabled = false;
nativeThis->UpdateEnabled(checkuri, XPI_WHITELIST, &enabled);
if (!enabled)
{
nsCOMPtr<nsIObserverService> os =
mozilla::services::GetObserverService();
if (os)
os->NotifyObservers(installInfo,
"xpinstall-install-blocked",
nsnull);
}
else
{
// save callback function if any (ignore bad args for now)
if ( argc >= 2 && JS_TypeOfValue(cx,argv[1]) == JSTYPE_FUNCTION )
{
trigger->SaveCallback( cx, argv[1] );
}
bool result;
nativeThis->StartInstall(installInfo, &result);
*rval = BOOLEAN_TO_JSVAL(result);
}
return JS_TRUE;
}
}
}
// didn't pass it on so we must delete trigger
delete trigger;
}
JS_ReportError(cx, "Incorrect arguments to InstallTrigger.Install()");
return JS_FALSE;
}
//
// Native method InstallChrome
//
static JSBool
InstallTriggerGlobalInstallChrome(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = getTriggerNative(cx, obj);
if (!nativeThis)
return JS_FALSE;
uint32 chromeType = NOT_CHROME;
nsAutoString sourceURL;
nsAutoString name;
*rval = JSVAL_FALSE;
// get chromeType first, the update enabled check for skins skips whitelisting
if (argc >=1)
{
if (!JS_ValueToECMAUint32(cx, argv[0], &chromeType))
return JS_FALSE;
}
// make sure XPInstall is enabled, return if not
nsIScriptGlobalObject *globalObject = nsnull;
nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
if (scriptContext)
globalObject = scriptContext->GetGlobalObject();
if (!globalObject)
return JS_TRUE;
// get window.location to construct relative URLs
nsCOMPtr<nsIURI> baseURL;
JSObject* global = JS_GetGlobalObject(cx);
if (global)
{
jsval v;
if (JS_GetProperty(cx,global,"location",&v))
{
nsAutoString location;
ConvertJSValToStr( location, cx, v );
NS_NewURI(getter_AddRefs(baseURL), location);
}
}
if ( argc >= 3 )
{
ConvertJSValToStr(sourceURL, cx, argv[1]);
ConvertJSValToStr(name, cx, argv[2]);
if (baseURL)
{
nsCAutoString resolvedURL;
baseURL->Resolve(NS_ConvertUTF16toUTF8(sourceURL), resolvedURL);
sourceURL = NS_ConvertUTF8toUTF16(resolvedURL);
}
// Make sure caller is allowed to load this url.
nsresult rv = InstallTriggerCheckLoadURIFromScript(cx, sourceURL);
if (NS_FAILED(rv))
return JS_FALSE;
if ( chromeType & CHROME_ALL )
{
// there's at least one known chrome type
nsCOMPtr<nsIURI> checkuri;
nsresult rv = nativeThis->GetOriginatingURI(globalObject,
getter_AddRefs(checkuri));
if (NS_SUCCEEDED(rv))
{
nsAutoPtr<nsXPITriggerInfo> trigger(new nsXPITriggerInfo());
nsAutoPtr<nsXPITriggerItem> item(new nsXPITriggerItem(name.get(),
sourceURL.get(),
nsnull));
if (trigger && item)
{
// trigger will free item when complete
trigger->Add(item.forget());
nsCOMPtr<nsIDOMWindow> win = do_QueryInterface(globalObject);
nsCOMPtr<nsIXPIInstallInfo> installInfo =
new nsXPIInstallInfo(win, checkuri, trigger, chromeType);
if (installInfo)
{
// installInfo owns trigger now
trigger.forget();
bool enabled = false;
nativeThis->UpdateEnabled(checkuri, XPI_WHITELIST,
&enabled);
if (!enabled)
{
nsCOMPtr<nsIObserverService> os =
mozilla::services::GetObserverService();
if (os)
os->NotifyObservers(installInfo,
"xpinstall-install-blocked",
nsnull);
}
else
{
bool nativeRet = false;
nativeThis->StartInstall(installInfo, &nativeRet);
*rval = BOOLEAN_TO_JSVAL(nativeRet);
}
}
}
}
}
}
return JS_TRUE;
}
//
// Native method StartSoftwareUpdate
//
static JSBool
InstallTriggerGlobalStartSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = getTriggerNative(cx, obj);
if (!nativeThis)
return JS_FALSE;
bool nativeRet;
PRInt32 flags = 0;
*rval = JSVAL_FALSE;
nsIScriptGlobalObject *globalObject = nsnull;
nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
if (scriptContext)
globalObject = scriptContext->GetGlobalObject();
if (!globalObject)
return JS_TRUE;
// get window.location to construct relative URLs
nsCOMPtr<nsIURI> baseURL;
JSObject* global = JS_GetGlobalObject(cx);
if (global)
{
jsval v;
if (JS_GetProperty(cx,global,"location",&v))
{
nsAutoString location;
ConvertJSValToStr( location, cx, v );
NS_NewURI(getter_AddRefs(baseURL), location);
}
}
if ( argc >= 1 )
{
nsAutoString xpiURL;
ConvertJSValToStr(xpiURL, cx, argv[0]);
if (baseURL)
{
nsCAutoString resolvedURL;
baseURL->Resolve(NS_ConvertUTF16toUTF8(xpiURL), resolvedURL);
xpiURL = NS_ConvertUTF8toUTF16(resolvedURL);
}
// Make sure caller is allowed to load this url.
nsresult rv = InstallTriggerCheckLoadURIFromScript(cx, xpiURL);
if (NS_FAILED(rv))
return JS_FALSE;
if (argc >= 2 && !JS_ValueToInt32(cx, argv[1], (int32 *)&flags))
{
JS_ReportError(cx, "StartSoftwareUpdate() 2nd parameter must be a number");
return JS_FALSE;
}
nsCOMPtr<nsIURI> checkuri;
rv = nativeThis->GetOriginatingURI(globalObject, getter_AddRefs(checkuri));
if (NS_SUCCEEDED(rv))
{
nsAutoPtr<nsXPITriggerInfo> trigger(new nsXPITriggerInfo());
nsAutoPtr<nsXPITriggerItem> item(new nsXPITriggerItem(0,
xpiURL.get(),
nsnull));
if (trigger && item)
{
// trigger will free item when complete
trigger->Add(item.forget());
nsCOMPtr<nsIDOMWindow> win = do_QueryInterface(globalObject);
nsCOMPtr<nsIXPIInstallInfo> installInfo =
new nsXPIInstallInfo(win, checkuri, trigger, 0);
if (installInfo)
{
// From here trigger is owned by installInfo until passed on to nsXPInstallManager
trigger.forget();
bool enabled = false;
nativeThis->UpdateEnabled(checkuri, XPI_WHITELIST, &enabled);
if (!enabled)
{
nsCOMPtr<nsIObserverService> os =
mozilla::services::GetObserverService();
if (os)
os->NotifyObservers(installInfo,
"xpinstall-install-blocked",
nsnull);
}
else
{
nativeThis->StartInstall(installInfo, &nativeRet);
*rval = BOOLEAN_TO_JSVAL(nativeRet);
}
}
}
}
}
else
{
JS_ReportError(cx, "Function StartSoftwareUpdate requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// InstallTriggerGlobal class methods
//
static JSFunctionSpec InstallTriggerGlobalMethods[] =
{
{"UpdateEnabled", InstallTriggerGlobalUpdateEnabled, 0,0,0},
{"StartSoftwareUpdate", InstallTriggerGlobalStartSoftwareUpdate, 2,0,0},
{"updateEnabled", InstallTriggerGlobalUpdateEnabled, 0,0,0},
{"enabled", InstallTriggerGlobalUpdateEnabled, 0,0,0},
{"install", InstallTriggerGlobalInstall, 2,0,0},
{"installChrome", InstallTriggerGlobalInstallChrome, 2,0,0},
{"startSoftwareUpdate", InstallTriggerGlobalStartSoftwareUpdate, 2,0,0},
{nsnull,nsnull,0,0,0}
};
static JSConstDoubleSpec diff_constants[] =
{
{ nsIDOMInstallTriggerGlobal::MAJOR_DIFF, "MAJOR_DIFF" },
{ nsIDOMInstallTriggerGlobal::MINOR_DIFF, "MINOR_DIFF" },
{ nsIDOMInstallTriggerGlobal::REL_DIFF, "REL_DIFF" },
{ nsIDOMInstallTriggerGlobal::BLD_DIFF, "BLD_DIFF" },
{ nsIDOMInstallTriggerGlobal::EQUAL, "EQUAL" },
{ nsIDOMInstallTriggerGlobal::NOT_FOUND, "NOT_FOUND" },
{ CHROME_SKIN, "SKIN" },
{ CHROME_LOCALE, "LOCALE" },
{ CHROME_CONTENT, "CONTENT" },
{ CHROME_ALL, "PACKAGE" },
{0,nsnull}
};
nsresult InitInstallTriggerGlobalClass(JSContext *jscontext, JSObject *global, void** prototype)
{
JSObject *proto = nsnull;
if (prototype != nsnull)
*prototype = nsnull;
proto = JS_InitClass(jscontext, // context
global, // global object
nsnull, // parent proto
&InstallTriggerGlobalClass, // JSClass
nsnull, // JSNative ctor
nsnull, // ctor args
nsnull, // proto props
nsnull, // proto funcs
nsnull, // ctor props (static)
InstallTriggerGlobalMethods); // ctor funcs (static)
if (nsnull == proto) return NS_ERROR_FAILURE;
if ( false == JS_DefineConstDoubles(jscontext, proto, diff_constants) )
return NS_ERROR_FAILURE;
if (prototype != nsnull)
*prototype = proto;
return NS_OK;
}
//
// InstallTriggerGlobal class initialization
//
nsresult NS_InitInstallTriggerGlobalClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((true != JS_LookupProperty(jscontext, global, "InstallTriggerGlobal", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(true != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp))
{
nsresult rv = InitInstallTriggerGlobalClass(jscontext, global, (void**)&proto);
if (NS_FAILED(rv)) return rv;
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp))
{
proto = JSVAL_TO_OBJECT(vp);
}
else
{
return NS_ERROR_FAILURE;
}
if (aPrototype)
*aPrototype = proto;
return NS_OK;
}
//
// Method for creating a new InstallTriggerGlobal JavaScript object
//
nsresult
NS_NewScriptInstallTriggerGlobal(nsIScriptContext *aContext,
nsISupports *aSupports, nsISupports *aParent,
void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports &&
nsnull != aReturn,
"null argument to NS_NewScriptInstallTriggerGlobal");
JSObject *proto;
JSObject *parent = nsnull;
JSContext *jscontext = aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMInstallTriggerGlobal *installTriggerGlobal;
nsCOMPtr<nsIScriptObjectOwner> owner(do_QueryInterface(aParent));
if (owner) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
return NS_ERROR_FAILURE;
}
} else {
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(aParent));
if (sgo) {
parent = sgo->GetGlobalJSObject();
} else {
return NS_ERROR_FAILURE;
}
}
if (NS_OK != NS_InitInstallTriggerGlobalClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = CallQueryInterface(aSupports, &installTriggerGlobal);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &InstallTriggerGlobalClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, installTriggerGlobal);
}
else {
NS_RELEASE(installTriggerGlobal);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

View File

@ -1,112 +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 Communicator client code, released
* March 31, 1998.
*
* 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):
* Dave Townsend <dtownsend@oxymoronical.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 "nscore.h"
#include "nsIGenericFactory.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIComponentManager.h"
#include "nsIComponentRegistrar.h"
#include "nsIServiceManager.h"
#include "nsICategoryManager.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsCURILoader.h"
#include "nsSoftwareUpdateIIDs.h"
#include "nsInstallTrigger.h"
#include "nsXPInstallManager.h"
//----------------------------------------------------------------------
// Functions used to create new instances of a given object by the
// generic factory.
NS_GENERIC_FACTORY_CONSTRUCTOR(nsInstallTrigger)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPInstallManager)
//----------------------------------------------------------------------
static NS_METHOD
RegisterInstallTrigger( nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType,
const nsModuleComponentInfo *info)
{
nsresult rv = NS_OK;
nsCOMPtr<nsICategoryManager> catman =
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLCString previous;
rv = catman->AddCategoryEntry(JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY,
"InstallTrigger",
NS_INSTALLTRIGGERCOMPONENT_CONTRACTID,
true, true, getter_Copies(previous));
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
// The list of components we register
static const nsModuleComponentInfo components[] =
{
{ "InstallTrigger Component",
NS_SoftwareUpdateInstallTrigger_CID,
NS_INSTALLTRIGGERCOMPONENT_CONTRACTID,
nsInstallTriggerConstructor,
RegisterInstallTrigger
},
{ "XPInstall Content Handler",
NS_SoftwareUpdateInstallTrigger_CID,
NS_CONTENT_HANDLER_CONTRACTID_PREFIX"application/x-xpinstall",
nsInstallTriggerConstructor
},
{ "XPInstallManager Component",
NS_XPInstallManager_CID,
NS_XPINSTALLMANAGERCOMPONENT_CONTRACTID,
nsXPInstallManagerConstructor
}
};
NS_IMPL_NSGETMODULE(nsSoftwareUpdate, components)

View File

@ -1,94 +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 XPInstall.
*
* The Initial Developer of the Original Code is
* Dave Townsend <dtownsend@oxymoronical.com>.
*
* Portions created by the Initial Developer are Copyright (C) 2007
* 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 "nsXPIInstallInfo.h"
NS_IMPL_ISUPPORTS1(nsXPIInstallInfo, nsIXPIInstallInfo)
nsXPIInstallInfo::nsXPIInstallInfo(nsIDOMWindow *aOriginatingWindow,
nsIURI *aOriginatingURI,
nsXPITriggerInfo *aTriggerInfo,
PRUint32 aChromeType)
: mOriginatingWindow(aOriginatingWindow), mOriginatingURI(aOriginatingURI),
mTriggerInfo(aTriggerInfo), mChromeType(aChromeType)
{
}
nsXPIInstallInfo::~nsXPIInstallInfo()
{
delete mTriggerInfo;
}
/* [noscript, notxpcom] attribute triggerInfoPtr triggerInfo; */
NS_IMETHODIMP
nsXPIInstallInfo::GetTriggerInfo(nsXPITriggerInfo * *aTriggerInfo)
{
*aTriggerInfo = mTriggerInfo;
return NS_OK;
}
NS_IMETHODIMP
nsXPIInstallInfo::SetTriggerInfo(nsXPITriggerInfo * aTriggerInfo)
{
mTriggerInfo = aTriggerInfo;
return NS_OK;
}
/* readonly attribute nsIDOMWindow originatingWindow; */
NS_IMETHODIMP
nsXPIInstallInfo::GetOriginatingWindow(nsIDOMWindow * *aOriginatingWindow)
{
NS_IF_ADDREF(*aOriginatingWindow = mOriginatingWindow);
return NS_OK;
}
/* readonly attribute nsIURI uri; */
NS_IMETHODIMP
nsXPIInstallInfo::GetOriginatingURI(nsIURI * *aOriginatingURI)
{
NS_IF_ADDREF(*aOriginatingURI = mOriginatingURI);
return NS_OK;
}
/* readonly attribute PRUint32 type; */
NS_IMETHODIMP
nsXPIInstallInfo::GetChromeType(PRUint32 *aChromeType)
{
*aChromeType = mChromeType;
return NS_OK;
}

View File

@ -1,62 +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 XPInstall.
*
* The Initial Developer of the Original Code is
* Dave Townsend <dtownsend@oxymoronical.com>.
*
* Portions created by the Initial Developer are Copyright (C) 2007
* 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 "nsXPITriggerInfo.h"
#include "nsIXPIInstallInfo.h"
#include "nsIDOMWindow.h"
#include "nsIDocShell.h"
#include "nsIURI.h"
class nsXPIInstallInfo : public nsIXPIInstallInfo
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIXPIINSTALLINFO
nsXPIInstallInfo(nsIDOMWindow *aOriginatingWindow,
nsIURI *aOriginatingURI, nsXPITriggerInfo *aTriggerInfo,
PRUint32 aChromeType);
private:
~nsXPIInstallInfo();
nsCOMPtr<nsIDOMWindow> mOriginatingWindow;
nsCOMPtr<nsIURI> mOriginatingURI;
nsXPITriggerInfo* mTriggerInfo;
PRUint32 mChromeType;
};

View File

@ -1,355 +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 Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
* Dave Townsend <dtownsend@oxymoronical.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 "mozilla/Util.h"
#include "jscntxt.h"
#include "nscore.h"
#include "plstr.h"
#include "nsXPITriggerInfo.h"
#include "nsNetUtil.h"
#include "nsDebug.h"
#include "nsAutoPtr.h"
#include "nsThreadUtils.h"
#include "nsIServiceManager.h"
#include "nsIJSContextStack.h"
#include "nsIScriptSecurityManager.h"
#include "nsICryptoHash.h"
#include "nsIX509Cert.h"
using namespace mozilla;
//
// nsXPITriggerItem
//
nsXPITriggerItem::nsXPITriggerItem( const PRUnichar* aName,
const PRUnichar* aURL,
const PRUnichar* aIconURL,
const char* aHash,
PRInt32 aFlags)
: mName(aName), mURL(aURL), mIconURL(aIconURL), mHashFound(false), mFlags(aFlags)
{
MOZ_COUNT_CTOR(nsXPITriggerItem);
// check for arguments
PRInt32 qmark = mURL.FindChar('?');
if ( qmark != kNotFound )
{
mArguments = Substring( mURL, qmark+1, mURL.Length() );
}
// construct name if not passed in
if ( mName.IsEmpty() )
{
// Use the filename as the display name by starting after the last
// slash in the URL, looking backwards from the arguments delimiter if
// we found one. By good fortune using kNotFound as the offset for
// RFindChar() starts at the end, so we can use qmark in all cases.
PRInt32 namestart = mURL.RFindChar( '/', qmark );
// the real start is after the slash (or 0 if not found)
namestart = ( namestart==kNotFound ) ? 0 : namestart + 1;
PRInt32 length;
if (qmark == kNotFound)
length = mURL.Length(); // no '?', slurp up rest of URL
else
length = (qmark - namestart); // filename stops at the '?'
mName = Substring( mURL, namestart, length );
}
// parse optional hash into its parts
if (aHash)
{
mHashFound = true;
char * colon = PL_strchr(aHash, ':');
if (colon)
{
mHasher = do_CreateInstance("@mozilla.org/security/hash;1");
if (!mHasher) return;
*colon = '\0'; // null the colon so that aHash is just the type.
nsresult rv = mHasher->InitWithString(nsDependentCString(aHash));
*colon = ':'; // restore the colon
if (NS_SUCCEEDED(rv))
mHash = colon+1;
}
}
}
nsXPITriggerItem::~nsXPITriggerItem()
{
MOZ_COUNT_DTOR(nsXPITriggerItem);
}
const PRUnichar*
nsXPITriggerItem::GetSafeURLString()
{
// create the safe url string the first time
if (mSafeURL.IsEmpty() && !mURL.IsEmpty())
{
nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), mURL);
if (uri)
{
nsCAutoString spec;
uri->SetUserPass(EmptyCString());
uri->GetSpec(spec);
mSafeURL = NS_ConvertUTF8toUTF16(spec);
}
}
return mSafeURL.get();
}
void
nsXPITriggerItem::SetPrincipal(nsIPrincipal* aPrincipal)
{
mPrincipal = aPrincipal;
// aPrincipal can be null for various failure cases.
// see bug 213894 for an example.
// nsXPInstallManager::OnCertAvailable can be called with a null principal
// and it can also force a null principal.
if (!aPrincipal)
return;
bool hasCert;
aPrincipal->GetHasCertificate(&hasCert);
if (hasCert) {
nsCOMPtr<nsISupports> certificate;
aPrincipal->GetCertificate(getter_AddRefs(certificate));
nsCOMPtr<nsIX509Cert> x509 = do_QueryInterface(certificate);
if (x509) {
x509->GetCommonName(mCertName);
if (mCertName.Length() > 0)
return;
}
nsCAutoString prettyName;
aPrincipal->GetPrettyName(prettyName);
CopyUTF8toUTF16(prettyName, mCertName);
}
}
//
// nsXPITriggerInfo
//
nsXPITriggerInfo::nsXPITriggerInfo()
: mCx(0), mCbval(JSVAL_NULL)
{
MOZ_COUNT_CTOR(nsXPITriggerInfo);
}
nsXPITriggerInfo::~nsXPITriggerInfo()
{
nsXPITriggerItem* item;
for(PRUint32 i=0; i < Size(); i++)
{
item = Get(i);
delete item;
}
mItems.Clear();
if ( mCx && !JSVAL_IS_NULL(mCbval) ) {
JS_BeginRequest(mCx);
JS_RemoveValueRoot(mCx, &mCbval );
JS_EndRequest(mCx);
}
MOZ_COUNT_DTOR(nsXPITriggerInfo);
}
void nsXPITriggerInfo::SaveCallback( JSContext *aCx, jsval aVal )
{
NS_ASSERTION( mCx == 0, "callback set twice, memory leak" );
// We'll only retain the callback if we can get a strong reference to the
// context.
if (!(JS_GetOptions(aCx) & JSOPTION_PRIVATE_IS_NSISUPPORTS))
return;
mContextWrapper = static_cast<nsISupports *>(JS_GetContextPrivate(aCx));
if (!mContextWrapper)
return;
mCx = aCx;
mCbval = aVal;
mThread = do_GetCurrentThread();
if ( !JSVAL_IS_NULL(mCbval) ) {
JS_BeginRequest(mCx);
JS_AddValueRoot(mCx, &mCbval );
JS_EndRequest(mCx);
}
}
XPITriggerEvent::~XPITriggerEvent()
{
JS_BeginRequest(cx);
JS_RemoveValueRoot(cx, &cbval);
JS_EndRequest(cx);
}
NS_IMETHODIMP
XPITriggerEvent::Run()
{
JSAutoRequest ar(cx);
// If Components doesn't exist in the global object then XPConnect has
// been torn down, probably because the page was closed. Bail out if that
// is the case.
JSObject* innerGlobal = JS_GetGlobalForObject(cx, JSVAL_TO_OBJECT(cbval));
jsval components;
if (!JS_LookupProperty(cx, innerGlobal, "Components", &components) ||
!JSVAL_IS_OBJECT(components))
return 0;
// Build arguments into rooted jsval array
jsval args[2] = { JSVAL_NULL, JSVAL_NULL };
js::AutoArrayRooter tvr(cx, ArrayLength(args), args);
// args[0] is the URL
JSString *str = JS_NewUCStringCopyZ(cx, reinterpret_cast<const jschar*>(URL.get()));
if (!str)
return 0;
args[0] = STRING_TO_JSVAL(str);
// args[1] is the status
if (!JS_NewNumberValue(cx, status, &args[1]))
return 0;
class StackPushGuard {
nsCOMPtr<nsIJSContextStack> mStack;
public:
StackPushGuard(JSContext *cx)
: mStack(do_GetService("@mozilla.org/js/xpc/ContextStack;1"))
{
if (mStack)
mStack->Push(cx);
}
~StackPushGuard()
{
if (mStack)
mStack->Pop(nsnull);
}
} stackPushGuard(cx);
nsCOMPtr<nsIScriptSecurityManager> secman =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
if (!secman)
{
JS_ReportError(cx, "Could not get script security manager service");
return 0;
}
nsCOMPtr<nsIPrincipal> principal;
nsresult rv = secman->GetSubjectPrincipal(getter_AddRefs(principal));
if (NS_FAILED(rv) || !principal)
{
JS_ReportError(cx, "Could not get principal from script security manager");
return 0;
}
bool equals = false;
principal->Equals(princ, &equals);
if (!equals)
{
JS_ReportError(cx, "Principal of callback context is different than InstallTriggers");
return 0;
}
jsval ret;
JS_CallFunctionValue(cx,
JS_GetGlobalObject(cx),
cbval,
2,
args,
&ret);
return 0;
}
void nsXPITriggerInfo::SendStatus(const PRUnichar* URL, PRInt32 status)
{
nsresult rv;
if ( mCx && mContextWrapper && !JSVAL_IS_NULL(mCbval) )
{
// create event and post it
nsRefPtr<XPITriggerEvent> event = new XPITriggerEvent();
if (event)
{
event->URL = URL;
event->status = status;
event->cx = mCx;
event->princ = mPrincipal;
event->cbval = mCbval;
JS_BeginRequest(event->cx);
JS_AddNamedValueRoot(event->cx, &event->cbval,
"XPITriggerEvent::cbval" );
JS_EndRequest(event->cx);
// Hold a strong reference to keep the underlying
// JSContext from dying before we handle this event.
event->ref = mContextWrapper;
rv = mThread->Dispatch(event, NS_DISPATCH_NORMAL);
}
else
rv = NS_ERROR_OUT_OF_MEMORY;
if ( NS_FAILED( rv ) )
{
// couldn't get event queue -- maybe window is gone or
// some similarly catastrophic occurrence
NS_WARNING("failed to dispatch XPITriggerEvent");
}
}
}

View File

@ -1,144 +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 Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 nsXPITriggerInfo_h
#define nsXPITriggerInfo_h
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsCOMPtr.h"
#include "nsISupportsUtils.h"
#include "nsILocalFile.h"
#include "nsIOutputStream.h"
#include "jsapi.h"
#include "prthread.h"
#include "nsIXPConnect.h"
#include "nsICryptoHash.h"
#include "nsIPrincipal.h"
#include "nsThreadUtils.h"
struct XPITriggerEvent : public nsRunnable {
nsString URL;
PRInt32 status;
JSContext* cx;
jsval cbval;
nsCOMPtr<nsISupports> ref;
nsCOMPtr<nsIPrincipal> princ;
virtual ~XPITriggerEvent();
NS_IMETHOD Run();
};
class nsXPITriggerItem
{
public:
nsXPITriggerItem( const PRUnichar* name,
const PRUnichar* URL,
const PRUnichar* iconURL,
const char* hash = nsnull,
PRInt32 flags = 0);
~nsXPITriggerItem();
nsString mName;
nsString mURL;
nsString mIconURL;
nsString mArguments;
nsString mCertName;
bool mHashFound; // this flag indicates that we found _some_ hash info in the trigger
nsCString mHash;
nsCOMPtr<nsICryptoHash> mHasher;
PRInt32 mFlags;
nsCOMPtr<nsILocalFile> mFile;
nsCOMPtr<nsIOutputStream> mOutStream;
nsCOMPtr<nsIPrincipal> mPrincipal;
void SetPrincipal(nsIPrincipal* aPrincipal);
bool IsFileURL() { return StringBeginsWith(mURL, NS_LITERAL_STRING("file:/")); }
const PRUnichar* GetSafeURLString();
private:
//-- prevent inadvertent copies and assignments
nsXPITriggerItem& operator=(const nsXPITriggerItem& rhs);
nsXPITriggerItem(const nsXPITriggerItem& rhs);
nsString mSafeURL;
};
class nsXPITriggerInfo
{
public:
nsXPITriggerInfo();
~nsXPITriggerInfo();
void Add( nsXPITriggerItem *aItem )
{ if ( aItem ) mItems.AppendElement( (void*)aItem ); }
nsXPITriggerItem* Get( PRUint32 aIndex )
{ return (nsXPITriggerItem*)mItems.ElementAt(aIndex);}
void SaveCallback( JSContext *aCx, jsval aVal );
PRUint32 Size() { return mItems.Count(); }
void SendStatus(const PRUnichar* URL, PRInt32 status);
void SetPrincipal(nsIPrincipal* aPrinc) { mPrincipal = aPrinc; }
private:
nsVoidArray mItems;
JSContext *mCx;
nsCOMPtr<nsISupports> mContextWrapper;
jsval mCbval;
nsCOMPtr<nsIThread> mThread;
nsCOMPtr<nsIPrincipal> mPrincipal;
//-- prevent inadvertent copies and assignments
nsXPITriggerInfo& operator=(const nsXPITriggerInfo& rhs);
nsXPITriggerInfo(const nsXPITriggerInfo& rhs);
};
#endif /* nsXPITriggerInfo_h */

File diff suppressed because it is too large Load Diff

View File

@ -1,144 +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 Communicator client code, released
* March 31, 1998.
*
* 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):
* Daniel Veditz <dveditz@netscape.com>
* Dave Townsend <dtownsend@oxymoronical.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 _NS_XPINSTALLMANAGER_H
#define _NS_XPINSTALLMANAGER_H
#include "nsInstall.h"
#include "nscore.h"
#include "nsISupports.h"
#include "nsString.h"
#include "nsIURL.h"
#include "nsIInputStream.h"
#include "nsIStreamListener.h"
#include "nsIXPInstallManager.h"
#include "nsIXPIDialogService.h"
#include "nsXPITriggerInfo.h"
#include "nsIXPIProgressDialog.h"
#include "nsIChromeRegistry.h"
#include "nsIDOMWindow.h"
#include "nsIObserver.h"
#include "nsIBadCertListener2.h"
#include "nsISSLErrorListener.h"
#include "nsIChannelEventSink.h"
#include "nsIZipReader.h"
#include "nsIXPIInstallInfo.h"
#include "nsILoadGroup.h"
#include "nsCOMPtr.h"
#include "nsIProgressEventSink.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIDialogParamBlock.h"
#include "nsPICertNotification.h"
#include "nsWeakReference.h"
#define NS_XPIDIALOGSERVICE_CONTRACTID "@mozilla.org/embedui/xpinstall-dialog-service;1"
#define NS_XPINSTALLMANAGERCOMPONENT_CONTRACTID "@mozilla.org/xpinstall/install-manager;1"
#define XPI_PROGRESS_TOPIC "xpinstall-progress"
class nsXPInstallManager : public nsIXPIDialogService,
public nsIXPInstallManager,
public nsIObserver,
public nsIStreamListener,
public nsIProgressEventSink,
public nsIInterfaceRequestor,
public nsPICertNotification,
public nsIBadCertListener2,
public nsISSLErrorListener,
public nsIChannelEventSink,
public nsSupportsWeakReference
{
public:
nsXPInstallManager();
virtual ~nsXPInstallManager();
NS_DECL_ISUPPORTS
NS_DECL_NSIXPIDIALOGSERVICE
NS_DECL_NSIXPINSTALLMANAGER
NS_DECL_NSIOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIPROGRESSEVENTSINK
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSPICERTNOTIFICATION
NS_DECL_NSIBADCERTLISTENER2
NS_DECL_NSISSLERRORLISTENER
NS_DECL_NSICHANNELEVENTSINK
NS_IMETHOD InitManager(nsIDOMWindow* aParentWindow, nsXPITriggerInfo* aTrigger, PRUint32 aChromeType );
private:
nsresult InitManagerInternal();
nsresult InstallItems();
NS_IMETHOD DownloadNext();
void Shutdown(PRInt32 status = nsInstall::USER_CANCELLED);
NS_IMETHOD GetDestinationFile(nsString& url, nsILocalFile* *file);
NS_IMETHOD LoadParams(PRUint32 aCount, const PRUnichar** aPackageList, nsIDialogParamBlock** aParams);
#ifdef ENABLE_SKIN_SIMPLE_INSTALLATION_UI
bool ConfirmChromeInstall(nsIDOMWindow* aParentWindow, const PRUnichar** aPackage);
#endif
bool VerifyHash(nsXPITriggerItem* aItem);
PRInt32 GetIndexFromURL(const PRUnichar* aUrl);
nsresult CheckCert(nsIChannel* aChannel);
nsXPITriggerInfo* mTriggers;
nsXPITriggerItem* mItem;
PRUint32 mNextItem;
PRUint32 mChromeType;
PRInt32 mContentLength;
PRInt32 mOutstandingCertLoads;
bool mDialogOpen;
bool mCancelled;
bool mNeedsShutdown;
bool mFromChrome;
nsCOMPtr<nsIXPIProgressDialog> mDlg;
nsCOMPtr<nsIDOMWindow> mParentWindow;
nsCOMPtr<nsILoadGroup> mLoadGroup;
};
#endif

Binary file not shown.

View File

@ -1,74 +0,0 @@
<HTML>
<!-- ***** 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 Communicator client code, released March
- 31, 1998.
-
- The Initial Developer of the Original Code is
- Netscape Communications Corporation.
- Portions created by the Initial Developer are Copyright (C) 1998-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- Samir Gehani <sgehani@netscape.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 LGPL or the GPL. 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 ***** -->
<HEAD>
<TITLE>XPInstall Pre-Checkin Trigger Test</TITLE>
<SCRIPT>
function xpinstallCallback(url, status)
{
if (status == 0)
msg = "XPInstall Test: PASSED\n";
else
msg = "XPInstall Test: FAILED\n";
dump(msg);
alert(msg);
}
</SCRIPT>
</HEAD>
<BODY>
<H3>XPInstall Pre-Checkin Trigger Test</H3>
<HR>
Click on the link below to execute the XPInstall pre-checkin test. <BR>
The test result (PASS or FAIL) will pop up in an alert after the test completes. <P>
<A HREF="javascript:
xpi={'XPInstall Pre-Checkin Test':'pre_checkin.xpi'};
InstallTrigger.install(xpi,xpinstallCallback);
">Test XPInstall</A>
</BODY>
</HTML>

View File

@ -1,170 +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 XPInstall.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Veditz <dveditz@netscape.com> (Original Author)
*
* 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 ***** */
/* implementation of a test XPInstall Dialog Service */
// -----------------------------------------------------------------------
// Test the XPInstall embedding API's by dropping this component into
// the Mozilla components directory and registering it.
//
// Do not export as part of a normal build since this will override the
// built-in Mozilla UI we want to use.
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// constants
// -----------------------------------------------------------------------
const XPIDIALOGSERVICE_CONTRACTID =
"@mozilla.org/embedui/xpinstall-dialog-service;1";
const XPIDIALOGSERVICE_CID =
Components.ID("{9A5BEF68-3FDA-4926-9809-87A5A1CC8505}");
const XPI_TOPIC = "xpinstall-progress";
const OPEN = "open";
const CANCEL = "cancel";
// -----------------------------------------------------------------------
// XPInstall Dialog Service
// -----------------------------------------------------------------------
function testXPIDialogService() {}
testXPIDialogService.prototype =
{
QueryInterface: function( iid )
{
if (iid.equals(Components.interfaces.nsIXPIDialogService) ||
iid.equals(Components.interfaces.nsIXPIProgressDialog) ||
iid.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
},
confirmInstall: function( parent, packages, count )
{
// stash parent window for use later
this.mParent = parent;
// quick and dirty data display
var str = "num packages: " + count/2 + "\n\n";
for ( i = 0; i < count; ++i)
str += packages[i++] + ' -- ' + packages[i] + '\n';
str += "\nDo you want to install?";
return parent.confirm(str);
},
openProgressDialog: function( packages, count, mgr )
{
this.dlg = this.mParent.open();
mgr.observe( this, XPI_TOPIC, OPEN );
},
onStateChange: function( index, state, error )
{
dump("---XPIDlg--- State: "+index+', '+state+', '+error+'\n');
},
onProgress: function( index, value, max )
{
dump("---XPIDlg--- "+index+": "+value+' of '+max+'\n');
}
};
// -----------------------------------------------------------------------
// XPInstall Dialog Service Module and Factory
// -----------------------------------------------------------------------
// --- module entry point ---
function NSGetModule(compMgr, fileSpec) { return XPIDlgSvcModule; }
// --- module ---
var XPIDlgSvcModule =
{
registerSelf: function( compMgr, fileSpec, location, type )
{
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
compMgr.registerFactoryLocation(XPIDIALOGSERVICE_CID,
'XPInstall Dialog Service test component',
XPIDIALOGSERVICE_CONTRACTID, fileSpec,
location, type);
},
unregisterSelf: function( compMgr, fileSpec, location )
{
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
compMgr.unregisterFactoryLocation(XPIDIALOGSERVICE_CID, fileSpec);
},
getClassObject: function( compMgr, cid, iid )
{
if (!cid.equals(XPIDIALOGSERVICE_CID))
throw Components.results.NS_ERROR_NO_INTERFACE;
if (!iid.equals(Components.interfaces.nsIFactory))
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
return XPIDlgSvcFactory;
},
canUnload: function( compMgr ) { return true; }
};
// --- factory ---
var XPIDlgSvcFactory =
{
createInstance: function( outer, iid )
{
if (outer != null)
throw Components.results.NS_ERROR_NO_AGGREGATION;
if (!iid.equals(Components.interfaces.nsIXPIDialogService) &&
!iid.equals(Components.interfaces.nsISupports))
throw Components.results.NS_ERROR_INVALID_ARG;
return new testXPIDialogService();
}
};

View File

@ -1,108 +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
# Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2008
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either of 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@
relativesrcdir = xpinstall/tests
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
ifneq (mobile,$(MOZ_BUILD_APP))
_BROWSER_FILES = harness.js \
browser_unsigned_url.js \
browser_unsigned_trigger.js \
browser_whitelist.js \
browser_whitelist2.js \
browser_whitelist3.js \
browser_whitelist4.js \
browser_whitelist5.js \
browser_whitelist6.js \
browser_hash.js \
browser_badhash.js \
browser_badhashtype.js \
browser_signed_url.js \
browser_signed_trigger.js \
browser_signed_untrusted.js \
browser_signed_tampered.js \
browser_signed_multiple.js \
browser_signed_naming.js \
browser_empty.js \
browser_corrupt.js \
browser_cookies.js \
browser_cookies2.js \
browser_cookies3.js \
browser_cookies4.js \
browser_enabled.js \
browser_enabled2.js \
browser_enabled3.js \
browser_softwareupdate.js \
browser_installchrome.js \
browser_opendialog.js \
browser_localfile.js \
browser_localfile2.js \
browser_auth.js \
browser_auth2.js \
browser_auth3.js \
browser_offline.js \
browser_chrome.js \
browser_cancel.js \
browser_navigateaway.js \
browser_navigateaway2.js \
browser_bug540558.js \
unsigned.xpi \
signed.xpi \
signed2.xpi \
signed-no-o.xpi \
signed-no-cn.xpi \
signed-untrusted.xpi \
signed-tampered.xpi \
empty.xpi \
corrupt.xpi \
enabled.html \
installtrigger.html \
startsoftwareupdate.html \
installchrome.html \
authRedirect.sjs \
cookieRedirect.sjs \
bug540558.html \
$(NULL)
libs:: $(_BROWSER_FILES)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
endif

View File

@ -1,21 +0,0 @@
// Simple script redirects to the query part of the uri if the browser
// authenticates with username "testuser" password "testpass"
function handleRequest(request, response) {
if (request.hasHeader("Authorization")) {
if (request.getHeader("Authorization") == "Basic dGVzdHVzZXI6dGVzdHBhc3M=") {
response.setStatusLine(request.httpVersion, 302, "Found");
response.setHeader("Location", request.queryString);
response.write("See " + request.queryString);
}
else {
response.setStatusLine(request.httpVersion, 403, "Forbidden");
response.write("Invalid credentials");
}
}
else {
response.setStatusLine(request.httpVersion, 401, "Authentication required");
response.setHeader("WWW-Authenticate", "basic realm=\"XPInstall\"", false);
response.write("Unauthenticed request");
}
}

View File

@ -1,49 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Test whether an install succeeds when authentication is required
// This verifies bug 312473
function test() {
Harness.authenticationCallback = get_auth_info;
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": TESTROOT + "authRedirect.sjs?" + TESTROOT + "unsigned.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function get_auth_info() {
return [ "testuser", "testpass" ];
}
function check_xpi_install(addon, status) {
is(status, 0, "Install should succeed");
}
function finish_test() {
var authMgr = Components.classes['@mozilla.org/network/http-auth-manager;1']
.getService(Components.interfaces.nsIHttpAuthManager);
authMgr.clearAll();
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,45 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Test whether an install fails when authentication is required and bad
// credentials are given
// This verifies bug 312473
function test() {
Harness.authenticationCallback = get_auth_info;
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": TESTROOT + "authRedirect.sjs?" + TESTROOT + "unsigned.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function get_auth_info() {
return [ "baduser", "badpass" ];
}
function check_xpi_install(addon, status) {
is(status, -228, "Install should fail");
}
function finish_test() {
var authMgr = Components.classes['@mozilla.org/network/http-auth-manager;1']
.getService(Components.interfaces.nsIHttpAuthManager);
authMgr.clearAll();
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,45 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Test whether an install fails when authentication is required and it is
// canceled
// This verifies bug 312473
function test() {
Harness.authenticationCallback = get_auth_info;
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": TESTROOT + "authRedirect.sjs?" + TESTROOT + "unsigned.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function get_auth_info() {
return null;
}
function check_xpi_install(addon, status) {
is(status, -228, "Install should fail");
}
function finish_test() {
var authMgr = Components.classes['@mozilla.org/network/http-auth-manager;1']
.getService(Components.interfaces.nsIHttpAuthManager);
authMgr.clearAll();
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,39 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Test whether an install fails when an invalid hash is included
// This verifies bug 302284
function test() {
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": {
URL: TESTROOT + "unsigned.xpi",
Hash: "sha1:643b08418599ddbd1ea8a511c90696578fb844b9",
toString: function() { return this.URL; }
}
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function check_xpi_install(addon, status) {
is(status, -261, "Install should fail");
}
function finish_test() {
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,39 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Test whether an install fails when an unknown hash type is included
// This verifies bug 302284
function test() {
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": {
URL: TESTROOT + "unsigned.xpi",
Hash: "foo:3d0dc22e1f394e159b08aaf5f0f97de4d5c65f4f",
toString: function() { return this.URL; }
}
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function check_xpi_install(addon, status) {
is(status, -261, "Install should fail");
}
function finish_test() {
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,35 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests that calling InstallTrigger.installChrome works
function test() {
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "bug540558.html");
}
function check_xpi_install(addon, status) {
is(status, 0, "Install should succeed");
}
function finish_test() {
Services.perms.remove("example.com", "install");
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,47 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests that cancelling an in progress download works.
var gManager = null;
function test() {
waitForExplicitFinish();
gManager = Components.classes["@mozilla.org/xpinstall/install-manager;1"]
.createInstance(Components.interfaces.nsIXPInstallManager);
gManager.initManagerFromChrome([ TESTROOT + "unsigned.xpi" ],
1, listener);
}
function finish_test() {
finish();
}
var listener = {
onStateChange: function(index, state, value) {
is(index, 0, "There is only one download");
if (state == Components.interfaces.nsIXPIProgressDialog.INSTALL_DONE)
is(value, -210, "Install should have been cancelled");
else if (state == Components.interfaces.nsIXPIProgressDialog.DIALOG_CLOSE)
finish_test();
},
onProgress: function(index, value, maxValue) {
is(index, 0, "There is only one download");
gManager.QueryInterface(Components.interfaces.nsIObserver);
gManager.observe(null, "xpinstall-progress", "cancel");
},
QueryInterface: function(iid) {
if (iid.equals(Components.interfaces.nsIXPIProgressDialog) ||
iid.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
}
};
// ----------------------------------------------------------------------------

View File

@ -1,47 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests that starting a download from chrome works and bypasses the whitelist
function test() {
waitForExplicitFinish();
var xpimgr = Components.classes["@mozilla.org/xpinstall/install-manager;1"]
.createInstance(Components.interfaces.nsIXPInstallManager);
xpimgr.initManagerFromChrome([ TESTROOT + "unsigned.xpi" ],
1, listener);
}
function finish_test() {
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
finish();
}
var listener = {
onStateChange: function(index, state, value) {
is(index, 0, "There is only one download");
if (state == Components.interfaces.nsIXPIProgressDialog.INSTALL_DONE)
is(value, 0, "Install should have succeeded");
else if (state == Components.interfaces.nsIXPIProgressDialog.DIALOG_CLOSE)
finish_test();
},
onProgress: function(index, value, maxValue) {
is(index, 0, "There is only one download");
},
QueryInterface: function(iid) {
if (iid.equals(Components.interfaces.nsIXPIProgressDialog) ||
iid.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
}
};
// ----------------------------------------------------------------------------

View File

@ -1,37 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Test that an install that requires cookies to be sent fails when no cookies
// are set
// This verifies bug 462739
function test() {
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Cookie check": TESTROOT + "cookieRedirect.sjs?" + TESTROOT + "unsigned.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function check_xpi_install(addon, status) {
is(status, -228, "Install should fail");
}
function finish_test() {
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,50 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Test that an install that requires cookies to be sent succeeds when cookies
// are set
// This verifies bug 462739
function test() {
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var cm = Components.classes["@mozilla.org/cookiemanager;1"]
.getService(Components.interfaces.nsICookieManager2);
cm.add("example.com", "/browser/xpinstall/tests", "xpinstall", "true", false,
false, true, (Date.now() / 1000) + 60);
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Cookie check": TESTROOT + "cookieRedirect.sjs?" + TESTROOT + "unsigned.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function check_xpi_install(addon, status) {
is(status, 0, "Install should succeed");
}
function finish_test() {
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
var cm = Components.classes["@mozilla.org/cookiemanager;1"]
.getService(Components.interfaces.nsICookieManager2);
cm.remove("example.com", "xpinstall", "/browser/xpinstall/tests", false);
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,53 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Test that an install that requires cookies to be sent succeeds when cookies
// are set and third party cookies are disabled.
// This verifies bug 462739
function test() {
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var cm = Components.classes["@mozilla.org/cookiemanager;1"]
.getService(Components.interfaces.nsICookieManager2);
cm.add("example.com", "/browser/xpinstall/tests", "xpinstall", "true", false,
false, true, (Date.now() / 1000) + 60);
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
Services.prefs.setIntPref("network.cookie.cookieBehavior", 1);
var triggers = encodeURIComponent(JSON.stringify({
"Cookie check": TESTROOT + "cookieRedirect.sjs?" + TESTROOT + "unsigned.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function check_xpi_install(addon, status) {
is(status, 0, "Install should succeed");
}
function finish_test() {
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
var cm = Components.classes["@mozilla.org/cookiemanager;1"]
.getService(Components.interfaces.nsICookieManager2);
cm.remove("example.com", "xpinstall", "/browser/xpinstall/tests", false);
Services.prefs.clearUserPref("network.cookie.cookieBehavior");
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,49 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Test that an install that requires cookies to be sent fails when cookies
// are set and third party cookies are disabled and the request is to a third
// party.
// This verifies bug 462739
function test() {
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var cm = Components.classes["@mozilla.org/cookiemanager;1"]
.getService(Components.interfaces.nsICookieManager2);
cm.add("example.com", "/browser/xpinstall/tests", "xpinstall", "true", false,
false, true, (Date.now() / 1000) + 60);
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
Services.prefs.setIntPref("network.cookie.cookieBehavior", 1);
var triggers = encodeURIComponent(JSON.stringify({
"Cookie check": TESTROOT2 + "cookieRedirect.sjs?" + TESTROOT + "unsigned.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function check_xpi_install(addon, status) {
is(status, -228, "Install should fail");
}
function finish_test() {
var cm = Components.classes["@mozilla.org/cookiemanager;1"]
.getService(Components.interfaces.nsICookieManager2);
cm.remove("example.com", "xpinstall", "/browser/xpinstall/tests", false);
Services.prefs.clearUserPref("network.cookie.cookieBehavior");
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,37 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Test whether an install fails when the xpi is corrupt.
function test() {
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Corrupt XPI": TESTROOT + "corrupt.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function check_xpi_install(addon, status) {
is(status, -207, "Install should fail");
}
function finish_test() {
Services.perms.remove("example.com", "install");
var doc = gBrowser.contentDocument;
is(doc.getElementById("status").textContent, "-207", "Callback should have seen the failure");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,34 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Test whether an install fails when there is no install script present.
function test() {
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Empty XPI": TESTROOT + "empty.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function check_xpi_install(addon, status) {
is(status, -204, "Install should fail");
}
function finish_test() {
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,27 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Test whether an InstallTrigger.enabled is working
function test() {
waitForExplicitFinish();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function() {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
// Allow the in-page load handler to run first
executeSoon(page_loaded);
}, true);
gBrowser.loadURI(TESTROOT + "enabled.html");
}
function page_loaded() {
var doc = gBrowser.contentDocument;
is(doc.getElementById("enabled").textContent, "true", "installTrigger should have been enabled");
gBrowser.removeCurrentTab();
finish();
}

View File

@ -1,31 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Test whether an InstallTrigger.enabled is working
function test() {
waitForExplicitFinish();
Services.prefs.setBoolPref("xpinstall.enabled", false);
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function() {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
// Allow the in-page load handler to run first
executeSoon(page_loaded);
}, true);
gBrowser.loadURI(TESTROOT + "enabled.html");
}
function page_loaded() {
Services.prefs.clearUserPref("xpinstall.enabled");
var doc = gBrowser.contentDocument;
is(doc.getElementById("enabled").textContent, "false", "installTrigger should have not been enabled");
gBrowser.removeCurrentTab();
finish();
}

View File

@ -1,35 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Test whether an InstallTrigger.install call fails when xpinstall is disabled
function test() {
waitForExplicitFinish();
Services.prefs.setBoolPref("xpinstall.enabled", false);
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": TESTROOT + "unsigned.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function() {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
// Allow the in-page load handler to run first
executeSoon(page_loaded);
}, true);
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function page_loaded() {
Services.prefs.clearUserPref("xpinstall.enabled");
var doc = gBrowser.contentDocument;
is(doc.getElementById("return").textContent, "false", "installTrigger should have not been enabled");
gBrowser.removeCurrentTab();
finish();
}
// ----------------------------------------------------------------------------

View File

@ -1,43 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Test whether an install succeeds when a valid hash is included
// This verifies bug 302284
function test() {
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": {
URL: TESTROOT + "unsigned.xpi",
Hash: "sha1:3d0dc22e1f394e159b08aaf5f0f97de4d5c65f4f",
toString: function() { return this.URL; }
}
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function check_xpi_install(addon, status) {
is(status, 0, "Install should succeed");
}
function finish_test() {
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,35 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests that calling InstallTrigger.installChrome works
function test() {
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installchrome.html? " + encodeURIComponent(TESTROOT + "unsigned.xpi"));
}
function check_xpi_install(addon, status) {
is(status, 0, "Install should succeed");
}
function finish_test() {
Services.perms.remove("example.com", "install");
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,35 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests installing an local file works when loading the url
function test() {
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var cr = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
.getService(Components.interfaces.nsIChromeRegistry);
var path = cr.convertChromeURL(makeURI(CHROMEROOT + "unsigned.xpi")).spec;
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(path);
}
function check_xpi_install(addon, status) {
is(status, 0, "Install should succeed");
}
function finish_test() {
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
gBrowser.removeCurrentTab();
Harness.finish();
}
// ----------------------------------------------------------------------------

View File

@ -1,36 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Test whether an install fails if the url is a local file when requested from
// web content
function test() {
waitForExplicitFinish();
var cr = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
.getService(Components.interfaces.nsIChromeRegistry);
var path = cr.convertChromeURL(makeURI(CHROMEROOT + "unsigned.xpi")).spec;
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": path
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.selectedBrowser.addEventListener("load", function() {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
// Allow the in-page load handler to run first
executeSoon(page_loaded);
}, true);
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function page_loaded() {
var doc = gBrowser.contentDocument;
is(doc.getElementById("return").textContent, "exception", "installTrigger should have failed");
gBrowser.removeCurrentTab();
finish();
}
// ----------------------------------------------------------------------------

View File

@ -1,45 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests that navigating away from the initiating page during the install
// doesn't break the install.
// This verifies bug 473060
function test() {
Harness.downloadProgressCallback = download_progress;
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": TESTROOT + "unsigned.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function download_progress(addon, value, maxValue) {
gBrowser.loadURI("about:blank");
}
function check_xpi_install(addon, status) {
is(status, 0, "Install should succeed");
}
function finish_test() {
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,44 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests that closing the initiating page during the install doesn't break the
// install.
// This verifies bugs 473060 and 475347
function test() {
Harness.downloadProgressCallback = download_progress;
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": TESTROOT + "unsigned.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function download_progress(addon, value, maxValue) {
gBrowser.removeCurrentTab();
}
function check_xpi_install(addon, status) {
is(status, 0, "Install should succeed");
}
function finish_test() {
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
Services.perms.remove("example.com", "install");
Harness.finish();
}

View File

@ -1,50 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests that going offline cancels an in progress download.
function test() {
Harness.downloadProgressCallback = download_progress;
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": TESTROOT + "unsigned.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function download_progress(addon, value, maxValue) {
try {
Services.io.manageOfflineStatus = false;
Services.prefs.setBoolPref("browser.offline", true);
Services.io.offline = true;
} catch (ex) {
}
}
function check_xpi_install(addon, status) {
is(status, -210, "Install should be cancelled");
}
function finish_test() {
try {
Services.prefs.setBoolPref("browser.offline", false);
Services.io.offline = false;
} catch (ex) {
}
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,41 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Test whether an install succeeds when the progress dialog is already open.
function test() {
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
window.openDialog("chrome://mozapps/content/extensions/extensions.xul", "",
"chrome,menubar,extra-chrome,toolbar,dialog=no,resizable");
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": TESTROOT + "unsigned.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function check_xpi_install(addon, status) {
is(status, 0, "Install should succeed");
}
function finish_test() {
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,56 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests installing two signed add-ons in the same trigger works.
// This verifies bug 453545
function test() {
Harness.installConfirmCallback = confirm_install;
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Signed XPI": TESTROOT + "signed.xpi",
"Signed XPI 2": TESTROOT + "signed2.xpi",
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function confirm_install(window) {
items = window.document.getElementById("itemList").childNodes;
is(items.length, 2, "Should be 2 items listed in the confirmation dialog");
is(items[0].name, "Signed XPI", "Should have seen the name from the trigger list");
is(items[0].url, TESTROOT + "signed.xpi", "Should have listed the correct url for the item");
is(items[0].cert, "(Object Signer)", "Should have seen the signer");
is(items[0].signed, "true", "Should have listed the item as signed");
is(items[1].name, "Signed XPI 2", "Should have seen the name from the trigger list");
is(items[1].url, TESTROOT + "signed2.xpi", "Should have listed the correct url for the item");
is(items[1].cert, "(Object Signer)", "Should have seen the signer");
is(items[1].signed, "true", "Should have listed the item as signed");
return true;
}
function check_xpi_install(addon, status) {
is(status, 0, "Installs should succeed");
}
function finish_test() {
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("signed-xpi@tests.mozilla.org");
em.cancelInstallItem("signed-xpi2@tests.mozilla.org");
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,63 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests that the correct signer is presented for combinations of O and CN present.
// The signed files have (when present) O=Mozilla Testing, CN=Object Signer
// This verifies bug 372980
function test() {
Harness.installConfirmCallback = confirm_install;
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Signed XPI (O and CN)": TESTROOT + "signed.xpi",
"Signed XPI (CN)": TESTROOT + "signed-no-o.xpi",
"Signed XPI (O)": TESTROOT + "signed-no-cn.xpi",
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function confirm_install(window) {
items = window.document.getElementById("itemList").childNodes;
is(items.length, 3, "Should be 3 items listed in the confirmation dialog");
is(items[0].name, "Signed XPI (O and CN)", "Should have seen the name from the trigger list");
is(items[0].url, TESTROOT + "signed.xpi", "Should have listed the correct url for the item");
is(items[0].cert, "(Object Signer)", "Should have seen the signer");
is(items[0].signed, "true", "Should have listed the item as signed");
is(items[1].name, "Signed XPI (CN)", "Should have seen the name from the trigger list");
is(items[1].url, TESTROOT + "signed-no-o.xpi", "Should have listed the correct url for the item");
is(items[1].cert, "(Object Signer)", "Should have seen the signer");
is(items[1].signed, "true", "Should have listed the item as signed");
is(items[2].name, "Signed XPI (O)", "Should have seen the name from the trigger list");
is(items[2].url, TESTROOT + "signed-no-cn.xpi", "Should have listed the correct url for the item");
is(items[2].cert, "(Mozilla Testing)", "Should have seen the signer");
is(items[2].signed, "true", "Should have listed the item as signed");
return true;
}
function check_xpi_install(addon, status) {
is(status, 0, "Installs should succeed");
}
function finish_test() {
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("signed-xpi@tests.mozilla.org");
em.cancelInstallItem("signed-xpi-no-o@tests.mozilla.org");
em.cancelInstallItem("signed-xpi-no-cn@tests.mozilla.org");
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,45 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests installing a signed add-on that has been tampered with after signing.
function test() {
Harness.installConfirmCallback = confirm_install;
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Tampered Signed XPI": TESTROOT + "signed-tampered.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function confirm_install(window) {
items = window.document.getElementById("itemList").childNodes;
is(items.length, 1, "Should only be 1 item listed in the confirmation dialog");
is(items[0].name, "Tampered Signed XPI", "Should have seen the name from the trigger list");
is(items[0].url, TESTROOT + "signed-tampered.xpi", "Should have listed the correct url for the item");
is(items[0].cert, "(Object Signer)", "Should have seen the signer");
is(items[0].signed, "true", "Should have listed the item as signed");
return true;
}
function check_xpi_install(addon, status) {
is(status, -260, "Install should fail");
}
function finish_test() {
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,50 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests installing an signed add-on through an InstallTrigger call in web
// content.
function test() {
Harness.installConfirmCallback = confirm_install;
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Signed XPI": TESTROOT + "signed.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function confirm_install(window) {
items = window.document.getElementById("itemList").childNodes;
is(items.length, 1, "Should only be 1 item listed in the confirmation dialog");
is(items[0].name, "Signed XPI", "Should have seen the name from the trigger list");
is(items[0].url, TESTROOT + "signed.xpi", "Should have listed the correct url for the item");
is(items[0].cert, "(Object Signer)", "Should have seen the signer");
is(items[0].signed, "true", "Should have listed the item as signed");
return true;
}
function check_xpi_install(addon, status) {
is(status, 0, "Install should succeed");
}
function finish_test() {
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("signed-xpi@tests.mozilla.org");
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,47 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests installing an add-on signed by an untrusted certificate through an
// InstallTrigger call in web content.
function test() {
Harness.installConfirmCallback = confirm_install;
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Untrusted Signed XPI": TESTROOT + "signed-untrusted.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function confirm_install(window) {
items = window.document.getElementById("itemList").childNodes;
is(items.length, 1, "Should only be 1 item listed in the confirmation dialog");
is(items[0].name, "Untrusted Signed XPI", "Should have seen the name from the trigger list");
is(items[0].url, TESTROOT + "signed-untrusted.xpi", "Should have listed the correct url for the item");
is(items[0].cert, "(Unknown Signer)", "Should have seen the supposed signer");
is(items[0].signed, "true", "Should have listed the item as signed");
return true;
}
function check_xpi_install(addon, status) {
is(status, -260, "Install should fail");
}
function finish_test() {
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}
// ----------------------------------------------------------------------------

View File

@ -1,42 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests installing an signed add-on by navigating directly to the url
function test() {
Harness.installConfirmCallback = confirm_install;
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "signed.xpi");
}
function confirm_install(window) {
items = window.document.getElementById("itemList").childNodes;
is(items.length, 1, "Should only be 1 item listed in the confirmation dialog");
is(items[0].name, "signed.xpi", "Should have had the filename for the item name");
is(items[0].url, TESTROOT + "signed.xpi", "Should have listed the correct url for the item");
is(items[0].cert, "(Object Signer)", "Should have seen the signer");
is(items[0].signed, "true", "Should have listed the item as signed");
return true;
}
function check_xpi_install(addon, status) {
is(status, 0, "Install should succeed");
}
function finish_test() {
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("signed-xpi@tests.mozilla.org");
gBrowser.removeCurrentTab();
Harness.finish();
}
// ----------------------------------------------------------------------------

View File

@ -1,35 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests that calling InstallTrigger.startSoftwareUpdate works
function test() {
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "startsoftwareupdate.html? " + encodeURIComponent(TESTROOT + "unsigned.xpi"));
}
function check_xpi_install(addon, status) {
is(status, 0, "Install should succeed");
}
function finish_test() {
Services.perms.remove("example.com", "install");
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,58 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests installing an unsigned add-on through an InstallTrigger call in web
// content.
function test() {
Harness.installConfirmCallback = confirm_install;
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": {
URL: TESTROOT + "unsigned.xpi",
IconURL: TESTROOT + "icon.png",
toString: function() { return this.URL; }
}
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function confirm_install(window) {
items = window.document.getElementById("itemList").childNodes;
is(items.length, 1, "Should only be 1 item listed in the confirmation dialog");
is(items[0].name, "Unsigned XPI", "Should have seen the name from the trigger list");
is(items[0].url, TESTROOT + "unsigned.xpi", "Should have listed the correct url for the item");
is(items[0].icon, TESTROOT + "icon.png", "Should have listed the correct icon for the item");
is(items[0].signed, "false", "Should have listed the item as unsigned");
return true;
}
function check_xpi_install(addon, status) {
is(status, 0, "Install should succeed");
}
function finish_test() {
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
Services.perms.remove("example.com", "install");
var doc = gBrowser.contentDocument;
is(doc.getElementById("return").textContent, "true", "installTrigger should have claimed success");
is(doc.getElementById("status").textContent, "0", "Callback should have seen a success");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,42 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests installing an unsigned add-on by navigating directly to the url
function test() {
Harness.installConfirmCallback = confirm_install;
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "unsigned.xpi");
}
function confirm_install(window) {
items = window.document.getElementById("itemList").childNodes;
is(items.length, 1, "Should only be 1 item listed in the confirmation dialog");
is(items[0].name, "unsigned.xpi", "Should have had the filename for the item name");
is(items[0].url, TESTROOT + "unsigned.xpi", "Should have listed the correct url for the item");
is(items[0].icon, "", "Should have listed no icon for the item");
is(items[0].signed, "false", "Should have listed the item as unsigned");
return true;
}
function check_xpi_install(addon, status) {
is(status, 0, "Install should succeed");
}
function finish_test() {
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
gBrowser.removeCurrentTab();
Harness.finish();
}
// ----------------------------------------------------------------------------

View File

@ -1,53 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests installing an unsigned add-on through an InstallTrigger call in web
// content. This should be blocked by the whitelist check.
// This verifies bug 252830
function test() {
Harness.installConfirmCallback = confirm_install;
Harness.installBlockedCallback = allow_blocked;
Harness.installEndedCallback = check_xpi_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": TESTROOT + "unsigned.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function allow_blocked(installInfo) {
is(installInfo.originatingWindow, gBrowser.contentWindow, "Install should have been triggered by the right window");
is(installInfo.originatingURI.spec, gBrowser.currentURI.spec, "Install should have been triggered by the right uri");
return true;
}
function confirm_install(window) {
items = window.document.getElementById("itemList").childNodes;
is(items.length, 1, "Should only be 1 item listed in the confirmation dialog");
is(items[0].name, "Unsigned XPI", "Should have seen the name from the trigger list");
is(items[0].url, TESTROOT + "unsigned.xpi", "Should have listed the correct url for the item");
is(items[0].signed, "false", "Should have listed the item as unsigned");
return true;
}
function check_xpi_install(addon, status) {
is(status, 0, "Install should succeed");
}
function finish_test() {
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
gBrowser.removeCurrentTab();
Harness.finish();
}
// ----------------------------------------------------------------------------

View File

@ -1,38 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests installing an unsigned add-on through an InstallTrigger call in web
// content. This should be blocked by the whitelist check because the source
// is not whitelisted, even though the target is.
function test() {
Harness.installBlockedCallback = allow_blocked;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.org/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": TESTROOT2 + "unsigned.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}
function allow_blocked(installInfo) {
is(installInfo.originatingWindow, gBrowser.contentWindow, "Install should have been triggered by the right window");
is(installInfo.originatingURI.spec, gBrowser.currentURI.spec, "Install should have been triggered by the right uri");
return false;
}
function finish_test() {
Services.perms.remove("example.org", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,35 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests installing an unsigned add-on through a navigation. Should not be
// blocked since the referer is whitelisted.
function test() {
Harness.installConfirmCallback = confirm_install;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.org/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": TESTROOT2 + "unsigned.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "unsigned.xpi", makeURI(TESTROOT2 + "test.html"));
}
function confirm_install(window) {
return false;
}
function finish_test() {
Services.perms.remove("example.org", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,37 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests installing an unsigned add-on through a navigation. Should be
// blocked since the referer is not whitelisted even though the target is.
function test() {
Harness.installBlockedCallback = allow_blocked;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
var pm = Services.perms;
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
var triggers = encodeURIComponent(JSON.stringify({
"Unsigned XPI": TESTROOT2 + "unsigned.xpi"
}));
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "unsigned.xpi", makeURI(TESTROOT2 + "test.html"));
}
function allow_blocked(installInfo) {
is(installInfo.originatingWindow, gBrowser.contentWindow, "Install should have been triggered by the right window");
is(installInfo.originatingURI.spec, TESTROOT2 + "test.html", "Install should have been triggered by the right uri");
return false;
}
function finish_test() {
Services.perms.remove("example.com", "install");
gBrowser.removeCurrentTab();
Harness.finish();
}

View File

@ -1,31 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests installing an unsigned add-on through a startSoftwareUpdate call in web
// content. This should be blocked by the whitelist check.
// This verifies bug 252830
function test() {
Harness.installBlockedCallback = allow_blocked;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "startsoftwareupdate.html? " + encodeURIComponent(TESTROOT + "unsigned.xpi"));
}
function allow_blocked(installInfo) {
is(installInfo.originatingWindow, gBrowser.contentWindow, "Install should have been triggered by the right window");
is(installInfo.originatingURI.spec, gBrowser.currentURI.spec, "Install should have been triggered by the right uri");
return false;
}
function finish_test() {
gBrowser.removeCurrentTab();
Harness.finish();
}
// ----------------------------------------------------------------------------

View File

@ -1,31 +0,0 @@
// Load in the test harness
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
var rootDir = getRootDirectory(window.location.href);
scriptLoader.loadSubScript(rootDir + "harness.js", this);
// ----------------------------------------------------------------------------
// Tests installing an unsigned add-on through an installChrome call in web
// content. This should be blocked by the whitelist check.
// This verifies bug 252830
function test() {
Harness.installBlockedCallback = allow_blocked;
Harness.installsCompletedCallback = finish_test;
Harness.setup();
gBrowser.selectedTab = gBrowser.addTab();
gBrowser.loadURI(TESTROOT + "installchrome.html? " + encodeURIComponent(TESTROOT + "unsigned.xpi"));
}
function allow_blocked(installInfo) {
is(installInfo.originatingWindow, gBrowser.contentWindow, "Install should have been triggered by the right window");
is(installInfo.originatingURI.spec, gBrowser.currentURI.spec, "Install should have been triggered by the right uri");
return false;
}
function finish_test() {
gBrowser.removeCurrentTab();
Harness.finish();
}
// ----------------------------------------------------------------------------

View File

@ -1,23 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<!-- This page tests that window.InstallTrigger.install works -->
<head>
<title>InstallTrigger tests</title>
<script type="text/javascript">
function startInstall() {
window.InstallTrigger.install({
"Unsigned XPI": "http://example.com/browser/xpinstall/tests/unsigned.xpi"
});
}
</script>
</head>
<body onload="startInstall()">
<p>InstallTrigger tests</p>
<p id="return"></p>
<p id="status"></p>
</body>
</html>

View File

@ -1,24 +0,0 @@
// Simple script redirects to the query part of the uri if the cookie "xpinstall"
// has the value "true", otherwise gives a 500 error.
function handleRequest(request, response)
{
let cookie = null;
if (request.hasHeader("Cookie")) {
let cookies = request.getHeader("Cookie").split(";");
for (let i = 0; i < cookies.length; i++) {
if (cookies[i].substring(0, 10) == "xpinstall=")
cookie = cookies[i].substring(10);
}
}
if (cookie == "true") {
response.setStatusLine(request.httpVersion, 302, "Found");
response.setHeader("Location", request.queryString);
response.write("See " + request.queryString);
}
else {
response.setStatusLine(request.httpVersion, 500, "Internal Server Error");
response.write("Invalid request");
}
}

View File

@ -1 +0,0 @@
This is a corrupt zip file

Binary file not shown.

View File

@ -1,20 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<!-- This page will test if InstallTrigger seems to be enabled -->
<head>
<title>InstallTrigger tests</title>
<script type="text/javascript">
function init() {
document.getElementById("enabled").textContent = InstallTrigger.enabled() ? "true" : "false";
}
</script>
</head>
<body onload="init()">
<p>InstallTrigger tests</p>
<p id="enabled"></p>
</body>
</html>

View File

@ -1,246 +0,0 @@
const TESTROOT = "http://example.com/browser/xpinstall/tests/";
const TESTROOT2 = "http://example.org/browser/xpinstall/tests/";
const XPINSTALL_URL = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul";
const PROMPT_URL = "chrome://global/content/commonDialog.xul";
const ADDONS_URL = "chrome://mozapps/content/extensions/extensions.xul";
var rootDir = getRootDirectory(gTestPath);
var path = rootDir.split('/');
var chromeName = path[0] + '//' + path[2];
var croot = chromeName + "/content/browser/xpinstall/tests/";
var jar = getJar(croot);
if (jar) {
var tmpdir = extractJarToTmp(jar);
croot = 'file://' + tmpdir.path + '/';
}
const CHROMEROOT = croot;
/**
* This is a test harness designed to handle responding to UI during the process
* of installing an XPI. A test can set callbacks to hear about specific parts
* of the sequence.
* Before use setup must be called and finish must be called afterwards.
*/
var Harness = {
// If set then the install is expected to be blocked by the whitelist. The
// callback should return true to continue with the install anyway.
installBlockedCallback: null,
// If set will be called in the event of authentication being needed to get
// the xpi. Should return a 2 element array of username and password, or
// null to not authenticate.
authenticationCallback: null,
// If set this will be called to allow checking the contents of the xpinstall
// confirmation dialog. The callback should return true to continue the install.
installConfirmCallback: null,
// If set will be called when downloading of an item has begun.
downloadStartedCallback: null,
// If set will be called during the download of an item.
downloadProgressCallback: null,
// If set will be called when downloading of an item has ended.
downloadEndedCallback: null,
// If set will be called when installation by the extension manager of an xpi
// item starts
installStartedCallback: null,
// If set will be called when each xpi item to be installed completes
// installation.
installEndedCallback: null,
// If set will be called when all triggered items are installed or the install
// is canceled.
installsCompletedCallback: null,
listenerIndex: null,
// Setup and tear down functions
setup: function() {
waitForExplicitFinish();
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
os.addObserver(this, "xpinstall-install-blocked", false);
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
wm.addListener(this);
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
this.listenerIndex = em.addInstallListener(this);
},
finish: function() {
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
os.removeObserver(this, "xpinstall-install-blocked");
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
wm.removeListener(this);
var win = wm.getMostRecentWindow("Extension:Manager");
if (win)
win.close();
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
em.removeInstallListenerAt(this.listenerIndex);
finish();
},
endTest: function() {
// Defer the final notification to allow things like the InstallTrigger
// callback to complete
executeSoon(this.installsCompletedCallback);
this.installBlockedCallback = null;
this.authenticationCallback = null;
this.installConfirmCallback = null;
this.downloadStartedCallback = null;
this.downloadProgressCallback = null;
this.downloadEndedCallback = null;
this.installStartedCallback = null;
this.installEndedCallback = null;
this.installsCompletedCallback = null;
},
// Window open handling
windowLoad: function(window) {
// Allow any other load handlers to execute
var self = this;
executeSoon(function() { self.windowReady(window); } );
},
windowReady: function(window) {
if (window.document.location.href == XPINSTALL_URL) {
if (this.installBlockedCallback)
ok(false, "Should have been blocked by the whitelist");
// If there is a confirm callback then its return status determines whether
// to install the items or not. If not the test is over.
if (this.installConfirmCallback && !this.installConfirmCallback(window)) {
window.document.documentElement.cancelDialog();
this.endTest();
}
else {
// Initially the accept button is disabled on a countdown timer
var button = window.document.documentElement.getButton("accept");
button.disabled = false;
window.document.documentElement.acceptDialog();
}
}
else if (window.document.location.href == PROMPT_URL) {
switch (window.args.promptType) {
default:
if (window.opener.document.location.href == ADDONS_URL) {
// A prompt opened by the add-ons manager is liable to be an
// xpinstall error, just close it, we'll see the error in
// onInstallEnded anyway.
window.document.documentElement.acceptDialog();
}
break;
case "promptUserAndPass":
// This is a login dialog, hopefully an authentication prompt
// for the xpi.
if (this.authenticationCallback) {
var auth = this.authenticationCallback();
if (auth && auth.length == 2) {
window.document.getElementById("loginTextbox").value = auth[0];
window.document.getElementById("password1Textbox").value = auth[1];
window.document.documentElement.acceptDialog();
}
else {
window.document.documentElement.cancelDialog();
}
}
else {
window.document.documentElement.cancelDialog();
}
break;
}
}
},
// Install blocked handling
installBlocked: function(installInfo) {
ok(!!this.installBlockedCallback, "Shouldn't have been blocked by the whitelist");
if (this.installBlockedCallback && this.installBlockedCallback(installInfo)) {
this.installBlockedCallback = null;
var mgr = Components.classes["@mozilla.org/xpinstall/install-manager;1"]
.createInstance(Components.interfaces.nsIXPInstallManager);
mgr.initManagerWithInstallInfo(installInfo);
}
else {
this.endTest();
}
},
// nsIWindowMediatorListener
onWindowTitleChange: function(window, title) {
},
onOpenWindow: function(window) {
var domwindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);
var self = this;
domwindow.addEventListener("load", function() {
self.windowLoad(domwindow);
}, false);
},
onCloseWindow: function(window) {
},
// nsIAddonInstallListener
onDownloadStarted: function(addon) {
if (this.downloadStartedCallback)
this.downloadStartedCallback(addon);
},
onDownloadProgress: function(addon, value, maxValue) {
if (this.downloadProgressCallback)
this.downloadProgressCallback(addon, value, maxValue);
},
onDownloadEnded: function(addon) {
if (this.downloadEndedCallback)
this.downloadEndedCallback(addon);
},
onInstallStarted: function(addon) {
if (this.installStartedCallback)
this.installStartedCallback(addon);
},
onCompatibilityCheckStarted: function(addon) {
},
onCompatibilityCheckEnded: function(addon, status) {
},
onInstallEnded: function(addon, status) {
if (this.installEndedCallback)
this.installEndedCallback(addon, status);
},
onInstallsCompleted: function() {
this.endTest();
},
// nsIObserver
observe: function(subject, topic, data) {
var installInfo = subject.QueryInterface(Components.interfaces.nsIXPIInstallInfo);
this.installBlocked(installInfo);
},
QueryInterface: function(iid) {
if (iid.equals(Components.interfaces.nsIObserver) ||
iid.equals(Components.interfaces.nsIAddonInstallListener) ||
iid.equals(Components.interfaces.nsIWindowMediatorListener) ||
iid.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
}
}

View File

@ -1,21 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<!-- This page will accept a url as the uri query and pass it to InstallTrigger.installChrome -->
<head>
<title>InstallTrigger tests</title>
<script type="text/javascript">
function startInstall() {
InstallTrigger.installChrome(InstallTrigger.SKIN,
decodeURIComponent(document.location.search.substring(1)),
"test");
}
</script>
</head>
<body onload="startInstall()">
<p>InstallTrigger tests</p>
</body>
</html>

View File

@ -1,32 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<!-- This page will accept some json as the uri query and pass it to InstallTrigger.install -->
<head>
<title>InstallTrigger tests</title>
<script type="text/javascript">
function installCallback(url, status) {
document.getElementById("status").textContent = status;
}
function startInstall() {
var text = decodeURIComponent(document.location.search.substring(1));
var triggers = JSON.parse(text);
try {
document.getElementById("return").textContent = InstallTrigger.install(triggers, installCallback);
}
catch (e) {
document.getElementById("return").textContent = "exception";
}
}
</script>
</head>
<body onload="startInstall()">
<p>InstallTrigger tests</p>
<p id="return"></p>
<p id="status"></p>
</body>
</html>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,19 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<!-- This page will accept a url as the uri query and pass it to InstallTrigger.startSoftwareUpdate -->
<head>
<title>InstallTrigger tests</title>
<script type="text/javascript">
function startInstall() {
InstallTrigger.startSoftwareUpdate(decodeURIComponent(document.location.search.substring(1)));
}
</script>
</head>
<body onload="startInstall()">
<p>InstallTrigger tests</p>
</body>
</html>

Binary file not shown.