Created
October 12, 2011 16:25
-
-
Save teramako/1281723 to your computer and use it in GitHub Desktop.
擬似Chrome URLを作成してXULを開けるようにする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
@license MPL 1.1/GPL 2.0/LGPL 2.1 | |
*/ | |
const { classes: Cc, interfaces: Ci, utils: Cu } = Components; | |
const UUID = "{9362f799-ce76-4d7c-9335-396b1c7870a6}"; | |
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | |
XPCOMUtils.defineLazyModuleGetter(this, "Services", "resource://gre/modules/Services.jsm"); | |
var PseudoChromeProtocolHandler; | |
installProtocolHandler(rootFile); | |
function installProtocolHandler (aRootFile) { | |
var rootSpec = aRootFile.isDirectory() ? | |
Services.io.newFileURI(aRootFile).spec : | |
"jar:" + Services.io.newFileURI(aRootFile).spec + "!/"; | |
PseudoChromeProtocolHandler = { | |
scheme: "pseudo-chrome", | |
defaultPort: -1, | |
protocolFlags: Ci.nsIProtocolHandler.URI_DANGEROUS_TO_LOAD | | |
Ci.nsIProtocolHandler.URI_IS_LOCAL_RESOURCE | | |
Ci.nsIProtocolHandler.URI_NORELATIVE | | |
Ci.nsIProtocolHandler.URI_NOAUTH, | |
get system_principal() { | |
delete this.system_principal; | |
return this.system_principal = Cc["@mozilla.org/scriptsecuritymanager;1"]. | |
getService(Ci.nsIScriptSecurityManager). | |
getSystemPrincipal(); | |
}, | |
newURI: function PC_newURI(aSpec, aOriginCharset, aBaseUri) { | |
let uri = Cc["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI); | |
uri.spec = aSpec; | |
return uri; | |
}, | |
newChannel: function PC_newChannel(aURI) { | |
Services.console.logStringMessage(rootSpec + aURI.path); | |
let url = rootSpec + aURI.path.substr(2); | |
let ch = Services.io.newChannel(url, null, null); | |
ch.originalURI = aURI; | |
ch.owner = this.system_principal; | |
return ch; | |
}, | |
allowPort: function PC_allowPort(aPort, aScheme) { | |
return false; | |
}, | |
QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]), | |
classID: Components.ID(UUID), | |
factory: { | |
createInstance: function PC_createInstance(aOuter, aIID) { | |
if (aOuter) { | |
throw Components.results.NS_ERROR_NO_AGGREGATION; | |
} | |
return PseudoChromeProtocolHandler.QueryInterface(aIID); | |
}, | |
lockFactory: function BNPH_lockFactory(aLock) { | |
throw Components.results.NS_ERROR_NOT_IMPLEMENTED; | |
}, | |
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIFactory]) | |
}, | |
}; | |
var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); | |
registrar.registerFactory(Components.ID(UUID), | |
"PseudoChromeProtocolHandler", | |
"@mozilla.org/network/protocol;1?name=pseudo-chrome", | |
PseudoChromeProtocolHandler.factory); | |
} | |
function uninstallProtocolHandler () { | |
if ("@mozilla.org/network/protocol;1?name=pseudo-chrome" in Cc) { | |
var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); | |
registrar.unregisterFactory(Components.ID(UUID), | |
PseudoChromeProtocolHandler.factory); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment