First part of fix for web-based protocol handlers failing in certain situations (bug 394483); r=biesi, sr=sicking

This commit is contained in:
dmose%mozilla.org 2007-10-04 06:10:48 +00:00
Родитель 53dc722681
Коммит c930b4f459
19 изменённых файлов: 393 добавлений и 204 удалений

Просмотреть файл

@ -108,7 +108,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrefetchService, Init)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsOfflineCacheUpdateService,
nsOfflineCacheUpdateService::GetInstance)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsOfflineCacheUpdate)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLocalHandlerApp)
NS_GENERIC_FACTORY_CONSTRUCTOR(PlatformLocalHandlerApp_t)
#if defined(XP_MAC) || defined(XP_MACOSX)
#include "nsInternetConfigService.h"
@ -218,7 +218,8 @@ static const nsModuleComponentInfo gDocShellModuleInfo[] = {
{ NS_OFFLINECACHEUPDATE_CLASSNAME, NS_OFFLINECACHEUPDATE_CID, NS_OFFLINECACHEUPDATE_CONTRACTID,
nsOfflineCacheUpdateConstructor, },
{ "Local Application Handler App", NS_LOCALHANDLERAPP_CID,
NS_LOCALHANDLERAPP_CONTRACTID, nsLocalHandlerAppConstructor, },
NS_LOCALHANDLERAPP_CONTRACTID, PlatformLocalHandlerApp_tConstructor, },
#if defined(XP_MAC) || defined(XP_MACOSX)
{ "Internet Config Service", NS_INTERNETCONFIGSERVICE_CID, NS_INTERNETCONFIGSERVICE_CONTRACTID,
nsInternetConfigServiceConstructor, },

Просмотреть файл

