mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 540558: window.InstallTrigger.install exists but won't work. r=dveditz
This commit is contained in:
parent
5fd942335d
commit
d08a98eaa9
@ -121,6 +121,36 @@ FinalizeInstallTriggerGlobal(JSContext *cx, JSObject *obj)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
//
|
||||
@ -163,7 +193,12 @@ static nsIDOMInstallTriggerGlobal* getTriggerNative(JSContext *cx, JSObject *obj
|
||||
if (!JS_InstanceOf(cx, obj, &InstallTriggerGlobalClass, nsnull))
|
||||
return nsnull;
|
||||
|
||||
return (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj);
|
||||
nsIDOMInstallTriggerGlobal *native = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj);
|
||||
if (!native) {
|
||||
// xpinstall script contexts delay creation of the native.
|
||||
CreateNativeObject(cx, obj, &native);
|
||||
}
|
||||
return native;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -83,6 +83,7 @@ _BROWSER_FILES = harness.js \
|
||||
browser_cancel.js \
|
||||
browser_navigateaway.js \
|
||||
browser_navigateaway2.js \
|
||||
browser_bug540558.js \
|
||||
unsigned.xpi \
|
||||
signed.xpi \
|
||||
signed2.xpi \
|
||||
@ -98,6 +99,7 @@ _BROWSER_FILES = harness.js \
|
||||
installchrome.html \
|
||||
authRedirect.sjs \
|
||||
cookieRedirect.sjs \
|
||||
bug540558.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_BROWSER_FILES)
|
||||
|
37
xpinstall/tests/browser_bug540558.js
Normal file
37
xpinstall/tests/browser_bug540558.js
Normal file
@ -0,0 +1,37 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests that calling InstallTrigger.installChrome works
|
||||
function test() {
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
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() {
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.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();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
23
xpinstall/tests/bug540558.html
Normal file
23
xpinstall/tests/bug540558.html
Normal file
@ -0,0 +1,23 @@
|
||||
<!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>
|
Loading…
Reference in New Issue
Block a user