Bug 252830: Blocked XPI install should have allow once feature. r+sr=dveditz, r=gavin.sharp, a=bzbarsky
This commit is contained in:
Родитель
e424c0dd34
Коммит
5847ea8113
|
@ -662,13 +662,16 @@ const gXPInstallObserver = {
|
|||
{
|
||||
var brandBundle = document.getElementById("bundle_brand");
|
||||
var browserBundle = document.getElementById("bundle_browser");
|
||||
var browser, webNav, wm;
|
||||
switch (aTopic) {
|
||||
case "xpinstall-install-blocked":
|
||||
var shell = aSubject.QueryInterface(Components.interfaces.nsIDocShell);
|
||||
browser = this._getBrowser(shell);
|
||||
var installInfo = aSubject.QueryInterface(Components.interfaces.nsIXPIInstallInfo);
|
||||
var win = installInfo.originatingWindow;
|
||||
var shell = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIWebNavigation)
|
||||
.QueryInterface(Components.interfaces.nsIDocShell);
|
||||
var browser = this._getBrowser(shell);
|
||||
if (browser) {
|
||||
var host = aData;
|
||||
var host = installInfo.originatingURI.host;
|
||||
var brandShortName = brandBundle.getString("brandShortName");
|
||||
var notificationName, messageString, buttons;
|
||||
if (!gPrefService.getBoolPref("xpinstall.enabled")) {
|
||||
|
@ -698,10 +701,15 @@ const gXPInstallObserver = {
|
|||
[brandShortName, host]);
|
||||
|
||||
buttons = [{
|
||||
label: browserBundle.getString("xpinstallPromptWarningButton"),
|
||||
accessKey: browserBundle.getString("xpinstallPromptWarningButton.accesskey"),
|
||||
label: browserBundle.getString("xpinstallPromptAllowButton"),
|
||||
accessKey: browserBundle.getString("xpinstallPromptAllowButton.accesskey"),
|
||||
popup: null,
|
||||
callback: function() { return xpinstallEditPermissions(shell, host); }
|
||||
callback: function() {
|
||||
var mgr = Components.classes["@mozilla.org/xpinstall/install-manager;1"]
|
||||
.createInstance(Components.interfaces.nsIXPInstallManager);
|
||||
mgr.initManagerWithInstallInfo(installInfo);
|
||||
return false;
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
|
@ -718,34 +726,6 @@ const gXPInstallObserver = {
|
|||
}
|
||||
};
|
||||
|
||||
function xpinstallEditPermissions(aDocShell, aHost)
|
||||
{
|
||||
var browser = gXPInstallObserver._getBrowser(aDocShell);
|
||||
if (browser) {
|
||||
var bundlePreferences = document.getElementById("bundle_preferences");
|
||||
var params = { blockVisible : false,
|
||||
sessionVisible : false,
|
||||
allowVisible : true,
|
||||
prefilledHost : aHost,
|
||||
permissionType : "install",
|
||||
windowTitle : bundlePreferences.getString("addons_permissions_title"),
|
||||
introText : bundlePreferences.getString("addonspermissionstext") };
|
||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||
.getService(Components.interfaces.nsIWindowMediator);
|
||||
var existingWindow = wm.getMostRecentWindow("Browser:Permissions");
|
||||
if (existingWindow) {
|
||||
existingWindow.initWithParams(params);
|
||||
existingWindow.focus();
|
||||
}
|
||||
else
|
||||
window.openDialog("chrome://browser/content/preferences/permissions.xul",
|
||||
"_blank", "resizable,dialog=no,centerscreen", params);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function BrowserStartup()
|
||||
{
|
||||
gBrowser = document.getElementById("content");
|
||||
|
|
|
@ -28,11 +28,11 @@ bookmarkCurTab_accesskey=B
|
|||
bookmarkAllTabsDefault=[Folder Name]
|
||||
|
||||
xpinstallPromptWarning=%S prevented this site (%S) from asking you to install software on your computer.
|
||||
xpinstallPromptWarningButton=Edit Options...
|
||||
xpinstallPromptAllowButton=Allow
|
||||
# Accessibility Note:
|
||||
# Be sure you do not choose an accesskey that is used elsewhere in the active context (e.g. main menu bar, submenu of the warning popup button)
|
||||
# See http://www.mozilla.org/access/keyboard/accesskey for details
|
||||
xpinstallPromptWarningButton.accesskey=O
|
||||
xpinstallPromptAllowButton.accesskey=A
|
||||
xpinstallDisabledMessageLocked=Software installation has been disabled by your system administrator.
|
||||
xpinstallDisabledMessage=Software installation is currently disabled. Click Enable and try again.
|
||||
xpinstallDisabledButton=Enable
|
||||
|
|
|
@ -53,6 +53,7 @@ XPIDLSRCS = \
|
|||
nsIXPIProgressDialog.idl \
|
||||
nsIXPINotifier.idl \
|
||||
nsIXPInstallManager.idl \
|
||||
nsIXPIInstallInfo.idl \
|
||||
nsPIXPIProxy.idl \
|
||||
nsPIXPIStubHook.idl \
|
||||
nsPICertNotification.idl \
|
||||
|
|
|
@ -42,11 +42,12 @@
|
|||
#include "nsString.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsXPITriggerInfo.h"
|
||||
#include "nsIXPIInstallInfo.h"
|
||||
|
||||
|
||||
#define NS_IDOMINSTALLTRIGGERGLOBAL_IID \
|
||||
{ 0x18c2f987, 0xb09f, 0x11d2, \
|
||||
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}}
|
||||
{ 0xe8c7941c, 0xaaa0, 0x4faf, \
|
||||
{0x83, 0xe8, 0x01, 0xbe, 0x8b, 0xbe, 0x8a, 0x57}}
|
||||
|
||||
class nsIDOMInstallTriggerGlobal : public nsISupports {
|
||||
public:
|
||||
|
@ -60,8 +61,14 @@ public:
|
|||
EQUAL = 0
|
||||
};
|
||||
|
||||
NS_IMETHOD GetOriginatingURI(nsIScriptGlobalObject* aGlobalObject, nsIURI * *aUri)=0;
|
||||
|
||||
NS_IMETHOD UpdateEnabled(nsIScriptGlobalObject* aGlobalObject, PRBool aUseWhitelist, PRBool* aReturn)=0;
|
||||
|
||||
NS_IMETHOD UpdateEnabled(nsIURI* aURI, PRBool aUseWhitelist, PRBool* aReturn)=0;
|
||||
|
||||
NS_IMETHOD StartInstall(nsIXPIInstallInfo* aInstallInfo, PRBool* aReturn)=0;
|
||||
|
||||
NS_IMETHOD Install(nsIScriptGlobalObject* globalObject, nsXPITriggerInfo* aInfo, PRBool* aReturn)=0;
|
||||
|
||||
NS_IMETHOD InstallChrome(nsIScriptGlobalObject* globalObject, PRUint32 aType, nsXPITriggerItem* aItem, PRBool* aReturn)=0;
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/* ***** 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 nsIDOMWindowInternal;
|
||||
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 nsIDOMWindowInternal 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;
|
||||
};
|
|
@ -37,11 +37,12 @@
|
|||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIXPIProgressDialog;
|
||||
interface nsIXPIInstallInfo;
|
||||
|
||||
/**
|
||||
* Interface to XPInstallManager - manages download and install operations.
|
||||
*/
|
||||
[scriptable, uuid(566689cb-9926-4bec-a66e-a034e364ad2c)]
|
||||
[scriptable, uuid(83fdd52f-2d34-4e22-981d-cf3c4ae76faa)]
|
||||
interface nsIXPInstallManager : nsISupports
|
||||
{
|
||||
/**
|
||||
|
@ -70,5 +71,14 @@ interface nsIXPInstallManager : nsISupports
|
|||
[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);
|
||||
};
|
||||
|
||||
|
|
|
@ -124,6 +124,7 @@ CPPSRCS = \
|
|||
nsJSFileSpecObj.cpp \
|
||||
nsInstallLogComment.cpp \
|
||||
nsInstallBitwise.cpp \
|
||||
nsXPIInstallInfo.cpp \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(OS_ARCH),WINNT)
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "nsIDOMInstallTriggerGlobal.h"
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "netCore.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsISupports.h"
|
||||
|
@ -69,7 +70,7 @@
|
|||
#include "nsIContentHandler.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIURI.h"
|
||||
|
||||
#include "nsXPIInstallInfo.h"
|
||||
|
||||
|
||||
nsInstallTrigger::nsInstallTrigger()
|
||||
|
@ -190,13 +191,7 @@ nsInstallTrigger::HandleContent(const char * aContentType,
|
|||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
|
||||
// We have what we need to start an XPInstall, now figure out if we are
|
||||
// going to honor this request based on PermissionManager settings
|
||||
PRBool enabled = PR_FALSE;
|
||||
// Keep the host so that it can be sent to the
|
||||
// xpinstall-install-blocked observers to display the host to be
|
||||
// whitelisted
|
||||
nsCAutoString host;
|
||||
nsCOMPtr<nsIURI> checkuri;
|
||||
|
||||
if ( useReferrer )
|
||||
{
|
||||
|
@ -207,10 +202,8 @@ nsInstallTrigger::HandleContent(const char * aContentType,
|
|||
// 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.
|
||||
|
||||
enabled = AllowInstall( referringURI );
|
||||
if (referringURI)
|
||||
referringURI->GetHost(host);
|
||||
|
||||
checkuri = referringURI;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -246,31 +239,39 @@ nsInstallTrigger::HandleContent(const char * aContentType,
|
|||
// controls) and will require community policing of the default
|
||||
// trusted sites.
|
||||
|
||||
enabled = AllowInstall( uri );
|
||||
uri->GetHost(host);
|
||||
checkuri = uri;
|
||||
}
|
||||
|
||||
|
||||
if ( enabled )
|
||||
nsAutoPtr<nsXPITriggerInfo> trigger(new nsXPITriggerInfo());
|
||||
nsAutoPtr<nsXPITriggerItem> item(new nsXPITriggerItem(0, NS_ConvertUTF8toUTF16(urispec).get(),
|
||||
nsnull));
|
||||
if (trigger && item)
|
||||
{
|
||||
rv = StartSoftwareUpdate( globalObject,
|
||||
NS_ConvertUTF8toUTF16(urispec),
|
||||
0,
|
||||
&enabled);
|
||||
}
|
||||
else
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(globalObject));
|
||||
nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
|
||||
if (os) {
|
||||
os->NotifyObservers(win->GetDocShell(),
|
||||
"xpinstall-install-blocked",
|
||||
NS_ConvertUTF8toUTF16(host).get());
|
||||
// trigger will own the item now
|
||||
trigger->Add(item.forget());
|
||||
nsCOMPtr<nsIDOMWindowInternal> 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(do_GetService("@mozilla.org/observer-service;1"));
|
||||
if (os)
|
||||
os->NotifyObservers(installInfo,
|
||||
"xpinstall-install-blocked",
|
||||
nsnull);
|
||||
return NS_ERROR_ABORT;
|
||||
}
|
||||
}
|
||||
rv = NS_ERROR_ABORT;
|
||||
}
|
||||
|
||||
return rv;
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
||||
|
@ -384,8 +385,37 @@ nsInstallTrigger::AllowInstall(nsIURI* aLaunchURI)
|
|||
}
|
||||
|
||||
|
||||
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, PRBool aUseWhitelist, PRBool* 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, PRBool aUseWhitelist, PRBool* aReturn)
|
||||
{
|
||||
// disallow unless we successfully find otherwise
|
||||
*aReturn = PR_FALSE;
|
||||
|
@ -397,28 +427,35 @@ nsInstallTrigger::UpdateEnabled(nsIScriptGlobalObject* aGlobalObject, PRBool aUs
|
|||
if (prefBranch)
|
||||
prefBranch->GetBoolPref( XPINSTALL_ENABLE_PREF, aReturn);
|
||||
}
|
||||
else
|
||||
else if (aURI)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aGlobalObject);
|
||||
|
||||
// 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 )
|
||||
{
|
||||
*aReturn = AllowInstall( doc->GetDocumentURI() );
|
||||
}
|
||||
}
|
||||
*aReturn = AllowInstall(aURI);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInstallTrigger::StartInstall(nsIXPIInstallInfo* aInstallInfo, PRBool* aReturn)
|
||||
{
|
||||
if (aReturn)
|
||||
*aReturn = PR_FALSE;
|
||||
|
||||
nsXPInstallManager *mgr = new nsXPInstallManager();
|
||||
if (mgr)
|
||||
{
|
||||
nsresult rv = mgr->InitManagerWithInstallInfo(aInstallInfo);
|
||||
if (NS_SUCCEEDED(rv) && aReturn)
|
||||
*aReturn = PR_TRUE;
|
||||
return rv;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInstallTrigger::Install(nsIScriptGlobalObject* aGlobalObject, nsXPITriggerInfo* aTrigger, PRBool* aReturn)
|
||||
{
|
||||
|
@ -429,8 +466,9 @@ nsInstallTrigger::Install(nsIScriptGlobalObject* aGlobalObject, nsXPITriggerInfo
|
|||
nsXPInstallManager *mgr = new nsXPInstallManager();
|
||||
if (mgr)
|
||||
{
|
||||
nsCOMPtr<nsIDOMWindowInternal> win(do_QueryInterface(aGlobalObject));
|
||||
// The Install manager will delete itself when done
|
||||
rv = mgr->InitManager( aGlobalObject, aTrigger, 0 );
|
||||
rv = mgr->InitManager( win, aTrigger, 0 );
|
||||
if (NS_SUCCEEDED(rv))
|
||||
*aReturn = PR_TRUE;
|
||||
}
|
||||
|
@ -464,16 +502,22 @@ nsInstallTrigger::InstallChrome(nsIScriptGlobalObject* aGlobalObject, PRUint32 a
|
|||
{
|
||||
trigger->Add( aItem );
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> win(do_QueryInterface(aGlobalObject));
|
||||
// The Install manager will delete itself when done
|
||||
rv = mgr->InitManager( aGlobalObject, trigger, aType );
|
||||
rv = mgr->InitManager( win, trigger, aType );
|
||||
*aReturn = PR_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
delete mgr;
|
||||
delete aItem;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delete aItem;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -496,8 +540,9 @@ nsInstallTrigger::StartSoftwareUpdate(nsIScriptGlobalObject* aGlobalObject, cons
|
|||
if (item)
|
||||
{
|
||||
trigger->Add( item );
|
||||
nsCOMPtr<nsIDOMWindowInternal> win(do_QueryInterface(aGlobalObject));
|
||||
// The Install manager will delete itself when done
|
||||
rv = mgr->InitManager(aGlobalObject, trigger, 0 );
|
||||
rv = mgr->InitManager(win, trigger, 0 );
|
||||
*aReturn = PR_TRUE;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -47,7 +47,10 @@ class nsInstallTrigger: public nsIScriptObjectOwner,
|
|||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
NS_IMETHOD GetOriginatingURI(nsIScriptGlobalObject* aGlobalObject, nsIURI * *aUri);
|
||||
NS_IMETHOD UpdateEnabled(nsIScriptGlobalObject* aGlobalObject, PRBool aUseWhitelist, PRBool* aReturn);
|
||||
NS_IMETHOD UpdateEnabled(nsIURI* aURI, PRBool aUseWhitelist, PRBool* aReturn);
|
||||
NS_IMETHOD StartInstall(nsIXPIInstallInfo* aInstallInfo, PRBool* aReturn);
|
||||
NS_IMETHOD Install(nsIScriptGlobalObject* aGlobalObject, nsXPITriggerInfo *aInfo, PRBool* aReturn);
|
||||
NS_IMETHOD InstallChrome(nsIScriptGlobalObject* aGlobalObject, PRUint32 aType, nsXPITriggerItem* aItem, PRBool* aReturn);
|
||||
NS_IMETHOD StartSoftwareUpdate(nsIScriptGlobalObject* aGlobalObject, const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn);
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
|
||||
#include "jsapi.h"
|
||||
#include "nscore.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
|
@ -52,6 +53,7 @@
|
|||
#include "nsInstallTrigger.h"
|
||||
#include "nsXPITriggerInfo.h"
|
||||
#include "nsDOMJSUtils.h"
|
||||
#include "nsXPIInstallInfo.h"
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
@ -238,21 +240,9 @@ InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *arg
|
|||
if (scriptContext)
|
||||
globalObject = scriptContext->GetGlobalObject();
|
||||
|
||||
PRBool enabled = PR_FALSE;
|
||||
nativeThis->UpdateEnabled(globalObject, XPI_WHITELIST, &enabled);
|
||||
if (!enabled || !globalObject)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(globalObject));
|
||||
nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
|
||||
if (os)
|
||||
{
|
||||
os->NotifyObservers(win->GetDocShell(), "xpinstall-install-blocked",
|
||||
NS_LITERAL_STRING("install").get());
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
if (!globalObject)
|
||||
return JS_TRUE;
|
||||
|
||||
nsCOMPtr<nsIScriptSecurityManager> secman(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID));
|
||||
if (!secman)
|
||||
{
|
||||
|
@ -394,10 +384,36 @@ InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *arg
|
|||
// pass on only if good stuff found
|
||||
if (!abortLoad && trigger->Size() > 0)
|
||||
{
|
||||
PRBool result;
|
||||
nativeThis->Install(globalObject, trigger, &result);
|
||||
*rval = BOOLEAN_TO_JSVAL(result);
|
||||
return JS_TRUE;
|
||||
nsCOMPtr<nsIURI> checkuri;
|
||||
nsresult rv = nativeThis->GetOriginatingURI(globalObject,
|
||||
getter_AddRefs(checkuri));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsIDOMWindowInternal> win(do_QueryInterface(globalObject));
|
||||
nsCOMPtr<nsIXPIInstallInfo> installInfo =
|
||||
new nsXPIInstallInfo(win, checkuri, trigger, 0);
|
||||
if (installInfo)
|
||||
{
|
||||
// installInfo now owns triggers
|
||||
PRBool enabled = PR_FALSE;
|
||||
nativeThis->UpdateEnabled(checkuri, XPI_WHITELIST, &enabled);
|
||||
if (!enabled)
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
|
||||
if (os)
|
||||
os->NotifyObservers(installInfo,
|
||||
"xpinstall-install-blocked",
|
||||
nsnull);
|
||||
}
|
||||
else
|
||||
{
|
||||
PRBool 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;
|
||||
|
@ -434,21 +450,9 @@ InstallTriggerGlobalInstallChrome(JSContext *cx, JSObject *obj, uintN argc, jsva
|
|||
if (scriptContext)
|
||||
globalObject = scriptContext->GetGlobalObject();
|
||||
|
||||
PRBool enabled = PR_FALSE;
|
||||
nativeThis->UpdateEnabled(globalObject, XPI_WHITELIST, &enabled);
|
||||
if (!enabled || !globalObject)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(globalObject));
|
||||
nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
|
||||
if (os)
|
||||
{
|
||||
os->NotifyObservers(win->GetDocShell(), "xpinstall-install-blocked",
|
||||
NS_LITERAL_STRING("install").get());
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
if (!globalObject)
|
||||
return JS_TRUE;
|
||||
|
||||
// get window.location to construct relative URLs
|
||||
nsCOMPtr<nsIURI> baseURL;
|
||||
JSObject* global = JS_GetGlobalObject(cx);
|
||||
|
@ -484,13 +488,46 @@ InstallTriggerGlobalInstallChrome(JSContext *cx, JSObject *obj, uintN argc, jsva
|
|||
if ( chromeType & CHROME_ALL )
|
||||
{
|
||||
// there's at least one known chrome type
|
||||
nsXPITriggerItem* item = new nsXPITriggerItem(name.get(),
|
||||
sourceURL.get(),
|
||||
nsnull);
|
||||
|
||||
PRBool nativeRet = PR_FALSE;
|
||||
nativeThis->InstallChrome(globalObject, chromeType, item, &nativeRet);
|
||||
*rval = BOOLEAN_TO_JSVAL(nativeRet);
|
||||
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<nsIDOMWindowInternal> win(do_QueryInterface(globalObject));
|
||||
nsCOMPtr<nsIXPIInstallInfo> installInfo =
|
||||
new nsXPIInstallInfo(win, checkuri, trigger, chromeType);
|
||||
if (installInfo)
|
||||
{
|
||||
// installInfo owns trigger now
|
||||
trigger.forget();
|
||||
PRBool enabled = PR_FALSE;
|
||||
nativeThis->UpdateEnabled(checkuri, XPI_WHITELIST,
|
||||
&enabled);
|
||||
if (!enabled)
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
|
||||
if (os)
|
||||
os->NotifyObservers(installInfo,
|
||||
"xpinstall-install-blocked",
|
||||
nsnull);
|
||||
}
|
||||
else
|
||||
{
|
||||
PRBool nativeRet = PR_FALSE;
|
||||
nativeThis->StartInstall(installInfo, &nativeRet);
|
||||
*rval = BOOLEAN_TO_JSVAL(nativeRet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return JS_TRUE;
|
||||
|
@ -512,26 +549,14 @@ InstallTriggerGlobalStartSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc
|
|||
|
||||
*rval = JSVAL_FALSE;
|
||||
|
||||
// make sure XPInstall is enabled, return if not
|
||||
nsIScriptGlobalObject *globalObject = nsnull;
|
||||
nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
|
||||
if (scriptContext)
|
||||
globalObject = scriptContext->GetGlobalObject();
|
||||
|
||||
PRBool enabled = PR_FALSE;
|
||||
nativeThis->UpdateEnabled(globalObject, XPI_WHITELIST, &enabled);
|
||||
if (!enabled || !globalObject)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(globalObject));
|
||||
nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
|
||||
if (os)
|
||||
{
|
||||
os->NotifyObservers(win->GetDocShell(), "xpinstall-install-blocked",
|
||||
NS_LITERAL_STRING("install").get());
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (!globalObject)
|
||||
return JS_TRUE;
|
||||
|
||||
// get window.location to construct relative URLs
|
||||
nsCOMPtr<nsIURI> baseURL;
|
||||
JSObject* global = JS_GetGlobalObject(cx);
|
||||
|
@ -569,9 +594,42 @@ InstallTriggerGlobalStartSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc
|
|||
return JS_FALSE;
|
||||
}
|
||||
|
||||
if(NS_OK == nativeThis->StartSoftwareUpdate(globalObject, xpiURL, flags, &nativeRet))
|
||||
nsCOMPtr<nsIURI> checkuri;
|
||||
rv = nativeThis->GetOriginatingURI(globalObject, getter_AddRefs(checkuri));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
*rval = BOOLEAN_TO_JSVAL(nativeRet);
|
||||
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<nsIDOMWindowInternal> 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();
|
||||
PRBool enabled = PR_FALSE;
|
||||
nativeThis->UpdateEnabled(checkuri, XPI_WHITELIST, &enabled);
|
||||
if (!enabled)
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
|
||||
if (os)
|
||||
os->NotifyObservers(installInfo,
|
||||
"xpinstall-install-blocked",
|
||||
nsnull);
|
||||
}
|
||||
else
|
||||
{
|
||||
nativeThis->StartInstall(installInfo, &nativeRet);
|
||||
*rval = BOOLEAN_TO_JSVAL(nativeRet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
/* ***** 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(nsIDOMWindowInternal *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 nsIDOMWindowInternal originatingWindow; */
|
||||
NS_IMETHODIMP
|
||||
nsXPIInstallInfo::GetOriginatingWindow(nsIDOMWindowInternal * *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;
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/* ***** 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 "nsIDOMWindowInternal.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIURI.h"
|
||||
|
||||
class nsXPIInstallInfo : public nsIXPIInstallInfo
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIXPIINSTALLINFO
|
||||
|
||||
nsXPIInstallInfo(nsIDOMWindowInternal *aOriginatingWindow,
|
||||
nsIURI *aOriginatingURI, nsXPITriggerInfo *aTriggerInfo,
|
||||
PRUint32 aChromeType);
|
||||
|
||||
private:
|
||||
~nsXPIInstallInfo();
|
||||
|
||||
nsXPITriggerInfo* mTriggerInfo;
|
||||
nsCOMPtr<nsIDOMWindowInternal> mOriginatingWindow;
|
||||
nsCOMPtr<nsIURI> mOriginatingURI;
|
||||
PRUint32 mChromeType;
|
||||
};
|
|
@ -212,13 +212,38 @@ nsXPInstallManager::InitManagerWithHashes(const PRUnichar **aURLs,
|
|||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPInstallManager::InitManagerWithInstallInfo(nsIXPIInstallInfo* aInstallInfo)
|
||||
{
|
||||
nsXPITriggerInfo* triggers;
|
||||
nsresult rv = aInstallInfo->GetTriggerInfo(&triggers);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> win;
|
||||
rv = aInstallInfo->GetOriginatingWindow(getter_AddRefs(win));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRUint32 type;
|
||||
rv = aInstallInfo->GetChromeType(&type);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
// Passing ownership onto InitManager which will free when necessary
|
||||
aInstallInfo->SetTriggerInfo(nsnull);
|
||||
return InitManager(win, triggers, type);
|
||||
}
|
||||
}
|
||||
|
||||
NS_RELEASE_THIS();
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPInstallManager::InitManager(nsIScriptGlobalObject* aGlobalObject, nsXPITriggerInfo* aTriggers, PRUint32 aChromeType)
|
||||
nsXPInstallManager::InitManager(nsIDOMWindowInternal* aParentWindow, nsXPITriggerInfo* aTriggers, PRUint32 aChromeType)
|
||||
{
|
||||
if ( !aTriggers || aTriggers->Size() == 0 )
|
||||
{
|
||||
NS_WARNING("XPInstallManager called with no trigger info!");
|
||||
delete aTriggers;
|
||||
NS_RELEASE_THIS();
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
|
@ -229,7 +254,7 @@ nsXPInstallManager::InitManager(nsIScriptGlobalObject* aGlobalObject, nsXPITrigg
|
|||
mChromeType = aChromeType;
|
||||
mNeedsShutdown = PR_TRUE;
|
||||
|
||||
mParentWindow = do_QueryInterface(aGlobalObject);
|
||||
mParentWindow = aParentWindow;
|
||||
|
||||
// Start downloading initial chunks looking for signatures,
|
||||
mOutstandingCertLoads = mTriggers->Size();
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
#include "nsIObserver.h"
|
||||
#include "nsIBadCertListener.h"
|
||||
#include "nsIChannelEventSink.h"
|
||||
#include "nsIXPIInstallInfo.h"
|
||||
|
||||
#include "nsISoftwareUpdate.h"
|
||||
|
||||
|
@ -106,7 +107,7 @@ class nsXPInstallManager : public nsIXPIListener,
|
|||
NS_DECL_NSIBADCERTLISTENER
|
||||
NS_DECL_NSICHANNELEVENTSINK
|
||||
|
||||
NS_IMETHOD InitManager(nsIScriptGlobalObject* aGlobalObject, nsXPITriggerInfo* aTrigger, PRUint32 aChromeType );
|
||||
NS_IMETHOD InitManager(nsIDOMWindowInternal* aParentWindow, nsXPITriggerInfo* aTrigger, PRUint32 aChromeType );
|
||||
|
||||
private:
|
||||
nsresult InitManagerInternal();
|
||||
|
|
Загрузка…
Ссылка в новой задаче