@ -52,7 +52,7 @@ typedef long nsHandlerInfoAction;
* nsIHandlerInfo gives access to the information about how a given protocol
* scheme or MIME-type is handled.
*/
[scriptable, uuid(325e56a7-3762-4312-aec7-f1fcf84b4145)]
[scriptable, uuid(325e56a7-3762-4312-aec7-f1fcf84b4145)]
interface nsIHandlerInfo : nsISupports {
/**
* The type of this handler info. For MIME handlers, this is the MIME type.
@ -239,7 +239,7 @@ interface nsIMIMEInfo : nsIHandlerInfo {
* we should also try to make nsIWebContentHandlerInfo inherit from or possibly
* be replaced by nsIWebHandlerApp (bug 394710).
*/
[scriptable, uuid(b504f39e-d88a-4435-8e0d-e13f1070f7e7)]
[scriptable, uuid(8d298761-0963-4c90-99e2-6ea498825e82)]
interface nsIHandlerApp : nsISupports {
/**
@ -259,6 +259,21 @@ interface nsIHandlerApp : nsISupports {
* @returns true if the two are logically equivalent, false otherwise
*/
boolean equals(in nsIHandlerApp aHandlerApp);
/**
* Launches the application with the specified URI.
*
* @param aURI
* The URI to launch this application with
*
* @param aWindowContext
* Required for web handlers; is passed through to
* nsIURILoader.openURI, but see bug 394483 for info on
* how this needs to evolve.
*/
void launchWithURI(in nsIURI aURI,
[optional] in nsIInterfaceRequestor aWindowContext);
};
/**

Просмотреть файл

@ -367,6 +367,7 @@ MAKEFILES_uriloader="
uriloader/base/Makefile
uriloader/exthandler/Makefile
uriloader/exthandler/tests/Makefile
uriloader/exthandler/tests/browser/Makefile
"
MAKEFILES_profile="

Просмотреть файл

@ -103,6 +103,7 @@ ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
OSHELPER += nsInternetConfig.cpp \
nsInternetConfigService.cpp \
nsMIMEInfoMac.cpp \
nsLocalHandlerAppMac.cpp \
$(NULL)
endif

Просмотреть файл

Просмотреть файл

@ -0,0 +1,59 @@
/* ***** 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 code.
*
* The Initial Developer of the Original Code is
* the Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Dan Mosedale <dmose@mozilla.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef NSLOCALHANDLERAPPMAC_H_
#define NSLOCALHANDLERAPPMAC_H_
#include "nsLocalHandlerApp.h"
class nsLocalHandlerAppMac : public nsLocalHandlerApp {
public:
nsLocalHandlerAppMac() { }
nsLocalHandlerAppMac(const PRUnichar *aName, nsIFile *aExecutable)
: nsLocalHandlerApp(aName, aExecutable) {}
nsLocalHandlerAppMac(const nsAString & aName, nsIFile *aExecutable)
: nsLocalHandlerApp(aName, aExecutable) {}
virtual ~nsLocalHandlerAppMac() { }
NS_IMETHOD LaunchWithURI(nsIURI* aURI,
nsIInterfaceRequestor* aWindowContext);
};
#endif /*NSLOCALHANDLERAPPMAC_H_*/

Просмотреть файл

@ -99,49 +99,6 @@ nsMIMEInfoMac::LaunchWithFile(nsIFile *aFile)
return app->LaunchWithDoc(localFile, PR_FALSE);
}
NS_IMETHODIMP
nsMIMEInfoMac::LaunchWithURI(nsIURI* aURI,
nsIInterfaceRequestor* aWindowContext)
{
nsCOMPtr<nsIFile> application;
nsresult rv;
// for now, this is only being called with protocol handlers; that
// will change once we get to more general registerContentHandler
// support
NS_ASSERTION(mClass == eProtocolInfo,
"nsMIMEInfoBase should be a protocol handler");
if (mPreferredAction == useHelperApp) {
// check for and launch with web handler app
nsCOMPtr<nsIWebHandlerApp> webHandlerApp =
do_QueryInterface(mPreferredApplication, &rv);
if (NS_SUCCEEDED(rv)) {
return LaunchWithWebHandler(webHandlerApp, aURI, aWindowContext);
}
// otherwise, get the application executable from the handler
nsCOMPtr<nsILocalHandlerApp> localHandlerApp =
do_QueryInterface(mPreferredApplication, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = localHandlerApp->GetExecutable(getter_AddRefs(application));
NS_ENSURE_SUCCESS(rv, rv);
// pass the entire URI to the handler.
nsCAutoString spec;
aURI->GetSpec(spec);
return OpenApplicationWithURI(application, spec);
}
if (mPreferredAction == useSystemDefault) {
return LoadUriInternal(aURI);
}
return NS_ERROR_INVALID_ARG;
}
nsresult
nsMIMEInfoMac::LoadUriInternal(nsIURI *aURI)
{
@ -167,51 +124,3 @@ nsMIMEInfoMac::GetHasDefaultHandler(PRBool *_retval)
return NS_OK;
}
/**
* static; mostly copy/pasted from nsMacShellService.cpp (which is in browser/,
* so we can't depend on it here). This code probably really wants to live
* somewhere more central; see bug 389922.
*/
nsresult
nsMIMEInfoMac::OpenApplicationWithURI(nsIFile* aApplication,
const nsCString& aURI)
{
nsresult rv;
nsCOMPtr<nsILocalFileMac> lfm(do_QueryInterface(aApplication, &rv));
NS_ENSURE_SUCCESS(rv, rv);
CFURLRef appURL;
rv = lfm->GetCFURL(&appURL);
if (NS_FAILED(rv))
return rv;
const UInt8* uriString = (const UInt8*)aURI.get();
CFURLRef uri = ::CFURLCreateWithBytes(NULL, uriString, aURI.Length(),
kCFStringEncodingUTF8, NULL);
if (!uri) {
::CFRelease(appURL);
return NS_ERROR_OUT_OF_MEMORY;
}
CFArrayRef uris = ::CFArrayCreate(NULL, (const void**)&uri, 1, NULL);
if (!uris) {
::CFRelease(uri);
::CFRelease(appURL);
return NS_ERROR_OUT_OF_MEMORY;
}
LSLaunchURLSpec launchSpec;
launchSpec.appURL = appURL;
launchSpec.itemURLs = uris;
launchSpec.passThruParams = NULL;
launchSpec.launchFlags = kLSLaunchDefaults;
launchSpec.asyncRefCon = NULL;
OSErr err = ::LSOpenFromURLSpec(&launchSpec, NULL);
::CFRelease(uris);
::CFRelease(uri);
::CFRelease(appURL);
return err != noErr ? NS_ERROR_FAILURE : NS_OK;
}

Просмотреть файл

@ -46,8 +46,6 @@ class nsMIMEInfoMac : public nsMIMEInfoImpl {
nsMIMEInfoMac(const nsACString& aType, HandlerClass aClass) :
nsMIMEInfoImpl(aType, aClass) {}
NS_IMETHOD LaunchWithURI(nsIURI* aURI,
nsIInterfaceRequestor* aWindowContext);
NS_IMETHOD LaunchWithFile(nsIFile* aFile);
NS_IMETHOD GetHasDefaultHandler(PRBool *_retval);
protected:

Просмотреть файл

@ -2030,7 +2030,6 @@ nsresult nsExternalAppHandler::OpenWithApplication()
// perform launch with application. That won't happen until we are done downloading
// the content and are sure we've showna progress dialog. This was done to simplify the
// logic that was showing up in this method.
NS_IMETHODIMP nsExternalAppHandler::LaunchWithApplication(nsIFile * aApplication, PRBool aRememberThisPreference)
{
if (mCanceled)
@ -2041,8 +2040,8 @@ NS_IMETHODIMP nsExternalAppHandler::LaunchWithApplication(nsIFile * aApplication
mReceivedDispositionInfo = PR_TRUE;
if (mMimeInfo && aApplication) {
nsLocalHandlerApp *handlerApp(new nsLocalHandlerApp(EmptyString(),
aApplication));
PlatformLocalHandlerApp_t *handlerApp =
new PlatformLocalHandlerApp_t(EmptyString(), aApplication);
mMimeInfo->SetPreferredApplicationHandler(handlerApp);
}

Просмотреть файл

@ -39,6 +39,8 @@
* ***** END LICENSE BLOCK ***** */
#include "nsLocalHandlerApp.h"
#include "nsIURI.h"
#include "nsIProcess.h"
// XXX why does nsMIMEInfoImpl have a threadsafe nsISupports? do we need one
// here too?
@ -91,6 +93,32 @@ nsLocalHandlerApp::Equals(nsIHandlerApp *aHandlerApp, PRBool *_retval)
return executable->Equals(mExecutable, _retval);
}
NS_IMETHODIMP
nsLocalHandlerApp::LaunchWithURI(nsIURI *aURI,
nsIInterfaceRequestor *aWindowContext)
{
// pass the entire URI to the handler.
nsCAutoString spec;
aURI->GetSpec(spec);
return LaunchWithIProcess(spec);
}
nsresult
nsLocalHandlerApp::LaunchWithIProcess(const nsCString& aArg)
{
nsresult rv;
nsCOMPtr<nsIProcess> process = do_CreateInstance(NS_PROCESS_CONTRACTID, &rv);
if (NS_FAILED(rv))
return rv;
if (NS_FAILED(rv = process->Init(mExecutable)))
return rv;
const char *string = aArg.get();
PRUint32 pid;
return process->Run(PR_FALSE, &string, 1, &pid);
}
////////////////////////////////////////////////////////////////////////////////
//// nsILocalHandlerApp

Просмотреть файл

@ -63,6 +63,28 @@ public:
protected:
nsString mName;
nsCOMPtr<nsIFile> mExecutable;
/**
* Launches this application with a single argument (typically either
* a file path or a URI spec). This is meant as a helper method for
* implementations of (e.g.) LaunchWithURI.
*
* @param aApp The application to launch (may not be null)
* @param aArg The argument to pass on the command line
*/
NS_HIDDEN_(nsresult) LaunchWithIProcess(const nsCString &aArg);
};
// any platforms that need a platform-specific class instead of just
// using nsLocalHandlerApp need to add an include and a typedef here.
#ifdef XP_MACOSX
# ifndef NSLOCALHANDLERAPPMAC_H_
# include "mac/nsLocalHandlerAppMac.h"
typedef nsLocalHandlerAppMac PlatformLocalHandlerApp_t;
# endif
#else
typedef nsLocalHandlerApp PlatformLocalHandlerApp_t;
#endif
#endif // __nsLocalHandlerAppImpl_h__

Просмотреть файл

@ -387,8 +387,6 @@ NS_IMETHODIMP
nsMIMEInfoBase::LaunchWithURI(nsIURI* aURI,
nsIInterfaceRequestor* aWindowContext)
{
nsresult rv;
// for now, this is only being called with protocol handlers; that
// will change once we get to more general registerContentHandler
// support
@ -403,26 +401,7 @@ nsMIMEInfoBase::LaunchWithURI(nsIURI* aURI,
if (!mPreferredApplication)
return NS_ERROR_FILE_NOT_FOUND;
// check for and possibly launch with web application
nsCOMPtr<nsIWebHandlerApp> webHandler =
do_QueryInterface(mPreferredApplication, &rv);
if (NS_SUCCEEDED(rv)) {
return LaunchWithWebHandler(webHandler, aURI, aWindowContext);
}
// ok, we must have a local handler app
nsCOMPtr<nsILocalHandlerApp> localHandler =
do_QueryInterface(mPreferredApplication, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIFile> executable;
rv = localHandler->GetExecutable(getter_AddRefs(executable));
NS_ENSURE_SUCCESS(rv, rv);
// pass the entire URI to the handler.
nsCAutoString spec;
aURI->GetSpec(spec);
return LaunchWithIProcess(executable, spec);
return mPreferredApplication->LaunchWithURI(aURI, aWindowContext);
}
return NS_ERROR_INVALID_ARG;
@ -459,70 +438,6 @@ nsMIMEInfoBase::LaunchWithIProcess(nsIFile* aApp, const nsCString& aArg)
return process->Run(PR_FALSE, &string, 1, &pid);
}
/* static */
nsresult
nsMIMEInfoBase::LaunchWithWebHandler(nsIWebHandlerApp *aApp, nsIURI *aURI,
nsIInterfaceRequestor *aWindowContext)
{
nsCAutoString uriTemplate;
nsresult rv = aApp->GetUriTemplate(uriTemplate);
if (NS_FAILED(rv)) {
return NS_ERROR_INVALID_ARG;
}
// get the URI spec so we can escape it for insertion into the template
nsCAutoString uriSpecToHandle;
rv = aURI->GetSpec(uriSpecToHandle);
if (NS_FAILED(rv)) {
return NS_ERROR_INVALID_ARG;
}
// XXX need to strip passwd & username from URI to handle, as per the
// WhatWG HTML5 draft. nsSimpleURL, which is what we're going to get,
// can't do this directly. Ideally, we'd fix nsStandardURL to make it
// possible to turn off all of its quirks handling, and use that...
// XXX this doesn't exactly match how the HTML5 draft is requesting us to
// escape; at the very least, it should be escaping @ signs, and there
// may well be more issues (bug 382019).
nsCAutoString escapedUriSpecToHandle;
NS_EscapeURL(uriSpecToHandle, esc_Minimal | esc_Forced | esc_Colon,
escapedUriSpecToHandle);
// XXX note that this replace all occurrences of %s with the URL to be
// handled, instead of just the first, as specified by the current draft
// of the spec. Bug 394476 filed to track this.
uriTemplate.ReplaceSubstring(NS_LITERAL_CSTRING("%s"),
escapedUriSpecToHandle);
// convert spec to URI; no original charset needed since there's no way
// to communicate that information to any handler
nsCOMPtr<nsIURI> uriToSend;
rv = NS_NewURI(getter_AddRefs(uriToSend), uriTemplate);
if (NS_FAILED(rv))
return rv;
// create a channel
nsCOMPtr<nsIChannel> newChannel;
rv = NS_NewChannel(getter_AddRefs(newChannel), uriToSend, nsnull, nsnull,
nsnull, nsIChannel::LOAD_DOCUMENT_URI);
if (NS_FAILED(rv))
return rv;
// load the URI
nsCOMPtr<nsIURILoader> uriLoader = do_GetService(NS_URI_LOADER_CONTRACTID,
&rv);
NS_ENSURE_SUCCESS(rv, rv);
// XXX ideally, aIsContentPreferred (the second param) should really be
// passed in from above. Practically, PR_TRUE is probably a reasonable
// default since browsers don't care much, and link click is likely to be
// the more interesting case for non-browser apps. See
// <https://bugzilla.mozilla.org/show_bug.cgi?id=392957#c9> for details.
return uriLoader->OpenURI(newChannel, PR_TRUE, aWindowContext);
}
// nsMIMEInfoImpl implementation
NS_IMETHODIMP
nsMIMEInfoImpl::GetDefaultDescription(nsAString& aDefaultDescription)

Просмотреть файл

@ -155,24 +155,6 @@ class nsMIMEInfoBase : public nsIMIMEInfo {
static NS_HIDDEN_(nsresult) LaunchWithIProcess(nsIFile* aApp,
const nsCString &aArg);
/**
* Used to launch a web-based handler with this URI.
*
* @param aURI The URI to launch with.
*
* @param aWindowContext
* The window to parent the dialog against, and, if a web handler
* is chosen, it is loaded in this window as well. This parameter
* may be ultimately passed nsIURILoader.openURI in the case of a
* web handler, and aWindowContext is null or not present, web
* handlers will fail. We need to do better than that; bug 394483
* filed in order to track.
*
*/
static NS_HIDDEN_(nsresult)
LaunchWithWebHandler(nsIWebHandlerApp *aApp, nsIURI *aURI,
nsIInterfaceRequestor *aWindowContext);
/**
* Given a file: nsIURI, return the associated nsILocalFile
*

Просмотреть файл

@ -21,6 +21,7 @@
* Contributor(s):
* Shawn Wilsher <me@shawnwilsher.com>
* Myk Melez <myk@mozilla.org>
* Dan Mosedale <dmose@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
@ -84,6 +85,38 @@ nsWebHandlerApp.prototype = {
return false;
},
launchWithURI: function nWHA__launchWithURI(aURI, aWindowContext) {
// XXX need to strip passwd & username from URI to handle, as per the
// WhatWG HTML5 draft. nsSimpleURL, which is what we're going to get,
// can't do this directly. Ideally, we'd fix nsStandardURL to make it
// possible to turn off all of its quirks handling, and use that...
// encode the URI to be handled
var escapedUriSpecToHandle = encodeURIComponent(aURI.spec);
// insert the encoded URI
var uriToSend = this.uriTemplate.replace("%s", escapedUriSpecToHandle);
// create a channel from this URI
var ioService = Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
var channel = ioService.newChannel(uriToSend, null, null);
channel.loadFlags = Components.interfaces.nsIChannel.LOAD_DOCUMENT_URI;
// load the channel
var uriLoader = Components.classes["@mozilla.org/uriloader;1"].
getService(Components.interfaces.nsIURILoader);
// XXX ideally, aIsContentPreferred (the second param) should really be
// passed in from above. Practically, true is probably a reasonable
// default since browsers don't care much, and link click is likely to be
// the more interesting case for non-browser apps. See
// <https://bugzilla.mozilla.org/show_bug.cgi?id=392957#c9> for details.
uriLoader.openURI(channel, true, aWindowContext);
return;
},
//////////////////////////////////////////////////////////////////////////////
//// nsIWebHandlerApp

Просмотреть файл

@ -20,6 +20,7 @@
#
# Contributor(s):
# Myk Melez <myk@mozilla.org>
# Dan Mosedale <dmose@mozilla.org>
#
# 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"),
@ -40,6 +41,9 @@ topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
DIRS += mochitest \
$(NULL)
include $(DEPTH)/config/autoconf.mk
MODULE = test_uriloader_exthandler

Просмотреть файл

@ -0,0 +1,54 @@
# ***** 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) 2007
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Dan Mosedale <dmose@mozilla.org>
#
# 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 = uriloader/exthandler/tests/mochitest
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_TEST_FILES = \
test_handlerApps.xhtml \
handlerApps.js \
handlerApp.xhtml \
$(NULL)
libs:: $(_TEST_FILES)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)

Просмотреть файл

@ -0,0 +1,27 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Pseudo Web Handler App</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="onLoad()">
Pseudo Web Handler App
<script class="testbody" type="text/javascript">
<![CDATA[
function onLoad() {
var originalUriToHandle = encodeURIComponent(window.opener.testURI);
window.opener.is(location.search, "?uri=" + originalUriToHandle,
"uri passed to web-handler app");
window.opener.SimpleTest.finish()
window.close();
}
]]>
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,128 @@
/* ***** 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 code.
*
* The Initial Developer of the Original Code is
* the Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Dan Mosedale <dmose@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 ***** */
// handlerApp.xhtml grabs this for verification purposes via window.opener
var testURI = "webcal://127.0.0.1/rheeeeet.html";
function test() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
// set up the web handler object
var webHandler =
Components.classes["@mozilla.org/uriloader/web-handler-app;1"].
createInstance(Components.interfaces.nsIWebHandlerApp);
webHandler.name = "Test Web Handler App";
webHandler.uriTemplate =
"http://localhost:8888/tests/uriloader/exthandler/tests/mochitest/" +
"handlerApp.xhtml?uri=%s";
// set up the uri to test with
var ioService = Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
var uri = ioService.newURI(testURI, null, null);
// create a window, and launch the handler in it
var newWindow = window.open("", "handlerWindow", "height=300,width=300");
var windowContext =
newWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
getInterface(Components.interfaces.nsIWebNavigation).
QueryInterface(Components.interfaces.nsIDocShell);
webHandler.launchWithURI(uri, windowContext);
// if we get this far without an exception, we've passed
ok(true, "webHandler launchWithURI test");
// set up the local handler object
var localHandler =
Components.classes["@mozilla.org/uriloader/local-handler-app;1"].
createInstance(Components.interfaces.nsILocalHandlerApp);
localHandler.name = "Test Local Handler App";
// get a local app that we know will be there and do something sane
var osString = Components.classes["@mozilla.org/xre/app-info;1"].
getService(Components.interfaces.nsIXULRuntime).OS;
var dirSvc = Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIDirectoryServiceProvider);
if (osString == "WINNT") {
var windowsDir = dirSvc.getFile("WinD", {});
var exe = windowsDir.clone();
exe.appendRelativePath("SYSTEM32\\HOSTNAME.EXE");
} else if (osString == "Darwin") {
var localAppsDir = dirSvc.getFile("LocApp", {});
exe = localAppsDir.clone();
exe.append("iCal.app"); // lingers after the tests finish, but this seems
// seems better than explicitly killing it, since
// developers who run the tests locally may well
// information in their running copy of iCal
} else {
// assume a generic UNIX variant
exe = Components.classes["@mozilla.org/file/local;1"].
createInstance(Components.interfaces.nsILocalFile);
exe.initWithPath("/bin/test");
}
localHandler.executable = exe;
localHandler.launchWithURI(ioService.newURI(testURI, null, null));
// if we get this far without an exception, we've passed
ok(true, "localHandler launchWithURI test");
// if we ever decide that killing iCal is the right thing to do, change
// the if statement below from "NOTDarwin" to "Darwin"
if (osString == "NOTDarwin") {
var killall = Components.classes["@mozilla.org/file/local;1"].
createInstance(Components.interfaces.nsILocalFile);
killall.initWithPath("/usr/bin/killall");
var process = Components.classes["@mozilla.org/process/util;1"].
createInstance(Components.interfaces.nsIProcess);
process.init(killall);
var args = ['iCal'];
process.run(false, args, args.length);
}
SimpleTest.waitForExplicitFinish();
}
test();

Просмотреть файл

@ -0,0 +1,13 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test for Handler Apps </title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="handlerApps.js"/>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
</body>
</html>