зеркало из https://github.com/mozilla/pjs.git
Bug 391279 - Allow createInstance to work for web handlers. r=cbiesinger, sr=dmose
This commit is contained in:
Родитель
2f796568c1
Коммит
56156f50fa
|
@ -237,6 +237,7 @@ bin/components/nsContentPrefService.js
|
|||
bin/components/nsContentDispatchChooser.js
|
||||
bin/components/nsHandlerService.js
|
||||
bin/components/nsScriptableIO.js
|
||||
bin/components/nsWebHandlerApp.js
|
||||
|
||||
; Modules
|
||||
bin/modules/*
|
||||
|
|
|
@ -237,6 +237,7 @@ bin\components\nsContentPrefService.js
|
|||
bin\components\nsContentDispatchChooser.js
|
||||
bin\components\nsHandlerService.js
|
||||
bin\components\nsScriptableIO.js
|
||||
bin\components\nsWebHandlerApp.js
|
||||
|
||||
; Modules
|
||||
bin\modules\*
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
#include "nsExternalProtocolHandler.h"
|
||||
#include "nsPrefetchService.h"
|
||||
#include "nsOfflineCacheUpdate.h"
|
||||
#include "nsHandlerAppImpl.h"
|
||||
#include "nsLocalHandlerApp.h"
|
||||
|
||||
// session history
|
||||
#include "nsSHEntry.h"
|
||||
|
|
|
@ -149,6 +149,7 @@ bin\components\downloads.xpt
|
|||
; Protocol/Content handling
|
||||
bin\components\nsContentDispatchChooser.js
|
||||
bin\components\nsHandlerService.js
|
||||
bin\components\nsWebHandlerApp.js
|
||||
|
||||
; spellchecker (may not be present)
|
||||
bin\components\spellchecker.xpt
|
||||
|
|
|
@ -222,8 +222,8 @@ interface nsIHandlerApp : nsISupports {
|
|||
/**
|
||||
* nsILocalHandlerApp is a local OS-level executable
|
||||
*/
|
||||
[scriptable, uuid(e21f3d75-9103-490e-bfb9-1bf09cc3f103)]
|
||||
interface nsILocalHandlerApp: nsISupports {
|
||||
[scriptable, uuid(9812be73-273c-478c-8170-c3e0db08ae7c)]
|
||||
interface nsILocalHandlerApp : nsIHandlerApp {
|
||||
|
||||
/**
|
||||
* Pointer to the executable file used to handle content
|
||||
|
@ -237,8 +237,8 @@ interface nsILocalHandlerApp: nsISupports {
|
|||
* we probably want to work with WhatWG to spec out and implement POST-based
|
||||
* handlers as well.
|
||||
*/
|
||||
[scriptable, uuid(065cd099-2f71-4ac8-9dab-17fc079e9647)]
|
||||
interface nsIWebHandlerApp: nsISupports {
|
||||
[scriptable, uuid(7521a093-c498-45ce-b462-df7ba0d882f6)]
|
||||
interface nsIWebHandlerApp : nsIHandlerApp {
|
||||
|
||||
/**
|
||||
* Template used to construct the URI to GET. Template is expected to have
|
||||
|
|
|
@ -288,6 +288,7 @@ bin\components\nsAboutAbout.js
|
|||
bin\components\nsDefaultCLH.js
|
||||
bin\components\nsContentDispatchChooser.js
|
||||
bin\components\nsHandlerService.js
|
||||
bin\components\nsWebHandlerApp.js
|
||||
|
||||
; Modules
|
||||
bin\modules\*
|
||||
|
|
|
@ -148,7 +148,7 @@ CPPSRCS = \
|
|||
nsExternalHelperAppService.cpp \
|
||||
nsExternalProtocolHandler.cpp \
|
||||
nsMIMEInfoImpl.cpp \
|
||||
nsHandlerAppImpl.cpp \
|
||||
nsLocalHandlerApp.cpp \
|
||||
$(OSHELPER) \
|
||||
$(NULL)
|
||||
|
||||
|
@ -158,7 +158,10 @@ GARBAGE += nsOSHelperAppService.cpp $(srcdir)/nsOSHelperAppService.cpp \
|
|||
nsMIMEInfoWin.cpp $(srcdir)/nsMIMEInfoWin.cpp
|
||||
endif
|
||||
|
||||
EXTRA_COMPONENTS = nsHandlerService.js
|
||||
EXTRA_COMPONENTS = \
|
||||
nsHandlerService.js \
|
||||
nsWebHandlerApp.js \
|
||||
$(NULL)
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a static lib.
|
||||
FORCE_STATIC_LIB = 1
|
||||
|
|
|
@ -75,5 +75,8 @@ nsIExternalHelperAppService
|
|||
#define NS_LOCALHANDLERAPP_CONTRACTID \
|
||||
"@mozilla.org/uriloader/local-handler-app;1"
|
||||
|
||||
#define NS_WEBHANDLERAPP_CONTRACTID \
|
||||
"@mozilla.org/uriloader/web-handler-app;1"
|
||||
|
||||
%}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsExternalHelperAppService.h"
|
||||
#include "nsCExternalHandlerService.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIFile.h"
|
||||
|
@ -124,7 +125,7 @@
|
|||
#include "nsCRT.h"
|
||||
|
||||
#include "nsMIMEInfoImpl.h"
|
||||
#include "nsHandlerAppImpl.h"
|
||||
#include "nsLocalHandlerApp.h"
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
PRLogModuleInfo* nsExternalHelperAppService::mLog = nsnull;
|
||||
|
@ -824,11 +825,13 @@ nsresult nsExternalHelperAppService::FillHandlerAppFromSource(
|
|||
const PRUnichar * uriTemplate = nsnull;
|
||||
FillLiteralValueFromTarget(aSource, kNC_UriTemplate, &uriTemplate);
|
||||
if (uriTemplate && uriTemplate[0]) {
|
||||
nsWebHandlerApp *handlerApp(new nsWebHandlerApp(appName,
|
||||
NS_ConvertUTF16toUTF8(uriTemplate)));
|
||||
if (!handlerApp) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsCOMPtr<nsIWebHandlerApp> handlerApp =
|
||||
do_CreateInstance(NS_WEBHANDLERAPP_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
handlerApp->SetName(nsDependentString(appName));
|
||||
handlerApp->SetUriTemplate(NS_ConvertUTF16toUTF8(uriTemplate));
|
||||
|
||||
NS_ADDREF(*aHandlerApp = handlerApp);
|
||||
} else {
|
||||
return NS_ERROR_FAILURE; // no path name _and_ no uri template
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim:expandtab:shiftwidth=2:tabstop=2:cin:
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* the Mozilla Corporation.
|
||||
* 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 ***** */
|
||||
|
||||
#include "nsLocalHandlerApp.h"
|
||||
|
||||
// XXX why does nsMIMEInfoImpl have a threadsafe nsISupports? do we need one
|
||||
// here too?
|
||||
NS_IMPL_ISUPPORTS2(nsLocalHandlerApp, nsILocalHandlerApp, nsIHandlerApp)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// nsIHandlerApp
|
||||
|
||||
NS_IMETHODIMP nsLocalHandlerApp::GetName(nsAString& aName)
|
||||
{
|
||||
if (mName.IsEmpty() && mExecutable) {
|
||||
// Don't want to cache this, just in case someone resets the app
|
||||
// without changing the description....
|
||||
mExecutable->GetLeafName(aName);
|
||||
} else {
|
||||
aName.Assign(mName);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsLocalHandlerApp::SetName(const nsAString & aName)
|
||||
{
|
||||
mName.Assign(aName);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// nsILocalHandlerApp
|
||||
|
||||
NS_IMETHODIMP nsLocalHandlerApp::GetExecutable(nsIFile **aExecutable)
|
||||
{
|
||||
NS_IF_ADDREF(*aExecutable = mExecutable);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsLocalHandlerApp::SetExecutable(nsIFile *aExecutable)
|
||||
{
|
||||
mExecutable = aExecutable;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim:expandtab:shiftwidth=2:tabstop=2:cin:
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* the Mozilla Corporation.
|
||||
* 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 ***** */
|
||||
|
||||
#ifndef __nsLocalHandlerAppImpl_h__
|
||||
#define __nsLocalHandlerAppImpl_h__
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsIMIMEInfo.h"
|
||||
#include "nsIFile.h"
|
||||
|
||||
class nsLocalHandlerApp : public nsILocalHandlerApp
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIHANDLERAPP
|
||||
NS_DECL_NSILOCALHANDLERAPP
|
||||
|
||||
nsLocalHandlerApp() { }
|
||||
|
||||
nsLocalHandlerApp(const PRUnichar *aName, nsIFile *aExecutable)
|
||||
: mName(aName), mExecutable(aExecutable) { }
|
||||
|
||||
nsLocalHandlerApp(const nsAString & aName, nsIFile *aExecutable)
|
||||
: mName(aName), mExecutable(aExecutable) { }
|
||||
virtual ~nsLocalHandlerApp() { }
|
||||
|
||||
protected:
|
||||
nsString mName;
|
||||
nsCOMPtr<nsIFile> mExecutable;
|
||||
};
|
||||
|
||||
#endif // __nsLocalHandlerAppImpl_h__
|
|
@ -0,0 +1,98 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2007
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Shawn Wilsher <me@shawnwilsher.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 ***** */
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Constants
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// nsWebHandler class
|
||||
|
||||
function nsWebHandlerApp() {}
|
||||
|
||||
nsWebHandlerApp.prototype = {
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//// nsWebHandler
|
||||
|
||||
classDescription: "A web handler for protocols and content",
|
||||
classID: Components.ID("8b1ae382-51a9-4972-b930-56977a57919d"),
|
||||
contractID: "@mozilla.org/uriloader/web-handler-app;1",
|
||||
|
||||
_name: null,
|
||||
_uriTemplate: null,
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//// nsIHandlerApp
|
||||
|
||||
get name() {
|
||||
return this._name;
|
||||
},
|
||||
|
||||
set name(aName) {
|
||||
this._name = aName;
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//// nsIWebHandlerApp
|
||||
|
||||
get uriTemplate() {
|
||||
return this._uriTemplate;
|
||||
},
|
||||
|
||||
set uriTemplate(aURITemplate) {
|
||||
this._uriTemplate = aURITemplate;
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//// nsISupports
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebHandlerApp, Ci.nsIHandlerApp])
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Module
|
||||
|
||||
let components = [nsWebHandlerApp];
|
||||
|
||||
function NSGetModule(compMgr, fileSpec)
|
||||
{
|
||||
return XPCOMUtils.generateModule(components);
|
||||
}
|
||||
|
|
@ -53,16 +53,10 @@ function run_test() {
|
|||
}
|
||||
};
|
||||
|
||||
var webHandler = {
|
||||
name: "Web Handler",
|
||||
uriTemplate: "http://www.example.com/?%s",
|
||||
interfaces: [Ci.nsIHandlerApp, Ci.nsIWebHandlerApp, Ci.nsISupports],
|
||||
QueryInterface: function(iid) {
|
||||
if (!this.interfaces.some( function(v) { return iid.equals(v) } ))
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
return this;
|
||||
}
|
||||
};
|
||||
var webHandler = Cc["@mozilla.org/uriloader/web-handler-app;1"].
|
||||
createInstance(Ci.nsIWebHandlerApp);
|
||||
webHandler.name = "Web Handler";
|
||||
webHandler.uriTemplate = "http://www.example.com/?%s";
|
||||
|
||||
var handlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"].
|
||||
getService(Ci.nsIHandlerService);
|
||||
|
|
Загрузка…
Ссылка в новой задаче